3636import com .ibm .j9ddr .vm29 .pointer .helper .J9ObjectHelper ;
3737import com .ibm .j9ddr .vm29 .types .UDATA ;
3838
39-
4039class GCMixedObjectIterator_V1 extends GCObjectIterator
4140{
42- protected final static HashMap <J9ClassPointer , boolean []> descriptionCache = new HashMap <J9ClassPointer , boolean []>();
41+ protected final static HashMap <J9ClassPointer , boolean []> descriptionCache = new HashMap <>();
42+
4343 protected ObjectReferencePointer data ;
4444 protected boolean [] descriptionArray ;
4545 protected int scanIndex ;
4646 protected int scanLimit ;
4747 protected int bytesInObjectSlot ;
4848 protected int objectsInDescriptionSlot ;
49-
49+
5050 protected static void setCache (J9ClassPointer clazz , boolean [] description )
5151 {
5252 descriptionCache .put (clazz , description );
@@ -56,80 +56,82 @@ protected static boolean[] checkCache(J9ClassPointer clazz)
5656 {
5757 return descriptionCache .get (clazz );
5858 }
59-
59+
6060 protected GCMixedObjectIterator_V1 (J9ObjectPointer object , boolean includeClassSlot ) throws CorruptDataException
6161 {
6262 super (object , includeClassSlot );
63-
64- J9ClassPointer clazz = J9ObjectHelper .clazz (object );
65- bytesInObjectSlot = (int )ObjectReferencePointer .SIZEOF ;
66- objectsInDescriptionSlot = UDATA .SIZEOF * 8 ; // 8 bits per byte
67-
63+
64+ J9ClassPointer clazz = J9ObjectHelper .clazz (object );
65+ bytesInObjectSlot = (int ) ObjectReferencePointer .SIZEOF ;
66+ objectsInDescriptionSlot = UDATA .SIZEOF * Byte . SIZE ;
67+
6868 VoidPointer data = VoidPointer .cast (object .addOffset (ObjectModel .getHeaderSize (object )));
6969 initialize (clazz , data );
7070 }
7171
7272 protected GCMixedObjectIterator_V1 (J9ClassPointer clazz , VoidPointer addr ) throws CorruptDataException
7373 {
7474 super (null , false ); // includeClassSlot = false
75- bytesInObjectSlot = (int )ObjectReferencePointer .SIZEOF ;
76- objectsInDescriptionSlot = UDATA .SIZEOF * 8 ; // 8 bits per byte
77-
75+ bytesInObjectSlot = (int ) ObjectReferencePointer .SIZEOF ;
76+ objectsInDescriptionSlot = UDATA .SIZEOF * Byte . SIZE ;
77+
7878 initialize (clazz , addr );
7979 }
8080
81- private void initialize (J9ClassPointer clazz , VoidPointer addr ) throws CorruptDataException
81+ private void initialize (J9ClassPointer clazz , VoidPointer addr ) throws CorruptDataException
8282 {
83- data = ObjectReferencePointer .cast (addr );
84- scanIndex = 0 ;
83+ int totalInstanceSize = clazz .totalInstanceSize ().intValue ();
8584
86- scanLimit = clazz .totalInstanceSize ().intValue () / bytesInObjectSlot ;
85+ data = ObjectReferencePointer .cast (addr );
86+ scanIndex = 0 ;
87+ scanLimit = totalInstanceSize / bytesInObjectSlot ;
8788 descriptionArray = checkCache (clazz );
8889 if (null == descriptionArray ) {
89- descriptionArray = new boolean [(clazz . totalInstanceSize (). intValue () + bytesInObjectSlot - 1 ) / bytesInObjectSlot ];
90+ descriptionArray = new boolean [(totalInstanceSize + bytesInObjectSlot - 1 ) / bytesInObjectSlot ];
9091 if ((scanLimit > 0 ) && clazz .instanceDescription ().notNull ()) {
9192 initializeDescriptionArray (clazz );
9293 setCache (clazz , descriptionArray );
9394 }
9495 }
9596 }
96-
97+
9798 protected void initializeDescriptionArray (J9ClassPointer clazz ) throws CorruptDataException
9899 {
99100 UDATAPointer descriptionPtr = clazz .instanceDescription ();
100- long tempDescription ;
101-
101+ UDATA tempDescription ;
102+
102103 if (descriptionPtr .anyBitsIn (1 )) {
103104 // Immediate
104- tempDescription = descriptionPtr . getAddress () >>> 1 ;
105+ tempDescription = UDATA . cast ( descriptionPtr ). rightShift ( 1 ) ;
105106 initializeDescriptionArray (tempDescription , 0 );
106107 } else {
107108 int descriptionSlot = 0 ;
108109 int descriptionIndex = 0 ;
109110 while (descriptionIndex < scanLimit ) {
110- tempDescription = descriptionPtr .at (descriptionSlot ++). longValue () ;
111+ tempDescription = descriptionPtr .at (descriptionSlot ++);
111112 initializeDescriptionArray (tempDescription , descriptionIndex );
112113 descriptionIndex += objectsInDescriptionSlot ;
113114 }
114115 }
115116 }
116117
117- private void initializeDescriptionArray (long tempDescription , int offset )
118+ private void initializeDescriptionArray (UDATA tempDescription , int offset )
118119 {
119- for (int i = 0 ; i < objectsInDescriptionSlot ; i ++) {
120- if (1 == ( tempDescription & 1 )) {
120+ for (int i = 0 ; i < objectsInDescriptionSlot ; i ++) {
121+ if (tempDescription . anyBitsIn ( 1 )) {
121122 descriptionArray [offset + i ] = true ;
122123 }
123- tempDescription >>>= 1 ;
124+ tempDescription = tempDescription . rightShift ( 1 ) ;
124125 }
125126 }
126-
127+
128+ @ Override
127129 public boolean hasNext ()
128130 {
129131 if (object != null && includeClassSlot ) {
130132 return true ;
131133 }
132-
134+
133135 while (scanIndex < scanLimit ) {
134136 if (descriptionArray [scanIndex ]) {
135137 return true ;
@@ -148,18 +150,19 @@ public J9ObjectPointer next()
148150 includeClassSlot = false ;
149151 return J9ObjectHelper .clazz (object ).classObject ();
150152 }
151- J9ObjectPointer next = J9ObjectPointer .cast (data .at (scanIndex ));
153+ J9ObjectPointer next = J9ObjectPointer .cast (data .at (scanIndex ));
152154 scanIndex ++;
153155 return next ;
154156 } else {
155157 throw new NoSuchElementException ("There are no more items available through this iterator" );
156158 }
157159 } catch (CorruptDataException e ) {
158- raiseCorruptDataEvent ("Error getting next item" , e , false ); // can try to recover from this
160+ raiseCorruptDataEvent ("Error getting next item" , e , false ); // can try to recover from this
159161 return null ;
160- }
162+ }
161163 }
162164
165+ @ Override
163166 public VoidPointer nextAddress ()
164167 {
165168 try {
@@ -168,15 +171,15 @@ public VoidPointer nextAddress()
168171 includeClassSlot = false ;
169172 return VoidPointer .cast (J9ObjectHelper .clazz (object ).classObjectEA ());
170173 }
171- VoidPointer next = VoidPointer .cast (data .add (scanIndex ));
174+ VoidPointer next = VoidPointer .cast (data .add (scanIndex ));
172175 scanIndex ++;
173176 return next ;
174177 } else {
175178 throw new NoSuchElementException ("There are no more items available through this iterator" );
176179 }
177180 } catch (CorruptDataException e ) {
178- raiseCorruptDataEvent ("Error getting next item" , e , false ); // can try to recover from this
181+ raiseCorruptDataEvent ("Error getting next item" , e , false ); // can try to recover from this
179182 return null ;
180- }
183+ }
181184 }
182185}
0 commit comments