Skip to content

Commit 1dca6aa

Browse files
OracleLabsAutomationelkorchi
authored andcommitted
[GR-57704] Backport to 23.1: Reset Provider.Service.constructorCache field.
PullRequest: graal/18722
2 parents c7fa1ca + d16da55 commit 1dca6aa

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/ObjectScanner.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ protected void scanField(AnalysisField field, JavaConstant receiver, ScanReason
183183

184184
} catch (UnsupportedFeatureException ex) {
185185
unsupportedFeatureDuringFieldScan(bb, field, receiver, ex, reason);
186+
} catch (AnalysisError analysisError) {
187+
if (analysisError.getCause() instanceof UnsupportedFeatureException ex) {
188+
unsupportedFeatureDuringFieldScan(bb, field, receiver, ex, reason);
189+
} else {
190+
throw analysisError;
191+
}
186192
}
187193
}
188194

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SecuritySubstitutions.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ final class Target_java_security_Provider {
192192
private static Target_java_security_Provider_ServiceKey previousKey;
193193
}
194194

195+
@TargetClass(value = java.security.Provider.class, innerClass = "Service")
196+
final class Target_java_security_Provider_Service {
197+
198+
/**
199+
* The field is lazily initialized on first access. We already have the necessary reflection
200+
* configuration for the reflective lookup at image run time.
201+
*/
202+
@Alias //
203+
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) //
204+
private Object constructorCache;
205+
}
206+
195207
@Platforms(Platform.HOSTED_ONLY.class)
196208
class ServiceKeyComputer implements FieldValueTransformer {
197209
@Override

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -972,11 +972,15 @@ public RecordComponent[] getRecordComponents(Class<?> type) {
972972

973973
@Override
974974
public void registerHeapDynamicHub(Object object, ScanReason reason) {
975-
assert !sealed;
976975
DynamicHub hub = (DynamicHub) object;
977976
Class<?> javaClass = hub.getHostedJavaClass();
978-
if (heapDynamicHubs.add(hub) && !SubstitutionReflectivityFilter.shouldExclude(javaClass, metaAccess, universe)) {
979-
registerTypesForClass(metaAccess.lookupJavaType(javaClass), javaClass);
977+
if (heapDynamicHubs.add(hub)) {
978+
if (sealed) {
979+
throw new UnsupportedFeatureException("Registering new class for reflection when the image heap is already sealed: " + javaClass);
980+
}
981+
if (!SubstitutionReflectivityFilter.shouldExclude(javaClass, metaAccess, universe)) {
982+
registerTypesForClass(metaAccess.lookupJavaType(javaClass), javaClass);
983+
}
980984
}
981985
}
982986

@@ -988,24 +992,32 @@ public Set<DynamicHub> getHeapDynamicHubs() {
988992

989993
@Override
990994
public void registerHeapReflectionField(Field reflectField, ScanReason reason) {
991-
assert !sealed;
992995
AnalysisField analysisField = metaAccess.lookupJavaField(reflectField);
993-
if (heapFields.put(analysisField, reflectField) == null && !SubstitutionReflectivityFilter.shouldExclude(reflectField, metaAccess, universe)) {
994-
registerTypesForField(analysisField, reflectField);
995-
if (analysisField.getDeclaringClass().isAnnotation()) {
996-
processAnnotationField(reflectField);
996+
if (heapFields.put(analysisField, reflectField) == null) {
997+
if (sealed) {
998+
throw new UnsupportedFeatureException("Registering new field for reflection when the image heap is already sealed: " + reflectField);
999+
}
1000+
if (!SubstitutionReflectivityFilter.shouldExclude(reflectField, metaAccess, universe)) {
1001+
registerTypesForField(analysisField, reflectField);
1002+
if (analysisField.getDeclaringClass().isAnnotation()) {
1003+
processAnnotationField(reflectField);
1004+
}
9971005
}
9981006
}
9991007
}
10001008

10011009
@Override
10021010
public void registerHeapReflectionExecutable(Executable reflectExecutable, ScanReason reason) {
1003-
assert !sealed;
10041011
AnalysisMethod analysisMethod = metaAccess.lookupJavaMethod(reflectExecutable);
1005-
if (heapMethods.put(analysisMethod, reflectExecutable) == null && !SubstitutionReflectivityFilter.shouldExclude(reflectExecutable, metaAccess, universe)) {
1006-
registerTypesForMethod(analysisMethod, reflectExecutable);
1007-
if (reflectExecutable instanceof Method && reflectExecutable.getDeclaringClass().isAnnotation()) {
1008-
processAnnotationMethod(false, (Method) reflectExecutable);
1012+
if (heapMethods.put(analysisMethod, reflectExecutable) == null) {
1013+
if (sealed) {
1014+
throw new UnsupportedFeatureException("Registering new method for reflection when the image heap is already sealed: " + reflectExecutable);
1015+
}
1016+
if (!SubstitutionReflectivityFilter.shouldExclude(reflectExecutable, metaAccess, universe)) {
1017+
registerTypesForMethod(analysisMethod, reflectExecutable);
1018+
if (reflectExecutable instanceof Method && reflectExecutable.getDeclaringClass().isAnnotation()) {
1019+
processAnnotationMethod(false, (Method) reflectExecutable);
1020+
}
10091021
}
10101022
}
10111023
}

0 commit comments

Comments
 (0)