This repository was archived by the owner on Feb 29, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed
Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -247,6 +247,12 @@ void JvmtiAgent::JvmtiOnBreakpoint(
247247 jthread thread,
248248 jmethodID method,
249249 jlocation location) {
250+ // Ignore breakpoint events from debugger worker threads. Debugging
251+ // the debugger may cause deadlock.
252+ if (JvmtiAgentThread::IsInAgentThread ()) {
253+ return ;
254+ }
255+
250256 std::shared_ptr<Debugger> debugger = debugger_;
251257
252258 if (debugger != nullptr ) {
Original file line number Diff line number Diff line change 2121namespace devtools {
2222namespace cdbg {
2323
24+ // Thread local variable indicating whether the current thread is JVMTI
25+ // agent thread created by "JvmtiAgentThread".
26+ static __thread bool g_is_agent_thread = false ;
27+
28+
2429JvmtiAgentThread::JvmtiAgentThread () {
2530}
2631
@@ -85,6 +90,9 @@ bool JvmtiAgentThread::StartAgentThread(
8590 [] (jvmtiEnv* jvmti, JNIEnv* jni, void * arg) {
8691 set_thread_jni (jni);
8792
93+ DCHECK (!g_is_agent_thread);
94+ g_is_agent_thread = true ;
95+
8896 auto * agent_arg = reinterpret_cast <
8997 std::pair<string, std::function<bool ()>>*>(arg);
9098
@@ -94,6 +102,8 @@ bool JvmtiAgentThread::StartAgentThread(
94102
95103 LOG (INFO) << " Agent thread exited: " << agent_arg->first ;
96104
105+ g_is_agent_thread = false ;
106+
97107 delete agent_arg;
98108 },
99109 agent_arg,
@@ -111,6 +121,10 @@ bool JvmtiAgentThread::StartAgentThread(
111121}
112122
113123
124+ bool JvmtiAgentThread::IsInAgentThread () {
125+ return g_is_agent_thread;
126+ }
127+
114128} // namespace cdbg
115129} // namespace devtools
116130
Original file line number Diff line number Diff line change @@ -40,6 +40,10 @@ class JvmtiAgentThread : public AgentThread {
4040
4141 void Sleep (int ms) override ;
4242
43+ // Returns true if the current thread is JVMTI agent thread created by
44+ // this class.
45+ static bool IsInAgentThread ();
46+
4347 private:
4448 // Creates the thread objects and starts the agent thread.
4549 bool StartAgentThread (
You can’t perform that action at this time.
0 commit comments