001/* 002 * This file is part of the Jikes RVM project (http://jikesrvm.org). 003 * 004 * This file is licensed to You under the Eclipse Public License (EPL); 005 * You may not use this file except in compliance with the License. You 006 * may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/eclipse-1.0.php 009 * 010 * See the COPYRIGHT.txt file distributed with this work for information 011 * regarding copyright ownership. 012 */ 013package org.jikesrvm.compilers.baseline; 014 015import static org.jikesrvm.runtime.ExitStatus.*; 016 017import org.jikesrvm.VM; 018 019/** 020 * Class to handle command-line arguments and options for the 021 * baseline compiler. 022 * <p> 023 * Note: This file is mechanically generated from BaselineOptions.template 024 * and MasterOptions.template 025 * <p> 026 * Note: Boolean options are defined in /home/vagrant/rvm-trunk/rvm/src-generated/options/BooleanOptions.baseline.dat /home/vagrant/rvm-trunk/rvm/src-generated/options/SharedBooleanOptions.dat 027 * All other options are defined in /home/vagrant/rvm-trunk/rvm/src-generated/options/ValueOptions.baseline.dat /home/vagrant/rvm-trunk/rvm/src-generated/options/SharedValueOptions.dat 028 * (value, enumeration, bitmask) 029 * 030 **/ 031public final class BaselineOptions implements Cloneable { 032 033 private void printOptionsHeader() { 034 VM.sysWriteln("Current value of options for Baseline compiler:"); 035 } 036 037// BEGIN CODE GENERATED FROM MasterOptions.template 038/* 039 * This file is part of the Jikes RVM project (http://jikesrvm.org). 040 * 041 * This file is licensed to You under the Eclipse Public License (EPL); 042 * You may not use this file except in compliance with the License. You 043 * may obtain a copy of the License at 044 * 045 * http://www.opensource.org/licenses/eclipse-1.0.php 046 * 047 * See the COPYRIGHT.txt file distributed with this work for information 048 * regarding copyright ownership. 049 */ 050 // Begin template-specified options 051 /** Insert edge counters on all bytecode-level conditional branches */ 052 public boolean PROFILE_EDGE_COUNTERS = VM.BuildForAdaptiveSystem; 053 /** Select methods for optimized recompilation by using invocation counters */ 054 public boolean INVOCATION_COUNTERS = false; 055 /** Print method name at start of compilation */ 056 public boolean PRINT_METHOD = false; 057 /** Print final machine code */ 058 public boolean PRINT_MACHINECODE = false; 059 /** File into which to dump edge counter data */ 060 public String PROFILE_EDGE_COUNTER_FILE = "EdgeCounters"; 061 /** Only apply print options against methods whose name contains this string */ 062 private java.util.HashSet<String> METHOD_TO_PRINT = null; 063 // End template-specified options 064 065 // Begin generated support for "Enumeration" options 066 // End generated support for "Enumeration" options 067 068 // Begin generated support for "Set" options 069 // METHOD_TO_PRINT 070 /** 071 * Has the given parameter been added to METHOD_TO_PRINT set of options? 072 * 073 * @param q the parameter 074 * @return {@code true} when the parameter has been added, 075 * {@code false} otherwise 076 */ 077 public boolean isMETHOD_TO_PRINT(String q) { 078 return METHOD_TO_PRINT != null && METHOD_TO_PRINT.contains(q); 079 } 080 /** 081 * Does the given parameter appear within a set the String of one of the options? 082 * 083 * @param q the parameter to search for 084 * @return {@code true} when it does appear, {@code false} otherwise 085 */ 086 public boolean fuzzyMatchMETHOD_TO_PRINT(String q) { 087 if (METHOD_TO_PRINT != null) { 088 for (final String s : METHOD_TO_PRINT) { 089 if (q.indexOf(s) > -1) 090 return true; 091 } 092 } 093 return false; 094 } 095 /** 096 * Have any items been placed in the set METHOD_TO_PRINT? 097 * 098 * @return {@code true} if the set exists and is not empty 099 */ 100 public boolean hasMETHOD_TO_PRINT() { 101 return METHOD_TO_PRINT != null && !METHOD_TO_PRINT.isEmpty(); 102 } 103 /** 104 * Return an iterator over the items in METHOD_TO_PRINT 105 * 106 * @return an iterator over the items in METHOD_TO_PRINT. The iterator 107 * may be empty. 108 */ 109 public java.util.Iterator<String> getMETHOD_TO_PRINTs() { 110 if (METHOD_TO_PRINT == null) { 111 return org.jikesrvm.util.EmptyIterator.<String>getInstance(); 112 } else { 113 return METHOD_TO_PRINT.iterator(); 114 } 115 } 116 // End generated support for "Set" options 117 118 @Override 119 @SuppressWarnings("unchecked") 120 public Object clone() throws CloneNotSupportedException { 121 BaselineOptions clone = (BaselineOptions)super.clone(); 122 if (METHOD_TO_PRINT != null) { 123 clone.METHOD_TO_PRINT = (java.util.HashSet<String>)this.METHOD_TO_PRINT.clone(); 124 } 125 return clone; 126 } 127 128 public BaselineOptions dup() { 129 try { 130 return (BaselineOptions) clone(); 131 } 132 catch (CloneNotSupportedException e) { 133 final InternalError error = new InternalError("Unexpected CloneNotSupportedException."); 134 error.initCause(e); 135 throw error; 136 } 137 } 138 139 /** 140 * Take a string (most likely a command-line argument) and try to proccess it 141 * as an option command. Return true if the string was understood, false 142 * otherwise. 143 * 144 * @param prefix a Sring to use as a command prefix when printing help. 145 * @param arg a String to try to process as an option command 146 * @return true if successful, false otherwise 147 */ 148 @org.vmmagic.pragma.NoOptCompile 149 public boolean processAsOption(String prefix, String arg) { 150 151 // First handle the "option commands" 152 if (arg.equals("help")) { 153 printHelp(prefix); 154 return true; 155 } 156 if (arg.equals("printOptions")) { 157 printOptions(); 158 return true; 159 } 160 if (arg.length() == 0) { 161 printHelp(prefix); 162 return true; 163 } 164 // Make sure only process O? option if initial runtime compiler! 165 if ((prefix.indexOf("irc")!=-1 || 166 prefix.indexOf("bc")!=-1 || 167 prefix.indexOf("eoc")!=-1) && 168 instanceProcessAsOption(arg)) { 169 return true; 170 } 171 172 // Required format of arg is 'name=value' 173 // Split into 'name' and 'value' strings 174 int split = arg.indexOf('='); 175 if (split == -1) { 176 if (!(arg.equals("O0") || arg.equals("O1") || arg.equals("O2") || arg.equals("O3"))) { 177 VM.sysWrite(" Illegal option specification!\n \""+arg+ 178 "\" must be specified as a name-value pair in the form of option=value\n"); 179 } 180 return false; 181 } 182 String name = arg.substring(0,split); 183 String value = arg.substring(split+1); 184 185 //Begin generated command-line processing 186 if (name.equals("profile_edge_counters")) { 187 if (value.equals("true")) { 188 PROFILE_EDGE_COUNTERS = true; 189 return true; 190 } else if (value.equals("false")) { 191 PROFILE_EDGE_COUNTERS = false; 192 return true; 193 } else 194 return false; 195 } 196 if (name.equals("invocation_counters")) { 197 if (value.equals("true")) { 198 INVOCATION_COUNTERS = true; 199 return true; 200 } else if (value.equals("false")) { 201 INVOCATION_COUNTERS = false; 202 return true; 203 } else 204 return false; 205 } 206 if (name.equals("verbose")) { 207 if (value.equals("true")) { 208 PRINT_METHOD = true; 209 return true; 210 } else if (value.equals("false")) { 211 PRINT_METHOD = false; 212 return true; 213 } else 214 return false; 215 } 216 if (name.equals("mc")) { 217 if (value.equals("true")) { 218 PRINT_MACHINECODE = true; 219 return true; 220 } else if (value.equals("false")) { 221 PRINT_MACHINECODE = false; 222 return true; 223 } else 224 return false; 225 } 226 if (name.equals("profile_edge_counter_file")) { 227 PROFILE_EDGE_COUNTER_FILE = value; 228 return true; 229 } 230 if (name.equals("method_to_print")) { 231 if (METHOD_TO_PRINT == null) { 232 METHOD_TO_PRINT = new java.util.HashSet<String>(); 233 } 234 METHOD_TO_PRINT.add(value); 235 return true; 236 } 237 //End generated command-line processing 238 239 // None of the above tests matched, so this wasn't an option 240 return false; 241 } 242 243 /** 244 * Prints a short description of every option 245 * 246 * @param prefix the prefix for the option 247 */ 248 public static void printHelp(String prefix) { 249 250 instancePrintHelpHeader(prefix); 251 252 //Begin generated help messages 253 VM.sysWrite("Boolean Options ("+prefix+"<option>=true or "+prefix+":<option>=false)\n"); 254 VM.sysWrite("Option Description\n"); 255 VM.sysWrite("profile_edge_counters Insert edge counters on all bytecode-level conditional branches\n"); 256 VM.sysWrite("invocation_counters Select methods for optimized recompilation by using invocation counters\n"); 257 VM.sysWrite("verbose Print method name at start of compilation\n"); 258 VM.sysWrite("mc Print final machine code\n"); 259 VM.sysWrite("\nValue Options ("+prefix+"<option>=<value>)\n"); 260 VM.sysWrite("Option Type Description\n"); 261 VM.sysWrite("profile_edge_counter_file String File into which to dump edge counter data\n"); 262 VM.sysWrite("\nSelection Options (set option to one of an enumeration of possible values)\n"); 263 VM.sysWrite("\nSet Options (option is a set of values)\n"); 264 VM.sysWrite("method_to_print Only apply print options against methods whose name contains this string\n"); 265 instancePrintHelpFooter(prefix); 266 267 VM.sysExit(EXIT_STATUS_PRINTED_HELP_MESSAGE); 268 } 269 270 /** @return a String representing the options values */ 271 @Override 272 @org.vmmagic.pragma.NoOptCompile 273 public String toString() { 274 StringBuilder result = new StringBuilder(); 275 276 // Begin generated option value printing 277 result.append("\tprofile_edge_counters = ").append(PROFILE_EDGE_COUNTERS).append("\n"); 278 result.append("\tinvocation_counters = ").append(INVOCATION_COUNTERS).append("\n"); 279 result.append("\tverbose = ").append(PRINT_METHOD).append("\n"); 280 result.append("\tmc = ").append(PRINT_MACHINECODE).append("\n"); 281 result.append("\tprofile_edge_counter_file = ").append(PROFILE_EDGE_COUNTER_FILE).append("\n"); 282 { 283 String val = (METHOD_TO_PRINT==null)?"[]":METHOD_TO_PRINT.toString(); 284 result.append("\tmethod_to_print = ").append(val).append("\n"); 285 } 286 return result.toString(); 287 //End generated toString() 288 } 289 290 /** print a String value of this options object */ 291 @org.vmmagic.pragma.NoOptCompile 292 public void printOptions() { 293 printOptionsHeader(); 294 295 // Begin generated option value printing 296 VM.sysWriteln("\tprofile_edge_counters = ",PROFILE_EDGE_COUNTERS); 297 VM.sysWriteln("\tinvocation_counters = ",INVOCATION_COUNTERS); 298 VM.sysWriteln("\tverbose = ",PRINT_METHOD); 299 VM.sysWriteln("\tmc = ",PRINT_MACHINECODE); 300 VM.sysWriteln("\tprofile_edge_counter_file = ",PROFILE_EDGE_COUNTER_FILE); 301 { 302 String val = (METHOD_TO_PRINT==null)?"[]":METHOD_TO_PRINT.toString(); 303 VM.sysWriteln("\tmethod_to_print = ", val); 304 } 305 //End generated option value printing 306 } 307// END CODE GENERATED FROM MasterOptions.template 308 309 private boolean instanceProcessAsOption(String arg) { 310 return false; 311 } 312 313 private static void instancePrintHelpHeader(String prefix) { 314 VM.sysWrite("Commands\n"); 315 VM.sysWrite(prefix+"[:help]\t\t\tPrint brief description of baseline compiler's command-line arguments\n"); 316 VM.sysWrite(prefix+":printOptions\t\tPrint the current values of the active baseline compiler options\n"); 317 VM.sysWrite("\n"); 318 } 319 320 private static void instancePrintHelpFooter(String prefix) { 321 } 322}