Skip to content

Commit b098b68

Browse files
Espresso ClassfileParser: detect jdk.internal.ValueBased
1 parent 5978ab7 commit b098b68

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/ClassfileParser.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import static com.oracle.truffle.espresso.classfile.Constants.ACC_SUPER;
5151
import static com.oracle.truffle.espresso.classfile.Constants.ACC_SYNCHRONIZED;
5252
import static com.oracle.truffle.espresso.classfile.Constants.ACC_SYNTHETIC;
53+
import static com.oracle.truffle.espresso.classfile.Constants.ACC_VALUE_BASED;
5354
import static com.oracle.truffle.espresso.classfile.Constants.ACC_VARARGS;
5455
import static com.oracle.truffle.espresso.classfile.Constants.ACC_VOLATILE;
5556
import static com.oracle.truffle.espresso.classfile.Constants.JVM_RECOGNIZED_CLASS_MODIFIERS;
@@ -893,7 +894,7 @@ RuntimeVisibleAnnotationsAttribute parseRuntimeVisibleAnnotations(int attributeS
893894
flags = switch (location) {
894895
case Method -> parseMethodVMAnnotations(subStream);
895896
case Field -> parseFieldVMAnnotations(subStream);
896-
case Class -> 0;
897+
case Class -> parseClassVMAnnotations(subStream);
897898
};
898899
}
899900

@@ -943,6 +944,20 @@ private int parseFieldVMAnnotations(ClassfileStream subStream) {
943944
}
944945
return flags;
945946
}
947+
948+
private int parseClassVMAnnotations(ClassfileStream subStream) {
949+
int flags = 0;
950+
int count = subStream.readU2();
951+
for (int j = 0; j < count; j++) {
952+
int typeIndex = parseAnnotation(subStream);
953+
// Validation of the type is done at runtime by guest java code.
954+
Symbol<?> annotType = pool.utf8At(typeIndex, "annotation type");
955+
if (ParserTypes.jdk_internal_ValueBased.equals(annotType)) {
956+
flags |= ACC_VALUE_BASED;
957+
}
958+
}
959+
return flags;
960+
}
946961
}
947962

948963
@SuppressWarnings("unchecked")
@@ -1248,6 +1263,10 @@ private Attribute[] parseClassAttributes() throws ValidationException {
12481263
throw classFormatError("Duplicate PermittedSubclasses attribute");
12491264
}
12501265
classAttributes[i] = permittedSubclasses = parsePermittedSubclasses(attributeName);
1266+
} else if (attributeName.equals(ParserNames.RuntimeVisibleAnnotations)) {
1267+
RuntimeVisibleAnnotationsAttribute annotations = commonAttributeParser.parseRuntimeVisibleAnnotations(attributeSize, AnnotationLocation.Class);
1268+
classFlags |= annotations.flags;
1269+
classAttributes[i] = annotations.attribute;
12511270
} else {
12521271
Attribute attr = commonAttributeParser.parseCommonAttribute(attributeName, attributeSize);
12531272
// stream.skip(attributeSize);

espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/Constants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ public final class Constants {
5353

5454
// Not part of the spec, used internally by the VM.
5555
// Methods
56-
public static final int ACC_FINALIZER = 0x00010000;
5756
public static final int ACC_FORCE_INLINE = 0x00020000;
5857
public static final int ACC_LAMBDA_FORM_COMPILED = 0x00040000;
5958
public static final int ACC_CALLER_SENSITIVE = 0x00080000;
6059
public static final int ACC_HIDDEN = 0x00100000; // also for fields
6160
public static final int ACC_SCOPED = 0x00200000;
6261
public static final int ACC_DONT_INLINE = 0x00400000;
6362
// Classes
63+
public static final int ACC_FINALIZER = 0x00010000;
6464
public static final int ACC_IS_HIDDEN_CLASS = 0x04000000; // synchronized with JVM_ACC_IS_HIDDEN_CLASS
65+
public static final int ACC_VALUE_BASED = 0x00020000;
6566
// Fields
6667
public static final int ACC_STABLE = 0x00010000;
6768

espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/descriptors/ParserSymbols.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public static final class ParserTypes {
7575
public static final Symbol<Type> jdk_internal_vm_annotation_ForceInline = SYMBOLS.putType("Ljdk/internal/vm/annotation/ForceInline;");
7676
public static final Symbol<Type> java_lang_invoke_DontInline = SYMBOLS.putType("Ljava/lang/invoke/DontInline;");
7777
public static final Symbol<Type> jdk_internal_vm_annotation_DontInline = SYMBOLS.putType("Ljdk/internal/vm/annotation/DontInline;");
78+
public static final Symbol<Type> jdk_internal_ValueBased = SYMBOLS.putType("Ljdk/internal/ValueBased;");
7879

7980
// ScopedMemoryAccess
8081
public static final Symbol<Type> jdk_internal_misc_ScopedMemoryAccess$Scoped = SYMBOLS.putType("Ljdk/internal/misc/ScopedMemoryAccess$Scoped;");

0 commit comments

Comments
 (0)