1 /*
   2  * Copyright (c) 2016, 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;
  25 
  26 import java.util.ArrayList;
  27 import java.util.List;
  28 import java.util.function.Function;
  29 
  30 public class AotTestGeneratorsFactory implements Function<String[], List<TestsGenerator>> {
  31     private static final String AOT_OPTIONS = "-XX:+UseAOT -XX:AOTLibrary=./aottest.so";
  32     private static final String AOT_COMPILER_BUILD_ACTION
  33             = "@build compiler.aot.AotCompiler";
  34     private static final String AOT_COMPILER_RUN_ACTION_PREFIX
  35             = "@run driver compiler.aot.AotCompiler -extraopt -Xmixed -libname aottest.so -class ";
  36 
  37     @Override
  38     public List<TestsGenerator> apply(String[] input) {
  39         List<TestsGenerator> result = new ArrayList<>();
  40         for (String generatorName : input) {
  41             switch (generatorName) {
  42                 case "ByteCode":
  43                     result.add(new ByteCodeGenerator("aot_bytecode_tests",
  44                             AotTestGeneratorsFactory::generateBytecodeHeader, AOT_OPTIONS));
  45                     break;
  46                 case "JavaCode":
  47                     result.add(new JavaCodeGenerator("aot_java_tests",
  48                             AotTestGeneratorsFactory::generateJavaHeader, AOT_OPTIONS));
  49                     break;
  50                 default:
  51                     throw new IllegalArgumentException("Unknown generator: " + generatorName);
  52             }
  53         }
  54         return result;
  55     }
  56 
  57     private static String[] generateBytecodeHeader(String mainClassName) {
  58         return new String[]{
  59             AOT_COMPILER_BUILD_ACTION,
  60             AOT_COMPILER_RUN_ACTION_PREFIX + mainClassName
  61         };
  62     }
  63 
  64     private static String[] generateJavaHeader(String mainClassName) {
  65         return new String[]{
  66             "@compile " + mainClassName + ".java",
  67             AOT_COMPILER_BUILD_ACTION,
  68             AOT_COMPILER_RUN_ACTION_PREFIX + mainClassName
  69         };
  70     }
  71 }