< prev index next >

test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/StaticMemberVariableFactory.java

Print this page




   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 jdk.test.lib.jittester.IRNode;
  28 import jdk.test.lib.jittester.ProductionFailedException;
  29 import jdk.test.lib.jittester.StaticMemberVariable;
  30 import jdk.test.lib.jittester.Symbol;
  31 import jdk.test.lib.jittester.SymbolTable;
  32 import jdk.test.lib.jittester.Type;
  33 import jdk.test.lib.jittester.VariableInfo;
  34 import jdk.test.lib.jittester.types.TypeKlass;
  35 import jdk.test.lib.jittester.utils.PseudoRandom;
  36 
  37 class StaticMemberVariableFactory extends Factory {
  38     private final Type type;
  39     private final int flags;
  40     private final Type ownerClass;
  41 
  42     StaticMemberVariableFactory(TypeKlass ownerClass, Type type, int flags) {
  43         this.ownerClass = ownerClass;
  44         this.type = type;
  45         this.flags = flags;
  46     }
  47 
  48     @Override
  49     public IRNode produce() throws ProductionFailedException {
  50         // Get the variables of the requested type from SymbolTable
  51         ArrayList<Symbol> variables = new ArrayList<>(SymbolTable.get(type, VariableInfo.class));
  52         if (!variables.isEmpty()) {
  53             PseudoRandom.shuffle(variables);
  54             for (Symbol symbol : variables) {
  55                 VariableInfo varInfo = (VariableInfo) symbol;
  56                 if ((varInfo.flags & VariableInfo.FINAL) == (flags & VariableInfo.FINAL)
  57                         && (varInfo.flags & VariableInfo.INITIALIZED) == (flags & VariableInfo.INITIALIZED)
  58                         && (varInfo.flags & VariableInfo.STATIC) > 0) {
  59                     return new StaticMemberVariable((TypeKlass) ownerClass, varInfo);
  60                 }
  61             }
  62         }
  63         throw new ProductionFailedException();
  64     }
  65 }


   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 
  28 import jdk.test.lib.jittester.ProductionFailedException;
  29 import jdk.test.lib.jittester.StaticMemberVariable;
  30 import jdk.test.lib.jittester.Symbol;
  31 import jdk.test.lib.jittester.SymbolTable;
  32 import jdk.test.lib.jittester.Type;
  33 import jdk.test.lib.jittester.VariableInfo;
  34 import jdk.test.lib.jittester.types.TypeKlass;
  35 import jdk.test.lib.jittester.utils.PseudoRandom;
  36 
  37 class StaticMemberVariableFactory extends Factory<StaticMemberVariable> {
  38     private final Type type;
  39     private final int flags;
  40     private final Type ownerClass;
  41 
  42     StaticMemberVariableFactory(TypeKlass ownerClass, Type type, int flags) {
  43         this.ownerClass = ownerClass;
  44         this.type = type;
  45         this.flags = flags;
  46     }
  47 
  48     @Override
  49     public StaticMemberVariable produce() throws ProductionFailedException {
  50         // Get the variables of the requested type from SymbolTable
  51         ArrayList<Symbol> variables = new ArrayList<>(SymbolTable.get(type, VariableInfo.class));
  52         if (!variables.isEmpty()) {
  53             PseudoRandom.shuffle(variables);
  54             for (Symbol symbol : variables) {
  55                 VariableInfo varInfo = (VariableInfo) symbol;
  56                 if ((varInfo.flags & VariableInfo.FINAL) == (flags & VariableInfo.FINAL)
  57                         && (varInfo.flags & VariableInfo.INITIALIZED) == (flags & VariableInfo.INITIALIZED)
  58                         && (varInfo.flags & VariableInfo.STATIC) > 0) {
  59                     return new StaticMemberVariable((TypeKlass) ownerClass, varInfo);
  60                 }
  61             }
  62         }
  63         throw new ProductionFailedException();
  64     }
  65 }
< prev index next >