Uploaded image for project: 'CCC Migration Project'
  1. CCC Migration Project
  2. CCC-8155881

JNI Specification for DetachCurrentThread needs modification in relation to pending exceptions

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 9
    • docs
    • behavioral
    • minimal
    • No risk at all this simply brings the existing VM behaviour into compliance with the JNI specification.
    • Other
    • SE

      Summary

      Allow DetachCurrentThread to be called with an exception pending.

      Problem

      Currently the JNI specification indicates that, unless listed otherwise, no JNI method should be called with a pending exception. DetachCurrentThread is not listed as allowing a pending exception, but the implementation of DetachCurrentThread in hotspot implements the "uncaught exception handling" that is expected in Java threads - via the Thread->exit() call which invokes JavaThread::exit

      This puts hotspot in conflict with the specification, but the uncaught exception handling is highly desirable so we do not want to change the behaviour of the VM.

      But it is probably too strong to mandate that DetachCurrentThread must do uncaught exception handling, so we simply modify the spec to allow hotspots behaviour to be compliant.

      Solution

      Proposed changes:

      First add DetachCurrentThread to the list of methods that can be called with an exception pending:

      --- old/docs/technotes/guides/jni/spec/design.html Tue May 31 02:47:24 2016
      +++ new/docs/technotes/guides/jni/spec/design.html Tue May 31 02:47:22 2016
      @@ -678,7 +678,8 @@
       DeleteWeakGlobalRef()
       MonitorExit()
       PushLocalFrame()
      -PopLocalFrame()</pre>
      +PopLocalFrame()
      +DetachCurrentThread()</pre>

           

      Secondly, add a note in DetachCurrentThread that any such exception may be reported:

      --- old/docs/technotes/guides/jni/spec/invocation.html Tue May 31 02:47:29 2016
      +++ new/docs/technotes/guides/jni/spec/invocation.html Tue May 31 02:47:27 2016
      @@ -666,6 +666,8 @@
       The main thread can be detached from the VM.
       <p>Trying to detach a thread that is not attached
       is a no-op.</p>
      +<p>If an exception is pending when <code>DetachCurrentThread</code> is called,
      +the VM may choose to report its existence.</p>

      Specification

      Proposed change:
      
      --- old/docs/technotes/guides/jni/spec/design.html Tue May 31 02:47:24 2016
      +++ new/docs/technotes/guides/jni/spec/design.html Tue May 31 02:47:22 2016
      @@ -678,7 +678,8 @@
       DeleteWeakGlobalRef()
       MonitorExit()
       PushLocalFrame()
      -PopLocalFrame()</pre>
      +PopLocalFrame()
      +DetachCurrentThread()</pre>
       
       <table width="100%" summary="">
       <tr>
      --- old/docs/technotes/guides/jni/spec/invocation.html Tue May 31 02:47:29 2016
      +++ new/docs/technotes/guides/jni/spec/invocation.html Tue May 31 02:47:27 2016
      @@ -666,6 +666,8 @@
       The main thread can be detached from the VM.
       <p>Trying to detach a thread that is not attached
       is a no-op.</p>
      +<p>If an exception is pending when <code>DetachCurrentThread</code> is called,
      +the VM may choose to report its existence.</p>

            dholmes David Holmes
            dholmes David Holmes
            Serguei Spitsyn
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: