From 8a6f5c0f7f917bb2012becafcd13338cdf46eaa4 Mon Sep 17 00:00:00 2001 From: Gengchen Tuo Date: Wed, 21 Jun 2023 16:26:30 -0400 Subject: [PATCH] Add a walk state flag to skip methods with the JvmtiMountTransition annotation Since it's only related to JVMTI, a walk state flag is added to enable the behaviour when doing JVMTI-related stack walk. Related: https://github.com/eclipse-openj9/openj9/issues/17490 Signed-off-by: Gengchen Tuo --- .../share/classes/jdk/internal/vm/Continuation.java | 2 ++ runtime/jvmti/jvmtiHelpers.c | 2 +- runtime/oti/j9.h | 2 ++ runtime/oti/j9consts.h | 1 + runtime/vm/swalk.c | 7 +++++++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/jcl/src/java.base/share/classes/jdk/internal/vm/Continuation.java b/jcl/src/java.base/share/classes/jdk/internal/vm/Continuation.java index b594f4368bc..0a0916d29f6 100644 --- a/jcl/src/java.base/share/classes/jdk/internal/vm/Continuation.java +++ b/jcl/src/java.base/share/classes/jdk/internal/vm/Continuation.java @@ -28,6 +28,7 @@ import jdk.internal.access.JavaLangAccess; import jdk.internal.access.SharedSecrets; import jdk.internal.misc.Unsafe; +import jdk.internal.vm.annotation.JvmtiMountTransition; /** * Continuation class performing the mount/unmount operation for VirtualThread @@ -277,6 +278,7 @@ public PreemptStatus tryPreempt(Thread t) { } /* Continuation Native APIs */ + @JvmtiMountTransition private native boolean enterImpl(); private static native boolean yieldImpl(boolean isFinished); diff --git a/runtime/jvmti/jvmtiHelpers.c b/runtime/jvmti/jvmtiHelpers.c index c26867e95ae..47ceb20b0be 100644 --- a/runtime/jvmti/jvmtiHelpers.c +++ b/runtime/jvmti/jvmtiHelpers.c @@ -1813,7 +1813,7 @@ UDATA findDecompileInfo(J9VMThread *currentThread, J9VMThread *targetThread, UDATA depth, J9StackWalkState *walkState) { walkState->walkThread = targetThread; - walkState->flags = J9_STACKWALK_ITERATE_FRAMES | J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_VISIBLE_ONLY | J9_STACKWALK_RECORD_BYTECODE_PC_OFFSET | J9_STACKWALK_MAINTAIN_REGISTER_MAP; + walkState->flags = J9_STACKWALK_ITERATE_FRAMES | J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_VISIBLE_ONLY | J9_STACKWALK_RECORD_BYTECODE_PC_OFFSET | J9_STACKWALK_MAINTAIN_REGISTER_MAP | J9_STACKWALK_SKIP_JVMTI_MOUNT_TRANSITION_FRAMES; walkState->skipCount = depth; walkState->userData1 = (void *)JVMTI_ERROR_NO_MORE_FRAMES; walkState->frameWalkFunction = findDecompileInfoFrameIterator; diff --git a/runtime/oti/j9.h b/runtime/oti/j9.h index 4f4959ce50b..c00f57ff4ab 100644 --- a/runtime/oti/j9.h +++ b/runtime/oti/j9.h @@ -374,6 +374,8 @@ static const struct { \ #define J9VM_VIRTUALTHREAD_ROOT_NODE_STATE ((I_32)0xBAADF00D) +#define J9_IS_JVMTI_MOUNT_TRANSITION(method) \ + ((NULL != (method)) && (J9_ARE_ANY_BITS_SET(getExtendedModifiersDataFromROMMethod(J9_ROM_METHOD_FROM_RAM_METHOD(method)), CFR_METHOD_EXT_JVMTIMOUNTTRANSITION_ANNOTATION))) #if defined(OPENJ9_BUILD) #define J9_SHARED_CACHE_DEFAULT_BOOT_SHARING(vm) TRUE #else /* defined(OPENJ9_BUILD) */ diff --git a/runtime/oti/j9consts.h b/runtime/oti/j9consts.h index 7f192a102d4..8b5d45b6635 100644 --- a/runtime/oti/j9consts.h +++ b/runtime/oti/j9consts.h @@ -401,6 +401,7 @@ extern "C" { #define J9_STACKWALK_CACHE_METHODS 0x400 #define J9_STACKWALK_CACHE_MASK 0x700 #define J9_STACKWALK_SKIP_HIDDEN_FRAMES 0x800 +#define J9_STACKWALK_SKIP_JVMTI_MOUNT_TRANSITION_FRAMES 0x1000 #define J9_STACKWALK_UNUSED_0x10000 0x10000 #define J9_STACKWALK_LINEAR 0x20000 #define J9_STACKWALK_VISIBLE_ONLY 0x40000 diff --git a/runtime/vm/swalk.c b/runtime/vm/swalk.c index a41008f073e..f1e08a64e42 100644 --- a/runtime/vm/swalk.c +++ b/runtime/vm/swalk.c @@ -481,6 +481,13 @@ UDATA walkFrame(J9StackWalkState * walkState) return J9_STACKWALK_KEEP_ITERATING; } + /* Skip methods with JvmtiMountTransition annotation */ + if (J9_ARE_ALL_BITS_SET(walkState->flags, J9_STACKWALK_SKIP_JVMTI_MOUNT_TRANSITION_FRAMES) + && J9_IS_JVMTI_MOUNT_TRANSITION(walkState->method) + ) { + return J9_STACKWALK_KEEP_ITERATING; + } + if (walkState->skipCount) { --walkState->skipCount; return J9_STACKWALK_KEEP_ITERATING;