Skip to content

Commit

Permalink
Merge pull request #16335 from hangshao0/Test
Browse files Browse the repository at this point in the history
Unset Valhalla modifiers in Class.toGenericString()
  • Loading branch information
tajila committed Nov 22, 2022
2 parents defdf9a + 4f81c68 commit 55c52ff
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 17 deletions.
29 changes: 29 additions & 0 deletions jcl/src/java.base/share/classes/java/lang/Class.java
Expand Up @@ -2804,6 +2804,22 @@ public String toGenericString() {
boolean isArray = isArray();
boolean isInterface = !isArray && (0 != (modifiers & Modifier.INTERFACE));

/*[IF INLINE-TYPES]*/
String valueType;
if (Modifier.VALUE == (Modifier.VALUE & modifiers)) {
/**
* Modifier.PRIMITIVE is not added by OpenJDK yet. It shares the same bit as Modifier.STRICT.
* TODO: Change Modifier.STRICT to Modifier.PRIMITIVE.
*/
if (Modifier.STRICT == (Modifier.STRICT & modifiers)) {
valueType = "primitive "; //$NON-NLS-1$
} else {
valueType = "value "; //$NON-NLS-1$
}
} else {
valueType = ""; //$NON-NLS-1$
}
/*[ENDIF] INLINE-TYPES */
// Get kind of type before modifying the modifiers
String kindOfType;
if ((!isArray) && ((modifiers & ANNOTATION) != 0)) {
Expand All @@ -2824,6 +2840,16 @@ public String toGenericString() {
if (isInterface) {
modifiers -= Modifier.INTERFACE;
}
/*[IF INLINE-TYPES]*/
/**
* IDENTITY shares the same bit as SYNCHRONIZED. VALUE shares the same bit as VOLATILE.
* Modifier.toString() is used later in this function which translates them to "synchronized" and "volatile",
* which is incorrect. So remove these bits if they are set.
* Modifier.PRIMITIVE is not added by OpenJDK yet. It shares the same bit as Modifier.STRICT.
* TODO: Change Modifier.STRICT to Modifier.PRIMITIVE.
*/
modifiers &= ~(Modifier.IDENTITY | Modifier.VALUE | Modifier.STRICT);
/*[ENDIF] INLINE-TYPES */

// Build generic string
/*[IF Sidecar19-SE]*/
Expand All @@ -2850,6 +2876,9 @@ public String toGenericString() {
if (result.length() > 0) {
result.append(' ');
}
/*[IF INLINE-TYPES]*/
result.append(valueType);
/*[ENDIF] INLINE-TYPES */
result.append(kindOfType);
result.append(getName());

Expand Down
Expand Up @@ -998,24 +998,34 @@ public void test_getModifiers_classTypes() {
AnnotationClazz.class,
EnumClazz.class,
};
int IDENTITY = 0;
try {
Field f = Modifier.class.getDeclaredField("IDENTITY");
IDENTITY = f.getInt(null);
} catch (NoSuchFieldException e) {
/* Let IDENTITY be 0 in non-Valhalla builds. */
} catch(Exception e) {
Assert.fail("Unexpected exception " + e.getClass().getName() + " thrown when getting the value of modifier");
}

int[] modifiers = new int[] {
0x0000, //
0x0004, // protected
0x0002, // private
0x0000, //
0x0001, // public
0x0010, // final
0x0008, // static
0x0018, // final static
0x0009, // public static
0x0011, // public final
0x0019, // public final static
0x0000, //
0x0410, // static
0x0400, // abstract
0x1001, // public synthetic
0x2608, // static abstract interface annotation
0x4018, // static final enum
0x0000 | IDENTITY, // (Identity)
0x0004 | IDENTITY, // protected (Identity)
0x0002 | IDENTITY, // private (Identity)
0x0000 | IDENTITY, // (Identity)
0x0001 | IDENTITY, // public (Identity)
0x0010 | IDENTITY, // final (Identity)
0x0008 | IDENTITY, // static (Identity)
0x0018 | IDENTITY, // final static (Identity)
0x0009 | IDENTITY, // public static (Identity)
0x0011 | IDENTITY, // public final (Identity)
0x0019 | IDENTITY, // public final static (Identity)
0x0000 | IDENTITY, // (Identity)
0x0410, // static
0x0400 | IDENTITY, // abstract (Identity)
0x1001 | IDENTITY, // public synthetic (Identity)
0x2608, // static abstract interface annotation
0x4018 | IDENTITY, // static final enum (Identity)
};

StringBuilder errors = new StringBuilder();
Expand Down

0 comments on commit 55c52ff

Please sign in to comment.