changeset 17033:2d6dd2eebd51

Fixed HSAIL deopt
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 02 Sep 2014 21:42:37 -0700
parents 8f3ece00da4f
children 86749331247a
files src/cpu/sparc/vm/sharedRuntime_sparc.cpp src/cpu/x86/vm/sharedRuntime_x86_32.cpp src/cpu/x86/vm/sharedRuntime_x86_64.cpp src/gpu/hsail/vm/gpu_hsail.cpp src/share/vm/graal/graalRuntime.cpp src/share/vm/graal/graalRuntime.hpp src/share/vm/runtime/sharedRuntime.hpp
diffstat 7 files changed, 84 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/cpu/sparc/vm/sharedRuntime_sparc.cpp	Tue Sep 02 21:42:29 2014 -0700
+++ b/src/cpu/sparc/vm/sharedRuntime_sparc.cpp	Tue Sep 02 21:42:37 2014 -0700
@@ -516,10 +516,11 @@
                               const VMRegPair *regs,
                               Label& skip_fixup);
   void gen_i2c_adapter(int total_args_passed,
-                              // VMReg max_arg,
-                              int comp_args_on_stack, // VMRegStackSlots
-                              const BasicType *sig_bt,
-                              const VMRegPair *regs);
+                       // VMReg max_arg,
+                       int comp_args_on_stack, // VMRegStackSlots
+                       const BasicType *sig_bt,
+                       const VMRegPair *regs,
+                       int frame_extension_argument = -1);
 
   AdapterGenerator(MacroAssembler *_masm) : masm(_masm) {}
 };
@@ -763,12 +764,13 @@
   __ bind(L_fail);
 }
 
-void AdapterGenerator::gen_i2c_adapter(
-                            int total_args_passed,
-                            // VMReg max_arg,
-                            int comp_args_on_stack, // VMRegStackSlots
-                            const BasicType *sig_bt,
-                            const VMRegPair *regs) {
+void AdapterGenerator::gen_i2c_adapter(int total_args_passed,
+                                       // VMReg max_arg,
+                                       int comp_args_on_stack, // VMRegStackSlots
+                                       const BasicType *sig_bt,
+                                       const VMRegPair *regs,
+                                       int frame_extension_argument) {
+  assert(frame_extension_argument == -1, "unsupported");
 
   // Generate an I2C adapter: adjust the I-frame to make space for the C-frame
   // layout.  Lesp was saved by the calling I-frame and will be restored on
@@ -1026,9 +1028,10 @@
                                     int total_args_passed,
                                     int comp_args_on_stack,
                                     const BasicType *sig_bt,
-                                    const VMRegPair *regs) {
+                                    const VMRegPair *regs,
+                                    int frame_extension_arguments) {
   AdapterGenerator agen(masm);
-  agen.gen_i2c_adapter(total_args_passed, comp_args_on_stack, sig_bt, regs);
+  agen.gen_i2c_adapter(total_args_passed, comp_args_on_stack, sig_bt, regs, frame_extension_argument);
 }
 
 // ---------------------------------------------------------------
--- a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp	Tue Sep 02 21:42:29 2014 -0700
+++ b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp	Tue Sep 02 21:42:37 2014 -0700
@@ -712,10 +712,12 @@
 }
 
 void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
-                            int total_args_passed,
-                            int comp_args_on_stack,
-                            const BasicType *sig_bt,
-                            const VMRegPair *regs) {
+                                    int total_args_passed,
+                                    int comp_args_on_stack,
+                                    const BasicType *sig_bt,
+                                    const VMRegPair *regs
+                                    int frame_extension_argument) {
+  assert(frame_extension_arguments == -1, "unsupported");
 
   // Note: rsi contains the senderSP on entry. We must preserve it since
   // we may do a i2c -> c2i transition if we lose a race where compiled
--- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Tue Sep 02 21:42:29 2014 -0700
+++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Tue Sep 02 21:42:37 2014 -0700
@@ -643,10 +643,11 @@
 }
 
 void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
-                            int total_args_passed,
-                            int comp_args_on_stack,
-                            const BasicType *sig_bt,
-                            const VMRegPair *regs) {
+                                    int total_args_passed,
+                                    int comp_args_on_stack,
+                                    const BasicType *sig_bt,
+                                    const VMRegPair *regs,
+                                    int frame_extension_argument) {
 
   // Note: r13 contains the senderSP on entry. We must preserve it since
   // we may do a i2c -> c2i transition if we lose a race where compiled
@@ -704,6 +705,42 @@
     __ block_comment("} verify_i2ce ");
   }
 
