Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8261482: Adjust jmap histo command to accept noparallel option to inspect heap serially #2519

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -628,6 +628,7 @@ void HeapInspection::heap_inspection(outputStream* st, uint parallel_thread_num)

histo.sort();
histo.print_histo_on(st);
st->print_cr("Create histogram with %u threads", parallel_thread_num);
} else {
st->print_cr("ERROR: Ran out of C-heap; histogram not generated");
}
@@ -261,7 +261,7 @@ jint dump_heap(AttachOperation* op, outputStream* out) {
// Input arguments :-
// arg0: "-live" or "-all"
// arg1: Name of the dump file or NULL
// arg2: parallel thread number
// arg2: Parallel "true" or "false"
static jint heap_inspection(AttachOperation* op, outputStream* out) {
bool live_objects_only = true; // default is true to retain the behavior before this change is made
outputStream* os = out; // if path not specified or path is NULL, use out
@@ -286,14 +286,9 @@ static jint heap_inspection(AttachOperation* op, outputStream* out) {
os = fs;
}

const char* num_str = op->arg(2);
if (num_str != NULL && num_str[0] != '\0') {
uintx num;
if (!Arguments::parse_uintx(num_str, &num, 0)) {
out->print_cr("Invalid parallel thread number: [%s]", num_str);
return JNI_ERR;
}
parallel_thread_num = num == 0 ? parallel_thread_num : (uint)num;
const char* parallel = op->arg(2);
if (strcmp(parallel, "false") == 0) {
parallel_thread_num = 1;
}

VM_GC_HeapInspection heapop(os, live_objects_only /* request full gc */, parallel_thread_num);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
@@ -169,7 +169,7 @@ private static void histo(String pid, String options)
UnsupportedEncodingException {
String liveopt = "-all";
String filename = null;
String parallel = null;
Boolean parallel = true;
String subopts[] = options.split(",");

for (int i = 0; i < subopts.length; i++) {
@@ -184,12 +184,8 @@ private static void histo(String pid, String options)
System.err.println("Fail: invalid option or no file name '" + subopt + "'");
usage(1);
}
} else if (subopt.startsWith("parallel=")) {
parallel = subopt.substring("parallel=".length());
if (parallel == null) {
System.err.println("Fail: no number provided in option: '" + subopt + "'");
usage(1);
}
} else if (subopt.equals("noparallel")) {
parallel = false;
} else {
System.err.println("Fail: invalid option: '" + subopt + "'");
usage(1);
@@ -199,7 +195,7 @@ private static void histo(String pid, String options)
System.out.flush();

// inspectHeap is not the same as jcmd GC.class_histogram
executeCommandForPid(pid, "inspectheap", liveopt, filename, parallel);
executeCommandForPid(pid, "inspectheap", liveopt, filename, Boolean.toString(parallel));
}

private static void dump(String pid, String options)
@@ -319,10 +315,7 @@ private static void usage(int exit) {
System.err.println(" live count only live objects (takes precedence if both \"live\" and \"all\" are specified)");
System.err.println(" all count all objects in the heap (default if one of \"live\" or \"all\" is not specified)");
System.err.println(" file=<file> dump data to <file>");
System.err.println(" parallel=<number> parallel threads number for heap iteration:");
System.err.println(" parallel=0 default behavior, use predefined number of threads");
System.err.println(" parallel=1 disable parallel heap iteration");
System.err.println(" parallel=<N> use N threads for parallel heap iteration");
System.err.println(" noparallel If specified, the heap is inspected serially.");
System.err.println("");
System.err.println(" Example: jmap -histo:live,file=/tmp/histo.data <pid>");
System.exit(exit);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
@@ -109,9 +109,11 @@ public static void main(String[] args) throws Exception {
testHisto();
testHistoLive();
testHistoAll();
testHistoNonParallel();
testHistoToFile();
testHistoLiveToFile();
testHistoAllToFile();
testHistoToFileNonParallel();
testFinalizerInfo();
testClstats();
testDump();
@@ -137,47 +139,38 @@ private static void testHistoAll() throws Exception {
output.shouldHaveExitValue(0);
}

private static void testHistoParallelZero() throws Exception {
OutputAnalyzer output = jmap("-histo:parallel=0");
output.shouldHaveExitValue(0);
}

private static void testHistoParallel() throws Exception {
OutputAnalyzer output = jmap("-histo:parallel=2");
output.shouldHaveExitValue(0);
}

private static void testHistoNonParallel() throws Exception {
OutputAnalyzer output = jmap("-histo:parallel=1");
OutputAnalyzer output = jmap("-histo:noparallel");
output.shouldHaveExitValue(0);
}

private static void testHistoToFile() throws Exception {
histoToFile(false, false, 1);
histoToFile(false, false);
}

private static void testHistoLiveToFile() throws Exception {
histoToFile(true, false, 1);
histoToFile(true, false);
}

private static void testHistoAllToFile() throws Exception {
histoToFile(false, true, 1);
histoToFile(false, true);
}

private static void testHistoFileParallelZero() throws Exception {
histoToFile(false, false, 0);
private static void testHistoToFileNonParallel() throws Exception {
histoToFile(false, false, true);
}

private static void testHistoFileParallel() throws Exception {
histoToFile(false, false, 2);
private static void histoToFile(boolean live,
boolean explicitAll) throws Exception {
histoToFile(live, explicitAll, false);
}

private static void histoToFile(boolean live,
boolean explicitAll,
int parallelThreadNum) throws Exception {
boolean noParallel) throws Exception {
String liveArg = "";
String fileArg = "";
String parArg = "parallel=" + parallelThreadNum;
String parArg = "";
String allArgs = "-histo:";

if (live && explicitAll) {
@@ -189,6 +182,9 @@ private static void histoToFile(boolean live,
if (explicitAll) {
liveArg = "all,";
}
if (noParallel) {
parArg="noparallel";
}

File file = new File("jmap.histo.file" + System.currentTimeMillis() + ".histo");
if (file.exists()) {
ProTip! Use n and p to navigate between commits in a pull request.