提交 f969d02c 编写于 作者: T twisti

6950178: Zero stack improvements

Summary: Moves the logic for determining the size of the Zero stack into the ZeroStack class.
Reviewed-by: twisti
Contributed-by: NGary Benson <gbenson@redhat.com>
上级 a71d5b43
...@@ -26,6 +26,11 @@ ...@@ -26,6 +26,11 @@
#include "incls/_precompiled.incl" #include "incls/_precompiled.incl"
#include "incls/_stack_zero.cpp.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) { void ZeroStack::handle_overflow(TRAPS) {
JavaThread *thread = (JavaThread *) THREAD; JavaThread *thread = (JavaThread *) THREAD;
......
...@@ -42,6 +42,8 @@ class ZeroStack { ...@@ -42,6 +42,8 @@ class ZeroStack {
return _base == NULL; return _base == NULL;
} }
int suggest_size(Thread *thread) const;
void setup(void *mem, size_t size) { void setup(void *mem, size_t size) {
assert(needs_setup(), "already set up"); assert(needs_setup(), "already set up");
assert(!(size & WordAlignmentMask), "unaligned"); assert(!(size & WordAlignmentMask), "unaligned");
...@@ -67,6 +69,9 @@ class ZeroStack { ...@@ -67,6 +69,9 @@ class ZeroStack {
_sp = new_sp; _sp = new_sp;
} }
int total_words() const {
return _top - _base;
}
int available_words() const { int available_words() const {
return _sp - _base; return _sp - _base;
} }
...@@ -89,6 +94,7 @@ class ZeroStack { ...@@ -89,6 +94,7 @@ class ZeroStack {
int shadow_pages_size() const { int shadow_pages_size() const {
return _shadow_pages_size; return _shadow_pages_size;
} }
int abi_stack_available(Thread *thread) const;
public: public:
void overflow_check(int required_words, TRAPS); void overflow_check(int required_words, TRAPS);
......
...@@ -25,19 +25,24 @@ ...@@ -25,19 +25,24 @@
// This function should match SharkStack::CreateStackOverflowCheck // This function should match SharkStack::CreateStackOverflowCheck
inline void ZeroStack::overflow_check(int required_words, TRAPS) { inline void ZeroStack::overflow_check(int required_words, TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
// Check the Zero stack // Check the Zero stack
if (required_words > available_words()) { if (available_words() < required_words) {
handle_overflow(THREAD); handle_overflow(THREAD);
return; return;
} }
// Check the ABI stack // Check the ABI stack
address stack_top = thread->stack_base() - thread->stack_size(); if (abi_stack_available(THREAD) < 0) {
int free_stack = ((address) &stack_top) - stack_top;
if (free_stack < shadow_pages_size()) {
handle_overflow(THREAD); handle_overflow(THREAD);
return; 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();
}
...@@ -51,10 +51,7 @@ class StubGenerator: public StubCodeGenerator { ...@@ -51,10 +51,7 @@ class StubGenerator: public StubCodeGenerator {
// Set up the stack if necessary // Set up the stack if necessary
bool stack_needs_teardown = false; bool stack_needs_teardown = false;
if (stack->needs_setup()) { if (stack->needs_setup()) {
size_t stack_used = thread->stack_base() - (address) &stack_used; size_t zero_stack_size = stack->suggest_size(thread);
size_t stack_free = thread->stack_size() - stack_used;
size_t zero_stack_size = align_size_down(stack_free / 2, wordSize);
stack->setup(alloca(zero_stack_size), zero_stack_size); stack->setup(alloca(zero_stack_size), zero_stack_size);
stack_needs_teardown = true; stack_needs_teardown = true;
} }
......
...@@ -61,6 +61,7 @@ stack_<arch>.inline.hpp thread.hpp ...@@ -61,6 +61,7 @@ stack_<arch>.inline.hpp thread.hpp
stack_<arch>.cpp interpreterRuntime.hpp stack_<arch>.cpp interpreterRuntime.hpp
stack_<arch>.cpp stack_<arch>.hpp stack_<arch>.cpp stack_<arch>.hpp
stack_<arch>.cpp stack_<arch>.inline.hpp
stubGenerator_<arch>.cpp stack_<arch>.inline.hpp stubGenerator_<arch>.cpp stack_<arch>.inline.hpp
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册