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 java.util.ArrayList; 27 import java.util.Collection; 28 import jdk.test.lib.jittester.IRNode; 29 import jdk.test.lib.jittester.ProductionFailedException; 30 import jdk.test.lib.jittester.Symbol; 31 import jdk.test.lib.jittester.SymbolTable; 32 import jdk.test.lib.jittester.VariableInfo; 33 import jdk.test.lib.jittester.functions.FunctionInfo; 34 import jdk.test.lib.jittester.functions.FunctionRedefinitionBlock; 35 import jdk.test.lib.jittester.types.TypeKlass; 36 37 class FunctionRedefinitionBlockFactory extends Factory<FunctionRedefinitionBlock> { 38 private final int statementLimit; 39 private final int operatorLimit; 40 private final long complexityLimit; 41 private final int level; 42 private final TypeKlass ownerClass; 43 private final Collection<Symbol> functionSet; 44 45 FunctionRedefinitionBlockFactory(Collection<Symbol> functionSet, TypeKlass ownerClass, 46 long complexityLimit, int statementLimit, int operatorLimit, int level) { 47 this.functionSet = functionSet; 48 this.ownerClass = ownerClass; 49 this.complexityLimit = complexityLimit; 50 this.statementLimit = statementLimit; 51 this.operatorLimit = operatorLimit; 52 this.level = level; 53 } 54 55 @Override 56 public FunctionRedefinitionBlock produce() throws ProductionFailedException { 57 ArrayList<IRNode> content = new ArrayList<>(); 58 if (functionSet.size() > 0) { 59 long funcComplexity = complexityLimit / functionSet.size(); 60 IRNodeBuilder builder = new IRNodeBuilder().setOwnerKlass(ownerClass) 61 .setComplexityLimit(funcComplexity) 62 .setStatementLimit(statementLimit) 63 .setOperatorLimit(operatorLimit) 64 .setLevel(level); 65 for (Symbol symbol : functionSet) { 66 FunctionInfo functionInfo = (FunctionInfo) symbol; 67 Symbol thisSymbol = null; 68 if ((functionInfo.flags & FunctionInfo.STATIC) > 0) { 69 thisSymbol = SymbolTable.get("this", VariableInfo.class); 70 SymbolTable.remove(thisSymbol); 71 } 72 try { 73 content.add(builder.setFunctionInfo(functionInfo) 74 .setFlags(functionInfo.flags) 75 .getFunctionRedefinitionFactory() 76 .produce()); 77 } catch (ProductionFailedException e) { 78 if ((functionInfo.flags & FunctionInfo.STATIC) == 0) { 79 ownerClass.setAbstract(); 80 } 81 } 82 if ((functionInfo.flags & FunctionInfo.STATIC) > 0) { 83 SymbolTable.add(thisSymbol); 84 } 85 } 86 } 87 return new FunctionRedefinitionBlock(content, level); 88 } 89 }