@@ -98,7 +98,7 @@ public void scanBootImageHeapRoots(Comparator<AnalysisField> fieldComparator, Co
9898 fields = fieldsList ;
9999 }
100100 for (AnalysisField field : fields ) {
101- if (Modifier .isStatic (field .getModifiers ()) && field .getJavaKind () == JavaKind . Object && field . isRead ()) {
101+ if (Modifier .isStatic (field .getModifiers ()) && field .isRead ()) {
102102 execute (() -> scanRootField (field ));
103103 }
104104 }
@@ -157,7 +157,9 @@ protected void scanField(AnalysisField field, JavaConstant receiver, ScanReason
157157 /* The value is not available yet. */
158158 return ;
159159 }
160- JavaConstant fieldValue = bb .getUniverse ().getHeapScanner ().readFieldValue (field , receiver );
160+ assert isUnwrapped (receiver );
161+
162+ JavaConstant fieldValue = readFieldValue (field , receiver );
161163 if (fieldValue == null ) {
162164 StringBuilder backtrace = new StringBuilder ();
163165 buildObjectBacktrace (bb , reason , backtrace );
@@ -179,20 +181,47 @@ protected void scanField(AnalysisField field, JavaConstant receiver, ScanReason
179181 * referenced elements are being scanned.
180182 */
181183 scanConstant (fieldValue , reason );
184+ } else if (fieldValue .getJavaKind ().isNumericInteger ()) {
185+ scanningObserver .forPrimitiveFieldValue (receiver , field , fieldValue , reason );
182186 }
183187
184188 } catch (UnsupportedFeatureException ex ) {
185189 unsupportedFeatureDuringFieldScan (bb , field , receiver , ex , reason );
186190 }
187191 }
188192
193+ protected JavaConstant readFieldValue (AnalysisField field , JavaConstant receiver ) {
194+ return bb .getConstantReflectionProvider ().readFieldValue (field , receiver );
195+ }
196+
197+ /**
198+ * Must unwrap the receiver if it is an ImageHeapConstant to scan the hosted value, if any, for
199+ * verification, otherwise the verification just compares shadow heap with shadow heap for
200+ * embedded roots, which is completely useless.
201+ */
202+ private static JavaConstant maybeUnwrap (JavaConstant receiver ) {
203+ if (receiver instanceof ImageHeapConstant heapConstant && heapConstant .getHostedObject () != null ) {
204+ return heapConstant .getHostedObject ();
205+ }
206+ return receiver ;
207+ }
208+
209+ private static boolean isUnwrapped (JavaConstant receiver ) {
210+ if (receiver instanceof ImageHeapConstant heapConstant ) {
211+ // Non hosted backed ImageHeapConstant is considered unwrapped
212+ return heapConstant .getHostedObject () == null ;
213+ }
214+ return true ;
215+ }
216+
189217 /**
190218 * Scans constant arrays, one element at the time.
191219 *
192220 * @param array the array to be scanned
193221 */
194222 protected final void scanArray (JavaConstant array , ScanReason prevReason ) {
195223
224+ assert isUnwrapped (array );
196225 AnalysisType arrayType = bb .getMetaAccess ().lookupJavaType (array );
197226 ScanReason reason = new ArrayScan (arrayType , array , prevReason );
198227
@@ -246,13 +275,14 @@ public void scanConstant(JavaConstant value, ScanReason reason) {
246275 bb .registerTypeAsInHeap (bb .getMetaAccess ().lookupJavaType (value ), reason );
247276 return ;
248277 }
249- Object valueObj = (value instanceof ImageHeapConstant ) ? value : constantAsObject (bb , value );
278+ JavaConstant unwrappedValue = maybeUnwrap (value );
279+ Object valueObj = unwrappedValue instanceof ImageHeapConstant ? unwrappedValue : constantAsObject (bb , unwrappedValue );
250280 if (scannedObjects .putAndAcquire (valueObj ) == null ) {
251281 try {
252- scanningObserver .forScannedConstant (value , reason );
282+ scanningObserver .forScannedConstant (unwrappedValue , reason );
253283 } finally {
254284 scannedObjects .release (valueObj );
255- WorklistEntry worklistEntry = new WorklistEntry (value , reason );
285+ WorklistEntry worklistEntry = new WorklistEntry (unwrappedValue , reason );
256286 if (executor != null ) {
257287 executor .execute (debug -> doScan (worklistEntry ));
258288 } else {
@@ -339,12 +369,22 @@ public static String asString(BigBang bb, JavaConstant constant, boolean appendT
339369 return "null" ;
340370 }
341371 AnalysisType type = bb .getMetaAccess ().lookupJavaType (constant );
342- if (constant instanceof ImageHeapConstant ) {
343- // Checkstyle: allow Class.getSimpleName
344- return constant .getClass ().getSimpleName () + "<" + type .toJavaName () + ">" ;
345- // Checkstyle: disallow Class.getSimpleName
372+ JavaConstant hosted = constant ;
373+ if (constant instanceof ImageHeapConstant heapConstant ) {
374+ JavaConstant hostedObject = heapConstant .getHostedObject ();
375+ if (hostedObject == null ) {
376+ // Checkstyle: allow Class.getSimpleName
377+ return constant .getClass ().getSimpleName () + "<" + type .toJavaName () + ">" ;
378+ // Checkstyle: disallow Class.getSimpleName
379+ }
380+ hosted = hostedObject ;
381+ }
382+
383+ if (hosted .getJavaKind ().isPrimitive ()) {
384+ return hosted .toValueString ();
346385 }
347- Object obj = constantAsObject (bb , constant );
386+
387+ Object obj = constantAsObject (bb , hosted );
348388 String str = type .toJavaName () + '@' + Integer .toHexString (System .identityHashCode (obj ));
349389 if (appendToString ) {
350390 try {
@@ -381,7 +421,7 @@ private void doScan(WorklistEntry entry) {
381421 /* Scan constant's instance fields. */
382422 for (ResolvedJavaField javaField : type .getInstanceFields (true )) {
383423 AnalysisField field = (AnalysisField ) javaField ;
384- if (field .getJavaKind () == JavaKind . Object && field . isRead ()) {
424+ if (field .isRead ()) {
385425 assert !Modifier .isStatic (field .getModifiers ());
386426 scanField (field , entry .constant , entry .reason );
387427 }
@@ -589,15 +629,21 @@ public String toString() {
589629
590630 public static class ArrayScan extends ScanReason {
591631 final AnalysisType arrayType ;
632+ final int idx ;
592633
593634 public ArrayScan (AnalysisType arrayType , JavaConstant array , ScanReason previous ) {
635+ this (arrayType , array , previous , -1 );
636+ }
637+
638+ public ArrayScan (AnalysisType arrayType , JavaConstant array , ScanReason previous , int idx ) {
594639 super (previous , array );
595640 this .arrayType = arrayType ;
641+ this .idx = idx ;
596642 }
597643
598644 @ Override
599645 public String toString (BigBang bb ) {
600- return "indexing into array " + asString (bb , constant );
646+ return "indexing into array " + asString (bb , constant ) + ( idx != - 1 ? " at index " + idx : "" ) ;
601647 }
602648
603649 @ Override
0 commit comments