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

Update Object.wait to use Blocker.begin/end for Java 19+ #16324

Merged
merged 1 commit into from
Nov 22, 2022
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
19 changes: 18 additions & 1 deletion jcl/src/java.base/share/classes/java/lang/Object.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
*******************************************************************************/
package java.lang;

/*[IF JAVA_SPEC_VERSION >= 19] */
import jdk.internal.misc.Blocker;
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */

/**
* Object is the root of the java class hierarchy. All non-base types
* respond to the messages defined in this class.
Expand Down Expand Up @@ -269,7 +273,20 @@ public final void wait(long time) throws InterruptedException {
* @see #wait(long)
* @see java.lang.Thread
*/
public final native void wait(long time, int frac) throws InterruptedException;
public final void wait(long time, int frac) throws InterruptedException {
/*[IF JAVA_SPEC_VERSION >= 19] */
long blockerRC = Blocker.begin();
try {
waitImpl(time, frac);
} finally {
Blocker.end(blockerRC);
}
/*[ELSE] JAVA_SPEC_VERSION >= 19 */
waitImpl(time, frac);
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */
}

private final native void waitImpl(long time, int frac) throws InterruptedException;

/*
* Used as a prototype for the jit.
Expand Down
12 changes: 6 additions & 6 deletions runtime/util/final.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2014 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 @@ -27,15 +27,15 @@

UDATA methodIsFinalInObject(UDATA nameLength, U_8* name, UDATA sigLength, U_8* sig) {

const char names[] = "wait\0" "wait\0" "wait\0" "notify\0" "notifyAll\0" "getClass\0";
const char names[] = "wait\0" "wait\0" "wait\0" "waitImpl\0" "notify\0" "notifyAll\0" "getClass\0";
const U_8 nameLengths[] = {
sizeof("wait") - 1, sizeof("wait") - 1, sizeof("wait") - 1,
sizeof("wait") - 1, sizeof("wait") - 1, sizeof("wait") - 1, sizeof("waitImpl") - 1,
sizeof("notify") - 1, sizeof("notifyAll") - 1, sizeof("getClass") - 1 };
const char sigs[] = "()V\0" "(J)V\0" "(JI)V\0" "()V\0" "()V\0" "()Ljava/lang/Class;\0";
const char sigs[] = "()V\0" "(J)V\0" "(JI)V\0" "(JI)V\0" "()V\0" "()V\0" "()Ljava/lang/Class;\0";
const U_8 sigLengths[] = {
sizeof("()V") - 1, sizeof("(J)V") - 1, sizeof("(JI)V") - 1,
sizeof("()V") - 1, sizeof("(J)V") - 1, sizeof("(JI)V") - 1, sizeof("(JI)V") - 1,
sizeof("()V") - 1, sizeof("()V") - 1, sizeof("()Ljava/lang/Class;") - 1 };
#define OBJECT_FINAL_COUNT 6
#define OBJECT_FINAL_COUNT 7
#define SHORTEST_METHOD_NAME (sizeof("wait") - 1)
#define LONGEST_METHOD_NAME (sizeof("notifyAll") - 1)

Expand Down
6 changes: 3 additions & 3 deletions runtime/vm/BytecodeInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4853,9 +4853,9 @@ class INTERPRETER_CLASS
return rc;
}

/* java.lang.Object: public final native void wait(long millis, int nanos); */
/* java.lang.Object: public final native void waitImpl(long millis, int nanos); */
VMINLINE VM_BytecodeAction
inlObjectWait(REGISTER_ARGS_LIST)
inlObjectWaitImpl(REGISTER_ARGS_LIST)
{
VM_BytecodeAction rc = EXECUTE_BYTECODE;
I_32 nanos = *(I_32*)_sp;
Expand Down Expand Up @@ -10701,7 +10701,7 @@ runMethod: {
JUMP_TARGET(J9_BCLOOP_SEND_TARGET_INL_THREAD_SLEEP):
PERFORM_ACTION(inlThreadSleep(REGISTER_ARGS));
JUMP_TARGET(J9_BCLOOP_SEND_TARGET_INL_OBJECT_WAIT):
PERFORM_ACTION(inlObjectWait(REGISTER_ARGS));
PERFORM_ACTION(inlObjectWaitImpl(REGISTER_ARGS));
JUMP_TARGET(J9_BCLOOP_SEND_TARGET_INL_CLASSLOADER_LOADLIBRARYWITHPATH):
PERFORM_ACTION(inlClassLoaderLoadLibraryWithPath(REGISTER_ARGS));
JUMP_TARGET(J9_BCLOOP_SEND_TARGET_INL_THREAD_ISINTERRUPTEDIMPL):
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/FastJNI_java_lang_Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

extern "C" {

/* java.lang.Object: public final native void wait(long millis, int nanos) throws InterruptedException; */
/* java.lang.Object: public final native void waitImpl(long millis, int nanos) throws InterruptedException; */
void JNICALL
Fast_java_lang_Object_wait(J9VMThread *currentThread, j9object_t receiverObject, jlong millis, jint nanos)
{
Expand Down Expand Up @@ -90,7 +90,7 @@ Fast_java_lang_Object_notify(J9VMThread *currentThread, j9object_t receiverObjec
}

J9_FAST_JNI_METHOD_TABLE(java_lang_Object)
J9_FAST_JNI_METHOD("wait", "(JI)V", Fast_java_lang_Object_wait,
J9_FAST_JNI_METHOD("waitImpl", "(JI)V", Fast_java_lang_Object_wait,
J9_FAST_JNI_RETAIN_VM_ACCESS | J9_FAST_JNI_DO_NOT_WRAP_OBJECTS)
J9_FAST_JNI_METHOD("notifyAll", "()V", Fast_java_lang_Object_notifyAll,
J9_FAST_JNI_RETAIN_VM_ACCESS | J9_FAST_JNI_DO_NOT_WRAP_OBJECTS)
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/bindnatv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static inlMapping mappings[] = {
{ "Java_java_lang_invoke_MethodHandles_getStackClass__I", J9_BCLOOP_SEND_TARGET_INL_VM_GETSTACKCLASS },
{ "Java_java_lang_Class_getStackClass__I", J9_BCLOOP_SEND_TARGET_INL_VM_GETSTACKCLASS },
{ "Java_java_lang_Thread_sleepImpl__JI", J9_BCLOOP_SEND_TARGET_INL_THREAD_SLEEP },
{ "Java_java_lang_Object_wait__JI", J9_BCLOOP_SEND_TARGET_INL_OBJECT_WAIT },
{ "Java_java_lang_Object_waitImpl__JI", J9_BCLOOP_SEND_TARGET_INL_OBJECT_WAIT },
{ "Java_java_lang_ClassLoader_loadLibraryWithPath___3BLjava_lang_ClassLoader_2_3B", J9_BCLOOP_SEND_TARGET_INL_CLASSLOADER_LOADLIBRARYWITHPATH },
{ "Java_java_lang_Thread_isInterruptedImpl__", J9_BCLOOP_SEND_TARGET_INL_THREAD_ISINTERRUPTEDIMPL },
{ "Java_java_lang_ClassLoader_initAnonClassLoader__Ljava_lang_InternalAnonymousClassLoader_2", J9_BCLOOP_SEND_TARGET_INL_CLASSLOADER_INITIALIZEANONCLASSLOADER },
Expand Down