Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initializeMethodRunAddressForSnapshot function #20828

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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