summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/thread.cc26
-rw-r--r--test/051-thread/expected.txt1
-rw-r--r--test/051-thread/src/Main.java2
3 files changed, 26 insertions, 3 deletions
diff --git a/src/thread.cc b/src/thread.cc
index 0dd3766fec..e997723e5e 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -214,13 +214,33 @@ Thread* Thread::FromManagedThread(JNIEnv* env, jobject java_thread) {
return reinterpret_cast<Thread*>(static_cast<uintptr_t>(gThread_vmData->GetInt(thread)));
}
-void Thread::Create(Object* peer, size_t stack_size) {
- CHECK(peer != NULL);
-
+size_t FixStackSize(size_t stack_size) {
+ // A stack size of zero means "use the default".
if (stack_size == 0) {
stack_size = Runtime::Current()->GetDefaultStackSize();
}
+ // It's not possible to request a stack smaller than the system-defined PTHREAD_STACK_MIN.
+ if (stack_size < PTHREAD_STACK_MIN) {
+ stack_size = PTHREAD_STACK_MIN;
+ }
+
+ // It's likely that callers are trying to ensure they have at least a certain amount of
+ // stack space, so we should add our reserved space on top of what they requested, rather
+ // than implicitly take it away from them.
+ stack_size += Thread::kStackOverflowReservedBytes;
+
+ // Some systems require the stack size to be a multiple of the system page size, so round up.
+ stack_size = RoundUp(stack_size, kPageSize);
+
+ return stack_size;
+}
+
+void Thread::Create(Object* peer, size_t stack_size) {
+ CHECK(peer != NULL);
+
+ stack_size = FixStackSize(stack_size);
+
Thread* native_thread = new Thread;
native_thread->peer_ = peer;
diff --git a/test/051-thread/expected.txt b/test/051-thread/expected.txt
index fbe32f61e6..53700490a2 100644
--- a/test/051-thread/expected.txt
+++ b/test/051-thread/expected.txt
@@ -1,3 +1,4 @@
+Initializing System.out...
running 0
running 1
running 2
diff --git a/test/051-thread/src/Main.java b/test/051-thread/src/Main.java
index 9acc89e6ca..7cc3db4898 100644
--- a/test/051-thread/src/Main.java
+++ b/test/051-thread/src/Main.java
@@ -5,6 +5,8 @@
*/
public class Main {
public static void main(String[] args) {
+ System.out.println("Initializing System.out...");
+
for (int i = 0; i < 512; i++) {
MyThread myThread = new MyThread();
myThread.start();