Skip to content

Commit

Permalink
Merge pull request #20609 from tajila/jfr3
Browse files Browse the repository at this point in the history
Add frametype info to iterateStackTrace callback
  • Loading branch information
gacholio authored Nov 16, 2024
2 parents 7d1ffb0 + 854931a commit efaa4f6
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 118 deletions.
28 changes: 14 additions & 14 deletions runtime/j9vm/j7vmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,16 +500,16 @@ JVM_FillInStackTrace(JNIEnv* env, jobject throwable)
}

/**
* Find the specified class in given class loader
* Find the specified class in given class loader
*
* @param env
* @param className null-terminated class name string.
* @param init initialize the class when set
* @param classLoader classloader of the class
* @param classLoader classloader of the class
* @param throwError set to true in order to throw errors
* @return Assumed to be a jclass.
*
* Note: this call is implemented from info provided via CMVC 154874.
* Note: this call is implemented from info provided via CMVC 154874.
*/
jobject JNICALL
JVM_FindClassFromClassLoader(JNIEnv* env, char* className, jboolean init, jobject classLoader, jboolean throwError)
Expand Down Expand Up @@ -1425,7 +1425,7 @@ typedef struct GetStackTraceElementUserData {

/* Return TRUE to keep iterating, FALSE to halt the walk. */
static UDATA
getStackTraceElementIterator(J9VMThread * vmThread, void * voidUserData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass)
getStackTraceElementIterator(J9VMThread * vmThread, void * voidUserData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass, UDATA frameType)
{
GetStackTraceElementUserData * userData = voidUserData;

Expand Down Expand Up @@ -1784,33 +1784,33 @@ JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, NULL);
} else {
j9object_t componentTypeClassObject = J9_JNI_UNWRAP_REFERENCE(eltClass);

if (NULL != componentTypeClassObject) {
J9Class *componentTypeClass = J9VM_J9CLASS_FROM_HEAPCLASS(currentThread, componentTypeClassObject);

/* create an array class with the desired arity */
UDATA count = dimensions;
J9Class *componentArrayClass = componentTypeClass;
BOOLEAN exceptionIsPending = FALSE;

while ((count > 0) && (!exceptionIsPending)) {
componentArrayClass = fetchArrayClass(currentThread, componentArrayClass);
exceptionIsPending = (NULL != currentThread->currentException);
count -= 1;
}

if (!exceptionIsPending) {
/* make a copy of the dimensions array in non-object memory */
I_32 onStackDimensions[MAX_DIMENSIONS];
j9object_t directObject = NULL;
UDATA i = 0;

memset(onStackDimensions, 0, sizeof(onStackDimensions));
dimensionsArrayObject = J9_JNI_UNWRAP_REFERENCE(dim);
for (i = 0; i < dimensions; i++) {
onStackDimensions[i] = J9JAVAARRAYOFINT_LOAD(currentThread, dimensionsArrayObject, i);
}

directObject = vmFuncs->helperMultiANewArray(currentThread, (J9ArrayClass *)componentArrayClass, (UDATA)dimensions, onStackDimensions, J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);
if (NULL != directObject) {
result = vmFuncs->j9jni_createLocalRef(env, directObject);
Expand Down Expand Up @@ -2435,11 +2435,11 @@ JVM_GetHostName(char* name, int namelen)
* sun.jvm.args =
*/
/*
* Notes:
* Redirector has an implementation of JVM_InitAgentProperties.
* This method is still kept within the actual jvm dll in case that a launcher uses this jvm dll directly without going through the redirector.
* If this method need to be modified, the changes have to be synchronized for both versions.
*/
* Notes:
* Redirector has an implementation of JVM_InitAgentProperties.
* This method is still kept within the actual jvm dll in case that a launcher uses this jvm dll directly without going through the redirector.
* If this method need to be modified, the changes have to be synchronized for both versions.
*/
jobject JNICALL
JVM_InitAgentProperties(JNIEnv *env, jobject agent_props)
{
Expand Down
2 changes: 1 addition & 1 deletion runtime/j9vm/javanextvmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ typedef struct GetStackTraceElementUserData {
} GetStackTraceElementUserData;

static UDATA
getStackTraceElementIterator(J9VMThread *vmThread, void *voidUserData, UDATA bytecodeOffset, J9ROMClass *romClass, J9ROMMethod *romMethod, J9UTF8 *fileName, UDATA lineNumber, J9ClassLoader *classLoader, J9Class* ramClass)
getStackTraceElementIterator(J9VMThread *vmThread, void *voidUserData, UDATA bytecodeOffset, J9ROMClass *romClass, J9ROMMethod *romMethod, J9UTF8 *fileName, UDATA lineNumber, J9ClassLoader *classLoader, J9Class* ramClass, UDATA frameType)
{
UDATA result = J9_STACKWALK_STOP_ITERATING;

Expand Down
8 changes: 4 additions & 4 deletions runtime/jcl/common/jclexception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extern "C" {
static void setStackTraceElementFields(J9VMThread *vmThread, j9object_t element, J9ClassLoader *classLoader);
#endif /* JAVA_SPEC_VERSION >= 11 */

static UDATA getStackTraceIterator(J9VMThread * vmThread, void * voidUserData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass);
static UDATA getStackTraceIterator(J9VMThread * vmThread, void * voidUserData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass, UDATA frameType);

/**
* Saves enough context into the StackTraceElement to allow printing later. For
Expand Down Expand Up @@ -91,7 +91,7 @@ setStackTraceElementSource(J9VMThread* vmThread, j9object_t stackTraceElement, J


static UDATA
getStackTraceIterator(J9VMThread * vmThread, void * voidUserData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass)
getStackTraceIterator(J9VMThread * vmThread, void * voidUserData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass, UDATA frameType)
{
J9GetStackTraceUserData *userData = (J9GetStackTraceUserData*)voidUserData;
J9JavaVM * vm = vmThread->javaVM;
Expand Down Expand Up @@ -301,7 +301,7 @@ getStackTraceIterator(J9VMThread * vmThread, void * voidUserData, UDATA bytecode
return rc;
}

J9IndexableObject *
J9IndexableObject *
getStackTrace(J9VMThread * vmThread, j9object_t * exceptionAddr, UDATA pruneConstructors)
{
J9JavaVM * vm = vmThread->javaVM;
Expand Down Expand Up @@ -332,7 +332,7 @@ getStackTrace(J9VMThread * vmThread, j9object_t * exceptionAddr, UDATA pruneCons
if (arrayClass == NULL) {
/* the first class in vm->arrayROMClasses is the array class for Objects */
arrayClass = vmFuncs->internalCreateArrayClass(vmThread,
(J9ROMArrayClass *) J9ROMIMAGEHEADER_FIRSTCLASS(vm->arrayROMClasses),
(J9ROMArrayClass *) J9ROMIMAGEHEADER_FIRSTCLASS(vm->arrayROMClasses),
elementClass);
if (arrayClass == NULL) {
/* exception is pending from the call */
Expand Down
6 changes: 6 additions & 0 deletions runtime/oti/j9consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,12 @@ extern "C" {
#define J9_JAVA_NATIVE 0x100
#define J9_JAVA_STATIC 0x8

/* Stack walker frame Types */
#define J9VM_STACK_FRAME_INTERPRETER 0
#define J9VM_STACK_FRAME_JIT 1
#define J9VM_STACK_FRAME_JIT_INLINE 2
#define J9VM_STACK_FRAME_NATIVE 3

/* JFR event types */

#define J9JFR_EVENT_TYPE_EXECUTION_SAMPLE 0
Expand Down
2 changes: 1 addition & 1 deletion runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4981,7 +4981,7 @@ typedef struct J9InternalVMFunctions {
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
void ( *cleanUpClassLoader)(struct J9VMThread *vmThread, struct J9ClassLoader* classLoader) ;
#endif /* defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */
UDATA ( *iterateStackTrace)(struct J9VMThread * vmThread, j9object_t* exception, UDATA (*callback) (struct J9VMThread * vmThread, void * userData, UDATA bytecodeOffset, struct J9ROMClass * romClass, struct J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, struct J9ClassLoader* classLoader, struct J9Class* ramClass), void * userData, UDATA pruneConstructors, UDATA skipHiddenFrames) ;
UDATA ( *iterateStackTrace)(struct J9VMThread * vmThread, j9object_t* exception, UDATA (*callback) (struct J9VMThread * vmThread, void * userData, UDATA bytecodeOffset, struct J9ROMClass * romClass, struct J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, struct J9ClassLoader* classLoader, struct J9Class* ramClass, UDATA frameType), void * userData, UDATA pruneConstructors, UDATA skipHiddenFrames) ;
char* ( *getNPEMessage)(struct J9NPEMessageData *npeMsgData);
void ( *internalReleaseVMAccessNoMutex)(struct J9VMThread * vmThread) ;
struct J9HookInterface** ( *getVMHookInterface)(struct J9JavaVM* vm) ;
Expand Down
4 changes: 2 additions & 2 deletions runtime/oti/vm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ internalExceptionDescribe(J9VMThread *vmThread);
* @return UDATA
*/
UDATA
iterateStackTrace(J9VMThread * vmThread, j9object_t* exception, UDATA (*callback) (J9VMThread * vmThread, void * userData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass), void * userData, UDATA pruneConstructors, UDATA skipHiddenFrames);
iterateStackTrace(J9VMThread * vmThread, j9object_t* exception, UDATA (*callback) (J9VMThread * vmThread, void * userData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass, UDATA frameType), void * userData, UDATA pruneConstructors, UDATA skipHiddenFrames);

/**
* @brief
Expand All @@ -881,7 +881,7 @@ iterateStackTrace(J9VMThread * vmThread, j9object_t* exception, UDATA (*callba
* @return UDATA
*/
UDATA
iterateStackTraceImpl(J9VMThread * vmThread, j9object_t* exception, UDATA (*callback) (J9VMThread * vmThread, void * userData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass), void * userData, UDATA pruneConstructors, UDATA skipHiddenFrames, UDATA sizeOfWalkstateCache, BOOLEAN exceptionIsJavaObject);
iterateStackTraceImpl(J9VMThread * vmThread, j9object_t* exception, UDATA (*callback) (J9VMThread * vmThread, void * userData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass, UDATA frameType), void * userData, UDATA pruneConstructors, UDATA skipHiddenFrames, UDATA sizeOfWalkstateCache, BOOLEAN exceptionIsJavaObject);


/* ---------------- exceptionsupport.c ---------------- */
Expand Down
6 changes: 3 additions & 3 deletions runtime/rasdump/javadump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

/* Callback Function prototypes */
UDATA writeFrameCallBack (J9VMThread* vmThread, J9StackWalkState* state);
UDATA writeExceptionFrameCallBack (J9VMThread* vmThread, void* userData, UDATA bytecodeOffset, J9ROMClass* romClass, J9ROMMethod* romMethod, J9UTF8* sourceFile, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass);
UDATA writeExceptionFrameCallBack (J9VMThread* vmThread, void* userData, UDATA bytecodeOffset, J9ROMClass* romClass, J9ROMMethod* romMethod, J9UTF8* sourceFile, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass, UDATA frameType);
void writeLoaderCallBack (void* classLoader, void* userData);
void writeLibrariesCallBack (void* classLoader, void* userData);
void writeClassesCallBack (void* classLoader, void* userData);
Expand Down Expand Up @@ -240,7 +240,7 @@ private :

/* Allow the callback functions access */
friend UDATA writeFrameCallBack (J9VMThread* vmThread, J9StackWalkState* state);
friend UDATA writeExceptionFrameCallBack (J9VMThread* vmThread, void* userData, UDATA bytecodeOffset, J9ROMClass* romClass, J9ROMMethod* romMethod, J9UTF8* sourceFile, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass);
friend UDATA writeExceptionFrameCallBack (J9VMThread* vmThread, void* userData, UDATA bytecodeOffset, J9ROMClass* romClass, J9ROMMethod* romMethod, J9UTF8* sourceFile, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass, UDATA frameType);
friend void writeLoaderCallBack (void* classLoader, void* userData);
friend void writeLibrariesCallBack (void* classLoader, void* userData);
friend void writeClassesCallBack (void* classLoader, void* userData);
Expand Down Expand Up @@ -5757,7 +5757,7 @@ writeFrameCallBack(J9VMThread* vmThread, J9StackWalkState* state)
}

UDATA
writeExceptionFrameCallBack(J9VMThread* vmThread, void* userData, UDATA bytecodeOffset, J9ROMClass* romClass, J9ROMMethod* romMethod, J9UTF8* sourceFile, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass)
writeExceptionFrameCallBack(J9VMThread* vmThread, void* userData, UDATA bytecodeOffset, J9ROMClass* romClass, J9ROMMethod* romMethod, J9UTF8* sourceFile, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass, UDATA frameType)
{
JavaCoreDumpWriter *jcdw = (JavaCoreDumpWriter *)((J9StackWalkState*)userData)->userData1;
return jcdw->writeExceptionFrame(userData, romClass, romMethod, sourceFile, lineNumber);
Expand Down
Loading

0 comments on commit efaa4f6

Please sign in to comment.