diff --git a/src/cpu/zero/vm/stack_zero.cpp b/src/cpu/zero/vm/stack_zero.cpp index 328e52e6b002ac448101fca9163a3092fcd9c77f..532f54e77986bfccaa8b792fa65058e8290e1c2d 100644 --- a/src/cpu/zero/vm/stack_zero.cpp +++ b/src/cpu/zero/vm/stack_zero.cpp @@ -26,6 +26,11 @@ #include "incls/_precompiled.incl" #include "incls/_stack_zero.cpp.incl" +int ZeroStack::suggest_size(Thread *thread) const { + assert(needs_setup(), "already set up"); + return align_size_down(abi_stack_available(thread) / 2, wordSize); +} + void ZeroStack::handle_overflow(TRAPS) { JavaThread *thread = (JavaThread *) THREAD; diff --git a/src/cpu/zero/vm/stack_zero.hpp b/src/cpu/zero/vm/stack_zero.hpp index ab3beca476084859e5a02a0d9e2ab6bc0557ecb3..691cbc790e5190586507b319fda7d5a3fce8f922 100644 --- a/src/cpu/zero/vm/stack_zero.hpp +++ b/src/cpu/zero/vm/stack_zero.hpp @@ -42,6 +42,8 @@ class ZeroStack { return _base == NULL; } + int suggest_size(Thread *thread) const; + void setup(void *mem, size_t size) { assert(needs_setup(), "already set up"); assert(!(size & WordAlignmentMask), "unaligned"); @@ -67,6 +69,9 @@ class ZeroStack { _sp = new_sp; } + int total_words() const { + return _top - _base; + } int available_words() const { return _sp - _base; } @@ -89,6 +94,7 @@ class ZeroStack { int shadow_pages_size() const { return _shadow_pages_size; } + int abi_stack_available(Thread *thread) const; public: void overflow_check(int required_words, TRAPS); diff --git a/src/cpu/zero/vm/stack_zero.inline.hpp b/src/cpu/zero/vm/stack_zero.inline.hpp index ffb247c603936b2a327163af64134caf62a812c2..89513dbb75ecb0d2e4d2c7e1cafb68e621212a00 100644 --- a/src/cpu/zero/vm/stack_zero.inline.hpp +++ b/src/cpu/zero/vm/stack_zero.inline.hpp @@ -25,19 +25,24 @@ // This function should match SharkStack::CreateStackOverflowCheck inline void ZeroStack::overflow_check(int required_words, TRAPS) { - JavaThread *thread = (JavaThread *) THREAD; - // Check the Zero stack - if (required_words > available_words()) { + if (available_words() < required_words) { handle_overflow(THREAD); return; } // Check the ABI stack - address stack_top = thread->stack_base() - thread->stack_size(); - int free_stack = ((address) &stack_top) - stack_top; - if (free_stack < shadow_pages_size()) { + if (abi_stack_available(THREAD) < 0) { handle_overflow(THREAD); return; } } + +// This method returns the amount of ABI stack available for us +// to use under normal circumstances. Note that the returned +// value can be negative. +inline int ZeroStack::abi_stack_available(Thread *thread) const { + int stack_used = thread->stack_base() - (address) &stack_used; + int stack_free = thread->stack_size() - stack_used; + return stack_free - shadow_pages_size(); +} diff --git a/src/cpu/zero/vm/stubGenerator_zero.cpp b/src/cpu/zero/vm/stubGenerator_zero.cpp index 4ffa5d18919881ebcf3bed7fb09ef335f191934d..a1b093ad57bd7d83894118641fd6fee174601254 100644 --- a/src/cpu/zero/vm/stubGenerator_zero.cpp +++ b/src/cpu/zero/vm/stubGenerator_zero.cpp @@ -51,10 +51,7 @@ class StubGenerator: public StubCodeGenerator { // Set up the stack if necessary bool stack_needs_teardown = false; if (stack->needs_setup()) { - size_t stack_used = thread->stack_base() - (address) &stack_used; - size_t stack_free = thread->stack_size() - stack_used; - size_t zero_stack_size = align_size_down(stack_free / 2, wordSize); - + size_t zero_stack_size = stack->suggest_size(thread); stack->setup(alloca(zero_stack_size), zero_stack_size); stack_needs_teardown = true; } diff --git a/src/share/vm/includeDB_zero b/src/share/vm/includeDB_zero index b5c7a60440f63758e51eb5e34b94d1079afe12fa..20a7fed1ec3b6ca2200750908593a9be690fabe3 100644 --- a/src/share/vm/includeDB_zero +++ b/src/share/vm/includeDB_zero @@ -61,6 +61,7 @@ stack_.inline.hpp thread.hpp stack_.cpp interpreterRuntime.hpp stack_.cpp stack_.hpp +stack_.cpp stack_.inline.hpp stubGenerator_.cpp stack_.inline.hpp