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

Always create nullable array before null-restricted #20139

Merged
merged 1 commit into from
Sep 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
1 change: 1 addition & 0 deletions runtime/oti/j9.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ static const struct { \
#define J9_IS_NULL_RESTRICTED_FIELD_FLATTENED(fieldClazz, romFieldShape) FALSE
#define J9_VALUETYPE_FLATTENED_SIZE(clazz)((UDATA) 0) /* It is not possible for this macro to be used since we always check J9_IS_J9CLASS_FLATTENED before ever using it. */
#define J9_IS_J9ARRAYCLASS_NULL_RESTRICTED(clazz) FALSE
#define J9CLASS_GET_NULLRESTRICTED_ARRAY(clazz) NULL
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
#define IS_REF_OR_VAL_SIGNATURE(firstChar) ('L' == (firstChar))

Expand Down
47 changes: 32 additions & 15 deletions runtime/vm/classsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,8 @@ findPrimitiveArrayClass(J9JavaVM* vm, jchar sigChar)
}
}


/**
* @internal
*
* Allocates and fills in the relevant fields of an array class
*/
J9Class *
internalCreateArrayClass(J9VMThread *vmThread, J9ROMArrayClass *romClass, J9Class *elementClass)
{
return internalCreateArrayClassWithOptions(vmThread, romClass, elementClass, 0);
}

J9Class *
internalCreateArrayClassWithOptions(J9VMThread *vmThread, J9ROMArrayClass *romClass, J9Class *elementClass, UDATA options)
static J9Class *
internalCreateArrayClassHelper(J9VMThread *vmThread, J9ROMArrayClass *romClass, J9Class *elementClass, UDATA options)
{
J9Class *result = NULL;
j9object_t heapClass = J9VM_J9CLASS_TO_HEAPCLASS(elementClass);
Expand All @@ -217,8 +205,12 @@ internalCreateArrayClassWithOptions(J9VMThread *vmThread, J9ROMArrayClass *romCl
* creating an instance of the array. Element class init must be done
* before the arrayClass is created so that in the case of an init failure
* the arrayClass is not temporarily exposed.
* Don't try to initialize class for null-restricted array creation since
* the regular arrayClass will always be created first.
*/
if (J9_IS_J9CLASS_ALLOW_DEFAULT_VALUE(elementClass)) {
if (J9_IS_J9CLASS_ALLOW_DEFAULT_VALUE(elementClass)
&& J9_ARE_NO_BITS_SET(options, J9_FINDCLASS_FLAG_CLASS_OPTION_NULL_RESTRICTED_ARRAY)
) {
UDATA initStatus = elementClass->initializeStatus;
if ((J9ClassInitSucceeded != initStatus) && ((UDATA)vmThread != initStatus)) {
initializeClass(vmThread, elementClass);
Expand Down Expand Up @@ -267,6 +259,31 @@ internalCreateArrayClassWithOptions(J9VMThread *vmThread, J9ROMArrayClass *romCl
return result;
}

/**
* @internal
*
* Allocates and fills in the relevant fields of an array class
*/
J9Class *
internalCreateArrayClass(J9VMThread *vmThread, J9ROMArrayClass *romClass, J9Class *elementClass)
{
return internalCreateArrayClassHelper(vmThread, romClass, elementClass, 0);
}

J9Class *
internalCreateArrayClassWithOptions(J9VMThread *vmThread, J9ROMArrayClass *romClass, J9Class *elementClass, UDATA options)
{
/* Create elementClass's arrayClass as a prerequisite to nullRestrictedArrayClass */
if (J9_ARE_ALL_BITS_SET(options, J9_FINDCLASS_FLAG_CLASS_OPTION_NULL_RESTRICTED_ARRAY)
&& (NULL == elementClass->arrayClass)
) {
if (NULL == internalCreateArrayClassHelper(vmThread, romClass, elementClass, 0)) {
return NULL;
}
}
return internalCreateArrayClassHelper(vmThread, romClass, elementClass, options);
}

/**
* Peek the classHashTable to see if the `className` class has already been loaded by `classLoader`.
*
Expand Down
8 changes: 2 additions & 6 deletions runtime/vm/createramclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2404,18 +2404,14 @@ internalCreateRAMClassDone(J9VMThread *vmThread, J9ClassLoader *classLoader, J9C
if (J9ROMCLASS_IS_ARRAY(romClass)) {
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (J9_ARE_ALL_BITS_SET(options, J9_FINDCLASS_FLAG_CLASS_OPTION_NULL_RESTRICTED_ARRAY)) {
((J9ArrayClass *)state->ramClass)->companionArray = elementClass->arrayClass;
elementClass->nullRestrictedArrayClass = state->ramClass;
((J9ArrayClass *)elementClass->arrayClass)->companionArray = elementClass->nullRestrictedArrayClass;
} else
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
{
((J9ArrayClass *)elementClass)->arrayClass = state->ramClass;
}
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if ((NULL != elementClass->nullRestrictedArrayClass) && (NULL != elementClass->arrayClass)) {
((J9ArrayClass *)elementClass->arrayClass)->companionArray = elementClass->nullRestrictedArrayClass;
((J9ArrayClass *)elementClass->nullRestrictedArrayClass)->companionArray = elementClass->arrayClass;
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
/* Assigning into the arrayClass field creates an implicit reference to the class from its class loader */
javaVM->memoryManagerFunctions->j9gc_objaccess_postStoreClassToClassLoader(vmThread, classLoader, state->ramClass);
}
Expand Down