RFR: 8372039: post_sampled_object_alloc is called while lock is handled [v4]

Alex Menkov amenkov at openjdk.org
Tue Dec 2 21:09:16 UTC 2025


On Fri, 28 Nov 2025 21:09:24 GMT, Leonid Mesnik <lmesnik at openjdk.org> wrote:

>> The AOT allocates objects while holding lock. The jvmti events can't be posted in such case. The allocation sampling might be just temporary disabled while AOT objects are allocated. 
>> 
>> I prefer to disable jvmti events for allocation only, not for AOT globally. If there are more events should be generated during AOT initialization, we might want to preserve them and post after initialization is completed. 
>> 
>> The existing failure could be reproduced by running tests with jvmti stress agent and ZGC enabled. Like
>> make run-test JTREG_JVMTI_STRESS_AGENT=debugger=true TEST=gc/z/TestGarbageCollectorMXBean.java
>> 
>> Note: 
>> I prelaced NoJvmtiVMObjectAllocMark, it was not used. Also it was incorrect. The 
>> NoJvmtiEventsMark should be set even if jvmti events are not enable for this thread. Since jvmti events might be enabled just in the middle of the mark.
>
> Leonid Mesnik has updated the pull request incrementally with one additional commit since the last revision:
> 
>   made jvmti_events_disalber as counter

src/hotspot/share/runtime/javaThread.cpp line 454:

> 452:   _is_disable_suspend(false),
> 453:   _is_in_java_upcall(false),
> 454:   _jvmti_events_disabled(false),

Suggestion:

  _jvmti_events_disabled(0),

src/hotspot/share/runtime/javaThread.hpp line 768:

> 766:   // - JVMTI is making a Java upcall (_is_in_java_upcall)
> 767:   bool should_hide_jvmti_events() const          { return _is_in_VTMS_transition || _is_disable_suspend
> 768:     || _is_in_java_upcall || _jvmti_events_disabled != 0; }

Suggestion:

  bool should_hide_jvmti_events() const {
    return _is_in_VTMS_transition || _is_disable_suspend || _is_in_java_upcall || _jvmti_events_disabled != 0;
  }

test/hotspot/jtreg/serviceability/jvmti/events/SampledObjectAlloc/SamplingDuringInit/SamplingDuringInit.java line 26:

> 24: /**
> 25:  * @test
> 26:  * @summary  Test verify that object allocation sampling is disabled during AOT.

Suggestion:

 * @summary The test verifies that object allocation sampling is disabled during AOT.

test/hotspot/jtreg/serviceability/jvmti/events/SampledObjectAlloc/SamplingDuringInit/libSamplingDuringInit.cpp line 26:

> 24: #include "jvmti.h"
> 25: #include "jvmti_common.hpp"
> 26: 

Suggestion:

test/hotspot/jtreg/serviceability/jvmti/events/SampledObjectAlloc/SamplingDuringInit/libSamplingDuringInit.cpp line 34:

> 32:   LOG("Sampled object\n");
> 33: }
> 34: 

Suggestion:

test/hotspot/jtreg/serviceability/jvmti/events/SampledObjectAlloc/SamplingDuringInit/libSamplingDuringInit.cpp line 49:

> 47:     return JNI_ERR;
> 48:   }
> 49: 

Suggestion:

test/hotspot/jtreg/serviceability/jvmti/events/SampledObjectAlloc/SamplingDuringInit/libSamplingDuringInit.cpp line 67:

> 65:   err = jvmti->SetHeapSamplingInterval(10);
> 66:   check_jvmti_error(err, "SetHeapSamplingInterval");
> 67: 

Suggestion:

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/28544#discussion_r2582743429
PR Review Comment: https://git.openjdk.org/jdk/pull/28544#discussion_r2582750762
PR Review Comment: https://git.openjdk.org/jdk/pull/28544#discussion_r2582754970
PR Review Comment: https://git.openjdk.org/jdk/pull/28544#discussion_r2582755827
PR Review Comment: https://git.openjdk.org/jdk/pull/28544#discussion_r2582756365
PR Review Comment: https://git.openjdk.org/jdk/pull/28544#discussion_r2582756981
PR Review Comment: https://git.openjdk.org/jdk/pull/28544#discussion_r2582759498


More information about the serviceability-dev mailing list