Skip to content

Commit

Permalink
Merge pull request #16324 from fengxue-IS/wait-blocker
Browse files Browse the repository at this point in the history
Update Object.wait to use Blocker.begin/end for Java 19+
  • Loading branch information
gacholio committed Nov 22, 2022
2 parents 3fe5f29 + 1a7af61 commit defdf9a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
19 changes: 18 additions & 1 deletion jcl/src/java.base/share/classes/java/lang/Object.java
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
@@ -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
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
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
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

0 comments on commit defdf9a

Please sign in to comment.