Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
8242009: Review setting test.java/vm.opts in jcmd/jhsdb and debugger …
Browse files Browse the repository at this point in the history
…in serviceability tests

Reviewed-by: cjplummer
  • Loading branch information
Daniil Titov committed May 12, 2020
1 parent e686fb6 commit a726aca
Show file tree
Hide file tree
Showing 36 changed files with 161 additions and 109 deletions.
4 changes: 3 additions & 1 deletion test/hotspot/jtreg/serviceability/attach/ConcAttachTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
Expand Down Expand Up @@ -39,6 +39,7 @@
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.AttachNotSupportedException;

import jdk.test.lib.Utils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Asserts;
import jdk.test.lib.JDKToolLauncher;
Expand Down Expand Up @@ -80,6 +81,7 @@ public void run() {

private static void checkAttachListenerThread() throws InterruptedException, IOException {
JDKToolLauncher jcmd = JDKToolLauncher.createUsingTestJDK("jcmd");
jcmd.addVMArgs(Utils.getTestJavaOpts());
jcmd.addToolArg(strPID);
jcmd.addToolArg("Thread.print");

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
Expand Down Expand Up @@ -32,6 +32,7 @@
import java.io.IOException;
import java.nio.file.Path;

import jdk.test.lib.Utils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.process.OutputAnalyzer;
Expand All @@ -40,6 +41,7 @@ public class RemovingUnixDomainSocketTest {

private static void runJCmd(long pid) throws InterruptedException, IOException {
JDKToolLauncher jcmd = JDKToolLauncher.createUsingTestJDK("jcmd");
jcmd.addVMArgs(Utils.getTestJavaOpts());
jcmd.addToolArg(Long.toString(pid));
jcmd.addToolArg("VM.version");

Expand All @@ -53,7 +55,7 @@ private static void runJCmd(long pid) throws InterruptedException, IOException {
System.out.println(out.getStdout());
System.err.println(out.getStderr());

out.stderrShouldBeEmpty();
out.stderrShouldBeEmptyIgnoreVMWarnings();
}

public static void main(String... args) throws Exception {
Expand Down
5 changes: 3 additions & 2 deletions test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java
Expand Up @@ -30,9 +30,9 @@
* @run main/othervm/timeout=2400 CDSJMapClstats
*/

import java.util.List;
import java.util.Arrays;
import java.util.stream.Collectors;

import jdk.test.lib.Utils;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.cds.CDSOptions;
import jdk.test.lib.apps.LingeredApp;
Expand All @@ -46,6 +46,7 @@ public class CDSJMapClstats {
private static void runClstats(long lingeredAppPid) throws Exception {

JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jmap");
launcher.addToolArg("--clstats");
launcher.addToolArg("--pid");
Expand Down
4 changes: 2 additions & 2 deletions test/hotspot/jtreg/serviceability/sa/ClhsdbDumpclass.java
Expand Up @@ -27,11 +27,10 @@
import java.util.List;
import java.util.Map;

import jdk.test.lib.Utils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.SA.SATestUtils;
import jtreg.SkippedException;

/**
Expand Down Expand Up @@ -70,6 +69,7 @@ public static void main(String[] args) throws Exception {

// Run javap on the generated class file to make sure it's valid.
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("javap");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg(APP_DOT_CLASSNAME);
System.out.println("> javap " + APP_DOT_CLASSNAME);
List<String> cmdStringList = Arrays.asList(launcher.getCommand());
Expand Down
Expand Up @@ -22,11 +22,8 @@
* questions.
*/

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import jdk.test.lib.JDKToolLauncher;
Expand Down Expand Up @@ -61,6 +58,7 @@ private static void runJstackInLoop(LingeredApp app) throws Exception {
for (int i = 0; i < MAX_ITERATIONS; i++) {
JDKToolLauncher launcher = JDKToolLauncher
.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
launcher.addToolArg("jstack");
launcher.addToolArg("--pid");
launcher.addToolArg(Long.toString(app.getPid()));
Expand All @@ -76,7 +74,7 @@ private static void runJstackInLoop(LingeredApp app) throws Exception {
System.err.println(out.getStderr());
}

out.stderrShouldBeEmpty(); // NPE's are reported on the err stream
out.stderrShouldBeEmptyIgnoreVMWarnings();
out.stdoutShouldNotContain("Error occurred during stack walking:");
out.stdoutShouldContain(LingeredAppWithRecComputation.THREAD_NAME);
List<String> stdoutList = Arrays.asList(out.getStdout().split("\\R"));
Expand Down
6 changes: 3 additions & 3 deletions test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java
Expand Up @@ -25,10 +25,8 @@
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.Arrays;

import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.OutputAnalyzer;
Expand Down Expand Up @@ -56,6 +54,7 @@ public ClhsdbLauncher() {
private void attach(long lingeredAppPid)
throws IOException {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("clhsdb");
if (lingeredAppPid != -1) {
launcher.addToolArg("--pid=" + Long.toString(lingeredAppPid));
Expand All @@ -75,6 +74,7 @@ private void loadCore(String coreFileName)
throws IOException {

JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("clhsdb");
launcher.addToolArg("--core=" + coreFileName);
launcher.addToolArg("--exe=" + JDKToolFinder.getTestJDKTool("java"));
Expand Down
Expand Up @@ -31,8 +31,6 @@
* @run main DeadlockDetectionTest
*/

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import jdk.test.lib.apps.LingeredApp;
Expand All @@ -51,6 +49,7 @@ public class DeadlockDetectionTest {

private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jstack");
if (toolArgs != null) {
for (String toolArg : toolArgs) {
Expand Down
19 changes: 2 additions & 17 deletions test/hotspot/jtreg/serviceability/sa/JhsdbThreadInfoTest.java
Expand Up @@ -21,14 +21,8 @@
* questions.
*/

import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.SA.SATestUtils;
import jdk.test.lib.Utils;
Expand All @@ -50,6 +44,7 @@ public static void main(String[] args) throws Exception {
System.out.println("Started LingeredApp with pid " + app.getPid());

JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
jhsdbLauncher.addVMArgs(Utils.getTestJavaOpts());

jhsdbLauncher.addToolArg("jstack");
jhsdbLauncher.addToolArg("--pid");
Expand All @@ -73,17 +68,7 @@ public static void main(String[] args) throws Exception {
out.shouldNotContain(" prio=0 ");
out.shouldNotContain(" java.lang.Thread.State: UNKNOWN");

// stderr should be empty except for VM warnings.
if (!out.getStderr().isEmpty()) {
List<String> lines = Arrays.asList(out.getStderr().split("(\\r\\n|\\n|\\r)"));
Pattern p = Pattern.compile(".*VM warning.*");
for (String line : lines) {
Matcher m = p.matcher(line);
if (!m.matches()) {
throw new RuntimeException("Stderr has output other than VM warnings");
}
}
}
out.stderrShouldBeEmptyIgnoreVMWarnings();

System.out.println("Test Completed");
} catch (Exception ex) {
Expand Down
Expand Up @@ -21,28 +21,20 @@
* questions.
*/

import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.nio.file.Files;
import java.io.IOException;
import java.io.BufferedInputStream;
import java.util.stream.Collectors;
import java.io.FileInputStream;

import sun.jvm.hotspot.HotSpotAgent;
import sun.jvm.hotspot.debugger.*;

import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Asserts;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.Platform;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.SA.SATestUtils;
import jdk.test.lib.Utils;
import jdk.test.lib.hprof.HprofParser;
import jdk.test.lib.hprof.parser.HprofReader;
import jdk.test.lib.hprof.parser.PositionDataInputStream;
import jdk.test.lib.hprof.model.Snapshot;
Expand Down Expand Up @@ -91,6 +83,7 @@ private static void attachDumpAndVerify(String heapDumpFileName,
long lingeredAppPid) throws Exception {

JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jmap");
launcher.addToolArg("--binaryheap");
launcher.addToolArg("--dumpfile");
Expand Down
25 changes: 2 additions & 23 deletions test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackLock.java
Expand Up @@ -21,20 +21,9 @@
* questions.
*/

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.Asserts;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.SA.SATestUtils;
import jdk.test.lib.Utils;

Expand All @@ -57,6 +46,7 @@ public static void main (String... args) throws Exception {
System.out.println ("Started LingeredApp with pid " + app.getPid());

JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jstack");
launcher.addToolArg("--pid");
launcher.addToolArg(Long.toString(app.getPid()));
Expand All @@ -75,18 +65,7 @@ public static void main (String... args) throws Exception {
out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Thread\\)$");
out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for int\\)$");

// stderr should be empty except for VM warnings.
if (!out.getStderr().isEmpty()) {
List<String> lines = Arrays.asList(out.getStderr().split("(\\r\\n|\\n|\\r)"));
Pattern p = Pattern.compile(".*VM warning.*");
for (String line : lines) {
Matcher m = p.matcher(line);
if (!m.matches()) {
throw new RuntimeException("Stderr has output other than VM warnings");
}
}
}

out.stderrShouldBeEmptyIgnoreVMWarnings();

System.out.println("Test Completed");
} finally {
Expand Down
Expand Up @@ -132,6 +132,7 @@ private static void runJstackMixedInLoop(LingeredApp app) throws Exception {
for (int i = 0; i < MAX_ITERATIONS; i++) {
JDKToolLauncher launcher = JDKToolLauncher
.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jstack");
launcher.addToolArg("--mixed");
launcher.addToolArg("--pid");
Expand Down
3 changes: 2 additions & 1 deletion test/hotspot/jtreg/serviceability/sa/TestJmapCore.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, 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
Expand Down Expand Up @@ -120,6 +120,7 @@ static void test(String type) throws Throwable {

File dumpFile = new File("heap.hprof");
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("jmap");
launcher.addToolArg("--binaryheap");
launcher.addToolArg("--dumpfile=" + dumpFile);
Expand Down
8 changes: 6 additions & 2 deletions test/hotspot/jtreg/serviceability/sa/TestSysProps.java
Expand Up @@ -21,10 +21,10 @@
* questions.
*/

import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;

import jdk.test.lib.Utils;
import jdk.test.lib.apps.LingeredApp;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Platform;
Expand Down Expand Up @@ -58,7 +58,9 @@ public static void findProp(String[] propLines, String propname, String cmdName)
public static void countProps(String[] propLines, int expectedCount, String cmdName) {
int numProps = 0;
for (String propLine : propLines) {
if (propLine.indexOf("=") != -1) {
// Ignore the debug output lines (they start with '[' and printed
// in the output when the test is run with -Xlog VM option).
if (!propLine.startsWith("[") && propLine.indexOf("=") != -1) {
numProps++;
}
}
Expand All @@ -79,6 +81,7 @@ public static void main (String... args) throws Exception {
// Get properties using the SA version of jinfo

JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
jhsdbLauncher.addVMArgs(Utils.getTestJavaOpts());
jhsdbLauncher.addToolArg("jinfo");
jhsdbLauncher.addToolArg("--sysprops");
jhsdbLauncher.addToolArg("--pid");
Expand All @@ -99,6 +102,7 @@ public static void main (String... args) throws Exception {
// Get the properties using the Attach API version of jinfo

JDKToolLauncher jinfoLauncher = JDKToolLauncher.createUsingTestJDK("jinfo");
jinfoLauncher.addVMArgs(Utils.getTestJavaOpts());
jinfoLauncher.addToolArg("-sysprops");
jinfoLauncher.addToolArg(Long.toString(app.getPid()));

Expand Down
Expand Up @@ -33,7 +33,7 @@

import jdk.test.lib.Asserts;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.Platform;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.SA.SATestUtils;
Expand Down Expand Up @@ -98,6 +98,7 @@ private static void testHProfFileFormat(String vmArgs, long heapSize,

JDKToolLauncher jMapLauncher = JDKToolLauncher
.createUsingTestJDK("jhsdb");
jMapLauncher.addVMArgs(Utils.getTestJavaOpts());
jMapLauncher.addToolArg("jmap");
jMapLauncher.addToolArg("--binaryheap");
jMapLauncher.addToolArg("--pid");
Expand Down

0 comments on commit a726aca

Please sign in to comment.