@@ -182,14 +182,6 @@ void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register
182182
183183 if (len->is_valid ()) {
184184 movl (Address (obj, arrayOopDesc::length_offset_in_bytes ()), len);
185- #ifdef _LP64
186- if (!is_aligned (arrayOopDesc::header_size_in_bytes (), BytesPerWord)) {
187- assert (is_aligned (arrayOopDesc::header_size_in_bytes (), BytesPerInt), " must be 4-byte aligned" );
188- movl (Address (obj, arrayOopDesc::header_size_in_bytes ()), 0 );
189- }
190- #else
191- assert (is_aligned (arrayOopDesc::header_size_in_bytes (), BytesPerInt), " must be 4-byte aligned" );
192- #endif
193185 }
194186#ifdef _LP64
195187 else if (UseCompressedClassPointers && !UseCompactObjectHeaders) {
@@ -226,9 +218,8 @@ void C1_MacroAssembler::initialize_object(Register obj, Register klass, Register
226218 assert ((con_size_in_bytes & MinObjAlignmentInBytesMask) == 0 ,
227219 " con_size_in_bytes is not multiple of alignment" );
228220 const int hdr_size_in_bytes = instanceOopDesc::header_size () * HeapWordSize;
229- if (UseCompactObjectHeaders) {
230- assert (hdr_size_in_bytes == 8 , " check object headers size" );
231- }
221+ assert (!UseCompactObjectHeaders || hdr_size_in_bytes == 8 , " check object headers size" );
222+
232223 initialize_header (obj, klass, noreg, t1, t2);
233224
234225 if (!(UseTLAB && ZeroTLAB && is_tlab_allocated)) {
@@ -296,12 +287,22 @@ void C1_MacroAssembler::allocate_array(Register obj, Register len, Register t1,
296287
297288 initialize_header (obj, klass, len, t1, t2);
298289
290+ // Clear leading 4 bytes, if necessary.
291+ // TODO: This could perhaps go into initialize_body() and also clear the leading 4 bytes
292+ // for non-array objects, thereby replacing the klass-gap clearing code in initialize_header().
293+ int base_offset = base_offset_in_bytes;
294+ #ifdef _LP64
295+ if (!is_aligned (base_offset, BytesPerWord)) {
296+ assert (is_aligned (base_offset, BytesPerInt), " must be 4-byte aligned" );
297+ movl (Address (obj, base_offset), 0 );
298+ base_offset += BytesPerInt;
299+ }
300+ #endif
301+ assert (is_aligned (base_offset, BytesPerWord), " must be word aligned" );
302+
299303 // clear rest of allocated space
300304 const Register len_zero = len;
301- // We align-up the header size to word-size, because we clear the
302- // possible alignment gap in initialize_header().
303- int hdr_size = align_up (base_offset_in_bytes, BytesPerWord);
304- initialize_body (obj, arr_size, hdr_size, len_zero);
305+ initialize_body (obj, arr_size, base_offset, len_zero);
305306
306307 if (CURRENT_ENV->dtrace_alloc_probes ()) {
307308 assert (obj == rax, " must be" );
0 commit comments