10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "c1/c1_MacroAssembler.hpp"
27 #include "c1/c1_Runtime1.hpp"
28 #include "gc/shared/barrierSetAssembler.hpp"
29 #include "gc/shared/collectedHeap.hpp"
30 #include "gc/shared/tlab_globals.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "oops/arrayOop.hpp"
33 #include "oops/markWord.hpp"
34 #include "runtime/basicLock.hpp"
35 #include "runtime/os.hpp"
36 #include "runtime/sharedRuntime.hpp"
37 #include "runtime/stubRoutines.hpp"
38
39 void C1_MacroAssembler::float_cmp(bool is_float, int unordered_result,
40 FloatRegister f0, FloatRegister f1,
41 Register result)
42 {
43 Label done;
44 if (is_float) {
45 fcmps(f0, f1);
46 } else {
47 fcmpd(f0, f1);
48 }
49 if (unordered_result < 0) {
50 // we want -1 for unordered or less than, 0 for equal and 1 for
51 // greater than.
52 cset(result, NE); // Not equal or unordered
53 cneg(result, result, LT); // Less than or unordered
82 // load object
83 ldr(obj, Address(basic_lock, BasicObjectLock::obj_offset()));
84 verify_oop(obj);
85
86 fast_unlock(obj, hdr, temp, rscratch2, slow_case);
87 }
88
89
90 // Defines obj, preserves var_size_in_bytes
91 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
92 if (UseTLAB) {
93 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
94 } else {
95 b(slow_case);
96 }
97 }
98
99 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
100 assert_different_registers(obj, klass, len);
101
102 if (UseCompactObjectHeaders) {
103 ldr(t1, Address(klass, Klass::prototype_header_offset()));
104 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
105 } else {
106 mov(t1, checked_cast<int32_t>(markWord::prototype().value()));
107 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
108 encode_klass_not_null(t1, klass); // Take care not to kill klass
109 strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
110 }
111
112 if (len->is_valid()) {
113 strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
114 int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
115 if (!is_aligned(base_offset, BytesPerWord)) {
116 assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
117 // Clear gap/first 4 bytes following the length field.
118 strw(zr, Address(obj, base_offset));
119 }
120 } else if (!UseCompactObjectHeaders) {
121 store_klass_gap(obj, zr);
122 }
123 }
124
125 // preserves obj, destroys len_in_bytes
126 //
127 // Scratch registers: t1 = r10, t2 = r11
220 // following the length field in initialize_header().
221 int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
222 // clear rest of allocated space
223 if (zero_array) {
224 initialize_body(obj, arr_size, base_offset, t1, t2);
225 }
226 if (Compilation::current()->bailed_out()) {
227 return;
228 }
229
230 membar(StoreStore);
231
232 if (CURRENT_ENV->dtrace_alloc_probes()) {
233 assert(obj == r0, "must be");
234 far_call(RuntimeAddress(Runtime1::entry_for(StubId::c1_dtrace_object_alloc_id)));
235 }
236
237 verify_oop(obj);
238 }
239
240 void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes) {
241 assert(bang_size_in_bytes >= framesize, "stack bang size incorrect");
242 // Make sure there is enough stack space for this method's activation.
243 // Note that we do this before creating a frame.
244 generate_stack_overflow_check(bang_size_in_bytes);
245 MacroAssembler::build_frame(framesize);
246
247 // Insert nmethod entry barrier into frame.
248 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
249 bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
250 }
251
252 void C1_MacroAssembler::remove_frame(int framesize) {
253 MacroAssembler::remove_frame(framesize);
254 }
255
256
257 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
258 // If we have to make this method not-entrant we'll overwrite its
259 // first instruction with a jump. For this action to be legal we
260 // must ensure that this first instruction is a B, BL, NOP, BKPT,
261 // SVC, HVC, or SMC. Make it a NOP.
262 nop();
263 }
264
265 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
266 // rfp, + 0: link
267 // + 1: return address
268 // + 2: argument with offset 0
269 // + 3: argument with offset 1
270 // + 4: ...
271
272 ldr(reg, Address(rfp, (offset_in_words + 2) * BytesPerWord));
273 }
274
275 #ifndef PRODUCT
276
277 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
278 if (!VerifyOops) return;
279 verify_oop_addr(Address(sp, stack_offset));
280 }
281
282 void C1_MacroAssembler::verify_not_null_oop(Register r) {
283 if (!VerifyOops) return;
284 Label not_null;
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "c1/c1_MacroAssembler.hpp"
27 #include "c1/c1_Runtime1.hpp"
28 #include "gc/shared/barrierSetAssembler.hpp"
29 #include "gc/shared/collectedHeap.hpp"
30 #include "gc/shared/barrierSet.hpp"
31 #include "gc/shared/barrierSetAssembler.hpp"
32 #include "gc/shared/tlab_globals.hpp"
33 #include "interpreter/interpreter.hpp"
34 #include "oops/arrayOop.hpp"
35 #include "oops/markWord.hpp"
36 #include "runtime/arguments.hpp"
37 #include "runtime/basicLock.hpp"
38 #include "runtime/os.hpp"
39 #include "runtime/sharedRuntime.hpp"
40 #include "runtime/stubRoutines.hpp"
41
42 void C1_MacroAssembler::float_cmp(bool is_float, int unordered_result,
43 FloatRegister f0, FloatRegister f1,
44 Register result)
45 {
46 Label done;
47 if (is_float) {
48 fcmps(f0, f1);
49 } else {
50 fcmpd(f0, f1);
51 }
52 if (unordered_result < 0) {
53 // we want -1 for unordered or less than, 0 for equal and 1 for
54 // greater than.
55 cset(result, NE); // Not equal or unordered
56 cneg(result, result, LT); // Less than or unordered
85 // load object
86 ldr(obj, Address(basic_lock, BasicObjectLock::obj_offset()));
87 verify_oop(obj);
88
89 fast_unlock(obj, hdr, temp, rscratch2, slow_case);
90 }
91
92
93 // Defines obj, preserves var_size_in_bytes
94 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
95 if (UseTLAB) {
96 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
97 } else {
98 b(slow_case);
99 }
100 }
101
102 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
103 assert_different_registers(obj, klass, len);
104
105 if (UseCompactObjectHeaders || Arguments::is_valhalla_enabled()) {
106 // COH: Markword contains class pointer which is only known at runtime.
107 // Valhalla: Could have value class which has a different prototype header to a normal object.
108 // In both cases, we need to fetch dynamically.
109 ldr(t1, Address(klass, Klass::prototype_header_offset()));
110 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
111 } else {
112 // Otherwise: Can use the statically computed prototype header which is the same for every object.
113 mov(t1, checked_cast<int32_t>(markWord::prototype().value()));
114 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
115 }
116
117 if (!UseCompactObjectHeaders) {
118 // COH: Markword already contains class pointer. Nothing else to do.
119 // Otherwise: Store encoded klass pointer following the markword
120 encode_klass_not_null(t1, klass); // Take care not to kill klass
121 strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
122 }
123
124 if (len->is_valid()) {
125 strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
126 int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
127 if (!is_aligned(base_offset, BytesPerWord)) {
128 assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
129 // Clear gap/first 4 bytes following the length field.
130 strw(zr, Address(obj, base_offset));
131 }
132 } else if (!UseCompactObjectHeaders) {
133 store_klass_gap(obj, zr);
134 }
135 }
136
137 // preserves obj, destroys len_in_bytes
138 //
139 // Scratch registers: t1 = r10, t2 = r11
232 // following the length field in initialize_header().
233 int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
234 // clear rest of allocated space
235 if (zero_array) {
236 initialize_body(obj, arr_size, base_offset, t1, t2);
237 }
238 if (Compilation::current()->bailed_out()) {
239 return;
240 }
241
242 membar(StoreStore);
243
244 if (CURRENT_ENV->dtrace_alloc_probes()) {
245 assert(obj == r0, "must be");
246 far_call(RuntimeAddress(Runtime1::entry_for(StubId::c1_dtrace_object_alloc_id)));
247 }
248
249 verify_oop(obj);
250 }
251
252 void C1_MacroAssembler::build_frame_helper(int frame_size_in_bytes, int sp_offset_for_orig_pc, int sp_inc, bool reset_orig_pc, bool needs_stack_repair) {
253 MacroAssembler::build_frame(frame_size_in_bytes);
254
255 if (needs_stack_repair) {
256 save_stack_increment(sp_inc, frame_size_in_bytes);
257 }
258 if (reset_orig_pc) {
259 // Zero orig_pc to detect deoptimization during buffering in the entry points
260 str(zr, Address(sp, sp_offset_for_orig_pc));
261 }
262 }
263
264 void C1_MacroAssembler::build_frame(int frame_size_in_bytes, int bang_size_in_bytes, int sp_offset_for_orig_pc, bool needs_stack_repair, bool has_scalarized_args, Label* verified_inline_entry_label) {
265 // Make sure there is enough stack space for this method's activation.
266 // Note that we do this before creating a frame.
267 assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
268 generate_stack_overflow_check(bang_size_in_bytes);
269
270 build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, has_scalarized_args, needs_stack_repair);
271
272 // Insert nmethod entry barrier into frame.
273 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
274 bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
275
276 if (verified_inline_entry_label != nullptr) {
277 // Jump here from the scalarized entry points that already created the frame.
278 bind(*verified_inline_entry_label);
279 }
280 }
281
282 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
283 // If we have to make this method not-entrant we'll overwrite its
284 // first instruction with a jump. For this action to be legal we
285 // must ensure that this first instruction is a B, BL, NOP, BKPT,
286 // SVC, HVC, or SMC. Make it a NOP.
287 nop();
288 if (C1Breakpoint) brk(1);
289 }
290
291 int C1_MacroAssembler::scalarized_entry(const CompiledEntrySignature* ces, int frame_size_in_bytes, int bang_size_in_bytes, int sp_offset_for_orig_pc, Label& verified_inline_entry_label, bool is_inline_ro_entry) {
292 assert(InlineTypePassFieldsAsArgs, "sanity");
293 // Make sure there is enough stack space for this method's activation.
294 assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
295 generate_stack_overflow_check(bang_size_in_bytes);
296
297 GrowableArray<SigEntry>* sig = ces->sig();
298 GrowableArray<SigEntry>* sig_cc = is_inline_ro_entry ? ces->sig_cc_ro() : ces->sig_cc();
299 VMRegPair* regs = ces->regs();
300 VMRegPair* regs_cc = is_inline_ro_entry ? ces->regs_cc_ro() : ces->regs_cc();
301 int args_on_stack = ces->args_on_stack();
302 int args_on_stack_cc = is_inline_ro_entry ? ces->args_on_stack_cc_ro() : ces->args_on_stack_cc();
303
304 assert(sig->length() <= sig_cc->length(), "Zero-sized inline class not allowed!");
305 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sig_cc->length());
306 int args_passed = sig->length();
307 int args_passed_cc = SigEntry::fill_sig_bt(sig_cc, sig_bt);
308
309 // Create a temp frame so we can call into the runtime. It must be properly set up to accommodate GC.
310 build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, true, ces->c1_needs_stack_repair());
311
312 // The runtime call might safepoint, make sure nmethod entry barrier is executed
313 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
314 // C1 code is not hot enough to micro optimize the nmethod entry barrier with an out-of-line stub
315 bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
316
317 // FIXME -- call runtime only if we cannot in-line allocate all the incoming inline type args.
318 mov(r19, (intptr_t) ces->method());
319 if (is_inline_ro_entry) {
320 far_call(RuntimeAddress(Runtime1::entry_for(StubId::c1_buffer_inline_args_no_receiver_id)));
321 } else {
322 far_call(RuntimeAddress(Runtime1::entry_for(StubId::c1_buffer_inline_args_id)));
323 }
324 int rt_call_offset = offset();
325
326 // The runtime call returns the new array in r20 instead of the usual r0
327 // because r0 is also j_rarg7 which may be holding a live argument here.
328 Register val_array = r20;
329
330 // Remove the temp frame
331 MacroAssembler::remove_frame(frame_size_in_bytes);
332
333 // Check if we need to extend the stack for packing
334 int sp_inc = 0;
335 if (args_on_stack > args_on_stack_cc) {
336 sp_inc = extend_stack_for_inline_args(args_on_stack);
337 }
338
339 shuffle_inline_args(true, is_inline_ro_entry, sig_cc,
340 args_passed_cc, args_on_stack_cc, regs_cc, // from
341 args_passed, args_on_stack, regs, // to
342 sp_inc, val_array);
343
344 // Create the real frame. Below jump will then skip over the stack banging and frame
345 // setup code in the verified_inline_entry (which has a different real_frame_size).
346 build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, sp_inc, false, ces->c1_needs_stack_repair());
347
348 b(verified_inline_entry_label);
349 return rt_call_offset;
350 }
351
352
353 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
354 // rfp, + 0: link
355 // + 1: return address
356 // + 2: argument with offset 0
357 // + 3: argument with offset 1
358 // + 4: ...
359
360 ldr(reg, Address(rfp, (offset_in_words + 2) * BytesPerWord));
361 }
362
363 #ifndef PRODUCT
364
365 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
366 if (!VerifyOops) return;
367 verify_oop_addr(Address(sp, stack_offset));
368 }
369
370 void C1_MacroAssembler::verify_not_null_oop(Register r) {
371 if (!VerifyOops) return;
372 Label not_null;
|