This commit is contained in:
Tatiana Pivovarova 2016-05-18 19:16:14 +00:00
commit 6fd77565f4
148 changed files with 3700 additions and 1346 deletions

View File

@ -91,10 +91,10 @@ manifest:
@echo 'Main-Class: jdk.test.lib.jittester.Automatic' >> $(MANIFEST)
compile_testlib: INIT
$(JAVAC) -XDignore.symbol.file -Xlint $(TESTLIBRARY_SRC_FILES) -d $(CLASSES_DIR) -source 1.8
$(JAVAC) -XDignore.symbol.file -XaddExports:java.base/jdk.internal.misc=ALL-UNNAMED -XaddExports:java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED -Xlint $(TESTLIBRARY_SRC_FILES) -d $(CLASSES_DIR)
COMPILE: INIT filelist compile_testlib
$(JAVAC) -cp $(CLASSES_DIR) -XDignore.symbol.file -Xlint -sourcepath $(SRC_DIR) -d $(CLASSES_DIR) -source 1.8 @filelist
$(JAVAC) -cp $(CLASSES_DIR) -XDignore.symbol.file -XaddExports:java.base/jdk.internal.misc=ALL-UNNAMED -XaddExports:java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED -Xlint -sourcepath $(SRC_DIR) -d $(CLASSES_DIR) @filelist
filelist: $(SRC_FILES)
@rm -f $@
@ -104,7 +104,7 @@ INIT: $(DIST_DIR)
$(shell if [ ! -d $(CLASSES_DIR) ]; then mkdir -p $(CLASSES_DIR); fi)
install: clean_testbase testgroup testroot copytestlibrary JAR cleantmp
$(JAVA) -jar $(DIST_JAR) $(APPLICATION_ARGS)
$(JAVA) -XaddExports:java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED -ea -jar $(DIST_JAR) $(APPLICATION_ARGS)
clean_testbase:
@rm -rf $(TESTBASE_DIR)

View File

