changeset 2977:f43620c8febc

7158807: Revise stack management with volatile call sites Summary: Add missing stack banging into method handle assebly code and throw a StackOverflowError. Reviewed-by: jrose, twisti
author andrew
date Fri, 12 Oct 2012 14:26:47 +0100
parents 8b8c198ec5c4
children 5da7e3791b0d
files src/cpu/sparc/vm/methodHandles_sparc.cpp src/cpu/x86/vm/methodHandles_x86.cpp
diffstat 2 files changed, 60 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/cpu/sparc/vm/methodHandles_sparc.cpp	Fri Jun 08 12:49:52 2012 -0400
+++ b/src/cpu/sparc/vm/methodHandles_sparc.cpp	Fri Oct 12 14:26:47 2012 +0100
@@ -694,6 +694,17 @@
   if (arg_slots.is_constant() && arg_slots.as_constant() == 0)
     return;
 
+  // We have to insert at least one word, so bang the stack.
+  if (UseStackBanging) {
+    // Save G3_method_handle since bang_stack_with_offset uses it as a temp register
+    __ mov(G3_method_handle, temp_reg);
+    int frame_size = (arg_slots.is_constant() ? -1 * arg_slots.as_constant() * wordSize : 0);
+    if (frame_size <= 0)
+      frame_size = 256 * Interpreter::stackElementSize;  // conservative
+    __ generate_stack_overflow_check(frame_size);
+    __ mov(temp_reg, G3_method_handle);
+  }
+
   assert_different_registers(argslot_reg, temp_reg, temp2_reg, temp3_reg,
                              (!arg_slots.is_register() ? Gargs : arg_slots.as_register()));
 
@@ -1587,6 +1598,14 @@
                         "copied argument(s) must fall within current frame");
       }
 
+      if (UseStackBanging) {
+        // Save G3_method_handle since bang_stack_with_offset uses it as a temp register
+        __ mov(G3_method_handle, O3_scratch);
+         // Bang the stack before pushing args.
+        int frame_size = 256 * Interpreter::stackElementSize;  // conservative
+        __ generate_stack_overflow_check(frame_size + sizeof(RicochetFrame));
+        __ mov(O3_scratch, G3_method_handle);
+      }
       // insert location is always the bottom of the argument list:
       __ neg(O1_stack_move);
       push_arg_slots(_masm, O0_argslot, O1_stack_move, O2_scratch, O3_scratch);
@@ -2003,6 +2022,18 @@
       // The return handler will further cut back the stack when it takes
       // down the RF.  Perhaps there is a way to streamline this further.
 
+      if (UseStackBanging) {
+        // Save G3_method_handle since bang_stack_with_offset uses it as a temp register
+        __ mov(G3_method_handle, O4_scratch);
+        // Bang the stack before recursive call.
+        // Even if slots == 0, we are inside a RicochetFrame.
+        int frame_size = collect_count.is_constant() ? collect_count.as_constant() * wordSize : -1;
+        if (frame_size < 0) {
+          frame_size = 256 * Interpreter::stackElementSize;  // conservative
+        }
+        __ generate_stack_overflow_check(frame_size + sizeof(RicochetFrame));
+        __ mov(O4_scratch, G3_method_handle);
+      }
       // State during recursive call:
       // ... keep1 | dest | dest=42 | keep3 | RF... | collect | bounce_pc |
       __ jump_to_method_handle_entry(G3_method_handle, O1_scratch);
--- a/src/cpu/x86/vm/methodHandles_x86.cpp	Fri Jun 08 12:49:52 2012 -0400
+++ b/src/cpu/x86/vm/methodHandles_x86.cpp	Fri Oct 12 14:26:47 2012 +0100
@@ -687,6 +687,14 @@
   if (VerifyMethodHandles)
     verify_stack_move(_masm, arg_slots, -1);
 
+  // We have to insert at least one word, so bang the stack.
+  if (UseStackBanging) {
+    int frame_size = (arg_slots.is_constant() ? -1 * arg_slots.as_constant() * wordSize : 0);
+    if (frame_size <= 0)
+      frame_size = 256 * Interpreter::stackElementSize;  // conservative
+    __ generate_stack_overflow_check(frame_size);
+  }
+
   // Make space on the stack for the inserted argument(s).
   // Then pull down everything shallower than rax_argslot.
   // The stacked return address gets pulled down with everything else.
@@ -1698,6 +1706,11 @@
                         "copied argument(s) must fall within current frame");
       }
 
+      if (UseStackBanging) {
+        // Bang the stack before pushing args.
+        int frame_size = 256 * Interpreter::stackElementSize;  // conservative
+        __ generate_stack_overflow_check(frame_size + sizeof(RicochetFrame));
+      }
       // insert location is always the bottom of the argument list:
       Address insert_location = __ argument_address(constant(0));
       int pre_arg_words = insert_location.disp() / wordSize;   // return PC is pushed
@@ -2135,6 +2148,15 @@
       // The return handler will further cut back the stack when it takes
       // down the RF.  Perhaps there is a way to streamline this further.
 
+      if (UseStackBanging) {
+        // Bang the stack before recursive call.
+        // Even if slots == 0, we are inside a RicochetFrame.
+        int frame_size = collect_count.is_constant() ? collect_count.as_constant() * wordSize : -1;
+        if (frame_size < 0) {
+          frame_size = 256 * Interpreter::stackElementSize;  // conservative
+        }
+        __ generate_stack_overflow_check(frame_size + sizeof(RicochetFrame));
+      }
       // State during recursive call:
       // ... keep1 | dest | dest=42 | keep3 | RF... | collect | bounce_pc |
       __ jump_to_method_handle_entry(rcx_recv, rdx_temp);
@@ -2265,10 +2287,15 @@
 
       // grab another temp
       Register rsi_temp = rsi;
-      { if (rsi_temp == saved_last_sp)  __ push(saved_last_sp); }
+      if (rsi_temp == saved_last_sp) {
+        __ push(saved_last_sp);
+        // Need to re-push return PC to keep it on stack top.
+        __ lea(saved_last_sp, ExternalAddress(SharedRuntime::ricochet_blob()->bounce_addr()).addr());
+        __ push(saved_last_sp);
+      }
       // (preceding push must be done after argslot address is taken!)
 #define UNPUSH_RSI \
-      { if (rsi_temp == saved_last_sp)  __ pop(saved_last_sp); }
+      { if (rsi_temp == saved_last_sp) { __ pop(saved_last_sp); __ pop(saved_last_sp); } }
 
       // arx_argslot points both to the array and to the first output arg
       vmarg = Address(rax_argslot, 0);