Skip to content

Commit a685011

Browse files
author
Thomas Schatzl
committedJul 7, 2021
8269022: Put evacuation failure string directly into gc=info log message
Reviewed-by: iwalulya, lkorinth, kbarrett
1 parent 72530ef commit a685011

File tree

4 files changed

+124
-26
lines changed

4 files changed

+124
-26
lines changed
 

‎src/hotspot/share/gc/g1/g1CollectedHeap.cpp

+41-20
Original file line numberDiff line numberDiff line change
@@ -2877,17 +2877,6 @@ void G1CollectedHeap::expand_heap_after_young_collection(){
28772877
}
28782878
}
28792879

2880-
void G1CollectedHeap::set_young_gc_name(char* young_gc_name) {
2881-
G1GCPauseType pause_type =
2882-
// The strings for all Concurrent Start pauses are the same, so the parameter
2883-
// does not matter here.
2884-
collector_state()->young_gc_pause_type(false /* concurrent_operation_is_full_mark */);
2885-
snprintf(young_gc_name,
2886-
MaxYoungGCNameLength,
2887-
"Pause Young (%s)",
2888-
G1GCPauseTypeHelper::to_string(pause_type));
2889-
}
2890-
28912880
bool G1CollectedHeap::do_collection_pause_at_safepoint(double target_pause_time_ms) {
28922881
assert_at_safepoint_on_vm_thread();
28932882
guarantee(!is_gc_active(), "collection is not reentrant");
@@ -2915,6 +2904,46 @@ void G1CollectedHeap::gc_tracer_report_gc_end(bool concurrent_operation_is_full_
29152904
_gc_timer_stw->time_partitions());
29162905
}
29172906

