8196124: [testbug] runtime/appcds/jigsaw/classpathtests/DummyClassesInBootClassPath.java passes despite of error

Create another archive with whitebox.jar in the -Xbootclasspath/a; check output from TestCommon.execCommon().

Reviewed-by: iklam, mseledtsov
This commit is contained in:
Calvin Cheung 2018-02-01 10:55:27 -08:00
parent aa51ac19b3
commit ea5f35759b
2 changed files with 44 additions and 35 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -45,6 +45,16 @@ import jdk.test.lib.process.OutputAnalyzer;
public class DummyClassesInBootClassPath { public class DummyClassesInBootClassPath {
private static final String METHOD_NAME = "thisClassIsDummy()"; private static final String METHOD_NAME = "thisClassIsDummy()";
static void checkOutput(OutputAnalyzer output, String[] classNames) throws Exception {
for (int i = 0; i < classNames.length; i++) {
String cn = classNames[i].replace('/', '.');
TestCommon.checkExec(output,
"java.lang.NoSuchMethodException: " + cn + "." +
METHOD_NAME);
output.shouldNotContain(cn + ".class should be in shared space.");
}
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String classNames[] = { "java/net/HttpCookie", String classNames[] = { "java/net/HttpCookie",
"javax/activation/MimeType"}; "javax/activation/MimeType"};
@ -52,8 +62,8 @@ public class DummyClassesInBootClassPath {
String appJar = TestCommon.getTestJar("dummyClasses.jar"); String appJar = TestCommon.getTestJar("dummyClasses.jar");
OutputAnalyzer dumpOutput = TestCommon.dump( OutputAnalyzer dumpOutput = TestCommon.dump(
appJar, classNames, "-Xbootclasspath/a:" + appJar); appJar, classNames, "-Xbootclasspath/a:" + appJar,
"--add-modules", "java.activation");
List<String> argsList = new ArrayList<String>(); List<String> argsList = new ArrayList<String>();
for (int i = 0; i < classNames.length; i++) { for (int i = 0; i < classNames.length; i++) {
argsList.add(classNames[i].replace('/', '.')); argsList.add(classNames[i].replace('/', '.'));
@ -61,27 +71,24 @@ public class DummyClassesInBootClassPath {
String[] arguments = new String[argsList.size()]; String[] arguments = new String[argsList.size()];
arguments = argsList.toArray(arguments); arguments = argsList.toArray(arguments);
OutputAnalyzer execOutput = TestCommon.execCommon( OutputAnalyzer execOutput = TestCommon.execCommon(
"-cp", TestCommon.getTestDir("."), "-verbose:class", "--add-modules", "java.activation", "-Xbootclasspath/a:" + appJar,
"--add-modules", "java.activation", "DummyClassHelper", arguments[0], arguments[1]);
"-Xbootclasspath/a:" + appJar, "DummyClassHelper", checkOutput(execOutput, classNames);
arguments[0], arguments[1]);
for (int i = 0; i < arguments.length; i++) {
TestCommon.checkExec(execOutput,
"java.lang.NoSuchMethodException: " + arguments[i] + "." +
METHOD_NAME);
}
JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox"); JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
String whiteBoxJar = TestCommon.getTestJar("WhiteBox.jar"); String whiteBoxJar = TestCommon.getTestJar("WhiteBox.jar");
String bootClassPath = "-Xbootclasspath/a:" + appJar + String bootClassPath = "-Xbootclasspath/a:" + appJar +
File.pathSeparator + whiteBoxJar; File.pathSeparator + whiteBoxJar;
dumpOutput = TestCommon.dump(
appJar, classNames, bootClassPath, "--add-modules", "java.activation");
argsList.add("testWithWhiteBox"); argsList.add("testWithWhiteBox");
arguments = new String[argsList.size()]; arguments = new String[argsList.size()];
arguments = argsList.toArray(arguments); arguments = argsList.toArray(arguments);
String[] opts = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", String[] opts = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
bootClassPath, "-XX:+TraceClassPaths", "DummyClassHelper", "--add-modules", "java.activation", bootClassPath, "-Xlog:class+path=trace",
arguments[0], arguments[1], arguments[2]}; "DummyClassHelper", arguments[0], arguments[1], arguments[2]};
OutputAnalyzer output = TestCommon.execCommon(opts); execOutput = TestCommon.execCommon(opts);
checkOutput(execOutput, classNames);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,30 +27,32 @@ import java.lang.reflect.*;
import sun.hotspot.WhiteBox; import sun.hotspot.WhiteBox;
public class DummyClassHelper { public class DummyClassHelper {
static void checkDummyMethod(Class<?> cls, String className) {
Method m = null;
try {
m = cls.getMethod("thisClassIsDummy");
throw new java.lang.RuntimeException(className +
" should be loaded from the jimage and should not have the thisClassIsDummy() method.");
} catch(NoSuchMethodException ex) {
System.out.println(ex.toString());
}
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String[] classNames = {args[0], args[1]}; String[] classNames = {args[0], args[1]};
Class cls = null; Class cls = null;
if (args.length == 2) { boolean doWBCheck = (args.length == 3);
for (int i = 0; i < classNames.length; i++) { WhiteBox wb = null;
Method m = null; if (doWBCheck) {
cls = Class.forName(classNames[i]); wb = WhiteBox.getWhiteBox();
try { }
m = cls.getMethod("thisClassIsDummy"); for (int i = 0; i < classNames.length; i++) {
throw new java.lang.RuntimeException(classNames[i] + cls = Class.forName(classNames[i]);
" should be loaded from the jimage and should not have the thisClassIsDummy() method."); checkDummyMethod(cls, classNames[i]);
} catch(NoSuchMethodException ex) { if (doWBCheck) {
System.out.println(ex.toString());
}
}
} else {
WhiteBox wb = WhiteBox.getWhiteBox();
for (int i = 0; i < classNames.length; i++) {
cls = Class.forName(classNames[i]);
if (!wb.isSharedClass(cls)) { if (!wb.isSharedClass(cls)) {
System.out.println(classNames[i] + ".class" + " is not in shared space as expected.");
} else {
throw new java.lang.RuntimeException(classNames[i] + throw new java.lang.RuntimeException(classNames[i] +
".class shouldn't be in shared space."); ".class should be in shared space.");
} }
} }
} }