Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/CompileCommand.java
41161 views
/*1* Copyright (c) 2015, 2020, 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 compiler.compilercontrol.share.method.MethodDescriptor;2627/**28* Compile Command description interface29*/30public class CompileCommand {31public final Command command;32public final MethodDescriptor methodDescriptor;33public final Scenario.Compiler compiler;34public final Scenario.Type type;35public final String argument;3637public CompileCommand(Command command,38MethodDescriptor methodDescriptor,39Scenario.Compiler compiler,40Scenario.Type type) {41this.command = command;42this.methodDescriptor = methodDescriptor;43this.compiler = compiler;44this.type = type;45this.argument = null;46}4748public CompileCommand(Command command,49MethodDescriptor methodDescriptor,50Scenario.Compiler compiler,51Scenario.Type type,52String argument) {53this.command = command;54this.methodDescriptor = methodDescriptor;55this.compiler = compiler;56this.type = type;57this.argument = argument;58}596061/**62* Shows that this compile command is valid63*64* @return true if this is a valid command65*/66public boolean isValid() {67if (command == Command.NONEXISTENT) {68return false;69}70// -XX:CompileCommand(File) ignores invalid items71// Invalid intrinsic ids in CompilerDirectivesFile will force hotspot to exit with non-zero value.72if (command == Command.INTRINSIC && type == Scenario.Type.DIRECTIVE) {73if (argument != null) {74String[] ids = argument.split(",");75for (String id : ids) {76char ch = id.charAt(0);7778// Not a strict check.79// a valid ControlIntrinsic argument is separated by ",", each one starts with '+' or '-'.80// intrinsicId starts with '_'81if ((ch != '+' && ch != '-') || id.charAt(1) != '_') {82return false;83}84}85}86}8788return methodDescriptor.isValid();89}9091/**92* Formats the command according to the following pattern:93* {@code <command_name> Type: <type> Compiler: <compiler> MethodDescriptor: <method_descriptor> IsValid: <true/false>}94* Sample output:95* COMPILEONLY Type: OPTION Compiler: C1 MethodDescriptor: *Klass.method* IsValid: true96*/97protected String formatFields() {98return command.name() +99" Type: " + type +100" Compiler: " + compiler +101" MethodDescriptor: " + (methodDescriptor == null ? "null" : methodDescriptor.getString()) +102" IsValid: " + isValid();103}104105/**106* Returns formatted string representation in the form107* {@code "(CompileCommand Field1: <field1> Field2: <field2> ...)}108* The fields are formatted by {@link #formatFields()}.109*/110public String toString() {111return "(CompileCommand " + formatFields() + ")";112}113}114115116