|
25 | 25 | package com.oracle.svm.reflect.hosted; |
26 | 26 |
|
27 | 27 | import java.util.function.Consumer; |
28 | | -import java.util.function.Function; |
29 | 28 |
|
30 | 29 | import org.graalvm.compiler.core.common.util.UnsafeArrayTypeWriter; |
31 | 30 | import org.graalvm.compiler.debug.GraalError; |
32 | 31 |
|
| 32 | +import com.oracle.svm.core.code.CodeInfoEncoder.Encoders; |
33 | 33 | import com.oracle.svm.util.SubstrateAnnotationExtracter.AnnotationMemberValue; |
34 | 34 | import com.oracle.svm.util.SubstrateAnnotationExtracter.AnnotationValue; |
35 | 35 | import com.oracle.svm.util.SubstrateAnnotationExtracter.ArrayValue; |
36 | 36 | import com.oracle.svm.util.SubstrateAnnotationExtracter.ClassValue; |
37 | 37 | import com.oracle.svm.util.SubstrateAnnotationExtracter.EnumValue; |
| 38 | +import com.oracle.svm.util.SubstrateAnnotationExtracter.ExceptionProxyValue; |
38 | 39 | import com.oracle.svm.util.SubstrateAnnotationExtracter.PrimitiveValue; |
39 | 40 | import com.oracle.svm.util.SubstrateAnnotationExtracter.StringValue; |
40 | 41 | import com.oracle.svm.util.SubstrateAnnotationExtracter.TypeAnnotationValue; |
41 | 42 |
|
42 | 43 | public class AnnotationEncoder { |
43 | | - static void encodeAnnotation(UnsafeArrayTypeWriter buf, AnnotationValue value, Function<Class<?>, Integer> classEncoder, Function<String, Integer> stringEncoder) { |
44 | | - buf.putS4(classEncoder.apply(value.getType())); |
| 44 | + static void encodeAnnotation(UnsafeArrayTypeWriter buf, AnnotationValue value, Encoders encoders) { |
| 45 | + buf.putS4(encoders.sourceClasses.getIndex(value.getType())); |
45 | 46 | buf.putU2(value.getMemberCount()); |
46 | 47 | value.forEachMember((memberName, memberValue) -> { |
47 | | - buf.putS4(stringEncoder.apply(memberName)); |
48 | | - encodeAnnotationMember(buf, memberValue, classEncoder, stringEncoder); |
| 48 | + buf.putS4(encoders.sourceMethodNames.getIndex(memberName)); |
| 49 | + encodeAnnotationMember(buf, memberValue, encoders); |
49 | 50 | }); |
50 | 51 | } |
51 | 52 |
|
52 | | - static void encodeAnnotationMember(UnsafeArrayTypeWriter buf, AnnotationMemberValue memberValue, Function<Class<?>, Integer> classEncoder, Function<String, Integer> stringEncoder) { |
| 53 | + static void encodeAnnotationMember(UnsafeArrayTypeWriter buf, AnnotationMemberValue memberValue, Encoders encoders) { |
53 | 54 | buf.putU1(memberValue.getTag()); |
54 | 55 | if (memberValue instanceof AnnotationValue) { |
55 | | - encodeAnnotation(buf, (AnnotationValue) memberValue, classEncoder, stringEncoder); |
| 56 | + encodeAnnotation(buf, (AnnotationValue) memberValue, encoders); |
56 | 57 | } else if (memberValue instanceof ClassValue) { |
57 | | - buf.putS4(classEncoder.apply(((ClassValue) memberValue).getValue())); |
| 58 | + buf.putS4(encoders.sourceClasses.getIndex(((ClassValue) memberValue).getValue())); |
58 | 59 | } else if (memberValue instanceof EnumValue) { |
59 | | - buf.putS4(classEncoder.apply(((EnumValue) memberValue).getType())); |
60 | | - buf.putS4(stringEncoder.apply(((EnumValue) memberValue).getName())); |
| 60 | + buf.putS4(encoders.sourceClasses.getIndex(((EnumValue) memberValue).getType())); |
| 61 | + buf.putS4(encoders.sourceMethodNames.getIndex(((EnumValue) memberValue).getName())); |
61 | 62 | } else if (memberValue instanceof StringValue) { |
62 | | - buf.putS4(stringEncoder.apply(((StringValue) memberValue).getValue())); |
| 63 | + buf.putS4(encoders.sourceMethodNames.getIndex(((StringValue) memberValue).getValue())); |
63 | 64 | } else if (memberValue instanceof ArrayValue) { |
64 | 65 | buf.putU2(((ArrayValue) memberValue).getElementCount()); |
65 | | - ((ArrayValue) memberValue).forEachElement(element -> encodeAnnotationMember(buf, element, classEncoder, stringEncoder)); |
| 66 | + ((ArrayValue) memberValue).forEachElement(element -> encodeAnnotationMember(buf, element, encoders)); |
66 | 67 | } else if (memberValue instanceof PrimitiveValue) { |
67 | 68 | Object value = ((PrimitiveValue) memberValue).getValue(); |
68 | 69 | switch (memberValue.getTag()) { |
@@ -93,19 +94,21 @@ static void encodeAnnotationMember(UnsafeArrayTypeWriter buf, AnnotationMemberVa |
93 | 94 | default: |
94 | 95 | throw GraalError.shouldNotReachHere("Invalid annotation encoding"); |
95 | 96 | } |
| 97 | + } else if (memberValue instanceof ExceptionProxyValue) { |
| 98 | + buf.putS4(encoders.objectConstants.getIndex(((ExceptionProxyValue) memberValue).getObjectConstant())); |
96 | 99 | } else { |
97 | 100 | throw GraalError.shouldNotReachHere("Invalid annotation member type: " + memberValue.getClass()); |
98 | 101 | } |
99 | 102 | } |
100 | 103 |
|
101 | | - static void encodeTypeAnnotation(UnsafeArrayTypeWriter buf, TypeAnnotationValue value, Function<Class<?>, Integer> classEncoder, Function<String, Integer> stringEncoder) { |
| 104 | + static void encodeTypeAnnotation(UnsafeArrayTypeWriter buf, TypeAnnotationValue value, Encoders encoders) { |
102 | 105 | for (byte b : value.getTargetInfo()) { |
103 | 106 | buf.putU1(b); |
104 | 107 | } |
105 | 108 | for (byte b : value.getLocationInfo()) { |
106 | 109 | buf.putU1(b); |
107 | 110 | } |
108 | | - encodeAnnotation(buf, value.getAnnotationData(), classEncoder, stringEncoder); |
| 111 | + encodeAnnotation(buf, value.getAnnotationData(), encoders); |
109 | 112 | } |
110 | 113 |
|
111 | 114 | static <T> void encodeArray(UnsafeArrayTypeWriter buf, T[] elements, Consumer<T> encoder) { |
|
0 commit comments