2907+
// GCTraceTime wrapper that constructs the message according to GC pause type and
2908+
// GC cause.
2909+
// The code relies on the fact that GCTraceTimeWrapper stores the string passed
2910+
// initially as a reference only, so that we can modify it as needed.
2911+
class G1YoungGCTraceTime {
2912+
G1GCPauseType _pause_type;
2913+
GCCause::Cause _pause_cause;
2914+
2915+
static const uint MaxYoungGCNameLength = 128;
2916+
char _young_gc_name_data[MaxYoungGCNameLength];
2917+
2918+
GCTraceTime(Info, gc) _tt;
2919+
2920+
const char* update_young_gc_name() {
2921+
snprintf(_young_gc_name_data,
2922+
MaxYoungGCNameLength,
2923+
"Pause Young (%s) (%s)%s",
2924+
G1GCPauseTypeHelper::to_string(_pause_type),
2925+
GCCause::to_string(_pause_cause),
2926+
G1CollectedHeap::heap()->evacuation_failed() ? " (Evacuation Failure)" : "");
2927+
return _young_gc_name_data;
2928+
}
2929+
2930+
public:
2931+
G1YoungGCTraceTime(GCCause::Cause cause) :
2932+
// Take snapshot of current pause type at start as it may be modified during gc.
2933+
// The strings for all Concurrent Start pauses are the same, so the parameter
2934+
// does not matter here.
2935+
_pause_type(G1CollectedHeap::heap()->collector_state()->young_gc_pause_type(false /* concurrent_operation_is_full_mark */)),
2936+
_pause_cause(cause),
2937+
// Fake a "no cause" and manually add the correct string in update_young_gc_name()
2938+
// to make the string look more natural.
2939+
_tt(update_young_gc_name(), NULL, GCCause::_no_gc, true) {
2940+
}
2941+
2942+
~G1YoungGCTraceTime() {
2943+
update_young_gc_name();
2944+
}
2945+
};
2946+
29182947
void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_pause_time_ms) {
29192948
GCIdMark gc_id_mark;
29202949

@@ -2960,10 +2989,7 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus
29602989

29612990
GCTraceCPUTime tcpu;
29622991

2963-
char young_gc_name[MaxYoungGCNameLength];
2964-
set_young_gc_name(young_gc_name);
2965-
2966-
GCTraceTime(Info, gc) tm(young_gc_name, NULL, gc_cause(), true);
2992+
G1YoungGCTraceTime tm(gc_cause());
29672993

29682994
uint active_workers = WorkerPolicy::calc_active_workers(workers()->total_workers(),
29692995
workers()->active_workers(),
@@ -3052,11 +3078,6 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus
30523078
gc_epilogue(false);
30533079
}
30543080

3055-
// Print the remainder of the GC log output.
3056-
if (evacuation_failed()) {
3057-
log_info(gc)("To-space exhausted");
3058-
}
3059-
30603081
policy()->print_phases();
30613082
heap_transition.print();
30623083

‎src/hotspot/share/gc/g1/g1CollectedHeap.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,6 @@ class G1CollectedHeap : public CollectedHeap {
396396
#define assert_used_and_recalculate_used_equal(g1h) do {} while(0)
397397
#endif
398398

399-
static const uint MaxYoungGCNameLength = 128;
400-
// Sets given young_gc_name to the canonical young gc pause string. Young_gc_name
401-
// must be at least of length MaxYoungGCNameLength.
402-
void set_young_gc_name(char* young_gc_name);
403-
404399
// The young region list.
405400
G1EdenRegions _eden;
406401
G1SurvivorRegions _survivor;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package gc.g1;
25+
26+
/*
27+
* @test TestEvacuationFailure
28+
* @summary Ensure the output for a minor GC with G1 that has evacuation failure contains the correct strings.
29+
* @requires vm.gc.G1
30+
* @requires vm.debug
31+
* @library /test/lib
32+
* @modules java.base/jdk.internal.misc
33+
* java.management
34+
* @build sun.hotspot.WhiteBox
35+
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
36+
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
37+
* gc.g1.TestEvacuationFailure
38+
*/
39+
40+
import jdk.test.lib.process.OutputAnalyzer;
41+
import jdk.test.lib.Platform;
42+
import jdk.test.lib.process.ProcessTools;
43+
44+
public class TestEvacuationFailure {
45+
46+
public static void main(String[] args) throws Exception {
47+
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
48+
"-Xmx32M",
49+
"-Xmn16M",
50+
"-XX:+G1EvacuationFailureALot",
51+
"-XX:G1EvacuationFailureALotCount=100",
52+
"-XX:G1EvacuationFailureALotInterval=1",
53+
"-XX:+UnlockDiagnosticVMOptions",
54+
"-XX:-G1UsePreventiveGC",
55+
"-Xlog:gc",
56+
GCTestWithEvacuationFailure.class.getName());
57+
58+
OutputAnalyzer output = new OutputAnalyzer(pb.start());
59+
System.out.println(output.getStdout());
60+
output.shouldContain("(Evacuation Failure)");
61+
output.shouldHaveExitValue(0);
62+
}
63+
64+
static class GCTestWithEvacuationFailure {
65+
private static byte[] garbage;
66+
private static byte[] largeObject;
67+
private static Object[] holder = new Object[200]; // Must be larger than G1EvacuationFailureALotCount
68+
69+
public static void main(String [] args) {
70+
largeObject = new byte[16 * 1024 * 1024];
71+
System.out.println("Creating garbage");
72+
// Create 16 MB of garbage. This should result in at least one GC,
73+
// (Heap size is 32M, we use 17MB for the large object above)
74+
// which is larger than G1EvacuationFailureALotInterval.
75+
for (int i = 0; i < 16 * 1024; i++) {
76+
holder[i % holder.length] = new byte[1024];
77+
}
78+
System.out.println("Done");
79+
}
80+
}
81+
}
82+

‎test/hotspot/jtreg/gc/g1/plab/TestPLABEvacuationFailure.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private static Map<Long, PlabInfo> getEvacFailureOldStats() {
196196

197197
private static List<Long> getGcIdPlabEvacFailures(OutputAnalyzer out) {
198198
return out.asLines().stream()
199-
.filter(line -> line.contains("space exhausted"))
199+
.filter(line -> line.contains("(Evacuation Failure)"))
200200
.map(line -> LogParser.getGcIdFromLine(line, GC_ID_PATTERN))
201201
.collect(Collectors.toList());
202202
}

0 commit comments

Comments
 (0)
Please sign in to comment.