Skip to content

Commit

Permalink
Add new jdk.internal.value.ValueClass native methods
Browse files Browse the repository at this point in the history
This change adds:
- JVM_IsFlatArray
- JVM_NewNullableAtomicArray
- JVM_NewNullRestrictedAtomicArray

Signed-off-by: Theresa Mammarella <[email protected]>
  • Loading branch information
theresa-m committed Jan 21, 2025
1 parent cccf21d commit 0e544ae
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 12 deletions.
5 changes: 4 additions & 1 deletion runtime/j9vm/exports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,13 @@ endif()

if(J9VM_OPT_VALHALLA_VALUE_TYPES)
jvm_add_exports(jvm
JVM_IsValhallaEnabled
JVM_IsFlatArray
JVM_IsImplicitlyConstructibleClass
JVM_IsNullRestrictedArray
JVM_IsValhallaEnabled
JVM_NewNullableAtomicArray
JVM_NewNullRestrictedArray
JVM_NewNullRestrictedAtomicArray
JVM_VirtualThreadHideFrames
)
endif()
11 changes: 10 additions & 1 deletion runtime/j9vm/j9vmnatives.xml
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
<export name="AsyncGetCallTrace"/>

<!-- Additions for Valhalla -->
<export name="JVM_IsValhallaEnabled">
<export name="JVM_IsFlatArray">
<include-if condition="spec.flags.opt_valhallaValueTypes"/>
</export>
<export name="JVM_IsImplicitlyConstructibleClass">
Expand All @@ -340,9 +340,18 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
<export name="JVM_IsNullRestrictedArray">
<include-if condition="spec.flags.opt_valhallaValueTypes"/>
</export>
<export name="JVM_IsValhallaEnabled">
<include-if condition="spec.flags.opt_valhallaValueTypes"/>
</export>
<export name="JVM_NewNullableAtomicArray">
<include-if condition="spec.flags.opt_valhallaValueTypes"/>
</export>
<export name="JVM_NewNullRestrictedArray">
<include-if condition="spec.flags.opt_valhallaValueTypes"/>
</export>
<export name="JVM_NewNullRestrictedAtomicArray">
<include-if condition="spec.flags.opt_valhallaValueTypes"/>
</export>
<export name="JVM_VirtualThreadHideFrames">
<include-if condition="spec.flags.opt_valhallaValueTypes"/>
</export>
Expand Down
66 changes: 57 additions & 9 deletions runtime/j9vm/valhallavmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,42 +73,72 @@ JVM_IsNullRestrictedArray(JNIEnv *env, jobject obj)
return result;
}

JNIEXPORT jarray JNICALL
JVM_NewNullRestrictedArray(JNIEnv *env, jclass componentType, jint length)
JNIEXPORT jboolean JNICALL
JVM_IsFlatArray(JNIEnv *env, jobject obj)
{
jboolean result = JNI_FALSE;
J9VMThread *currentThread = (J9VMThread *)env;
J9InternalVMFunctions *vmFuncs = currentThread->javaVM->internalVMFunctions;
vmFuncs->internalEnterVMFromJNI(currentThread);
if (NULL == obj) {
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGNULLPOINTEREXCEPTION, NULL);
} else {
J9Class *j9clazz = J9OBJECT_CLAZZ(currentThread, J9_JNI_UNWRAP_REFERENCE(obj));
if (J9CLASS_IS_ARRAY(j9clazz) && J9_IS_J9CLASS_FLATTENED(j9clazz)) {
result = JNI_TRUE;
}
}
vmFuncs->internalExitVMToJNI(currentThread);
return result;
}

