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) {
70 // save object being locked into the BasicObjectLock
71 str(obj, Address(disp_hdr, BasicObjectLock::obj_offset()));
72
73 null_check_offset = offset();
74
75 if (DiagnoseSyncOnValueBasedClasses != 0) {
76 load_klass(hdr, obj);
77 ldrb(hdr, Address(hdr, Klass::misc_flags_offset()));
78 tst(hdr, KlassFlags::_misc_is_value_based_class);
79 br(Assembler::NE, slow_case);
80 }
81
82 if (LockingMode == LM_LIGHTWEIGHT) {
83 lightweight_lock(disp_hdr, obj, hdr, temp, rscratch2, slow_case);
84 } else if (LockingMode == LM_LEGACY) {
85 Label done;
86 // Load object header
87 ldr(hdr, Address(obj, hdr_offset));
88 // and mark it as unlocked
89 orr(hdr, hdr, markWord::unlocked_value);
90 // save unlocked object header into the displaced header location on the stack
91 str(hdr, Address(disp_hdr, 0));
92 // test if object header is still the same (i.e. unlocked), and if so, store the
93 // displaced header address in the object header - if it is not the same, get the
94 // object header instead
95 lea(rscratch2, Address(obj, hdr_offset));
96 cmpxchgptr(hdr, disp_hdr, rscratch2, rscratch1, done, /*fallthough*/nullptr);
97 // if the object header was the same, we're done
98 // if the object header was not the same, it is now in the hdr register
99 // => test if it is a stack pointer into the same stack (recursive locking), i.e.:
100 //
101 // 1) (hdr & aligned_mask) == 0
102 // 2) sp <= hdr
103 // 3) hdr <= sp + page_size
104 //
105 // these 3 tests can be done by evaluating the following expression:
106 //
107 // (hdr - sp) & (aligned_mask - page_size)
108 //
109 // assuming both the stack pointer and page_size have their least
158 }
159 // done
160 bind(done);
161 dec_held_monitor_count(rscratch1);
162 }
163 }
164
165
166 // Defines obj, preserves var_size_in_bytes
167 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
168 if (UseTLAB) {
169 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
170 } else {
171 b(slow_case);
172 }
173 }
174
175 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
176 assert_different_registers(obj, klass, len);
177
178 if (UseCompactObjectHeaders) {
179 ldr(t1, Address(klass, Klass::prototype_header_offset()));
180 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
181 } else {
182 mov(t1, checked_cast<int32_t>(markWord::prototype().value()));
183 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
184 if (UseCompressedClassPointers) { // Take care not to kill klass
185 encode_klass_not_null(t1, klass);
186 strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
187 } else {
188 str(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
189 }
190 }
191
192 if (len->is_valid()) {
193 strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
194 int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
195 if (!is_aligned(base_offset, BytesPerWord)) {
196 assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
197 // Clear gap/first 4 bytes following the length field.
198 strw(zr, Address(obj, base_offset));
199 }
200 } else if (UseCompressedClassPointers && !UseCompactObjectHeaders) {
201 store_klass_gap(obj, zr);
202 }
203 }
300 // following the length field in initialize_header().
301 int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
302 // clear rest of allocated space
303 if (zero_array) {
304 initialize_body(obj, arr_size, base_offset, t1, t2);
305 }
306 if (Compilation::current()->bailed_out()) {
307 return;
308 }
309
310 membar(StoreStore);
311
312 if (CURRENT_ENV->dtrace_alloc_probes()) {
313 assert(obj == r0, "must be");
314 far_call(RuntimeAddress(Runtime1::entry_for(C1StubId::dtrace_object_alloc_id)));
315 }
316
317 verify_oop(obj);
318 }
319
320 void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes) {
321 assert(bang_size_in_bytes >= framesize, "stack bang size incorrect");
322 // Make sure there is enough stack space for this method's activation.
323 // Note that we do this before creating a frame.
324 generate_stack_overflow_check(bang_size_in_bytes);
325 MacroAssembler::build_frame(framesize);
326
327 // Insert nmethod entry barrier into frame.
328 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
329 bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
330 }
331
332 void C1_MacroAssembler::remove_frame(int framesize) {
333 MacroAssembler::remove_frame(framesize);
334 }
335
336
337 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
338 // If we have to make this method not-entrant we'll overwrite its
339 // first instruction with a jump. For this action to be legal we
340 // must ensure that this first instruction is a B, BL, NOP, BKPT,
341 // SVC, HVC, or SMC. Make it a NOP.
342 nop();
343 }
344
345 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
346 // rfp, + 0: link
347 // + 1: return address
348 // + 2: argument with offset 0
349 // + 3: argument with offset 1
350 // + 4: ...
351
352 ldr(reg, Address(rfp, (offset_in_words + 2) * BytesPerWord));
353 }
354
355 #ifndef PRODUCT
356
357 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
358 if (!VerifyOops) return;
359 verify_oop_addr(Address(sp, stack_offset));
360 }
361
362 void C1_MacroAssembler::verify_not_null_oop(Register r) {
363 if (!VerifyOops) return;
364 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/basicLock.hpp"
37 #include "runtime/os.hpp"
38 #include "runtime/sharedRuntime.hpp"
39 #include "runtime/stubRoutines.hpp"
40
41 void C1_MacroAssembler::float_cmp(bool is_float, int unordered_result,
42 FloatRegister f0, FloatRegister f1,
43 Register result)
44 {
45 Label done;
46 if (is_float) {
47 fcmps(f0, f1);
48 } else {
49 fcmpd(f0, f1);
50 }
51 if (unordered_result < 0) {
72 // save object being locked into the BasicObjectLock
73 str(obj, Address(disp_hdr, BasicObjectLock::obj_offset()));
74
75 null_check_offset = offset();
76
77 if (DiagnoseSyncOnValueBasedClasses != 0) {
78 load_klass(hdr, obj);
79 ldrb(hdr, Address(hdr, Klass::misc_flags_offset()));
80 tst(hdr, KlassFlags::_misc_is_value_based_class);
81 br(Assembler::NE, slow_case);
82 }
83
84 if (LockingMode == LM_LIGHTWEIGHT) {
85 lightweight_lock(disp_hdr, obj, hdr, temp, rscratch2, slow_case);
86 } else if (LockingMode == LM_LEGACY) {
87 Label done;
88 // Load object header
89 ldr(hdr, Address(obj, hdr_offset));
90 // and mark it as unlocked
91 orr(hdr, hdr, markWord::unlocked_value);
92
93 if (EnableValhalla) {
94 // Mask always_locked bit such that we go to the slow path if object is an inline type
95 andr(hdr, hdr, ~markWord::inline_type_bit_in_place);
96 }
97
98 // save unlocked object header into the displaced header location on the stack
99 str(hdr, Address(disp_hdr, 0));
100 // test if object header is still the same (i.e. unlocked), and if so, store the
101 // displaced header address in the object header - if it is not the same, get the
102 // object header instead
103 lea(rscratch2, Address(obj, hdr_offset));
104 cmpxchgptr(hdr, disp_hdr, rscratch2, rscratch1, done, /*fallthough*/nullptr);
105 // if the object header was the same, we're done
106 // if the object header was not the same, it is now in the hdr register
107 // => test if it is a stack pointer into the same stack (recursive locking), i.e.:
108 //
109 // 1) (hdr & aligned_mask) == 0
110 // 2) sp <= hdr
111 // 3) hdr <= sp + page_size
112 //
113 // these 3 tests can be done by evaluating the following expression:
114 //
115 // (hdr - sp) & (aligned_mask - page_size)
116 //
117 // assuming both the stack pointer and page_size have their least
166 }
167 // done
168 bind(done);
169 dec_held_monitor_count(rscratch1);
170 }
171 }
172
173
174 // Defines obj, preserves var_size_in_bytes
175 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
176 if (UseTLAB) {
177 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
178 } else {
179 b(slow_case);
180 }
181 }
182
183 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
184 assert_different_registers(obj, klass, len);
185
186 if (UseCompactObjectHeaders || EnableValhalla) {
187 ldr(t1, Address(klass, Klass::prototype_header_offset()));
188 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
189 } else {
190 mov(t1, checked_cast<int32_t>(markWord::prototype().value()));
191 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
192 }
193
194 if (!UseCompactObjectHeaders) {
195 if (UseCompressedClassPointers) { // Take care not to kill klass
196 encode_klass_not_null(t1, klass);
197 strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
198 } else {
199 str(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
200 }
201 }
202
203 if (len->is_valid()) {
204 strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
205 int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
206 if (!is_aligned(base_offset, BytesPerWord)) {
207 assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
208 // Clear gap/first 4 bytes following the length field.
209 strw(zr, Address(obj, base_offset));
210 }
211 } else if (UseCompressedClassPointers && !UseCompactObjectHeaders) {
212 store_klass_gap(obj, zr);
213 }
214 }
311 // following the length field in initialize_header().
312 int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
313 // clear rest of allocated space
314 if (zero_array) {
315 initialize_body(obj, arr_size, base_offset, t1, t2);
316 }
317 if (Compilation::current()->bailed_out()) {
318 return;
319 }
320
321 membar(StoreStore);
322
323 if (CURRENT_ENV->dtrace_alloc_probes()) {
324 assert(obj == r0, "must be");
325 far_call(RuntimeAddress(Runtime1::entry_for(C1StubId::dtrace_object_alloc_id)));
326 }
327
328 verify_oop(obj);
329 }
330
331 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) {
332 MacroAssembler::build_frame(frame_size_in_bytes);
333
334 if (needs_stack_repair) {
335 save_stack_increment(sp_inc, frame_size_in_bytes);
336 }
337 if (reset_orig_pc) {
338 // Zero orig_pc to detect deoptimization during buffering in the entry points
339 str(zr, Address(sp, sp_offset_for_orig_pc));
340 }
341 }
342
343 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) {
344 // Make sure there is enough stack space for this method's activation.
345 // Note that we do this before creating a frame.
346 assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
347 generate_stack_overflow_check(bang_size_in_bytes);
348
349 build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, has_scalarized_args, needs_stack_repair);
350
351 // Insert nmethod entry barrier into frame.
352 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
353 bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
354
355 if (verified_inline_entry_label != nullptr) {
356 // Jump here from the scalarized entry points that already created the frame.
357 bind(*verified_inline_entry_label);
358 }
359 }
360
361 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
362 // If we have to make this method not-entrant we'll overwrite its
363 // first instruction with a jump. For this action to be legal we
364 // must ensure that this first instruction is a B, BL, NOP, BKPT,
365 // SVC, HVC, or SMC. Make it a NOP.
366 nop();
367 if (C1Breakpoint) brk(1);
368 }
369
370 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) {
371 assert(InlineTypePassFieldsAsArgs, "sanity");
372 // Make sure there is enough stack space for this method's activation.
373 assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
374 generate_stack_overflow_check(bang_size_in_bytes);
375
376 GrowableArray<SigEntry>* sig = ces->sig();
377 GrowableArray<SigEntry>* sig_cc = is_inline_ro_entry ? ces->sig_cc_ro() : ces->sig_cc();
378 VMRegPair* regs = ces->regs();
379 VMRegPair* regs_cc = is_inline_ro_entry ? ces->regs_cc_ro() : ces->regs_cc();
380 int args_on_stack = ces->args_on_stack();
381 int args_on_stack_cc = is_inline_ro_entry ? ces->args_on_stack_cc_ro() : ces->args_on_stack_cc();
382
383 assert(sig->length() <= sig_cc->length(), "Zero-sized inline class not allowed!");
384 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sig_cc->length());
385 int args_passed = sig->length();
386 int args_passed_cc = SigEntry::fill_sig_bt(sig_cc, sig_bt);
387
388 // Create a temp frame so we can call into the runtime. It must be properly set up to accommodate GC.
389 build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, true, ces->c1_needs_stack_repair());
390
391 // The runtime call might safepoint, make sure nmethod entry barrier is executed
392 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
393 // C1 code is not hot enough to micro optimize the nmethod entry barrier with an out-of-line stub
394 bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
395
396 // FIXME -- call runtime only if we cannot in-line allocate all the incoming inline type args.
397 mov(r19, (intptr_t) ces->method());
398 if (is_inline_ro_entry) {
399 far_call(RuntimeAddress(Runtime1::entry_for(C1StubId::buffer_inline_args_no_receiver_id)));
400 } else {
401 far_call(RuntimeAddress(Runtime1::entry_for(C1StubId::buffer_inline_args_id)));
402 }
403 int rt_call_offset = offset();
404
405 // The runtime call returns the new array in r20 instead of the usual r0
406 // because r0 is also j_rarg7 which may be holding a live argument here.
407 Register val_array = r20;
408
409 // Remove the temp frame
410 MacroAssembler::remove_frame(frame_size_in_bytes);
411
412 // Check if we need to extend the stack for packing
413 int sp_inc = 0;
414 if (args_on_stack > args_on_stack_cc) {
415 sp_inc = extend_stack_for_inline_args(args_on_stack);
416 }
417
418 shuffle_inline_args(true, is_inline_ro_entry, sig_cc,
419 args_passed_cc, args_on_stack_cc, regs_cc, // from
420 args_passed, args_on_stack, regs, // to
421 sp_inc, val_array);
422
423 // Create the real frame. Below jump will then skip over the stack banging and frame
424 // setup code in the verified_inline_entry (which has a different real_frame_size).
425 build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, sp_inc, false, ces->c1_needs_stack_repair());
426
427 b(verified_inline_entry_label);
428 return rt_call_offset;
429 }
430
431
432 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
433 // rfp, + 0: link
434 // + 1: return address
435 // + 2: argument with offset 0
436 // + 3: argument with offset 1
437 // + 4: ...
438
439 ldr(reg, Address(rfp, (offset_in_words + 2) * BytesPerWord));
440 }
441
442 #ifndef PRODUCT
443
444 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
445 if (!VerifyOops) return;
446 verify_oop_addr(Address(sp, stack_offset));
447 }
448
449 void C1_MacroAssembler::verify_not_null_oop(Register r) {
450 if (!VerifyOops) return;
451 Label not_null;
|