-
Notifications
You must be signed in to change notification settings - Fork 937
Obtain can_generate_sampled_object_alloc_events JVMTI capability only when needed #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… when needed Only one JVM TI agent can hold can_generate_sampled_object_alloc_events capability at a time. To avoid multiple profiler instances from conflicting with each other, profiler should obtain the capability only when needed and release it as soon as a profiling session finishes.
test/test/alloc/AllocTests.java
Outdated
|
|
||
| @Test(mainClass = MapReaderOpt.class, jvmVer = {11, Integer.MAX_VALUE}) | ||
| public void objectSamplerWtihDifferentAsprofs(TestProcess p) throws Exception { | ||
| Thread.sleep(1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that? If there is a problem with timing, it should be solved centrally, preferably in a more reliable way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the sleep
test/test/alloc/AllocTests.java
Outdated
| // _[k] suffix in collapsed output corresponds to jdk.ObjectAllocationOutsideTLAB, which means alloc tracer is being used | ||
| assert !out.contains("_\\[k\\]"); // we are using alloc tracer instead of object sampler, should definitely not happen on first profiling call | ||
| Path asprofCopy = Path.of("/tmp/libasyncProfiler." + p.currentOs().getLibExt()); | ||
| Files.copy(Path.of("build/lib/libasyncProfiler." + p.currentOs().getLibExt()), asprofCopy, StandardCopyOption.REPLACE_EXISTING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to encapsulate the logic for getting library path in TestProcess, especially since TestProcess already has it.
test/test/alloc/AllocTests.java
Outdated
| Output out = p.profile("-e alloc -d 3 -o collapsed"); | ||
| // _[k] suffix in collapsed output corresponds to jdk.ObjectAllocationOutsideTLAB, which means alloc tracer is being used | ||
| assert !out.contains("_\\[k\\]"); // we are using alloc tracer instead of object sampler, should definitely not happen on first profiling call | ||
| Path asprofCopy = Path.of("/tmp/libasyncProfiler." + p.currentOs().getLibExt()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary file should have a unique name (not to clash with an existing library and to be able to run multiple test processes simultaneously). The file should be deleted on exit.
Description
Only one JVM TI agent can hold can_generate_sampled_object_alloc_events capability at a time. To avoid multiple profiler instances from conflicting with each other, profiler should obtain the capability only when needed and release it as soon as a profiling session finishes.
Related issues
Motivation and context
This allows multiple different async profiler instances to use the object sampler on the same java process one after the other.
How has this been tested?
Verifying that the test fails without implementation changes: https://github.com/openorclose/async-profiler/actions/runs/11050192717/job/30697437468#step:6:51
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.