Skip to content

Commit 6c68ce2

Browse files
author
Andrew Haley
committed
8270947: AArch64: C1: use zero_words to initialize all objects
Reviewed-by: ngasson, adinn
1 parent cd7e30e commit 6c68ce2

File tree

8 files changed

+28831
-165
lines changed

8 files changed

+28831
-165
lines changed

src/hotspot/cpu/aarch64/aarch64.ad

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14983,12 +14983,12 @@ instruct clearArray_reg_reg(iRegL_R11 cnt, iRegP_R10 base, Universe dummy, rFlag
1498314983
ins_pipe(pipe_class_memory);
1498414984
%}
1498514985

14986-
instruct clearArray_imm_reg(immL cnt, iRegP_R10 base, Universe dummy, rFlagsReg cr)
14986+
instruct clearArray_imm_reg(immL cnt, iRegP_R10 base, iRegL_R11 temp, Universe dummy, rFlagsReg cr)
1498714987
%{
1498814988
predicate((uint64_t)n->in(2)->get_long()
1498914989
< (uint64_t)(BlockZeroingLowLimit >> LogBytesPerWord));
1499014990
match(Set dummy (ClearArray cnt base));
14991-
effect(USE_KILL base);
14991+
effect(TEMP temp, USE_KILL base, KILL cr);
1499214992

1499314993
ins_cost(4 * INSN_COST);
1499414994
format %{ "ClearArray $cnt, $base" %}

src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,8 @@ void LIRGenerator::do_NewInstance(NewInstance* x) {
11271127
CodeEmitInfo* info = state_for(x, x->state());
11281128
LIR_Opr reg = result_register_for(x->type());
11291129
new_instance(reg, x->klass(), x->is_unresolved(),
1130-
FrameMap::r2_oop_opr,
1131-
FrameMap::r5_oop_opr,
1130+
FrameMap::r10_oop_opr,
1131+
FrameMap::r11_oop_opr,
11321132
FrameMap::r4_oop_opr,
11331133
LIR_OprFact::illegalOpr,
11341134
FrameMap::r3_metadata_opr, info);
@@ -1143,8 +1143,8 @@ void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
11431143
length.load_item_force(FrameMap::r19_opr);
11441144

11451145
LIR_Opr reg = result_register_for(x->type());
1146-
LIR_Opr tmp1 = FrameMap::r2_oop_opr;
1147-
LIR_Opr tmp2 = FrameMap::r4_oop_opr;
1146+
LIR_Opr tmp1 = FrameMap::r10_oop_opr;
1147+
LIR_Opr tmp2 = FrameMap::r11_oop_opr;
11481148
LIR_Opr tmp3 = FrameMap::r5_oop_opr;
11491149
LIR_Opr tmp4 = reg;
11501150
LIR_Opr klass_reg = FrameMap::r3_metadata_opr;
@@ -1172,8 +1172,8 @@ void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {
11721172
CodeEmitInfo* info = state_for(x, x->state());
11731173

11741174
LIR_Opr reg = result_register_for(x->type());
1175-
LIR_Opr tmp1 = FrameMap::r2_oop_opr;
1176-
LIR_Opr tmp2 = FrameMap::r4_oop_opr;
1175+
LIR_Opr tmp1 = FrameMap::r10_oop_opr;
1176+
LIR_Opr tmp2 = FrameMap::r11_oop_opr;
11771177
LIR_Opr tmp3 = FrameMap::r5_oop_opr;
11781178
LIR_Opr tmp4 = reg;
11791179
LIR_Opr klass_reg = FrameMap::r3_metadata_opr;

src/hotspot/cpu/aarch64/c1_MacroAssembler_aarch64.cpp

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
3+
* Copyright (c) 2014, 2021, Red Hat Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -180,20 +180,24 @@ void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register
180180
}
181181

182182
// preserves obj, destroys len_in_bytes
183-
void C1_MacroAssembler::initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1) {
183+
//
184+
// Scratch registers: t1 = r10, t2 = r11
185+
//
186+
void C1_MacroAssembler::initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1, Register t2) {
184187
assert(hdr_size_in_bytes >= 0, "header size must be positive or 0");
188+
assert(t1 == r10 && t2 == r11, "must be");
189+
185190
Label done;
186191

187192
// len_in_bytes is positive and ptr sized
188193
subs(len_in_bytes, len_in_bytes, hdr_size_in_bytes);
189194
br(Assembler::EQ, done);
190195

191-
// Preserve obj
192-
if (hdr_size_in_bytes)
193-
add(obj, obj, hdr_size_in_bytes);
194-
zero_memory(obj, len_in_bytes, t1);
195-
if (hdr_size_in_bytes)
196-
sub(obj, obj, hdr_size_in_bytes);
196+
// zero_words() takes ptr in r10 and count in words in r11
197+
mov(rscratch1, len_in_bytes);
198+
lea(t1, Address(obj, hdr_size_in_bytes));
199+
lsr(t2, rscratch1, LogBytesPerWord);
200+
zero_words(t1, t2);
197201

198202
bind(done);
199203
}
@@ -208,6 +212,7 @@ void C1_MacroAssembler::allocate_object(Register obj, Register t1, Register t2,
208212
initialize_object(obj, klass, noreg, object_size * HeapWordSize, t1, t2, UseTLAB);
209213
}
210214

215+
// Scratch registers: t1 = r10, t2 = r11
211216
void C1_MacroAssembler::initialize_object(Register obj, Register klass, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, bool is_tlab_allocated) {
212217
assert((con_size_in_bytes & MinObjAlignmentInBytesMask) == 0,
213218
"con_size_in_bytes is not multiple of alignment");
@@ -218,45 +223,13 @@ void C1_MacroAssembler::initialize_object(Register obj, Register klass, Register
218223
if (!(UseTLAB && ZeroTLAB && is_tlab_allocated)) {
219224
// clear rest of allocated space
220225
const Register index = t2;
221-
const int threshold = 16 * BytesPerWord; // approximate break even point for code size (see comments below)
222226
if (var_size_in_bytes != noreg) {
223227
mov(index, var_size_in_bytes);
224-
initialize_body(obj, index, hdr_size_in_bytes, t1);
225-
} else if (con_size_in_bytes <= threshold) {
226-
// use explicit null stores
227-
int i = hdr_size_in_bytes;
228-
if (i < con_size_in_bytes && (con_size_in_bytes % (2 * BytesPerWord))) {
229-
str(zr, Address(obj, i));
230-
i += BytesPerWord;
231-
}
232-
for (; i < con_size_in_bytes; i += 2 * BytesPerWord)
233-
stp(zr, zr, Address(obj, i));
228+
initialize_body(obj, index, hdr_size_in_bytes, t1, t2);
234229
} else if (con_size_in_bytes > hdr_size_in_bytes) {
235-
block_comment("zero memory");
236-
// use loop to null out the fields
237-
238-
int words = (con_size_in_bytes - hdr_size_in_bytes) / BytesPerWord;
239-
mov(index, words / 8);
240-
241-
const int unroll = 8; // Number of str(zr) instructions we'll unroll
242-
int remainder = words % unroll;
243-
lea(rscratch1, Address(obj, hdr_size_in_bytes + remainder * BytesPerWord));
244-
245-
Label entry_point, loop;
246-
b(entry_point);
247-
248-
bind(loop);
249-
sub(index, index, 1);
250-
for (int i = -unroll; i < 0; i++) {
251-
if (-i == remainder)
252-
bind(entry_point);
253-
str(zr, Address(rscratch1, i * wordSize));
254-
}
255-
if (remainder == 0)
256-
bind(entry_point);
257-
add(rscratch1, rscratch1, unroll * wordSize);
258-
cbnz(index, loop);
259-
230+
con_size_in_bytes -= hdr_size_in_bytes;
231+
lea(t1, Address(obj, hdr_size_in_bytes));
232+
zero_words(t1, con_size_in_bytes / BytesPerWord);
260233
}
261234
}
262235

@@ -291,8 +264,7 @@ void C1_MacroAssembler::allocate_array(Register obj, Register len, Register t1,
291264
initialize_header(obj, klass, len, t1, t2);
292265

293266
// clear rest of allocated space
294-
const Register len_zero = len;
295-
initialize_body(obj, arr_size, header_size * BytesPerWord, len_zero);
267+
initialize_body(obj, arr_size, header_size * BytesPerWord, t1, t2);
296268

297269
membar(StoreStore);
298270

src/hotspot/cpu/aarch64/c1_MacroAssembler_aarch64.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2014, 2015, Red Hat Inc. All rights reserved.
2+
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2014, 2021, Red Hat Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -48,7 +48,7 @@ using MacroAssembler::null_check;
4848
);
4949

5050
void initialize_header(Register obj, Register klass, Register len, Register t1, Register t2);
51-
void initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1);
51+
void initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1, Register t2);
5252

5353
void float_cmp(bool is_float, int unordered_result,
5454
FloatRegister f0, FloatRegister f1,

src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
3+
* Copyright (c) 2014, 2021, Red Hat Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -656,9 +656,9 @@ OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {
656656
if ((id == fast_new_instance_id || id == fast_new_instance_init_check_id) &&
657657
!UseTLAB && Universe::heap()->supports_inline_contig_alloc()) {
658658
Label slow_path;
659-
Register obj_size = r2;
660-
Register t1 = r19;
661-
Register t2 = r4;
659+
Register obj_size = r19;
660+
Register t1 = r10;
661+
Register t2 = r11;
662662
assert_different_registers(klass, obj, obj_size, t1, t2);
663663

664664
__ stp(r19, zr, Address(__ pre(sp, -2 * wordSize)));
@@ -769,9 +769,9 @@ OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {
769769
// allocations.
770770
// Otherwise, just go to the slow path.
771771
if (!UseTLAB && Universe::heap()->supports_inline_contig_alloc()) {
772-
Register arr_size = r4;
773-
Register t1 = r2;
774-
Register t2 = r5;
772+
Register arr_size = r5;
773+
Register t1 = r10;
774+
Register t2 = r11;
775775
Label slow_path;
776776
assert_different_registers(length, klass, obj, arr_size, t1, t2);
777777

@@ -801,7 +801,7 @@ OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {
801801
__ andr(t1, t1, Klass::_lh_header_size_mask);
802802
__ sub(arr_size, arr_size, t1); // body length
803803
__ add(t1, t1, obj); // body start
804-
__ initialize_body(t1, arr_size, 0, t2);
804+
__ initialize_body(t1, arr_size, 0, t1, t2);
805805
__ membar(Assembler::StoreStore);
806806
__ verify_oop(obj);
807807

0 commit comments

Comments
 (0)