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

 82   // load object
 83   ldr(obj, Address(disp_hdr, BasicObjectLock::obj_offset()));
 84   verify_oop(obj);
 85 
 86   lightweight_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     if (UseCompressedClassPointers) { // Take care not to kill klass
109       encode_klass_not_null(t1, klass);
110       strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
111     } else {
112       str(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
113     }
114   }
115 
116   if (len->is_valid()) {
117     strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
118     int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
119     if (!is_aligned(base_offset, BytesPerWord)) {
120       assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
121       // Clear gap/first 4 bytes following the length field.
122       strw(zr, Address(obj, base_offset));
123     }
124   } else if (UseCompressedClassPointers && !UseCompactObjectHeaders) {
125     store_klass_gap(obj, zr);
126   }
127 }

224   // following the length field in initialize_header().
225   int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
226   // clear rest of allocated space
227   if (zero_array) {
228     initialize_body(obj, arr_size, base_offset, t1, t2);
229   }
230   if (Compilation::current()->bailed_out()) {
231     return;
232   }
233 
234   membar(StoreStore);
235 
236   if (CURRENT_ENV->dtrace_alloc_probes()) {
237     assert(obj == r0, "must be");
238     far_call(RuntimeAddress(Runtime1::entry_for(StubId::c1_dtrace_object_alloc_id)));
239   }
240 
241   verify_oop(obj);
242 }
243 
244 void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes) {
245   assert(bang_size_in_bytes >= framesize, "stack bang size incorrect");











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

248   generate_stack_overflow_check(bang_size_in_bytes);
249   MacroAssembler::build_frame(framesize);

250 
251   // Insert nmethod entry barrier into frame.
252   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
253   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
254 }
255 
256 void C1_MacroAssembler::remove_frame(int framesize) {
257   MacroAssembler::remove_frame(framesize);


258 }
259 
260 
261 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
262   // If we have to make this method not-entrant we'll overwrite its
263   // first instruction with a jump.  For this action to be legal we
264   // must ensure that this first instruction is a B, BL, NOP, BKPT,
265   // SVC, HVC, or SMC.  Make it a NOP.
266   nop();

267 }
268 






























































269 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
270   // rfp, + 0: link
271   //     + 1: return address
272   //     + 2: argument with offset 0
273   //     + 3: argument with offset 1
274   //     + 4: ...
275 
276   ldr(reg, Address(rfp, (offset_in_words + 2) * BytesPerWord));
277 }
278 
279 #ifndef PRODUCT
280 
281 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
282   if (!VerifyOops) return;
283   verify_oop_addr(Address(sp, stack_offset));
284 }
285 
286 void C1_MacroAssembler::verify_not_null_oop(Register r) {
287   if (!VerifyOops) return;
288   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) {

 84   // load object
 85   ldr(obj, Address(disp_hdr, BasicObjectLock::obj_offset()));
 86   verify_oop(obj);
 87 
 88   lightweight_unlock(obj, hdr, temp, rscratch2, slow_case);
 89 }
 90 
 91 
 92 // Defines obj, preserves var_size_in_bytes
 93 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
 94   if (UseTLAB) {
 95     tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
 96   } else {
 97     b(slow_case);
 98   }
 99 }
100 
101 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
102   assert_different_registers(obj, klass, len);
103 
104   if (UseCompactObjectHeaders || EnableValhalla) {
105     // COH: Markword contains class pointer which is only known at runtime.
106     // Valhalla: Could have value class which has a different prototype header to a normal object.
107     // In both cases, we need to fetch dynamically.
108     ldr(t1, Address(klass, Klass::prototype_header_offset()));
109     str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
110   } else {
111     // Otherwise: Can use the statically computed prototype header which is the same for every object.
112     mov(t1, checked_cast<int32_t>(markWord::prototype().value()));
113     str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
114   }
115 
116   if (!UseCompactObjectHeaders) {
117     // COH: Markword already contains class pointer. Nothing else to do.
118     // Otherwise: Fetch klass pointer following the markword
119     if (UseCompressedClassPointers) { // Take care not to kill klass
120       encode_klass_not_null(t1, klass);
121       strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
122     } else {
123       str(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
124     }
125   }
126 
127   if (len->is_valid()) {
128     strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
129     int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
130     if (!is_aligned(base_offset, BytesPerWord)) {
131       assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
132       // Clear gap/first 4 bytes following the length field.
133       strw(zr, Address(obj, base_offset));
134     }
135   } else if (UseCompressedClassPointers && !UseCompactObjectHeaders) {
136     store_klass_gap(obj, zr);
137   }
138 }

