Skip to content

Commit

Permalink
review: moved notifyJvmtiStart/notifyJvmtiEnd calls from VirtualThrea…
Browse files Browse the repository at this point in the history
…d.run to the caller
  • Loading branch information
sspitsyn committed Oct 17, 2024
1 parent 0ad3fd7 commit f8d0515
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
31 changes: 13 additions & 18 deletions src/java.base/share/classes/java/lang/VirtualThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,12 @@ private static Runnable wrap(VirtualThread vthread, Runnable task) {
@Hidden
@JvmtiMountTransition
public void run() {
// notify JVMTI
vthread.notifyJvmtiStart();

vthread.run(task);

// notify JVMTI
vthread.notifyJvmtiEnd();
vthread.notifyJvmtiStart(); // notify JVMTI
try {
vthread.run(task);
} finally {
vthread.notifyJvmtiEnd(); // notify JVMTI
}
}
};
}
Expand Down Expand Up @@ -409,18 +408,14 @@ private void run(Runnable task) {
} catch (Throwable exc) {
dispatchUncaughtException(exc);
} finally {
try {
// pop any remaining scopes from the stack, this may block
StackableScope.popAll();

// emit JFR event if enabled
if (VirtualThreadEndEvent.isTurnedOn()) {
var event = new VirtualThreadEndEvent();
event.javaThreadId = threadId();
event.commit();
}
// pop any remaining scopes from the stack, this may block
StackableScope.popAll();

} finally {
// emit JFR event if enabled
if (VirtualThreadEndEvent.isTurnedOn()) {
var event = new VirtualThreadEndEvent();
event.javaThreadId = threadId();
event.commit();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* or ends virtual thread mount state transition (VTMS transition).
*
* @implNote
* This annotation is only used for VirtualThread methods.
* This annotation is only used for some VirtualThread and Continuation methods.
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
Expand Down

0 comments on commit f8d0515

Please sign in to comment.