Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/CommandFileBuilder.java
41161 views
/*1* Copyright (c) 2015, 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 compiler.compilercontrol.share.scenario;2425import java.io.IOException;26import java.io.PrintWriter;27import java.util.ArrayList;28import java.util.List;29import java.util.function.Function;3031/**32* Creates CompileCommandFile from the given array of commands33*/34public class CommandFileBuilder extends AbstractCommandBuilder {35private final String fileName;3637public CommandFileBuilder(String fileName) {38this.fileName = fileName;39}4041@Override42public List<String> getOptions() {43Function<CompileCommand, String> mapper = cc -> {44StringBuilder sb = new StringBuilder(cc.command.name);45sb.append(" ");46sb.append(cc.methodDescriptor.getString());47if (cc.argument != null) {48sb.append(" ");49sb.append(cc.argument);50}51return sb.toString();52};5354// Create CommandFile55try (PrintWriter pw = new PrintWriter(fileName)) {56compileCommands.stream()57.map(mapper)58.forEach(pw::println);59if (pw.checkError()) {60throw new Error("TESTBUG: write error");61}62} catch (IOException e) {63throw new Error("TESTBUG: can't write a file", e);64}65List<String> opt = new ArrayList<>();66opt.add("-XX:CompileCommandFile=" + fileName);67return opt;68}69}707172