< prev index next >

src/hotspot/cpu/aarch64/c1_MacroAssembler_aarch64.cpp

Print this page

 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) {

 71   str(obj, Address(disp_hdr, BasicObjectLock::obj_offset()));
 72 
 73   null_check_offset = offset();
 74 
 75   if (LockingMode == LM_LIGHTWEIGHT) {
 76     lightweight_lock(disp_hdr, obj, hdr, temp, rscratch2, slow_case);
 77   } else if (LockingMode == LM_LEGACY) {
 78 
 79     if (DiagnoseSyncOnValueBasedClasses != 0) {
 80       load_klass(hdr, obj);
 81       ldrb(hdr, Address(hdr, Klass::misc_flags_offset()));
 82       tst(hdr, KlassFlags::_misc_is_value_based_class);
 83       br(Assembler::NE, slow_case);
 84     }
 85 
 86     Label done;
 87     // Load object header
 88     ldr(hdr, Address(obj, hdr_offset));
 89     // and mark it as unlocked
 90     orr(hdr, hdr, markWord::unlocked_value);






 91     // save unlocked object header into the displaced header location on the stack
 92     str(hdr, Address(disp_hdr, 0));
 93     // test if object header is still the same (i.e. unlocked), and if so, store the
 94     // displaced header address in the object header - if it is not the same, get the
 95     // object header instead
 96     lea(rscratch2, Address(obj, hdr_offset));
 97     cmpxchgptr(hdr, disp_hdr, rscratch2, rscratch1, done, /*fallthough*/nullptr);
 98     // if the object header was the same, we're done
 99     // if the object header was not the same, it is now in the hdr register
100     // => test if it is a stack pointer into the same stack (recursive locking), i.e.:
101     //
102     // 1) (hdr & aligned_mask) == 0
103     // 2) sp <= hdr
104     // 3) hdr <= sp + page_size
105     //
106     // these 3 tests can be done by evaluating the following expression:
107     //
108     // (hdr - sp) & (aligned_mask - page_size)
109     //
110     // assuming both the stack pointer and page_size have their least

159     }
160     // done
161     bind(done);
162     dec_held_monitor_count(rscratch1);
163   }
164 }
165 
166 
167 // Defines obj, preserves var_size_in_bytes
168 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
169   if (UseTLAB) {
170     tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
171   } else {
172     b(slow_case);
173   }
174 }
175 
176 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
177   assert_different_registers(obj, klass, len);
178 
179   if (UseCompactObjectHeaders) {
180     ldr(t1, Address(klass, Klass::prototype_header_offset()));
181     str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
182   } else {
183     mov(t1, checked_cast<int32_t>(markWord::prototype().value()));
184     str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));



185     if (UseCompressedClassPointers) { // Take care not to kill klass
186       encode_klass_not_null(t1, klass);
187       strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
188     } else {
189       str(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
190     }
191   }
192 
193   if (len->is_valid()) {
194     strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
195     int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
196     if (!is_aligned(base_offset, BytesPerWord)) {
197       assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
198       // Clear gap/first 4 bytes following the length field.
199       strw(zr, Address(obj, base_offset));
200     }
201   } else if (UseCompressedClassPointers && !UseCompactObjectHeaders) {
202     store_klass_gap(obj, zr);
203   }
204 }

301   // following the length field in initialize_header().
302   int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
303   // clear rest of allocated space
304   if (zero_array) {
305     initialize_body(obj, arr_size, base_offset, t1, t2);
306   }
307   if (Compilation::current()->bailed_out()) {
308     return;
309   }
310 
311   membar(StoreStore);
312 
313   if (CURRENT_ENV->dtrace_alloc_probes()) {
314     assert(obj == r0, "must be");
315     far_call(RuntimeAddress(Runtime1::entry_for(C1StubId::dtrace_object_alloc_id)));
316   }
317 
318   verify_oop(obj);
319 }
320 
321 void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes) {
322   assert(bang_size_in_bytes >= framesize, "stack bang size incorrect");











323   // Make sure there is enough stack space for this method's activation.
324   // Note that we do this before creating a frame.

325   generate_stack_overflow_check(bang_size_in_bytes);
326   MacroAssembler::build_frame(framesize);

327 
328   // Insert nmethod entry barrier into frame.
329   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
330   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
331 }
332 
333 void C1_MacroAssembler::remove_frame(int framesize) {
334   MacroAssembler::remove_frame(framesize);


335 }
336 
337 
338 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
339   // If we have to make this method not-entrant we'll overwrite its
340   // first instruction with a jump.  For this action to be legal we
341   // must ensure that this first instruction is a B, BL, NOP, BKPT,
342   // SVC, HVC, or SMC.  Make it a NOP.
343   nop();






























































344 }
345 

