Repository navigation
Fix inconsistency between J9Class and annotation data when redefine - #13424
Conversation
|
@tajila I am confused about the existing code. This line https://github.com/EricYangIBM/openj9-openjdk-jdk11/blob/openj9/src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java#L119 implies that the start of the byte array holds the number of annotations. However this doesn't copy the number of annotations to the byte array, just the data. I'm not sure how |
The first two bytes of the data is the number of annotations. See |
5d7a868 to
d07f5da
Compare
|
Is there a way to find the start of a J9Class reference that is appended to the byte array? I.e. I think I have to check the size of the reference and subtract it from the length. |
yes basically once you know the size of the array, then you can extract the j9class using the technique you mentioned. The size of j9class will be |
I meant in the java code to pass to getConstantPool |
|
|
17946de to
aa7f323
Compare
|
Can you add a test that verifies there is no timing hole with redefinition. Take a look at |
6009562 to
e423e0e
Compare
|
I'm trying to set the annotationCache to null in the test so that the fetch and parse path is taken. My attempt at nulling the cache using reflection doesn't seem to do anything. I think I may have to set it using the |
|
I don't see why using reflection wouldn't work. The annotationCache doesn't seem to be filtered from reflection. Unsafe and the annotationCacheOffset are used to avoid synchronization when reading the annotationCache field. Regardless, I think you can work around the Unsafe.getUnsafe() restriction by using reflection to get the Unsafe.theUnsafe field. |
|
After adding this code (https://github.com/eclipse-openj9/openj9/pull/13424/files#diff-f52ad38ef1cc6b03312e51701549d9d406fca56be88db1989fe47a4aa08970e1R44-R47), the not null cache path (I added a print) was still taken 99 times out of 100. Perhaps it was overwritten by other threads? |
|
Yes, if any annotation is requested the cache would be recreated. |
|
Setting the cache through the offset doesn't work either. If I add |
|
|
|
It would be good to restore it afterwards for subsequent testing. |
|
Sorry, ignore that, it's for a different cache. |
|
The VM nulls the annotationCache appropriately when classes are redefined, You can look at callers of flushClassLoaderReflectCache(), the test shouldn't need to (and shouldn't) do it. If it's not happening you need to dig into why the VM isn't doing it for your test. If you run the test without the fix, does it reproduce the problem? |
No, the prints show that the cache is not null and the test passes. |
cb88a22 to
9f2f5b4
Compare
|
Added a test for type annotations for implemented interfaces and extended superclasses, passes with the changes, fails without. (Same "constantpool index out of bounds" exception) I had an issue where the second test run would not execute the redefines properly, not sure why. The first test would fail (without the changes) and the second would pass because the redefines were not done. This did not depend on either test; I renamed tests to change the order of execution and still the second test would pass. |
Did you get an error message? |
|
No error messages. It just passed with printlns of the |
|
Jenkins test sanity win jdk8 |
|
Jenkins test sanity,extended plinux jdk11 |
If a class is redefined between annotation fetch and parse, a `Wrong type at constant pool index` or `Constant pool index out of bounds` exception may be thrown due to inconsistency between the annotation data and J9Class. Pass the J9ConstantPool along with the annotation data to ensure that `parseAnnotations` looks up the correct constant pool. - Add new class `InternalConstantPool` that `ConstantPool` will hold an instance of (instead of `InternalRamClass`) - Change `getConstantPool` to take `InternalConstantPool` or `Class` (if `Class`, create `InternalConstantPool` from it). - Change `sun/reflect/ConstantPool` natives to take an `InternalConstantPool` argument so that the correct constant pool is looked up (e.g. after HCR) - Add a jithelper to get `J9ConstantPool` from `J9Class` - Add test that redefines a class while fetching its annotations Closes: eclipse-openj9#10026 Signed-off-by: Eric Yang <eric.yang@ibm.com>
a403d52 to
0bae7e3
Compare
|
Jenkins test sanity,extended plinux jdk11 |
|
JDK8 tests passed |
DanHeidinga
left a comment
There was a problem hiding this comment.
lgtm (didn't review the test code)
|
@tajila any further concerns? Otherwise I'll merge this |
|
LGTM @DanHeidinga you can go ahead |
|
Did anyone try a 32-bit Windows build? I expect the compiler to complain about casts between signed and unsigned types of differing sizes: I think those casts should use |
|
Guessing this is the cause of #13825. I'm creating a revert PR to use for confirming this. |
|
|
|
@EricYangIBM Please create a PR to address Keiths comment above |
Change UDATA casts to use IDATA when casting to and from jlong. PR: eclipse-openj9#13424 Signed-off-by: Eric Yang <eric.yang@ibm.com>
|
I didn't realize the failing test was added by this PR. Reverting as this is the cause of #13825 and also the cause of an internal test failure. Note in the nightly testing the failure #13825 didn't occur on plinux on either jdk8 or jdk11. Maybe more intermittent or doesn't occur on this platform. The failures also didn't occur on jdk17. |
If a class is redefined between annotation fetch and parse, a
Wrong type at constant pool indexorConstant pool index out of boundsexception may be thrown due to inconsistency between the annotation data
and J9Class. Pass the J9ConstantPool along with the annotation data to
ensure that
parseAnnotationslooks up the correct constant pool.InternalConstantPoolthatConstantPoolwill hold aninstance of (instead of
InternalRamClass)getConstantPoolto takeInternalConstantPoolorClass(if
Class, createInternalConstantPoolfrom it).sun/reflect/ConstantPoolnatives to take anInternalConstantPoolargument so that the correct constant pool is looked up (e.g. after HCR)
J9ConstantPoolfromJ9ClassCloses: #10026
Signed-off-by: Eric Yang eric.yang@ibm.com