1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.test.lib.jittester.factories; 25 26 import jdk.test.lib.jittester.IRNode; 27 import jdk.test.lib.jittester.ProductionFailedException; 28 import jdk.test.lib.jittester.ProductionLimiter; 29 import jdk.test.lib.jittester.Rule; 30 import jdk.test.lib.jittester.Statement; 31 import jdk.test.lib.jittester.TypeList; 32 import jdk.test.lib.jittester.types.TypeKlass; 33 import jdk.test.lib.jittester.utils.PseudoRandom; 34 35 class StatementFactory extends Factory<Statement> { 36 private final Rule<IRNode> rule; 37 private final boolean needSemicolon; 38 39 StatementFactory(long complexityLimit, int operatorLimit, 40 TypeKlass ownerClass, boolean exceptionSafe, 41 boolean noconsts, boolean needSemicolon ){ 42 this.needSemicolon = needSemicolon; 43 rule = new Rule<>("statement"); 44 IRNodeBuilder builder = new IRNodeBuilder() 45 .setComplexityLimit(complexityLimit) 46 .setOperatorLimit(operatorLimit) 47 .setOwnerKlass(ownerClass) 48 .setExceptionSafe(exceptionSafe) 49 .setNoConsts(noconsts) 50 .setResultType(PseudoRandom.randomElement(TypeList.getAll())); 51 rule.add("array_creation", builder.getArrayCreationFactory()); 52 rule.add("assignment", builder.getAssignmentOperatorFactory()); 53 rule.add("function", builder.getFunctionFactory(), 0.1); 54 } 55 56 @Override 57 public Statement produce() throws ProductionFailedException { 58 ProductionLimiter.setLimit(); 59 try { 60 return new Statement(rule.produce(), needSemicolon); 61 } finally { 62 ProductionLimiter.setUnlimited(); 63 } 64 } 65 }