@ -23,125 +23,165 @@
package jdk.test.lib.jittester;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.ProductionParams;
import jdk.test.lib.jittester.SymbolTable;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.Pair;
import jdk.test.lib.jittester.factories.IRNodeBuilder;
import jdk.test.lib.jittester.TypesParser;
import jdk.test.lib.jittester.jtreg.Printer;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.visitors.JavaCodeVisitor;
import jdk.test.lib.jittester.utils.FixedTrees;
import jdk.test.lib.jittester.utils.OptionResolver;
import jdk.test.lib.jittester.utils.OptionResolver.Option;
import jdk.test.lib.jittester.utils.PseudoRandom;
public class Automatic {
public static final int minutesToWait = 3;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalTime;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
private static String makeTestCase(String name) {
public class Automatic {
private static final int MINUTES_TO_WAIT = Integer.getInteger("jdk.test.lib.jittester", 3);
static String getJtregHeader(String mainClass, boolean addCompile) {
String synopsis = "seed = '" + ProductionParams.seed.value() + "'"
+ ", specificSeed = '" + PseudoRandom.getCurrentSeed() + "'";
StringBuilder header = new StringBuilder();
header.append("/*\n * @test\n * @summary ")
.append(synopsis)
.append(" \n* @library / ../\n");
if (addCompile) {
header.append("\n * @compile ")
.append(mainClass)
.append(".java\n");
}
header.append(" * @run build jdk.test.lib.jittester.jtreg.JitTesterDriver "
+ "jdk.test.lib.jittester.jtreg.Printer\n")
.append(" * @run driver jdk.test.lib.jittester.jtreg.JitTesterDriver ")
.append(mainClass)
.append("\n */\n\n");
if (ProductionParams.printHierarchy.value()) {
header.append("/*\n")
.append(Automatic.printHierarchy())
.append("*/\n");
}
return header.toString();
}
private static Pair<IRNode, IRNode> generateIRTree(String name) {
SymbolTable.removeAll();
TypeList.removeAll();
StringBuilder resultVis = new StringBuilder();
StringBuilder headerBuilder = new StringBuilder();
try {
IRNodeBuilder builder = new IRNodeBuilder()
.setPrefix(name)
.setName(name)
.setLevel(0);
JavaCodeVisitor vis = new JavaCodeVisitor();
String synopsis = "seed = '" + ProductionParams.seed.value() + "'";
String pathPrefix = ProductionParams.testbaseDir.value()
.replaceAll("([^/]+)", "..");
headerBuilder
.append("/*\n")
.append(" * @test\n")
.append(" * @summary ")
.append(synopsis)
.append("\n")
.append(" * @compile ")
.append(name)
.append(".java\n")
.append(" * @run build jdk.test.lib.jittester.jtreg.JitTesterDriver\n")
.append(" * @run driver jdk.test.lib.jittester.jtreg.JitTesterDriver ")
.append(name)
.append("\n")
.append(" */\n\n");
IRNodeBuilder builder = new IRNodeBuilder()
.setPrefix(name)
.setName(name)
.setLevel(0);
if (!ProductionParams.disableClasses.value()) {
long comlexityLimit = (long) (ProductionParams.complexityLimit.value()
* PseudoRandom.random());
IRNode privateClasses = builder.setComplexityLimit(comlexityLimit)
Long complexityLimit = ProductionParams.complexityLimit.value();
IRNode privateClasses = null;
if (!ProductionParams.disableClasses.value()) {
long privateClassComlexity = (long) (complexityLimit * PseudoRandom.random());
try {
privateClasses = builder.setComplexityLimit(privateClassComlexity)
.getClassDefinitionBlockFactory()
.produce();
if (privateClasses != null) {
resultVis.append(privateClasses.accept(vis));
}
} catch (ProductionFailedException ex) {
ex.printStackTrace(System.out);
}
long mainComplexityLimit = (long) (ProductionParams.complexityLimit.value()
* PseudoRandom.random());
IRNode mainClass = builder.setComplexityLimit(mainComplexityLimit)
}
long mainClassComplexity = (long) (complexityLimit * PseudoRandom.random());
IRNode mainClass = null;
try {
mainClass = builder.setComplexityLimit(mainClassComplexity)
.getMainKlassFactory()
.produce();
resultVis.append(mainClass.accept(vis));
if (ProductionParams.printHierarchy.value()) {
headerBuilder
.append("/*\n")
.append(Automatic.printHierarchy())
.append("*/\n");
}
} catch (Exception e) {
e.printStackTrace(System.out);
TypeKlass aClass = new TypeKlass(name);
mainClass.getChild(1).addChild(FixedTrees.generateMainOrExecuteMethod(aClass, true));
mainClass.getChild(1).addChild(FixedTrees.generateMainOrExecuteMethod(aClass, false));
} catch (ProductionFailedException ex) {
ex.printStackTrace(System.out);
}
return headerBuilder.append(resultVis).toString();
return new Pair<>(mainClass, privateClasses);
}
private static void initializeTestGenerator(String[] params) {
OptionResolver parser = new OptionResolver();
Option<String> propertyFileOpt = parser.addStringOption('p', "property-file", "",
"File to read properties from");
Option<String> propertyFileOpt = parser.addStringOption('p', "property-file",
"conf/default.properties", "File to read properties from");
ProductionParams.register(parser);
parser.parse(params, propertyFileOpt);
jdk.test.lib.jittester.utils.PseudoRandom.reset(ProductionParams.seed.value());
TypesParser.parseTypesAndMethods(ProductionParams.classesFile.value(), ProductionParams.excludeMethodsFile.value());
PseudoRandom.reset(ProductionParams.seed.value());
TypesParser.parseTypesAndMethods(ProductionParams.classesFile.value(),
ProductionParams.excludeMethodsFile.value());
if (ProductionParams.specificSeed.isSet()) {
PseudoRandom.setCurrentSeed(ProductionParams.specificSeed.value());
}
}
public static void main(String[] args) {
initializeTestGenerator(args);
int counter = 0;
try {
String testbaseDir = ProductionParams.testbaseDir.value();
Path testbaseDir = Paths.get(ProductionParams.testbaseDir.value());
System.out.printf(" %13s | %8s | %8s | %8s |%n", "start time", "count", "generat",
"running");
System.out.printf(" %13s | %8s | %8s | %8s |%n", "---", "---", "---","---");
String path = getJavaPath();
String javacPath = Paths.get(path, "javac").toString();
String javaPath = Paths.get(path, "java").toString();
// compile Printer class first. A common one for all tests
ensureExisting(testbaseDir);
ProcessBuilder pbPrinter = new ProcessBuilder(javacPath,
Paths.get(testbaseDir.toString(), "jdk", "test", "lib", "jittester",
"jtreg", "Printer.java").toString());
runProcess(pbPrinter, testbaseDir.resolve("Printer").toString());
do {
double start = System.currentTimeMillis();
System.out.print("[" + LocalTime.now() + "] |");
String name = "Test_" + counter;
generateTestFile(name);
Pair<IRNode, IRNode> irTree = generateIRTree(name);
System.out.printf(" %8d |", counter);
double generationTime = System.currentTimeMillis() - start;
String path = getJavaPath();
ProcessBuilder pb = new ProcessBuilder(path + "javac", testbaseDir + "/" + name + ".java");
runProcess(pb, testbaseDir + "/" + name);
System.out.printf(" %8.0f |", generationTime);
if (!ProductionParams.disableJavacodeGeneration.value()) {
JavaCodeGenerator generator = new JavaCodeGenerator();
String javaFile = generator.apply(irTree.first, irTree.second);
ProcessBuilder pb = new ProcessBuilder(javacPath, "-cp", testbaseDir.toString()
+ ":" + generator.getTestbase().toString(), javaFile);
runProcess(pb, generator.getTestbase().resolve(name).toString());
start = System.currentTimeMillis();
// Run compiled class files
pb = new ProcessBuilder(javaPath, "-Xint", "-cp", testbaseDir.toString()
+ ":" + generator.getTestbase().toString(), name);
String goldFile = name + ".gold";
runProcess(pb, generator.getTestbase().resolve(goldFile).toString());
}
if (!ProductionParams.disableBytecodeGeneration.value()) {
ByteCodeGenerator generator = new ByteCodeGenerator();
generator.apply(irTree.first, irTree.second);
generator.writeJtregBytecodeRunner(name);
// Run generated bytecode
ProcessBuilder pb = new ProcessBuilder(javaPath, "-Xint", "-Xverify", "-cp",
testbaseDir.toString() + ":" + generator.getTestbase().toString(),
name);
String goldFile = name + ".gold";
start = System.currentTimeMillis();
runProcess(pb, generator.getTestbase().resolve(goldFile).toString());
}
start = System.currentTimeMillis();
pb = new ProcessBuilder(path + "java", "-Xint", "-cp", testbaseDir, name);
name = name + ".gold";
runProcess(pb, testbaseDir + "/" + name);
double runningTime = System.currentTimeMillis() - start;
System.out.printf("%4d : generation time (ms) : %8.0f running time (ms) : %8.0f\n",
counter, generationTime, runningTime);
if (runningTime < TimeUnit.MINUTES.toMillis(minutesToWait))
++counter;
System.out.printf(" %8.0f |%n", runningTime);
if (runningTime < TimeUnit.MINUTES.toMillis(MINUTES_TO_WAIT)) {
++counter;
}
} while (counter < ProductionParams.numberOfTests.value());
} catch (IOException | InterruptedException ex) {
Logger.getLogger(Automatic.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
}
}
@ -156,65 +196,47 @@ public class Automatic {
return "";
}
private static void runProcess(ProcessBuilder pb, String name)
private static int runProcess(ProcessBuilder pb, String name)
throws IOException, InterruptedException {
pb.redirectError(new File(name + ".err"));
pb.redirectOutput(new File(name + ".out"));
Process process = pb.start();
if (process.waitFor(minutesToWait, TimeUnit.MINUTES)) {
if (process.waitFor(MINUTES_TO_WAIT, TimeUnit.MINUTES)) {
try (FileWriter file = new FileWriter(name + ".exit")) {
file.write(Integer.toString(process.exitValue()));
}
return process.exitValue();
} else {
process.destroyForcibly();
}
TimeUnit.MILLISECONDS.sleep(300);
}
private static void generateTestFile(String testName) {
String code = makeTestCase(testName);
String testbaseDir = ProductionParams.testbaseDir.value();
String fileName = testbaseDir + "/" + testName + ".java";
try (FileWriter file = new FileWriter(fileName)) {
file.write(code);
//file.close();
} catch (IOException ex) {
Logger.getLogger(Automatic.class.getName())
.log(Level.SEVERE, " Cannot write to file " + fileName, ex);
return -1;
}
}
private static String printHierarchy() {
String r = "CLASS HIERARCHY:\n";
for (Type t : TypeList.getAll()) {
if (t instanceof TypeKlass) {
TypeKlass k = (TypeKlass) t;
if (k.isAbstract()) {
r += "abstract ";
}
if (k.isFinal()) {
r += "final ";
}
if (k.isInterface()) {
r += "interface ";
} else {
r += "class ";
}
r += k.getName() + ": ";
HashSet<String> parents = k.getParentsNames();
if (parents != null) {
Iterator<String> n = parents.iterator();
int size = parents.size();
for (int i = 0; n.hasNext() && i < size - 1; i++) {
r += n.next() + ", ";
}
if (n.hasNext()) {
r += n.next();
}
}
r += "\n";
return TypeList.getAll().stream()
.filter(t -> t instanceof TypeKlass)
.map(t -> typeDescription((TypeKlass) t))
.collect(Collectors.joining("\n","CLASS HIERARCHY:\n", "\n"));
}
private static String typeDescription(TypeKlass type) {
StringBuilder result = new StringBuilder();
String parents = type.getParentsNames().stream().collect(Collectors.joining(","));
result.append(type.isAbstract() ? "abstract " : "")
.append(type.isFinal() ? "final " : "")
.append(type.isInterface() ? "interface " : "class ")
.append(type.getName())
.append(parents.isEmpty() ? "" : ": " + parents);
return result.toString();
}
static void ensureExisting(Path path) {
if (Files.notExists(path)) {
try {
Files.createDirectories(path);
} catch (IOException ex) {
ex.printStackTrace();
}
}
return r;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2016, 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
@ -26,12 +26,8 @@ package jdk.test.lib.jittester;
import jdk.test.lib.jittester.visitors.Visitor;
public class BinaryOperator extends Operator {
protected String operationCode;
protected Type resultType;
public BinaryOperator(OperatorKind opKind, IRNode leftOperand, IRNode rightOperand) {
super(opKind.priority);
operationCode = opKind.text;
public BinaryOperator(OperatorKind opKind, Type resultType, IRNode leftOperand, IRNode rightOperand) {
super(opKind, resultType);
addChild(leftOperand);
addChild(rightOperand);
}
@ -47,10 +43,6 @@ public class BinaryOperator extends Operator {
}
}
public String getOperationCode() {
return operationCode;
}
@Override
public<T> T accept(Visitor<T> v) {
return v.visit(this);

View File

@ -28,17 +28,12 @@ import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.visitors.Visitor;
public class Block extends IRNode {
private final Type returnType;
public Block(TypeKlass klass, Type returnType, List<IRNode> content, int level) {
setKlass(klass);
public Block(TypeKlass owner, Type returnType, List<? extends IRNode> content, int level) {
super(returnType);
setOwner(owner);
addChildren(content);
this.level = level;
this.returnType = returnType;
}
public Type getReturnType() {
return returnType;
}
protected int size() {

View File

@ -27,6 +27,10 @@ import jdk.test.lib.jittester.visitors.Visitor;
public class Break extends IRNode {
public Break() {
super(TypeList.VOID);
}
@Override
public<T> T accept(Visitor<T> v) {
return v.visit(this);

View File

@ -27,9 +27,9 @@ public abstract class BuiltInType extends Type {
private static class BuiltInTypeCapacityHelper {
static String builtInTypes[] = {"boolean", "byte", "short", "char", "int", "long", "float", "double"};
private static final String builtInTypes[] = {"boolean", "byte", "short", "char", "int", "long", "float", "double"};
static private int getIndexFor(String typeName) {
private static int getIndexFor(String typeName) {
for (int i = 0; i < builtInTypes.length; i++) {
if (typeName.compareTo(builtInTypes[i]) == 0) {
return i;
@ -38,7 +38,7 @@ public abstract class BuiltInType extends Type {
return -1;
}
static public int compare(String typeName1, String typeName2) {
public static int compare(String typeName1, String typeName2) {
int i1 = getIndexFor(typeName1);
int i2 = getIndexFor(typeName2);

View File

@ -0,0 +1,96 @@
/*
* Copyright (c) 2016, 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.
*/
package jdk.test.lib.jittester;
import jdk.test.lib.jittester.visitors.ByteCodeVisitor;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.function.BiFunction;
/**
* Generates class files from bytecode
*/
class ByteCodeGenerator implements BiFunction<IRNode, IRNode, String> {
private final Path testbase = Paths.get(ProductionParams.testbaseDir.value(),
"bytecode_tests");
public void writeJtregBytecodeRunner(String name) {
try (FileWriter file = new FileWriter(testbase.resolve(name + ".java").toFile())) {
file.write(Automatic.getJtregHeader(name, false));
} catch (IOException e) {
e.printStackTrace();
}
}
public String apply(IRNode mainClass, IRNode privateClasses) {
Automatic.ensureExisting(testbase);
try {
ByteCodeVisitor vis = new ByteCodeVisitor();
if (privateClasses != null) {
privateClasses.accept(vis);
}
mainClass.accept(vis);
Path mainClassPath = testbase.resolve(mainClass.getName() + ".class");
writeToClassFile(mainClassPath, vis.getByteCode(mainClass.getName()));
if (privateClasses != null) {
privateClasses.getChildren().forEach(c -> {
String name = c.getName();
Path classPath = testbase.resolve(name + ".class");
writeToClassFile(classPath, vis.getByteCode(name));
});
}
return mainClassPath.toString();
} catch (Throwable t) {
Path errFile = testbase.resolve(mainClass.getName() + ".err");
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(errFile,
StandardOpenOption.CREATE_NEW))) {
t.printStackTrace(pw);
} catch (IOException e) {
t.printStackTrace();
throw new Error("can't write error to error file " + errFile, e);
}
return null;
}
}
public Path getTestbase() {
return testbase;
}
private void writeToClassFile(Path path, byte[] bytecode) {
try (FileOutputStream file = new FileOutputStream(path.toString())) {
file.write(bytecode);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2016, 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
@ -26,11 +26,9 @@ package jdk.test.lib.jittester;
import jdk.test.lib.jittester.visitors.Visitor;
public class CastOperator extends Operator {
private final Type resultType;
public CastOperator(Type resultType, IRNode casted) {
super(13);
this.resultType = resultType;
super(null, 13, resultType);
addChild(casted);
}
@ -43,8 +41,4 @@ public class CastOperator extends Operator {
public<T> T accept(Visitor<T> v) {
return v.visit(this);
}
public Type getResultType() {
return resultType;
}
}

View File

@ -31,6 +31,7 @@ public class CatchBlock extends IRNode {
public final List<Type> throwables;
public CatchBlock(IRNode body, List<Type> throwables, int level) {
super(body.getResultType());
this.level = level;
this.throwables = Collections.unmodifiableList(throwables);
addChild(body);

View File

@ -27,6 +27,10 @@ import jdk.test.lib.jittester.visitors.Visitor;
public class Continue extends IRNode {
public Continue() {
super(TypeList.VOID);
}
@Override
public<T> T accept(Visitor<T> v) {
return v.visit(this);

View File

@ -27,6 +27,7 @@ import jdk.test.lib.jittester.visitors.Visitor;
public class Declaration extends IRNode {
public Declaration(IRNode declarationExpr) {
super(declarationExpr.getResultType());
addChild(declarationExpr);
}

View File

@ -37,16 +37,26 @@ import jdk.test.lib.jittester.visitors.Visitor;
public abstract class IRNode {
private IRNode parent;
private final List<IRNode> children = new ArrayList<>();
protected IRNode klass;
protected TypeKlass owner;
protected int level;
private final Type resultType;
protected IRNode(Type resultType) {
this.resultType = resultType;
}
public Type getResultType() {
return resultType;
}
//TODO
//private boolean isCFDeviation;
public abstract <T> T accept(Visitor<T> v);
public void setKlass(TypeKlass klass) {
this.klass = klass;
if (Objects.isNull(klass)) {
public void setOwner(TypeKlass owner) {
this.owner = owner;
if (Objects.isNull(owner)) {
System.out.println(getClass().getName() + " null");
for (StackTraceElement s : Thread.currentThread().getStackTrace()) {
System.out.println(s.toString());
@ -55,20 +65,17 @@ public abstract class IRNode {
}
public void addChild(IRNode child) {
children.add(child);
if (!Objects.isNull(child)) {
if (Objects.nonNull(child)) {
children.add(child);
child.parent = this;
}
}
public void addChildren(List<? extends IRNode> ch) {
if (!Objects.isNull(ch)) {
children.addAll(ch);
for (IRNode c : ch) {
if (!Objects.isNull(c)) {
c.parent = this;
}
}
if (Objects.nonNull(ch)) {
ch.stream()
.filter(c -> c != null)
.forEach(this::addChild);
}
}
@ -80,8 +87,8 @@ public abstract class IRNode {
return i < children.size() ? children.get(i) : null;
}
public IRNode getKlass() {
return klass;
public TypeKlass getOwner() {
return owner;
}
public IRNode getParent() {
@ -90,7 +97,7 @@ public abstract class IRNode {
public void setChild(int index, IRNode child) {
children.set(index, child);
if (!Objects.isNull(child)) {
if (Objects.nonNull(child)) {
child.parent = this;
}
}
@ -145,7 +152,7 @@ public abstract class IRNode {
@Override
public final String toString() {
throw new Error("Should be toJavaCode");
return getName();
}
public String getName() {
@ -154,7 +161,7 @@ public abstract class IRNode {
public static long countDepth(Collection<IRNode> input) {
return input.stream()
.filter(c -> !Objects.isNull(c))
.filter(Objects::nonNull)
.mapToLong(IRNode::countDepth)
.max().orElse(0L);
}
@ -166,7 +173,7 @@ public abstract class IRNode {
public List<IRNode> getStackableLeaves() {
List<IRNode> result = new ArrayList<>();
children.stream()
.filter(c -> !Objects.isNull(c))
.filter(Objects::nonNull)
.forEach(c -> {
if (countDepth() == c.level && (c instanceof Block)) {
result.add(c);

View File

@ -30,9 +30,10 @@ public class If extends IRNode {
CONDITION,
THEN,
ELSE,
};
}
public If(IRNode condition, IRNode thenBlock, IRNode elseBlock, int level) {
public If(IRNode condition, Block thenBlock, Block elseBlock, int level) {
super(thenBlock.getResultType());
this.level = level;
resizeUpChildren(IfPart.values().length);
setChild(IfPart.CONDITION.ordinal(), condition);
@ -43,7 +44,7 @@ public class If extends IRNode {
@Override
public long complexity() {
IRNode condition = getChild(IfPart.CONDITION.ordinal());
IRNode thenBlock= getChild(IfPart.THEN.ordinal());
IRNode thenBlock = getChild(IfPart.THEN.ordinal());
IRNode elseBlock = getChild(IfPart.ELSE.ordinal());
return (condition != null ? condition.complexity() : 0)
+ Math.max(thenBlock != null ? thenBlock.complexity() : 0,

View File

@ -26,20 +26,14 @@ package jdk.test.lib.jittester;
import jdk.test.lib.jittester.visitors.Visitor;
public abstract class Initialization extends IRNode {
protected VariableInfo variableInfo = new VariableInfo();
protected Initialization() {
}
private final VariableInfo variableInfo;
protected Initialization(VariableInfo varInfo, IRNode initExpr) {
super(varInfo.type);
variableInfo = varInfo;
addChild(initExpr);
}
public VariableInfo get() {
return variableInfo;
}
@Override
public long complexity() {
return getChild(0).complexity() + 1;

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2016, 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.
*/
package jdk.test.lib.jittester;
import jdk.test.lib.jittester.visitors.JavaCodeVisitor;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.BiFunction;
/**
* Generates class files from java source code
*/
class JavaCodeGenerator implements BiFunction<IRNode, IRNode, String> {
private final Path testbase = Paths.get(ProductionParams.testbaseDir.value(), "java_tests");
private String generateJavaCode(IRNode mainClass, IRNode privateClasses) {
StringBuilder code = new StringBuilder();
JavaCodeVisitor vis = new JavaCodeVisitor();
code.append(Automatic.getJtregHeader(mainClass.getName(), true));
if (privateClasses != null) {
code.append(privateClasses.accept(vis));
}
code.append(mainClass.accept(vis));
return code.toString();
}
public Path getTestbase() {
return testbase;
}
@Override
public String apply(IRNode mainClass, IRNode privateClasses) {
String code = generateJavaCode(mainClass, privateClasses);
Automatic.ensureExisting(testbase);
Path fileName = testbase.resolve(mainClass.getName() + ".java");
try (FileWriter file = new FileWriter(fileName.toFile())) {
file.write(code);
return fileName.toString();
} catch (IOException ex) {
ex.printStackTrace();
}
return "";
}
}

View File

@ -27,11 +27,10 @@ import jdk.test.lib.jittester.visitors.Visitor;
public class Literal extends IRNode {
public final Object value;
protected final Type resultType;
public Literal(Object v, Type t) {
super(t);
value = v;
resultType = t;
}
@Override
@ -44,10 +43,6 @@ public class Literal extends IRNode {
return v.visit(this);
}
public Type getResultType() {
return resultType;
}
public Object getValue() {
return value;
}

View File

@ -25,16 +25,9 @@ package jdk.test.lib.jittester;
import jdk.test.lib.jittester.visitors.Visitor;
public class LocalVariable extends IRNode implements VariableBase {
private VariableInfo value = new VariableInfo();
public class LocalVariable extends VariableBase {
public LocalVariable(VariableInfo value) {
this.value = value;
}
@Override
public VariableInfo get() {
return value;
super(value);
}
@Override

View File

@ -1,37 +0,0 @@
/*
* Copyright (c) 2005, 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.
*/
package jdk.test.lib.jittester;
import jdk.test.lib.jittester.visitors.Visitor;
public class LogicOperator extends IRNode {
protected LogicOperator() {
}
@Override
public<T> T accept(Visitor<T> v) {
return v.visit(this);
}
}

View File

@ -25,19 +25,13 @@ package jdk.test.lib.jittester;
import jdk.test.lib.jittester.visitors.Visitor;
public class NonStaticMemberVariable extends IRNode implements VariableBase {
private final VariableInfo value;
public class NonStaticMemberVariable extends VariableBase {
public NonStaticMemberVariable(IRNode object, VariableInfo value) {
this.value = value;
super(value);
addChild(object);
}
@Override
public VariableInfo get() {
return value;
}
@Override
public long complexity() {
return getChild(0).complexity();
@ -47,8 +41,4 @@ public class NonStaticMemberVariable extends IRNode implements VariableBase {
public<T> T accept(Visitor<T> v) {
return v.visit(this);
}
public VariableInfo getValue() {
return value;
}
}

View File

@ -27,6 +27,10 @@ import jdk.test.lib.jittester.visitors.Visitor;
public class Nothing extends IRNode {
public Nothing() {
super(TypeList.VOID);
}
@Override
public long complexity() {
return 0;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2016, 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
@ -24,18 +24,28 @@
package jdk.test.lib.jittester;
public abstract class Operator extends IRNode {
protected int operatorPriority;
protected final OperatorKind opKind;
private final int priority;
public int getPriority() {
return operatorPriority;
return priority;
}
public OperatorKind getOperationKind() {
return opKind;
}
public enum Order {
LEFT, RIGHT
};
}
// This constructor is called to construct an IR-tree node.
protected Operator(int operatorPriority) {
this.operatorPriority = operatorPriority;
protected Operator(OperatorKind opKind, Type resultType) {
this(opKind, opKind.priority, resultType);
}
protected Operator(OperatorKind opKind, int operatorPriority, Type resultType) {
super(resultType);
this.opKind = opKind;
this.priority = operatorPriority;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, 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
@ -25,58 +25,96 @@ package jdk.test.lib.jittester;
// all unary and binary operator kinds
public enum OperatorKind {
COMPOUND_ADD("+=", 1),
COMPOUND_SUB("-=", 1),
COMPOUND_MUL("*=", 1),
COMPOUND_DIV("-=", 1),
COMPOUND_MOD("%=", 1),
COMPOUND_AND("&=", 1),
COMPOUND_OR ("|=", 1),
COMPOUND_XOR("^=", 1),
COMPOUND_SHR(">>=", 1),
COMPOUND_SHL("<<=", 1),
COMPOUND_SAR(">>>=", 1),
ASSIGN ("=", 1),
OR ("||", 3),
BIT_OR ("|", 5),
BIT_XOR ("^", 6),
AND ("&&", 7),
BIT_AND ("&", 7),
EQ ("==", 8),
NE ("!=", 8),
GT (">", 9),
LT ("<", 9),
GE (">=", 9),
LE ("<=", 9),
SHR (">>", 10),
SHL ("<<", 10),
SAR (">>>", 10),
ADD ("+", 11),
STRADD ("+", 11),
SUB ("-", 11),
MUL ("*", 12),
DIV ("/", 12),
MOD ("%", 12),
NOT ("!", 14),
BIT_NOT ("~", 14),
UNARY_PLUS ("+", 14),
UNARY_MINUS ("-", 14),
PRE_DEC ("--", 15, true),
POST_DEC ("--", 15, false),
PRE_INC ("++", 16, true),
POST_INC ("++", 16, false),
/** a += b */
COMPOUND_ADD(1),
/** a -= b */
COMPOUND_SUB(1),
/** a *= b */
COMPOUND_MUL(1),
/** a /= b */
COMPOUND_DIV(1),
/** a %= b */
COMPOUND_MOD(1),
/** a &= b */
COMPOUND_AND(1),
/** a |= b */
COMPOUND_OR (1),
/** a ^= b */
COMPOUND_XOR(1),
/** a >>= b */
COMPOUND_SHR(1),
/** a <<= b */
COMPOUND_SHL(1),
/** a >>>= b */
COMPOUND_SAR(1),
/** a = b */
ASSIGN (1),
/** a || b */
OR (3),
/** a | b */
BIT_OR (5),
/** a ^ b */
BIT_XOR (6),
/** a && b */
AND (7),
/** a & b */
BIT_AND (7),
/** a == b */
EQ (8),
/** a != b */
NE (8),
/** a > b */
GT (9),
/** a < b */
LT (9),
/** a >= b */
GE (9),
/** a <= b */
LE (9),
/** a >> b */
SHR (10),
/** a << b */
SHL (10),
/** a >>> b */
SAR (10),
/** a + b */
ADD (11),
/** a.toString() + b */
STRADD (11),
/** a - b */
SUB (11),
/** a * b */
MUL (12),
/** a / b */
DIV (12),
/** a % b */
MOD (12),
/** !a */
NOT (14),
/** ~a */
BIT_NOT (14),
/** +a */
UNARY_PLUS (14),
/** -a */
UNARY_MINUS (14),
/** --a */
PRE_DEC (15, true),
/** a-- */
POST_DEC (15, false),
/** ++a */
PRE_INC (16, true),
/** a++ */
POST_INC (16, false),
;
public final String text;
public final int priority;
public final boolean isPrefix; // used for unary operators
private OperatorKind(String text, int priority) {
this(text, priority, true);
private OperatorKind(int priority) {
this(priority, true);
}
private OperatorKind(String text, int priority, boolean isPrefix) {
this.text = text;
private OperatorKind(int priority, boolean isPrefix) {
this.priority = priority;
this.isPrefix = isPrefix;
}

View File

@ -25,15 +25,16 @@ package jdk.test.lib.jittester;
import java.util.ArrayList;
import java.util.List;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.visitors.Visitor;
public class PrintVariables extends IRNode {
private final String printerName;
private final ArrayList<Symbol> vars;
public PrintVariables(String printerName, ArrayList<Symbol> vars, int level) {
this.printerName = printerName;
this.vars = vars;
public PrintVariables(TypeKlass owner, int level) {
super(TypeList.VOID);
this.owner = owner;
this.vars = SymbolTable.getAllCombined(owner, VariableInfo.class);
this.level = level;
}
@ -45,8 +46,4 @@ public class PrintVariables extends IRNode {
public List<Symbol> getVars() {
return vars;
}
public String getPrinterName() {
return printerName;
}
}

View File

@ -68,11 +68,14 @@ public class ProductionParams {
public static Option<Boolean> disableNestedBlocks = null;
public static Option<Boolean> disableArrays = null;
public static Option<Boolean> enableFinalizers = null;
public static Option<Boolean> disableBytecodeGeneration = null;
public static Option<Boolean> disableJavacodeGeneration = null;
// workaraound: to reduce chance throwing ArrayIndexOutOfBoundsException
public static Option<Integer> chanceExpressionIndex = null;
public static Option<String> testbaseDir = null;
public static Option<Integer> numberOfTests = null;
public static Option<String> seed = null;
public static Option<Long> specificSeed = null;
public static Option<String> classesFile = null;
public static Option<String> excludeMethodsFile = null;
@ -117,11 +120,14 @@ public class ProductionParams {
disableNestedBlocks = optionResolver.addBooleanOption("disable-nested-blocks", "Disable generation of nested blocks");
disableArrays = optionResolver.addBooleanOption("disable-arrays", "Disable generation of arrays");
enableFinalizers = optionResolver.addBooleanOption("enable-finalizers", "Enable finalizers (for stress testing)");
disableBytecodeGeneration = optionResolver.addBooleanOption("disable-bytecode-generation", "Disable generation of bytecode output");
disableJavacodeGeneration = optionResolver.addBooleanOption("disable-javacode-generation", "Disable generation of java source code output");
chanceExpressionIndex = optionResolver.addIntegerOption("chance-expression-index", 0, "A non negative decimal integer used to restrict chane of generating expression in array index while creating or accessing by index");
testbaseDir = optionResolver.addStringOption("testbase-dir", ".", "Testbase dir");
numberOfTests = optionResolver.addIntegerOption('n', "number-of-tests", 0, "Number of test classes to generate");
seed = optionResolver.addStringOption("seed", "", "Random seed");
classesFile = optionResolver.addStringOption('f', "classes-file", "", "File to read classes from");
excludeMethodsFile = optionResolver.addStringOption('r', "exclude-methods-file", "", "File to read excluded methods from");
specificSeed = optionResolver.addLongOption('z', "specificSeed", 0L, "A seed to be set for specific test generation(regular seed still needed for initialization)");
classesFile = optionResolver.addStringOption('f', "classes-file", "conf/classes.lst", "File to read classes from");
excludeMethodsFile = optionResolver.addStringOption('r', "exclude-methods-file", "conf/exclude.methods.lst", "File to read excluded methods from");
}
}

View File

@ -32,27 +32,26 @@ import jdk.test.lib.jittester.utils.PseudoRandom;
/**
* The Rule. A helper to perform production.
*/
public class Rule extends Factory implements Comparable<Rule> {
private String name;
public class Rule<T extends IRNode> extends Factory<T> implements Comparable<Rule<T>> {
private final String name;
private final TreeSet<RuleEntry> variants;
private Integer limit = -1;
@Override
public int compareTo(Rule rule) {
public int compareTo(Rule<T> rule) {
return name.compareTo(rule.name);
}
private TreeSet<RuleEntry> variants;
public Rule(String name) {
this.name = name;
variants = new TreeSet<>();
}
public void add(String ruleName, Factory factory) {
public void add(String ruleName, Factory<? extends T> factory) {
add(ruleName, factory, 1.0);
}
public void add(String ruleName, Factory factory, double weight) {
public void add(String ruleName, Factory<? extends T> factory, double weight) {
variants.add(new RuleEntry(ruleName, factory, weight));
}
@ -61,7 +60,7 @@ public class Rule extends Factory implements Comparable<Rule> {
}
@Override
public IRNode produce() throws ProductionFailedException {
public T produce() throws ProductionFailedException {
if (!variants.isEmpty()) {
// Begin production.
LinkedList<RuleEntry> rulesList = new LinkedList<>(variants);
@ -98,19 +97,19 @@ public class Rule extends Factory implements Comparable<Rule> {
throw new ProductionFailedException();
}
private class RuleEntry extends Factory implements Comparable<RuleEntry> {
private class RuleEntry extends Factory<T> implements Comparable<RuleEntry> {
private final double weight;
private final Factory factory;
private final Factory<? extends T> factory;
private final String name;
private RuleEntry(String name, Factory factory, double weight) {
private RuleEntry(String name, Factory<? extends T> factory, double weight) {
this.name = name;
this.weight = weight;
this.factory = factory;
}
@Override
public IRNode produce() throws ProductionFailedException {
public T produce() throws ProductionFailedException {
return factory.produce();
}

View File

@ -29,6 +29,7 @@ public class Statement extends IRNode {
private final boolean needSemicolon;
public Statement(IRNode statementBody, boolean needSemicolon) {
super(statementBody.getResultType());
this.needSemicolon = needSemicolon;
addChild(statementBody);
}

View File

@ -26,17 +26,11 @@ package jdk.test.lib.jittester;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.visitors.Visitor;
public class StaticMemberVariable extends IRNode implements VariableBase {
private final VariableInfo varInfo;
public class StaticMemberVariable extends VariableBase {
public StaticMemberVariable(TypeKlass owner, VariableInfo varInfo) {
setKlass(owner);
this.varInfo = varInfo;
}
@Override
public VariableInfo get() {
return varInfo;
super(varInfo);
setOwner(owner);
}
@Override

View File

@ -30,6 +30,7 @@ public class Switch extends IRNode {
private final int caseBlockIdx;
public Switch(int level, List<IRNode> chldrn, int caseBlockIdx) {
super(chldrn.get(caseBlockIdx).getResultType());
this.level = level;
addChildren(chldrn);
this.caseBlockIdx = caseBlockIdx;

View File

@ -29,7 +29,7 @@ public class Symbol {
public String name;
public Type type;
public TypeKlass klass;
public TypeKlass owner;
public static final int NONE = 0x00;
public static final int PRIVATE = 0x01;
public static final int DEFAULT = 0x02;
@ -47,16 +47,16 @@ public class Symbol {
this.name = name;
}
public Symbol(String name, TypeKlass klass, Type type, int flags) {
public Symbol(String name, TypeKlass owner, Type type, int flags) {
this.name = name;
this.klass = klass;
this.owner = owner;
this.type = type;
this.flags = flags;
}
protected Symbol(Symbol value) {
this.name = value.name;
this.klass = value.klass;
this.owner = value.owner;
this.type = value.type;
this.flags = value.flags;
}
@ -71,7 +71,7 @@ public class Symbol {
}
try {
Symbol s = (Symbol) o;
return klass.equals(s.klass) && name.equals(s.name);
return owner.equals(s.owner) && name.equals(s.name);
} catch (Exception e) {
return false;
}
@ -110,4 +110,9 @@ public class Symbol {
public Symbol deepCopy() {
return new Symbol(this);
}
public TypeKlass getOwner() {
return owner;
}
}

View File

@ -28,6 +28,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import java.util.stream.Collectors;
import jdk.test.lib.jittester.types.TypeKlass;
@ -42,9 +43,8 @@ public class SymbolTable {
String classList = ProductionParams.addExternalSymbols.value();
if (classList.equals("all")) {
for (Type type : TypeList.getReferenceTypes()) {
type.exportSymbols();
}
TypeList.getReferenceTypes()
.forEach(Type::exportSymbols);
} else {
String[] splittedList = classList.split(",");
for (Type type : TypeList.getReferenceTypes()) {
@ -96,13 +96,9 @@ public class SymbolTable {
public static Collection<Symbol> get(Type type, Class<?> classToCheck) {
HashMap<Type, ArrayList<Symbol>> vars = SYMBOL_STACK.peek();
if (vars.containsKey(type)) {
ArrayList<Symbol> result = new ArrayList<>();
for (Symbol symbol : vars.get(type)) {
if (classToCheck.isInstance(symbol)) {
result.add(symbol);
}
}
return result;
return vars.get(type).stream()
.filter(classToCheck::isInstance)
.collect(Collectors.toList());
}
return new ArrayList<>();
}
@ -113,7 +109,7 @@ public class SymbolTable {
if (vars.containsKey(type)) {
ArrayList<Symbol> result = new ArrayList<>();
for (Symbol symbol : vars.get(type)) {
if (classToCheck.isInstance(symbol) && typeKlass.equals(symbol.klass)) {
if (classToCheck.isInstance(symbol) && typeKlass.equals(symbol.owner)) {
result.add(symbol);
}
}
@ -150,7 +146,7 @@ public class SymbolTable {
for (Type type : SYMBOL_STACK.peek().keySet()) {
ArrayList<Symbol> symbolsOfType = SYMBOL_STACK.peek().get(type);
for (Symbol symbol : symbolsOfType) {
if (classToCheck.isInstance(symbol) && typeKlass.equals(symbol.klass)) {
if (classToCheck.isInstance(symbol) && typeKlass.equals(symbol.owner)) {
if (!result.containsKey(type)) {
result.put(type, new ArrayList<>());
}
@ -193,7 +189,7 @@ public class SymbolTable {
for (Type type : SYMBOL_STACK.peek().keySet()) {
ArrayList<Symbol> symbolsOfType = SYMBOL_STACK.peek().get(type);
for (Symbol symbol : symbolsOfType) {
if (classToCheck.isInstance(symbol) && typeKlass.equals(symbol.klass)) {
if (classToCheck.isInstance(symbol) && typeKlass.equals(symbol.owner)) {
result.add(symbol);
}
}
@ -207,7 +203,7 @@ public class SymbolTable {
for (Type t : SYMBOL_STACK.peek().keySet()) {
ArrayList<Symbol> symbolsOfType = SYMBOL_STACK.peek().get(t);
for (Symbol symbol : symbolsOfType) {
if (typeKlass.equals(symbol.klass)) {
if (typeKlass.equals(symbol.owner)) {
result.add(symbol);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2016, 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
@ -30,12 +30,11 @@ public class TernaryOperator extends Operator {
CONDITION,
TRUE,
FALSE,
};
}
//protected Production conditionalExpression, leftExpression, rightExpression;
protected Type resultType;
public TernaryOperator(IRNode condition, IRNode trueBranch, IRNode falseBranch) {
super(2);
super(null, 2, trueBranch.getResultType());
resizeUpChildren(TernaryPart.values().length);
setChild(TernaryPart.CONDITION.ordinal(), condition);
setChild(TernaryPart.TRUE.ordinal(), trueBranch);

View File

@ -27,6 +27,7 @@ import jdk.test.lib.jittester.visitors.Visitor;
public class Throw extends IRNode {
public Throw(IRNode throwable) {
super(throwable.getResultType());
addChild(throwable);
}

View File

@ -29,6 +29,7 @@ import jdk.test.lib.jittester.visitors.Visitor;
public class TryCatchBlock extends IRNode {
public TryCatchBlock(IRNode body, IRNode finallyBlock, List<CatchBlock> catchBlocks, int level) {
super(body.getResultType());
this.level = level;
addChild(body);
addChild(finallyBlock);

View File

@ -33,9 +33,15 @@ public abstract class Type extends IRNode implements Comparable<Type> {
private final String typeName;
protected Type(String typeName) {
super(null);
this.typeName = typeName;
}
@Override
public Type getResultType() {
return this;
}
@Override
public boolean equals(Object t) {
if (this == t) {

View File

@ -27,19 +27,31 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
import jdk.test.lib.jittester.types.TypeArray;
import jdk.test.lib.jittester.types.TypeBoolean;
import jdk.test.lib.jittester.types.TypeByte;
import jdk.test.lib.jittester.types.TypeChar;
import jdk.test.lib.jittester.types.TypeDouble;
import jdk.test.lib.jittester.types.TypeFloat;
import jdk.test.lib.jittester.types.TypeInt;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeLong;
import jdk.test.lib.jittester.types.TypeShort;
import jdk.test.lib.jittester.types.TypeVoid;
public class TypeList {
private static final TypeVoid TYPE_VOID = new TypeVoid();
public static final TypeVoid VOID = new TypeVoid();
public static final TypeBoolean BOOLEAN = new TypeBoolean();
public static final TypeByte BYTE = new TypeByte();
public static final TypeChar CHAR = new TypeChar();
public static final TypeShort SHORT = new TypeShort();
public static final TypeInt INT = new TypeInt();
public static final TypeLong LONG = new TypeLong();
public static final TypeFloat FLOAT = new TypeFloat();
public static final TypeDouble DOUBLE = new TypeDouble();
public static final TypeKlass OBJECT = new TypeKlass("java.lang.Object");
public static final TypeKlass STRING = new TypeKlass("java.lang.String", TypeKlass.FINAL);
private static final List<Type> TYPES = new ArrayList<>();
private static final List<Type> BUILTIN_TYPES = new ArrayList<>();
private static final List<Type> BUILTIN_INT_TYPES = new ArrayList<>();
@ -47,14 +59,14 @@ public class TypeList {
private static final List<Type> REFERENCE_TYPES = new ArrayList<>();
static {
BUILTIN_INT_TYPES.add(new TypeBoolean());
BUILTIN_INT_TYPES.add(new TypeByte());
BUILTIN_INT_TYPES.add(new TypeChar());
BUILTIN_INT_TYPES.add(new TypeShort());
BUILTIN_INT_TYPES.add(new TypeInt());
BUILTIN_INT_TYPES.add(new TypeLong());
BUILTIN_FP_TYPES.add(new TypeFloat());
BUILTIN_FP_TYPES.add(new TypeDouble());
BUILTIN_INT_TYPES.add(BOOLEAN);
BUILTIN_INT_TYPES.add(BYTE);
BUILTIN_INT_TYPES.add(CHAR);
BUILTIN_INT_TYPES.add(SHORT);
BUILTIN_INT_TYPES.add(INT);
BUILTIN_INT_TYPES.add(LONG);
BUILTIN_FP_TYPES.add(FLOAT);
BUILTIN_FP_TYPES.add(DOUBLE);
BUILTIN_TYPES.addAll(BUILTIN_INT_TYPES);
BUILTIN_TYPES.addAll(BUILTIN_FP_TYPES);
@ -62,13 +74,13 @@ public class TypeList {
TYPES.addAll(BUILTIN_TYPES);
if (!ProductionParams.disableArrays.value()) {
REFERENCE_TYPES.add(new TypeArray().produce());
TYPES.addAll(REFERENCE_TYPES);
}
}
public static TypeVoid getVoid() {
return TYPE_VOID;
STRING.addParent(OBJECT.getName());
STRING.setParent(OBJECT);
add(STRING);
add(OBJECT);
}
public static Collection<Type> getAll() {
@ -100,14 +112,14 @@ public class TypeList {
}
public static boolean isBuiltIn(Type t) {
return isBuiltInInt(t) || isBuiltInFP(t);
return isBuiltInInt(t) || isBuiltInFP(t) || t.equals(VOID);
}
protected static boolean isIn(Type t) {
return TYPES.contains(t);
}
protected static boolean isReferenceType(Type t) {
public static boolean isReferenceType(Type t) {
return REFERENCE_TYPES.contains(t);
}

View File

@ -42,7 +42,6 @@ import jdk.test.lib.Asserts;
import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.types.TypeArray;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeVoid;
/**
* Class used for parsing included classes file and excluded methods file
@ -62,7 +61,7 @@ public class TypesParser {
public static void parseTypesAndMethods(String klassesFileName, String exMethodsFileName) {
Asserts.assertNotNull(klassesFileName, "Classes input file name is null");
Asserts.assertFalse(klassesFileName.isEmpty(), "Classes input file name is empty");
Set<Class<?>> klasses = parseKlasses(klassesFileName);
List<Class<?>> klasses = parseKlasses(klassesFileName);
Set<Executable> methodsToExclude;
if (exMethodsFileName != null && !exMethodsFileName.isEmpty()) {
methodsToExclude = parseMethods(exMethodsFileName);
@ -119,15 +118,18 @@ public class TypesParser {
}
if (klass.isPrimitive()) {
if (klass.equals(void.class)) {
type = new TypeVoid();
type = TypeList.VOID;
} else {
type = TypeList.find(klass.getName());
}
} else {
int flags = getKlassFlags(klass);
if (klass.isArray()) {
TypeKlass elementType
= new TypeKlass(klass.getCanonicalName().replaceAll("\\[\\]", ""), flags);
Class<?> elementKlass = klass.getComponentType();
while (elementKlass.isArray()) {
elementKlass = elementKlass.getComponentType();
}
Type elementType = getType(elementKlass);
int dim = getArrayClassDimension(klass);
type = new TypeArray(elementType, dim);
} else {
@ -138,10 +140,14 @@ public class TypesParser {
type = new TypeKlass(canonicalName, flags);
}
Class<?> parentKlass = klass.getSuperclass();
TypeKlass typeKlass = (TypeKlass) type;
if (parentKlass != null) {
TypeKlass parentTypeKlass = (TypeKlass) getType(parentKlass);
((TypeKlass) type).addParent(parentTypeKlass.getName());
((TypeKlass) type).setParent(parentTypeKlass);
typeKlass.addParent(parentTypeKlass.getName());
typeKlass.setParent(parentTypeKlass);
}
for (Class<?> iface : klass.getInterfaces()) {
typeKlass.addParent(getType(iface).getName());
}
}
TYPE_CACHE.put(klass, type);
@ -197,10 +203,10 @@ public class TypesParser {
return flags;
}
private static Set<Class<?>> parseKlasses(String klassesFileName) {
private static List<Class<?>> parseKlasses(String klassesFileName) {
Asserts.assertNotNull(klassesFileName, "Classes input file name is null");
Asserts.assertFalse(klassesFileName.isEmpty(), "Classes input file name is empty");
Set<String> klassNamesSet = new HashSet<>();
List<String> klassNamesList = new ArrayList<>();
Path klassesFilePath = (new File(klassesFileName)).toPath();
try {
Files.lines(klassesFilePath).forEach(line -> {
@ -211,20 +217,20 @@ public class TypesParser {
String msg = String.format("Format of the classes input file \"%s\" is incorrect,"
+ " line \"%s\" has wrong format", klassesFileName, line);
Asserts.assertTrue(line.matches("\\w[\\w\\.$]*"), msg);
klassNamesSet.add(line.replaceAll(";", ""));
klassNamesList.add(line.replaceAll(";", ""));
});
} catch (IOException ex) {
throw new Error("Error reading klasses file", ex);
}
Set<Class<?>> klassesSet = new HashSet<>();
klassNamesSet.stream().forEach(klassName -> {
List<Class<?>> klassesList = new ArrayList<>();
klassNamesList.stream().forEach(klassName -> {
try {
klassesSet.add(Class.forName(klassName));
klassesList.add(Class.forName(klassName));
} catch (ClassNotFoundException ex) {
throw new Error("Unexpected exception while parsing klasses file", ex);
}
});
return klassesSet;
return klassesList;
}
private static Set<Executable> parseMethods(String methodsFileName) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2016, 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
@ -26,12 +26,8 @@ package jdk.test.lib.jittester;
import jdk.test.lib.jittester.visitors.Visitor;
public class UnaryOperator extends Operator {
protected OperatorKind opKind;
protected Type resultType;
public UnaryOperator(OperatorKind opKind, IRNode expression) {
super(opKind.priority);
this.opKind = opKind;
super(opKind, expression.getResultType());
addChild(expression);
}
@ -49,8 +45,4 @@ public class UnaryOperator extends Operator {
public boolean isPrefix() {
return opKind.isPrefix;
}
public String getOperatorText() {
return opKind.text;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2016, 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
@ -23,7 +23,14 @@
package jdk.test.lib.jittester;
public interface VariableBase {
public abstract class VariableBase extends IRNode {
private final VariableInfo variableInfo;
protected VariableBase(VariableInfo variableInfo) {
super(variableInfo.type);
this.variableInfo = variableInfo;
}
VariableInfo get();
public VariableInfo getVariableInfo() {
return variableInfo;
}
}

View File

@ -26,9 +26,10 @@ package jdk.test.lib.jittester;
import jdk.test.lib.jittester.visitors.Visitor;
public class VariableDeclaration extends IRNode {
protected final VariableInfo variableInfo;
private final VariableInfo variableInfo;
public VariableDeclaration(VariableInfo value) {
super(value.type);
variableInfo = value;
}

View File

@ -24,10 +24,12 @@
package jdk.test.lib.jittester;
import java.util.ArrayList;
import jdk.test.lib.jittester.visitors.Visitor;
public class VariableDeclarationBlock extends IRNode {
public VariableDeclarationBlock(ArrayList<IRNode> content, int level) {
public VariableDeclarationBlock(ArrayList<? extends Declaration> content, int level) {
super(TypeList.VOID);
addChildren(content);
this.level = level;
}
@ -40,10 +42,6 @@ public class VariableDeclarationBlock extends IRNode {
.sum();
}
protected int size() {
return getChildren() != null ? getChildren().size() : 0;
}
@Override
public<T> T accept(Visitor<T> v) {
return v.visit(this);

View File

@ -55,4 +55,8 @@ public class VariableInfo extends Symbol {
public Symbol deepCopy() {
return new VariableInfo(this);
}
public boolean isLocal() {
return (flags & LOCAL) != 0;
}
}

View File

@ -28,7 +28,6 @@ import java.util.List;
import java.util.stream.Collectors;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.Literal;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.VariableDeclaration;
import jdk.test.lib.jittester.types.TypeArray;
import jdk.test.lib.jittester.visitors.Visitor;
@ -39,6 +38,7 @@ public class ArrayCreation extends IRNode {
private final List<Byte> dims;
public ArrayCreation(VariableDeclaration var, TypeArray array, ArrayList<IRNode> dimensionSizeExpressions) {
super(array);
this.variable = var;
this.array = array;
addChildren(dimensionSizeExpressions);
@ -55,8 +55,8 @@ public class ArrayCreation extends IRNode {
type.setDimentions(dims);
}
public Type getArrayType() {
return array.type;
public TypeArray getArrayType() {
return array;
}
@Override

View File

@ -25,10 +25,12 @@ package jdk.test.lib.jittester.arrays;
import java.util.ArrayList;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.types.TypeArray;
import jdk.test.lib.jittester.visitors.Visitor;
public class ArrayElement extends IRNode {
public ArrayElement(IRNode array, ArrayList<IRNode> dimensionExpressions) {
super(((TypeArray) array.getResultType()).type);
addChild(array);
addChildren(dimensionExpressions);
}

View File

@ -40,6 +40,7 @@ dimentions, where N < M.
public class ArrayExtraction extends IRNode {
private final List<Byte> dims;
public ArrayExtraction(IRNode array, ArrayList<IRNode> dimensionExpressions) {
super(array.getResultType());
addChild(array);
addChildren(dimensionExpressions);
if (array instanceof ArrayCreation) {
@ -56,7 +57,7 @@ public class ArrayExtraction extends IRNode {
}
} else if (array instanceof LocalVariable) {
LocalVariable loc = (LocalVariable) array;
TypeArray type = (TypeArray) loc.get().type;
TypeArray type = (TypeArray) loc.getVariableInfo().type;
dims = type.getDims();
for (int i = dimensionExpressions.size(); i < type.dimensions; ++i) {
dims.add(type.getDims().get(i));

View File

@ -25,10 +25,12 @@ package jdk.test.lib.jittester.classes;
import java.util.ArrayList;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.visitors.Visitor;
public class ClassDefinitionBlock extends IRNode {
public ClassDefinitionBlock(ArrayList<IRNode> content, int level) {
super(TypeList.VOID);
this.level = level;
addChildren(content);
}

View File

@ -24,6 +24,7 @@
package jdk.test.lib.jittester.classes;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.visitors.Visitor;
@ -32,6 +33,7 @@ public class Interface extends IRNode {
private TypeKlass parent = null;
public Interface(TypeKlass parent, String name, int level, IRNode functionDeclaraionBlock) {
super(TypeList.find(functionDeclaraionBlock.getOwner().getName()));
this.parent = parent;
this.name = name;
this.level = level;

View File

@ -70,19 +70,21 @@ public class Klass extends IRNode {
IRNode functionDefinitions, IRNode abstractFunctionRedefinitions,
IRNode overridenFunctionRedefitions, IRNode functionDeclarations,
IRNode printVariablesBlock) {
super(thisKlass);
this.thisKlass = thisKlass;
klass = thisKlass;
owner = thisKlass;
this.parentKlass = parent;
this.interfaces = interfaces;
this.name = name;
this.level = level;
addChild(variableDeclarations);
addChild(constructorDefinitions);
addChild(abstractFunctionRedefinitions);
addChild(overridenFunctionRedefitions);
addChild(functionDefinitions);
addChild(functionDeclarations);
addChild(printVariablesBlock);
resizeUpChildren(KlassPart.values().length);
setChild(KlassPart.DATA_MEMBERS.ordinal(), variableDeclarations);
setChild(KlassPart.CONSTRUCTORS.ordinal(), constructorDefinitions);
setChild(KlassPart.REDEFINED_FUNCTIONS.ordinal(), abstractFunctionRedefinitions);
setChild(KlassPart.OVERRIDEN_FUNCTIONS.ordinal(), overridenFunctionRedefitions);
setChild(KlassPart.MEMBER_FUNCTIONS.ordinal(), functionDefinitions);
setChild(KlassPart.MEMBER_FUNCTIONS_DECLARATIONS.ordinal(), functionDeclarations);
setChild(KlassPart.PRINT_VARIABLES.ordinal(), printVariablesBlock);
}
@Override

View File

@ -40,6 +40,7 @@ public class MainKlass extends IRNode {
public MainKlass(String name, TypeKlass thisKlass, IRNode variableDeclarations,
IRNode functionDefinitions, IRNode testFunction, IRNode printVariables) {
super(thisKlass);
addChild(variableDeclarations);
addChild(functionDefinitions);
addChild(testFunction);
@ -64,4 +65,8 @@ public class MainKlass extends IRNode {
public String getName() {
return name;
}
public TypeKlass getThisKlass() {
return thisKlass;
}
}

View File

@ -33,7 +33,7 @@ import jdk.test.lib.jittester.functions.ArgumentDeclaration;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
class ArgumentDeclarationFactory extends Factory {
class ArgumentDeclarationFactory extends Factory<ArgumentDeclaration> {
private final int argumentNumber;
private final TypeKlass ownerClass;

View File

@ -23,15 +23,15 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.Operator;
import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Rule;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.types.TypeKlass;
class ArithmeticOperatorFactory extends Factory {
private final Rule rule;
class ArithmeticOperatorFactory extends Factory<Operator> {
private final Rule<Operator> rule;
ArithmeticOperatorFactory(long complexityLimit, int operatorLimit, TypeKlass ownerClass,
Type resultType, boolean exceptionSafe, boolean noconsts) throws ProductionFailedException {
@ -42,7 +42,7 @@ class ArithmeticOperatorFactory extends Factory {
.setResultType(resultType)
.setExceptionSafe(exceptionSafe)
.setNoConsts(noconsts);
rule = new Rule("arithmetic");
rule = new Rule<>("arithmetic");
rule.add("add", builder.setOperatorKind(OperatorKind.ADD).getBinaryOperatorFactory());
rule.add("sub", builder.setOperatorKind(OperatorKind.SUB).getBinaryOperatorFactory());
rule.add("mul", builder.setOperatorKind(OperatorKind.MUL).getBinaryOperatorFactory());
@ -55,7 +55,7 @@ class ArithmeticOperatorFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public Operator produce() throws ProductionFailedException {
return rule.produce();
}
}

View File

@ -29,15 +29,14 @@ import jdk.test.lib.jittester.Literal;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.ProductionParams;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.VariableDeclaration;
import jdk.test.lib.jittester.arrays.ArrayCreation;
import jdk.test.lib.jittester.types.TypeArray;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeByte;
import jdk.test.lib.jittester.types.TypeVoid;
import jdk.test.lib.jittester.utils.PseudoRandom;
class ArrayCreationFactory extends SafeFactory {
class ArrayCreationFactory extends SafeFactory<ArrayCreation> {
private final long complexityLimit;
private final int operatorLimit;
private final Type resultType;
@ -56,16 +55,16 @@ class ArrayCreationFactory extends SafeFactory {
}
@Override
protected IRNode sproduce() throws ProductionFailedException {
protected ArrayCreation sproduce() throws ProductionFailedException {
if (resultType instanceof TypeArray) {
TypeArray arrayResultType = (TypeArray) resultType;
if (arrayResultType.type.equals(new TypeVoid())) {
if (arrayResultType.type.equals(TypeList.VOID)) {
arrayResultType = arrayResultType.produce();
}
IRNodeBuilder builder = new IRNodeBuilder()
.setComplexityLimit(complexityLimit)
.setOwnerKlass(ownerClass)
.setResultType(new TypeByte())
.setResultType(TypeList.BYTE)
.setExceptionSafe(exceptionSafe)
.setNoConsts(noconsts);
double chanceExpression = ProductionParams.chanceExpressionIndex.value() / 100;
@ -77,14 +76,14 @@ class ArrayCreationFactory extends SafeFactory {
.getExpressionFactory()
.produce());
} else {
Literal dimension = (Literal)builder.getLiteralFactory().produce();
Literal dimension = builder.getLiteralFactory().produce();
while (Integer.valueOf(dimension.getValue().toString()) < 1) {
dimension = (Literal)builder.getLiteralFactory().produce();
dimension = builder.getLiteralFactory().produce();
}
dims.add(dimension);
}
}
VariableDeclaration var = (VariableDeclaration) builder
VariableDeclaration var = builder
.setOwnerKlass(ownerClass)
.setResultType(arrayResultType)
.setIsLocal(true)

View File

@ -29,15 +29,15 @@ import jdk.test.lib.jittester.Literal;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.ProductionParams;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.arrays.ArrayCreation;
import jdk.test.lib.jittester.arrays.ArrayElement;
import jdk.test.lib.jittester.arrays.ArrayExtraction;
import jdk.test.lib.jittester.types.TypeArray;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeByte;
import jdk.test.lib.jittester.utils.PseudoRandom;
class ArrayElementFactory extends SafeFactory {
class ArrayElementFactory extends SafeFactory<ArrayElement> {
private final long complexityLimit;
private final int operatorLimit;
private final Type resultType;
@ -56,7 +56,7 @@ class ArrayElementFactory extends SafeFactory {
}
@Override
protected IRNode sproduce() throws ProductionFailedException {
protected ArrayElement sproduce() throws ProductionFailedException {
if (resultType instanceof TypeArray) {
throw new ProductionFailedException();
}
@ -76,10 +76,10 @@ class ArrayElementFactory extends SafeFactory {
.setResultType(new TypeArray(resultType, dimensionsCount))
.getExpressionFactory()
.produce();
ExpressionFactory expressionFactory = builder
Factory<IRNode> expressionFactory = builder
.setComplexityLimit(complexityPerDimension)
.setOperatorLimit(operatorLimitPerDimension)
.setResultType(new TypeByte())
.setResultType(TypeList.BYTE)
.getExpressionFactory();
double chanceExpression = ProductionParams.chanceExpressionIndex.value() / 100.;
ArrayList<IRNode> perDimensionExpressions = new ArrayList<>(dimensionsCount);
@ -96,7 +96,7 @@ class ArrayElementFactory extends SafeFactory {
if (i < arrayExtraction.getDimsNumber())
dimLimit = arrayExtraction.getDim(i);
}
perDimensionExpressions.add(new Literal(PseudoRandom.randomNotNegative(dimLimit), new TypeByte()));
perDimensionExpressions.add(new Literal((byte)PseudoRandom.randomNotNegative(dimLimit), TypeList.BYTE));
}
}
return new ArrayElement(arrayReturningExpression, perDimensionExpressions);

View File

@ -29,14 +29,14 @@ import jdk.test.lib.jittester.Literal;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.ProductionParams;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.arrays.ArrayCreation;
import jdk.test.lib.jittester.arrays.ArrayExtraction;
import jdk.test.lib.jittester.types.TypeArray;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeByte;
import jdk.test.lib.jittester.utils.PseudoRandom;
class ArrayExtractionFactory extends SafeFactory {
class ArrayExtractionFactory extends SafeFactory<ArrayExtraction> {
private final long complexityLimit;
private final int operatorLimit;
private final Type resultType;
@ -55,7 +55,7 @@ class ArrayExtractionFactory extends SafeFactory {
}
@Override
public IRNode sproduce() throws ProductionFailedException {
public ArrayExtraction sproduce() throws ProductionFailedException {
if (resultType instanceof TypeArray) {
TypeArray arrayType = (TypeArray) resultType;
int delta = PseudoRandom.randomNotZero(ProductionParams.dimensionsLimit.value()
@ -79,7 +79,7 @@ class ArrayExtractionFactory extends SafeFactory {
double chanceExpression = ProductionParams.chanceExpressionIndex.value() / 100.;
for (int i = 0; i < delta; i++) {
if (PseudoRandom.randomBoolean(chanceExpression)) {
perDimensionExpression.add(builder.setResultType(new TypeByte())
perDimensionExpression.add(builder.setResultType(TypeList.BYTE)
.setComplexityLimit(dimComplLimit)
.setOperatorLimit(dimOpLimit)
.getExpressionFactory()
@ -94,7 +94,7 @@ class ArrayExtractionFactory extends SafeFactory {
if (i < arrayExtraction.getDimsNumber())
dimLimit = arrayExtraction.getDim(i);
}
perDimensionExpression.add(new Literal(PseudoRandom.randomNotNegative(dimLimit), new TypeByte()));
perDimensionExpression.add(new Literal((byte)PseudoRandom.randomNotNegative(dimLimit), TypeList.BYTE));
}
}
return new ArrayExtraction(arrayReturningExpression, perDimensionExpression);

View File

@ -24,7 +24,8 @@
package jdk.test.lib.jittester.factories;
import java.util.ArrayList;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.Operator;
import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Rule;
@ -34,7 +35,7 @@ import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
class AssignmentOperatorFactory extends Factory {
class AssignmentOperatorFactory extends Factory<Operator> {
private final int operatorLimit;
private final long complexityLimit;
private final Type resultType;
@ -42,8 +43,8 @@ class AssignmentOperatorFactory extends Factory {
private final boolean noconsts;
private final TypeKlass ownerClass;
private Rule fillRule(Type resultType) throws ProductionFailedException {
Rule rule = new Rule("assignment");
private Rule<Operator> fillRule(Type resultType) throws ProductionFailedException {
Rule<Operator> rule = new Rule<>("assignment");
IRNodeBuilder builder = new IRNodeBuilder()
.setComplexityLimit(complexityLimit)
.setOperatorLimit(operatorLimit)
@ -84,14 +85,14 @@ class AssignmentOperatorFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public Operator produce() throws ProductionFailedException {
if (resultType == null) { // if no result type is given - choose any.
ArrayList<Type> allTypes = new ArrayList<>(TypeList.getAll());
PseudoRandom.shuffle(allTypes);
for (Type type : allTypes) {
SymbolTable.push();
try {
IRNode result = fillRule(type).produce();
Operator result = fillRule(type).produce();
SymbolTable.merge();
return result;
} catch (ProductionFailedException e) {

View File

@ -31,8 +31,8 @@ import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Rule;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.utils.TypeUtil;
import jdk.test.lib.jittester.VariableBase;
import jdk.test.lib.jittester.utils.TypeUtil;
import jdk.test.lib.jittester.VariableInfo;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
@ -49,7 +49,7 @@ class AssignmentOperatorImplFactory extends BinaryOperatorFactory {
}
@Override
protected Pair<Type, Type> generateTypes() throws ProductionFailedException {
protected Pair<Type, Type> generateTypes() {
return new Pair<>(resultType, PseudoRandom.randomElement(
TypeUtil.getImplicitlyCastable(TypeList.getAll(), resultType)));
}
@ -68,23 +68,22 @@ class AssignmentOperatorImplFactory extends BinaryOperatorFactory {
.setOperatorLimit(leftOperatorLimit)
.setResultType(leftOperandType)
.setIsConstant(false);
Rule rule = new Rule("assignment");
Rule<VariableBase> rule = new Rule<>("assignment");
rule.add("initialized_nonconst_var", builder.setIsInitialized(true).getVariableFactory());
rule.add("uninitialized_nonconst_var", builder.setIsInitialized(false).getVariableFactory());
IRNode leftOperandValue = rule.produce();
VariableBase leftOperandValue = rule.produce();
IRNode rightOperandValue = builder.setComplexityLimit(rightComplexityLimit)
.setOperatorLimit(rightOperatorLimit)
.setResultType(rightOperandType)
.getExpressionFactory()
.produce();
try {
VariableBase v = (VariableBase) leftOperandValue;
if ((v.get().flags & VariableInfo.INITIALIZED) == 0) {
v.get().flags |= VariableInfo.INITIALIZED;
if ((leftOperandValue.getVariableInfo().flags & VariableInfo.INITIALIZED) == 0) {
leftOperandValue.getVariableInfo().flags |= VariableInfo.INITIALIZED;
}
} catch (Exception e) {
throw new ProductionFailedException(e.getMessage());
}
return new BinaryOperator(opKind, leftOperandValue, rightOperandValue);
return new BinaryOperator(opKind, resultType, leftOperandValue, rightOperandValue);
}
}

View File

@ -30,7 +30,6 @@ import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.utils.TypeUtil;
import jdk.test.lib.jittester.types.TypeInt;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
@ -47,18 +46,18 @@ class BinaryArithmeticOperatorFactory extends BinaryOperatorFactory {
// arithmetic for built-in types less capacious than "int" is not supported.
if (TypeList.isBuiltIn(resultType)) {
BuiltInType builtInType = (BuiltInType) resultType;
return builtInType.equals(new TypeInt()) || builtInType.isMoreCapaciousThan(new TypeInt());
return builtInType.equals(TypeList.INT) || builtInType.isMoreCapaciousThan(TypeList.INT);
} else {
return false;
}
}
@Override
protected Pair<Type, Type> generateTypes() throws ProductionFailedException {
protected Pair<Type, Type> generateTypes() {
Collection<Type> castableFromResultType = TypeUtil.getImplicitlyCastable(TypeList.getBuiltIn(), resultType);
// built-in types less capacious than int are automatically casted to int in arithmetic.
final Type leftType = PseudoRandom.randomElement(castableFromResultType);
final Type rightType = resultType.equals(new TypeInt()) ?
final Type rightType = resultType.equals(TypeList.INT) ?
PseudoRandom.randomElement(castableFromResultType) : resultType;
//TODO: is there sense to swap them randomly as it was done in original code?
return PseudoRandom.randomBoolean() ? new Pair<>(leftType, rightType) : new Pair<>(rightType, leftType);

View File

@ -29,10 +29,7 @@ import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.utils.TypeUtil;
import jdk.test.lib.jittester.types.TypeBoolean;
import jdk.test.lib.jittester.types.TypeInt;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeLong;
import jdk.test.lib.jittester.utils.PseudoRandom;
import java.util.Collection;
@ -45,15 +42,15 @@ class BinaryBitwiseOperatorFactory extends BinaryOperatorFactory {
@Override
protected boolean isApplicable(Type resultType) {
return resultType.equals(new TypeInt()) || resultType.equals(new TypeLong()) || resultType.equals(new TypeBoolean());
return resultType.equals(TypeList.INT) || resultType.equals(TypeList.LONG) || resultType.equals(TypeList.BOOLEAN);
}
@Override
protected Pair<Type, Type> generateTypes() throws ProductionFailedException {
protected Pair<Type, Type> generateTypes() {
Collection<Type> castableFromResult = TypeUtil.getImplicitlyCastable(TypeList.getBuiltIn(), resultType);
// built-in types less capacious than int are automatically casted to int in arithmetic.
final Type leftType = PseudoRandom.randomElement(castableFromResult);
final Type rightType = resultType.equals(new TypeInt()) ? PseudoRandom.randomElement(castableFromResult) : resultType;
final Type rightType = resultType.equals(TypeList.INT) ? PseudoRandom.randomElement(castableFromResult) : resultType;
//TODO: is there sense to swap them randomly as it was done in original code?
return PseudoRandom.randomBoolean() ? new Pair<>(leftType, rightType) : new Pair<>(rightType, leftType);
}

View File

@ -28,7 +28,6 @@ import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.types.TypeBoolean;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
@ -43,13 +42,13 @@ class BinaryComparisonOperatorFactory extends BinaryOperatorFactory {
@Override
protected boolean isApplicable(Type resultType) {
return resultType.equals(new TypeBoolean());
return resultType.equals(TypeList.BOOLEAN);
}
@Override
protected Pair<Type, Type> generateTypes() throws ProductionFailedException {
protected Pair<Type, Type> generateTypes() {
final List<Type> builtInExceptBoolean = new ArrayList<>(TypeList.getBuiltIn());
builtInExceptBoolean.remove(new TypeBoolean());
builtInExceptBoolean.remove(TypeList.BOOLEAN);
return new Pair<>(PseudoRandom.randomElement(builtInExceptBoolean),
PseudoRandom.randomElement(builtInExceptBoolean));
}

View File

@ -28,7 +28,6 @@ import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.types.TypeBoolean;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
@ -43,13 +42,13 @@ class BinaryEqualityOperatorFactory extends BinaryOperatorFactory {
@Override
protected boolean isApplicable(Type resultType) {
return resultType.equals(new TypeBoolean());
return resultType.equals(TypeList.BOOLEAN);
}
@Override
protected Pair<Type, Type> generateTypes() throws ProductionFailedException {
protected Pair<Type, Type> generateTypes() {
final List<Type> builtInExceptBoolean = new ArrayList<>(TypeList.getBuiltIn());
builtInExceptBoolean.remove(new TypeBoolean());
builtInExceptBoolean.remove(TypeList.BOOLEAN);
return new Pair<>(PseudoRandom.randomElement(builtInExceptBoolean), PseudoRandom.randomElement(builtInExceptBoolean));
}
}

View File

@ -30,7 +30,7 @@ import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.SymbolTable;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.types.TypeBoolean;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
@ -42,11 +42,11 @@ public class BinaryLogicOperatorFactory extends BinaryOperatorFactory {
@Override
protected boolean isApplicable(Type resultType) {
return resultType.equals(new TypeBoolean());
return resultType.equals(TypeList.BOOLEAN);
}
@Override
protected Pair<Type, Type> generateTypes() throws ProductionFailedException {
protected Pair<Type, Type> generateTypes() {
return new Pair<>(resultType, resultType);
}
@ -81,6 +81,6 @@ public class BinaryLogicOperatorFactory extends BinaryOperatorFactory {
} finally {
SymbolTable.pop();
}
return new BinaryOperator(opKind, leftOperand, rightOperand);
return new BinaryOperator(opKind, resultType, leftOperand, rightOperand);
}
}

View File

@ -33,7 +33,7 @@ import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
abstract class BinaryOperatorFactory extends OperatorFactory {
abstract class BinaryOperatorFactory extends OperatorFactory<BinaryOperator> {
protected final OperatorKind opKind;
protected final Type resultType;
protected final Type ownerClass;
@ -48,7 +48,7 @@ abstract class BinaryOperatorFactory extends OperatorFactory {
protected abstract boolean isApplicable(Type resultType);
protected abstract Pair<Type, Type> generateTypes() throws ProductionFailedException;
protected abstract Pair<Type, Type> generateTypes();
protected BinaryOperator generateProduction(Type leftType, Type rightType) throws ProductionFailedException {
int leftOpLimit = (int) (PseudoRandom.random() * (operatorLimit - 1));
@ -72,11 +72,11 @@ abstract class BinaryOperatorFactory extends OperatorFactory {
.setResultType(rightType)
.getExpressionFactory()
.produce();
return new BinaryOperator(opKind, leftExpr, rightExpr);
return new BinaryOperator(opKind, resultType, leftExpr, rightExpr);
}
@Override
public final IRNode produce() throws ProductionFailedException {
public final BinaryOperator produce() throws ProductionFailedException {
if (!isApplicable(resultType)) {
//avoid implicit use of resultType.toString()
throw new ProductionFailedException("Type " + resultType.getName() + " is not applicable by " + getClass().getName());
@ -91,7 +91,7 @@ abstract class BinaryOperatorFactory extends OperatorFactory {
try {
SymbolTable.push();
IRNode p = generateProduction(types.first, types.second);
BinaryOperator p = generateProduction(types.first, types.second);
SymbolTable.merge();
return p;
} catch (ProductionFailedException e) {

View File

@ -28,9 +28,7 @@ import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.types.TypeInt;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeLong;
import jdk.test.lib.jittester.utils.PseudoRandom;
import jdk.test.lib.jittester.utils.TypeUtil;
@ -42,13 +40,13 @@ class BinaryShiftOperatorFactory extends BinaryOperatorFactory {
@Override
protected boolean isApplicable(Type resultType) {
return resultType.equals(new TypeInt()) || resultType.equals(new TypeLong());
return resultType.equals(TypeList.INT) || resultType.equals(TypeList.LONG);
}
@Override
protected Pair<Type, Type> generateTypes() throws ProductionFailedException {
Type leftType = resultType.equals(new TypeInt()) ? PseudoRandom.randomElement(TypeUtil.getImplicitlyCastable(TypeList.getBuiltInInt(), resultType)) : resultType;
Type rightType = PseudoRandom.randomElement(TypeUtil.getImplicitlyCastable(TypeList.getBuiltInInt(), new TypeLong()));
protected Pair<Type, Type> generateTypes() {
Type leftType = resultType.equals(TypeList.INT) ? PseudoRandom.randomElement(TypeUtil.getImplicitlyCastable(TypeList.getBuiltInInt(), resultType)) : resultType;
Type rightType = PseudoRandom.randomElement(TypeUtil.getImplicitlyCastable(TypeList.getBuiltInInt(), TypeList.LONG));
return new Pair<>(leftType, rightType);
}
}

View File

@ -38,11 +38,11 @@ class BinaryStringPlusFactory extends BinaryOperatorFactory {
@Override
protected boolean isApplicable(Type resultType) {
return resultType.equals(TypeList.find("java.lang.String"));
}
return resultType.equals(TypeList.STRING);
}
@Override
protected Pair<Type, Type> generateTypes() throws ProductionFailedException {
protected Pair<Type, Type> generateTypes() {
return new Pair<>(resultType, resultType);
}
}

View File

@ -23,7 +23,6 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Type;
@ -31,8 +30,6 @@ import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.utils.TypeUtil;
import jdk.test.lib.jittester.UnaryOperator;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeInt;
import jdk.test.lib.jittester.types.TypeLong;
import jdk.test.lib.jittester.utils.PseudoRandom;
class BitwiseInversionOperatorFactory extends UnaryOperatorFactory {
@ -43,12 +40,12 @@ class BitwiseInversionOperatorFactory extends UnaryOperatorFactory {
@Override
protected boolean isApplicable(Type resultType) {
return resultType.equals(new TypeInt()) || resultType.equals(new TypeLong());
return resultType.equals(TypeList.INT) || resultType.equals(TypeList.LONG);
}
@Override
protected Type generateType() throws ProductionFailedException {
if (resultType.equals(new TypeInt())) {
protected Type generateType() {
if (resultType.equals(TypeList.INT)) {
return PseudoRandom.randomElement(TypeUtil.getImplicitlyCastable(TypeList.getBuiltIn(), resultType));
} else {
return resultType;
@ -56,7 +53,7 @@ class BitwiseInversionOperatorFactory extends UnaryOperatorFactory {
}
@Override
protected IRNode generateProduction(Type resultType) throws ProductionFailedException {
protected UnaryOperator generateProduction(Type resultType) throws ProductionFailedException {
return new UnaryOperator(opKind, new IRNodeBuilder().setComplexityLimit(complexityLimit - 1)
.setOperatorLimit(operatorLimit - 1)
.setOwnerKlass((TypeKlass) ownerClass)

View File

@ -23,15 +23,15 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.Operator;
import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Rule;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.types.TypeKlass;
class BitwiseOperatorFactory extends Factory {
private final Rule rule;
class BitwiseOperatorFactory extends Factory<Operator> {
private final Rule<Operator> rule;
BitwiseOperatorFactory(long complexityLimit, int operatorLimit, TypeKlass ownerClass,
Type resultType, boolean exceptionSafe, boolean noconsts) throws ProductionFailedException {
@ -42,7 +42,7 @@ class BitwiseOperatorFactory extends Factory {
.setResultType(resultType)
.setExceptionSafe(exceptionSafe)
.setNoConsts(noconsts);
rule = new Rule("bitwise");
rule = new Rule<>("bitwise");
rule.add("and", builder.setOperatorKind(OperatorKind.BIT_AND).getBinaryOperatorFactory());
rule.add("or", builder.setOperatorKind(OperatorKind.BIT_OR).getBinaryOperatorFactory());
rule.add("xor", builder.setOperatorKind(OperatorKind.BIT_XOR).getBinaryOperatorFactory());
@ -53,7 +53,7 @@ class BitwiseOperatorFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public Operator produce() throws ProductionFailedException {
return rule.produce();
}
}

View File

@ -38,13 +38,12 @@ import jdk.test.lib.jittester.loops.DoWhile;
import jdk.test.lib.jittester.loops.For;
import jdk.test.lib.jittester.loops.While;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeVoid;
import jdk.test.lib.jittester.utils.PseudoRandom;
import java.util.ArrayList;
import java.util.List;
class BlockFactory extends Factory {
class BlockFactory extends Factory<Block> {
private final Type returnType;
private final long complexityLimit;
private final int statementLimit;
@ -74,7 +73,7 @@ class BlockFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public Block produce() throws ProductionFailedException {
if (statementLimit > 0 && complexityLimit > 0) {
List<IRNode> content = new ArrayList<>();
int slimit = PseudoRandom.randomNotZero(statementLimit);
@ -89,12 +88,12 @@ class BlockFactory extends Factory {
.setCanHaveContinues(canHaveContinues)
.setExceptionSafe(false)
.setNoConsts(false);
Rule rule;
Rule<IRNode> rule;
SymbolTable.push();
for (int i = 0; i < slimit && climit > 0; ) {
int subLimit = (int) (PseudoRandom.random() * (slimit - i - 1));
builder.setComplexityLimit((long) (PseudoRandom.random() * climit));
rule = new Rule("block");
rule = new Rule<>("block");
rule.add("statement", builder.getStatementFactory(), 5);
if (!ProductionParams.disableVarsInBlock.value()) {
rule.add("decl", builder.setIsLocal(true).getDeclarationFactory());
@ -131,14 +130,14 @@ class BlockFactory extends Factory {
}
}
// Ok, if the block can end with break and continue. Generate the appropriate productions.
rule = new Rule("block_ending");
rule = new Rule<>("block_ending");
if (canHaveBreaks && !subBlock) {
rule.add("break", builder.getBreakFactory());
}
if (canHaveContinues && !subBlock) {
rule.add("continue", builder.getContinueFactory());
}
if (canHaveReturn && !subBlock && !returnType.equals(new TypeVoid())) {
if (canHaveReturn && !subBlock && !returnType.equals(TypeList.VOID)) {
rule.add("return", builder.setComplexityLimit(climit).getReturnFactory());
}
if (canHaveThrow && !subBlock) {
@ -166,7 +165,7 @@ class BlockFactory extends Factory {
throw new ProductionFailedException();
}
private void addControlFlowDeviation(Rule rule, IRNodeBuilder builder) {
private void addControlFlowDeviation(Rule<IRNode> rule, IRNodeBuilder builder) {
if (!ProductionParams.disableIf.value()) {
rule.add("if", builder.getIfFactory());
}

View File

@ -24,12 +24,11 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.Break;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.ProductionFailedException;
class BreakFactory extends Factory {
class BreakFactory extends Factory<Break> {
@Override
public IRNode produce() throws ProductionFailedException {
public Break produce() throws ProductionFailedException {
return new Break();
}
}

View File

@ -33,7 +33,7 @@ import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
class CastOperatorFactory extends OperatorFactory {
class CastOperatorFactory extends OperatorFactory<CastOperator> {
private final Type resultType;
private final Type ownerClass;
@ -45,12 +45,12 @@ class CastOperatorFactory extends OperatorFactory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public CastOperator produce() throws ProductionFailedException {
ArrayList<Type> argType = new ArrayList<>(TypeList.getAll());
PseudoRandom.shuffle(argType);
for (Type type : argType) {
try {
ExpressionFactory expressionFactory = new IRNodeBuilder()
Factory<IRNode> expressionFactory = new IRNodeBuilder()
.setComplexityLimit(complexityLimit - 1)
.setOperatorLimit(operatorLimit - 1)
.setOwnerKlass((TypeKlass) ownerClass)
@ -59,14 +59,11 @@ class CastOperatorFactory extends OperatorFactory {
.setResultType(type)
.getExpressionFactory();
SymbolTable.push();
if (type.equals(resultType)) {
IRNode expr = expressionFactory.produce();
SymbolTable.merge();
return expr;
} else if ((!exceptionSafe || exceptionSafe && !(type instanceof TypeKlass))
&& type.canExplicitlyCastTo(resultType)) {
if (type.equals(resultType) ||
((!exceptionSafe || exceptionSafe && !(type instanceof TypeKlass))
&& type.canExplicitlyCastTo(resultType))) {
// In safe mode we cannot explicitly cast an object, because it may throw.
IRNode castOperator = new CastOperator(resultType, expressionFactory.produce());
CastOperator castOperator = new CastOperator(resultType, expressionFactory.produce());
SymbolTable.merge();
return castOperator;
}

View File

@ -38,7 +38,7 @@ import jdk.test.lib.jittester.classes.Klass;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
class ClassDefinitionBlockFactory extends Factory {
class ClassDefinitionBlockFactory extends Factory<ClassDefinitionBlock> {
private final String prefix;
private final long complexityLimit;
private final int classesLimit;
@ -62,7 +62,7 @@ class ClassDefinitionBlockFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public ClassDefinitionBlock produce() throws ProductionFailedException {
ArrayList<IRNode> content = new ArrayList<>();
int limit = (int) Math.ceil(PseudoRandom.random() * classesLimit);
if (limit > 0) {
@ -74,9 +74,8 @@ class ClassDefinitionBlockFactory extends Factory {
.setComplexityLimit(classCompl);
for (int i = 0; i < limit; i++) {
try {
Rule rule = new Rule("class");
Rule<IRNode> rule = new Rule<>("class");
rule.add("basic_class", builder.setName(prefix + "_Class_" + i)
.setPrinterName(prefix + ".Printer")
.setMemberFunctionsLimit(memberFunctionsLimit)
.getKlassFactory());
if (!ProductionParams.disableInterfaces.value()) {
@ -110,13 +109,12 @@ class ClassDefinitionBlockFactory extends Factory {
IRNode randomChild = childs.get(0);
List<IRNode> leaves = randomChild.getStackableLeaves();
if (!leaves.isEmpty()) {
PseudoRandom.shuffle(leaves);
Block randomLeaf = (Block) leaves.get(0);
TypeKlass klass = (TypeKlass) randomChild.getKlass();
Block randomLeaf = (Block) leaves.get(PseudoRandom.randomNotNegative(leaves.size()));
TypeKlass owner = randomChild.getOwner();
int newLevel = randomLeaf.getLevel() + 1;
Type retType = randomLeaf.getReturnType();
Type retType = randomLeaf.getResultType();
IRNodeBuilder b = new IRNodeBuilder()
.setOwnerKlass(klass)
.setOwnerKlass(owner)
.setResultType(retType)
.setComplexityLimit(complexityLimit)
.setStatementLimit(statementLimit)
@ -137,7 +135,7 @@ class ClassDefinitionBlockFactory extends Factory {
.filter(c -> c instanceof Klass && c.countDepth() > maxDepth)
.collect(Collectors.toList());
for (IRNode ch : childs) {
List<IRNode> leaves = null;
List<IRNode> leaves;
do {
long depth = Math.max(ch.countDepth(), maxDepth + 1);
leaves = ch.getDeviantBlocks(depth);

View File

@ -30,8 +30,8 @@ import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.VariableBase;
import jdk.test.lib.jittester.utils.TypeUtil;
import jdk.test.lib.jittester.types.TypeBoolean;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
@ -43,11 +43,11 @@ class CompoundArithmeticAssignmentOperatorFactory extends BinaryOperatorFactory
@Override
protected boolean isApplicable(Type resultType) {
return TypeList.isBuiltIn(resultType) && !resultType.equals(new TypeBoolean());
return TypeList.isBuiltIn(resultType) && !resultType.equals(TypeList.BOOLEAN);
}
@Override
protected Pair<Type, Type> generateTypes() throws ProductionFailedException {
protected Pair<Type, Type> generateTypes() {
return new Pair<>(resultType, PseudoRandom.randomElement(
TypeUtil.getExplicitlyCastable(TypeList.getBuiltIn(), resultType)));
}
@ -66,13 +66,13 @@ class CompoundArithmeticAssignmentOperatorFactory extends BinaryOperatorFactory
.setResultType(rightType)
.getExpressionFactory()
.produce();
IRNode leftExpr = builder.setComplexityLimit(leftComplexityLimit)
VariableBase leftExpr = builder.setComplexityLimit(leftComplexityLimit)
.setOperatorLimit(leftOperatorLimit)
.setResultType(leftType)
.setIsConstant(false)
.setIsInitialized(true)
.getVariableFactory()
.produce();
return new BinaryOperator(opKind, leftExpr, rightExpr);
return new BinaryOperator(opKind, resultType, leftExpr, rightExpr);
}
}

View File

@ -46,7 +46,7 @@ class CompoundBitwiseAssignmentOperatorFactory extends BinaryOperatorFactory {
}
@Override
protected Pair<Type, Type> generateTypes() throws ProductionFailedException {
protected Pair<Type, Type> generateTypes() {
return new Pair<>(resultType, PseudoRandom.randomElement(TypeUtil.getExplicitlyCastable(TypeList.getBuiltInInt(), resultType)));
}
@ -71,6 +71,6 @@ class CompoundBitwiseAssignmentOperatorFactory extends BinaryOperatorFactory {
.setResultType(rightType)
.getExpressionFactory()
.produce();
return new BinaryOperator(opKind, leftExpr, rightExpr);
return new BinaryOperator(opKind, resultType, leftExpr, rightExpr);
}
}

View File

@ -32,7 +32,6 @@ import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.utils.TypeUtil;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeBoolean;
import jdk.test.lib.jittester.utils.PseudoRandom;
class CompoundShiftAssignmentOperatorFactory extends BinaryOperatorFactory {
@ -43,11 +42,11 @@ class CompoundShiftAssignmentOperatorFactory extends BinaryOperatorFactory {
@Override
protected boolean isApplicable(Type resultType) {
return TypeList.isBuiltInInt(resultType) && !resultType.equals(new TypeBoolean());
return TypeList.isBuiltInInt(resultType) && !resultType.equals(TypeList.BOOLEAN);
}
@Override
protected Pair<Type, Type> generateTypes() throws ProductionFailedException {
protected Pair<Type, Type> generateTypes() {
return new Pair<>(resultType, PseudoRandom.randomElement(
TypeUtil.getExplicitlyCastable(TypeList.getBuiltInInt(), resultType)));
}
@ -73,6 +72,6 @@ class CompoundShiftAssignmentOperatorFactory extends BinaryOperatorFactory {
.setResultType(rightType)
.getExpressionFactory()
.produce();
return new BinaryOperator(opKind, leftExpr, rightExpr);
return new BinaryOperator(opKind, resultType, leftExpr, rightExpr);
}
}

View File

@ -31,7 +31,7 @@ import jdk.test.lib.jittester.functions.ConstructorDefinitionBlock;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
class ConstructorDefinitionBlockFactory extends Factory {
class ConstructorDefinitionBlockFactory extends Factory<ConstructorDefinitionBlock> {
private final long complexityLimit;
private final int statementLimit;
private final int operatorLimit;
@ -53,7 +53,7 @@ class ConstructorDefinitionBlockFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public ConstructorDefinitionBlock produce() throws ProductionFailedException {
IRNodeBuilder builder = new IRNodeBuilder()
.setOwnerKlass(ownerClass)
.setStatementLimit(statementLimit)

View File

@ -28,15 +28,15 @@ import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Symbol;
import jdk.test.lib.jittester.SymbolTable;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.VariableInfo;
import jdk.test.lib.jittester.functions.ArgumentDeclaration;
import jdk.test.lib.jittester.functions.ConstructorDefinition;
import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeVoid;
import jdk.test.lib.jittester.utils.PseudoRandom;
class ConstructorDefinitionFactory extends Factory {
class ConstructorDefinitionFactory extends Factory<ConstructorDefinition> {
private final long complexityLimit;
private final int statementLimit;
private final int operatorLimit;
@ -55,7 +55,7 @@ class ConstructorDefinitionFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public ConstructorDefinition produce() throws ProductionFailedException {
int argNumber = (int) (PseudoRandom.random() * memberFunctionsArgLimit);
ArrayList<VariableInfo> argumentsInfo = new ArrayList<>(argNumber);
ArrayList<ArgumentDeclaration> argumentsDeclaration = new ArrayList<>(argNumber);
@ -90,7 +90,7 @@ class ConstructorDefinitionFactory extends Factory {
}
long blockComplLimit = (long) (PseudoRandom.random() * complexityLimit);
try {
body = builder.setResultType(new TypeVoid())
body = builder.setResultType(TypeList.VOID)
.setComplexityLimit(blockComplLimit)
.setStatementLimit(statementLimit)
.setOperatorLimit(operatorLimit)

View File

@ -24,12 +24,11 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.Continue;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.ProductionFailedException;
class ContinueFactory extends Factory {
class ContinueFactory extends Factory<Continue> {
@Override
public IRNode produce() throws ProductionFailedException {
public Continue produce() throws ProductionFailedException {
return new Continue();
}
}

View File

@ -24,20 +24,20 @@
package jdk.test.lib.jittester.factories;
import java.util.List;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.LiteralInitializer;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.SymbolTable;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.utils.TypeUtil;
import jdk.test.lib.jittester.VariableInfo;
import jdk.test.lib.jittester.utils.TypeUtil;
import jdk.test.lib.jittester.loops.CounterInitializer;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeInt;
import jdk.test.lib.jittester.utils.PseudoRandom;
class CounterInitializerFactory extends SafeFactory {
class CounterInitializerFactory extends SafeFactory<CounterInitializer> {
private final int counterValue;
private final TypeKlass ownerClass;
@ -47,9 +47,9 @@ class CounterInitializerFactory extends SafeFactory {
}
@Override
protected IRNode sproduce() throws ProductionFailedException {
List<Type> types = TypeUtil.getMoreCapaciousThan(TypeList.getBuiltIn(), new TypeInt());
types.add(new TypeInt());
protected CounterInitializer sproduce() throws ProductionFailedException {
List<Type> types = TypeUtil.getMoreCapaciousThan(TypeList.getBuiltIn(), TypeList.INT);
types.add(TypeList.INT);
final Type selectedType = PseudoRandom.randomElement(types);
IRNode init = new LiteralInitializer(counterValue, selectedType);
String resultName = "var_" + SymbolTable.getNextVariableNumber();

View File

@ -27,10 +27,11 @@ import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.LocalVariable;
import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Statement;
import jdk.test.lib.jittester.UnaryOperator;
import jdk.test.lib.jittester.loops.CounterManipulator;
class CounterManipulatorFactory extends Factory {
class CounterManipulatorFactory extends Factory<CounterManipulator> {
private final LocalVariable counter;
CounterManipulatorFactory(LocalVariable counter) {
@ -38,9 +39,9 @@ class CounterManipulatorFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public CounterManipulator produce() throws ProductionFailedException {
// We'll keep it simple for the time being..
IRNode manipulator = new UnaryOperator(OperatorKind.POST_DEC, counter);
return new CounterManipulator(manipulator);
return new CounterManipulator(new Statement(manipulator, false));
}
}

View File

@ -31,7 +31,7 @@ import jdk.test.lib.jittester.Rule;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.types.TypeKlass;
class DeclarationFactory extends Factory {
class DeclarationFactory extends Factory<Declaration> {
private final int operatorLimit;
private final long complexityLimit;
private final boolean isLocal;
@ -48,29 +48,42 @@ class DeclarationFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
Rule rule = new Rule("declaration");
public Declaration produce() throws ProductionFailedException {
Rule<IRNode> rule = new Rule<>("declaration");
IRNodeBuilder builder = new IRNodeBuilder().setOwnerKlass(ownerClass)
.setResultType(TypeList.getVoid())
.setResultType(TypeList.VOID)
.setIsLocal(isLocal)
.setComplexityLimit(complexityLimit)
.setOperatorLimit(operatorLimit)
.setIsLocal(isLocal)
.setExceptionSafe(exceptionSafe);
rule.add("decl", builder.setIsStatic(false).getVariableDeclarationFactory());
rule.add("decl_and_init", builder.setIsConstant(false)
.setIsStatic(false).getVariableInitializationFactory());
rule.add("decl", builder
.setIsStatic(false)
.getVariableDeclarationFactory());
rule.add("decl_and_init", builder
.setIsConstant(false)
.setIsStatic(false)
.getVariableInitializationFactory());
if (!ProductionParams.disableFinalVariables.value()) {
rule.add("const_decl_and_init", builder.setIsConstant(true)
.setIsStatic(false).getVariableInitializationFactory());
rule.add("const_decl_and_init", builder
.setIsConstant(true)
.setIsStatic(false)
.getVariableInitializationFactory());
}
if (!isLocal && !ProductionParams.disableStatic.value()) {
rule.add("static_decl", builder.setIsStatic(true).getVariableDeclarationFactory());
rule.add("static_decl_and_init", builder.setIsConstant(false)
.setIsStatic(true).getVariableInitializationFactory());
rule.add("static_decl", builder
.setIsConstant(false)
.setIsStatic(true)
.getVariableDeclarationFactory());
rule.add("static_decl_and_init", builder
.setIsConstant(false)
.setIsStatic(true)
.getVariableInitializationFactory());
if (!ProductionParams.disableFinalVariables.value()) {
rule.add("static_const_decl_and_init", builder.setIsConstant(true)
.setIsStatic(true).getVariableInitializationFactory());
rule.add("static_const_decl_and_init", builder
.setIsConstant(true)
.setIsStatic(true)
.getVariableInitializationFactory());
}
}
return new Declaration(rule.produce());

View File

@ -23,21 +23,21 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.Initialization;
import jdk.test.lib.jittester.Block;
import jdk.test.lib.jittester.Literal;
import jdk.test.lib.jittester.LocalVariable;
import jdk.test.lib.jittester.Nothing;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.SymbolTable;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.loops.DoWhile;
import jdk.test.lib.jittester.loops.Loop;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeInt;
import jdk.test.lib.jittester.utils.PseudoRandom;
class DoWhileFactory extends SafeFactory {
import java.util.LinkedList;
class DoWhileFactory extends SafeFactory<DoWhile> {
private final Loop loop;
private final long complexityLimit;
private final int statementLimit;
@ -62,7 +62,8 @@ class DoWhileFactory extends SafeFactory {
}
@Override
protected IRNode sproduce() throws ProductionFailedException {
protected DoWhile sproduce() throws ProductionFailedException {
Block emptyBlock = new Block(ownerClass, returnType, new LinkedList<>(), level - 1);
if (statementLimit > 0 && complexityLimit > 0) {
long complexity = complexityLimit;
// Loop header parameters
@ -89,7 +90,7 @@ class DoWhileFactory extends SafeFactory {
.setResultType(returnType)
.setOperatorLimit(operatorLimit);
loop.initialization = builder.getCounterInitializerFactory(0).produce();
IRNode header;
Block header;
try {
header = builder.setComplexityLimit(headerComplLimit)
.setStatementLimit(headerStatementLimit)
@ -101,17 +102,17 @@ class DoWhileFactory extends SafeFactory {
.getBlockFactory()
.produce();
} catch (ProductionFailedException e) {
header = new Nothing();
header = emptyBlock;
}
// getChildren().set(DoWhile.DoWhilePart.HEADER.ordinal(), header);
LocalVariable counter = new LocalVariable(((Initialization) loop.initialization).get());
Literal limiter = new Literal(Integer.valueOf((int) thisLoopIterLimit), new TypeInt());
LocalVariable counter = new LocalVariable(loop.initialization.getVariableInfo());
Literal limiter = new Literal((int) thisLoopIterLimit, TypeList.INT);
loop.condition = builder.setComplexityLimit(condComplLimit)
.setLocalVariable(counter)
.getLoopingConditionFactory(limiter)
.produce();
SymbolTable.push();
IRNode body1;
Block body1;
try {
body1 = builder.setComplexityLimit(body1ComplLimit)
.setStatementLimit(body1StatementLimit)
@ -123,11 +124,11 @@ class DoWhileFactory extends SafeFactory {
.getBlockFactory()
.produce();
} catch (ProductionFailedException e) {
body1 = new Nothing();
body1 = emptyBlock;
}
// getChildren().set(DoWhile.DoWhilePart.BODY1.ordinal(), body1);
loop.manipulator = builder.setLocalVariable(counter).getCounterManipulatorFactory().produce();
IRNode body2;
Block body2;
try {
body2 = builder.setComplexityLimit(body2ComplLimit)
.setStatementLimit(body2StatementLimit)
@ -139,7 +140,7 @@ class DoWhileFactory extends SafeFactory {
.getBlockFactory()
.produce();
} catch (ProductionFailedException e) {
body2 = new Nothing();
body2 = emptyBlock;
}
// getChildren().set(DoWhile.DoWhilePart.BODY2.ordinal(), body2);
SymbolTable.pop();

View File

@ -29,11 +29,11 @@ import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.ProductionLimiter;
import jdk.test.lib.jittester.ProductionParams;
import jdk.test.lib.jittester.Rule;
import jdk.test.lib.jittester.Type;;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.types.TypeKlass;
class ExpressionFactory extends SafeFactory {
private final Rule rule;
class ExpressionFactory extends SafeFactory<IRNode> {
private final Rule<IRNode> rule;
ExpressionFactory(long complexityLimit, int operatorLimit, TypeKlass ownerClass, Type resultType,
boolean exceptionSafe, boolean noconsts) throws ProductionFailedException {
@ -44,7 +44,7 @@ class ExpressionFactory extends SafeFactory {
.setResultType(resultType)
.setExceptionSafe(exceptionSafe)
.setNoConsts(noconsts);
rule = new Rule("expression");
rule = new Rule<>("expression");
if (!noconsts) {
rule.add("literal", builder.getLiteralFactory());
rule.add("constant", builder.setIsConstant(true)

View File

@ -26,6 +26,6 @@ package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.ProductionFailedException;
public abstract class Factory {
public abstract IRNode produce() throws ProductionFailedException;
public abstract class Factory<T extends IRNode> {
public abstract T produce() throws ProductionFailedException;
}

View File

@ -23,22 +23,25 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.Block;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.Initialization;
import jdk.test.lib.jittester.Literal;
import jdk.test.lib.jittester.LocalVariable;
import jdk.test.lib.jittester.Nothing;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Rule;
import jdk.test.lib.jittester.Statement;
import jdk.test.lib.jittester.SymbolTable;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.loops.For;
import jdk.test.lib.jittester.loops.Loop;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeInt;
import jdk.test.lib.jittester.utils.PseudoRandom;
class ForFactory extends SafeFactory {
import java.util.LinkedList;
class ForFactory extends SafeFactory<For> {
private final Loop loop;
private final long complexityLimit;
private final int statementLimit;
@ -46,7 +49,6 @@ class ForFactory extends SafeFactory {
private final TypeKlass ownerClass;
private final Type returnType;
private final int level;
private long thisLoopIterLimit = 0;
private final boolean canHaveReturn;
ForFactory(TypeKlass ownerClass, Type returnType, long complexityLimit, int statementLimit,
@ -62,7 +64,8 @@ class ForFactory extends SafeFactory {
}
@Override
protected IRNode sproduce() throws ProductionFailedException {
protected For sproduce() throws ProductionFailedException {
Block emptyBlock = new Block(ownerClass, returnType, new LinkedList<>(), level - 1);
if (statementLimit <= 0 || complexityLimit <= 0) {
throw new ProductionFailedException();
}
@ -81,7 +84,7 @@ class ForFactory extends SafeFactory {
long statement1ComplLimit = (long) (0.005 * complexity * PseudoRandom.random());
complexity -= statement1ComplLimit;
// Loop body parameters
thisLoopIterLimit = (long) (0.0001 * complexity * PseudoRandom.random());
long thisLoopIterLimit = (long) (0.0001 * complexity * PseudoRandom.random());
if (thisLoopIterLimit > Integer.MAX_VALUE || thisLoopIterLimit == 0) {
throw new ProductionFailedException();
}
@ -100,7 +103,7 @@ class ForFactory extends SafeFactory {
int body3StatementLimit = PseudoRandom.randomNotZero((int) (statementLimit / 4.0));
// Production
loop.initialization = builder.getCounterInitializerFactory(0).produce();
IRNode header;
Block header;
try {
header = builder.setComplexityLimit(headerComplLimit)
.setStatementLimit(headerStatementLimit)
@ -112,12 +115,12 @@ class ForFactory extends SafeFactory {
.getBlockFactory()
.produce();
} catch (ProductionFailedException e) {
header = new Nothing();
header = emptyBlock;
}
SymbolTable.push();
IRNode statement1;
try {
Rule rule = new Rule("statement1");
Rule<IRNode> rule = new Rule<>("statement1");
builder.setComplexityLimit(statement1ComplLimit);
rule.add("assignment", builder.getAssignmentOperatorFactory());
rule.add("function", builder.getFunctionFactory(), 0.1);
@ -129,20 +132,20 @@ class ForFactory extends SafeFactory {
} catch (ProductionFailedException e) {
statement1 = new Nothing();
}
LocalVariable counter = new LocalVariable(((Initialization) loop.initialization).get());
Literal limiter = new Literal(Integer.valueOf((int) thisLoopIterLimit), new TypeInt());
LocalVariable counter = new LocalVariable(loop.initialization.getVariableInfo());
Literal limiter = new Literal((int) thisLoopIterLimit, TypeList.INT);
loop.condition = builder.setComplexityLimit(condComplLimit)
.setLocalVariable(counter)
.getLoopingConditionFactory(limiter)
.produce();
IRNode statement2;
try {
statement2 = builder.setComplexityLimit(statement2ComplLimit)
statement2 = builder.setComplexityLimit(statement2ComplLimit)
.getAssignmentOperatorFactory().produce();
} catch (ProductionFailedException e) {
statement2 = new Nothing();
}
IRNode body1;
Block body1;
try {
body1 = builder.setComplexityLimit(body1ComplLimit)
.setStatementLimit(body1StatementLimit)
@ -154,10 +157,10 @@ class ForFactory extends SafeFactory {
.getBlockFactory()
.produce();
} catch (ProductionFailedException e) {
body1 = new Nothing();
body1 = emptyBlock;
}
loop.manipulator = builder.setLocalVariable(counter).getCounterManipulatorFactory().produce();
IRNode body2;
Block body2;
try {
body2 = builder.setComplexityLimit(body2ComplLimit)
.setStatementLimit(body2StatementLimit)
@ -169,9 +172,9 @@ class ForFactory extends SafeFactory {
.getBlockFactory()
.produce();
} catch (ProductionFailedException e) {
body2 = new Nothing();
body2 = emptyBlock;
}
IRNode body3;
Block body3;
try {
body3 = builder.setComplexityLimit(body3ComplLimit)
.setStatementLimit(body3StatementLimit)
@ -183,10 +186,13 @@ class ForFactory extends SafeFactory {
.getBlockFactory()
.produce();
} catch (ProductionFailedException e) {
body3 = new Nothing();
body3 = emptyBlock;
}
SymbolTable.pop();
return new For(level, loop, thisLoopIterLimit, header, statement1, statement2, body1,
return new For(level, loop, thisLoopIterLimit, header,
new Statement(statement1, false),
new Statement(statement2, false),
body1,
body2, body3);
}
}

View File

@ -31,7 +31,7 @@ import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
class FunctionDeclarationBlockFactory extends Factory {
class FunctionDeclarationBlockFactory extends Factory<FunctionDeclarationBlock> {
private final int memberFunctionsLimit;
private final int memberFunctionsArgLimit;
private final int level;
@ -46,7 +46,7 @@ class FunctionDeclarationBlockFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public FunctionDeclarationBlock produce() throws ProductionFailedException {
ArrayList<IRNode> content = new ArrayList<>();
int memFunLimit = (int) (PseudoRandom.random() * memberFunctionsLimit);
if (memFunLimit > 0) {

View File

@ -27,7 +27,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Symbol;
import jdk.test.lib.jittester.SymbolTable;
@ -39,10 +38,9 @@ import jdk.test.lib.jittester.functions.FunctionDeclaration;
import jdk.test.lib.jittester.functions.FunctionDefinition;
import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeVoid;
import jdk.test.lib.jittester.utils.PseudoRandom;
class FunctionDeclarationFactory extends Factory {
class FunctionDeclarationFactory extends Factory<FunctionDeclaration> {
private final Type resultType;
private final TypeKlass ownerClass;
private final String name;
@ -59,11 +57,11 @@ class FunctionDeclarationFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public FunctionDeclaration produce() throws ProductionFailedException {
Type resType = resultType;
if (resType == null) {
List<Type> types = new ArrayList<>(TypeList.getAll());
types.add(new TypeVoid());
types.add(TypeList.VOID);
resType = PseudoRandom.randomElement(types);
}
int argNumber = (int) (PseudoRandom.random() * memberFunctionsArgLimit);

View File

@ -35,7 +35,7 @@ import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
class FunctionDefinitionBlockFactory extends Factory {
class FunctionDefinitionBlockFactory extends Factory<FunctionDefinitionBlock> {
private final long complexityLimit;
private final int statementLimit;
private final int operatorLimit;
@ -59,7 +59,7 @@ class FunctionDefinitionBlockFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public FunctionDefinitionBlock produce() throws ProductionFailedException {
ArrayList<IRNode> content = new ArrayList<>();
int memFunLimit = (int) (PseudoRandom.random() * memberFunctionsLimit);
if (memFunLimit > 0) {

View File

@ -28,6 +28,7 @@ import java.util.Collection;
import java.util.List;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.Nothing;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Symbol;
import jdk.test.lib.jittester.SymbolTable;
@ -37,11 +38,11 @@ import jdk.test.lib.jittester.VariableInfo;
import jdk.test.lib.jittester.functions.ArgumentDeclaration;
import jdk.test.lib.jittester.functions.FunctionDefinition;
import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.functions.Return;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeVoid;
import jdk.test.lib.jittester.utils.PseudoRandom;
class FunctionDefinitionFactory extends Factory {
class FunctionDefinitionFactory extends Factory<FunctionDefinition> {
private final Type resultType;
private final String name;
private final long complexityLimit;
@ -67,11 +68,11 @@ class FunctionDefinitionFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public FunctionDefinition produce() throws ProductionFailedException {
Type resType = resultType;
if (resType == null) {
List<Type> types = new ArrayList<>(TypeList.getAll());
types.add(new TypeVoid());
types.add(TypeList.VOID);
resType = PseudoRandom.randomElement(types);
}
int argNumber = (int) (PseudoRandom.random() * memberFunctionsArgLimit);
@ -86,7 +87,7 @@ class FunctionDefinitionFactory extends Factory {
ArrayList<ArgumentDeclaration> argumentsDeclaration = new ArrayList<>(argNumber);
SymbolTable.push();
IRNode body;
IRNode returnNode;
Return returnNode;
FunctionInfo functionInfo;
try {
IRNodeBuilder builder = new IRNodeBuilder().setArgumentType(ownerClass);
@ -127,13 +128,13 @@ class FunctionDefinitionFactory extends Factory {
.setCanHaveReturn(true)
.getBlockFactory()
.produce();
if (!resType.equals(new TypeVoid())) {
if (!resType.equals(TypeList.VOID)) {
returnNode = builder.setComplexityLimit(complexityLimit - blockComplLimit)
.setExceptionSafe(false)
.getReturnFactory()
.produce();
} else {
returnNode = null;
returnNode = new Return(new Nothing());
}
} finally {
SymbolTable.pop();

View File

@ -37,7 +37,7 @@ import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
class FunctionFactory extends SafeFactory {
class FunctionFactory extends SafeFactory<Function> {
private final FunctionInfo functionInfo;
private final int operatorLimit;
private final long complexityLimit;
@ -55,7 +55,7 @@ class FunctionFactory extends SafeFactory {
}
@Override
protected IRNode sproduce() throws ProductionFailedException {
protected Function sproduce() throws ProductionFailedException {
// Currently no function is exception-safe
if (exceptionSafe) {
throw new ProductionFailedException();
@ -72,7 +72,7 @@ class FunctionFactory extends SafeFactory {
for (Symbol function : allFunctions) {
FunctionInfo functionInfo = (FunctionInfo) function;
// Don't try to construct abstract classes.
if (functionInfo.isConstructor() && functionInfo.klass.isAbstract()) {
if (functionInfo.isConstructor() && functionInfo.owner.isAbstract()) {
continue;
}
// We don't call methods from the same class which are not final, because if we
@ -94,7 +94,7 @@ class FunctionFactory extends SafeFactory {
// If it's a local call.. or it's a call using some variable to some object of some type in our hierarchy
boolean inHierarchy = false;
if (ownerClass.equals(functionInfo.klass) || (inHierarchy = klassHierarchy.contains(functionInfo.klass))) {
if (ownerClass.equals(functionInfo.owner) || (inHierarchy = klassHierarchy.contains(functionInfo.owner))) {
if ((functionInfo.flags & FunctionInfo.FINAL) == 0 && (functionInfo.flags & FunctionInfo.STATIC) == 0
&& (functionInfo.flags & FunctionInfo.NONRECURSIVE) == 0) {
continue;
@ -121,7 +121,7 @@ class FunctionFactory extends SafeFactory {
// If there are function with a same name and same number of args,
// then disable usage of foldable expressions in the args.
boolean noconsts = false;
Collection<Symbol> allFuncsInKlass = SymbolTable.getAllCombined(functionInfo.klass,
Collection<Symbol> allFuncsInKlass = SymbolTable.getAllCombined(functionInfo.owner,
FunctionInfo.class);
for (Symbol s2 : allFuncsInKlass) {
FunctionInfo i2 = (FunctionInfo) function;

View File

@ -34,7 +34,7 @@ import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.functions.FunctionRedefinitionBlock;
import jdk.test.lib.jittester.types.TypeKlass;
class FunctionRedefinitionBlockFactory extends Factory {
class FunctionRedefinitionBlockFactory extends Factory<FunctionRedefinitionBlock> {
private final int statementLimit;
private final int operatorLimit;
private final long complexityLimit;
@ -53,7 +53,7 @@ class FunctionRedefinitionBlockFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public FunctionRedefinitionBlock produce() throws ProductionFailedException {
ArrayList<IRNode> content = new ArrayList<>();
if (functionSet.size() > 0) {
long funcComplexity = complexityLimit / functionSet.size();

View File

@ -25,17 +25,19 @@ package jdk.test.lib.jittester.factories;
import java.util.ArrayList;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.Nothing;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.SymbolTable;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.VariableInfo;
import jdk.test.lib.jittester.functions.ArgumentDeclaration;
import jdk.test.lib.jittester.functions.FunctionDefinition;
import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.functions.FunctionRedefinition;
import jdk.test.lib.jittester.functions.Return;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeVoid;
import jdk.test.lib.jittester.utils.PseudoRandom;
class FunctionRedefinitionFactory extends Factory {
class FunctionRedefinitionFactory extends Factory<FunctionRedefinition> {
private final long complexityLimit;
private final int statementLimit;
private final int operatorLimit;
@ -47,14 +49,14 @@ class FunctionRedefinitionFactory extends Factory {
long complexityLimit, int statementLimit, int operatorLimit, int level, int flags) {
this.ownerClass = ownerClass;
this.functionInfo = new FunctionInfo(functionInfo); // do deep coping
functionInfo.klass = ownerClass; // important! fix klass!
functionInfo.owner = ownerClass; // important! fix klass!
if ((functionInfo.flags & FunctionInfo.STATIC) == 0) {
functionInfo.argTypes.get(0).type = ownerClass; // redefine type of this
}
functionInfo.flags = flags; // apply new flags.
// fix the type of class where the args would be declared
for (VariableInfo varInfo : functionInfo.argTypes) {
varInfo.klass = ownerClass;
varInfo.owner = ownerClass;
}
this.complexityLimit = complexityLimit;
this.statementLimit = statementLimit;
@ -63,14 +65,14 @@ class FunctionRedefinitionFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public FunctionRedefinition produce() throws ProductionFailedException {
ArrayList<VariableInfo> argumentsInfo = functionInfo.argTypes;
SymbolTable.push();
IRNode body;
IRNode returnNode;
Return returnNode;
ArrayList<ArgumentDeclaration> argumentsDeclaration;
try {
if ((functionInfo.flags & FunctionInfo.STATIC) > 0) {
if (functionInfo.isStatic()) {
argumentsDeclaration = new ArrayList<>(argumentsInfo.size());
for (VariableInfo varInfo : argumentsInfo) {
argumentsDeclaration.add(new ArgumentDeclaration(varInfo));
@ -98,13 +100,13 @@ class FunctionRedefinitionFactory extends Factory {
.setCanHaveReturn(true)
.getBlockFactory()
.produce();
if (!functionInfo.type.equals(new TypeVoid())) {
if (!functionInfo.type.equals(TypeList.VOID)) {
returnNode = builder.setComplexityLimit(complexityLimit - blockComplLimit)
.setExceptionSafe(false)
.getReturnFactory()
.produce();
} else {
returnNode = null;
returnNode = new Return(new Nothing());
}
} catch (ProductionFailedException e) {
SymbolTable.pop();
@ -112,12 +114,12 @@ class FunctionRedefinitionFactory extends Factory {
throw e;
}
SymbolTable.pop();
if ((functionInfo.flags & FunctionInfo.STATIC) == 0) {
if (!functionInfo.isStatic()) {
functionInfo.flags &= ~FunctionInfo.ABSTRACT;
}
// If it's all ok, add the function to the symbol table.
SymbolTable.add(functionInfo);
return new FunctionDefinition(functionInfo, argumentsDeclaration, body, returnNode);
return new FunctionRedefinition(functionInfo, argumentsDeclaration, body, returnNode);
}
}

View File

@ -25,14 +25,64 @@ package jdk.test.lib.jittester.factories;
import java.util.Collection;
import java.util.Optional;
import jdk.test.lib.jittester.BinaryOperator;
import jdk.test.lib.jittester.Block;
import jdk.test.lib.jittester.Break;
import jdk.test.lib.jittester.CastOperator;
import jdk.test.lib.jittester.Continue;
import jdk.test.lib.jittester.Declaration;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.If;
import jdk.test.lib.jittester.Literal;
import jdk.test.lib.jittester.LocalVariable;
import jdk.test.lib.jittester.NonStaticMemberVariable;
import jdk.test.lib.jittester.Nothing;
import jdk.test.lib.jittester.Operator;
import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.PrintVariables;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.ProductionParams;
import jdk.test.lib.jittester.Statement;
import jdk.test.lib.jittester.StaticMemberVariable;
import jdk.test.lib.jittester.Switch;
import jdk.test.lib.jittester.Symbol;
import jdk.test.lib.jittester.TernaryOperator;
import jdk.test.lib.jittester.Throw;
import jdk.test.lib.jittester.TryCatchBlock;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.UnaryOperator;
import jdk.test.lib.jittester.VariableBase;
import jdk.test.lib.jittester.VariableDeclaration;
import jdk.test.lib.jittester.VariableDeclarationBlock;
import jdk.test.lib.jittester.VariableInitialization;
import jdk.test.lib.jittester.arrays.ArrayCreation;
import jdk.test.lib.jittester.arrays.ArrayElement;
import jdk.test.lib.jittester.arrays.ArrayExtraction;
import jdk.test.lib.jittester.classes.ClassDefinitionBlock;
import jdk.test.lib.jittester.classes.Interface;
import jdk.test.lib.jittester.classes.Klass;
import jdk.test.lib.jittester.classes.MainKlass;
import jdk.test.lib.jittester.functions.ArgumentDeclaration;
import jdk.test.lib.jittester.functions.ConstructorDefinition;
import jdk.test.lib.jittester.functions.ConstructorDefinitionBlock;
import jdk.test.lib.jittester.functions.Function;
import jdk.test.lib.jittester.functions.FunctionDeclaration;
import jdk.test.lib.jittester.functions.FunctionDeclarationBlock;
import jdk.test.lib.jittester.functions.FunctionDefinition;
import jdk.test.lib.jittester.functions.FunctionDefinitionBlock;
import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.functions.FunctionRedefinition;
import jdk.test.lib.jittester.functions.FunctionRedefinitionBlock;
import jdk.test.lib.jittester.functions.Return;
import jdk.test.lib.jittester.functions.StaticConstructorDefinition;
import jdk.test.lib.jittester.loops.CounterInitializer;
import jdk.test.lib.jittester.loops.CounterManipulator;
import jdk.test.lib.jittester.loops.DoWhile;
import jdk.test.lib.jittester.loops.For;
import jdk.test.lib.jittester.loops.LoopingCondition;
import jdk.test.lib.jittester.loops.While;
import jdk.test.lib.jittester.types.TypeKlass;
public class IRNodeBuilder {
@ -63,41 +113,40 @@ public class IRNodeBuilder {
private Optional<Boolean> isConstant = Optional.empty();
private Optional<Boolean> isInitialized = Optional.empty();
private Optional<String> name = Optional.empty();
private Optional<String> printerName = Optional.empty();
private Optional<Integer> flags = Optional.empty();
private Optional<FunctionInfo> functionInfo = Optional.empty();
private Optional<Boolean> semicolon = Optional.empty();
public ArgumentDeclarationFactory getArgumentDeclarationFactory() {
public Factory<ArgumentDeclaration> getArgumentDeclarationFactory() {
return new ArgumentDeclarationFactory(getArgumentType(), getVariableNumber());
}
public Factory getArithmeticOperatorFactory() throws ProductionFailedException {
public Factory<Operator> getArithmeticOperatorFactory() throws ProductionFailedException {
return new ArithmeticOperatorFactory(getComplexityLimit(), getOperatorLimit(),
getOwnerClass(), getResultType(), getExceptionSafe(), getNoConsts());
}
public ArrayCreationFactory getArrayCreationFactory() {
public Factory<ArrayCreation> getArrayCreationFactory() {
return new ArrayCreationFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
getResultType(), getExceptionSafe(), getNoConsts());
}
public ArrayElementFactory getArrayElementFactory() {
public Factory<ArrayElement> getArrayElementFactory() {
return new ArrayElementFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
getResultType(), getExceptionSafe(), getNoConsts());
}
public ArrayExtractionFactory getArrayExtractionFactory() {
public Factory<ArrayExtraction> getArrayExtractionFactory() {
return new ArrayExtractionFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
getResultType(), getExceptionSafe(), getNoConsts());
}
public AssignmentOperatorFactory getAssignmentOperatorFactory() {
public Factory<Operator> getAssignmentOperatorFactory() {
return new AssignmentOperatorFactory(getComplexityLimit(), getOperatorLimit(),
getOwnerClass(), resultType.orElse(null), getExceptionSafe(), getNoConsts());
}
public BinaryOperatorFactory getBinaryOperatorFactory() throws ProductionFailedException {
public Factory<BinaryOperator> getBinaryOperatorFactory() throws ProductionFailedException {
OperatorKind o = getOperatorKind();
switch (o) {
case ASSIGN:
@ -166,7 +215,7 @@ public class IRNodeBuilder {
}
}
public UnaryOperatorFactory getUnaryOperatorFactory() throws ProductionFailedException {
public Factory<UnaryOperator> getUnaryOperatorFactory() throws ProductionFailedException {
OperatorKind o = getOperatorKind();
switch (o) {
case NOT:
@ -193,24 +242,24 @@ public class IRNodeBuilder {
}
}
public BlockFactory getBlockFactory() throws ProductionFailedException {
public Factory<Block> getBlockFactory() {
return new BlockFactory(getOwnerClass(), getResultType(), getComplexityLimit(),
getStatementLimit(), getOperatorLimit(), getLevel(), subBlock.orElse(false),
canHaveBreaks.orElse(false), canHaveContinues.orElse(false),
getStatementLimit(), getOperatorLimit(), getLevel(), subBlock.orElse(false),
canHaveBreaks.orElse(false), canHaveContinues.orElse(false),
canHaveReturn.orElse(false), canHaveReturn.orElse(false));
//now 'throw' can be placed only in the same positions as 'return'
//now 'throw' can be placed only in the same positions as 'return'
}
public BreakFactory getBreakFactory() {
public Factory<Break> getBreakFactory() {
return new BreakFactory();
}
public CastOperatorFactory getCastOperatorFactory() {
public Factory<CastOperator> getCastOperatorFactory() {
return new CastOperatorFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
getResultType(), getExceptionSafe(), getNoConsts());
}
public Factory getClassDefinitionBlockFactory() {
public Factory<ClassDefinitionBlock> getClassDefinitionBlockFactory() {
return new ClassDefinitionBlockFactory(getPrefix(),
ProductionParams.classesLimit.value(),
ProductionParams.memberFunctionsLimit.value(),
@ -221,7 +270,7 @@ public class IRNodeBuilder {
getLevel());
}
public Factory getMainKlassFactory() {
public Factory<MainKlass> getMainKlassFactory() {
return new MainKlassFactory(getName(), getComplexityLimit(),
ProductionParams.memberFunctionsLimit.value(),
ProductionParams.memberFunctionsArgLimit.value(),
@ -230,200 +279,200 @@ public class IRNodeBuilder {
ProductionParams.operatorLimit.value());
}
public ConstructorDefinitionBlockFactory getConstructorDefinitionBlockFactory() {
public Factory<ConstructorDefinitionBlock> getConstructorDefinitionBlockFactory() {
return new ConstructorDefinitionBlockFactory(getOwnerClass(), getMemberFunctionsLimit(),
ProductionParams.memberFunctionsArgLimit.value(), getComplexityLimit(),
getStatementLimit(), getOperatorLimit(), getLevel());
}
public ConstructorDefinitionFactory getConstructorDefinitionFactory() {
public Factory<ConstructorDefinition> getConstructorDefinitionFactory() {
return new ConstructorDefinitionFactory(getOwnerClass(), getComplexityLimit(),
getStatementLimit(), getOperatorLimit(),
getMemberFunctionsArgLimit(), getLevel());
}
public ContinueFactory getContinueFactory() {
public Factory<Continue> getContinueFactory() {
return new ContinueFactory();
}
public CounterInitializerFactory getCounterInitializerFactory(int counterValue) {
public Factory<CounterInitializer> getCounterInitializerFactory(int counterValue) {
return new CounterInitializerFactory(getOwnerClass(), counterValue);
}
public CounterManipulatorFactory getCounterManipulatorFactory() {
public Factory<CounterManipulator> getCounterManipulatorFactory() {
return new CounterManipulatorFactory(getLocalVariable());
}
public DeclarationFactory getDeclarationFactory() {
public Factory<Declaration> getDeclarationFactory() {
return new DeclarationFactory(getOwnerClass(), getComplexityLimit(), getOperatorLimit(),
getIsLocal(), getExceptionSafe());
getIsLocal(), getExceptionSafe());
}
public DoWhileFactory getDoWhileFactory() {
public Factory<DoWhile> getDoWhileFactory() {
return new DoWhileFactory(getOwnerClass(), getResultType(), getComplexityLimit(),
getStatementLimit(), getOperatorLimit(), getLevel(), getCanHaveReturn());
}
public WhileFactory getWhileFactory() {
public Factory<While> getWhileFactory() {
return new WhileFactory(getOwnerClass(), getResultType(), getComplexityLimit(),
getStatementLimit(), getOperatorLimit(), getLevel(), getCanHaveReturn());
}
public IfFactory getIfFactory() {
public Factory<If> getIfFactory() {
return new IfFactory(getOwnerClass(), getResultType(), getComplexityLimit(),
getStatementLimit(), getOperatorLimit(), getLevel(), getCanHaveBreaks(),
getStatementLimit(), getOperatorLimit(), getLevel(), getCanHaveBreaks(),
getCanHaveContinues(), getCanHaveReturn());
}
public ForFactory getForFactory() {
public Factory<For> getForFactory() {
return new ForFactory(getOwnerClass(), getResultType(), getComplexityLimit(),
getStatementLimit(), getOperatorLimit(), getLevel(), getCanHaveReturn());
}
public SwitchFactory getSwitchFactory() { // TODO: switch is not used now
public Factory<Switch> getSwitchFactory() { // TODO: switch is not used now
return new SwitchFactory(getOwnerClass(), getComplexityLimit(), getStatementLimit(),
getOperatorLimit(), getLevel(), getCanHaveReturn());
}
public ExpressionFactory getExpressionFactory() throws ProductionFailedException {
public Factory<IRNode> getExpressionFactory() throws ProductionFailedException {
return new ExpressionFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
getResultType(), getExceptionSafe(), getNoConsts());
}
public FunctionDeclarationBlockFactory getFunctionDeclarationBlockFactory() {
public Factory<FunctionDeclarationBlock> getFunctionDeclarationBlockFactory() {
return new FunctionDeclarationBlockFactory(getOwnerClass(), getMemberFunctionsLimit(),
getMemberFunctionsArgLimit(), getLevel());
}
public FunctionDeclarationFactory getFunctionDeclarationFactory() {
return new FunctionDeclarationFactory(getName(), getOwnerClass(),resultType.orElse(null),
public Factory<FunctionDeclaration> getFunctionDeclarationFactory() {
return new FunctionDeclarationFactory(getName(), getOwnerClass(),resultType.orElse(TypeList.VOID),
getMemberFunctionsArgLimit(), getFlags());
}
public FunctionDefinitionBlockFactory getFunctionDefinitionBlockFactory() {
public Factory<FunctionDefinitionBlock> getFunctionDefinitionBlockFactory() {
return new FunctionDefinitionBlockFactory(getOwnerClass(), getMemberFunctionsLimit(),
getMemberFunctionsArgLimit(), getComplexityLimit(), getStatementLimit(),
getOperatorLimit(), getLevel(), getFlags());
}
public FunctionDefinitionFactory getFunctionDefinitionFactory() {
return new FunctionDefinitionFactory(getName(), getOwnerClass(), resultType.orElse(null),
public Factory<FunctionDefinition> getFunctionDefinitionFactory() {
return new FunctionDefinitionFactory(getName(), getOwnerClass(), resultType.orElse(TypeList.VOID),
getComplexityLimit(), getStatementLimit(), getOperatorLimit(),
getMemberFunctionsArgLimit(), getLevel(), getFlags());
}
public FunctionFactory getFunctionFactory() {
public Factory<Function> getFunctionFactory() {
return new FunctionFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
resultType.orElse(null), getExceptionSafe());
}
public FunctionRedefinitionBlockFactory getFunctionRedefinitionBlockFactory(Collection<Symbol>
functionSet) {
public Factory<FunctionRedefinitionBlock> getFunctionRedefinitionBlockFactory(Collection<Symbol>
functionSet) {
return new FunctionRedefinitionBlockFactory(functionSet, getOwnerClass(),
getComplexityLimit(), getStatementLimit(), getOperatorLimit(), getLevel());
}
public FunctionRedefinitionFactory getFunctionRedefinitionFactory() {
public Factory<FunctionRedefinition> getFunctionRedefinitionFactory() {
return new FunctionRedefinitionFactory(getFunctionInfo(), getOwnerClass(),
getComplexityLimit(), getStatementLimit(), getOperatorLimit(), getLevel(),
getFlags());
}
public InterfaceFactory getInterfaceFactory() {
public Factory<Interface> getInterfaceFactory() {
return new InterfaceFactory(getName(), getMemberFunctionsLimit(),
getMemberFunctionsArgLimit(), getLevel());
}
public KlassFactory getKlassFactory() {
return new KlassFactory(getName(), getPrinterName(), getComplexityLimit(),
public Factory<Klass> getKlassFactory() {
return new KlassFactory(getName(), getComplexityLimit(),
getMemberFunctionsLimit(), getMemberFunctionsArgLimit(), getStatementLimit(),
getOperatorLimit(), getLevel());
}
public LimitedExpressionFactory getLimitedExpressionFactory() throws ProductionFailedException {
public Factory<IRNode> getLimitedExpressionFactory() throws ProductionFailedException {
return new LimitedExpressionFactory(getComplexityLimit(), getOperatorLimit(),
getOwnerClass(), getResultType(), getExceptionSafe(), getNoConsts());
}
public LiteralFactory getLiteralFactory() {
public Factory<Literal> getLiteralFactory() {
return new LiteralFactory(getResultType());
}
public LocalVariableFactory getLocalVariableFactory() {
public Factory<LocalVariable> getLocalVariableFactory() {
return new LocalVariableFactory(/*getVariableType()*/getResultType(), getFlags());
}
public LogicOperatorFactory getLogicOperatorFactory() throws ProductionFailedException {
public Factory<Operator> getLogicOperatorFactory() throws ProductionFailedException {
return new LogicOperatorFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
getResultType(), getExceptionSafe(), getNoConsts());
}
public LoopingConditionFactory getLoopingConditionFactory(Literal _limiter) {
public Factory<LoopingCondition> getLoopingConditionFactory(Literal _limiter) {
return new LoopingConditionFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
getLocalVariable(), _limiter);
}
public NonStaticMemberVariableFactory getNonStaticMemberVariableFactory() {
public Factory<NonStaticMemberVariable> getNonStaticMemberVariableFactory() {
return new NonStaticMemberVariableFactory(getComplexityLimit(), getOperatorLimit(),
getOwnerClass(), /*getVariableType()*/getResultType(), getFlags(), getExceptionSafe());
}
public NothingFactory getNothingFactory() {
public Factory<Nothing> getNothingFactory() {
return new NothingFactory();
}
public PrintVariablesFactory getPrintVariablesFactory() {
return new PrintVariablesFactory(getPrinterName(), getOwnerClass(), getLevel());
public Factory<PrintVariables> getPrintVariablesFactory() {
return new PrintVariablesFactory(getOwnerClass(), getLevel());
}
public ReturnFactory getReturnFactory() {
public Factory<Return> getReturnFactory() {
return new ReturnFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
getResultType(), getExceptionSafe());
}
public ThrowFactory getThrowFactory() {
public Factory<Throw> getThrowFactory() {
return new ThrowFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(), getResultType(), getExceptionSafe());
}
public StatementFactory getStatementFactory() {
public Factory<Statement> getStatementFactory() {
return new StatementFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
getExceptionSafe(), getNoConsts(), semicolon.orElse(true));
}
public StaticConstructorDefinitionFactory getStaticConstructorDefinitionFactory() {
public Factory<StaticConstructorDefinition> getStaticConstructorDefinitionFactory() {
return new StaticConstructorDefinitionFactory(getOwnerClass(), getComplexityLimit(),
getStatementLimit(), getOperatorLimit(), getLevel());
}
public StaticMemberVariableFactory getStaticMemberVariableFactory() {
public Factory<StaticMemberVariable> getStaticMemberVariableFactory() {
return new StaticMemberVariableFactory(getOwnerClass(), /*getVariableType()*/getResultType(), getFlags());
}
public TernaryOperatorFactory getTernaryOperatorFactory() {
public Factory<TernaryOperator> getTernaryOperatorFactory() {
return new TernaryOperatorFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
getResultType(), getExceptionSafe(), getNoConsts());
}
public VariableDeclarationBlockFactory getVariableDeclarationBlockFactory() {
public Factory<VariableDeclarationBlock> getVariableDeclarationBlockFactory() {
return new VariableDeclarationBlockFactory(getOwnerClass(), getComplexityLimit(),
getOperatorLimit(), getLevel(), getExceptionSafe());
}
public VariableDeclarationFactory getVariableDeclarationFactory() {
public Factory<VariableDeclaration> getVariableDeclarationFactory() {
return new VariableDeclarationFactory(getOwnerClass(), getIsStatic(), getIsLocal(), getResultType());
}
public VariableFactory getVariableFactory() {
public Factory<VariableBase> getVariableFactory() {
return new VariableFactory(getComplexityLimit(), getOperatorLimit(), getOwnerClass(),
/*getVariableType()*/getResultType(), getIsConstant(), getIsInitialized(), getExceptionSafe(), getNoConsts());
}
public VariableInitializationFactory getVariableInitializationFactory() {
return new VariableInitializationFactory(getOwnerClass(), getIsConstant(), getIsStatic(),
getIsLocal(), getComplexityLimit(), getOperatorLimit(), getExceptionSafe());
public Factory<VariableInitialization> getVariableInitializationFactory() {
return new VariableInitializationFactory(getOwnerClass(), getIsConstant(), getIsStatic(),
getIsLocal(), getComplexityLimit(), getOperatorLimit(), getExceptionSafe());
}
public TryCatchBlockFactory getTryCatchBlockFactory() {
public Factory<TryCatchBlock> getTryCatchBlockFactory() {
return new TryCatchBlockFactory(getOwnerClass(), getResultType(),
getComplexityLimit(), getStatementLimit(), getOperatorLimit(),
getLevel(), subBlock.orElse(false), getCanHaveBreaks(),
@ -570,11 +619,6 @@ public class IRNodeBuilder {
return this;
}
public IRNodeBuilder setPrinterName(String value) {
printerName = Optional.of(value);
return this;
}
public IRNodeBuilder setSemicolon(boolean value) {
semicolon = Optional.of(value);
return this;
@ -698,9 +742,4 @@ public class IRNodeBuilder {
return functionInfo.orElseThrow(() -> new IllegalArgumentException(
"FunctionInfo wasn't set"));
}
private String getPrinterName() {
return printerName.orElseThrow(() -> new IllegalArgumentException(
"printerName wasn't set"));
}
}

View File

@ -23,21 +23,22 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.Block;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.If;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeBoolean;
import jdk.test.lib.jittester.utils.PseudoRandom;
class IfFactory extends SafeFactory {
protected long complexityLimit;
protected int statementLimit;
protected int operatorLimit;
protected boolean canHaveBreaks;
protected boolean canHaveContinues;
protected boolean canHaveReturn;
class IfFactory extends SafeFactory<If> {
protected final long complexityLimit;
protected final int statementLimit;
protected final int operatorLimit;
protected final boolean canHaveBreaks;
protected final boolean canHaveContinues;
protected final boolean canHaveReturn;
protected final TypeKlass ownerClass;
protected final Type returnType;
protected final int level;
@ -57,7 +58,7 @@ class IfFactory extends SafeFactory {
}
@Override
public IRNode sproduce() throws ProductionFailedException {
public If sproduce() throws ProductionFailedException {
// resizeUpChildren(If.IfPart.values().length);
if (statementLimit > 0 && complexityLimit > 0) {
long conditionComplLimit = (long) (0.01 * PseudoRandom.random() * (complexityLimit - 1));
@ -65,7 +66,7 @@ class IfFactory extends SafeFactory {
.setOwnerKlass(ownerClass)
.setOperatorLimit(operatorLimit);
IRNode condition = builder.setComplexityLimit(conditionComplLimit)
.setResultType(new TypeBoolean())
.setResultType(TypeList.BOOLEAN)
.setExceptionSafe(false)
.setNoConsts(false)
.getLimitedExpressionFactory()
@ -83,7 +84,7 @@ class IfFactory extends SafeFactory {
controlDeviation = PseudoRandom.randomBoolean() ? If.IfPart.THEN : If.IfPart.ELSE;
}
if (ifBlockLimit > 0 && ifBlockComplLimit > 0) {
IRNode thenBlock = null;
Block thenBlock;
builder.setResultType(returnType)
.setLevel(level)
.setComplexityLimit(ifBlockComplLimit)
@ -104,7 +105,7 @@ class IfFactory extends SafeFactory {
.produce();
}
// setChild(If.IfPart.THEN.ordinal(), thenBlock);
IRNode elseBlock = null;
Block elseBlock = null;
if (elseBlockLimit > 0 && elseBlockComplLimit > 0) {
builder.setComplexityLimit(elseBlockComplLimit)
.setStatementLimit(elseBlockLimit);

View File

@ -23,14 +23,12 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.UnaryOperator;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeBoolean;
class IncDecOperatorFactory extends UnaryOperatorFactory {
IncDecOperatorFactory(OperatorKind opKind, long complexityLimit, int operatorLimit,
@ -40,11 +38,11 @@ class IncDecOperatorFactory extends UnaryOperatorFactory {
@Override
protected boolean isApplicable(Type resultType) {
return TypeList.isBuiltInInt(resultType) && !resultType.equals(new TypeBoolean());
return TypeList.isBuiltInInt(resultType) && !resultType.equals(TypeList.BOOLEAN);
}
@Override
protected IRNode generateProduction(Type l) throws ProductionFailedException {
protected UnaryOperator generateProduction(Type l) throws ProductionFailedException {
return new UnaryOperator(opKind, new IRNodeBuilder().setComplexityLimit(complexityLimit - 1)
.setOperatorLimit(operatorLimit - 1)
.setOwnerKlass((TypeKlass) ownerClass)

View File

@ -37,7 +37,7 @@ import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
class InterfaceFactory extends Factory {
class InterfaceFactory extends Factory<Interface> {
private final String name;
private final int memberFunctionsLimit;
private final int memberFunctionsArgLimit;
@ -52,7 +52,7 @@ class InterfaceFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public Interface produce() throws ProductionFailedException {
TypeKlass thisKlass;
// Do we want to inherit something?
if (!ProductionParams.disableInheritance.value()) {
@ -76,7 +76,7 @@ class InterfaceFactory extends Factory {
parent.addChild(name);
for (Symbol symbol : SymbolTable.getAllCombined(parent, FunctionInfo.class)) {
FunctionInfo functionInfo = (FunctionInfo) symbol.deepCopy();
functionInfo.klass = thisKlass;
functionInfo.owner = thisKlass;
functionInfo.argTypes.get(0).type = thisKlass;
SymbolTable.add(functionInfo);
}

View File

@ -42,9 +42,8 @@ import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.utils.PseudoRandom;
class KlassFactory extends Factory {
class KlassFactory extends Factory<Klass> {
private final String name;
private final String printerName;
private final long complexityLimit;
private final int statementsInFunctionLimit;
private final int operatorLimit;
@ -55,11 +54,10 @@ class KlassFactory extends Factory {
private TypeKlass parent;
private int memberFunctionsLimit;
KlassFactory(String name, String printerName, long complexityLimit,
KlassFactory(String name, long complexityLimit,
int memberFunctionsLimit, int memberFunctionsArgLimit, int statementsInFunctionLimit,
int operatorLimit, int level) {
this.name = name;
this.printerName = printerName;
this.complexityLimit = complexityLimit;
this.memberFunctionsLimit = memberFunctionsLimit;
this.memberFunctionsArgLimit = memberFunctionsArgLimit;
@ -70,7 +68,7 @@ class KlassFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public Klass produce() throws ProductionFailedException {
HashSet<Symbol> abstractSet = new HashSet<>();
HashSet<Symbol> overrideSet = new HashSet<>();
thisKlass = new TypeKlass(name);
@ -135,15 +133,11 @@ class KlassFactory extends Factory {
SymbolTable.remove(symbol);
}
} else {
parent = (TypeKlass) TypeList.find("java.lang.Object");
parent = TypeList.OBJECT;
thisKlass.addParent(parent.getName());
thisKlass.setParent(parent);
parent.addChild(name);
}
// Just don't print it. It's assumed that we at least are inherited from Object.
if (parent.getName().equals("java.lang.Object")) {
parent = null;
}
SymbolTable.add(new VariableInfo("this", thisKlass, thisKlass,
VariableInfo.FINAL | VariableInfo.LOCAL | VariableInfo.INITIALIZED));
IRNode variableDeclarations = null;
@ -152,8 +146,7 @@ class KlassFactory extends Factory {
IRNode functionDeclarations = null;
IRNode abstractFunctionsRedefinitions = null;
IRNode overridenFunctionsRedefinitions = null;
IRNodeBuilder builder = new IRNodeBuilder().setPrinterName(printerName)
.setOwnerKlass(thisKlass)
IRNodeBuilder builder = new IRNodeBuilder().setOwnerKlass(thisKlass)
.setExceptionSafe(true);
try {
builder.setLevel(level + 1)
@ -227,7 +220,7 @@ class KlassFactory extends Factory {
}
}
if (probableParents.isEmpty()) {
parent = (TypeKlass) TypeList.find("java.lang.Object");
parent = TypeList.OBJECT;
} else {
parent = (TypeKlass) PseudoRandom.randomElement(probableParents);
}
@ -246,7 +239,7 @@ class KlassFactory extends Factory {
functionInfo.argTypes.get(0).type = thisKlass;
}
}
symbolCopy.klass = thisKlass;
symbolCopy.owner = thisKlass;
SymbolTable.add(symbolCopy);
}
}
@ -276,10 +269,9 @@ class KlassFactory extends Factory {
interfaces.add(iface);
iface.addChild(name);
thisKlass.addParent(iface.getName());
thisKlass.setParent(iface);
for (Symbol symbol : SymbolTable.getAllCombined(iface, FunctionInfo.class)) {
FunctionInfo functionInfo = (FunctionInfo) symbol.deepCopy();
functionInfo.klass = thisKlass;
functionInfo.owner = thisKlass;
functionInfo.argTypes.get(0).type = thisKlass;
SymbolTable.add(functionInfo);
}

View File

@ -23,23 +23,16 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.Literal;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.ProductionParams;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.types.TypeBoolean;
import jdk.test.lib.jittester.types.TypeByte;
import jdk.test.lib.jittester.types.TypeChar;
import jdk.test.lib.jittester.types.TypeDouble;
import jdk.test.lib.jittester.types.TypeFloat;
import jdk.test.lib.jittester.types.TypeInt;
import jdk.test.lib.jittester.types.TypeLong;
import jdk.test.lib.jittester.types.TypeShort;
import jdk.test.lib.jittester.utils.PseudoRandom;
class LiteralFactory extends Factory {
import java.util.Locale;
class LiteralFactory extends Factory<Literal> {
protected final Type resultType;
LiteralFactory(Type resultType) {
@ -47,31 +40,39 @@ class LiteralFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public Literal produce() throws ProductionFailedException {
Literal literal;
if (resultType.equals(new TypeBoolean())) {
literal = new Literal(PseudoRandom.randomBoolean(), new TypeBoolean());
} else if (resultType.equals(new TypeChar())) {
literal = new Literal((char) ((char) (PseudoRandom.random() * ('z' - 'A')) + 'A'), new TypeChar());
} else if (resultType.equals(new TypeInt())) {
literal = new Literal((int) (PseudoRandom.random() * Integer.MAX_VALUE), new TypeInt());
} else if (resultType.equals(new TypeLong())) {
literal = new Literal((long) (PseudoRandom.random() * Long.MAX_VALUE), new TypeLong());
} else if (resultType.equals(new TypeFloat())) {
literal = new Literal((float) (PseudoRandom.random() * Float.MAX_VALUE), new TypeFloat());
} else if (resultType.equals(new TypeDouble())) {
literal = new Literal(PseudoRandom.random() * Double.MAX_VALUE, new TypeDouble());
} else if (resultType.equals(new TypeByte())) {
literal = new Literal((byte)(PseudoRandom.random() * Byte.MAX_VALUE),new TypeByte());
} else if (resultType.equals(new TypeShort())) {
literal = new Literal((short)(PseudoRandom.random() * Short.MAX_VALUE), new TypeShort());
} else if (resultType.equals(TypeList.find("java.lang.String"))) {
if (resultType.equals(TypeList.BOOLEAN)) {
literal = new Literal(PseudoRandom.randomBoolean(), TypeList.BOOLEAN);
} else if (resultType.equals(TypeList.CHAR)) {
literal = new Literal((char) ((char) (PseudoRandom.random() * ('z' - 'A')) + 'A'), TypeList.CHAR);
} else if (resultType.equals(TypeList.INT)) {
literal = new Literal((int) (PseudoRandom.random() * Integer.MAX_VALUE), TypeList.INT);
} else if (resultType.equals(TypeList.LONG)) {
literal = new Literal((long) (PseudoRandom.random() * Long.MAX_VALUE), TypeList.LONG);
} else if (resultType.equals(TypeList.FLOAT)) {
literal = new Literal(new Float(String.format(
(Locale) null,
"%." + ProductionParams.floatingPointPrecision.value() + "EF",
(float) PseudoRandom.random() * Float.MAX_VALUE)),
TypeList.FLOAT);
} else if (resultType.equals(TypeList.DOUBLE)) {
literal = new Literal(new Double(String.format(
(Locale) null,
"%." + 2 * ProductionParams.floatingPointPrecision.value() + "E",
PseudoRandom.random() * Double.MAX_VALUE)),
TypeList.DOUBLE);
} else if (resultType.equals(TypeList.BYTE)) {
literal = new Literal((byte)(PseudoRandom.random() * Byte.MAX_VALUE), TypeList.BYTE);
} else if (resultType.equals(TypeList.SHORT)) {
literal = new Literal((short)(PseudoRandom.random() * Short.MAX_VALUE), TypeList.SHORT);
} else if (resultType.equals(TypeList.STRING)) {
int size = (int) (PseudoRandom.random() * ProductionParams.stringLiteralSizeLimit.value());
byte[] str = new byte[size];
for (int i = 0; i < size; i++) {
str[i] = (byte) ((int) (('z' - 'a') * PseudoRandom.random()) + 'a');
}
literal = new Literal("\"" + new String(str) + "\"", TypeList.find("java.lang.String"));
literal = new Literal(new String(str), TypeList.STRING);
} else {
throw new ProductionFailedException();
}

View File

@ -24,7 +24,7 @@
package jdk.test.lib.jittester.factories;
import java.util.ArrayList;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.LocalVariable;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Symbol;
@ -33,7 +33,7 @@ import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.VariableInfo;
import jdk.test.lib.jittester.utils.PseudoRandom;
class LocalVariableFactory extends Factory {
class LocalVariableFactory extends Factory<LocalVariable> {
private final Type type;
private final int flags;
@ -43,7 +43,7 @@ class LocalVariableFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public LocalVariable produce() throws ProductionFailedException {
// Get the variables of the requested type from SymbolTable
ArrayList<Symbol> allVariables = new ArrayList<>(SymbolTable.get(type, VariableInfo.class));
if (!allVariables.isEmpty()) {

View File

@ -23,15 +23,15 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.Operator;
import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Rule;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.types.TypeKlass;
class LogicOperatorFactory extends Factory {
private final Rule rule;
class LogicOperatorFactory extends Factory<Operator> {
private final Rule<Operator> rule;
LogicOperatorFactory(long complexityLimit, int operatorLimit, TypeKlass ownerClass, Type resultType,
boolean exceptionSafe, boolean noconsts) throws ProductionFailedException {
@ -42,7 +42,7 @@ class LogicOperatorFactory extends Factory {
.setResultType(resultType)
.setExceptionSafe(exceptionSafe)
.setNoConsts(noconsts);
rule = new Rule("arithmetic");
rule = new Rule<>("arithmetic");
rule.add("land", builder.setOperatorKind(OperatorKind.AND).getBinaryOperatorFactory());
rule.add("lor", builder.setOperatorKind(OperatorKind.OR).getBinaryOperatorFactory());
rule.add("greater", builder.setOperatorKind(OperatorKind.GT).getBinaryOperatorFactory());
@ -55,7 +55,7 @@ class LogicOperatorFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public Operator produce() throws ProductionFailedException {
return rule.produce();
}
}

View File

@ -23,12 +23,11 @@
package jdk.test.lib.jittester.factories;
import jdk.test.lib.jittester.IRNode;
import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.Type;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.UnaryOperator;
import jdk.test.lib.jittester.types.TypeBoolean;
import jdk.test.lib.jittester.types.TypeKlass;
class LogicalInversionOperatorFactory extends UnaryOperatorFactory {
@ -39,11 +38,11 @@ class LogicalInversionOperatorFactory extends UnaryOperatorFactory {
@Override
protected boolean isApplicable(Type resultType) {
return resultType.equals(new TypeBoolean());
return resultType.equals(TypeList.BOOLEAN);
}
@Override
protected IRNode generateProduction(Type resultType) throws ProductionFailedException {
protected UnaryOperator generateProduction(Type resultType) throws ProductionFailedException {
return new UnaryOperator(opKind, new ExpressionFactory(complexityLimit - 1,
operatorLimit - 1, (TypeKlass) ownerClass, resultType, exceptionSafe, noconsts).produce());
}

View File

@ -29,12 +29,12 @@ import jdk.test.lib.jittester.Literal;
import jdk.test.lib.jittester.LocalVariable;
import jdk.test.lib.jittester.OperatorKind;
import jdk.test.lib.jittester.ProductionFailedException;
import jdk.test.lib.jittester.TypeList;
import jdk.test.lib.jittester.loops.LoopingCondition;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeBoolean;
import jdk.test.lib.jittester.utils.PseudoRandom;
class LoopingConditionFactory extends Factory {
class LoopingConditionFactory extends Factory<LoopingCondition> {
private final LocalVariable counter;
private final Literal limiter;
private final int operatorLimit;
@ -51,11 +51,11 @@ class LoopingConditionFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
public LoopingCondition produce() throws ProductionFailedException {
IRNode leftExpression = null;
IRNode rightExpression = null;
LimitedExpressionFactory exprFactory = new IRNodeBuilder()
.setResultType(new TypeBoolean())
Factory<IRNode> exprFactory = new IRNodeBuilder()
.setResultType(TypeList.BOOLEAN)
.setComplexityLimit((complexityLimit - 1) / 2)
.setOperatorLimit((operatorLimit - 1) / 2)
.setOwnerKlass(ownerClass)
@ -75,10 +75,10 @@ class LoopingConditionFactory extends Factory {
// Just as a temporary solution we'll assume that the counter is monotonically increasing.
// And use counter < n condition to limit the loop.
// In future we may introduce other equivalent relations as well.
IRNode condition = new BinaryOperator(OperatorKind.LT, counter, limiter);
condition = (rightExpression != null) ? new BinaryOperator(OperatorKind.AND, condition,
BinaryOperator condition = new BinaryOperator(OperatorKind.LT, TypeList.BOOLEAN, counter, limiter);
condition = (rightExpression != null) ? new BinaryOperator(OperatorKind.AND, TypeList.BOOLEAN, condition,
rightExpression) : condition;
condition = (leftExpression != null) ? new BinaryOperator(OperatorKind.AND, leftExpression,
condition = (leftExpression != null) ? new BinaryOperator(OperatorKind.AND, TypeList.BOOLEAN, leftExpression,
condition) : condition;
return new LoopingCondition(condition);
}

View File

@ -38,10 +38,9 @@ import jdk.test.lib.jittester.VariableInfo;
import jdk.test.lib.jittester.classes.MainKlass;
import jdk.test.lib.jittester.functions.FunctionInfo;
import jdk.test.lib.jittester.types.TypeKlass;
import jdk.test.lib.jittester.types.TypeVoid;
import jdk.test.lib.jittester.utils.PseudoRandom;
class MainKlassFactory extends Factory {
class MainKlassFactory extends Factory<MainKlass> {
private final String name;
private final long complexityLimit;
private final int statementsInTestFunctionLimit;
@ -64,8 +63,8 @@ class MainKlassFactory extends Factory {
}
@Override
public IRNode produce() throws ProductionFailedException {
TypeKlass parent = (TypeKlass) TypeList.find("java.lang.Object");
public MainKlass produce() throws ProductionFailedException {
TypeKlass parent = TypeList.OBJECT;
thisKlass = new TypeKlass(name);
thisKlass.addParent(parent.getName());
thisKlass.setParent(parent);
@ -80,8 +79,7 @@ class MainKlassFactory extends Factory {
.setMemberFunctionsArgLimit(memberFunctionsArgLimit)
.setStatementLimit(statementsInFunctionLimit)
.setLevel(1)
.setExceptionSafe(true)
.setPrinterName("Printer");
.setExceptionSafe(true);
IRNode variableDeclarations = builder
.setComplexityLimit((long) (complexityLimit * 0.05))
.getVariableDeclarationBlockFactory().produce();
@ -93,7 +91,7 @@ class MainKlassFactory extends Factory {
.getFunctionDefinitionBlockFactory()
.produce();
}
IRNode testFunction = builder.setResultType(new TypeVoid())
IRNode testFunction = builder.setResultType(TypeList.VOID)
.setComplexityLimit(complexityLimit)
.setStatementLimit(statementsInTestFunctionLimit)
.getBlockFactory()
@ -109,6 +107,7 @@ class MainKlassFactory extends Factory {
childs.add(printVariables);
ensureMinDepth(childs, builder);
ensureMaxDepth(childs);
TypeList.add(thisKlass);
return new MainKlass(name, thisKlass, variableDeclarations,
functionDefinitions, testFunction, printVariables);
}
@ -119,7 +118,7 @@ class MainKlassFactory extends Factory {
.filter(c -> c.isCFDeviation() && c.countDepth() > maxDepth)
.collect(Collectors.toList());
for (IRNode child : filtered) {
List<IRNode> leaves = null;
List<IRNode> leaves;
do {
long depth = Math.max(child.countDepth(), maxDepth + 1);
leaves = child.getDeviantBlocks(depth);
@ -138,16 +137,14 @@ class MainKlassFactory extends Factory {
private void addMoreChildren(List<IRNode> childs, int minDepth, IRNodeBuilder builder)
throws ProductionFailedException {
while (!childs.isEmpty() && IRNode.countDepth(childs) < minDepth) {
PseudoRandom.shuffle(childs);
IRNode randomChild = childs.get(0);
IRNode randomChild = childs.get(PseudoRandom.randomNotNegative(childs.size()));
List<IRNode> leaves = randomChild.getStackableLeaves();
if (!leaves.isEmpty()) {
PseudoRandom.shuffle(leaves);
Block randomLeaf = (Block) leaves.get(0);
TypeKlass klass = (TypeKlass) randomChild.getKlass();
Block randomLeaf = (Block) leaves.get(PseudoRandom.randomNotNegative(leaves.size()));
TypeKlass owner = randomChild.getOwner();
int newLevel = randomLeaf.getLevel() + 1;
Type retType = randomLeaf.getReturnType();
IRNode newBlock = builder.setOwnerKlass(klass)
Type retType = randomLeaf.getResultType();
IRNode newBlock = builder.setOwnerKlass(owner)
.setResultType(retType)
.setComplexityLimit(complexityLimit)
.setStatementLimit(statementsInFunctionLimit)

Some files were not shown because too many files have changed in this diff Show More