summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2019-02-21 10:15:28 +0000
committerNicolas Geoffray <ngeoffray@google.com>2019-02-21 10:15:28 +0000
commitc08c10713e8884e8adfbf6a8e370a9ec96c1883f (patch)
tree84dc682b40f38d0377639befe6f3d43e5655a43c
parent3611fdf703a6417c08a2e3d6e642d5936318de18 (diff)
downloadart-c08c10713e8884e8adfbf6a8e370a9ec96c1883f.tar.gz
art-c08c10713e8884e8adfbf6a8e370a9ec96c1883f.tar.bz2
art-c08c10713e8884e8adfbf6a8e370a9ec96c1883f.zip
Revert "Prevent agents from delaying system daemon threads"
This reverts commit 3611fdf703a6417c08a2e3d6e642d5936318de18. Bug: 123696564 Bug: 124284724 Reason for revert: b/124284724 Change-Id: I546758b4cbb5e3f62f7b66a2faed544abce0d9c2
-rw-r--r--openjdkjvmti/ti_thread.cc33
-rw-r--r--runtime/runtime.cc15
-rw-r--r--runtime/thread.cc8
-rw-r--r--runtime/thread.h2
-rw-r--r--runtime/well_known_classes.cc4
-rw-r--r--runtime/well_known_classes.h2
6 files changed, 5 insertions, 59 deletions
diff --git a/openjdkjvmti/ti_thread.cc b/openjdkjvmti/ti_thread.cc
index 1021648a2c..051db4c67e 100644
--- a/openjdkjvmti/ti_thread.cc
+++ b/openjdkjvmti/ti_thread.cc
@@ -47,7 +47,6 @@
#include "mirror/class.h"
#include "mirror/object-inl.h"
#include "mirror/string.h"
-#include "mirror/throwable.h"
#include "nativehelper/scoped_local_ref.h"
#include "nativehelper/scoped_utf_chars.h"
#include "obj_ptr.h"
@@ -84,17 +83,6 @@ struct ThreadCallback : public art::ThreadLifecycleCallback {
}
void ThreadStart(art::Thread* self) override REQUIRES_SHARED(art::Locks::mutator_lock_) {
- // Needs to be checked first because we might start these threads before we actually send the
- // VMInit event.
- if (self->IsSystemDaemon()) {
- // System daemon threads are things like the finalizer or gc thread. It would be dangerous to
- // allow agents to get in the way of these threads starting up. These threads include things
- // like the HeapTaskDaemon and the finalizer daemon.
- //
- // This event can happen during the time before VMInit or just after zygote fork. Since the
- // second is hard to distinguish we unfortunately cannot really check the state here.
- return;
- }
if (!started) {
// Runtime isn't started. We only expect at most the signal handler or JIT threads to be
// started here.
@@ -144,35 +132,16 @@ void ThreadUtil::VMInitEventSent() {
gThreadCallback.Post<ArtJvmtiEvent::kThreadStart>(art::Thread::Current());
}
-
-static void WaitForSystemDaemonStart(art::Thread* self) REQUIRES_SHARED(art::Locks::mutator_lock_) {
- {
- art::ScopedThreadStateChange strc(self, art::kNative);
- JNIEnv* jni = self->GetJniEnv();
- jni->CallStaticVoidMethod(art::WellKnownClasses::java_lang_Daemons,
- art::WellKnownClasses::java_lang_Daemons_waitForDaemonStart);
- }
- if (self->IsExceptionPending()) {
- LOG(WARNING) << "Exception occured when waiting for system daemons to start: "
- << self->GetException()->Dump();
- self->ClearException();
- }
-}
-
void ThreadUtil::CacheData() {
// We must have started since it is now safe to cache our data;
gThreadCallback.started = true;
- art::Thread* self = art::Thread::Current();
- art::ScopedObjectAccess soa(self);
+ art::ScopedObjectAccess soa(art::Thread::Current());
art::ObjPtr<art::mirror::Class> thread_class =
soa.Decode<art::mirror::Class>(art::WellKnownClasses::java_lang_Thread);
CHECK(thread_class != nullptr);
context_class_loader_ = thread_class->FindDeclaredInstanceField("contextClassLoader",
"Ljava/lang/ClassLoader;");
CHECK(context_class_loader_ != nullptr);
- // Now wait for all required system threads to come up before allowing the rest of loading to
- // continue.
- WaitForSystemDaemonStart(self);
}
void ThreadUtil::Unregister() {
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 7ecfdc70cd..1465b14d44 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -869,22 +869,15 @@ bool Runtime::Start() {
GetInstructionSetString(kRuntimeISA));
}
- StartDaemonThreads();
-
- // Make sure the environment is still clean (no lingering local refs from starting daemon
- // threads).
- {
- ScopedObjectAccess soa(self);
- self->GetJniEnv()->AssertLocalsEmpty();
- }
-
- // Send the initialized phase event. Send it after starting the Daemon threads so that agents
- // cannot delay the daemon threads from starting forever.
+ // Send the initialized phase event. Send it before starting daemons, as otherwise
+ // sending thread events becomes complicated.
{
ScopedObjectAccess soa(self);
callbacks_->NextRuntimePhase(RuntimePhaseCallback::RuntimePhase::kInit);
}
+ StartDaemonThreads();
+
{
ScopedObjectAccess soa(self);
self->GetJniEnv()->AssertLocalsEmpty();
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 44b45cfa75..4828aaef2c 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -4258,12 +4258,4 @@ int Thread::GetNativePriority() {
return priority;
}
-bool Thread::IsSystemDaemon() const {
- if (GetPeer() == nullptr) {
- return false;
- }
- return jni::DecodeArtField(
- WellKnownClasses::java_lang_Thread_systemDaemon)->GetBoolean(GetPeer());
-}
-
} // namespace art
diff --git a/runtime/thread.h b/runtime/thread.h
index ec276b59f5..7a14fd7b48 100644
--- a/runtime/thread.h
+++ b/runtime/thread.h
@@ -1230,8 +1230,6 @@ class Thread {
return this == jit_sensitive_thread_;
}
- bool IsSystemDaemon() const REQUIRES_SHARED(Locks::mutator_lock_);
-
// Returns true if StrictMode events are traced for the current thread.
static bool IsSensitiveThread() {
if (is_sensitive_thread_hook_ != nullptr) {
diff --git a/runtime/well_known_classes.cc b/runtime/well_known_classes.cc
index 19fbf63ff5..955a455d36 100644
--- a/runtime/well_known_classes.cc
+++ b/runtime/well_known_classes.cc
@@ -92,7 +92,6 @@ jmethodID WellKnownClasses::java_lang_ClassLoader_loadClass;
jmethodID WellKnownClasses::java_lang_ClassNotFoundException_init;
jmethodID WellKnownClasses::java_lang_Daemons_start;
jmethodID WellKnownClasses::java_lang_Daemons_stop;
-jmethodID WellKnownClasses::java_lang_Daemons_waitForDaemonStart;
jmethodID WellKnownClasses::java_lang_Double_valueOf;
jmethodID WellKnownClasses::java_lang_Float_valueOf;
jmethodID WellKnownClasses::java_lang_Integer_valueOf;
@@ -133,7 +132,6 @@ jfieldID WellKnownClasses::java_lang_Thread_lock;
jfieldID WellKnownClasses::java_lang_Thread_name;
jfieldID WellKnownClasses::java_lang_Thread_priority;
jfieldID WellKnownClasses::java_lang_Thread_nativePeer;
-jfieldID WellKnownClasses::java_lang_Thread_systemDaemon;
jfieldID WellKnownClasses::java_lang_Thread_unparkedBeforeStart;
jfieldID WellKnownClasses::java_lang_ThreadGroup_groups;
jfieldID WellKnownClasses::java_lang_ThreadGroup_ngroups;
@@ -353,7 +351,6 @@ void WellKnownClasses::Init(JNIEnv* env) {
java_lang_Daemons_start = CacheMethod(env, java_lang_Daemons, true, "start", "()V");
java_lang_Daemons_stop = CacheMethod(env, java_lang_Daemons, true, "stop", "()V");
- java_lang_Daemons_waitForDaemonStart = CacheMethod(env, java_lang_Daemons, true, "waitForDaemonStart", "()V");
java_lang_invoke_MethodHandles_lookup = CacheMethod(env, "java/lang/invoke/MethodHandles", true, "lookup", "()Ljava/lang/invoke/MethodHandles$Lookup;");
java_lang_invoke_MethodHandles_Lookup_findConstructor = CacheMethod(env, "java/lang/invoke/MethodHandles$Lookup", false, "findConstructor", "(Ljava/lang/Class;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;");
@@ -388,7 +385,6 @@ void WellKnownClasses::Init(JNIEnv* env) {
java_lang_Thread_name = CacheField(env, java_lang_Thread, false, "name", "Ljava/lang/String;");
java_lang_Thread_priority = CacheField(env, java_lang_Thread, false, "priority", "I");
java_lang_Thread_nativePeer = CacheField(env, java_lang_Thread, false, "nativePeer", "J");
- java_lang_Thread_systemDaemon = CacheField(env, java_lang_Thread, false, "systemDaemon", "Z");
java_lang_Thread_unparkedBeforeStart = CacheField(env, java_lang_Thread, false, "unparkedBeforeStart", "Z");
java_lang_ThreadGroup_groups = CacheField(env, java_lang_ThreadGroup, false, "groups", "[Ljava/lang/ThreadGroup;");
java_lang_ThreadGroup_ngroups = CacheField(env, java_lang_ThreadGroup, false, "ngroups", "I");
diff --git a/runtime/well_known_classes.h b/runtime/well_known_classes.h
index 3c5144fbd5..872b562bd5 100644
--- a/runtime/well_known_classes.h
+++ b/runtime/well_known_classes.h
@@ -101,7 +101,6 @@ struct WellKnownClasses {
static jmethodID java_lang_ClassNotFoundException_init;
static jmethodID java_lang_Daemons_start;
static jmethodID java_lang_Daemons_stop;
- static jmethodID java_lang_Daemons_waitForDaemonStart;
static jmethodID java_lang_Double_valueOf;
static jmethodID java_lang_Float_valueOf;
static jmethodID java_lang_Integer_valueOf;
@@ -142,7 +141,6 @@ struct WellKnownClasses {
static jfieldID java_lang_Thread_name;
static jfieldID java_lang_Thread_priority;
static jfieldID java_lang_Thread_nativePeer;
- static jfieldID java_lang_Thread_systemDaemon;
static jfieldID java_lang_Thread_unparkedBeforeStart;
static jfieldID java_lang_ThreadGroup_groups;
static jfieldID java_lang_ThreadGroup_ngroups;