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

New NullRestricted Attribute in Project Valhalla #17340

Closed
hangshao0 opened this issue May 4, 2023 · 13 comments · Fixed by #19995
Closed

New NullRestricted Attribute in Project Valhalla #17340

hangshao0 opened this issue May 4, 2023 · 13 comments · Fixed by #19995
Assignees
Labels
comp:vm project:valhalla Used to track Project Valhalla related work

Comments

@hangshao0
Copy link
Contributor

In the last spec: https://cr.openjdk.org/~dlsmith/jep401/jep401-20230428/specs/flattened-heap-jvms.html, a NullRestricted attribute is introduced.

It indicates that the field cannot be null. putfield and putstatic will throw NPE if there is an attempt to assigned null to such fields. The null restricted field needs to be initialized to the default instance.

@hangshao0 hangshao0 added comp:vm project:valhalla Used to track Project Valhalla related work labels May 4, 2023
@hangshao0
Copy link
Contributor Author

The null restricted field needs to be initialized to the default instance.

OpenJ9 is already doing this for Q types.

@hangshao0
Copy link
Contributor Author

FYI @theresa-m

@theresa-m theresa-m self-assigned this Jun 30, 2023
@theresa-m
Copy link
Contributor

@hangshao0 can you point me to where this is happening in the code?

@hangshao0
Copy link
Contributor Author

can you point me to where this is happening in the code?

The question is regarding #17340 (comment), i.e. where Q type is initialized to the default instance ?

@theresa-m
Copy link
Contributor

can you point me to where this is happening in the code?

The question is regarding #17340 (comment), i.e. where Q type is initialized to the default instance ?

yes.

@hangshao0
Copy link
Contributor Author

The default instance of a value type is allocated here:

