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