Skip to content

Commit

Permalink
Support -XX:[+/-]ShowHiddenFrames option
Browse files Browse the repository at this point in the history
- Added new VM option for -XX:[+/-]ShowHiddenFrames
- Added new VM runtime flag J9_RUNTIME_SHOW_HIDDEN_FRAMES for new option
- Add J9_STACKWALK_SKIP_HIDDEN_FRAMES stack walk flag
- Add check to skip hidden frames during walkFrame() call
- Add new flag to all fillInStackTrace implementations
- Add check to getStackTraceForThread
- Update StackWalker to use new J9_STACKWALK_SKIP_HIDDEN_FRAMES flag

Signed-off-by: Jack Lu <Jack.S.Lu@ibm.com>
  • Loading branch information
fengxue-IS committed Jan 25, 2022
1 parent 8f57aa0 commit 18375dd
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 12 deletions.
6 changes: 5 additions & 1 deletion runtime/j9vm/j7vmi.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2021 IBM Corp. and others
* Copyright (c) 2002, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -441,6 +441,10 @@ JVM_FillInStackTrace(JNIEnv* env, jobject throwable)
flags |= J9_STACKWALK_HIDE_EXCEPTION_FRAMES;
walkState->restartException = unwrappedThrowable;
}
/* If -XX:+ShowHiddenFrames option has not been set, skip hidden method frames */
if (J9_ARE_NO_BITS_SET(javaVM->runtimeFlags, J9_RUNTIME_SHOW_HIDDEN_FRAMES)) {
flags |= J9_STACKWALK_SKIP_HIDDEN_FRAMES;
}
walkState->skipCount = 1; /* skip the INL frame -- TODO revisit this */
#if JAVA_SPEC_VERSION >= 15
{
Expand Down
6 changes: 5 additions & 1 deletion runtime/jcl/common/getstacktrace.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1998, 2017 IBM Corp. and others
* Copyright (c) 1998, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -49,6 +49,10 @@ getStackTraceForThread(J9VMThread *currentThread, J9VMThread *targetThread, UDAT
/* walk stack and cache PCs */
walkState.walkThread = targetThread;
walkState.flags = J9_STACKWALK_CACHE_PCS | J9_STACKWALK_WALK_TRANSLATE_PC | J9_STACKWALK_SKIP_INLINES | J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_VISIBLE_ONLY;
/* If -XX:+ShowHiddenFrames option has not been set, skip hidden method frames */
if (J9_ARE_NO_BITS_SET(vm->runtimeFlags, J9_RUNTIME_SHOW_HIDDEN_FRAMES)) {
walkState.flags |= J9_STACKWALK_SKIP_HIDDEN_FRAMES;
}
walkState.skipCount = skipCount;
rc = vm->walkStackFrames(currentThread, &walkState);

Expand Down
11 changes: 7 additions & 4 deletions runtime/jcl/common/java_lang_StackWalker.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2021 IBM Corp. and others
* Copyright (c) 2017, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -67,9 +67,6 @@ stackFrameFilter(J9VMThread * currentThread, J9StackWalkState * walkState)
) {
/* skip reflection/MethodHandleInvoke frames */
result = J9_STACKWALK_KEEP_ITERATING;
} else if (J9_ARE_NO_BITS_SET((UDATA) (walkState->userData1), SHOW_HIDDEN_FRAMES) && VM_VMHelpers::isHiddenMethod(walkState->method)
) {
result = J9_STACKWALK_KEEP_ITERATING;
} else {
result = J9_STACKWALK_STOP_ITERATING;
}
Expand All @@ -93,6 +90,12 @@ Java_java_lang_StackWalker_walkWrapperImpl(JNIEnv *env, jclass clazz, jint flags
walkState->walkThread = vmThread;
walkState->flags = J9_STACKWALK_ITERATE_FRAMES | J9_STACKWALK_WALK_TRANSLATE_PC
| J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_VISIBLE_ONLY;
/* If -XX:+ShowHiddenFrames and StackWalker.SHOW_HIDDEN_FRAMES option has not been set, skip hidden method frames */
if (J9_ARE_NO_BITS_SET(vm->runtimeFlags, J9_RUNTIME_SHOW_HIDDEN_FRAMES)
&& J9_ARE_NO_BITS_SET((UDATA)flags, SHOW_HIDDEN_FRAMES)
) {
walkState->flags |= J9_STACKWALK_SKIP_HIDDEN_FRAMES;
}
walkState->frameWalkFunction = stackFrameFilter;
const char * walkerMethodChars = env->GetStringUTFChars(stackWalkerMethod, NULL);
if (NULL == walkerMethodChars) { /* native out of memory exception pending */
Expand Down
5 changes: 3 additions & 2 deletions runtime/oti/j9consts.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2021 IBM Corp. and others
* Copyright (c) 1991, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -291,7 +291,7 @@ extern "C" {
#define J9_RUNTIME_EXIT_STARTED 0x800000
#define J9_RUNTIME_UNUSED_0x1000000 0x1000000
#define J9_RUNTIME_NO_PRIORITIES 0x2000000
#define J9_RUNTIME_UNUSED_0x4000000 0x4000000
#define J9_RUNTIME_SHOW_HIDDEN_FRAMES 0x4000000
#define J9_RUNTIME_DISABLE_VM_SHUTDOWN 0x8000000
#define J9_RUNTIME_ALWAYS_SPLIT_BYTECODES 0x10000000
#define J9_RUNTIME_OMIT_STACK_TRACES 0x20000000
Expand Down Expand Up @@ -391,6 +391,7 @@ extern "C" {
#define J9_STACKWALK_CACHE_CPS 0x200
#define J9_STACKWALK_CACHE_METHODS 0x400
#define J9_STACKWALK_CACHE_MASK 0x700
#define J9_STACKWALK_SKIP_HIDDEN_FRAMES 0x800
#define J9_STACKWALK_INCLUDE_ARRAYLET_LEAVES 0x10000
#define J9_STACKWALK_LINEAR 0x20000
#define J9_STACKWALK_VISIBLE_ONLY 0x40000
Expand Down
4 changes: 3 additions & 1 deletion runtime/oti/jvminit.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2021 IBM Corp. and others
* Copyright (c) 1991, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -313,6 +313,8 @@ enum INIT_STAGE {
#define VMOPT_X142BOOSTGCTHRPRIO "-X142BoostGCThrPrio"
#define VMOPT_XREALTIME "-Xrealtime"
#define VMOPT_XNORTSJ "-Xnortsj"
#define VMOPT_XXNOSHOWHIDDENFRAMES "-XX:-ShowHiddenFrames"
#define VMOPT_XXSHOWHIDDENFRAMES "-XX:+ShowHiddenFrames"
#define VMOPT_XXNOSTACKTRACEINTHROWABLE "-XX:-StackTraceInThrowable"
#define VMOPT_XXSTACKTRACEINTHROWABLE "-XX:+StackTraceInThrowable"
#define VMOPT_XXNOPAGEALIGNDIRECTMEMORY "-XX:-PageAlignDirectMemory"
Expand Down
4 changes: 4 additions & 0 deletions runtime/vm/BytecodeInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3025,6 +3025,10 @@ class INTERPRETER_CLASS
walkFlags |= J9_STACKWALK_HIDE_EXCEPTION_FRAMES;
walkState->restartException = receiver;
}
/* If -XX:+ShowHiddenFrames option has not been set, skip hidden method frames */
if (J9_ARE_NO_BITS_SET(_vm->runtimeFlags, J9_RUNTIME_SHOW_HIDDEN_FRAMES)) {
walkFlags |= J9_STACKWALK_SKIP_HIDDEN_FRAMES;
}
walkState->flags = walkFlags;
walkState->skipCount = 1; /* skip the INL frame */
#if JAVA_SPEC_VERSION >= 15
Expand Down
6 changes: 5 additions & 1 deletion runtime/vm/FastJNI_java_lang_Throwable.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2001, 2020 IBM Corp. and others
* Copyright (c) 2001, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -57,6 +57,10 @@ Fast_java_lang_Throwable_fillInStackTrace(J9VMThread *currentThread, j9object_t
walkFlags |= J9_STACKWALK_HIDE_EXCEPTION_FRAMES;
walkState->restartException = receiver;
}
/* If -XX:+ShowHiddenFrames option has not been set, skip hidden method frames */
if (J9_ARE_NO_BITS_SET(vm->runtimeFlags, J9_RUNTIME_SHOW_HIDDEN_FRAMES)) {
walkFlags |= J9_STACKWALK_SKIP_HIDDEN_FRAMES;
}
walkState->flags = walkFlags;
walkState->skipCount = 1; /* skip the INL frame */
#if JAVA_SPEC_VERSION >= 15
Expand Down
10 changes: 9 additions & 1 deletion runtime/vm/jvminit.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2021 IBM Corp. and others
* Copyright (c) 1991, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -3787,6 +3787,14 @@ processVMArgsFromFirstToLast(J9JavaVM * vm)
}
#endif /* JAVA_SPEC_VERSION >= 18 */

{
IDATA showHiddenFrames = FIND_AND_CONSUME_ARG(EXACT_MATCH, VMOPT_XXSHOWHIDDENFRAMES, NULL);
IDATA noshowHiddenFrames = FIND_AND_CONSUME_ARG(EXACT_MATCH, VMOPT_XXNOSHOWHIDDENFRAMES, NULL);
if (showHiddenFrames > noshowHiddenFrames) {
vm->runtimeFlags |= J9_RUNTIME_SHOW_HIDDEN_FRAMES;
}
}

return JNI_OK;
}

Expand Down
12 changes: 11 additions & 1 deletion runtime/vm/swalk.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2021 IBM Corp. and others
* Copyright (c) 1991, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -164,6 +164,7 @@ UDATA walkStackFrames(J9VMThread *currentThread, J9StackWalkState *walkState)
if (walkState->flags & J9_STACKWALK_START_AT_JIT_FRAME) swPrintf(walkState, 2, "\tSTART_AT_JIT_FRAME\n");
if (walkState->flags & J9_STACKWALK_CACHE_CPS) swPrintf(walkState, 2, "\tCACHE_CPS\n");
if (walkState->flags & J9_STACKWALK_CACHE_PCS) swPrintf(walkState, 2, "\tCACHE_PCS\n");
if (walkState->flags & J9_STACKWALK_SKIP_HIDDEN_FRAMES) swPrintf(walkState, 2, "\tSKIP_HIDDEN_FRAME\n");
if (walkState->flags & J9_STACKWALK_COUNT_SPECIFIED) swPrintf(walkState, 2, "\tCOUNT_SPECIFIED\n");
if (walkState->flags & J9_STACKWALK_INCLUDE_ARRAYLET_LEAVES) swPrintf(walkState, 2, "\tINCLUDE_ARRAYLET_LEAVES\n");
if (walkState->flags & J9_STACKWALK_INCLUDE_NATIVES) swPrintf(walkState, 2, "\tINCLUDE_NATIVES\n");
Expand Down Expand Up @@ -423,6 +424,15 @@ UDATA walkFrame(J9StackWalkState * walkState)
}
#endif

/* Process hidden method frames */
if (J9_ARE_ALL_BITS_SET(walkState->flags, J9_STACKWALK_SKIP_HIDDEN_FRAMES)
&& (NULL != walkState->method)
&& (J9ROMCLASS_IS_ANON_OR_HIDDEN(J9_CLASS_FROM_METHOD(walkState->method)->romClass)
|| J9_ARE_ANY_BITS_SET(J9_ROM_METHOD_FROM_RAM_METHOD(walkState->method)->modifiers, J9AccMethodFrameIteratorSkip)
)) {
return J9_STACKWALK_KEEP_ITERATING;
}

if (walkState->skipCount) {
--walkState->skipCount;
return J9_STACKWALK_KEEP_ITERATING;
Expand Down

0 comments on commit 18375dd

Please sign in to comment.