@@ -203,13 +203,18 @@ public TypeData computeTypeData(AnalysisType type) {
203
203
return data ;
204
204
}
205
205
206
+ void markTypeReachable (AnalysisType type , ScanReason reason ) {
207
+ if (universe .sealed () && !type .isReachable ()) {
208
+ throw AnalysisError .typeNotFound (type );
209
+ }
210
+ type .registerAsReachable (reason );
211
+ }
212
+
206
213
void markTypeInstantiated (AnalysisType type , ScanReason reason ) {
207
- if (universe .sealed ()) {
208
- AnalysisError .guarantee (type .isReachable (), "The type %s should have been reachable during analysis." , type );
209
- AnalysisError .guarantee (type .isInstantiated (), "The type %s should have been instantiated during analysis." , type );
210
- } else {
211
- type .registerAsInstantiated (reason );
214
+ if (universe .sealed () && !type .isInstantiated ()) {
215
+ throw AnalysisError .typeNotFound (type );
212
216
}
217
+ type .registerAsInstantiated (reason );
213
218
}
214
219
215
220
public JavaConstant getImageHeapConstant (JavaConstant constant ) {
@@ -278,9 +283,9 @@ protected ImageHeapConstant getOrCreateImageHeapConstant(JavaConstant javaConsta
278
283
return existingTask instanceof ImageHeapConstant ? (ImageHeapConstant ) existingTask : ((AnalysisFuture <ImageHeapConstant >) existingTask ).ensureDone ();
279
284
}
280
285
281
- private static void ensureFieldPositionsComputed (ImageHeapConstant baseLayerConstant , ScanReason reason ) {
286
+ private void ensureFieldPositionsComputed (ImageHeapConstant baseLayerConstant , ScanReason reason ) {
282
287
AnalysisType objectType = baseLayerConstant .getType ();
283
- objectType . registerAsReachable ( reason );
288
+ markTypeReachable ( objectType , reason );
284
289
objectType .getStaticFields ();
285
290
objectType .getInstanceFields (true );
286
291
}
@@ -331,7 +336,7 @@ private ImageHeapArray createImageHeapObjectArray(JavaConstant constant, Analysi
331
336
/* Read hosted array element values only when the array is initialized. */
332
337
array .constantData .hostedValuesReader = new AnalysisFuture <>(() -> {
333
338
checkSealed (reason , "Trying to materialize an ImageHeapObjectArray for %s after the ImageHeapScanner is sealed." , constant );
334
- type . registerAsReachable ( reason );
339
+ markTypeReachable ( type , reason );
335
340
ScanReason arrayReason = new ArrayScan (type , array , reason );
336
341
Object [] elementValues = new Object [length ];
337
342
for (int idx = 0 ; idx < length ; idx ++) {
@@ -367,10 +372,10 @@ private ImageHeapInstance createImageHeapInstance(JavaConstant constant, Analysi
367
372
/* If this is a Class constant register the corresponding type as reachable. */
368
373
AnalysisType typeFromClassConstant = (AnalysisType ) constantReflection .asJavaType (instance );
369
374
if (typeFromClassConstant != null ) {
370
- typeFromClassConstant . registerAsReachable ( reason );
375
+ markTypeReachable ( typeFromClassConstant , reason );
371
376
}
372
377
/* We are about to query the type's fields, the type must be marked as reachable. */
373
- type . registerAsReachable ( reason );
378
+ markTypeReachable ( type , reason );
374
379
ResolvedJavaField [] instanceFields = type .getInstanceFields (true );
375
380
Object [] hostedFieldValues = new Object [instanceFields .length ];
376
381
for (ResolvedJavaField javaField : instanceFields ) {
0 commit comments