@@ -58,11 +58,6 @@ public class DebuggerAgent {
5858 public static synchronized void run (
5959 Instrumentation instrumentation , SharedCommunicationObjects sco ) {
6060 Config config = Config .get ();
61- if (!config .isDebuggerEnabled ()) {
62- LOGGER .info ("Debugger agent disabled" );
63- return ;
64- }
65- LOGGER .info ("Starting Dynamic Instrumentation" );
6661 ClassesToRetransformFinder classesToRetransformFinder = new ClassesToRetransformFinder ();
6762 setupSourceFileTracking (instrumentation , classesToRetransformFinder );
6863 Redaction .addUserDefinedKeywords (config );
@@ -95,6 +90,7 @@ public static synchronized void run(
9590 DebuggerContext .initTracer (new DebuggerTracer (debuggerSink .getProbeStatusSink ()));
9691 DefaultExceptionDebugger defaultExceptionDebugger = null ;
9792 if (config .isDebuggerExceptionEnabled ()) {
93+ LOGGER .info ("Starting Exception Replay" );
9894 defaultExceptionDebugger =
9995 new DefaultExceptionDebugger (
10096 configurationUpdater ,
@@ -112,6 +108,36 @@ public static synchronized void run(
112108 setupInstrumentTheWorldTransformer (
113109 config , instrumentation , debuggerSink , statsdMetricForwarder );
114110 }
111+ // Dynamic Instrumentation
112+ if (config .isDebuggerEnabled ()) {
113+ startDynamicInstrumentation (
114+ instrumentation , sco , config , configurationUpdater , debuggerSink , classNameFiltering );
115+ }
116+ try {
117+ /*
118+ Note: shutdown hooks are tricky because JVM holds reference for them forever preventing
119+ GC for anything that is reachable from it.
120+ */
121+ Runtime .getRuntime ().addShutdownHook (new ShutdownHook (configurationPoller , debuggerSink ));
122+ } catch (final IllegalStateException ex ) {
123+ // The JVM is already shutting down.
124+ }
125+ ExceptionProbeManager exceptionProbeManager =
126+ defaultExceptionDebugger != null
127+ ? defaultExceptionDebugger .getExceptionProbeManager ()
128+ : null ;
129+ TracerFlare .addReporter (
130+ new DebuggerReporter (configurationUpdater , sink , exceptionProbeManager ));
131+ }
132+
133+ private static void startDynamicInstrumentation (
134+ Instrumentation instrumentation ,
135+ SharedCommunicationObjects sco ,
136+ Config config ,
137+ ConfigurationUpdater configurationUpdater ,
138+ DebuggerSink debuggerSink ,
139+ ClassNameFiltering classNameFiltering ) {
140+ LOGGER .info ("Starting Dynamic Instrumentation" );
115141 String probeFileLocation = config .getDebuggerProbeFileLocation ();
116142 if (probeFileLocation != null ) {
117143 Path probeFilePath = Paths .get (probeFileLocation );
@@ -133,24 +159,9 @@ public static synchronized void run(
133159 }
134160 }
135161 subscribeConfigurationPoller (config , configurationUpdater , symDBEnablement );
136- try {
137- /*
138- Note: shutdown hooks are tricky because JVM holds reference for them forever preventing
139- GC for anything that is reachable from it.
140- */
141- Runtime .getRuntime ().addShutdownHook (new ShutdownHook (configurationPoller , debuggerSink ));
142- } catch (final IllegalStateException ex ) {
143- // The JVM is already shutting down.
144- }
145162 } else {
146163 LOGGER .debug ("No configuration poller available from SharedCommunicationObjects" );
147164 }
148- ExceptionProbeManager exceptionProbeManager =
149- defaultExceptionDebugger != null
150- ? defaultExceptionDebugger .getExceptionProbeManager ()
151- : null ;
152- TracerFlare .addReporter (
153- new DebuggerReporter (configurationUpdater , sink , exceptionProbeManager ));
154165 }
155166
156167 private static DebuggerSink createDebuggerSink (Config config , ProbeStatusSink probeStatusSink ) {
0 commit comments