< prev index next >

src/hotspot/cpu/aarch64/c1_MacroAssembler_aarch64.cpp

Print this page

 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 "precompiled.hpp"
 27 #include "c1/c1_MacroAssembler.hpp"
 28 #include "c1/c1_Runtime1.hpp"
 29 #include "gc/shared/barrierSetAssembler.hpp"
 30 #include "gc/shared/collectedHeap.hpp"


 31 #include "gc/shared/tlab_globals.hpp"
 32 #include "interpreter/interpreter.hpp"
 33 #include "oops/arrayOop.hpp"
 34 #include "oops/markWord.hpp"
 35 #include "runtime/basicLock.hpp"
 36 #include "runtime/os.hpp"
 37 #include "runtime/sharedRuntime.hpp"
 38 #include "runtime/stubRoutines.hpp"
 39 
 40 void C1_MacroAssembler::float_cmp(bool is_float, int unordered_result,
 41                                   FloatRegister f0, FloatRegister f1,
 42                                   Register result)
 43 {
 44   Label done;
 45   if (is_float) {
 46     fcmps(f0, f1);
 47   } else {
 48     fcmpd(f0, f1);
 49   }
 50   if (unordered_result < 0) {

 71   // save object being locked into the BasicObjectLock
 72   str(obj, Address(disp_hdr, BasicObjectLock::obj_offset()));
 73 
 74   null_check_offset = offset();
 75 
 76   if (DiagnoseSyncOnValueBasedClasses != 0) {
 77     load_klass(hdr, obj);
 78     ldrw(hdr, Address(hdr, Klass::access_flags_offset()));
 79     tstw(hdr, JVM_ACC_IS_VALUE_BASED_CLASS);
 80     br(Assembler::NE, slow_case);
 81   }
 82 
 83   // Load object header
 84   ldr(hdr, Address(obj, hdr_offset));
 85   if (LockingMode == LM_LIGHTWEIGHT) {
 86     lightweight_lock(obj, hdr, temp, rscratch2, slow_case);
 87   } else if (LockingMode == LM_LEGACY) {
 88     Label done;
 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

163       cmpxchgptr(disp_hdr, hdr, obj, rscratch2, done, &slow_case);
164     }
165     // done
166     bind(done);
167   }
168   decrement(Address(rthread, JavaThread::held_monitor_count_offset()));
169 }
170 
171 
172 // Defines obj, preserves var_size_in_bytes
173 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
174   if (UseTLAB) {
175     tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
176   } else {
177     b(slow_case);
178   }
179 }
180 
181 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
182   assert_different_registers(obj, klass, len);
183   // This assumes that all prototype bits fit in an int32_t
184   mov(t1, (int32_t)(intptr_t)markWord::prototype().value());






185   str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
186 
187   if (UseCompressedClassPointers) { // Take care not to kill klass
188     encode_klass_not_null(t1, klass);
189     strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
190   } else {
191     str(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
192   }
193 
194   if (len->is_valid()) {
195     strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
196   } else if (UseCompressedClassPointers) {
197     store_klass_gap(obj, zr);
198   }
199 }
200 
201 // preserves obj, destroys len_in_bytes
202 //
203 // Scratch registers: t1 = r10, t2 = r11
204 //

254      } else if (con_size_in_bytes > hdr_size_in_bytes) {
255        con_size_in_bytes -= hdr_size_in_bytes;
256        lea(t1, Address(obj, hdr_size_in_bytes));
257        address tpc = zero_words(t1, con_size_in_bytes / BytesPerWord);
258        if (tpc == nullptr) {
259          Compilation::current()->bailout("no space for trampoline stub");
260          return;
261        }
262      }
263   }
264 
265   membar(StoreStore);
266 
267   if (CURRENT_ENV->dtrace_alloc_probes()) {
268     assert(obj == r0, "must be");
269     far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
270   }
271 
272   verify_oop(obj);
273 }

