--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/compilercontrol/logcompilation/LogTest.java Thu May 12 13:25:11 2016 +0200
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8137167
+ * @summary Tests LogCompilation executed standalone without log commands or directives
+ * @modules java.base/jdk.internal.misc
+ * @library /testlibrary /test/lib /compiler/testlibrary ../share /
+ * @build compiler.compilercontrol.logcompilation.LogTest
+ * pool.sub.* pool.subpack.* sun.hotspot.WhiteBox
+ * compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.*
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox
+ * sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
+ * -XX:+UnlockDiagnosticVMOptions compiler.compilercontrol.logcompilation.LogTest
+ */
+
+package compiler.compilercontrol.logcompilation;
+
+import compiler.compilercontrol.share.processors.LogProcessor;
+import compiler.compilercontrol.share.scenario.Scenario;
+
+public class LogTest {
+ public static void main(String[] args) {
+ Scenario.Builder builder = Scenario.getBuilder();
+ builder.addFlag("-XX:+UnlockDiagnosticVMOptions");
+ builder.addFlag("-XX:+LogCompilation");
+ builder.addFlag("-XX:LogFile=" + LogProcessor.LOG_FILE);
+ Scenario scenario = builder.build();
+ scenario.execute();
+ }
+}
--- a/hotspot/test/compiler/compilercontrol/share/processors/LogProcessor.java Wed May 11 20:10:03 2016 -0400
+++ b/hotspot/test/compiler/compilercontrol/share/processors/LogProcessor.java Thu May 12 13:25:11 2016 +0200
@@ -28,7 +28,6 @@
import compiler.compilercontrol.share.scenario.State;
import jdk.test.lib.Asserts;
import jdk.test.lib.OutputAnalyzer;
-import jdk.test.lib.Pair;
import pool.PoolHelper;
import java.io.File;
@@ -55,18 +54,17 @@
"method='([^']+)'");
private final List<String> loggedMethods;
private final List<String> testMethods;
- private Scanner scanner = null;
public LogProcessor(Map<Executable, State> states) {
loggedMethods = states.keySet().stream()
.filter(x -> states.get(x).isLog())
- .map(MethodGenerator::logDescriptor)
+ .map(MethodGenerator::commandDescriptor)
.map(MethodDescriptor::getString)
.collect(Collectors.toList());
testMethods = new PoolHelper().getAllMethods()
.stream()
.map(pair -> pair.first)
- .map(MethodGenerator::logDescriptor)
+ .map(MethodGenerator::commandDescriptor)
.map(MethodDescriptor::getString)
.collect(Collectors.toList());
}
@@ -76,8 +74,7 @@
if (loggedMethods.isEmpty()) {
return;
}
- getScanner();
- matchTasks();
+ matchTasks(getScanner());
}
/*
@@ -85,6 +82,7 @@
*/
private Scanner getScanner() {
File logFile = new File(LOG_FILE);
+ Scanner scanner;
try {
scanner = new Scanner(logFile);
} catch (FileNotFoundException e) {
@@ -97,29 +95,35 @@
* Parses for <task method='java.lang.String indexOf (I)I' >
* and finds if there is a compilation log for this task
*/
- private void matchTasks() {
+ private void matchTasks(Scanner scanner) {
String task = scanner.findWithinHorizon(TASK_ELEMENT, 0);
while (task != null) {
String element = scanner.findWithinHorizon(ANY_ELEMENT, 0);
if (Pattern.matches(TASK_DONE_ELEMENT, element)
|| Pattern.matches(TASK_END_ELEMENT, element)) {
/* If there is nothing between <task> and </task>
- except <task done /> then compilation log is empty */
- Asserts.assertTrue(matchMethod(task), "Compilation log "
+ except <task done /> then compilation log is empty.
+ Check the method in this task should not be logged */
+ Asserts.assertFalse(matchMethod(task), "Compilation log "
+ "expected. Met: " + element);
}
task = scanner.findWithinHorizon(TASK_ELEMENT, 0);
}
}
- // Matches given string to regular expression
+ // Check that input method should be logged
private boolean matchMethod(String input) {
Matcher matcher = METHOD_PATTERN.matcher(input);
Asserts.assertTrue(matcher.find(), "Wrong matcher or input");
// Get method and normalize it
String method = normalize(matcher.group(1));
- // Check that this method matches regexp
- return loggedMethods.contains(method) || !testMethods.contains(method);
+ if (loggedMethods.contains(method)) {
+ return true;
+ }
+ if (!testMethods.contains(method)) {
+ return false;
+ }
+ return false;
}
// Normalize given signature to conform regular expression used in tests
--- a/hotspot/test/compiler/compilercontrol/share/scenario/Scenario.java Wed May 11 20:10:03 2016 -0400
+++ b/hotspot/test/compiler/compilercontrol/share/scenario/Scenario.java Thu May 12 13:25:11 2016 +0200
@@ -198,6 +198,7 @@
= new HashMap<>();
private final JcmdStateBuilder jcmdStateBuilder;
private final List<JcmdCommand> jcmdCommands = new ArrayList<>();
+ private boolean logCommandMet = false;
public Builder() {
addFlag("-Xmixed");
@@ -215,6 +216,9 @@
public void add(CompileCommand compileCommand) {
String[] vmOptions = compileCommand.command.vmOpts;
Collections.addAll(vmopts, vmOptions);
+ if (compileCommand.command == Command.LOG) {
+ logCommandMet = true;
+ }
if (compileCommand.type == Type.JCMD) {
jcmdStateBuilder.add((JcmdCommand) compileCommand);
jcmdCommands.add((JcmdCommand) compileCommand);
@@ -294,6 +298,18 @@
isValid &= builder.isValid();
}
options.addAll(jcmdStateBuilder.getOptions());
+
+ /*
+ * Update final states if LogCompilation is enabled and
+ * there is no any log command, then all methods should be logged
+ */
+ boolean isLogComp = vmopts.stream()
+ .anyMatch(opt -> opt.contains("-XX:+LogCompilation"));
+ if (isLogComp && !logCommandMet) {
+ finalStates.entrySet()
+ .forEach(entry -> entry.getValue().setLog(true));
+ }
+
return new Scenario(isValid, options, finalStates, ccList,
jcmdCommands, directives);
}