Skip to content

Commit

Permalink
Merge pull request #19834 from theresa-m/jni_isimplicit
Browse files Browse the repository at this point in the history
Implement JVM_IsImplicitlyConstructibleClass
  • Loading branch information
hangshao0 authored Jul 11, 2024
2 parents 228f348 + 8ae99ed commit 5a03e1a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
19 changes: 17 additions & 2 deletions runtime/j9vm/javanextvmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,23 @@ JVM_IsValhallaEnabled()
JNIEXPORT jboolean JNICALL
JVM_IsImplicitlyConstructibleClass(JNIEnv *env, jclass cls)
{
assert(!"JVM_IsImplicitlyConstructibleClass unimplemented");
return JNI_FALSE;
jboolean result = JNI_FALSE;
J9VMThread *currentThread = (J9VMThread *)env;
J9InternalVMFunctions const * const vmFuncs = currentThread->javaVM->internalVMFunctions;
vmFuncs->internalEnterVMFromJNI(currentThread);
if (NULL == cls) {
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGNULLPOINTEREXCEPTION, NULL);
} else {
J9Class *clazz = J9VM_J9CLASS_FROM_JCLASS(currentThread, cls);
J9ROMClass *romClass = clazz->romClass;
if (J9_ARE_ALL_BITS_SET(romClass->optionalFlags, J9_ROMCLASS_OPTINFO_IMPLICITCREATION_ATTRIBUTE)
&& J9_ARE_ALL_BITS_SET(getImplicitCreationFlags(romClass), J9AccImplicitCreateHasDefaultValue)
) {
result = JNI_TRUE;
}
}
vmFuncs->internalExitVMToJNI(currentThread);
return result;
}

JNIEXPORT jboolean JNICALL
Expand Down
1 change: 1 addition & 0 deletions test/functional/Valhalla/playlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
</variations>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
--enable-preview \
--add-exports java.base/jdk.internal.value=ALL-UNNAMED \
-cp $(Q)$(LIB_DIR)$(D)asm.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)ValhallaTests.jar$(Q) \
org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) -testnames ValhallaAttributeTests \
-groups $(TEST_GROUP) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package org.openj9.test.lworld;

import jdk.internal.vm.annotation.ImplicitlyConstructible;
import org.testng.annotations.Test;
import org.testng.Assert;

Expand Down Expand Up @@ -196,4 +197,31 @@ static public void testPutStaticNullToNullRestrictedField() throws Throwable {
}
Assert.fail("Test expected a NullPointerException wrapped in ExceptionInInitializerError.");
}

@ImplicitlyConstructible
static value class ImplicitClass {
Object o;
ImplicitClass(Object o) {
this.o = o;
}
}

/* Test to verify JVM_IsImplicitlyConstructibleClass */
@Test
static public void testValueClassIsImplicitlyConstructible() {
ImplicitClass ic = (ImplicitClass)jdk.internal.value.ValueClass.zeroInstance(ImplicitClass.class);
}

static value class NonImplicitClass {
Object o;
NonImplicitClass(Object o) {
this.o = o;
}
}

/* Test to verify JVM_IsImplicitlyConstructibleClass */
@Test(expectedExceptions = IllegalArgumentException.class)
static public void testValueClassIsImplicitlyConstructible2() {
jdk.internal.value.ValueClass.zeroInstance(NonImplicitClass.class);
}
}

0 comments on commit 5a03e1a

Please sign in to comment.