diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/thread.cc | 11 | ||||
| -rw-r--r-- | src/thread.h | 9 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/thread.cc b/src/thread.cc index c771c5b173..e1de92d0d0 100644 --- a/src/thread.cc +++ b/src/thread.cc @@ -373,7 +373,6 @@ void Thread::InitStackHwm() { PLOG(FATAL) << "pthread_getattr_np failed"; } - // stack_base is the "lowest addressable byte" of the stack. void* stack_base; size_t stack_size; errno = pthread_attr_getstack(&attributes, &stack_base, &stack_size); @@ -385,7 +384,15 @@ void Thread::InitStackHwm() { if (stack_size <= kStackOverflowReservedBytes) { LOG(FATAL) << "attempt to attach a thread with a too-small stack (" << stack_size << " bytes)"; } - stack_hwm_ = reinterpret_cast<byte*>(stack_base) + stack_size - kStackOverflowReservedBytes; + + // stack_base is the "lowest addressable byte" of the stack. + // Our stacks grow down, so we want stack_end_ to be near there, but reserving enough room + // to throw a StackOverflowError. + stack_end_ = reinterpret_cast<byte*>(stack_base) - kStackOverflowReservedBytes; + + // Sanity check. + int stack_variable; + CHECK_GT(&stack_variable, (void*) stack_end_); errno = pthread_attr_destroy(&attributes); if (errno != 0) { diff --git a/src/thread.h b/src/thread.h index b9df711325..6095407b48 100644 --- a/src/thread.h +++ b/src/thread.h @@ -410,8 +410,8 @@ class Thread { return ThreadOffset(OFFSETOF_MEMBER(Thread, state_)); } - static ThreadOffset StackHwmOffset() { - return ThreadOffset(OFFSETOF_MEMBER(Thread, stack_hwm_)); + static ThreadOffset StackEndOffset() { + return ThreadOffset(OFFSETOF_MEMBER(Thread, stack_end_)); } static ThreadOffset JniEnvOffset() { @@ -475,8 +475,9 @@ class Thread { // FIXME: placeholder for the gc cardTable uint32_t card_table_; - // The high water mark for this thread's stack. - byte* stack_hwm_; + // The end of this thread's stack. This is the lowest safely-addressable address on the stack. + // We leave extra space so there's room for the code that throws StackOverflowError. + byte* stack_end_; // Top of the managed stack, written out prior to the state transition from // kRunnable to kNative. Uses include to give the starting point for scanning |