346 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
347   // rfp, + 0: link
348   //     + 1: return address
349   //     + 2: argument with offset 0
350   //     + 3: argument with offset 1
351   //     + 4: ...
352 
353   ldr(reg, Address(rfp, (offset_in_words + 2) * BytesPerWord));
354 }
355 
356 #ifndef PRODUCT
357 
358 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
359   if (!VerifyOops) return;
360   verify_oop_addr(Address(sp, stack_offset));
361 }
362 
363 void C1_MacroAssembler::verify_not_null_oop(Register r) {
364   if (!VerifyOops) return;
365   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) {

 73   str(obj, Address(disp_hdr, BasicObjectLock::obj_offset()));
 74 
 75   null_check_offset = offset();
 76 
 77   if (LockingMode == LM_LIGHTWEIGHT) {
 78     lightweight_lock(disp_hdr, obj, hdr, temp, rscratch2, slow_case);
 79   } else if (LockingMode == LM_LEGACY) {
 80 
 81     if (DiagnoseSyncOnValueBasedClasses != 0) {
 82       load_klass(hdr, obj);
 83       ldrb(hdr, Address(hdr, Klass::misc_flags_offset()));
 84       tst(hdr, KlassFlags::_misc_is_value_based_class);
 85       br(Assembler::NE, slow_case);
 86     }
 87 
 88     Label done;
 89     // Load object header
 90     ldr(hdr, Address(obj, hdr_offset));
 91     // and mark it as unlocked
 92     orr(hdr, hdr, markWord::unlocked_value);
 93 
 94     if (EnableValhalla) {
 95       // Mask always_locked bit such that we go to the slow path if object is an inline type
 96       andr(hdr, hdr, ~markWord::inline_type_bit_in_place);
 97     }
 98 
 99     // save unlocked object header into the displaced header location on the stack
100     str(hdr, Address(disp_hdr, 0));
101     // test if object header is still the same (i.e. unlocked), and if so, store the
102     // displaced header address in the object header - if it is not the same, get the
103     // object header instead
104     lea(rscratch2, Address(obj, hdr_offset));
105     cmpxchgptr(hdr, disp_hdr, rscratch2, rscratch1, done, /*fallthough*/nullptr);
106     // if the object header was the same, we're done
107     // if the object header was not the same, it is now in the hdr register
108     // => test if it is a stack pointer into the same stack (recursive locking), i.e.:
109     //
110     // 1) (hdr & aligned_mask) == 0
111     // 2) sp <= hdr
112     // 3) hdr <= sp + page_size
113     //
114     // these 3 tests can be done by evaluating the following expression:
115     //
116     // (hdr - sp) & (aligned_mask - page_size)
117     //
118     // assuming both the stack pointer and page_size have their least

167     }
168     // done
169     bind(done);
170     dec_held_monitor_count(rscratch1);
171   }
172 }
173 
174 
175 // Defines obj, preserves var_size_in_bytes
176 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
177   if (UseTLAB) {
178     tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
179   } else {
180     b(slow_case);
181   }
182 }
183 
184 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
185   assert_different_registers(obj, klass, len);
186 
187   if (UseCompactObjectHeaders || EnableValhalla) {
188     ldr(t1, Address(klass, Klass::prototype_header_offset()));
189     str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
190   } else {
191     mov(t1, checked_cast<int32_t>(markWord::prototype().value()));
192     str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
193   }
194 
195   if (!UseCompactObjectHeaders) {
196     if (UseCompressedClassPointers) { // Take care not to kill klass
197       encode_klass_not_null(t1, klass);
198       strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
199     } else {
200       str(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
201     }
202   }
203 
204   if (len->is_valid()) {
205     strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
206     int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
207     if (!is_aligned(base_offset, BytesPerWord)) {
208       assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
209       // Clear gap/first 4 bytes following the length field.
210       strw(zr, Address(obj, base_offset));
211     }
212   } else if (UseCompressedClassPointers && !UseCompactObjectHeaders) {
213     store_klass_gap(obj, zr);
214   }
215 }

312   // following the length field in initialize_header().
313   int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
314   // clear rest of allocated space
315   if (zero_array) {
316     initialize_body(obj, arr_size, base_offset, t1, t2);
317   }
318   if (Compilation::current()->bailed_out()) {
319     return;
320   }
321 
322   membar(StoreStore);
323 
324   if (CURRENT_ENV->dtrace_alloc_probes()) {
325     assert(obj == r0, "must be");
326     far_call(RuntimeAddress(Runtime1::entry_for(C1StubId::dtrace_object_alloc_id)));
327   }
328 
329   verify_oop(obj);
330 }
331 
332 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) {
333   MacroAssembler::build_frame(frame_size_in_bytes);
334 
335   if (needs_stack_repair) {
336     save_stack_increment(sp_inc, frame_size_in_bytes);
337   }
338   if (reset_orig_pc) {
339     // Zero orig_pc to detect deoptimization during buffering in the entry points
340     str(zr, Address(sp, sp_offset_for_orig_pc));
341   }
342 }
343 
344 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) {
345   // Make sure there is enough stack space for this method's activation.
346   // Note that we do this before creating a frame.
347   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
348   generate_stack_overflow_check(bang_size_in_bytes);
349 
350   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, has_scalarized_args, needs_stack_repair);
351 
352   // Insert nmethod entry barrier into frame.
353   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
354   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);

