luceneutil icon indicating copy to clipboard operation
luceneutil copied to clipboard

StatisticsHelper doesn't generate "Garbage Generated" output

Open dsmiley opened this issue 7 years ago • 3 comments
trafficstars

StatisticsHelper.java generates information about the garbage collector during a benchmark task. Here's a snippet that winds up at the end of a ".stdout" log file:

Garbage Generated in Young Generation: 48913.992 MiB
Garbage Generated in Survivor Generation: 69.45353 MiB
Garbage Generated in Old Generation: 66.00384 MiB

Due to a bug, those numbers if done today will all be zero. StatisticsHelper.run calls Thread.currentThread().setDaemon(true); which looked wrong to me, and sure enough was causing an IllegalStateException on the thread (or something like that if I recall). A Runnable being invoked by an Executor ought not to mess with the state of it's thread. And I think it's unnecessary to try to make these threads daemons since stopStatistics() will cancel then shut it down.

Note quite related: I also thought it prudent to explicitly call run() from stopStatistics so we get the very latest information.

Another aside: it's suspicious to see all these volatile fields and furthermore "+=" operations on them. I don't think there are thread-safety concerns; they can all be regular fields. I don't think there needs to be synchronization in this class either. Calling executor.shutdown() triggers a happens-before relationship with the state modified by the task thread.

I could submit a PR if desired.

CC @shaie whom I suspect wrote StatisticsHelper originally

dsmiley avatar Sep 17 '18 03:09 dsmiley

+1 for a PR! Thanks @dsmiley.

mikemccand avatar Sep 17 '18 21:09 mikemccand

Might you look at the PR please?

dsmiley avatar Mar 04 '20 13:03 dsmiley

Thanks for the ping @dsmiley; I'll have a look.

mikemccand avatar Mar 04 '20 14:03 mikemccand