Skip to content

Commit

Permalink
Merge pull request #13924 from ehrenjulzert/master
Browse files Browse the repository at this point in the history
Add isFlattened and IsFlattenedArray Unsafe methods
  • Loading branch information
tajila committed Nov 21, 2021
2 parents c4da870 + e295c84 commit 1e7404f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
20 changes: 15 additions & 5 deletions jcl/src/java.base/share/classes/jdk/internal/misc/Unsafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -6555,8 +6555,23 @@ private static char convEndian(boolean isBigEndian, char value) {
public native <V> void putValue(Object obj, long offset, Class<?> clz, V value);
public native <V> V uninitializedDefaultValue(Class<?> clz);
public native <V> long valueHeaderSize(Class<V> clz);

/**
* Determines whether a class is a flattened array
*
* @param clz the class to check
* @return boolean value indicating whether the class is a flattened array
*/
public native boolean isFlattenedArray(Class<?> clz);

/**
* Determines whether a field is flattened
*
* @param field the field to check
* @return boolean value indicating whether the field is flattened
*/
public native boolean isFlattened(Field field);

public final <V> boolean compareAndSetValue(Object obj, long offset, Class<?> clz, V v1, V v2) {
throw OpenJDKCompileStubThrowError();
}
Expand Down Expand Up @@ -6625,11 +6640,6 @@ public final <V> Object getAndSetValueAcquire(Object obj, long offset, Class<?>
throw OpenJDKCompileStubThrowError();
}

public boolean isFlattened(java.lang.reflect.Field field) {
// ToDo: this is a temporary implementation - https://github.com/eclipse-openj9/openj9/issues/13614
return false;
}

public long getObjectSize(Object o) {
throw OpenJDKCompileStubThrowError();
}
Expand Down
1 change: 1 addition & 0 deletions runtime/oti/VMHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ typedef enum {
J9_BCLOOP_SEND_TARGET_INL_UNSAFE_UNINITIALIZEDDEFAULTVALUE,
J9_BCLOOP_SEND_TARGET_INL_UNSAFE_VALUEHEADERSIZE,
J9_BCLOOP_SEND_TARGET_INL_UNSAFE_ISFLATTENEDARRAY,
J9_BCLOOP_SEND_TARGET_INL_UNSAFE_ISFLATTENED,
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
J9_BCLOOP_SEND_TARGET_INL_INTERNALS_GET_INTERFACES,
J9_BCLOOP_SEND_TARGET_INL_ARRAY_NEW_ARRAY_IMPL,
Expand Down
44 changes: 42 additions & 2 deletions runtime/vm/BytecodeInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4021,15 +4021,52 @@ class INTERPRETER_CLASS
return EXECUTE_BYTECODE;
}

/* ToDo: unimplemented - https://github.com/eclipse-openj9/openj9/issues/13614 */
/* jdk.internal.misc.Unsafe: public native boolean isFlattenedArray(Class<?> clz); */
VMINLINE VM_BytecodeAction
inlUnsafeIsFlattenedArray(REGISTER_ARGS_LIST)
{
j9object_t cls = *(j9object_t*)_sp;

updateVMStruct(REGISTER_ARGS);
Assert_VM_unreachable();
buildInternalNativeStackFrame(REGISTER_ARGS);

I_32 result = (I_32)FALSE;
if (NULL != cls) {
J9Class *fieldClazz = J9VM_J9CLASS_FROM_HEAPCLASS(_currentThread, cls);
if (J9CLASS_IS_ARRAY(fieldClazz)) {
result = (I_32)J9_IS_J9CLASS_FLATTENED(fieldClazz);
}
}

restoreInternalNativeStackFrame(REGISTER_ARGS);
returnSingleFromINL(REGISTER_ARGS, result, 2);
return EXECUTE_BYTECODE;
}

VMINLINE VM_BytecodeAction
inlUnsafeIsFlattened(REGISTER_ARGS_LIST)
{
j9object_t field = *(j9object_t*)_sp;
VM_BytecodeAction rc = EXECUTE_BYTECODE;

updateVMStruct(REGISTER_ARGS);
buildInternalNativeStackFrame(REGISTER_ARGS);

if (NULL == field) {
rc = THROW_NPE;
} else {
J9JNIFieldID *fieldID = _vm->reflectFunctions.idFromFieldObject(_currentThread, NULL, field);
if (VM_VMHelpers::exceptionPending(_currentThread)) {
rc = GOTO_THROW_CURRENT_EXCEPTION;
} else {
I_32 result = (I_32)isFlattenableFieldFlattened(fieldID->declaringClass, fieldID->field);
restoreInternalNativeStackFrame(REGISTER_ARGS);
returnSingleFromINL(REGISTER_ARGS, result, 2);
}
}

return rc;
}
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */

/* java.lang.J9VMInternals: private native static void prepareClassImpl(Class clazz); */
Expand Down Expand Up @@ -9652,6 +9689,7 @@ class INTERPRETER_CLASS
JUMP_TABLE_ENTRY(J9_BCLOOP_SEND_TARGET_INL_UNSAFE_UNINITIALIZEDDEFAULTVALUE),
JUMP_TABLE_ENTRY(J9_BCLOOP_SEND_TARGET_INL_UNSAFE_VALUEHEADERSIZE),
JUMP_TABLE_ENTRY(J9_BCLOOP_SEND_TARGET_INL_UNSAFE_ISFLATTENEDARRAY),
JUMP_TABLE_ENTRY(J9_BCLOOP_SEND_TARGET_INL_UNSAFE_ISFLATTENED),
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
JUMP_TABLE_ENTRY(J9_BCLOOP_SEND_TARGET_INL_INTERNALS_GET_INTERFACES),
JUMP_TABLE_ENTRY(J9_BCLOOP_SEND_TARGET_INL_ARRAY_NEW_ARRAY_IMPL),
Expand Down Expand Up @@ -10221,6 +10259,8 @@ runMethod: {
PERFORM_ACTION(inlUnsafeValueHeaderSize(REGISTER_ARGS));
JUMP_TARGET(J9_BCLOOP_SEND_TARGET_INL_UNSAFE_ISFLATTENEDARRAY):
PERFORM_ACTION(inlUnsafeIsFlattenedArray(REGISTER_ARGS));
JUMP_TARGET(J9_BCLOOP_SEND_TARGET_INL_UNSAFE_ISFLATTENED):
PERFORM_ACTION(inlUnsafeIsFlattened(REGISTER_ARGS));
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
JUMP_TARGET(J9_BCLOOP_SEND_TARGET_INL_INTERNALS_GET_INTERFACES):
PERFORM_ACTION(inlInternalsGetInterfaces(REGISTER_ARGS));
Expand Down
9 changes: 6 additions & 3 deletions runtime/vm/ValueTypeHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,12 @@ getFlattenableFieldOffset(J9Class *fieldOwner, J9ROMFieldShape *field)
BOOLEAN
isFlattenableFieldFlattened(J9Class *fieldOwner, J9ROMFieldShape *field)
{
Assert_VM_notNull(fieldOwner);
Assert_VM_notNull(field);
BOOLEAN fieldFlattened = J9_IS_FIELD_FLATTENED(getFlattenableFieldType(fieldOwner, field), field);
BOOLEAN fieldFlattened = FALSE;
if (NULL != fieldOwner->flattenedClassCache) {
Assert_VM_notNull(fieldOwner);
Assert_VM_notNull(field);
fieldFlattened = J9_IS_FIELD_FLATTENED(getFlattenableFieldType(fieldOwner, field), field);
}

return fieldFlattened;
}
Expand Down
1 change: 1 addition & 0 deletions runtime/vm/bindnatv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ static inlMapping mappings[] = {
{ "Java_jdk_internal_misc_Unsafe_uninitializedDefaultValue__Ljava_lang_Class_2", J9_BCLOOP_SEND_TARGET_INL_UNSAFE_UNINITIALIZEDDEFAULTVALUE },
{ "Java_jdk_internal_misc_Unsafe_valueHeaderSize__Ljava_lang_Class_2", J9_BCLOOP_SEND_TARGET_INL_UNSAFE_VALUEHEADERSIZE },
{ "Java_jdk_internal_misc_Unsafe_isFlattenedArray__Ljava_lang_Class_2", J9_BCLOOP_SEND_TARGET_INL_UNSAFE_ISFLATTENEDARRAY },
{ "Java_jdk_internal_misc_Unsafe_isFlattened__Ljava_lang_reflect_Field_2", J9_BCLOOP_SEND_TARGET_INL_UNSAFE_ISFLATTENED },
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
{ "Java_java_lang_Thread_onSpinWait__", J9_BCLOOP_SEND_TARGET_INL_THREAD_ON_SPIN_WAIT },
#if JAVA_SPEC_VERSION >= 11
Expand Down

0 comments on commit 1e7404f

Please sign in to comment.