Skip to content

Commit afb9134

Browse files
committed
8355627: Don't use ThreadCritical for EventLog list
Reviewed-by: shade, lmesnik, zgu
1 parent 811f117 commit afb9134

File tree

2 files changed

+89
-11
lines changed

2 files changed

+89
-11
lines changed

src/hotspot/share/utilities/events.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@
2626
#include "memory/allocation.inline.hpp"
2727
#include "oops/instanceKlass.hpp"
2828
#include "oops/symbol.hpp"
29+
#include "runtime/atomic.hpp"
2930
#include "runtime/javaThread.hpp"
3031
#include "runtime/mutexLocker.hpp"
3132
#include "runtime/osThread.hpp"
32-
#include "runtime/threadCritical.hpp"
3333
#include "runtime/timer.hpp"
3434
#include "utilities/events.hpp"
3535

36-
3736
EventLog* Events::_logs = nullptr;
3837
StringEventLog* Events::_messages = nullptr;
3938
StringEventLog* Events::_memprotect_messages = nullptr;
@@ -48,18 +47,19 @@ StringEventLog* Events::_deopt_messages = nullptr;
4847
StringEventLog* Events::_dll_messages = nullptr;
4948

5049
EventLog::EventLog() {
51-
// This normally done during bootstrap when we're only single
52-
// threaded but use a ThreadCritical to ensure inclusion in case
53-
// some are created slightly late.
54-
ThreadCritical tc;
55-
_next = Events::_logs;
56-
Events::_logs = this;
50+
// This is normally done during bootstrap when we're only single threaded,
51+
// but use lock free add because there are some events that are created later.
52+
EventLog* old_head;
53+
do {
54+
old_head = Atomic::load(&Events::_logs);
55+
_next = old_head;
56+
} while (Atomic::cmpxchg(&Events::_logs, old_head, this) != old_head);
5757
}
5858

5959
// For each registered event logger, print out the current contents of
6060
// the buffer.
6161
void Events::print_all(outputStream* out, int max) {
62-
EventLog* log = _logs;
62+
EventLog* log = Atomic::load(&Events::_logs);
6363
while (log != nullptr) {
6464
log->print_log_on(out, max);
6565
log = log->next();
@@ -68,7 +68,7 @@ void Events::print_all(outputStream* out, int max) {
6868

6969
// Print a single event log specified by name.
7070
void Events::print_one(outputStream* out, const char* log_name, int max) {
71-
EventLog* log = _logs;
71+
EventLog* log = Atomic::load(&Events::_logs);
7272
int num_printed = 0;
7373
while (log != nullptr) {
7474
if (log->matches_name_or_handle(log_name)) {
@@ -81,7 +81,7 @@ void Events::print_one(outputStream* out, const char* log_name, int max) {
8181
if (num_printed == 0) {
8282
out->print_cr("The name \"%s\" did not match any known event log. "
8383
"Valid event log names are:", log_name);
84-
EventLog* log = _logs;
84+
EventLog* log = Atomic::load(&Events::_logs);
8585
while (log != nullptr) {
8686
log->print_names(out);
8787
out->cr();
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2025, 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+
25+
/*
26+
* @test
27+
* @bug 8355627
28+
* @summary Test that events are listed in the hs_err_pid file
29+
* @library /test/lib
30+
* @requires vm.flagless
31+
* @requires vm.debug == true & (os.family == "linux" | os.family == "windows")
32+
* @modules java.base/jdk.internal.misc
33+
* @run driver ShowEventsOnCrashTest
34+
*/
35+
36+
// Note: this test can only run on debug since it relies on VMError::controlled_crash() which
37+
// only exists in debug builds.
38+
import java.io.File;
39+
import java.util.regex.Pattern;
40+
41+
import jdk.test.lib.process.OutputAnalyzer;
42+
import jdk.test.lib.process.ProcessTools;
43+
44+
public class ShowEventsOnCrashTest {
45+
46+
public static void main(String[] args) throws Exception {
47+
48+
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
49+
"-XX:+UnlockDiagnosticVMOptions", "-Xmx100M", "-XX:-CreateCoredumpOnCrash",
50+
"-XX:ErrorHandlerTest=2",
51+
"-version");
52+
53+
OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());
54+
55+
// we should have crashed with an internal error. We should definitely NOT have crashed with a segfault
56+
// (which would be a sign that the assert poison page mechanism does not work).
57+
output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");
58+
output_detail.shouldMatch("# +Internal Error.*");
59+
File hs_err_file = HsErrFileUtils.openHsErrFileFromOutput(output_detail);
60+
// Pattern match the hs_err_pid file.
61+
Pattern[] patterns = new Pattern[] {
62+
Pattern.compile("Compilation events \\([0-9]* events\\):"),
63+
Pattern.compile("GC Heap History \\([0-9]* events\\):"),
64+
Pattern.compile("Dll operation events \\([0-9]* events\\):"),
65+
Pattern.compile("Deoptimization events \\([0-9]* events\\):"),
66+
Pattern.compile("Classes loaded \\([0-9]* events\\):"),
67+
Pattern.compile("Classes unloaded \\([0-9]* events\\):"),
68+
Pattern.compile("Classes redefined \\([0-9]* events\\):"),
69+
Pattern.compile("Internal exceptions \\([0-9]* events\\):"),
70+
Pattern.compile("VM Operations \\([0-9]* events\\):"),
71+
Pattern.compile("Memory protections \\([0-9]* events\\):")
72+
};
73+
74+
HsErrFileUtils.checkHsErrFileContent(hs_err_file, patterns, false);
75+
76+
}
77+
}
78+

0 commit comments

Comments
 (0)