8341273: JVMTI is not properly hiding some continuation related methods

Reviewed-by: alanb, amenkov
This commit is contained in:
Serguei Spitsyn 2024-10-29 19:59:43 +00:00
parent 520ddac970
commit 60364ef001
15 changed files with 316 additions and 79 deletions

View file

@ -56,6 +56,7 @@ import jdk.internal.vm.ThreadContainers;
import jdk.internal.vm.annotation.ChangesCurrentThread;
import jdk.internal.vm.annotation.Hidden;
import jdk.internal.vm.annotation.IntrinsicCandidate;
import jdk.internal.vm.annotation.JvmtiHideEvents;
import jdk.internal.vm.annotation.JvmtiMountTransition;
import jdk.internal.vm.annotation.ReservedStackAccess;
import sun.nio.ch.Interruptible;
@ -213,8 +214,14 @@ final class VirtualThread extends BaseVirtualThread {
private static Runnable wrap(VirtualThread vthread, Runnable task) {
return new Runnable() {
@Hidden
@JvmtiHideEvents
public void run() {
vthread.run(task);
vthread.notifyJvmtiStart(); // notify JVMTI
try {
vthread.run(task);
} finally {
vthread.notifyJvmtiEnd(); // notify JVMTI
}
}
};
}
@ -389,9 +396,6 @@ final class VirtualThread extends BaseVirtualThread {
private void run(Runnable task) {
assert Thread.currentThread() == this && state == RUNNING;
// notify JVMTI, may post VirtualThreadStart event
notifyJvmtiStart();
// emit JFR event if enabled
if (VirtualThreadStartEvent.isTurnedOn()) {
var event = new VirtualThreadStartEvent();
@ -405,20 +409,14 @@ final class VirtualThread extends BaseVirtualThread {
} catch (Throwable exc) {
dispatchUncaughtException(exc);
} finally {
try {
// pop any remaining scopes from the stack, this may block
StackableScope.popAll();
// 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();
}
} finally {
// notify JVMTI, may post VirtualThreadEnd event
notifyJvmtiEnd();
// emit JFR event if enabled
if (VirtualThreadEndEvent.isTurnedOn()) {
var event = new VirtualThreadEndEvent();
event.javaThreadId = threadId();
event.commit();
}
}
}

View file

@ -36,6 +36,7 @@ import java.util.function.Supplier;
import jdk.internal.access.JavaLangAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.vm.annotation.Hidden;
import jdk.internal.vm.annotation.JvmtiHideEvents;
/**
* A one-shot delimited continuation.
@ -305,6 +306,7 @@ public class Continuation {
@Hidden
@DontInline
@IntrinsicCandidate
@JvmtiHideEvents
private static void enter(Continuation c, boolean isContinue) {
// This method runs in the "entry frame".
// A yield jumps to this method's caller as if returning from this method.
@ -316,6 +318,7 @@ public class Continuation {
}
@Hidden
@JvmtiHideEvents
private void enter0() {
target.run();
}
@ -340,6 +343,7 @@ public class Continuation {
* @throws IllegalStateException if not currently in the given {@code scope},
*/
@Hidden
@JvmtiHideEvents
public static boolean yield(ContinuationScope scope) {
Continuation cont = JLA.getContinuation(currentCarrierThread());
Continuation c;
@ -352,6 +356,7 @@ public class Continuation {
}
@Hidden
@JvmtiHideEvents
private boolean yield0(ContinuationScope scope, Continuation child) {
preempted = false;

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.internal.vm.annotation;
import java.lang.annotation.*;
/**
* A method may be annotated with JvmtiHideEvents to hint that JVMTI events
* should not be generated in context of the annotated method.
*
* @implNote
* This annotation is only used for some VirtualThread and Continuation methods.
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface JvmtiHideEvents {
}

View file

@ -28,8 +28,11 @@ package jdk.internal.vm.annotation;
import java.lang.annotation.*;
/**
* A method is annotated as "jvmti mount transition" if it starts
* or ends virtual thread mount state transition (VTMS transition).
* A method may be annotated with JvmtiMountTransition to hint
* it is desirable to omit it from JVMTI stack traces.
* Normally, a method is annotated with @JvmtiMountTransition if it starts
* or ends Virtual Thread Mount State (VTMS) transition, so the thread
* identity is undefined or different at method entry and exit.
*
* @implNote
* This annotation is only used for VirtualThread methods.