274 void C1_MacroAssembler::allocate_array(Register obj, Register len, Register t1, Register t2, int header_size, int f, Register klass, Label& slow_case) {
275   assert_different_registers(obj, len, t1, t2, klass);
276 
277   // determine alignment mask
278   assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");
279 
280   // check for negative or excessive length
281   mov(rscratch1, (int32_t)max_array_allocation_length);
282   cmp(len, rscratch1);
283   br(Assembler::HS, slow_case);
284 
285   const Register arr_size = t2; // okay to be the same
286   // align object end
287   mov(arr_size, (int32_t)header_size * BytesPerWord + MinObjAlignmentInBytesMask);
288   add(arr_size, arr_size, len, ext::uxtw, f);
289   andr(arr_size, arr_size, ~MinObjAlignmentInBytesMask);
290 
291   try_allocate(obj, arr_size, 0, t1, t2, slow_case);
292 
293   initialize_header(obj, klass, len, t1, t2);
294 
295   // clear rest of allocated space
296   initialize_body(obj, arr_size, header_size * BytesPerWord, t1, t2);
297   if (Compilation::current()->bailed_out()) {
298     return;
299   }
300 
301   membar(StoreStore);
302 
303   if (CURRENT_ENV->dtrace_alloc_probes()) {
304     assert(obj == r0, "must be");
305     far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
306   }
307 
308   verify_oop(obj);
309 }
310 
311 void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes) {
312   assert(bang_size_in_bytes >= framesize, "stack bang size incorrect");











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

315   generate_stack_overflow_check(bang_size_in_bytes);
316   MacroAssembler::build_frame(framesize);

317 
318   // Insert nmethod entry barrier into frame.
319   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
320   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
321 }
322 
323 void C1_MacroAssembler::remove_frame(int framesize) {
324   MacroAssembler::remove_frame(framesize);


325 }
326 
327 
328 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
329   // If we have to make this method not-entrant we'll overwrite its
330   // first instruction with a jump.  For this action to be legal we
331   // must ensure that this first instruction is a B, BL, NOP, BKPT,
332   // SVC, HVC, or SMC.  Make it a NOP.
333   nop();

334 }
335 






























































336 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
337   // rfp, + 0: link
338   //     + 1: return address
339   //     + 2: argument with offset 0
340   //     + 3: argument with offset 1
341   //     + 4: ...
342 
343   ldr(reg, Address(rfp, (offset_in_words + 2) * BytesPerWord));
344 }
345 
346 #ifndef PRODUCT
347 
348 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
349   if (!VerifyOops) return;
350   verify_oop_addr(Address(sp, stack_offset));
351 }
352 
353 void C1_MacroAssembler::verify_not_null_oop(Register r) {
354   if (!VerifyOops) return;
355   Label not_null;

 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 "precompiled.hpp"
 27 #include "c1/c1_MacroAssembler.hpp"
 28 #include "c1/c1_Runtime1.hpp"
 29 #include "gc/shared/barrierSetAssembler.hpp"
 30 #include "gc/shared/collectedHeap.hpp"
 31 #include "gc/shared/barrierSet.hpp"
 32 #include "gc/shared/barrierSetAssembler.hpp"
 33 #include "gc/shared/tlab_globals.hpp"
 34 #include "interpreter/interpreter.hpp"
 35 #include "oops/arrayOop.hpp"
 36 #include "oops/markWord.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) {

 73   // save object being locked into the BasicObjectLock
 74   str(obj, Address(disp_hdr, BasicObjectLock::obj_offset()));
 75 
 76   null_check_offset = offset();
 77 
 78   if (DiagnoseSyncOnValueBasedClasses != 0) {
 79     load_klass(hdr, obj);
 80     ldrw(hdr, Address(hdr, Klass::access_flags_offset()));
 81     tstw(hdr, JVM_ACC_IS_VALUE_BASED_CLASS);
 82     br(Assembler::NE, slow_case);
 83   }
 84 
 85   // Load object header
 86   ldr(hdr, Address(obj, hdr_offset));
 87   if (LockingMode == LM_LIGHTWEIGHT) {
 88     lightweight_lock(obj, hdr, temp, rscratch2, slow_case);
 89   } else if (LockingMode == LM_LEGACY) {
 90     Label done;
 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

171       cmpxchgptr(disp_hdr, hdr, obj, rscratch2, done, &slow_case);
172     }
173     // done
174     bind(done);
175   }
176   decrement(Address(rthread, JavaThread::held_monitor_count_offset()));
177 }
178 
179 
180 // Defines obj, preserves var_size_in_bytes
181 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
182   if (UseTLAB) {
183     tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
184   } else {
185     b(slow_case);
186   }
187 }
188 
189 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
190   assert_different_registers(obj, klass, len);
191   if (EnableValhalla) {
192     // Need to copy markWord::prototype header for klass
193     assert_different_registers(obj, klass, len, t1, t2);
194     ldr(t1, Address(klass, Klass::prototype_header_offset()));
195   } else {
196     // This assumes that all prototype bits fit in an int32_t
197     mov(t1, (int32_t)(intptr_t)markWord::prototype().value());
198   }
199   str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
200 
201   if (UseCompressedClassPointers) { // Take care not to kill klass
202     encode_klass_not_null(t1, klass);
203     strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
204   } else {
205     str(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
206   }
207 
208   if (len->is_valid()) {
209     strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
210   } else if (UseCompressedClassPointers) {
211     store_klass_gap(obj, zr);
212   }
213 }
214 
215 // preserves obj, destroys len_in_bytes
216 //
217 // Scratch registers: t1 = r10, t2 = r11
218 //

