Warning "Duplicate class entries" caused by instrumentation threads interleaving
When starting our application we see those warnings about duplicate class entries:
[quasar] WARNING: Duplicate class entries with different data for class: [ClassName]
This warning is printed in the recordSuspendableMethods method, line 262.
After debugging the instrumentation process and putting a breakpoint at that line we see the following stack traces:
From the code above you see, that you get this warning only if the ClassEntry instance already exists in the classes map and if it is different (considering references) than the new one.
The stack trace above indicates that the ClassEntry instance is not present for the className in the classes map at the time of the if (entry == null) condition evaluation at line 319.
The above snippet is to confirm this further.
Therefore, there is a race condition in the classes map access by different threads.
Depending on the intended behaviour there could be (at least) 3 solutions that we would like to suggest:
-
In the first snippet you see that both the
oldEntryand theentryare the same in terms of data and thus can be possibly compared based on theequalmethod basis, instead of==reference comparison. -
extend the
synchronizedblock in thecheckClassmethod. This would possibly affect performance. -
reduce the log level to DEBUG or even TRACE (if combined with solution 1)).
Thanks Michal.
I can't reproduce this anymore after upgrading to 0.7.9 but I'll keep trying, as it is tricky to reproduce. As this code doesn't seem to have changed lately I suspect the race is still there but something has changed timing-wise to make it show up less.