Update the Lookup specific code against the JDK14 Spec#8657
Update the Lookup specific code against the JDK14 Spec#8657DanHeidinga merged 1 commit intoeclipse-openj9:masterfrom
Conversation
|
The code changes are still ongoing and the internal test case update is temporarily excluded for the moment as the new changes have no backwards compatibility with the old version (which means the tests involved need to be updated/modified to deal with these situations) Reviewer: @DanHeidinga |
3b68d09 to
276e2b4
Compare
0a5357a to
0fe4d0e
Compare
DanHeidinga
left a comment
There was a problem hiding this comment.
More comments to follow but github soft outage preventing me from commenting
There was a problem hiding this comment.
| if ( lookupClass.getName().startsWith("java.lang.invoke.")) { //$NON-NLS-1$ | |
| if (lookupClass.getName().startsWith("java.lang.invoke.")) { //$NON-NLS-1$ |
There was a problem hiding this comment.
@JasonFengJ9 Any thoughts on whether there's a cleaner way to do the jcl preprocessor tags here with less duplication?
There was a problem hiding this comment.
Sincere apology for late response, somehow I didn't catch the git notification (and strangely it didn't show up with mention query in the past).
I think JPP tags could be organized as following:
| static Lookup PUBLIC_LOOKUP = new Lookup(Object.class, Lookup.PUBLIC); | |
| static final int mhMask = | |
| /*[IF Java11] | |
| /*[IF Java14]*/ | |
| Lookup.UNCONDITIONAL; | |
| /*[ELSE]*/ | |
| Lookup.PUBLIC | Lookup.UNCONDITIONAL; | |
| /*[ENDIF] Java14 */ | |
| /*[ELSE] Java11 */ | |
| Lookup.PUBLIC; | |
| /*[ENDIF] Java11 */ | |
| static Lookup PUBLIC_LOOKUP = new Lookup(Object.class, mhMask); |
Alternatively static final int mhMask = could be moved within the JPP decoration to avoid the actual code like
static final int mhMask =
Lookup.PUBLIC;
There was a problem hiding this comment.
I will update the code against the suggestion above by @JasonFengJ9 if there is no other concern on the format.
There was a problem hiding this comment.
The code there has been updated as suggested above.
There was a problem hiding this comment.
Are all the new forms of these ctors used? Let's only add the ones we actually need
There was a problem hiding this comment.
Removed unused constructors as suggested above.
7c16326 to
b419269
Compare
b419269 to
893f1f7
Compare
There was a problem hiding this comment.
Use Objects.requireNonNull(lookupClass) here rather than the explicit method call for a null check
There was a problem hiding this comment.
This is a good use case for a switch statement:
switch(dropMode) {
case PUBLIC:
case MODULE:
case PACKAGE:
case PRIVATE:
case PROTECTED:
case UNCONDITIONAL:
/* dropMode is OK */
break;
default:
/*[MSG "K065R", "The requested lookup mode: 0x{0} is not one of the existing access modes: 0x{1}"]*/
throw new IllegalArgumentException(com.ibm.oti.util.Msg.getString("K065R", Integer.toHexString(dropMode), Integer.toHexString(fullAccessMode)));
}There was a problem hiding this comment.
Agreed and replaced with switch statement.
893f1f7 to
27703cc
Compare
|
The code changes in Considering the difference of behaviour on Java 11 and 14, I will temporarily disable the Lookup specific test (in |
593cac9 to
99faacc
Compare
|
@llxia, please help to double-check the changes in test scripts to see whether it still aligns with the existing test framework. We'd like to disable these tests involved temporarily on JDK14 due to the new changes in Spec and will create another PR to re-evaluate/address them all later. |
There was a problem hiding this comment.
nitpick : pls add Java14 here.
99faacc to
85bb47f
Compare
JasonFengJ9
left a comment
There was a problem hiding this comment.
PUBLIC_LOOKUP part change looks good to me.
85bb47f to
2e5e675
Compare
|
@DanHeidinga, you can keep reviewing the code as there should be no more update except |
|
@tajila Can you review this as well as you've been in this code before? It's well worth reviewing some of the cross-module cases as listed in https://download.java.net/java/early_access/jdk14/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#access-modes |
|
The changes in playlist.xml and testng.xml look good me. Please add comments in playlist and reference to the issue as this is a temporarily exclude. Thanks |
2e5e675 to
f947deb
Compare
Many thanks @llxia , the comments have been added to these playlists involved. |
f947deb to
fd6f62f
Compare
There was a problem hiding this comment.
void.class.isPrimitive() is true
| if ((lookupClass == void.class) || lookupClass.isPrimitive() || lookupClass.isArray()) { | |
| if (lookupClass.isPrimitive() || lookupClass.isArray()) { |
There was a problem hiding this comment.
Agreed and removed lookupClass == void.class against the suggestion above.
There was a problem hiding this comment.
Why would dropLookupMode ever modify the previousAccessClass?
There was a problem hiding this comment.
public static final int UNCONDITIONAL
...
If this lookup mode is set, the previous lookup class is always null.
<----- this is the new change when setting up UNCONDITIONAL since Java 14
The newly added description requires to handle previousAccessClass which is not specific to dropLookupMode() but everywhere when the UNCONDITIONAL bit is set initially.
There was a problem hiding this comment.
void.class.isPrimitive is true so we don't need to first check
There was a problem hiding this comment.
Why is this an exception? I don't see anything about this in the "Access modes" table showing dropLookupMode behaviour in https://download.java.net/java/early_access/jdk14/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#access-modes
It seems like this should apply to all dropped modes & the change to switch (dropMode & newAccessMode) is unnecessary
There was a problem hiding this comment.
As mentioned at #8571 (comment),
public void testDropLookupMode() throws Exception {
Lookup lookup = MethodHandles.privateLookupIn(m5.type1, m4.lookup);
assertTrue((lookup.lookupModes() & MODULE) == 0); <--- MODULE doesn't exist
...
Lookup lookup3 = lookup.dropLookupMode(MODULE);
---> assertTrue(lookup3.lookupModes() == (lookup.lookupModes() & ~(PROTECTED|PRIVATE|PACKAGE)));
Here's the printing message for the test above
[TestNG] Running:
java/lang/invoke/modules/Driver1.java
config jdk.test.ModuleAccessTest.setup(): success
----- testDropLookupMode --------
m4.lookup.lookupModes() = 31
m4.lookup.lookupClass() = class d1.D1
m4.lookup.lookupClass().getModule() = module m4
m5.type1.getModule() = module m5
lookup = e1.E1/d1.D1
lookup.lookupClass = class e1.E1
lookup.lookupClass().getModule() = module m5
lookup.lookupModes() = 15 <--------------------- 0xF or 1111 <---- MODULE doesn't exist
lookup.previousLookupClass() = class d1.D1
lookup.lookupModes() & ~(PROTECTED|PRIVATE|PACKAGE) = 1
lookup3.lookupModes() = 1 <------------------------------ PUBLIC is left eventually
test jdk.test.ModuleAccessTest.testDropLookupMode(): failure
Based on the weird result, the generated lookup doesn't hold the MODULE bit, in which case it shouldn't drop all PROTECTED|PRIVATE|PACKAGE as if the MODULE bit exists if the previous clarification from Oracle (mode to be dropped must exist in the access mode) is reasonable; Otherwise, Oracle should bring up with another explanation as to how this happens and why.
There was a problem hiding this comment.
| && (Modifier.isPublic(targetClassModifiers) || Modifier.isProtected(targetClassModifiers)) | |
| && targetClassIsPublic |
There was a problem hiding this comment.
| /* A protected class (must be a member class) is compiled to a public class as | |
| * the protected flag of this class doesn't exist on the VM level (there is no | |
| * access flag in the binary form representing 'protected') | |
| */ | |
| if (Modifier.isPublic(targetClassModifiers) || Modifier.isProtected(targetClassModifiers)) { | |
| if (targetClassIsPublic) { |
There was a problem hiding this comment.
| && (Modifier.isPublic(targetClassModifiers) || Modifier.isProtected(targetClassModifiers)) | |
| && (targetClassIsPublic) |
There was a problem hiding this comment.
| && (Modifier.isPublic(targetClassModifiers) || Modifier.isProtected(targetClassModifiers)) | |
| && (targetClassIsPublic) |
fd6f62f to
2951b12
Compare
The change is to update the code related to MH.Lookup to deal with the change of the full privilege access and the new concept called previous lookup class introduced in JDK14. Fixes: eclipse-openj9#8570, Fixes: eclipse-openj9#8571 Signed-off-by: Cheng Jin <[email protected]>
2951b12 to
9d59e82
Compare
|
Jenkins test sanity zlinux jdk11,jdk14 |
|
Jenkins test extended xlinux jdk14 |
|
Jenkins test sanity osx jdk8 |
|
I've launched builds on this to ensure it's passing on all platforms and releases. Given the tests pass and behaviour matches the RI, this may be the final form |
|
@ChengJin01 Can you open a PR with this change against the |
DanHeidinga
left a comment
There was a problem hiding this comment.
Approving given this matches the RIs behaviour and the JTREGs.
|
@DanHeidinga , the requested PR against |
The change is to update the code related to MH.Lookup
to deal with the change of the full privilege access
and the new concept called "previous lookup class" introduced
in JDK14.
Fixes: #8570, Fixes: #8571
Signed-off-by: Cheng Jin [email protected]