< prev index next >

src/hotspot/cpu/x86/c1_MacroAssembler_x86.cpp

Print this page

 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "c1/c1_MacroAssembler.hpp"
 26 #include "c1/c1_Runtime1.hpp"
 27 #include "code/compiledIC.hpp"
 28 #include "compiler/compilerDefinitions.inline.hpp"
 29 #include "gc/shared/barrierSet.hpp"
 30 #include "gc/shared/barrierSetAssembler.hpp"
 31 #include "gc/shared/collectedHeap.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/globals.hpp"
 38 #include "runtime/os.hpp"
 39 #include "runtime/sharedRuntime.hpp"
 40 #include "runtime/stubRoutines.hpp"
 41 #include "utilities/checkedCast.hpp"
 42 #include "utilities/globalDefinitions.hpp"
 43 
 44 int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register basic_lock, Register tmp, Label& slow_case) {
 45   assert(hdr == rax, "hdr must be rax, for the cmpxchg instruction");
 46   assert_different_registers(hdr, obj, basic_lock, tmp);
 47   int null_check_offset = -1;
 48 
 49   verify_oop(obj);
 50 
 51   // save object being locked into the BasicObjectLock
 52   movptr(Address(basic_lock, BasicObjectLock::obj_offset()), obj);
 53 
 54   null_check_offset = offset();
 55 
 56   fast_lock(basic_lock, obj, hdr, tmp, slow_case);

 65   // load object
 66   movptr(obj, Address(basic_lock, BasicObjectLock::obj_offset()));
 67   verify_oop(obj);
 68 
 69   fast_unlock(obj, rax, hdr, slow_case);
 70 }
 71 
 72 
 73 // Defines obj, preserves var_size_in_bytes
 74 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
 75   if (UseTLAB) {
 76     tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
 77   } else {
 78     jmp(slow_case);
 79   }
 80 }
 81 
 82 
 83 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
 84   assert_different_registers(obj, klass, len, t1, t2);
 85   if (UseCompactObjectHeaders) {



 86     movptr(t1, Address(klass, Klass::prototype_header_offset()));
 87     movptr(Address(obj, oopDesc::mark_offset_in_bytes()), t1);
 88   } else { // Take care not to kill klass

 89     movptr(Address(obj, oopDesc::mark_offset_in_bytes()), checked_cast<int32_t>(markWord::prototype().value()));




 90     movptr(t1, klass);
 91     encode_klass_not_null(t1, rscratch1);
 92     movl(Address(obj, oopDesc::klass_offset_in_bytes()), t1);
 93   }
 94 
 95   if (len->is_valid()) {
 96     movl(Address(obj, arrayOopDesc::length_offset_in_bytes()), len);
 97     int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
 98     if (!is_aligned(base_offset, BytesPerWord)) {
 99       assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
100       // Clear gap/first 4 bytes following the length field.
101       xorl(t1, t1);
102       movl(Address(obj, base_offset), t1);
103     }
104   } else if (!UseCompactObjectHeaders) {
105     xorptr(t1, t1);
106     store_klass_gap(obj, t1);
107   }
108 }
109 
110 
111 // preserves obj, destroys len_in_bytes

202 
203   initialize_header(obj, klass, len, t1, t2);
204 
205   // clear rest of allocated space
206   if (zero_array) {
207     const Register len_zero = len;
208     // Align-up to word boundary, because we clear the 4 bytes potentially
209     // following the length field in initialize_header().
210     int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
211     initialize_body(obj, arr_size, base_offset, len_zero);
212   }
213 
214   if (CURRENT_ENV->dtrace_alloc_probes()) {
215     assert(obj == rax, "must be");
216     call(RuntimeAddress(Runtime1::entry_for(StubId::c1_dtrace_object_alloc_id)));
217   }
218 
219   verify_oop(obj);
220 }
221 
222 void C1_MacroAssembler::build_frame(int frame_size_in_bytes, int bang_size_in_bytes) {
223   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
























224   // Make sure there is enough stack space for this method's activation.
225   // Note that we do this before doing an enter(). This matches the
226   // ordering of C2's stack overflow check / rsp decrement and allows
227   // the SharedRuntime stack overflow handling to be consistent
228   // between the two compilers.

229   generate_stack_overflow_check(bang_size_in_bytes);
230 
231   push(rbp);
232   if (PreserveFramePointer) {
233     mov(rbp, rsp);
234   }
235   decrement(rsp, frame_size_in_bytes); // does not emit code for frame_size == 0
236 
237   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
238   // C1 code is not hot enough to micro optimize the nmethod entry barrier with an out-of-line stub
239   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */);
240 }
241 
242 
243 void C1_MacroAssembler::remove_frame(int frame_size_in_bytes) {
244   increment(rsp, frame_size_in_bytes);  // Does not emit code for frame_size == 0
245   pop(rbp);

246 }
247 
248 
249 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
250   if (breakAtEntry) int3();
251   // build frame
252 }
253 

























































254 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
255   // rbp, + 0: link
256   //     + 1: return address
257   //     + 2: argument with offset 0
258   //     + 3: argument with offset 1
259   //     + 4: ...
260 
261   movptr(reg, Address(rbp, (offset_in_words + 2) * BytesPerWord));
262 }
263 
264 #ifndef PRODUCT
265 
266 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
267   if (!VerifyOops) return;
268   verify_oop_addr(Address(rsp, stack_offset));
269 }
270 
271 void C1_MacroAssembler::verify_not_null_oop(Register r) {
272   if (!VerifyOops) return;
273   Label not_null;

 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "c1/c1_MacroAssembler.hpp"
 26 #include "c1/c1_Runtime1.hpp"
 27 #include "code/compiledIC.hpp"
 28 #include "compiler/compilerDefinitions.inline.hpp"
 29 #include "gc/shared/barrierSet.hpp"
 30 #include "gc/shared/barrierSetAssembler.hpp"
 31 #include "gc/shared/collectedHeap.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/frame.inline.hpp"
 39 #include "runtime/globals.hpp"
 40 #include "runtime/os.hpp"
 41 #include "runtime/sharedRuntime.hpp"
 42 #include "runtime/stubRoutines.hpp"
 43 #include "utilities/checkedCast.hpp"
 44 #include "utilities/globalDefinitions.hpp"
 45 
 46 int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register basic_lock, Register tmp, Label& slow_case) {
 47   assert(hdr == rax, "hdr must be rax, for the cmpxchg instruction");
 48   assert_different_registers(hdr, obj, basic_lock, tmp);
 49   int null_check_offset = -1;
 50 
 51   verify_oop(obj);
 52 
 53   // save object being locked into the BasicObjectLock
 54   movptr(Address(basic_lock, BasicObjectLock::obj_offset()), obj);
 55 
 56   null_check_offset = offset();
 57 
 58   fast_lock(basic_lock, obj, hdr, tmp, slow_case);

 67   // load object
 68   movptr(obj, Address(basic_lock, BasicObjectLock::obj_offset()));
 69   verify_oop(obj);
 70 
 71   fast_unlock(obj, rax, hdr, slow_case);
 72 }
 73 
 74 
 75 // Defines obj, preserves var_size_in_bytes
 76 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
 77   if (UseTLAB) {
 78     tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
 79   } else {
 80     jmp(slow_case);
 81   }
 82 }
 83 
 84 
 85 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
 86   assert_different_registers(obj, klass, len, t1, t2);
 87   if (UseCompactObjectHeaders || Arguments::is_valhalla_enabled()) {
 88     // COH: Markword contains class pointer which is only known at runtime.
 89     // Valhalla: Could have value class which has a different prototype header to a normal object.
 90     // In both cases, we need to fetch dynamically.
 91     movptr(t1, Address(klass, Klass::prototype_header_offset()));
 92     movptr(Address(obj, oopDesc::mark_offset_in_bytes()), t1);
 93   } else {
 94     // Otherwise: Can use the statically computed prototype header which is the same for every object.
 95     movptr(Address(obj, oopDesc::mark_offset_in_bytes()), checked_cast<int32_t>(markWord::prototype().value()));
 96   }
 97   if (!UseCompactObjectHeaders) {
 98     // COH: Markword already contains class pointer. Nothing else to do.
 99     // Otherwise: Store encoded klass pointer following the markword
100     movptr(t1, klass);
101     encode_klass_not_null(t1, rscratch1); // Take care not to kill klass
102     movl(Address(obj, oopDesc::klass_offset_in_bytes()), t1);
103   }
104 
105   if (len->is_valid()) {
106     movl(Address(obj, arrayOopDesc::length_offset_in_bytes()), len);
107     int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;
108     if (!is_aligned(base_offset, BytesPerWord)) {
109       assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
110       // Clear gap/first 4 bytes following the length field.
111       xorl(t1, t1);
112       movl(Address(obj, base_offset), t1);
113     }
114   } else if (!UseCompactObjectHeaders) {
115     xorptr(t1, t1);
116     store_klass_gap(obj, t1);
117   }
118 }
119 
120 
121 // preserves obj, destroys len_in_bytes

212 
213   initialize_header(obj, klass, len, t1, t2);
214 
215   // clear rest of allocated space
216   if (zero_array) {
217     const Register len_zero = len;
218     // Align-up to word boundary, because we clear the 4 bytes potentially
219     // following the length field in initialize_header().
220     int base_offset = align_up(base_offset_in_bytes, BytesPerWord);
221     initialize_body(obj, arr_size, base_offset, len_zero);
222   }
223 
224   if (CURRENT_ENV->dtrace_alloc_probes()) {
225     assert(obj == rax, "must be");
226     call(RuntimeAddress(Runtime1::entry_for(StubId::c1_dtrace_object_alloc_id)));
227   }
228 
229   verify_oop(obj);
230 }
231 
232 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) {
233   push(rbp);
234 #ifdef ASSERT
235   if (sp_inc > 0) {
236     movl(Address(rsp, 0), badRegWordVal);
237     movl(Address(rsp, VMRegImpl::stack_slot_size), badRegWordVal);
238   }
239 #endif
240   if (PreserveFramePointer) {
241     mov(rbp, rsp);
242   }
243   decrement(rsp, frame_size_in_bytes);
244 
245   if (needs_stack_repair) {
246     // Save stack increment (also account for fixed framesize and rbp)
247     assert((sp_inc & (StackAlignmentInBytes-1)) == 0, "stack increment not aligned");
248     int real_frame_size = sp_inc + frame_size_in_bytes;
249     movptr(Address(rsp, frame_size_in_bytes - wordSize), real_frame_size);
250   }
251   if (reset_orig_pc) {
252     // Zero orig_pc to detect deoptimization during buffering in the entry points
253     movptr(Address(rsp, sp_offset_for_orig_pc), 0);
254   }
255 }
256 
257 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) {
258   // Make sure there is enough stack space for this method's activation.
259   // Note that we do this before doing an enter(). This matches the
260   // ordering of C2's stack overflow check / rsp decrement and allows
261   // the SharedRuntime stack overflow handling to be consistent
262   // between the two compilers.
263   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
264   generate_stack_overflow_check(bang_size_in_bytes);
265 
266   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, has_scalarized_args, needs_stack_repair);




267 
268   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
269   // C1 code is not hot enough to micro optimize the nmethod entry barrier with an out-of-line stub
270   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */);


271 
272   if (verified_inline_entry_label != nullptr) {
273     // Jump here from the scalarized entry points that already created the frame.
274     bind(*verified_inline_entry_label);
275   }
276 }
277 

278 void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
279   if (breakAtEntry) int3();
280   // build frame
281 }
282 
283 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) {
284   assert(InlineTypePassFieldsAsArgs, "sanity");
285   // Make sure there is enough stack space for this method's activation.
286   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
287   generate_stack_overflow_check(bang_size_in_bytes);
288 
289   GrowableArray<SigEntry>* sig    = ces->sig();
290   GrowableArray<SigEntry>* sig_cc = is_inline_ro_entry ? ces->sig_cc_ro() : ces->sig_cc();
291   VMRegPair* regs      = ces->regs();
292   VMRegPair* regs_cc   = is_inline_ro_entry ? ces->regs_cc_ro() : ces->regs_cc();
293   int args_on_stack    = ces->args_on_stack();
294   int args_on_stack_cc = is_inline_ro_entry ? ces->args_on_stack_cc_ro() : ces->args_on_stack_cc();
295 
296   assert(sig->length() <= sig_cc->length(), "Zero-sized inline class not allowed!");
297   BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sig_cc->length());
298   int args_passed = sig->length();
299   int args_passed_cc = SigEntry::fill_sig_bt(sig_cc, sig_bt);
300 
301   // Create a temp frame so we can call into the runtime. It must be properly set up to accommodate GC.
302   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, true, ces->c1_needs_stack_repair());
303 
304   // The runtime call might safepoint, make sure nmethod entry barrier is executed
305   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
306   // C1 code is not hot enough to micro optimize the nmethod entry barrier with an out-of-line stub
307   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */);
308 
309   movptr(rbx, (intptr_t)(ces->method()));
310   if (is_inline_ro_entry) {
311     call(RuntimeAddress(Runtime1::entry_for(StubId::c1_buffer_inline_args_no_receiver_id)));
312   } else {
313     call(RuntimeAddress(Runtime1::entry_for(StubId::c1_buffer_inline_args_id)));
314   }
315   int rt_call_offset = offset();
316 
317   // Remove the temp frame
318   addptr(rsp, frame_size_in_bytes);
319   pop(rbp);
320 
321   // Check if we need to extend the stack for packing
322   int sp_inc = 0;
323   if (args_on_stack > args_on_stack_cc) {
324     sp_inc = extend_stack_for_inline_args(args_on_stack);
325   }
326 
327   shuffle_inline_args(true, is_inline_ro_entry, sig_cc,
328                       args_passed_cc, args_on_stack_cc, regs_cc, // from
329                       args_passed, args_on_stack, regs,          // to
330                       sp_inc, rax);
331 
332   // Create the real frame. Below jump will then skip over the stack banging and frame
333   // setup code in the verified_inline_entry (which has a different real_frame_size).
334   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, sp_inc, false, ces->c1_needs_stack_repair());
335 
336   jmp(verified_inline_entry_label);
337   return rt_call_offset;
338 }
339 
340 void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
341   // rbp, + 0: link
342   //     + 1: return address
343   //     + 2: argument with offset 0
344   //     + 3: argument with offset 1
345   //     + 4: ...
346 
347   movptr(reg, Address(rbp, (offset_in_words + 2) * BytesPerWord));
348 }
349 
350 #ifndef PRODUCT
351 
352 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
353   if (!VerifyOops) return;
354   verify_oop_addr(Address(rsp, stack_offset));
355 }
356 
357 void C1_MacroAssembler::verify_not_null_oop(Register r) {
358   if (!VerifyOops) return;
359   Label not_null;
< prev index next >