Skip to content

Commit

Permalink
Add initializeMethodRunAddressForSnapshot function
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Henderson <[email protected]>
  • Loading branch information
ThanHenderson committed Dec 12, 2024
1 parent e8707b4 commit 6f88bfb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
3 changes: 3 additions & 0 deletions runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4950,6 +4950,9 @@ typedef struct J9InternalVMFunctions {
void ( *printThreadInfo)(struct J9JavaVM *vm, struct J9VMThread *self, char *toFile, BOOLEAN allThreads) ;
void (JNICALL *initializeAttachedThread)(struct J9VMThread *vmContext, const char *name, j9object_t *group, UDATA daemon, struct J9VMThread *initializee) ;
void ( *initializeMethodRunAddressNoHook)(struct J9JavaVM* vm, J9Method *method) ;
#if defined(J9VM_OPT_SNAPSHOTS)
void ( *initializeMethodRunAddressForSnapshot)(struct J9JavaVM *vm, struct J9Method *method) ;
#endif /* defined(J9VM_OPT_SNAPSHOTS) */
void (JNICALL *sidecarInvokeReflectMethod)(struct J9VMThread *vmContext, jobject methodRef, jobject recevierRef, jobjectArray argsRef) ;
void (JNICALL *sidecarInvokeReflectConstructor)(struct J9VMThread *vmContext, jobject constructorRef, jobject recevierRef, jobjectArray argsRef) ;
struct J9MemorySegmentList* ( *allocateMemorySegmentListWithSize)(struct J9JavaVM * javaVM, U_32 numberOfMemorySegments, UDATA sizeOfElements, U_32 memoryCategory) ;
Expand Down
16 changes: 13 additions & 3 deletions runtime/oti/vm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1261,20 +1261,30 @@ growJavaStack(J9VMThread * vmThread, UDATA newStackSize);
* @brief
* @param *vmThread
* @param *method
* @param *jxeDescription
* @return void
*/
void
initializeMethodRunAddress(J9VMThread *vmThread, J9Method *method);

/**
* @brief
* @param vm
* @param *vm
* @param *method
* @return void
*/
void
initializeMethodRunAddressNoHook(J9JavaVM *vm, J9Method *method);

#if defined(J9VM_OPT_SNAPSHOTS)
/**
* @brief
* @param *vm
* @param *method
* @return void
*/
void
initializeMethodRunAddressNoHook(J9JavaVM* vm, J9Method *method);
initializeMethodRunAddressForSnapshot(J9JavaVM *vm, J9Method *method);
#endif /* defined(J9VM_OPT_SNAPSHOTS) */

/**
* @brief
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/VMSnapshotImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ VMSnapshotImpl::fixupMethodRunAddresses(J9Class *ramClass)
UDATA count = romClass->romMethodCount;
J9Method *ramMethod = ramClass->ramMethods;
for (UDATA i = 0; i < count; i++) {
initializeMethodRunAddressNoHook(_vm, ramMethod);
initializeMethodRunAddressForSnapshot(_vm, ramMethod);
ramMethod++;
}
}
Expand Down
26 changes: 26 additions & 0 deletions runtime/vm/initsendtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,32 @@ initializeMethodRunAddressNoHook(J9JavaVM* vm, J9Method *method)
method->methodRunAddress = J9_BCLOOP_ENCODE_SEND_TARGET(J9_BCLOOP_SEND_TARGET_NON_SYNC);
}

/* This function is similar to initializeMethodRunAddress but without the hook call.
* initializeMethodRunAddressNoHook cannot be used becuase method->extra
* and/or methodRunAddress may not be set properly when fixing up the classes
* before writing the snapshot.
*/
#if defined(J9VM_OPT_SNAPSHOTS)
void
initializeMethodRunAddressForSnapshot(J9JavaVM *vm, J9Method *method)
{
method->extra = (void *)J9_STARTPC_NOT_TRANSLATED;

#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
if (initializeMethodRunAddressMethodHandle(method)) {
return;
}
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */

#if defined(J9VM_OPT_METHOD_HANDLE)
if (initializeMethodRunAddressVarHandle(method)) {
return;
}
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
initializeMethodRunAddressNoHook(vm, method);
}
#endif /* defined(J9VM_OPT_SNAPSHOTS) */

#if !defined(J9VM_OPT_SNAPSHOTS)
J9Method cInitialStaticMethod = { 0, 0, J9_BCLOOP_ENCODE_SEND_TARGET(J9_BCLOOP_SEND_TARGET_INITIAL_STATIC), 0 };
J9Method cInitialSpecialMethod = { 0, 0, J9_BCLOOP_ENCODE_SEND_TARGET(J9_BCLOOP_SEND_TARGET_INITIAL_SPECIAL), 0 };
Expand Down
3 changes: 3 additions & 0 deletions runtime/vm/intfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ J9InternalVMFunctions J9InternalFunctions = {
printThreadInfo,
initializeAttachedThread,
initializeMethodRunAddressNoHook,
#if defined(J9VM_OPT_SNAPSHOTS)
initializeMethodRunAddressForSnapshot,
#endif /* defined(J9VM_OPT_SNAPSHOTS) */
sidecarInvokeReflectMethod,
sidecarInvokeReflectConstructor,
allocateMemorySegmentListWithSize,
Expand Down

0 comments on commit 6f88bfb

Please sign in to comment.