355 
356   if (verified_inline_entry_label != nullptr) {
357     // Jump here from the scalarized entry points that already created the frame.
358     bind(*verified_inline_entry_label);
359   }
360 }
361 

362 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
363   // If we have to make this method not-entrant we'll overwrite its
364   // first instruction with a jump.  For this action to be legal we
365   // must ensure that this first instruction is a B, BL, NOP, BKPT,
366   // SVC, HVC, or SMC.  Make it a NOP.
367   nop();
368   if (C1Breakpoint) brk(1);
369 }
370 
371 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) {
372   assert(InlineTypePassFieldsAsArgs, "sanity");
373   // Make sure there is enough stack space for this method's activation.
374   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
375   generate_stack_overflow_check(bang_size_in_bytes);
376 
377   GrowableArray<SigEntry>* sig    = ces->sig();
378   GrowableArray<SigEntry>* sig_cc = is_inline_ro_entry ? ces->sig_cc_ro() : ces->sig_cc();
379   VMRegPair* regs      = ces->regs();
380   VMRegPair* regs_cc   = is_inline_ro_entry ? ces->regs_cc_ro() : ces->regs_cc();
381   int args_on_stack    = ces->args_on_stack();
382   int args_on_stack_cc = is_inline_ro_entry ? ces->args_on_stack_cc_ro() : ces->args_on_stack_cc();
383 
384   assert(sig->length() <= sig_cc->length(), "Zero-sized inline class not allowed!");
385   BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sig_cc->length());
386   int args_passed = sig->length();
387   int args_passed_cc = SigEntry::fill_sig_bt(sig_cc, sig_bt);
388 
389   // Create a temp frame so we can call into the runtime. It must be properly set up to accommodate GC.
390   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, true, ces->c1_needs_stack_repair());
391 
392   // The runtime call might safepoint, make sure nmethod entry barrier is executed
393   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
394   // C1 code is not hot enough to micro optimize the nmethod entry barrier with an out-of-line stub
395   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
396 
397   // FIXME -- call runtime only if we cannot in-line allocate all the incoming inline type args.
398   mov(r19, (intptr_t) ces->method());
399   if (is_inline_ro_entry) {
400     far_call(RuntimeAddress(Runtime1::entry_for(C1StubId::buffer_inline_args_no_receiver_id)));
401   } else {
402     far_call(RuntimeAddress(Runtime1::entry_for(C1StubId::buffer_inline_args_id)));
403   }
404   int rt_call_offset = offset();
405 
406   // The runtime call returns the new array in r20 instead of the usual r0
407   // because r0 is also j_rarg7 which may be holding a live argument here.
408   Register val_array = r20;
409 
410   // Remove the temp frame
411   MacroAssembler::remove_frame(frame_size_in_bytes);
412 
413   // Check if we need to extend the stack for packing
414   int sp_inc = 0;
415   if (args_on_stack > args_on_stack_cc) {
416     sp_inc = extend_stack_for_inline_args(args_on_stack);
417   }
418 
419   shuffle_inline_args(true, is_inline_ro_entry, sig_cc,
420                       args_passed_cc, args_on_stack_cc, regs_cc, // from
421                       args_passed, args_on_stack, regs,          // to
422                       sp_inc, val_array);
423 
424   // Create the real frame. Below jump will then skip over the stack banging and frame
425   // setup code in the verified_inline_entry (which has a different real_frame_size).
426   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, sp_inc, false, ces->c1_needs_stack_repair());
427 
428   b(verified_inline_entry_label);
429   return rt_call_offset;
430 }
431 
432 
433 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
434   // rfp, + 0: link
435   //     + 1: return address
436   //     + 2: argument with offset 0
437   //     + 3: argument with offset 1
438   //     + 4: ...
439 
440   ldr(reg, Address(rfp, (offset_in_words + 2) * BytesPerWord));
441 }
442 
443 #ifndef PRODUCT
444 
445 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
446   if (!VerifyOops) return;
447   verify_oop_addr(Address(sp, stack_offset));
448 }
449 
450 void C1_MacroAssembler::verify_not_null_oop(Register r) {
451   if (!VerifyOops) return;
452   Label not_null;
< prev index next >