Skip to content

Commit a2e840f

Browse files
Rui Limrserb
authored andcommitted
8342786: Shenandoah: Emit AllocationRequiringGC jfr events
Reviewed-by: kdnilsen, serb, wkemper
1 parent 2a8e3b8 commit a2e840f

3 files changed

Lines changed: 102 additions & 2 deletions

File tree

src/hotspot/share/gc/shenandoah/shenandoahController.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
*
2424
*/
2525

26+
#include "gc/shared/allocTracer.hpp"
2627
#include "gc/shared/gc_globals.hpp"
2728
#include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
2829
#include "gc/shenandoah/shenandoahController.hpp"
2930
#include "gc/shenandoah/shenandoahHeap.hpp"
3031
#include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
3132

32-
3333
void ShenandoahController::update_gc_id() {
3434
_gc_id.add_then_fetch((size_t)1);
3535
}
@@ -45,10 +45,12 @@ void ShenandoahController::handle_alloc_failure(const ShenandoahAllocRequest& re
4545
const GCCause::Cause cause = is_humongous ? GCCause::_shenandoah_humongous_allocation_failure : GCCause::_allocation_failure;
4646

4747
ShenandoahHeap* const heap = ShenandoahHeap::heap();
48+
size_t req_byte = req.size() * HeapWordSize;
4849
if (heap->cancel_gc(cause)) {
49-
log_info(gc)("Failed to allocate %s, " PROPERFMT, req.type_string(), PROPERFMTARGS(req.size() * HeapWordSize));
50+
log_info(gc)("Failed to allocate %s, " PROPERFMT, req.type_string(), PROPERFMTARGS(req_byte));
5051
request_gc(cause);
5152
}
53+
AllocTracer::send_allocation_requiring_gc_event(req_byte, checked_cast<uint>(get_gc_id()));
5254

5355
if (block) {
5456
MonitorLocker ml(&_alloc_failure_waiters_lock);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
package jdk.jfr.event.gc.detailed;
26+
27+
/**
28+
* @test id=default
29+
* @key randomness
30+
* @requires vm.hasJFR
31+
* @requires vm.gc.Shenandoah
32+
* @library /test/lib /test/jdk
33+
* @run main/othervm -XX:+UseShenandoahGC -Xmx64m -XX:ActiveProcessorCount=1 jdk.jfr.event.gc.detailed.TestStressAllocationGCEventsWithShenandoah
34+
*/
35+
36+
/**
37+
* @test id=generational
38+
* @key randomness
39+
* @requires vm.hasJFR
40+
* @requires vm.gc.Shenandoah
41+
* @library /test/lib /test/jdk
42+
* @run main/othervm -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -Xmx64m -XX:ActiveProcessorCount=1 jdk.jfr.event.gc.detailed.TestStressAllocationGCEventsWithShenandoah
43+
*/
44+
public class TestStressAllocationGCEventsWithShenandoah {
45+
46+
public static void main(String[] args) throws Exception {
47+
new StressAllocationGCEvents().run(args);
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
package jdk.jfr.event.gc.detailed;
26+
27+
/**
28+
* @test id=default
29+
* @key randomness
30+
* @requires vm.hasJFR
31+
* @requires vm.gc.Shenandoah
32+
* @library /test/lib /test/jdk
33+
* @run main/othervm -XX:+UseShenandoahGC -Xmx256m -XX:ActiveProcessorCount=1 jdk.jfr.event.gc.detailed.TestStressBigAllocationGCEventsWithShenandoah 1048576
34+
*/
35+
36+
/**
37+
* @test id=generational
38+
* @key randomness
39+
* @requires vm.hasJFR
40+
* @requires vm.gc.Shenandoah
41+
* @library /test/lib /test/jdk
42+
* @run main/othervm -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -Xmx256m -XX:ActiveProcessorCount=1 jdk.jfr.event.gc.detailed.TestStressBigAllocationGCEventsWithShenandoah 1048576
43+
*/
44+
public class TestStressBigAllocationGCEventsWithShenandoah {
45+
46+
public static void main(String[] args) throws Exception {
47+
new StressAllocationGCEvents().run(args);
48+
}
49+
}

0 commit comments

Comments
 (0)