@@ -70,6 +70,7 @@ public class DebuggerAgent {
7070 static final AtomicBoolean exceptionReplayEnabled = new AtomicBoolean ();
7171 static final AtomicBoolean codeOriginEnabled = new AtomicBoolean ();
7272 static final AtomicBoolean distributedDebuggerEnabled = new AtomicBoolean ();
73+ static final AtomicBoolean symDBEnabled = new AtomicBoolean ();
7374 private static ClassesToRetransformFinder classesToRetransformFinder ;
7475
7576 public static synchronized void run (
@@ -89,10 +90,14 @@ public static synchronized void run(
8990 if (config .isDynamicInstrumentationEnabled ()) {
9091 startDynamicInstrumentation (config );
9192 startCodeOriginForSpans (config );
93+ startSymbolDatabase (config );
9294 if (config .getDynamicInstrumentationInstrumentTheWorld () != null ) {
9395 setupInstrumentTheWorldTransformer (config , instrumentation , sink );
9496 }
9597 }
98+ if (config .isSymbolDatabaseEnabled ()) {
99+ startSymbolDatabase (config );
100+ }
96101 try {
97102 /*
98103 Note: shutdown hooks are tricky because JVM holds reference for them forever preventing
@@ -165,24 +170,7 @@ public static void startDynamicInstrumentation(Config config) {
165170 return ;
166171 }
167172 if (configurationPoller != null ) {
168- if (config .isSymbolDatabaseEnabled ()) {
169- initClassNameFilter ();
170- List <ScopeFilter > scopeFilters =
171- Arrays .asList (new AvroFilter (), new ProtoFilter (), new WireFilter ());
172- SymbolAggregator symbolAggregator =
173- new SymbolAggregator (
174- classNameFilter ,
175- scopeFilters ,
176- sink .getSymbolSink (),
177- config .getSymbolDatabaseFlushThreshold ());
178- symbolAggregator .start ();
179- symDBEnablement =
180- new SymDBEnablement (instrumentation , config , symbolAggregator , classNameFilter );
181- if (config .isSymbolDatabaseForceUpload ()) {
182- symDBEnablement .startSymbolExtraction ();
183- }
184- }
185- subscribeConfigurationPoller (config , configurationUpdater , symDBEnablement );
173+ subscribeLiveDebugging (config , configurationUpdater );
186174 } else {
187175 LOGGER .debug ("No configuration poller available from SharedCommunicationObjects" );
188176 }
@@ -205,6 +193,61 @@ public static void stopDynamicInstrumentation() {
205193 }
206194 }
207195
196+ private static void subscribeLiveDebugging (
197+ Config config , ConfigurationUpdater configurationUpdater ) {
198+ LOGGER .debug ("Subscribing to Live Debugging..." );
199+ configurationPoller .addListener (
200+ Product .LIVE_DEBUGGING , new DebuggerProductChangesListener (config , configurationUpdater ));
201+ if (symDBEnablement != null && !config .isSymbolDatabaseForceUpload ()) {
202+ LOGGER .debug ("Subscribing to Symbol DB..." );
203+ configurationPoller .addListener (Product .LIVE_DEBUGGING_SYMBOL_DB , symDBEnablement );
204+ }
205+ }
206+
207+ public static void startSymbolDatabase (Config config ) {
208+ if (!symDBEnabled .compareAndSet (false , true )) {
209+ return ;
210+ }
211+ LOGGER .debug ("Starting Symbol Database" );
212+ initClassNameFilter ();
213+ List <ScopeFilter > scopeFilters =
214+ Arrays .asList (new AvroFilter (), new ProtoFilter (), new WireFilter ());
215+ SymbolAggregator symbolAggregator =
216+ new SymbolAggregator (
217+ classNameFilter ,
218+ scopeFilters ,
219+ sink .getSymbolSink (),
220+ config .getSymbolDatabaseFlushThreshold ());
221+ symbolAggregator .start ();
222+ symDBEnablement =
223+ new SymDBEnablement (instrumentation , config , symbolAggregator , classNameFilter );
224+ if (config .isSymbolDatabaseForceUpload ()) {
225+ symDBEnablement .startSymbolExtraction ();
226+ }
227+ subscribeSymDB (symDBEnablement );
228+ LOGGER .debug ("Started Symbol Database" );
229+ }
230+
231+ private static void subscribeSymDB (SymDBEnablement symDBEnablement ) {
232+ LOGGER .debug ("Subscribing to Symbol DB..." );
233+ configurationPoller .addListener (Product .LIVE_DEBUGGING_SYMBOL_DB , symDBEnablement );
234+ }
235+
236+ public static void stopSymbolDatabase () {
237+ if (!symDBEnabled .compareAndSet (true , false )) {
238+ return ;
239+ }
240+ LOGGER .info ("Stopping Symbol Database" );
241+ if (configurationPoller != null ) {
242+ configurationPoller .removeListeners (Product .LIVE_DEBUGGING_SYMBOL_DB );
243+ }
244+ SymDBEnablement localSymDBEnablement = symDBEnablement ;
245+ if (localSymDBEnablement != null ) {
246+ localSymDBEnablement .stopSymbolExtraction ();
247+ symDBEnablement = null ;
248+ }
249+ }
250+
208251 public static void startExceptionReplay (Config config ) {
209252 if (!exceptionReplayEnabled .compareAndSet (false , true )) {
210253 return ;
@@ -369,17 +412,6 @@ private static void setupSourceFileTracking(
369412 instrumentation .addTransformer (sourceFileTrackingTransformer );
370413 }
371414
372- private static void subscribeConfigurationPoller (
373- Config config , ConfigurationUpdater configurationUpdater , SymDBEnablement symDBEnablement ) {
374- LOGGER .debug ("Subscribing to Live Debugging..." );
375- configurationPoller .addListener (
376- Product .LIVE_DEBUGGING , new DebuggerProductChangesListener (config , configurationUpdater ));
377- if (symDBEnablement != null && !config .isSymbolDatabaseForceUpload ()) {
378- LOGGER .debug ("Subscribing to Symbol DB..." );
379- configurationPoller .addListener (Product .LIVE_DEBUGGING_SYMBOL_DB , symDBEnablement );
380- }
381- }
382-
383415 private static void unsubscribeConfigurationPoller () {
384416 if (configurationPoller != null ) {
385417 configurationPoller .removeListeners (Product .LIVE_DEBUGGING );
0 commit comments