Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/StratumClassesBuilder.java
41155 views
/*1* Copyright (c) 2018, 2019, 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 vm.mlvm.share;2425import jdk.test.lib.JDKToolLauncher;26import jdk.test.lib.Utils;27import jdk.test.lib.process.ProcessTools;28import nsk.share.jdi.sde.InstallSDE;29import vm.mlvm.tools.StratumAP;3031import java.io.IOException;32import java.nio.file.Files;33import java.nio.file.Path;34import java.nio.file.Paths;35import java.util.Arrays;36import java.util.stream.Stream;3738public class StratumClassesBuilder {39public static void main(String[] args) {40Path root = Paths.get(Utils.TEST_ROOT);41Arrays.stream(args)42.map(root::resolve)43.forEach(StratumClassesBuilder::build);44}4546private static void build(Path file) {47if (Files.notExists(file)) {48throw new Error("can't find " + file);49}50Path dst = Paths.get("bin")51.resolve("classes");52mkdir(dst);53compile(file, dst);54if (file.getFileName().toString().contains("SDE_")) {55IndifiedClassesBuilder.main(dst.toAbsolutePath().toString());56}57addStratum(dst);58}5960private static void mkdir(Path dst) {61try {62Files.createDirectories(dst);63} catch (IOException e) {64throw new Error("can't create dir " + dst, e);65}66}6768private static void compile(Path file, Path dst) {69JDKToolLauncher javac = JDKToolLauncher.create("javac")70.addToolArg("-d")71.addToolArg(dst.toString())72.addToolArg("-cp")73.addToolArg(Utils.TEST_CLASS_PATH)74.addToolArg("-processor")75.addToolArg(StratumAP.class.getName())76.addToolArg(file.toAbsolutePath().toString());7778String[] command = javac.getCommand();79try {80ProcessTools.executeCommand(command)81.shouldHaveExitValue(0);82} catch (Error | RuntimeException e) {83throw e;84} catch (Throwable e) {85throw new Error("execution of javac(" + Arrays.toString(command) + ") failed", e);86}87}8889private static void addStratum(Path dst) {90try (Stream<Path> files = Files.walk(dst)) {91files.map(Path::toAbsolutePath)92.filter(p -> p.getFileName().toString().contains("SDE_"))93.filter(p -> p.toString().endsWith(".class"))94.forEach(p -> {95try {96InstallSDE.install(97p.toFile(),98classToSmap(p).toFile(),99p.toFile(),100true);101} catch (IOException e) {102throw new Error("can't install sde for " + p);103}104});105} catch (IOException e) {106throw new Error("can't traverse " + dst, e);107}108}109110private static Path classToSmap(Path file) {111String filename = file.getFileName().toString();112return file.getParent()113.resolve(filename.replaceFirst("\\.class$", ".smap"));114}115}116117118