changeset 1183:bbb37067ce04

2008-11-06 Gary Benson <gbenson@redhat.com> * ports/hotspot/src/cpu/zero/vm/cppInterpreter_zero.hpp (CppInterpreter::stack_overflow_imminent): New method. * ports/hotspot/src/cpu/zero/vm/cppInterpreter_zero.cpp (CppInterpreter::stack_overflow_imminent): New method. (CppInterpreter::normal_entry): Add stack overflow check.
author Gary Benson <gbenson@redhat.com>
date Thu, 06 Nov 2008 06:22:51 -0500
parents 6c81f8c8aab3
children a261142d4db9
files ChangeLog ports/hotspot/src/cpu/zero/vm/cppInterpreter_zero.cpp ports/hotspot/src/cpu/zero/vm/cppInterpreter_zero.hpp
diffstat 3 files changed, 48 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Nov 05 22:51:47 2008 -0500
+++ b/ChangeLog	Thu Nov 06 06:22:51 2008 -0500
@@ -1,3 +1,12 @@
+2008-11-06  Gary Benson  <gbenson@redhat.com>
+
+	* ports/hotspot/src/cpu/zero/vm/cppInterpreter_zero.hpp
+	(CppInterpreter::stack_overflow_imminent): New method.
+
+	* ports/hotspot/src/cpu/zero/vm/cppInterpreter_zero.cpp
+	(CppInterpreter::stack_overflow_imminent): New method.
+	(CppInterpreter::normal_entry): Add stack overflow check.
+
 2008-11-05  Deepak Bhole  <dbhole@redhat.com>
 
 	* patches/icedtea-copy-plugs.patch: Add netscape.* classes to rt.jar when
@@ -8,7 +17,8 @@
 	* rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: Correct
 	indentation from last commit, remove debug output.
 
-2008-11-05  Gary Benson  <gbenson@redhat.com>
+2008-11-05  Andrew Haley  <aph@redhat.com>
+	    Gary Benson  <gbenson@redhat.com>
 
 	* contrib/mixtec-hacks.patch: new file.
 
--- a/ports/hotspot/src/cpu/zero/vm/cppInterpreter_zero.cpp	Wed Nov 05 22:51:47 2008 -0500
+++ b/ports/hotspot/src/cpu/zero/vm/cppInterpreter_zero.cpp	Thu Nov 06 06:22:51 2008 -0500
@@ -77,6 +77,13 @@
 
   intptr_t *result = NULL;
   int result_slots = 0;
+
+  // Check we're not about to run out of stack
+  if (stack_overflow_imminent(thread)) {
+    CALL_VM_NOCHECK(InterpreterRuntime::throw_StackOverflowError(thread));
+    goto unwind_and_return;
+  }
+
   while (true) {
     // We can set up the frame anchor with everything we want at
     // this point as we are thread_in_Java and no safepoints can
@@ -151,6 +158,8 @@
     }
   }
 
+ unwind_and_return:
+
   // Unwind the current frame
   thread->pop_zero_frame();
 
@@ -536,6 +545,30 @@
   stack->set_sp(stack->sp() + method->size_of_parameters());
 }
 
+bool CppInterpreter::stack_overflow_imminent(JavaThread *thread)
+{
+  // How is the ABI stack?
+  address stack_top = thread->stack_base() - thread->stack_size();
+  int free_stack = os::current_stack_pointer() - stack_top;
+  if (free_stack < StackShadowPages * os::vm_page_size()) {
+    return true;
+  }
+
+  // How is the Zero stack?
+  // Throwing a StackOverflowError involves a VM call, which means
+  // we need a frame on the stack.  We should be checking here to
+  // ensure that methods we call have enough room to install the
+  // largest possible frame, but that's more than twice the size
+  // of the entire Zero stack we get by default, so we just check
+  // we have *some* space instead...
+  free_stack = thread->zero_stack()->available_words() * wordSize;
+  if (free_stack < StackShadowPages * os::vm_page_size()) {
+    return true;
+  }
+  
+  return false;
+}
+
 InterpreterFrame *InterpreterFrame::build(ZeroStack*       stack,
                                           const methodOop  method,
                                           JavaThread*      thread)
--- a/ports/hotspot/src/cpu/zero/vm/cppInterpreter_zero.hpp	Wed Nov 05 22:51:47 2008 -0500
+++ b/ports/hotspot/src/cpu/zero/vm/cppInterpreter_zero.hpp	Thu Nov 06 06:22:51 2008 -0500
@@ -38,3 +38,7 @@
  public:
   // Main loop of normal_entry
   static void main_loop(int recurse, TRAPS);
+
+ private:
+  // Stack overflow checks
+  static bool stack_overflow_imminent(JavaThread *thread);