mirror of
https://github.com/openjdk/jdk.git
synced 2026-08-02 06:06:44 +00:00
8261034: improve jcmd GC.class_histogram to support parallel
Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
parent
ed32e02c05
commit
3c47cab6db
@ -496,13 +496,30 @@ void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {
|
||||
ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
|
||||
DCmdWithParser(output, heap),
|
||||
_all("-all", "Inspect all objects, including unreachable objects",
|
||||
"BOOLEAN", false, "false") {
|
||||
"BOOLEAN", false, "false"),
|
||||
_parallel_thread_num("-parallel",
|
||||
"Number of parallel threads to use for heap inspection. "
|
||||
"0 (the default) means let the VM determine the number of threads to use. "
|
||||
"1 means use one thread (disable parallelism). "
|
||||
"For any other value the VM will try to use the specified number of "
|
||||
"threads, but might use fewer.",
|
||||
"INT", false, "0") {
|
||||
_dcmdparser.add_dcmd_option(&_all);
|
||||
_dcmdparser.add_dcmd_option(&_parallel_thread_num);
|
||||
}
|
||||
|
||||
void ClassHistogramDCmd::execute(DCmdSource source, TRAPS) {
|
||||
jlong num = _parallel_thread_num.value();
|
||||
if (num < 0) {
|
||||
output()->print_cr("Parallel thread number out of range (>=0): " JLONG_FORMAT, num);
|
||||
return;
|
||||
}
|
||||
uint parallel_thread_num = num == 0
|
||||
? MAX2<uint>(1, (uint)os::initial_active_processor_count() * 3 / 8)
|
||||
: num;
|
||||
VM_GC_HeapInspection heapop(output(),
|
||||
!_all.value() /* request full gc if false */);
|
||||
!_all.value(), /* request full gc if false */
|
||||
parallel_thread_num);
|
||||
VMThread::execute(&heapop);
|
||||
}
|
||||
|
||||
|
||||
@ -339,6 +339,7 @@ public:
|
||||
class ClassHistogramDCmd : public DCmdWithParser {
|
||||
protected:
|
||||
DCmdArgument<bool> _all;
|
||||
DCmdArgument<jlong> _parallel_thread_num;
|
||||
public:
|
||||
ClassHistogramDCmd(outputStream* output, bool heap);
|
||||
static const char* name() {
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Test of diagnostic command GC.class_histogram -all=true
|
||||
* @library /test/lib
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* java.compiler
|
||||
* java.management
|
||||
* jdk.internal.jvmstat/sun.jvmstat.monitor
|
||||
* @run testng ClassHistogramAllTest
|
||||
*/
|
||||
public class ClassHistogramAllTest extends ClassHistogramTest {
|
||||
public ClassHistogramAllTest() {
|
||||
super();
|
||||
classHistogramArgs = "-all=true";
|
||||
}
|
||||
|
||||
/* See ClassHistogramTest for test cases */
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -21,6 +21,7 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
@ -42,7 +43,6 @@ import jdk.test.lib.dcmd.JMXExecutor;
|
||||
public class ClassHistogramTest {
|
||||
public static class TestClass {}
|
||||
public static TestClass[] instances = new TestClass[1024];
|
||||
protected String classHistogramArgs = "";
|
||||
|
||||
static {
|
||||
for (int i = 0; i < instances.length; ++i) {
|
||||
@ -50,8 +50,12 @@ public class ClassHistogramTest {
|
||||
}
|
||||
}
|
||||
|
||||
public void run(CommandExecutor executor) {
|
||||
public void run(CommandExecutor executor, String classHistogramArgs, String expactedErrMsg) {
|
||||
OutputAnalyzer output = executor.execute("GC.class_histogram " + classHistogramArgs);
|
||||
if (!expactedErrMsg.isEmpty()) {
|
||||
output.shouldMatch(expactedErrMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* example output:
|
||||
@ -87,8 +91,34 @@ public class ClassHistogramTest {
|
||||
Pattern.quote(TestClass.class.getName()) + "\\s*$");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jmx() {
|
||||
run(new JMXExecutor());
|
||||
@DataProvider(name="ArgsProvider")
|
||||
private Object[][] getArgs() {
|
||||
String parallelErr = "Parallel thread number out of range";
|
||||
return new Object[][] {
|
||||
// valid args
|
||||
{"", ""},
|
||||
{"-parallel=0", ""},
|
||||
{"-parallel=1", ""},
|
||||
{"-parallel=2", ""},
|
||||
{"-parallel="+Long.MAX_VALUE, ""},
|
||||
{"-all=false -parallel=0", ""},
|
||||
{"-all=false -parallel=1", ""},
|
||||
{"-all=false -parallel=2", ""},
|
||||
{"-all=true", ""},
|
||||
{"-all=true -parallel=0", ""},
|
||||
{"-all=true -parallel=1", ""},
|
||||
{"-all=true -parallel=2", ""},
|
||||
{"-parallel=2 -all=true", ""},
|
||||
// invalid args
|
||||
{"-parallel=-1", parallelErr},
|
||||
{"-parallel="+Long.MIN_VALUE, parallelErr},
|
||||
{"-all=false -parallel=-10", parallelErr},
|
||||
{"-all=true -parallel=-100", parallelErr},
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider="ArgsProvider")
|
||||
public void jmx(String args, String expactedErrMsg) {
|
||||
run(new JMXExecutor(), args, expactedErrMsg);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user