268      } else if (con_size_in_bytes > hdr_size_in_bytes) {
269        con_size_in_bytes -= hdr_size_in_bytes;
270        lea(t1, Address(obj, hdr_size_in_bytes));
271        address tpc = zero_words(t1, con_size_in_bytes / BytesPerWord);
272        if (tpc == nullptr) {
273          Compilation::current()->bailout("no space for trampoline stub");
274          return;
275        }
276      }
277   }
278 
279   membar(StoreStore);
280 
281   if (CURRENT_ENV->dtrace_alloc_probes()) {
282     assert(obj == r0, "must be");
283     far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
284   }
285 
286   verify_oop(obj);
287 }
288 
289 void C1_MacroAssembler::allocate_array(Register obj, Register len, Register t1, Register t2, int header_size, int f, Register klass, Label& slow_case) {
290   assert_different_registers(obj, len, t1, t2, klass);
291 
292   // determine alignment mask
293   assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");
294 
295   // check for negative or excessive length
296   mov(rscratch1, (int32_t)max_array_allocation_length);
297   cmp(len, rscratch1);
298   br(Assembler::HS, slow_case);
299 
300   const Register arr_size = t2; // okay to be the same
301   // align object end
302   mov(arr_size, (int32_t)header_size * BytesPerWord + MinObjAlignmentInBytesMask);
303   add(arr_size, arr_size, len, ext::uxtw, f);
304   andr(arr_size, arr_size, ~MinObjAlignmentInBytesMask);
305 
306   try_allocate(obj, arr_size, 0, t1, t2, slow_case);
307 
308   initialize_header(obj, klass, len, t1, t2);
309 
310   // clear rest of allocated space
311   initialize_body(obj, arr_size, header_size * BytesPerWord, t1, t2);
312   if (Compilation::current()->bailed_out()) {
313     return;
314   }
315 
316   membar(StoreStore);
317 
318   if (CURRENT_ENV->dtrace_alloc_probes()) {
319     assert(obj == r0, "must be");
320     far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
321   }
322 
323   verify_oop(obj);
324 }
325 
326 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) {
327   MacroAssembler::build_frame(frame_size_in_bytes);
328 
329   if (needs_stack_repair) {
330     save_stack_increment(sp_inc, frame_size_in_bytes);
331   }
332   if (reset_orig_pc) {
333     // Zero orig_pc to detect deoptimization during buffering in the entry points
334     str(zr, Address(sp, sp_offset_for_orig_pc));
335   }
336 }
337 
338 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) {
339   // Make sure there is enough stack space for this method's activation.
340   // Note that we do this before creating a frame.
341   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
342   generate_stack_overflow_check(bang_size_in_bytes);
343 
344   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, has_scalarized_args, needs_stack_repair);
345 
346   // Insert nmethod entry barrier into frame.
347   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
348   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);

349 
350   if (verified_inline_entry_label != nullptr) {
351     // Jump here from the scalarized entry points that already created the frame.
352     bind(*verified_inline_entry_label);
353   }
354 }
355 

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