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

Implement JVM_IsImplicitlyConstructibleClass #19834

Merged
merged 1 commit into from
Jul 11, 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
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);
}
}