Skip to content

Commit 3c47cab

Browse files
author
Hamlin Li
committedMay 12, 2021
8261034: improve jcmd GC.class_histogram to support parallel
Reviewed-by: cjplummer, sspitsyn
1 parent ed32e02 commit 3c47cab

File tree

4 files changed

+56
-49
lines changed

4 files changed

+56
-49
lines changed
 

‎src/hotspot/share/services/diagnosticCommand.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -496,13 +496,30 @@ void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {
496496
ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
497497
DCmdWithParser(output, heap),
498498
_all("-all", "Inspect all objects, including unreachable objects",
499-
"BOOLEAN", false, "false") {
499+
"BOOLEAN", false, "false"),
500+
_parallel_thread_num("-parallel",
501+
"Number of parallel threads to use for heap inspection. "
502+
"0 (the default) means let the VM determine the number of threads to use. "
503+
"1 means use one thread (disable parallelism). "
504+
"For any other value the VM will try to use the specified number of "
505+
"threads, but might use fewer.",
506+
"INT", false, "0") {
500507
_dcmdparser.add_dcmd_option(&_all);
508+
_dcmdparser.add_dcmd_option(&_parallel_thread_num);
501509
}
502510

503511
void ClassHistogramDCmd::execute(DCmdSource source, TRAPS) {
512+
jlong num = _parallel_thread_num.value();
513+
if (num < 0) {
514+
output()->print_cr("Parallel thread number out of range (>=0): " JLONG_FORMAT, num);
515+
return;
516+
}
517+
uint parallel_thread_num = num == 0
518+
? MAX2<uint>(1, (uint)os::initial_active_processor_count() * 3 / 8)
519+
: num;
504520
VM_GC_HeapInspection heapop(output(),
505-
!_all.value() /* request full gc if false */);
521+
!_all.value(), /* request full gc if false */
522+
parallel_thread_num);
506523
VMThread::execute(&heapop);
507524
}
508525

‎src/hotspot/share/services/diagnosticCommand.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ class HeapDumpDCmd : public DCmdWithParser {
339339
class ClassHistogramDCmd : public DCmdWithParser {
340340
protected:
341341
DCmdArgument<bool> _all;
342+
DCmdArgument<jlong> _parallel_thread_num;
342343
public:
343344
ClassHistogramDCmd(outputStream* output, bool heap);
344345
static const char* name() {

‎test/hotspot/jtreg/serviceability/dcmd/gc/ClassHistogramAllTest.java

-41
This file was deleted.

‎test/hotspot/jtreg/serviceability/dcmd/gc/ClassHistogramTest.java

+36-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, 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
@@ -21,6 +21,7 @@
2121
* questions.
2222
*/
2323

24+
import org.testng.annotations.DataProvider;
2425
import org.testng.annotations.Test;
2526

2627
import java.util.regex.Pattern;
@@ -42,16 +43,19 @@
4243
public class ClassHistogramTest {
4344
public static class TestClass {}
4445
public static TestClass[] instances = new TestClass[1024];
45-
protected String classHistogramArgs = "";
4646

4747
static {
4848
for (int i = 0; i < instances.length; ++i) {
4949
instances[i] = new TestClass();
5050
}
5151
}
5252

53-
public void run(CommandExecutor executor) {
53+
public void run(CommandExecutor executor, String classHistogramArgs, String expactedErrMsg) {
5454
OutputAnalyzer output = executor.execute("GC.class_histogram " + classHistogramArgs);
55+
if (!expactedErrMsg.isEmpty()) {
56+
output.shouldMatch(expactedErrMsg);
57+
return;
58+
}
5559

5660
/*
5761
* example output:
@@ -87,8 +91,34 @@ public void run(CommandExecutor executor) {
8791
Pattern.quote(TestClass.class.getName()) + "\\s*$");
8892
}
8993

90-
@Test
91-
public void jmx() {
92-
run(new JMXExecutor());
94+
@DataProvider(name="ArgsProvider")
95+
private Object[][] getArgs() {
96+
String parallelErr = "Parallel thread number out of range";
97+
return new Object[][] {
98+
// valid args
99+
{"", ""},
100+
{"-parallel=0", ""},
101+
{"-parallel=1", ""},
102+
{"-parallel=2", ""},
103+
{"-parallel="+Long.MAX_VALUE, ""},
104+
{"-all=false -parallel=0", ""},
105+
{"-all=false -parallel=1", ""},
106+
{"-all=false -parallel=2", ""},
107+
{"-all=true", ""},
108+
{"-all=true -parallel=0", ""},
109+
{"-all=true -parallel=1", ""},
110+
{"-all=true -parallel=2", ""},
111+
{"-parallel=2 -all=true", ""},
112+
// invalid args
113+
{"-parallel=-1", parallelErr},
114+
{"-parallel="+Long.MIN_VALUE, parallelErr},
115+
{"-all=false -parallel=-10", parallelErr},
116+
{"-all=true -parallel=-100", parallelErr},
117+
};
118+
}
119+
120+
@Test(dataProvider="ArgsProvider")
121+
public void jmx(String args, String expactedErrMsg) {
122+
run(new JMXExecutor(), args, expactedErrMsg);
93123
}
94124
}

0 commit comments

Comments
 (0)