Skip to content

Commit 63f95d2

Browse files
authored
Merge pull request eclipse-openj9#18016 from babsingh/skip_JvmtiMountTransition
Skip methods with JvmtiMountTransition annotation
2 parents 87d042a + 7e12846 commit 63f95d2

File tree

4 files changed

+147
-56
lines changed

4 files changed

+147
-56
lines changed

runtime/jvmti/jvmtiExtensionMechanism.c

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,89 +1864,107 @@ jvmtiInternalGetStackTraceExtended(jvmtiEnv* env,
18641864

18651865

18661866
static UDATA
1867-
jvmtiInternalGetStackTraceIteratorExtended(J9VMThread * currentThread, J9StackWalkState * walkState)
1867+
jvmtiInternalGetStackTraceIteratorExtended(J9VMThread *currentThread, J9StackWalkState *walkState)
18681868
{
1869-
J9JVMTIStackTraceType type;
1870-
jmethodID methodID;
1871-
jvmtiFrameInfoExtended * frame_buffer;
1872-
UDATA frameCount;
1869+
jmethodID methodID = NULL;
1870+
jvmtiFrameInfoExtended *frame_buffer = NULL;
1871+
UDATA frameCount = 0;
1872+
J9JVMTIStackTraceType type = (J9JVMTIStackTraceType)(UDATA)walkState->userData2;
1873+
J9Method *method = walkState->method;
18731874

1874-
/* In extra info mode when method enter is enabled, exclude natives which have not had method enter reported for them */
1875+
#if JAVA_SPEC_VERSION >= 20
1876+
J9ROMMethod *romMethod = NULL;
1877+
U_32 extendedModifiers = 0;
18751878

1876-
type = (J9JVMTIStackTraceType) (UDATA) walkState->userData2;
1877-
if (type & J9JVMTI_STACK_TRACE_PRUNE_UNREPORTED_METHODS) {
1878-
if ((UDATA)walkState->pc == J9SF_FRAME_TYPE_NATIVE_METHOD) {
1879-
/* INL natives never have enter/exit reported */
1879+
/* walkState->method can never be NULL since the J9_STACKWALK_VISIBLE_ONLY flag is set. */
1880+
Assert_JVMTI_true(NULL != method);
1881+
1882+
romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
1883+
extendedModifiers = getExtendedModifiersDataFromROMMethod(romMethod);
1884+
1885+
if (J9_ARE_ANY_BITS_SET(extendedModifiers, CFR_METHOD_EXT_JVMTIMOUNTTRANSITION_ANNOTATION)) {
1886+
goto skip;
1887+
}
1888+
#endif /* JAVA_SPEC_VERSION >= 20 */
1889+
1890+
/* In extra info mode when method enter is enabled, exclude natives which have not had method enter reported for them. */
1891+
if (J9_ARE_ANY_BITS_SET(type, J9JVMTI_STACK_TRACE_PRUNE_UNREPORTED_METHODS)) {
1892+
if (J9SF_FRAME_TYPE_NATIVE_METHOD == (UDATA)walkState->pc) {
1893+
/* INL natives never have enter/exit reported. */
18801894
return J9_STACKWALK_KEEP_ITERATING;
18811895
}
18821896
#if defined(J9VM_INTERP_NATIVE_SUPPORT)
1883-
if ((UDATA)walkState->pc == J9SF_FRAME_TYPE_JNI_NATIVE_METHOD) {
1884-
if (walkState->frameFlags & J9_STACK_FLAGS_JIT_JNI_CALL_OUT_FRAME) {
1885-
/* Direct JNI inlined into JIT method */
1897+
if (J9SF_FRAME_TYPE_JNI_NATIVE_METHOD == (UDATA)walkState->pc) {
1898+
if (J9_ARE_ANY_BITS_SET(walkState->frameFlags, J9_STACK_FLAGS_JIT_JNI_CALL_OUT_FRAME)) {
1899+
/* Direct JNI inlined into JIT method. */
18861900
return J9_STACKWALK_KEEP_ITERATING;
18871901
}
18881902
}
1889-
/* Direct JNI thunks (method is native, jitInfo != NULL) do have enter/exit reported */
1890-
#endif
1903+
/* Direct JNI thunks (method is native, jitInfo != NULL) do have enter/exit reported. */
1904+
#endif /* defined(J9VM_INTERP_NATIVE_SUPPORT) */
18911905
}
18921906

18931907
frame_buffer = walkState->userData1;
1894-
if (frame_buffer != NULL) {
1895-
methodID = getCurrentMethodID(currentThread, walkState->method);
1896-
if (methodID == NULL) {
1908+
if (NULL != frame_buffer) {
1909+
methodID = getCurrentMethodID(currentThread, method);
1910+
if (NULL == methodID) {
18971911
walkState->userData1 = NULL;
18981912
return J9_STACKWALK_STOP_ITERATING;
18991913
}
19001914

19011915
frame_buffer->method = methodID;
19021916

1903-
if (type & J9JVMTI_STACK_TRACE_EXTRA_FRAME_INFO) {
1904-
/* Fill in the extended data */
1905-
#ifdef J9VM_INTERP_NATIVE_SUPPORT
1906-
if (walkState->jitInfo == NULL) {
1917+
if (J9_ARE_ANY_BITS_SET(type, J9JVMTI_STACK_TRACE_EXTRA_FRAME_INFO)) {
1918+
/* Fill in the extended data. */
1919+
#if defined(J9VM_INTERP_NATIVE_SUPPORT)
1920+
if (NULL == walkState->jitInfo) {
19071921
frame_buffer->type = COM_IBM_STACK_FRAME_EXTENDED_NOT_JITTED;
19081922
} else if (J9_ARE_ANY_BITS_SET(type, J9JVMTI_STACK_TRACE_MARK_INLINED_FRAMES) && (walkState->inlineDepth > 0)) {
19091923
frame_buffer->type = COM_IBM_STACK_FRAME_EXTENDED_INLINED;
19101924
} else {
19111925
frame_buffer->type = COM_IBM_STACK_FRAME_EXTENDED_JITTED;
19121926
}
1913-
#else
1927+
#else /* defined(J9VM_INTERP_NATIVE_SUPPORT) */
19141928
frame_buffer->type = COM_IBM_STACK_FRAME_EXTENDED_NOT_JITTED;
1915-
#endif
1929+
#endif /* defined(J9VM_INTERP_NATIVE_SUPPORT) */
19161930
frame_buffer->machinepc = -1; /* not supported yet */
1917-
}
1931+
}
19181932

1919-
if (type & J9JVMTI_STACK_TRACE_ENTRY_LOCAL_STORAGE) {
1920-
#ifdef J9VM_INTERP_NATIVE_SUPPORT
1921-
if ((jlocation) walkState->bytecodePCOffset == -1) {
1922-
frame_buffer->nativeFrameAddress = (void *) walkState->walkedEntryLocalStorage;
1933+
if (J9_ARE_ANY_BITS_SET(type, J9JVMTI_STACK_TRACE_ENTRY_LOCAL_STORAGE)) {
1934+
#if defined(J9VM_INTERP_NATIVE_SUPPORT)
1935+
if (-1 == (jlocation)walkState->bytecodePCOffset) {
1936+
frame_buffer->nativeFrameAddress = (void *)walkState->walkedEntryLocalStorage;
19231937
} else {
19241938
frame_buffer->nativeFrameAddress = NULL;
19251939
}
1926-
#else
1940+
#else /* defined(J9VM_INTERP_NATIVE_SUPPORT) */
19271941
frame_buffer->nativeFrameAddress = NULL;
1928-
#endif
1942+
#endif /* defined(J9VM_INTERP_NATIVE_SUPPORT) */
19291943
}
19301944

1931-
/* The location = -1 for native method case is handled in the stack walker */
1932-
frame_buffer->location = (jlocation) walkState->bytecodePCOffset;
1945+
/* The location = -1 for native method case is handled in the stack walker. */
1946+
frame_buffer->location = (jlocation)walkState->bytecodePCOffset;
19331947

1934-
/* If the location specifies a JBinvokeinterface, back it up to the JBinvokeinterface2 */
1948+
/* If the location specifies a JBinvokeinterface, back it up to the JBinvokeinterface2. */
19351949
if (!IS_SPECIAL_FRAME_PC(walkState->pc)) {
1936-
if (*(walkState->pc) == JBinvokeinterface) {
1950+
if (JBinvokeinterface == *(walkState->pc)) {
19371951
frame_buffer->location -= 2;
19381952
}
19391953
}
19401954

19411955
walkState->userData1 = frame_buffer + 1;
19421956
}
19431957

1944-
frameCount = (UDATA) walkState->userData3;
1958+
frameCount = (UDATA)walkState->userData3;
19451959
++frameCount;
1946-
walkState->userData3 = (void *) frameCount;
1947-
if (frameCount == (UDATA) walkState->userData4) {
1960+
walkState->userData3 = (void *)frameCount;
1961+
if (frameCount == (UDATA)walkState->userData4) {
19481962
return J9_STACKWALK_STOP_ITERATING;
19491963
}
1964+
1965+
#if JAVA_SPEC_VERSION >= 20
1966+
skip:
1967+
#endif /* JAVA_SPEC_VERSION >= 20 */
19501968
return J9_STACKWALK_KEEP_ITERATING;
19511969
}
19521970

runtime/jvmti/jvmtiHelpers.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,30 @@ jvmtiTLSGet(J9VMThread *vmThread, j9object_t thread, UDATA key)
19741974
#endif /* JAVA_SPEC_VERSION >= 19 */
19751975
}
19761976

1977+
#if JAVA_SPEC_VERSION >= 20
1978+
UDATA
1979+
genericFrameIterator(J9VMThread *currentThread, J9StackWalkState *walkState)
1980+
{
1981+
J9Method *method = walkState->method;
1982+
J9ROMMethod *romMethod = NULL;
1983+
U_32 extendedModifiers = 0;
1984+
1985+
/* walkState->method can never be NULL since the J9_STACKWALK_VISIBLE_ONLY flag is set. */
1986+
Assert_JVMTI_true(NULL != method);
1987+
1988+
romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
1989+
extendedModifiers = getExtendedModifiersDataFromROMMethod(romMethod);
1990+
1991+
if (J9_ARE_ANY_BITS_SET(extendedModifiers, CFR_METHOD_EXT_JVMTIMOUNTTRANSITION_ANNOTATION)) {
1992+
/* The number of frames skipped is stored in userData1. */
1993+
UDATA framesSkipped = (UDATA)walkState->userData1;
1994+
walkState->userData1 = (void *)(framesSkipped + 1);
1995+
}
1996+
1997+
return J9_STACKWALK_KEEP_ITERATING;
1998+
}
1999+
#endif /* JAVA_SPEC_VERSION >= 20 */
2000+
19772001
UDATA
19782002
genericWalkStackFramesHelper(J9VMThread *currentThread, J9VMThread *targetThread, j9object_t threadObject, J9StackWalkState *walkState)
19792003
{

runtime/jvmti/jvmtiStackFrame.c

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ jvmtiGetFrameCount(jvmtiEnv* env,
383383
J9StackWalkState walkState;
384384
walkState.flags = J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_VISIBLE_ONLY;
385385
walkState.skipCount = 0;
386+
/* The number of frames skipped is stored in userData1. */
387+
walkState.userData1 = (void *)0;
388+
#if JAVA_SPEC_VERSION >= 20
389+
walkState.frameWalkFunction = genericFrameIterator;
390+
#endif /* JAVA_SPEC_VERSION >= 20 */
386391

387392
#if JAVA_SPEC_VERSION >= 19
388393
if (NULL != targetThread)
@@ -398,7 +403,7 @@ jvmtiGetFrameCount(jvmtiEnv* env,
398403
vmFuncs->resumeThreadForInspection(currentThread, targetThread);
399404
}
400405

401-
rv_count = (jint) walkState.framesWalked;
406+
rv_count = (jint)(walkState.framesWalked - (UDATA)walkState.userData1);
402407

403408
releaseVMThread(currentThread, targetThread, thread);
404409
}
@@ -683,32 +688,56 @@ jvmtiNotifyFramePop(jvmtiEnv *env,
683688

684689

685690
static UDATA
686-
jvmtiInternalGetStackTraceIterator(J9VMThread * currentThread, J9StackWalkState * walkState)
691+
jvmtiInternalGetStackTraceIterator(J9VMThread *currentThread, J9StackWalkState *walkState)
687692
{
688-
jmethodID methodID;
693+
jmethodID methodID = NULL;
694+
UDATA rc = J9_STACKWALK_KEEP_ITERATING;
695+
J9Method *method = walkState->method;
696+
697+
#if JAVA_SPEC_VERSION >= 20
698+
J9ROMMethod *romMethod = NULL;
699+
U_32 extendedModifiers = 0;
700+
701+
/* walkState->method can never be NULL since the J9_STACKWALK_VISIBLE_ONLY flag is set. */
702+
Assert_JVMTI_true(NULL != method);
703+
704+
romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
705+
extendedModifiers = getExtendedModifiersDataFromROMMethod(romMethod);
706+
707+
if (J9_ARE_ANY_BITS_SET(extendedModifiers, CFR_METHOD_EXT_JVMTIMOUNTTRANSITION_ANNOTATION)) {
708+
/* The number of frames skipped is stored in userData2. */
709+
UDATA framesSkipped = (UDATA)walkState->userData2;
710+
walkState->userData2 = (void *)(framesSkipped + 1);
711+
goto skip;
712+
}
713+
#endif /* JAVA_SPEC_VERSION >= 20 */
689714

690-
methodID = getCurrentMethodID(currentThread, walkState->method);
691-
if (methodID == NULL) {
715+
methodID = getCurrentMethodID(currentThread, method);
716+
if (NULL == methodID) {
692717
walkState->userData1 = NULL;
693-
return J9_STACKWALK_STOP_ITERATING;
718+
rc = J9_STACKWALK_STOP_ITERATING;
694719
} else {
695-
jvmtiFrameInfo * frame_buffer = walkState->userData1;
720+
jvmtiFrameInfo *frame_buffer = walkState->userData1;
696721

697722
frame_buffer->method = methodID;
698-
/* The location = -1 for native method case is handled in the stack walker */
699-
frame_buffer->location = (jlocation) walkState->bytecodePCOffset;
723+
/* The location = -1 for native method case is handled in the stack walker. */
724+
frame_buffer->location = (jlocation)walkState->bytecodePCOffset;
700725

701-
/* If the location specifies a JBinvokeinterface, back it up to the JBinvokeinterface2 */
726+
/* If the location specifies a JBinvokeinterface, back it up to the JBinvokeinterface2. */
702727

703728
if (!IS_SPECIAL_FRAME_PC(walkState->pc)) {
704-
if (*(walkState->pc) == JBinvokeinterface) {
729+
if (JBinvokeinterface == *(walkState->pc)) {
705730
frame_buffer->location -= 2;
706731
}
707732
}
708733

709734
walkState->userData1 = frame_buffer + 1;
710-
return J9_STACKWALK_KEEP_ITERATING;
711735
}
736+
737+
#if JAVA_SPEC_VERSION >= 20
738+
skip:
739+
#endif /* JAVA_SPEC_VERSION >= 20 */
740+
return rc;
712741
}
713742

714743

@@ -780,36 +809,45 @@ jvmtiInternalGetStackTrace(
780809
jint *count_ptr)
781810
{
782811
J9StackWalkState walkState = {0};
783-
812+
UDATA framesWalked = 0;
784813
walkState.flags = J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_VISIBLE_ONLY;
785814
walkState.skipCount = 0;
786-
815+
/* The number of frames skipped is stored in userData1. */
816+
walkState.userData1 = (void *)0;
817+
#if JAVA_SPEC_VERSION >= 20
818+
walkState.frameWalkFunction = genericFrameIterator;
819+
#endif /* JAVA_SPEC_VERSION >= 20 */
787820
genericWalkStackFramesHelper(currentThread, targetThread, threadObject, &walkState);
821+
framesWalked = walkState.framesWalked - (UDATA)walkState.userData1;
788822
if (start_depth == 0) {
789823
/* This violates the spec, but matches JDK behaviour - allows querying an empty stack with start_depth == 0 */
790824
walkState.skipCount = 0;
791825
} else if (start_depth > 0) {
792-
if (((UDATA) start_depth) >= walkState.framesWalked) {
826+
if (((UDATA)start_depth) >= framesWalked) {
793827
return JVMTI_ERROR_ILLEGAL_ARGUMENT;
794828
}
795829
walkState.skipCount = (UDATA) start_depth;
796830
} else {
797-
if (((UDATA) -start_depth) > walkState.framesWalked) {
831+
if (((UDATA)-start_depth) > framesWalked) {
798832
return JVMTI_ERROR_ILLEGAL_ARGUMENT;
799833
}
800-
walkState.skipCount = walkState.framesWalked + start_depth;
834+
walkState.skipCount = framesWalked + start_depth;
801835
}
802836
walkState.maxFrames = max_frame_count;
803837
walkState.flags = J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_VISIBLE_ONLY
804838
| J9_STACKWALK_RECORD_BYTECODE_PC_OFFSET | J9_STACKWALK_COUNT_SPECIFIED
805839
| J9_STACKWALK_ITERATE_FRAMES;
806840
walkState.userData1 = frame_buffer;
841+
/* The number of frames skipped is stored in userData2. */
842+
walkState.userData2 = (void *)0;
807843
walkState.frameWalkFunction = jvmtiInternalGetStackTraceIterator;
808844

809845
genericWalkStackFramesHelper(currentThread, targetThread, threadObject, &walkState);
846+
framesWalked = walkState.framesWalked - (UDATA)walkState.userData2;
847+
810848
if (NULL == walkState.userData1) {
811849
return JVMTI_ERROR_OUT_OF_MEMORY;
812850
}
813-
*count_ptr = (jint) walkState.framesWalked;
851+
*count_ptr = (jint)framesWalked;
814852
return JVMTI_ERROR_NONE;
815853
}

runtime/jvmti/jvmti_internal.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,17 @@ suspendAgentBreakpoint(J9VMThread * currentThread, J9JVMTIAgentBreakpoint * agen
13521352
UDATA
13531353
findDecompileInfo(J9VMThread *currentThread, J9VMThread *targetThread, UDATA depth, J9StackWalkState *walkState);
13541354

1355+
#if JAVA_SPEC_VERSION >= 20
1356+
/**
1357+
* A helper to iterate through the frames of a thread.
1358+
* @param[in] currentThread current thread
1359+
* @param[in] walkState a stack walk state
1360+
* @return 0 on success and non-zero on failure
1361+
*/
1362+
UDATA
1363+
genericFrameIterator(J9VMThread *currentThread, J9StackWalkState *walkState);
1364+
#endif /* JAVA_SPEC_VERSION >= 20 */
1365+
13551366
/**
13561367
* A helper to walk a platform thread or virtual thread
13571368
* @param[in] currentThread current thread

0 commit comments

Comments
 (0)