changeset 52873:bbef43f7dfd8 fibers

Move JVMTI mount event to after yield so that stack can be walked
author alanb
date Mon, 03 Dec 2018 09:30:26 +0000
parents e9aa1c8a7794
children 38663fca7d7c
files src/java.base/share/classes/java/lang/Fiber.java
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/Fiber.java	Fri Nov 30 14:43:10 2018 +0100
+++ b/src/java.base/share/classes/java/lang/Fiber.java	Mon Dec 03 09:30:26 2018 +0000
@@ -294,8 +294,8 @@
         assert Thread.currentCarrierThread().getFiber() == null;
 
         // set state to ST_RUNNING
-        boolean started = stateCompareAndSet(ST_STARTED, ST_RUNNABLE);
-        if (!started) {
+        boolean firstRun = stateCompareAndSet(ST_STARTED, ST_RUNNABLE);
+        if (!firstRun) {
             // continue on this carrier thread if fiber was parked
             if (stateCompareAndSet(ST_PARKED, ST_RUNNABLE)) {
                 parkPermitGetAndSet(false);  // consume parking permit
@@ -304,7 +304,7 @@
             }
         }
 
-        mount(started);
+        mount(firstRun);
         try {
             cont.run();
         } finally {
@@ -321,7 +321,7 @@
      * Mounts this fiber. This method must be invoked before the continuation
      * is run or continued. It binds the fiber to the current carrier thread.
      */
-    private void mount(boolean started) {
+    private void mount(boolean firstRun) {
         Thread thread = Thread.currentCarrierThread();
 
         // sets the carrier thread
@@ -335,9 +335,8 @@
         assert thread.getFiber() == null;
         thread.setFiber(this);
 
-        if (notifyJvmtiEvents) {
-            if (started)
-                notifyFiberStarted(thread, this);
+        if (firstRun && notifyJvmtiEvents) {
+            notifyFiberStarted(thread, this);
             notifyFiberMount(thread, this);
         }
     }
@@ -533,6 +532,11 @@
 
         // continued
         assert stateGet() == ST_RUNNABLE;
+
+        // notify JVMTI mount event here so that stack is avaiable to agents
+        if (notifyJvmtiEvents) {
+            notifyFiberMount(Thread.currentCarrierThread(), this);
+        }
     }
 
     /**