This commit is contained in:
Pavel Punegov 2016-05-11 19:41:50 +02:00
commit 415bf9842e
3 changed files with 85 additions and 12 deletions

View File

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

View File

@ -28,7 +28,6 @@ import compiler.compilercontrol.share.method.MethodGenerator;
import compiler.compilercontrol.share.scenario.State; import compiler.compilercontrol.share.scenario.State;
import jdk.test.lib.Asserts; import jdk.test.lib.Asserts;
import jdk.test.lib.OutputAnalyzer; import jdk.test.lib.OutputAnalyzer;
import jdk.test.lib.Pair;
import pool.PoolHelper; import pool.PoolHelper;
import java.io.File; import java.io.File;
@ -55,18 +54,17 @@ public class LogProcessor implements Consumer<OutputAnalyzer> {
"method='([^']+)'"); "method='([^']+)'");
private final List<String> loggedMethods; private final List<String> loggedMethods;
private final List<String> testMethods; private final List<String> testMethods;
private Scanner scanner = null;
public LogProcessor(Map<Executable, State> states) { public LogProcessor(Map<Executable, State> states) {
loggedMethods = states.keySet().stream() loggedMethods = states.keySet().stream()
.filter(x -> states.get(x).isLog()) .filter(x -> states.get(x).isLog())
.map(MethodGenerator::logDescriptor) .map(MethodGenerator::commandDescriptor)
.map(MethodDescriptor::getString) .map(MethodDescriptor::getString)
.collect(Collectors.toList()); .collect(Collectors.toList());
testMethods = new PoolHelper().getAllMethods() testMethods = new PoolHelper().getAllMethods()
.stream() .stream()
.map(pair -> pair.first) .map(pair -> pair.first)
.map(MethodGenerator::logDescriptor) .map(MethodGenerator::commandDescriptor)
.map(MethodDescriptor::getString) .map(MethodDescriptor::getString)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -76,8 +74,7 @@ public class LogProcessor implements Consumer<OutputAnalyzer> {
if (loggedMethods.isEmpty()) { if (loggedMethods.isEmpty()) {
return; return;
} }
getScanner(); matchTasks(getScanner());
matchTasks();
} }
/* /*
@ -85,6 +82,7 @@ public class LogProcessor implements Consumer<OutputAnalyzer> {
*/ */
private Scanner getScanner() { private Scanner getScanner() {
File logFile = new File(LOG_FILE); File logFile = new File(LOG_FILE);
Scanner scanner;
try { try {
scanner = new Scanner(logFile); scanner = new Scanner(logFile);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
@ -97,29 +95,35 @@ public class LogProcessor implements Consumer<OutputAnalyzer> {
* Parses for &lt;task method='java.lang.String indexOf (I)I' &gt; * Parses for &lt;task method='java.lang.String indexOf (I)I' &gt;
* and finds if there is a compilation log for this task * 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); String task = scanner.findWithinHorizon(TASK_ELEMENT, 0);
while (task != null) { while (task != null) {
String element = scanner.findWithinHorizon(ANY_ELEMENT, 0); String element = scanner.findWithinHorizon(ANY_ELEMENT, 0);
if (Pattern.matches(TASK_DONE_ELEMENT, element) if (Pattern.matches(TASK_DONE_ELEMENT, element)
|| Pattern.matches(TASK_END_ELEMENT, element)) { || Pattern.matches(TASK_END_ELEMENT, element)) {
/* If there is nothing between <task> and </task> /* If there is nothing between <task> and </task>
except <task done /> then compilation log is empty */ except <task done /> then compilation log is empty.
Asserts.assertTrue(matchMethod(task), "Compilation log " Check the method in this task should not be logged */
Asserts.assertFalse(matchMethod(task), "Compilation log "
+ "expected. Met: " + element); + "expected. Met: " + element);
} }
task = scanner.findWithinHorizon(TASK_ELEMENT, 0); task = scanner.findWithinHorizon(TASK_ELEMENT, 0);
} }
} }
// Matches given string to regular expression // Check that input method should be logged
private boolean matchMethod(String input) { private boolean matchMethod(String input) {
Matcher matcher = METHOD_PATTERN.matcher(input); Matcher matcher = METHOD_PATTERN.matcher(input);
Asserts.assertTrue(matcher.find(), "Wrong matcher or input"); Asserts.assertTrue(matcher.find(), "Wrong matcher or input");
// Get method and normalize it // Get method and normalize it
String method = normalize(matcher.group(1)); String method = normalize(matcher.group(1));
// Check that this method matches regexp if (loggedMethods.contains(method)) {
return loggedMethods.contains(method) || !testMethods.contains(method); return true;
}
if (!testMethods.contains(method)) {
return false;
}
return false;
} }
// Normalize given signature to conform regular expression used in tests // Normalize given signature to conform regular expression used in tests

View File

@ -198,6 +198,7 @@ public final class Scenario {
= new HashMap<>(); = new HashMap<>();
private final JcmdStateBuilder jcmdStateBuilder; private final JcmdStateBuilder jcmdStateBuilder;
private final List<JcmdCommand> jcmdCommands = new ArrayList<>(); private final List<JcmdCommand> jcmdCommands = new ArrayList<>();
private boolean logCommandMet = false;
public Builder() { public Builder() {
addFlag("-Xmixed"); addFlag("-Xmixed");
@ -215,6 +216,9 @@ public final class Scenario {
public void add(CompileCommand compileCommand) { public void add(CompileCommand compileCommand) {
String[] vmOptions = compileCommand.command.vmOpts; String[] vmOptions = compileCommand.command.vmOpts;
Collections.addAll(vmopts, vmOptions); Collections.addAll(vmopts, vmOptions);
if (compileCommand.command == Command.LOG) {
logCommandMet = true;
}
if (compileCommand.type == Type.JCMD) { if (compileCommand.type == Type.JCMD) {
jcmdStateBuilder.add((JcmdCommand) compileCommand); jcmdStateBuilder.add((JcmdCommand) compileCommand);
jcmdCommands.add((JcmdCommand) compileCommand); jcmdCommands.add((JcmdCommand) compileCommand);
@ -294,6 +298,18 @@ public final class Scenario {
isValid &= builder.isValid(); isValid &= builder.isValid();
} }
options.addAll(jcmdStateBuilder.getOptions()); 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, return new Scenario(isValid, options, finalStates, ccList,
jcmdCommands, directives); jcmdCommands, directives);
} }