Skip to content
Permalink
Browse files
8242009: Review setting test.java/vm.opts in jcmd/jhsdb and debugger …
…in serviceability tests

Reviewed-by: cjplummer
  • Loading branch information
Daniil Titov committed May 12, 2020
1 parent e686fb6 commit a726aca6de59f038bd1a10ab07f585ee5962de4c
Showing 36 changed files with 161 additions and 109 deletions.
@@ -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
@@ -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;
@@ -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");

@@ -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
@@ -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;
@@ -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");

@@ -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 {
@@ -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;
@@ -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");
@@ -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;

/**
@@ -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());
@@ -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;
@@ -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()));
@@ -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"));
@@ -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;
@@ -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));
@@ -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"));
@@ -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;
@@ -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) {
@@ -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;
@@ -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");
@@ -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) {
@@ -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;
@@ -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");
@@ -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;

@@ -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()));
@@ -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 {
@@ -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");
@@ -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
@@ -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);
@@ -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;
@@ -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++;
}
}
@@ -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");
@@ -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()));

@@ -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;
@@ -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");

0 comments on commit a726aca

Please sign in to comment.