First off, thanks as always for looking at this :-) Let me
inline my answers:
I actually "struggled" with this part of the change. My
change is correct semantically and if you care about
performance for when sampling a given thread.
Your change will work semantically but the performance is
the same as the global sampling.
What I mean by working semantically is that that the
tests and the code will work. However, this means that all
threads will be doing the sampling work but when the code
will post the event here:
(which is why your suggestion works, the change in
jvmtiExport basically ensures only the threads requested are
posting events)
The code will check that we actually only post for
threads we care about. The code above ensures that only
threads that were requested to be sampling are the ones that
are sampling internally.
Note: I REALLY prefer your suggestion for two reasons:
- We do not change the runtime/GC code at all, it
remains "simple"
- The overhead in the general case goes away and this
is a NOP for my actual use-case from a performance point of
view (sampling every thread)
But:
- Then sampling per thread really is just telling the
system don't pollute the callbacks, though internally you
are doing all the work anyway.
Let me know which you prefer :)
Also, do you see that enabling the sampling events globally still works?
Yes, otherwise HeapMonitorThreadTest.java would fail
since it checks that.
Done and done, I added a fprintf on stderr saying the
GetThreadInfo failed and the test is ignoring the add count.
Thanks again for looking and let me know what you think,
Jc