if (J9_IS_J9CLASS_VALUETYPE(clazz)) {
PUSH_OBJECT_IN_SPECIAL_FRAME(currentThread, initializationLock);
/* Preparation is the earliest point where the defaultValue would needed.
* I.e pre-filling static fields. Therefore, the defaultValue must be allocated at
* the end of verification
*/
j9object_t defaultValue = vm->memoryManagerFunctions->J9AllocateObject(currentThread, clazz, J9_GC_ALLOCATE_OBJECT_TENURED | J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);
initializationLock = POP_OBJECT_IN_SPECIAL_FRAME(currentThread);
clazz = VM_VMHelpers::currentClass(clazz);
if (NULL == defaultValue) {
setHeapOutOfMemoryError(currentThread);
goto done;
}
j9object_t *defaultValueAddress = &(clazz->flattenedClassCache->defaultValue);
J9STATIC_OBJECT_STORE(currentThread, clazz, defaultValueAddress, defaultValue);

The Q type instance fields are set here:

vmThread->javaVM->internalVMFunctions->defaultValueWithUnflattenedFlattenables(vmThread, clazz, objectPtr);

defaultValueWithUnflattenedFlattenables(J9VMThread *currentThread, J9Class *clazz, j9object_t instance)
{
J9FlattenedClassCacheEntry * entry = NULL;
J9Class * entryClazz = NULL;
UDATA length = clazz->flattenedClassCache->numberOfEntries;
UDATA const objectHeaderSize = J9VMTHREAD_OBJECT_HEADER_SIZE(currentThread);
MM_ObjectAccessBarrierAPI objectAccessBarrier(currentThread);
for (UDATA index = 0; index < length; index++) {
entry = J9_VM_FCC_ENTRY_FROM_CLASS(clazz, index);
entryClazz = J9_VM_FCC_CLASS_FROM_ENTRY(entry);
if (!J9_VM_FCC_ENTRY_IS_STATIC_FIELD(entry) && !J9_IS_FIELD_FLATTENED(entryClazz, entry->field)) {
objectAccessBarrier.inlineMixedObjectStoreObject(currentThread,
instance,
entry->offset + objectHeaderSize,
entryClazz->flattenedClassCache->defaultValue,
false);
}
}
}

defaultValueWithUnflattenedFlattenables() uses the default instance to set the fields if they are not flattened (inlined). Note the flattenedClassCache struct has all the J9Class of the Q type fields.

@theresa-m
Copy link
Contributor

theresa-m commented Aug 17, 2023

The remaining tasks for this issue are:

Remaining tasks:

  • NPE for aastore. For arrays javac does not store a NullRestricted flag with the field but instead inserts java/lang/Class.asNullRestrictedType and java/util/Objects.requireNonNull before calling aastore. asNullRestrictedType will need to be implemented.

@theresa-m
Copy link
Contributor

theresa-m commented Aug 29, 2023

@hangshao0 are there any other class verification checks you think should be added for NullRestricted? See the previous comment for all prs that are open against this issue.

@hangshao0
Copy link
Contributor Author

I haven't reviewed #18030 yet. But notice the following in the spec:

Section 5.3.5.
5. For each non-static field of C declared with a NullRestricted attribute......the class or interface named by the field's type must be a value class with an ImplicitCreation attribute whose ACC_DEFAULT flag is set. If not, loading throws an IncompatibleClassChangeError

Section 5.4.2
1. For each static field of C declared with a NullRestricted attribute......The resolved type must be of a value class with an ImplicitCreation attribute whose ACC_DEFAULT flag set. If not, preparation fails with an IncompatibleClassChangeError.

Section 6.5
if the value to store is null and the resolved field is declared with a NullRestricted attribute, the withfield instruction throws a NullPointerException.

@theresa-m
Copy link
Contributor

Thanks, #18030 should cover the first two but I didn't notice there was a specific error to be thrown. I'll update that.

@theresa-m
Copy link
Contributor

What about this one? Section 6.5.

The initial value of any instance field declared with a NullRestricted attribute is the initial instance of the field's class. The initial value of any instance field of a primitive type is the default value of the type ([2.3](https://docs.oracle.com/javase/specs/jvms/se16/html/jvms-2.html#jvms-2.3)). The initial value of any other instance field is null.

@hangshao0
Copy link
Contributor Author

What about this one? Section 6.5.

We are already doing that. See defaultValueWithUnflattenedFlattenables() where we are using the default initial instance (flattenedClassCache->defaultValue) to initialize the fields that are not flattened. For flattened fields, they are initialized to all zeros.

We need to change J9_IS_FIELD_FLATTENED() to include the check of null restricted attribute. Currently, it checks if the field class is flattened and it is not a volatile field > 8 bytes. We should only flatten null restricted fields, so the check for null restricted field should be added. In addition, we need to eventually replace all the places doing 'Q' type checks with null restricted attribute checks.

But I guess making the above changes now will break some tests, as javac is not updated to generate null restricted attribute yet in the default branch of Valhalla repo.

hangshao0 added a commit to hangshao0/openj9 that referenced this issue Sep 6, 2023
issue eclipse-openj9#17340

Signed-off-by: Hang Shao <hangshao@ca.ibm.com>
a7ehuo added a commit to a7ehuo/openj9 that referenced this issue Sep 11, 2023
This applies to `putfield`, `putstatic`, and `withfield`.

Related: eclipse-openj9#17340

Signed-off-by: Annabelle Huo <Annabelle.Huo@ibm.com>
theresa-m added a commit to theresa-m/openj9 that referenced this issue May 30, 2024
This change is needed to support @ImplicitlyConstructible and @NullRestricted annotations for functional tests. See eclipse-openj9#19459

In this change:
- J9ROMCLASS_IS_VALUE macro checks for ACC_IDENTITY flag instead of ACC_VALUE
- Remove J9AccValueType from codebase

There is more work to be done to fully remove ACC_VALUE (eclipse-openj9#18829) such as removing CFR_ACC_VALUE and adding runtime class file verification checks. Because functional value type tests are not able to run currently due to a recent update of the extensions repository I am making just a few changes toward getting those working.

I am also removing the assert in JVM_IsNullRestrictedArray which is triggered when building OpenJ9. This method can't be implemented right now because OpenJ9 doesn't have support for null restricted arrays yet. See eclipse-openj9#17340
theresa-m added a commit to theresa-m/openj9 that referenced this issue May 30, 2024
This change is needed to support @ImplicitlyConstructible and @NullRestricted annotations for functional tests. See eclipse-openj9#19459

In this change:
- J9ROMCLASS_IS_VALUE macro checks for ACC_IDENTITY flag instead of ACC_VALUE
- Remove J9AccValueType from codebase

There is more work to be done to fully remove ACC_VALUE (eclipse-openj9#18829) such as removing CFR_ACC_VALUE and adding runtime class file verification checks. Because functional value type tests are not able to run currently due to a recent update of the extensions repository I am making just a few changes toward getting those working.

I am also removing the assert in JVM_IsNullRestrictedArray which is triggered when building OpenJ9. This method can't be implemented right now because OpenJ9 doesn't have support for null restricted arrays yet. See eclipse-openj9#17340 eclipse-openj9#19460
theresa-m added a commit to theresa-m/openj9 that referenced this issue May 30, 2024
This change is needed to support @ImplicitlyConstructible and @NullRestricted annotations for functional tests. See eclipse-openj9#19459

In this change:
- J9ROMCLASS_IS_VALUE macro checks for ACC_IDENTITY flag instead of ACC_VALUE
- Remove J9AccValueType from codebase

There is more work to be done to fully remove ACC_VALUE (eclipse-openj9#18829) such as removing CFR_ACC_VALUE and adding runtime class file verification checks. Because functional value type tests are not able to run currently due to a recent update of the extensions repository I am making just a few changes toward getting those working.

I am also removing the assert in JVM_IsNullRestrictedArray which is triggered when building OpenJ9. This method can't be implemented right now because OpenJ9 doesn't have support for null restricted arrays yet. See eclipse-openj9#17340 eclipse-openj9#19460
theresa-m added a commit to theresa-m/openj9 that referenced this issue May 30, 2024
This change is needed to support @ImplicitlyConstructible and @NullRestricted annotations for functional tests. See eclipse-openj9#19459

In this change:
- J9ROMCLASS_IS_VALUE macro checks for ACC_IDENTITY flag instead of ACC_VALUE
- Remove J9AccValueType from codebase

There is more work to be done to fully remove ACC_VALUE (eclipse-openj9#18829) such as removing CFR_ACC_VALUE and adding runtime class file verification checks. Because functional value type tests are not able to run currently due to a recent update of the extensions repository I am making just a few changes toward getting those working.

I am also removing the assert in JVM_IsNullRestrictedArray which is triggered when building OpenJ9. This method can't be implemented right now because OpenJ9 doesn't have support for null restricted arrays yet. See eclipse-openj9#17340 eclipse-openj9#19460
theresa-m added a commit to theresa-m/openj9 that referenced this issue Jun 3, 2024
This change is needed to support @ImplicitlyConstructible and @NullRestricted annotations for functional tests. See eclipse-openj9#19459

In this change:
- J9ROMCLASS_IS_VALUE macro checks for ACC_IDENTITY flag instead of ACC_VALUE
- Remove J9AccValueType from codebase

There is more work to be done to fully remove ACC_VALUE (eclipse-openj9#18829) such as removing CFR_ACC_VALUE and adding runtime class file verification checks. Because functional value type tests are not able to run currently due to a recent update of the extensions repository I am making just a few changes toward getting those working.

I am also removing the assert in JVM_IsNullRestrictedArray which is triggered when building OpenJ9. This method can't be implemented right now because OpenJ9 doesn't have support for null restricted arrays yet. See eclipse-openj9#17340 eclipse-openj9#19460
AswathySK pushed a commit to AswathySK/openj9 that referenced this issue Jun 4, 2024
This change is needed to support @ImplicitlyConstructible and @NullRestricted annotations for functional tests. See eclipse-openj9#19459

In this change:
- J9ROMCLASS_IS_VALUE macro checks for ACC_IDENTITY flag instead of ACC_VALUE
- Remove J9AccValueType from codebase

There is more work to be done to fully remove ACC_VALUE (eclipse-openj9#18829) such as removing CFR_ACC_VALUE and adding runtime class file verification checks. Because functional value type tests are not able to run currently due to a recent update of the extensions repository I am making just a few changes toward getting those working.

I am also removing the assert in JVM_IsNullRestrictedArray which is triggered when building OpenJ9. This method can't be implemented right now because OpenJ9 doesn't have support for null restricted arrays yet. See eclipse-openj9#17340 eclipse-openj9#19460
@theresa-m
Copy link
Contributor

This issue will be closed by #19995. Further null restricted error handling will be related to CheckedType support #19764

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:vm project:valhalla Used to track Project Valhalla related work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants