< prev index next >

src/hotspot/cpu/x86/c1_MacroAssembler_x86.cpp

Print this page
@@ -32,10 +32,11 @@
  #include "gc/shared/tlab_globals.hpp"
  #include "interpreter/interpreter.hpp"
  #include "oops/arrayOop.hpp"
  #include "oops/markWord.hpp"
  #include "runtime/basicLock.hpp"
+ #include "runtime/frame.inline.hpp"
  #include "runtime/globals.hpp"
  #include "runtime/os.hpp"
  #include "runtime/sharedRuntime.hpp"
  #include "runtime/stubRoutines.hpp"
  #include "utilities/checkedCast.hpp"

@@ -80,21 +81,30 @@
  }
  
  
  void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
    assert_different_registers(obj, klass, len, t1, t2);
-   if (UseCompactObjectHeaders) {
+   if (UseCompactObjectHeaders || EnableValhalla) {
+     // COH: Markword contains class pointer which is only known at runtime.
+     // Valhalla: Could have value class which has a different prototype header to a normal object.
+     // In both cases, we need to fetch dynamically.
      movptr(t1, Address(klass, Klass::prototype_header_offset()));
      movptr(Address(obj, oopDesc::mark_offset_in_bytes()), t1);
-   } else if (UseCompressedClassPointers) { // Take care not to kill klass
-     movptr(Address(obj, oopDesc::mark_offset_in_bytes()), checked_cast<int32_t>(markWord::prototype().value()));
-     movptr(t1, klass);
-     encode_klass_not_null(t1, rscratch1);
-     movl(Address(obj, oopDesc::klass_offset_in_bytes()), t1);
    } else {
+     // Otherwise: Can use the statically computed prototype header which is the same for every object.
      movptr(Address(obj, oopDesc::mark_offset_in_bytes()), checked_cast<int32_t>(markWord::prototype().value()));
-     movptr(Address(obj, oopDesc::klass_offset_in_bytes()), klass);
+   }
+   if (!UseCompactObjectHeaders) {
+     // COH: Markword already contains class pointer. Nothing else to do.
+     // Otherwise: Fetch klass pointer following the markword
+     if (UseCompressedClassPointers) { // Take care not to kill klass
+       movptr(t1, klass);
+       encode_klass_not_null(t1, rscratch1);
+       movl(Address(obj, oopDesc::klass_offset_in_bytes()), t1);
+     } else {
+       movptr(Address(obj, oopDesc::klass_offset_in_bytes()), klass);
+     }
    }
  
    if (len->is_valid()) {
      movl(Address(obj, arrayOopDesc::length_offset_in_bytes()), len);
      int base_offset = arrayOopDesc::length_offset_in_bytes() + BytesPerInt;

@@ -220,42 +230,113 @@
    }
  
    verify_oop(obj);
  }
  
- void C1_MacroAssembler::build_frame(int frame_size_in_bytes, int bang_size_in_bytes) {
-   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
+ 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) {
+   push(rbp);
+   if (PreserveFramePointer) {
+     mov(rbp, rsp);
+   }
+   decrement(rsp, frame_size_in_bytes);
+ 
+   if (needs_stack_repair) {
+     // Save stack increment (also account for fixed framesize and rbp)
+     assert((sp_inc & (StackAlignmentInBytes-1)) == 0, "stack increment not aligned");
+     int real_frame_size = sp_inc + frame_size_in_bytes + wordSize;
+     movptr(Address(rsp, frame_size_in_bytes - wordSize), real_frame_size);
+   }
+   if (reset_orig_pc) {
+     // Zero orig_pc to detect deoptimization during buffering in the entry points
+     movptr(Address(rsp, sp_offset_for_orig_pc), 0);
+   }
+ }
+ 
+ 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) {
    // Make sure there is enough stack space for this method's activation.
    // Note that we do this before doing an enter(). This matches the
    // ordering of C2's stack overflow check / rsp decrement and allows
    // the SharedRuntime stack overflow handling to be consistent
    // between the two compilers.
+   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
    generate_stack_overflow_check(bang_size_in_bytes);
  
-   push(rbp);
-   if (PreserveFramePointer) {
-     mov(rbp, rsp);
-   }
-   decrement(rsp, frame_size_in_bytes); // does not emit code for frame_size == 0
+   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, has_scalarized_args, needs_stack_repair);
  
    BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
    // C1 code is not hot enough to micro optimize the nmethod entry barrier with an out-of-line stub
    bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */);
- }
- 
  
- void C1_MacroAssembler::remove_frame(int frame_size_in_bytes) {
-   increment(rsp, frame_size_in_bytes);  // Does not emit code for frame_size == 0
-   pop(rbp);
+   if (verified_inline_entry_label != nullptr) {
+     // Jump here from the scalarized entry points that already created the frame.
+     bind(*verified_inline_entry_label);
+   }
  }
  
- 
  void C1_MacroAssembler::verified_entry(bool breakAtEntry) {
    if (breakAtEntry) int3();
    // build frame
  }
  
+ 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) {
+   assert(InlineTypePassFieldsAsArgs, "sanity");
+   // Make sure there is enough stack space for this method's activation.
+   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
+   generate_stack_overflow_check(bang_size_in_bytes);
+ 
+   GrowableArray<SigEntry>* sig    = ces->sig();
+   GrowableArray<SigEntry>* sig_cc = is_inline_ro_entry ? ces->sig_cc_ro() : ces->sig_cc();
+   VMRegPair* regs      = ces->regs();
+   VMRegPair* regs_cc   = is_inline_ro_entry ? ces->regs_cc_ro() : ces->regs_cc();
+   int args_on_stack    = ces->args_on_stack();
+   int args_on_stack_cc = is_inline_ro_entry ? ces->args_on_stack_cc_ro() : ces->args_on_stack_cc();
+ 
+   assert(sig->length() <= sig_cc->length(), "Zero-sized inline class not allowed!");
+   BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sig_cc->length());
+   int args_passed = sig->length();
+   int args_passed_cc = SigEntry::fill_sig_bt(sig_cc, sig_bt);
+ 
+   // Create a temp frame so we can call into the runtime. It must be properly set up to accommodate GC.
+   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, 0, true, ces->c1_needs_stack_repair());
+ 
+   // The runtime call might safepoint, make sure nmethod entry barrier is executed
+   BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
+   // C1 code is not hot enough to micro optimize the nmethod entry barrier with an out-of-line stub
+   bs->nmethod_entry_barrier(this, nullptr /* slow_path */, nullptr /* continuation */);
+ 
+   // FIXME -- call runtime only if we cannot in-line allocate all the incoming inline type args.
+   movptr(rbx, (intptr_t)(ces->method()));
+   if (is_inline_ro_entry) {
+     call(RuntimeAddress(Runtime1::entry_for(StubId::c1_buffer_inline_args_no_receiver_id)));
+   } else {
+     call(RuntimeAddress(Runtime1::entry_for(StubId::c1_buffer_inline_args_id)));
+   }
+   int rt_call_offset = offset();
+ 
+   // Remove the temp frame
+   addptr(rsp, frame_size_in_bytes);
+   pop(rbp);
+ 
+   // Check if we need to extend the stack for packing
+   int sp_inc = 0;
+   if (args_on_stack > args_on_stack_cc) {
+     sp_inc = extend_stack_for_inline_args(args_on_stack);
+   }
+ 
+   shuffle_inline_args(true, is_inline_ro_entry, sig_cc,
+                       args_passed_cc, args_on_stack_cc, regs_cc, // from
+                       args_passed, args_on_stack, regs,          // to
+                       sp_inc, rax);
+ 
+   // Create the real frame. Below jump will then skip over the stack banging and frame
+   // setup code in the verified_inline_entry (which has a different real_frame_size).
+   build_frame_helper(frame_size_in_bytes, sp_offset_for_orig_pc, sp_inc, false, ces->c1_needs_stack_repair());
+ 
+   jmp(verified_inline_entry_label);
+   return rt_call_offset;
+ }
+ 
  void C1_MacroAssembler::load_parameter(int offset_in_words, Register reg) {
    // rbp, + 0: link
    //     + 1: return address
    //     + 2: argument with offset 0
    //     + 3: argument with offset 1
< prev index next >