static jarray
newArrayHelper(JNIEnv *env, jclass componentType, jint length, bool isNullRestricted)
{
J9VMThread *currentThread = (J9VMThread *)env;
J9JavaVM *vm = currentThread->javaVM;
J9InternalVMFunctions *vmFuncs = currentThread->javaVM->internalVMFunctions;
J9Class *ramClass = NULL;
J9Class *arrayClass = NULL;
UDATA options = 0;
j9object_t newArray = NULL;
jarray arrayRef = NULL;

vmFuncs->internalEnterVMFromJNI(currentThread);
ramClass = J9VMJAVALANGCLASS_VMREF(currentThread, J9_JNI_UNWRAP_REFERENCE(componentType));

if (length < 0) {
if ((NULL == ramClass) || (length < 0)) {
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, NULL);
goto done;
}

if (!(J9_IS_J9CLASS_VALUETYPE(ramClass) && J9_IS_J9CLASS_ALLOW_DEFAULT_VALUE(ramClass))) {
if (!J9_IS_J9CLASS_VALUETYPE(ramClass)) {
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, NULL);
goto done;
}

if (NULL == J9CLASS_GET_NULLRESTRICTED_ARRAY(ramClass)) {
if (isNullRestricted && !J9_IS_J9CLASS_ALLOW_DEFAULT_VALUE(ramClass)) {
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, NULL);
goto done;
}

arrayClass = ramClass->arrayClass;
if (isNullRestricted) {
arrayClass = J9CLASS_GET_NULLRESTRICTED_ARRAY(ramClass);
options = J9_FINDCLASS_FLAG_CLASS_OPTION_NULL_RESTRICTED_ARRAY;
}

if (NULL == arrayClass) {
J9ROMArrayClass *arrayOfObjectsROMClass = (J9ROMArrayClass *)J9ROMIMAGEHEADER_FIRSTCLASS(vm->arrayROMClasses);
vmFuncs->internalCreateArrayClassWithOptions(
currentThread, arrayOfObjectsROMClass, ramClass, J9_FINDCLASS_FLAG_CLASS_OPTION_NULL_RESTRICTED_ARRAY);
arrayClass = vmFuncs->internalCreateArrayClassWithOptions(currentThread, arrayOfObjectsROMClass, ramClass, options);
if (NULL != currentThread->currentException) {
goto done;
}
ramClass = VM_VMHelpers::currentClass(ramClass);
}

newArray = vm->memoryManagerFunctions->J9AllocateIndexableObject(
currentThread, J9CLASS_GET_NULLRESTRICTED_ARRAY(ramClass), length, J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);

currentThread, arrayClass, length, J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);
if (NULL == newArray) {
vmFuncs->setHeapOutOfMemoryError(currentThread);
goto done;
Expand All @@ -119,5 +149,23 @@ JVM_NewNullRestrictedArray(JNIEnv *env, jclass componentType, jint length)
vmFuncs->internalExitVMToJNI(currentThread);
return arrayRef;
}

JNIEXPORT jarray JNICALL
JVM_NewNullRestrictedArray(JNIEnv *env, jclass componentType, jint length)
{
return newArrayHelper(env, componentType, length, TRUE);
}

JNIEXPORT jarray JNICALL
JVM_NewNullRestrictedAtomicArray(JNIEnv *env, jclass componentType, jint length)
{
return newArrayHelper(env, componentType, length, TRUE);
}

JNIEXPORT jarray JNICALL
JVM_NewNullableAtomicArray(JNIEnv *env, jclass componentType, jint length)
{
return newArrayHelper(env, componentType, length, FALSE);
}
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
} /* extern "C" */
8 changes: 7 additions & 1 deletion runtime/redirector/forwarders.m4
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,19 @@ _IF([JAVA_SPEC_VERSION >= 21],
_IF([JAVA_SPEC_VERSION >= 21],
[_X(JVM_VirtualThreadUnmount, JNICALL, false, void, JNIEnv *env, jobject vthread, jboolean hide)])
_IF([defined(J9VM_OPT_VALHALLA_VALUE_TYPES)],
[_X(JVM_IsValhallaEnabled, JNICALL, false, jboolean, void)])
[_X(JVM_IsFlatArray, JNICALL, false, jboolean, JNIEnv *env, jclass cls)])
_IF([defined(J9VM_OPT_VALHALLA_VALUE_TYPES)],
[_X(JVM_IsImplicitlyConstructibleClass, JNICALL, false, jboolean, JNIEnv *env, jclass cls)])
_IF([defined(J9VM_OPT_VALHALLA_VALUE_TYPES)],
[_X(JVM_IsNullRestrictedArray, JNICALL, false, jboolean, JNIEnv *env, jobject obj)])
_IF([defined(J9VM_OPT_VALHALLA_VALUE_TYPES)],
[_X(JVM_IsValhallaEnabled, JNICALL, false, jboolean, void)])
_IF([defined(J9VM_OPT_VALHALLA_VALUE_TYPES)],
[_X(JVM_NewNullableAtomicArray, JNICALL, false, jarray, JNIEnv *env, jclass cls, jint length)])
_IF([defined(J9VM_OPT_VALHALLA_VALUE_TYPES)],
[_X(JVM_NewNullRestrictedArray, JNICALL, false, jarray, JNIEnv *env, jclass cls, jint length)])
_IF([defined(J9VM_OPT_VALHALLA_VALUE_TYPES)],
[_X(JVM_NewNullRestrictedAtomicArray, JNICALL, false, jarray, JNIEnv *env, jclass cls, jint length)])
_IF([JAVA_SPEC_VERSION >= 22],
[_X(JVM_ExpandStackFrameInfo, JNICALL, false, void, JNIEnv *env, jobject object)])
_IF([JAVA_SPEC_VERSION == 22],
Expand Down

0 comments on commit 0e544ae

Please sign in to comment.