Skip to content

Commit 0284fef

Browse files
committed
[GR-38094] Do not store record component accessors on the heap
PullRequest: graal/13399
2 parents 3f83a51 + 331d001 commit 0284fef

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/target/ReflectionMetadataDecoderImpl.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.Arrays;
3535
import java.util.function.Function;
3636

37+
import com.oracle.svm.core.util.VMError;
3738
import org.graalvm.compiler.core.common.util.UnsafeArrayTypeReader;
3839
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
3940
import org.graalvm.nativeimage.ImageSingletons;
@@ -498,7 +499,6 @@ private static Target_java_lang_reflect_RecordComponent decodeRecordComponent(Un
498499
String name = decodeName(buf, info);
499500
Class<?> type = decodeType(buf, info);
500501
String signature = decodeName(buf, info);
501-
Method accessor = (Method) decodeObject(buf, info);
502502
byte[] annotations = decodeByteArray(buf);
503503
byte[] typeAnnotations = decodeByteArray(buf);
504504

@@ -507,7 +507,11 @@ private static Target_java_lang_reflect_RecordComponent decodeRecordComponent(Un
507507
recordComponent.name = name;
508508
recordComponent.type = type;
509509
recordComponent.signature = signature;
510-
recordComponent.accessor = accessor;
510+
try {
511+
recordComponent.accessor = declaringClass.getDeclaredMethod(name);
512+
} catch (NoSuchMethodException e) {
513+
throw VMError.shouldNotReachHere("Record component accessors should have been registered by the analysis.");
514+
}
511515
recordComponent.annotations = annotations;
512516
recordComponent.typeAnnotations = typeAnnotations;
513517
return recordComponent;

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionMetadata.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,13 @@ static class RecordComponentMetadata extends AnnotatedElementMetadata {
213213
final String name;
214214
final HostedType type;
215215
final String signature;
216-
final JavaConstant accessor;
217216

218-
RecordComponentMetadata(HostedType declaringType, String name, HostedType type, String signature, JavaConstant accessor, AnnotationValue[] annotations, TypeAnnotationValue[] typeAnnotations) {
217+
RecordComponentMetadata(HostedType declaringType, String name, HostedType type, String signature, AnnotationValue[] annotations, TypeAnnotationValue[] typeAnnotations) {
219218
super(annotations, typeAnnotations);
220219
this.declaringType = declaringType;
221220
this.name = name;
222221
this.type = type;
223222
this.signature = signature;
224-
this.accessor = accessor;
225223
}
226224
}
227225

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionMetadataEncoderImpl.java

+1-17
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ private RecordComponentMetadata[] getRecordComponents(MetaAccessProvider metaAcc
607607
String name = getRecordComponentName(recordComponent);
608608
HostedType type = (HostedType) metaAccess.lookupJavaType(getRecordComponentType(recordComponent));
609609
String signature = getRecordComponentSignature(recordComponent);
610-
Method accessor = getRecordComponentAccessor(recordComponent);
611610

612611
/* Fill encoders with the necessary values. */
613612
encoders.sourceMethodNames.addObject(name);
@@ -616,13 +615,8 @@ private RecordComponentMetadata[] getRecordComponents(MetaAccessProvider metaAcc
616615
/* Register string and class values in annotations */
617616
AnnotationValue[] annotations = registerAnnotationValues(recordComponent);
618617
TypeAnnotationValue[] typeAnnotations = registerTypeAnnotationValues(recordComponent);
619-
JavaConstant accessorConstant = null;
620-
if (accessor != null) {
621-
accessorConstant = SubstrateObjectConstant.forObject(accessor);
622-
encoders.objectConstants.addObject(accessorConstant);
623-
}
624618

625-
metadata[i] = new RecordComponentMetadata(declaringType, name, type, signature, accessorConstant, annotations, typeAnnotations);
619+
metadata[i] = new RecordComponentMetadata(declaringType, name, type, signature, annotations, typeAnnotations);
626620
}
627621
return metadata;
628622
}
@@ -640,7 +634,6 @@ private RecordComponentMetadata[] getRecordComponents(MetaAccessProvider metaAcc
640634
private static final Method getRecordComponentName = (JavaVersionUtil.JAVA_SPEC >= 17) ? ReflectionUtil.lookupMethod(recordComponentClass, "getName") : null;
641635
private static final Method getRecordComponentType = (JavaVersionUtil.JAVA_SPEC >= 17) ? ReflectionUtil.lookupMethod(recordComponentClass, "getType") : null;
642636
private static final Method getRecordComponentSignature = (JavaVersionUtil.JAVA_SPEC >= 17) ? ReflectionUtil.lookupMethod(recordComponentClass, "getGenericSignature") : null;
643-
private static final Method getRecordComponentAccessor = (JavaVersionUtil.JAVA_SPEC >= 17) ? ReflectionUtil.lookupMethod(recordComponentClass, "getAccessor") : null;
644637

645638
private static String getRecordComponentName(Object recordComponent) {
646639
try {
@@ -666,14 +659,6 @@ private static String getRecordComponentSignature(Object recordComponent) {
666659
}
667660
}
668661

669-
private static Method getRecordComponentAccessor(Object recordComponent) {
670-
try {
671-
return (Method) getRecordComponentAccessor.invoke(recordComponent);
672-
} catch (IllegalAccessException | InvocationTargetException e) {
673-
throw VMError.shouldNotReachHere(e);
674-
}
675-
}
676-
677662
/**
678663
* See {@link ReflectionMetadataDecoderImpl} for the encoding format description.
679664
*/
@@ -986,7 +971,6 @@ private void encodeRecordComponent(UnsafeArrayTypeWriter buf, RecordComponentMet
986971
encodeName(buf, recordComponent.name);
987972
encodeType(buf, recordComponent.type);
988973
encodeName(buf, recordComponent.signature);
989-
encodeObject(buf, recordComponent.accessor);
990974
encodeByteArray(buf, encodeAnnotations(recordComponent.annotations));
991975
encodeByteArray(buf, encodeTypeAnnotations(recordComponent.typeAnnotations));
992976
}

0 commit comments

Comments
 (0)