Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit f235454

Browse files
author
mattwach
committed
Automated g4 rollback of changelist 150936297.
*** Reason for rollback *** Try adding this flag again, this time using the pre-existing requireStub() method that other methods are using to avoid trying to load classes too early. That should avoid the race condition that caused the original rollback. *** Original change description *** Automated g4 rollback of changelist 149961619. *** Reason for rollback *** Causes deadlock. b/36526050 *** Original change description *** Reimplement cl/146413726 to do the borg checking in Java. This change was needed due to a circular dependency introducted by the last change. See the comments in cl/146413726 for details. Unfortunately, this change requires adding a method to the JNI bridge. This requires many changes and complicates the implementation. Indeed most of the c... *** ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=159229602
1 parent 9f3a27d commit f235454

File tree

7 files changed

+56
-3
lines changed

7 files changed

+56
-3
lines changed

src/agent/bridge.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ class Bridge {
7676

7777
// Approves the breakpoint for a global rollout.
7878
virtual bool ApproveBreakpointCanary(const string& breakpoint_id) = 0;
79+
80+
// Tries to determine if the debugger is enabled. If the debugger is enabled,
81+
// sets is_enabled to true and returns true. If the debugger is disabled,
82+
// sets is_enabled to false and returns true. If the method can not determine
83+
// status, sets is_enabled to false and returns false.
84+
virtual bool IsEnabled(bool* is_enabled) = 0;
7985
};
8086

8187
} // namespace cdbg

src/agent/internals/src/main/java/com/google/devtools/cdbg/debuglets/java/GcpHubClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ public void approveBreakpointCanary(String breakpointId) throws Exception {
508508
throw new UnsupportedOperationException("GcpHubClient#approveBreakpointCanary not implemented");
509509
}
510510

511+
/**
512+
* If there is any reason to not enable the debugger, return false here.
513+
*/
514+
@Override
515+
public boolean isEnabled() {
516+
return true;
517+
}
518+
511519
@Override
512520
public void shutdown() {
513521
metadata.shutdown();

src/agent/internals/src/main/java/com/google/devtools/cdbg/debuglets/java/HubClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ void transmitBreakpointUpdate(String format, String breakpointId, byte[] breakpo
142142
* @throws Exception if the backend could not be notified or on failure on the backend side.
143143
*/
144144
void approveBreakpointCanary(String breakpointId) throws Exception;
145-
145+
146+
/**
147+
* Returns false if this agent should not be enabled.
148+
*/
149+
boolean isEnabled() throws Exception;
150+
146151
/**
147152
* Asynchronously aborts all pending requests and blocks any future network connections.
148153
*/

src/agent/jni_bridge.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,18 @@ bool JniBridge::ApproveBreakpointCanary(const string& breakpoint_id) {
220220
}
221221

222222

223+
bool JniBridge::IsEnabled(bool* is_enabled) {
224+
auto rc = jniproxy::HubClient()->isEnabled(jni_hub_.get());
225+
if (rc.HasException()) {
226+
*is_enabled = false;
227+
return false;
228+
}
229+
230+
*is_enabled = rc.GetData();
231+
return true;
232+
}
233+
234+
223235
void JniBridge::Shutdown() {
224236
MutexLock lock(&mu_);
225237

src/agent/jni_bridge.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ class JniBridge : public Bridge {
6969

7070
bool ApproveBreakpointCanary(const string& breakpoint_id) override;
7171

72+
// TODO(mattwach): This method might be better put into it's own interface.
73+
// The reason it's not done now is that creating a new interface involves
74+
// a lot of change and boilerplate. It would seems reasonable to see the need
75+
// for an interface expanded a bit before putting the definitions and
76+
// rules in place.
77+
bool IsEnabled(bool* is_enabled) override;
78+
7279
private:
7380
// Callback to create an instance of Java class implementing
7481
// the com.google.devtools.cdbg.debuglets.java.HubClient interface.

src/agent/worker.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ DEFINE_FLAG(
3838
namespace devtools {
3939
namespace cdbg {
4040

41-
int g_register_debuggee_attempts = 0;
41+
int g_is_enabled_attempts = 0;
4242

4343
Worker::Worker(
4444
Provider* provider,
@@ -146,6 +146,19 @@ void Worker::MainThreadProc() {
146146
return; // Signal to stop the main debugger thread.
147147
}
148148

149+
bool is_enabled = false;
150+
while (!is_unloading_ && !bridge_->IsEnabled(&is_enabled)) {
151+
// Wait for classes to load.
152+
++g_is_enabled_attempts;
153+
provider_->OnIdle();
154+
main_thread_event_->Wait(100); // Wait for 100ms to lower CPU usage
155+
}
156+
157+
if (!is_enabled) {
158+
LOG(WARNING) << "The debugger is disabled on this process.";
159+
return;
160+
}
161+
149162
while (!is_unloading_) {
150163
// Register debuggee if not registered or if previous call to list active
151164
// breakpoints failed.
@@ -202,7 +215,6 @@ void Worker::TransmissionThreadProc() {
202215
void Worker::RegisterDebuggee() {
203216
bool new_is_enabled = false;
204217
is_registered_ = bridge_->RegisterDebuggee(&new_is_enabled);
205-
++g_register_debuggee_attempts;
206218

207219
if (is_registered_) {
208220
provider_->EnableDebugger(new_is_enabled);

src/codegen/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@
288288
},
289289
{
290290
"methodName": "shutdown"
291+
},
292+
{
293+
"methodName": "isEnabled"
291294
}
292295
],
293296
"nativeNamespace": "jniproxy"

0 commit comments

Comments
 (0)