ART: Flag to fail thread creation
Add a flag to mark when the zygote is not allowed to create threads.
Bug: 27248115
Bug: 28149511
Change-Id: I1dc3620d9e7d0054c672b993d89459fc4b353dfc
diff --git a/runtime/native/java_lang_Thread.cc b/runtime/native/java_lang_Thread.cc
index 13edd67..a742e81 100644
--- a/runtime/native/java_lang_Thread.cc
+++ b/runtime/native/java_lang_Thread.cc
@@ -47,6 +47,15 @@
static void Thread_nativeCreate(JNIEnv* env, jclass, jobject java_thread, jlong stack_size,
jboolean daemon) {
+ // There are sections in the zygote that forbid thread creation.
+ Runtime* runtime = Runtime::Current();
+ if (runtime->IsZygote() && runtime->IsZygoteNoThreadSection()) {
+ jclass internal_error = env->FindClass("java/lang/InternalError");
+ CHECK(internal_error != nullptr);
+ env->ThrowNew(internal_error, "Cannot create threads in zygote");
+ return;
+ }
+
Thread::CreateNativeThread(env, java_thread, stack_size, daemon == JNI_TRUE);
}