+#ifdef GRAAL
+  if (frame_extension_argument != -1) {
+    // The frame_extension_argument is an int that describes the
+    // expected amount of argument space in the caller frame.  If that
+    // is greater than total_args_passed then enlarge the caller frame
+    // by that amount to ensure deopt works correctly.
+    assert(frame_extension_argument < total_args_passed, "out of range");
+    assert(sig_bt[frame_extension_argument] == T_INT, "wrong signature");
+
+    Label done;
+    int i = frame_extension_argument;
+    int ld_off = (total_args_passed - i)*Interpreter::stackElementSize;
+    // Check if anything needs to be done.  Too much space is ok.
+    __ movl(r13, Address(rsp, ld_off));
+    __ cmpl(r13, total_args_passed);
+    __ jcc(Assembler::lessEqual, done);
+    // Save the old rsp for the copy code
+    __ movptr(r11, rsp);
+    // Enlarge the frame
+    __ subl(r13, total_args_passed);
+    __ shlq(r13, 3);
+    __ subptr(rsp, r13);
+
+    // Now copy the arguments in reverse order so they don't get
+    // overwritten during the copy.
+    for (int i = total_args_passed - 1; i >= 0; i--) {
+      int ld_off = (total_args_passed - i) * Interpreter::stackElementSize;
+      __ movptr(r13, Address(r11, ld_off));
+      __ movptr(Address(rsp, ld_off), r13);
+    }
+    __ bind(done);
+  }
+#else
+  assert(frame_extension_argument == -1, "unsupported");
+#endif
+
   // Must preserve original SP for loading incoming arguments because
   // we need to align the outgoing SP for compiled code.
   __ movptr(r11, rsp);
--- a/src/gpu/hsail/vm/gpu_hsail.cpp	Tue Sep 02 21:42:29 2014 -0700
+++ b/src/gpu/hsail/vm/gpu_hsail.cpp	Tue Sep 02 21:42:37 2014 -0700
@@ -249,6 +249,7 @@
             int myActionReason = Deoptimization::make_trap_request(Deoptimization::trap_request_reason(pdeopt->reason()), Deoptimization::Action_none);
             javaArgs.push_int(myActionReason);
             javaArgs.push_oop((oop) NULL);
+            javaArgs.push_int(mh->size_of_parameters());
             if (TraceGPUInteraction) {
               tty->print_cr("[HSAIL] Deoptimizing to host for workitem=%d (slot=%d) with deoptId=%d, frame=" INTPTR_FORMAT ", actionAndReason=%d", workitem, k, deoptId, hsailFrame, myActionReason);
               // show the $d registers or stack slots containing references
--- a/src/share/vm/graal/graalRuntime.cpp	Tue Sep 02 21:42:29 2014 -0700
+++ b/src/share/vm/graal/graalRuntime.cpp	Tue Sep 02 21:42:37 2014 -0700
@@ -24,6 +24,7 @@
 #include "precompiled.hpp"
 #include "asm/codeBuffer.hpp"
 #include "compiler/compileBroker.hpp"
+#include "compiler/disassembler.hpp"
 #include "graal/graalRuntime.hpp"
 #include "graal/graalCompilerToVM.hpp"
 #include "graal/graalCompiler.hpp"
@@ -56,7 +57,12 @@
 
     graal_compute_offsets();
 
+#ifdef TARGET_ARCH_x86
+#ifdef _LP64
+    // Only supported on x86_64 for now
     _external_deopt_i2c_entry = create_external_deopt_i2c();
+#endif
+#endif
 
     // Ensure _non_oop_bits is initialized
     Universe::non_oop_word();
@@ -88,7 +94,7 @@
   cb.insts()->initialize_shared_locs((relocInfo*)buffer_locs, sizeof(buffer_locs)/sizeof(relocInfo));
   MacroAssembler masm(&cb);
 
-  int total_args_passed = 5;
+  int total_args_passed = 6;
 
   BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed);
   VMRegPair* regs   = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed);
@@ -98,13 +104,19 @@
   sig_bt[i++] = T_VOID; // long stakes 2 slots
   sig_bt[i++] = T_INT;
   sig_bt[i++] = T_OBJECT;
+  sig_bt[i++] = T_INT; // The number of actual arguments pass to the method.
 
   int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, false);
 
-  SharedRuntime::gen_i2c_adapter(&masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
+  SharedRuntime::gen_i2c_adapter(&masm, total_args_passed, comp_args_on_stack, sig_bt, regs, total_args_passed - 1);
   masm.flush();
 
-  return AdapterBlob::create(&cb)->content_begin();
+  AdapterBlob* adapter = AdapterBlob::create(&cb);
+  if (PrintAdapterHandlers) {
+    tty->print_cr("Decoding external_deopt_i2c");
+    Disassembler::decode(adapter->code_begin(), adapter->code_end());
+  }
+  return adapter->code_begin();
 }
 
 BasicType GraalRuntime::kindToBasicType(jchar ch) {
--- a/src/share/vm/graal/graalRuntime.hpp	Tue Sep 02 21:42:29 2014 -0700
+++ b/src/share/vm/graal/graalRuntime.hpp	Tue Sep 02 21:42:37 2014 -0700
@@ -217,7 +217,10 @@
 
   static BasicType kindToBasicType(jchar ch);
   static address create_external_deopt_i2c();
-  static address get_external_deopt_i2c_entry() {return _external_deopt_i2c_entry;}
+  static address get_external_deopt_i2c_entry() {
+    guarantee(_external_deopt_i2c_entry != NULL, "unsupported");
+    return _external_deopt_i2c_entry;
+  }
 
   // The following routines are all called from compiled Graal code
 
--- a/src/share/vm/runtime/sharedRuntime.hpp	Tue Sep 02 21:42:29 2014 -0700
+++ b/src/share/vm/runtime/sharedRuntime.hpp	Tue Sep 02 21:42:37 2014 -0700
@@ -405,7 +405,8 @@
                               int total_args_passed,
                               int comp_args_on_stack,
                               const BasicType *sig_bt,
-                              const VMRegPair *regs);
+                              const VMRegPair *regs,
+                              int frame_extension_argument = -1);
 
   // OSR support