@@ -128,7 +128,7 @@ public final class NativeImageHeap implements ImageHeap {
128128 private final Set <Object > knownImmutableObjects = Collections .newSetFromMap (new IdentityHashMap <>());
129129
130130 /** For diagnostic purpose only. */
131- HashMap <ObjectInfo , AdditionalReasonInfo > additionalReasonInfoMap = null ;
131+ HashMap <ObjectInfo , ObjectReachabilityInfo > objectReachabilityInfo = null ;
132132
133133 public NativeImageHeap (AnalysisUniverse aUniverse , HostedUniverse universe , HostedMetaAccess metaAccess , ImageHeapLayouter heapLayouter ) {
134134 this .aUniverse = aUniverse ;
@@ -141,7 +141,7 @@ public NativeImageHeap(AnalysisUniverse aUniverse, HostedUniverse universe, Host
141141 this .minInstanceSize = objectLayout .getMinimumInstanceObjectSize ();
142142 this .minArraySize = objectLayout .getMinimumArraySize ();
143143 if (ImageHeapConnectedComponentsFeature .Options .PrintImageHeapConnectedComponents .getValue ()) {
144- this .additionalReasonInfoMap = new HashMap <>();
144+ this .objectReachabilityInfo = new HashMap <>();
145145 }
146146 assert assertFillerObjectSizes ();
147147 }
@@ -324,7 +324,7 @@ public void addConstant(final JavaConstant constant, boolean immutableFromParent
324324 if (existing == null ) {
325325 addObjectToImageHeap (uncompressed , immutableFromParent , identityHashCode , reason );
326326 } else if (ImageHeapConnectedComponentsFeature .Options .PrintImageHeapConnectedComponents .getValue ()) {
327- additionalReasonInfoMap .get (existing ).addReason (reason );
327+ objectReachabilityInfo .get (existing ).addReason (reason );
328328 }
329329 }
330330
@@ -708,50 +708,6 @@ static class AddObjectData {
708708
709709 private final int imageHeapOffsetInAddressSpace = Heap .getHeap ().getImageHeapOffsetInAddressSpace ();
710710
711- enum InternalReason {
712- InternedStringsTable ,
713- FillerObject ,
714- StaticObjectFields ,
715- DataSection ,
716- StaticPrimitiveFields
717- }
718-
719- final class AdditionalReasonInfo {
720- private final Object firstReason ;
721- private LinkedHashSet <Object > allReasons ;
722- private int objectReachability ;
723-
724- AdditionalReasonInfo (ObjectInfo info , Object firstReason ) {
725- this .firstReason = firstReason ;
726- this .allReasons = null ;
727- this .objectReachability = ObjectReachabilityGroup .getFlagForObjectInfo (info , firstReason , additionalReasonInfoMap );
728- }
729-
730- void addReason (Object additionalReason ) {
731- if (allReasons == null ) {
732- this .allReasons = new LinkedHashSet <>();
733- }
734- this .allReasons .add (additionalReason );
735- this .objectReachability |= ObjectReachabilityGroup .getByReason (additionalReason , additionalReasonInfoMap );
736- }
737-
738- Set <Object > getAllReasons () {
739- if (allReasons == null ) {
740- this .allReasons = new LinkedHashSet <>();
741- }
742- this .allReasons .add (firstReason );
743- return this .allReasons ;
744- }
745-
746- int getObjectReachability () {
747- return objectReachability ;
748- }
749-
750- boolean objectReachableFrom (ObjectReachabilityGroup objectReachabilityGroup ) {
751- return (this .objectReachability & objectReachabilityGroup .flag ) != 0 ;
752- }
753- }
754-
755711 public final class ObjectInfo implements ImageHeapObject {
756712 private final JavaConstant constant ;
757713 private final HostedClass clazz ;
@@ -765,13 +721,6 @@ public final class ObjectInfo implements ImageHeapObject {
765721 * This is either another ObjectInfo, saying which object refers to this object, eventually
766722 * a root object which refers to this object, or is a String explaining why this object is
767723 * in the heap, or an {@link InternalReason}, or a {@link HostedField}.
768- *
769- * When PrintImageHeapConnectedComponents is turned on, this field will have a reference to
770- * a {@link AdditionalReasonInfo} containing data that is used to compute image heap
771- * connected components. Field {@code AdditionalReasonInfo.firstReason} will contain the
772- * reason that is assigned when PrintImageHeapConnectedComponents is turned off. We do this
773- * to keep ObjectInfo size the same and avoid adding additional unnecessary fields for
774- * ObjectInfo that would be used only for computing image heap connected components.
775724 */
776725 private Object reason ;
777726
@@ -790,7 +739,7 @@ public final class ObjectInfo implements ImageHeapObject {
790739 // For diagnostic purposes only
791740 this .reason = reason ;
792741 if (ImageHeapConnectedComponentsFeature .Options .PrintImageHeapConnectedComponents .getValue ()) {
793- additionalReasonInfoMap .put (this , new AdditionalReasonInfo (this , reason ));
742+ objectReachabilityInfo .put (this , new ObjectReachabilityInfo (this , reason ));
794743 }
795744 }
796745
@@ -946,6 +895,50 @@ private enum PhaseValue {
946895 }
947896 }
948897
898+ enum InternalReason {
899+ InternedStringsTable ,
900+ FillerObject ,
901+ StaticObjectFields ,
902+ DataSection ,
903+ StaticPrimitiveFields
904+ }
905+
906+ final class ObjectReachabilityInfo {
907+ private final Object firstReason ;
908+ private LinkedHashSet <Object > allReasons ;
909+ private int objectReachabilityGroup ;
910+
911+ ObjectReachabilityInfo (ObjectInfo info , Object firstReason ) {
912+ this .firstReason = firstReason ;
913+ this .allReasons = null ;
914+ this .objectReachabilityGroup = ObjectReachabilityGroup .getFlagForObjectInfo (info , firstReason , objectReachabilityInfo );
915+ }
916+
917+ void addReason (Object additionalReason ) {
918+ if (allReasons == null ) {
919+ this .allReasons = new LinkedHashSet <>();
920+ }
921+ this .allReasons .add (additionalReason );
922+ this .objectReachabilityGroup |= ObjectReachabilityGroup .getByReason (additionalReason , objectReachabilityInfo );
923+ }
924+
925+ Set <Object > getAllReasons () {
926+ if (allReasons == null ) {
927+ this .allReasons = new LinkedHashSet <>();
928+ }
929+ this .allReasons .add (firstReason );
930+ return this .allReasons ;
931+ }
932+
933+ int getObjectReachabilityGroup () {
934+ return objectReachabilityGroup ;
935+ }
936+
937+ boolean objectReachableFrom (ObjectReachabilityGroup objectReachabilityGroup ) {
938+ return (this .objectReachabilityGroup & objectReachabilityGroup .flag ) != 0 ;
939+ }
940+ }
941+
949942 /**
950943 * For diagnostic purposes only when
951944 * {@code ImageHeapConnectedComponentsFeature.Options.PrintImageHeapConnectedComponents} is
@@ -965,7 +958,7 @@ enum ObjectReachabilityGroup {
965958 this .flag = flag ;
966959 }
967960
968- static int getFlagForObjectInfo (ObjectInfo object , Object firstReason , HashMap <ObjectInfo , AdditionalReasonInfo > additionalReasonInfoHashMap ) {
961+ static int getFlagForObjectInfo (ObjectInfo object , Object firstReason , HashMap <ObjectInfo , ObjectReachabilityInfo > additionalReasonInfoHashMap ) {
969962 int result = 0 ;
970963 if (object .getObjectClass ().equals (ImageCodeInfo .class )) {
971964 result |= ImageCodeInfo .flag ;
@@ -977,14 +970,14 @@ static int getFlagForObjectInfo(ObjectInfo object, Object firstReason, HashMap<O
977970 return result ;
978971 }
979972
980- static int getByReason (Object reason , HashMap <ObjectInfo , AdditionalReasonInfo > additionalReasonInfoHashMap ) {
973+ static int getByReason (Object reason , HashMap <ObjectInfo , ObjectReachabilityInfo > additionalReasonInfoHashMap ) {
981974 if (reason .equals (InternalReason .InternedStringsTable )) {
982975 return ObjectReachabilityGroup .ImageCodeInfo .flag ;
983976 } else if (reason instanceof String || reason instanceof HostedField ) {
984977 return ObjectReachabilityGroup .MethodOrStaticField .flag ;
985978 } else if (reason instanceof ObjectInfo ) {
986979 ObjectInfo r = (ObjectInfo ) reason ;
987- return additionalReasonInfoHashMap .get (r ).getObjectReachability ();
980+ return additionalReasonInfoHashMap .get (r ).getObjectReachabilityGroup ();
988981 }
989982 return ObjectReachabilityGroup .Other .flag ;
990983 }
0 commit comments