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