< prev index next >

test/hotspot/jtreg/testlibrary/jittester/src/jdk/test/lib/jittester/factories/FunctionDefinitionBlockFactory.java

Print this page

  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  */

 25 
 26 import java.util.ArrayList;
 27 import jdk.test.lib.jittester.IRNode;
 28 import jdk.test.lib.jittester.ProductionFailedException;
 29 import jdk.test.lib.jittester.ProductionParams;
 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.FunctionDefinitionBlock;
 34 import jdk.test.lib.jittester.functions.FunctionInfo;
 35 import jdk.test.lib.jittester.types.TypeKlass;
 36 import jdk.test.lib.jittester.utils.PseudoRandom;
 37 
 38 class FunctionDefinitionBlockFactory extends Factory<FunctionDefinitionBlock> {
 39     private final long complexityLimit;
 40     private final int statementLimit;
 41     private final int operatorLimit;
 42     private final int memberFunctionsLimit;
 43     private final int memberFunctionsArgLimit;
 44     private final int initialFlags;

 45     private final int level;
 46     private final TypeKlass ownerClass;
 47 
 48     FunctionDefinitionBlockFactory(TypeKlass ownerClass, int memberFunctionsLimit,
 49             int memberFunctionsArgLimit, long complexityLimit, int statementLimit,
 50             int operatorLimit, int level, int initialFlags) {
 51         this.ownerClass = ownerClass;
 52         this.memberFunctionsLimit = memberFunctionsLimit;
 53         this.memberFunctionsArgLimit = memberFunctionsArgLimit;
 54         this.complexityLimit = complexityLimit;
 55         this.statementLimit = statementLimit;
 56         this.operatorLimit = operatorLimit;
 57         this.level = level;
 58         this.initialFlags = initialFlags;

 59     }
 60 
 61     @Override
 62     public FunctionDefinitionBlock produce() throws ProductionFailedException {
 63         ArrayList<IRNode> content = new ArrayList<>();
 64         int memFunLimit = (int) (PseudoRandom.random() * memberFunctionsLimit);
 65         if (memFunLimit > 0) {
 66             long memFunCompl = complexityLimit / memFunLimit;
 67             IRNodeBuilder builder = new IRNodeBuilder().setOwnerKlass(ownerClass)
 68                     .setComplexityLimit(memFunCompl)
 69                     .setStatementLimit(statementLimit)
 70                     .setOperatorLimit(operatorLimit)
 71                     .setMemberFunctionsArgLimit(memberFunctionsArgLimit)
 72                     .setLevel(level);
 73             for (int i = 0; i < memFunLimit; i++) {
 74                 int flags = initialFlags;
 75                 if (PseudoRandom.randomBoolean()) {
 76                     flags |= FunctionInfo.STATIC;
 77                 }
 78                 if (!ProductionParams.disableFinalMethods.value() && PseudoRandom.randomBoolean()) {
 79                     flags |= FunctionInfo.FINAL;
 80                 }
 81                 if (PseudoRandom.randomBoolean()) {
 82                     flags |= FunctionInfo.NONRECURSIVE;
 83                 }
 84                 if (PseudoRandom.randomBoolean()) {
 85                     flags |= FunctionInfo.SYNCHRONIZED;
 86                 }
 87                 switch ((int) (PseudoRandom.random() * 4)) {
 88                     case 0:
 89                         flags |= FunctionInfo.PRIVATE;
 90                         break;
 91                     case 1:
 92                         flags |= FunctionInfo.PROTECTED;
 93                         break;
 94                     case 2:
 95                         flags |= FunctionInfo.DEFAULT;
 96                         break;
 97                     case 3:
 98                         flags |= FunctionInfo.PUBLIC;
 99                         break;
100                 }
101                 Symbol thisSymbol = null;
102                 if ((flags & FunctionInfo.STATIC) > 0) {
103                     thisSymbol = SymbolTable.get("this", VariableInfo.class);
104                     SymbolTable.remove(thisSymbol);

  1 /*
  2  * Copyright (c) 2015, 2026, 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  */

 25 
 26 import java.util.ArrayList;
 27 import jdk.test.lib.jittester.IRNode;
 28 import jdk.test.lib.jittester.ProductionFailedException;
 29 import jdk.test.lib.jittester.ProductionParams;
 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.FunctionDefinitionBlock;
 34 import jdk.test.lib.jittester.functions.FunctionInfo;
 35 import jdk.test.lib.jittester.types.TypeKlass;
 36 import jdk.test.lib.jittester.utils.PseudoRandom;
 37 
 38 class FunctionDefinitionBlockFactory extends Factory<FunctionDefinitionBlock> {
 39     private final long complexityLimit;
 40     private final int statementLimit;
 41     private final int operatorLimit;
 42     private final int memberFunctionsLimit;
 43     private final int memberFunctionsArgLimit;
 44     private final int initialFlags;
 45     private final boolean isSynchronizedAllowed;
 46     private final int level;
 47     private final TypeKlass ownerClass;
 48 
 49     FunctionDefinitionBlockFactory(TypeKlass ownerClass, int memberFunctionsLimit,
 50             int memberFunctionsArgLimit, long complexityLimit, int statementLimit,
 51             int operatorLimit, int level, int initialFlags, boolean isSynchronizedAllowed) {
 52         this.ownerClass = ownerClass;
 53         this.memberFunctionsLimit = memberFunctionsLimit;
 54         this.memberFunctionsArgLimit = memberFunctionsArgLimit;
 55         this.complexityLimit = complexityLimit;
 56         this.statementLimit = statementLimit;
 57         this.operatorLimit = operatorLimit;
 58         this.level = level;
 59         this.initialFlags = initialFlags;
 60         this.isSynchronizedAllowed = isSynchronizedAllowed;
 61     }
 62 
 63     @Override
 64     public FunctionDefinitionBlock produce() throws ProductionFailedException {
 65         ArrayList<IRNode> content = new ArrayList<>();
 66         int memFunLimit = (int) (PseudoRandom.random() * memberFunctionsLimit);
 67         if (memFunLimit > 0) {
 68             long memFunCompl = complexityLimit / memFunLimit;
 69             IRNodeBuilder builder = new IRNodeBuilder().setOwnerKlass(ownerClass)
 70                     .setComplexityLimit(memFunCompl)
 71                     .setStatementLimit(statementLimit)
 72                     .setOperatorLimit(operatorLimit)
 73                     .setMemberFunctionsArgLimit(memberFunctionsArgLimit)
 74                     .setLevel(level);
 75             for (int i = 0; i < memFunLimit; i++) {
 76                 int flags = initialFlags;
 77                 if (PseudoRandom.randomBoolean()) {
 78                     flags |= FunctionInfo.STATIC;
 79                 }
 80                 if (!ProductionParams.disableFinalMethods.value() && PseudoRandom.randomBoolean()) {
 81                     flags |= FunctionInfo.FINAL;
 82                 }
 83                 if (PseudoRandom.randomBoolean()) {
 84                     flags |= FunctionInfo.NONRECURSIVE;
 85                 }
 86                 if (isSynchronizedAllowed && PseudoRandom.randomBoolean()) {
 87                     flags |= FunctionInfo.SYNCHRONIZED;
 88                 }
 89                 switch ((int) (PseudoRandom.random() * 4)) {
 90                     case 0:
 91                         flags |= FunctionInfo.PRIVATE;
 92                         break;
 93                     case 1:
 94                         flags |= FunctionInfo.PROTECTED;
 95                         break;
 96                     case 2:
 97                         flags |= FunctionInfo.DEFAULT;
 98                         break;
 99                     case 3:
100                         flags |= FunctionInfo.PUBLIC;
101                         break;
102                 }
103                 Symbol thisSymbol = null;
104                 if ((flags & FunctionInfo.STATIC) > 0) {
105                     thisSymbol = SymbolTable.get("this", VariableInfo.class);
106                     SymbolTable.remove(thisSymbol);
< prev index next >