Skip to content

Commit bf79406

Browse files
Merge in jdk-23+37 (24.1)
PullRequest: labsjdk-ce/106
2 parents 302d323 + cf965e7 commit bf79406

File tree

6 files changed

+200
-6
lines changed

6 files changed

+200
-6
lines changed

src/hotspot/share/services/classLoadingService.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -128,6 +128,22 @@ bool ClassLoadingService::set_verbose(bool verbose) {
128128
return verbose;
129129
}
130130

131+
bool ClassLoadingService::get_verbose() {
132+
for (LogTagSet* ts = LogTagSet::first(); ts != nullptr; ts = ts->next()) {
133+
// set_verbose looks for a non-exact match for class+load,
134+
// so look for all tag sets that match class+load*
135+
if (ts->contains(LogTag::_class) &&
136+
ts->contains(LogTag::_load)) {
137+
LogLevelType l = ts->level_for(LogConfiguration::StdoutLog);
138+
if (l != LogLevel::Info && l != LogLevel::Debug && l != LogLevel::Trace) {
139+
return false;
140+
}
141+
}
142+
}
143+
144+
return true;
145+
}
146+
131147
// Caller to this function must own Management_lock
132148
void ClassLoadingService::reset_trace_class_unloading() {
133149
assert(Management_lock->owned_by_self(), "Must own the Management_lock");

src/hotspot/share/services/classLoadingService.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -53,6 +53,7 @@ class ClassLoadingService : public AllStatic {
5353
public:
5454
static void init() NOT_MANAGEMENT_RETURN;
5555
static bool set_verbose(bool verbose) NOT_MANAGEMENT_RETURN_(false);
56+
static bool get_verbose() NOT_MANAGEMENT_RETURN_(false);
5657
static void reset_trace_class_unloading() NOT_MANAGEMENT_RETURN;
5758
static jlong loaded_class_count() NOT_MANAGEMENT_RETURN_(0L);
5859
static jlong unloaded_class_count() NOT_MANAGEMENT_RETURN_(0L);
@@ -63,7 +64,6 @@ class ClassLoadingService : public AllStatic {
6364
static jlong loaded_shared_class_bytes() NOT_MANAGEMENT_RETURN_(0L);
6465
static jlong unloaded_shared_class_bytes() NOT_MANAGEMENT_RETURN_(0L);
6566
static jlong class_method_data_size() NOT_MANAGEMENT_RETURN_(0L);
66-
static bool get_verbose() { return log_is_enabled(Info, class, load); }
6767

6868
static void notify_class_loaded(InstanceKlass* k, bool shared_class)
6969
NOT_MANAGEMENT_RETURN;

src/hotspot/share/services/memoryService.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -202,6 +202,21 @@ bool MemoryService::set_verbose(bool verbose) {
202202
return verbose;
203203
}
204204

205+
bool MemoryService::get_verbose() {
206+
for (LogTagSet* ts = LogTagSet::first(); ts != nullptr; ts = ts->next()) {
207+
// set_verbose only sets gc and not gc*, so check for an exact match
208+
const bool is_gc_exact_match = ts->contains(LogTag::_gc) && ts->ntags() == 1;
209+
if (is_gc_exact_match) {
210+
LogLevelType l = ts->level_for(LogConfiguration::StdoutLog);
211+
if (l == LogLevel::Info || l == LogLevel::Debug || l == LogLevel::Trace) {
212+
return true;
213+
}
214+
}
215+
}
216+
217+
return false;
218+
}
219+
205220
Handle MemoryService::create_MemoryUsage_obj(MemoryUsage usage, TRAPS) {
206221
InstanceKlass* ik = Management::java_lang_management_MemoryUsage_klass(CHECK_NH);
207222

src/hotspot/share/services/memoryService.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -106,8 +106,8 @@ class MemoryService : public AllStatic {
106106
GCCause::Cause cause,
107107
bool allMemoryPoolsAffected, const char* notificationMessage = nullptr);
108108

109-
static bool get_verbose() { return log_is_enabled(Info, gc); }
110109
static bool set_verbose(bool verbose);
110+
static bool get_verbose();
111111

112112
// Create an instance of java/lang/management/MemoryUsage
113113
static Handle create_MemoryUsage_obj(MemoryUsage usage, TRAPS);
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2024, 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+
* @test
26+
* @bug 8338139
27+
* @summary Basic unit test of ClassLoadingMXBean.set/isVerbose() when
28+
* related unified logging is enabled.
29+
*
30+
* @run main/othervm -Xlog:class+load=trace:file=vm.log TestVerboseClassLoading false
31+
* @run main/othervm -Xlog:class+load=debug:file=vm.log TestVerboseClassLoading false
32+
* @run main/othervm -Xlog:class+load=info:file=vm.log TestVerboseClassLoading false
33+
*
34+
* @run main/othervm -Xlog:class+load=trace TestVerboseClassLoading false
35+
* @run main/othervm -Xlog:class+load=debug TestVerboseClassLoading false
36+
* @run main/othervm -Xlog:class+load=info TestVerboseClassLoading false
37+
* @run main/othervm -Xlog:class+load=warning TestVerboseClassLoading false
38+
* @run main/othervm -Xlog:class+load=error TestVerboseClassLoading false
39+
* @run main/othervm -Xlog:class+load=off TestVerboseClassLoading false
40+
*
41+
* @run main/othervm -Xlog:class+load*=trace TestVerboseClassLoading true
42+
* @run main/othervm -Xlog:class+load*=debug TestVerboseClassLoading true
43+
* @run main/othervm -Xlog:class+load*=info TestVerboseClassLoading true
44+
* @run main/othervm -Xlog:class+load*=warning TestVerboseClassLoading false
45+
* @run main/othervm -Xlog:class+load*=error TestVerboseClassLoading false
46+
* @run main/othervm -Xlog:class+load*=off TestVerboseClassLoading false
47+
*
48+
* @run main/othervm -Xlog:class+load*=info,class+load+cause=trace TestVerboseClassLoading true
49+
* @run main/othervm -Xlog:class+load*=info,class+load+cause=debug TestVerboseClassLoading true
50+
* @run main/othervm -Xlog:class+load*=info,class+load+cause=info TestVerboseClassLoading true
51+
* @run main/othervm -Xlog:class+load*=info,class+load+cause=warning TestVerboseClassLoading false
52+
* @run main/othervm -Xlog:class+load*=info,class+load+cause=error TestVerboseClassLoading false
53+
* @run main/othervm -Xlog:class+load*=info,class+load+cause=off TestVerboseClassLoading false
54+
*
55+
* @run main/othervm -Xlog:all=trace:file=vm.log TestVerboseClassLoading false
56+
*/
57+
58+
import java.lang.management.ManagementFactory;
59+
import java.lang.management.ClassLoadingMXBean;
60+
61+
public class TestVerboseClassLoading {
62+
63+
public static void main(String[] args) throws Exception {
64+
ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();
65+
boolean expected = Boolean.parseBoolean(args[0]);
66+
boolean initial = mxBean.isVerbose();
67+
if (expected != initial) {
68+
throw new Error("Initial verbosity setting was unexpectedly " + initial);
69+
}
70+
mxBean.setVerbose(false);
71+
if (mxBean.isVerbose()) {
72+
throw new Error("Verbosity was still enabled");
73+
}
74+
mxBean.setVerbose(true);
75+
if (!mxBean.isVerbose()) {
76+
throw new Error("Verbosity was still disabled");
77+
}
78+
// Turn off again as a double-check and also to avoid excessive logging
79+
mxBean.setVerbose(false);
80+
if (mxBean.isVerbose()) {
81+
throw new Error("Verbosity was still enabled");
82+
}
83+
}
84+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2024, 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+
* @test
26+
* @bug 8338139
27+
* @summary Basic unit test of TestVerboseMemory.set/isVerbose() when
28+
* related unified logging is enabled.
29+
*
30+
* @run main/othervm -Xlog:gc=trace:file=vm.log TestVerboseMemory false
31+
* @run main/othervm -Xlog:gc=debug:file=vm.log TestVerboseMemory false
32+
* @run main/othervm -Xlog:gc=info:file=vm.log TestVerboseMemory false
33+
*
34+
* @run main/othervm -Xlog:gc=off TestVerboseMemory false
35+
* @run main/othervm -Xlog:gc=error TestVerboseMemory false
36+
* @run main/othervm -Xlog:gc=warning TestVerboseMemory false
37+
*
38+
* @run main/othervm -Xlog:gc=info TestVerboseMemory true
39+
* @run main/othervm -Xlog:gc=trace TestVerboseMemory true
40+
* @run main/othervm -Xlog:gc=debug TestVerboseMemory true
41+
*
42+
* @run main/othervm -Xlog:gc*=info TestVerboseMemory true
43+
* @run main/othervm -Xlog:gc*=debug TestVerboseMemory true
44+
* @run main/othervm -Xlog:gc*=trace TestVerboseMemory true
45+
*
46+
* @run main/othervm -Xlog:gc=info,gc+init=off TestVerboseMemory true
47+
* @run main/othervm -Xlog:gc=off,gc+init=info TestVerboseMemory false
48+
* @run main/othervm -Xlog:gc,gc+init TestVerboseMemory true
49+
*
50+
* @run main/othervm -Xlog:all=trace:file=vm.log TestVerboseMemory false
51+
*/
52+
53+
import java.lang.management.ManagementFactory;
54+
import java.lang.management.MemoryMXBean;
55+
56+
public class TestVerboseMemory {
57+
58+
public static void main(String[] args) throws Exception {
59+
MemoryMXBean mxBean = ManagementFactory.getMemoryMXBean();
60+
boolean expected = Boolean.parseBoolean(args[0]);
61+
boolean initial = mxBean.isVerbose();
62+
if (expected != initial) {
63+
throw new Error("Initial verbosity setting was unexpectedly " + initial);
64+
}
65+
mxBean.setVerbose(false);
66+
if (mxBean.isVerbose()) {
67+
throw new Error("Verbosity was still enabled");
68+
}
69+
mxBean.setVerbose(true);
70+
if (!mxBean.isVerbose()) {
71+
throw new Error("Verbosity was still disabled");
72+
}
73+
// Turn off again as a double-check and also to avoid excessive logging
74+
mxBean.setVerbose(false);
75+
if (mxBean.isVerbose()) {
76+
throw new Error("Verbosity was still enabled");
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)