235   // following the length field in initialize_header().
236   int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
237   // clear rest of allocated space
238   if (zero_array) {
239     initialize_body(obj, arr_size, base_offset, t1, t2);
240   }
241   if (Compilation::current()->bailed_out()) {
242     return;
243   }
244 
245   membar(StoreStore);
246 
247   if (CURRENT_ENV->dtrace_alloc_probes()) {
248     assert(obj == r0, "must be");
249     far_call(RuntimeAddress(Runtime1::entry_for(StubId::c1_dtrace_object_alloc_id)));
250   }
251 
252   verify_oop(obj);
253 }
254 
255 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) {
256   MacroAssembler::build_frame(frame_size_in_bytes);
257 
258   if (needs_stack_repair) {
259     save_stack_increment(sp_inc, frame_size_in_bytes);
260   }
261   if (reset_orig_pc) {
262     // Zero orig_pc to detect deoptimization during buffering in the entry points
263     str(zr, Address(sp, sp_offset_for_orig_pc));
264   }
265 }
266 
267 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) {
268   // Make sure there is enough stack space for this method's activation.
269   // Note that we do this before creating a frame.
270   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
271   generate_stack_overflow_check(bang_size_in_bytes);
272 
273   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, has_scalarized_args, needs_stack_repair);
274 
275   // Insert nmethod entry barrier into frame.
276   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
277   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);

278 
279   if (verified_inline_entry_label != nullptr) {
280     // Jump here from the scalarized entry points that already created the frame.
281     bind(*verified_inline_entry_label);
282   }
283 }
284 

285 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
286   // If we have to make this method not-entrant we'll overwrite its
287   // first instruction with a jump.  For this action to be legal we
288   // must ensure that this first instruction is a B, BL, NOP, BKPT,
289   // SVC, HVC, or SMC.  Make it a NOP.
290   nop();
291   if (C1Breakpoint) brk(1);
292 }
293 
294 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) {
295   assert(InlineTypePassFieldsAsArgs, "sanity");
296   // Make sure there is enough stack space for this method's activation.
297   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
298   generate_stack_overflow_check(bang_size_in_bytes);
299 
300   GrowableArray<SigEntry>* sig    = ces->sig();
301   GrowableArray<SigEntry>* sig_cc = is_inline_ro_entry ? ces->sig_cc_ro() : ces->sig_cc();
302   VMRegPair* regs      = ces->regs();
303   VMRegPair* regs_cc   = is_inline_ro_entry ? ces->regs_cc_ro() : ces->regs_cc();
304   int args_on_stack    = ces->args_on_stack();
305   int args_on_stack_cc = is_inline_ro_entry ? ces->args_on_stack_cc_ro() : ces->args_on_stack_cc();
306 
307   assert(sig->length() <= sig_cc->length(), "Zero-sized inline class not allowed!");
308   BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sig_cc->length());
309   int args_passed = sig->length();
310   int args_passed_cc = SigEntry::fill_sig_bt(sig_cc, sig_bt);
311 
312   // Create a temp frame so we can call into the runtime. It must be properly set up to accommodate GC.
313   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, true, ces->c1_needs_stack_repair());
314 
315   // The runtime call might safepoint, make sure nmethod entry barrier is executed
316   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
317   // C1 code is not hot enough to micro optimize the nmethod entry barrier with an out-of-line stub
318   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */, nullptr /* guard */);
319 
320   // FIXME -- call runtime only if we cannot in-line allocate all the incoming inline type args.
321   mov(r19, (intptr_t) ces->method());
322   if (is_inline_ro_entry) {
323     far_call(RuntimeAddress(Runtime1::entry_for(StubId::c1_buffer_inline_args_no_receiver_id)));
324   } else {
325     far_call(RuntimeAddress(Runtime1::entry_for(StubId::c1_buffer_inline_args_id)));
326   }
327   int rt_call_offset = offset();
328 
329   // The runtime call returns the new array in r20 instead of the usual r0
330   // because r0 is also j_rarg7 which may be holding a live argument here.
331   Register val_array = r20;
332 
333   // Remove the temp frame
334   MacroAssembler::remove_frame(frame_size_in_bytes);
335 
336   // Check if we need to extend the stack for packing
337   int sp_inc = 0;
338   if (args_on_stack > args_on_stack_cc) {
339     sp_inc = extend_stack_for_inline_args(args_on_stack);
340   }
341 
342   shuffle_inline_args(true, is_inline_ro_entry, sig_cc,
343                       args_passed_cc, args_on_stack_cc, regs_cc, // from
344                       args_passed, args_on_stack, regs,          // to
345                       sp_inc, val_array);
346 
347   // Create the real frame. Below jump will then skip over the stack banging and frame
348   // setup code in the verified_inline_entry (which has a different real_frame_size).
349   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, sp_inc, false, ces->c1_needs_stack_repair());
350 
351   b(verified_inline_entry_label);
352   return rt_call_offset;
353 }
354 
355 
356 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
357   // rfp, + 0: link
358   //     + 1: return address
359   //     + 2: argument with offset 0
360   //     + 3: argument with offset 1
361   //     + 4: ...
362 
363   ldr(reg, Address(rfp, (offset_in_words + 2) * BytesPerWord));
364 }
365 
366 #ifndef PRODUCT
367 
368 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
369   if (!VerifyOops) return;
370   verify_oop_addr(Address(sp, stack_offset));
371 }
372 
373 void C1_MacroAssembler::verify_not_null_oop(Register r) {
374   if (!VerifyOops) return;
375   Label not_null;
< prev index next >