-
Notifications
You must be signed in to change notification settings - Fork 109
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
8281463: [lworld] VALUE / PRIMITIVE modifiers should be supported by reflection #698
Changes from 2 commits
96578de
f28fb08
f83c35f
482e3f4
33e24a0
c7883a6
cd8d0de
946eea0
9af6875
cab6cae
349a939
f089c22
d6dbe8f
558d873
605d386
8f37b14
a220770
b3a7ea7
dcd5d44
ea58a93
754c41c
dd10bd4
ecd28d1
efdb333
9b2c0f0
b7343b5
28ef42f
e25b124
d3c5b54
9a21fe0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,7 +204,6 @@ public final class Class<T> implements java.io.Serializable, | |
private static final int ENUM = 0x00004000; | ||
private static final int SYNTHETIC = 0x00001000; | ||
private static final int VALUE_CLASS = 0x00000040; | ||
private static final int PERMITS_VALUE = 0x00000100; | ||
private static final int PRIMITIVE_CLASS = 0x00000800; | ||
|
||
private static native void registerNatives(); | ||
|
@@ -511,8 +510,8 @@ private static Class<?> forName(String name, boolean initialize, ClassLoader loa | |
|
||
/** Called after security check for system loader access checks have been made. */ | ||
private static native Class<?> forName0(String name, boolean initialize, | ||
ClassLoader loader, | ||
Class<?> caller) | ||
ClassLoader loader, | ||
Class<?> caller) | ||
throws ClassNotFoundException; | ||
|
||
|
||
|
@@ -1505,6 +1504,14 @@ public Set<AccessFlag> accessFlags() { | |
AccessFlag.Location.CLASS); | ||
} | ||
|
||
/** | ||
* {@return true if this class has the requested {@link AccessFlag}} | ||
* @param flag an {@link AccessFlag} | ||
*/ | ||
public boolean is(AccessFlag flag) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this API needed? We can do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are significant performance concerns. The current implementation of getModifers() is an intrinsic and all of the tests for modifiers are boolean operations against static constants. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new API requires discussion and also whether it needs to be performant. Can you bring this discussion to PR 7445.
|
||
return (getModifiers() & flag.mask()) == flag.mask(); | ||
} | ||
|
||
/** | ||
* If this {@code Class} object represents a local or anonymous | ||
* class within a method, returns a {@link | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,14 +131,12 @@ public enum AccessFlag { | |
* ACC_SUPER or the class file version number, and the flag no longer had any effect. | ||
* Now the flag has been repurposed as ACC_IDENTITY. | ||
*/ | ||
SUPER(0x0000_0020, false, Set.of(Location.CLASS)), | ||
// SUPER(0x0000_0020, false, Set.of(Location.CLASS)), | ||
RogerRiggs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* The access flag {@code ACC_IDENTITY} corresponding to the | ||
* source modifier {@link Modifier#VALUE value} with a mask | ||
* value of {@code 0x0020}. | ||
* The access flag {@code ACC_IDENTITY} with a mask value of {@code 0x0020}. | ||
*/ | ||
IDENTITY(Modifier.IDENTITY, true, Set.of(Location.CLASS)), | ||
IDENTITY(0x0000_0020, false, Set.of(Location.CLASS)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can also be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
||
/** | ||
* The module flag {@code ACC_OPEN} with a mask value of {@code | ||
|
@@ -169,11 +167,9 @@ public enum AccessFlag { | |
STATIC_PHASE(0x0000_0040, false, Set.of(Location.MODULE_REQUIRES)), | ||
|
||
/** | ||
* The access flag {@code ACC_VALUE} corresponding to the | ||
* source modifier {@link Modifier#VALUE value} with a mask | ||
* value of {@code 0x0040}. | ||
* The access flag {@code ACC_VALUE} with a mask value of {@code 0x0040}. | ||
*/ | ||
VALUE(Modifier.VALUE, true, Set.of(Location.CLASS)), | ||
VALUE(0x0000_0040, false, Set.of(Location.CLASS)), | ||
|
||
/** | ||
* The access flag {@code ACC_VOLATILE}, corresponding to the | ||
|
@@ -227,11 +223,9 @@ public enum AccessFlag { | |
Set.of(Location.CLASS, Location.METHOD, Location.INNER_CLASS)), | ||
|
||
/** | ||
* The access flag {@code ACC_PRIMITIVE}, corresponding to the source | ||
* modifier {@link Modifier#PRIMITIVE primitive} with a mask | ||
* value of {@code 0x0800}. | ||
* The access flag {@code ACC_PRIMITIVE} with a mask value of {@code 0x0800}. | ||
*/ | ||
PRIMITIVE(Modifier.PRIMITIVE, true, Set.of(Location.CLASS)), | ||
PRIMITIVE(0x0000_0800, false, Set.of(Location.CLASS)), | ||
|
||
/** | ||
* The access flag {@code ACC_STRICT}, corresponding to the source | ||
|
@@ -431,7 +425,7 @@ private static class LocationToFlags { | |
BRIDGE, VARARGS, NATIVE, | ||
ABSTRACT, STRICT, SYNTHETIC)), | ||
entry(Location.INNER_CLASS, | ||
Set.of(PUBLIC, PRIVATE, PROTECTED, | ||
Set.of(PUBLIC, PRIVATE, PROTECTED, IDENTITY, VALUE, PRIMITIVE, | ||
RogerRiggs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
STATIC, FINAL, INTERFACE, ABSTRACT, | ||
SYNTHETIC, ANNOTATION, ENUM)), | ||
entry(Location.METHOD_PARAMETER, | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -58,6 +58,7 @@ | |||||
*/ | ||||||
package jdk.internal.org.objectweb.asm; | ||||||
|
||||||
import java.lang.reflect.AccessFlag; | ||||||
import java.lang.reflect.Constructor; | ||||||
import java.lang.reflect.InvocationTargetException; | ||||||
import java.lang.reflect.Method; | ||||||
|
@@ -682,8 +683,7 @@ private static void appendDescriptor(final Class<?> clazz, final StringBuilder s | |||||
} | ||||||
|
||||||
static boolean isPrimitiveClass(Class<?> clazz) { | ||||||
int mods = clazz.getModifiers(); | ||||||
return (mods & 0x00000100) != 0; | ||||||
return clazz.is(AccessFlag.PRIMITIVE); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not performant. |
||||||
} | ||||||
|
||||||
// ----------------------------------------------------------------------------------------------- | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -29,7 +29,8 @@ | |||||
* @run main/othervm InnerClassAttributeValuenessTest | ||||||
*/ | ||||||
|
||||||
import com.sun.tools.classfile.AccessFlags; | ||||||
import java.lang.reflect.AccessFlag; | ||||||
import java.util.Set; | ||||||
|
||||||
public class InnerClassAttributeValuenessTest { | ||||||
|
||||||
|
@@ -48,7 +49,12 @@ public static Inner create(int v) { | |||||
} | ||||||
|
||||||
public static void main(String[] args) { | ||||||
if ((Inner.class.getModifiers() & AccessFlags.ACC_PRIMITIVE) == 0) | ||||||
Set<AccessFlag> flags = Inner.class.accessFlags(); | ||||||
System.out.println("accessFlags: " + flags); | ||||||
|
||||||
if (!Inner.class.is(AccessFlag.VALUE)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, not performant. |
||||||
throw new AssertionError("Value flag missing"); | ||||||
if (!Inner.class.is(AccessFlag.PRIMITIVE)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||||||
throw new AssertionError("Primitive Value flag missing"); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VALUE_CLASS
andPRIMITIVE_CLASS
can be removed now and replaced withAccessFlag::mask
.