Skip to content

Commit

Permalink
Merge pull request #20828 from ThanHenderson/initmraforsnap
Browse files Browse the repository at this point in the history
Add initializeMethodRunAddressForSnapshot function
  • Loading branch information
babsingh authored Dec 13, 2024
2 parents 6d451b1 + 3b4e5bf commit c938d77
Show file tree
Hide file tree
Showing 5 changed files with 49 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
22 changes: 20 additions & 2 deletions runtime/oti/vm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,6 @@ growJavaStack(J9VMThread * vmThread, UDATA newStackSize);
* @brief
* @param *vmThread
* @param *method
* @param *jxeDescription
* @return void
*/
void
Expand All @@ -1274,7 +1273,26 @@ initializeMethodRunAddress(J9VMThread *vmThread, J9Method *method);
* @return void
*/
void
initializeMethodRunAddressNoHook(J9JavaVM* vm, J9Method *method);
initializeMethodRunAddressNoHook(J9JavaVM *vm, J9Method *method);

#if defined(J9VM_OPT_SNAPSHOTS)
/**
* @brief This function is similar to initializeMethodRunAddress but without the hook call.
*
* Prior to writing a VM snapshot, J9Method::methodRunAddress and J9Method::extra need to be
* reinitialized to a state that is restore friendly (i.e. set to appropriate interpreter entries).
* initializeMethodRunAddress should not be used; it may run the J9HOOK_VM_INITIALIZE_SEND_TARGET
* hook that initializes invocation counts and sets J9Method::methodRunAddress's to JIT specific
* send targets. initializeMethodRunAddressNoHook should not be used because it does not perform
* MethodHandle and VarHandle send target initialization, nor does it reset J9Method::extra
* appropriately.
*
* @param vm pointer to the J9JavaVM
* @param method pointer to the J9Method
*/
void
initializeMethodRunAddressForSnapshot(J9JavaVM *vm, J9Method *method);
#endif /* defined(J9VM_OPT_SNAPSHOTS) */

/**
* @brief
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/VMSnapshotImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,12 +718,12 @@ VMSnapshotImpl::fixupMethodRunAddresses(J9Class *ramClass)
{
J9ROMClass *romClass = ramClass->romClass;

/* for all ramMethods call initializeMethodRunAdress for special methods */
/* Call initializeMethodRunAddressForSnapshot on all for J9Methods in a J9Class. */
if (0 != romClass->romMethodCount) {
UDATA count = romClass->romMethodCount;
J9Method *ramMethod = ramClass->ramMethods;
for (UDATA i = 0; i < count; i++) {
initializeMethodRunAddressNoHook(_vm, ramMethod);
initializeMethodRunAddressForSnapshot(_vm, ramMethod);
ramMethod++;
}
}
Expand Down
21 changes: 21 additions & 0 deletions runtime/vm/initsendtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,27 @@ initializeMethodRunAddressNoHook(J9JavaVM* vm, J9Method *method)
method->methodRunAddress = J9_BCLOOP_ENCODE_SEND_TARGET(J9_BCLOOP_SEND_TARGET_NON_SYNC);
}

#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 c938d77

Please sign in to comment.