Path: blob/master/test/hotspot/jtreg/vmTestbase/metaspace/stressHierarchy/common/GenClassesBuilder.java
41161 views
/*1* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package metaspace.stressHierarchy.common;2425import jdk.test.lib.JDKToolLauncher;26import jdk.test.lib.Utils;27import jdk.test.lib.process.ProcessTools;2829import java.io.IOException;30import java.nio.file.Files;31import java.nio.file.Path;32import java.nio.file.Paths;33import java.util.Arrays;34import java.util.stream.Stream;3536public class GenClassesBuilder {37public static void main(String[] args) {38Path srcDst = Paths.get("genSrc").toAbsolutePath();39Path classesDir = Paths.get(Utils.TEST_CLASSES).toAbsolutePath();40generateSource(srcDst);41compileSource(srcDst, classesDir);42}4344private static void compileSource(Path srcDst, Path classesDir) {45JDKToolLauncher javac = JDKToolLauncher.create("javac")46.addToolArg("-d")47.addToolArg(classesDir.toString())48.addToolArg("-cp")49.addToolArg(Utils.TEST_CLASS_PATH);50try (Stream<Path> stream = Files.walk(srcDst)) {51stream.map(Path::toAbsolutePath)52.map(Path::toString)53.filter(s -> s.endsWith(".java"))54.forEach(javac::addToolArg);55} catch (IOException e) {56throw new Error("traverse source dir " + srcDst, e);57}58String[] command = javac.getCommand();59try {60ProcessTools.executeCommand(command)61.shouldHaveExitValue(0);62} catch (Error | RuntimeException e) {63throw e;64} catch (Throwable e) {65throw new Error("execution of javac(" + Arrays.toString(command) + ") failed", e);66}67}6869private static void generateSource(Path dir) {70try {71Files.createDirectories(dir);72} catch (IOException e) {73throw new Error("can't create dirs for" + dir, e);74}7576try {77HumongousClassGen.main(new String[]{dir.toString()});78} catch (Exception e) {79throw new Error("can't generate classes", e);80}81}82}83848586