public static String getVersionString() { String fullVersion = String.format( "jruby %s (%s) %s %s %s %s on %s%s%s [%s-%s]", Constants.VERSION, Constants.RUBY_VERSION, Constants.COMPILE_DATE, Constants.REVISION, SafePropertyAccessor.getProperty("java.vm.name", "Unknown JVM"), SafePropertyAccessor.getProperty("java.vm.version", "Unknown JVM version"), SafePropertyAccessor.getProperty( "java.runtime.version", SafePropertyAccessor.getProperty("java.version", "Unknown version")), Options.COMPILE_INVOKEDYNAMIC.load() ? " +indy" : "", Options.COMPILE_MODE.load().shouldJIT() ? " +jit" : "", RbConfigLibrary.getOSName(), RbConfigLibrary.getArchitecture()); return fullVersion; }
public void processDotfile() { // try current dir, then home dir String home = SafePropertyAccessor.getProperty("user.dir"); File dotfile = new File(home + "/.jrubyrc"); if (!dotfile.exists()) { home = SafePropertyAccessor.getProperty("user.home"); dotfile = new File(home + "/.jrubyrc"); } // no dotfile! if (!dotfile.exists()) return; // update system properties with long form jruby properties from .jrubyrc Properties sysProps = System.getProperties(); Properties newProps = new Properties(); FileInputStream fis = null; try { // load properties and re-set as jruby.* fis = new FileInputStream(dotfile); newProps.load(fis); for (Map.Entry entry : newProps.entrySet()) { sysProps.put("jruby." + entry.getKey(), entry.getValue()); } // replace system properties System.setProperties(sysProps); } catch (IOException ioe) { // do anything? } finally { if (fis != null) try { fis.close(); } catch (Exception e) { } } }
private Status handleOutOfMemory(OutOfMemoryError oome) { // produce a nicer error since Rubyists aren't used to seeing this System.gc(); String memoryMax = SafePropertyAccessor.getProperty("jruby.memory.max"); String message = ""; if (memoryMax != null) { message = " of " + memoryMax; } config .getError() .println("Error: Your application used more memory than the safety cap" + message + "."); config.getError().println("Specify -J-Xmx####m to increase it (#### = cap size in MB)."); if (config.isVerbose()) { config.getError().println("Exception trace follows:"); oome.printStackTrace(); } else { config.getError().println("Specify -w for full OutOfMemoryError stack trace"); } return new Status(1); }
private static List<String> getDotfileDirectories() { ArrayList<String> searchList = new ArrayList<String>(); for (String homeProp : new String[] {"user.dir", "user.home"}) { String home = SafePropertyAccessor.getProperty(homeProp); if (home != null) searchList.add(home); } // JVM sometimes picks odd location for user.home based on a registry entry // (see http://bugs.sun.com/view_bug.do?bug_id=4787931). Add extra check in // case that entry is wrong. Add before user.home in search list. if (Platform.IS_WINDOWS) { String homeDrive = System.getenv("HOMEDRIVE"); String homePath = System.getenv("HOMEPATH"); if (homeDrive != null && homePath != null) { searchList.add(1, (homeDrive + homePath).replace('\\', '/')); } } return searchList; }
private Status handleStackOverflow(StackOverflowError soe) { // produce a nicer error since Rubyists aren't used to seeing this System.gc(); String stackMax = SafePropertyAccessor.getProperty("jruby.stack.max"); String message = ""; if (stackMax != null) { message = " of " + stackMax; } config .getError() .println( "Error: Your application used more stack memory than the safety cap" + message + "."); config.getError().println("Specify -J-Xss####k to increase it (#### = cap size in KB)."); if (config.isVerbose()) { config.getError().println("Exception trace follows:"); soe.printStackTrace(); } else { config.getError().println("Specify -w for full StackOverflowError stack trace"); } return new Status(1); }
public static String getLibDir(Ruby runtime) { String libdir = SafePropertyAccessor.getProperty("jruby.lib"); if (libdir == null) { String home = getNormalizedHome(runtime); if (home.startsWith("uri:")) { libdir = home + "/lib"; } else { libdir = new NormalizedFile(home, "lib").getPath(); } } else { try { // Our shell scripts pass in non-canonicalized paths, but even if we didn't // anyone who did would become unhappy because Ruby apps expect no relative // operators in the pathname (rubygems, for example). libdir = new NormalizedFile(libdir).getCanonicalPath(); } catch (IOException e) { libdir = new NormalizedFile(libdir).getAbsolutePath(); } } return libdir; }
// TODO: note lack of command.com support for Win 9x... public static String jrubyShell() { return SafePropertyAccessor.getProperty( "jruby.shell", Platform.IS_WINDOWS ? "cmd.exe" : "/bin/sh") .replace('\\', '/'); }
public static String jrubyScript() { return SafePropertyAccessor.getProperty("jruby.script", "jruby").replace('\\', '/'); }
/** * Just enough configuration settings (most don't make sense in Java) to run the rubytests unit * tests. The tests use <code>bindir</code>, <code>RUBY_INSTALL_NAME</code> and <code>EXEEXT * </code>. */ public void load(Ruby runtime, boolean wrap) { RubyModule configModule; configModule = runtime.defineModule("RbConfig"); RubyKernel.autoload( runtime.getObject(), runtime.newSymbol("Config"), runtime.newString("rbconfig/obsolete.rb")); configModule.defineAnnotatedMethods(RbConfigLibrary.class); RubyHash configHash = RubyHash.newHash(runtime); configModule.defineConstant("CONFIG", configHash); String[] versionParts; versionParts = Constants.RUBY_VERSION.split("\\."); setConfig(configHash, "MAJOR", versionParts[0]); setConfig(configHash, "MINOR", versionParts[1]); setConfig(configHash, "TEENY", versionParts[2]); setConfig(configHash, "ruby_version", versionParts[0] + '.' + versionParts[1] + ".0"); // Rubygems is too specific on host cpu so until we have real need lets default to universal // setConfig(configHash, "arch", System.getProperty("os.arch") + "-java" + // System.getProperty("java.specification.version")); setConfig( configHash, "arch", "universal-java" + System.getProperty("java.specification.version")); normalizedHome = getNormalizedHome(runtime); // Use property for binDir if available, otherwise fall back to common bin default String binDir = SafePropertyAccessor.getProperty("jruby.bindir"); if (binDir == null) { binDir = new NormalizedFile(normalizedHome, "bin").getPath(); } setConfig(configHash, "bindir", binDir); setConfig(configHash, "RUBY_INSTALL_NAME", jrubyScript()); setConfig(configHash, "RUBYW_INSTALL_NAME", IS_WINDOWS ? "jrubyw.exe" : jrubyScript()); setConfig(configHash, "ruby_install_name", jrubyScript()); setConfig(configHash, "rubyw_install_name", IS_WINDOWS ? "jrubyw.exe" : jrubyScript()); setConfig(configHash, "SHELL", jrubyShell()); setConfig(configHash, "prefix", normalizedHome); setConfig(configHash, "exec_prefix", normalizedHome); setConfig(configHash, "host_os", getOSName()); setConfig(configHash, "host_vendor", System.getProperty("java.vendor")); setConfig(configHash, "host_cpu", getArchitecture()); setConfig(configHash, "target_os", getOSName()); setConfig(configHash, "target_cpu", getArchitecture()); String jrubyJarFile = "jruby.jar"; URL jrubyPropertiesUrl = Ruby.getClassLoader().getResource("/org/jruby/Ruby.class"); if (jrubyPropertiesUrl != null) { Pattern jarFile = Pattern.compile("jar:file:.*?([a-zA-Z0-9.\\-]+\\.jar)!" + "/org/jruby/Ruby.class"); Matcher jarMatcher = jarFile.matcher(jrubyPropertiesUrl.toString()); jarMatcher.find(); if (jarMatcher.matches()) { jrubyJarFile = jarMatcher.group(1); } } setConfig(configHash, "LIBRUBY", jrubyJarFile); setConfig(configHash, "LIBRUBY_SO", jrubyJarFile); setConfig(configHash, "LIBRUBY_SO", jrubyJarFile); setConfig(configHash, "LIBRUBY_ALIASES", jrubyJarFile); setConfig(configHash, "build", Constants.BUILD); setConfig(configHash, "target", Constants.TARGET); String shareDir = new NormalizedFile(normalizedHome, "share").getPath(); String includeDir = new NormalizedFile(normalizedHome, "lib/native/" + getOSName()).getPath(); String vendorDirGeneral = getVendorDirGeneral(runtime); String siteDirGeneral = getSiteDirGeneral(runtime); String rubySharedLibDir = getRubySharedLibDir(runtime); String rubyLibDir = getRubyLibDir(runtime); String archDir = getArchDir(runtime); String vendorDir = getVendorDir(runtime); String vendorLibDir = getVendorLibDir(runtime); String vendorArchDir = getVendorArchDir(runtime); String siteDir = getSiteDir(runtime); String siteLibDir = getSiteLibDir(runtime); String siteArchDir = getSiteArchDir(runtime); String sysConfDir = getSysConfDir(runtime); setConfig(configHash, "libdir", vendorDirGeneral); setConfig(configHash, "rubylibprefix", vendorDirGeneral + "/ruby"); setConfig(configHash, "rubylibdir", rubyLibDir); setConfig(configHash, "rubysharedlibdir", rubySharedLibDir); if (!isSiteVendorSame(runtime)) { setConfig(configHash, "vendordir", vendorDir); setConfig(configHash, "vendorlibdir", vendorLibDir); setConfig(configHash, "vendorarchdir", vendorArchDir); } setConfig(configHash, "sitedir", siteDir); setConfig(configHash, "sitelibdir", siteLibDir); setConfig(configHash, "sitearchdir", siteArchDir); setConfig(configHash, "sitearch", "java"); setConfig(configHash, "archdir", archDir); setConfig(configHash, "topdir", archDir); setConfig(configHash, "includedir", includeDir); setConfig(configHash, "configure_args", ""); setConfig(configHash, "datadir", shareDir); setConfig(configHash, "mandir", new NormalizedFile(normalizedHome, "man").getPath()); setConfig(configHash, "sysconfdir", sysConfDir); setConfig(configHash, "localstatedir", new NormalizedFile(normalizedHome, "var").getPath()); setConfig(configHash, "DLEXT", "jar"); if (getRubygemsDir(runtime) != null) { setConfig(configHash, "rubygemsdir", new NormalizedFile(getRubygemsDir(runtime)).getPath()); } if (Platform.IS_WINDOWS) { setConfig(configHash, "EXEEXT", ".exe"); } else { setConfig(configHash, "EXEEXT", ""); } setConfig(configHash, "ridir", new NormalizedFile(shareDir, "ri").getPath()); // These will be used as jruby defaults for rubygems if found String gemhome = SafePropertyAccessor.getProperty("jruby.gem.home"); String gempath = SafePropertyAccessor.getProperty("jruby.gem.path"); if (gemhome != null) setConfig(configHash, "default_gem_home", gemhome); if (gempath != null) setConfig(configHash, "default_gem_path", gempath); setConfig(configHash, "joda-time.version", Constants.JODA_TIME_VERSION); setConfig(configHash, "tzdata.version", Constants.TZDATA_VERSION); RubyHash mkmfHash = RubyHash.newHash(runtime); setConfig(mkmfHash, "libdir", vendorDirGeneral); setConfig(mkmfHash, "arch", "java"); setConfig(mkmfHash, "rubylibdir", rubyLibDir); setConfig(mkmfHash, "rubysharedlibdir", rubySharedLibDir); if (!isSiteVendorSame(runtime)) { setConfig(mkmfHash, "vendordir", vendorDir); setConfig(mkmfHash, "vendorlibdir", vendorLibDir); setConfig(mkmfHash, "vendorarchdir", vendorArchDir); } setConfig(mkmfHash, "sitedir", siteDir); setConfig(mkmfHash, "sitelibdir", siteLibDir); setConfig(mkmfHash, "sitearchdir", siteArchDir); setConfig(mkmfHash, "sitearch", "java"); setConfig(mkmfHash, "archdir", archDir); setConfig(mkmfHash, "topdir", archDir); setConfig(mkmfHash, "configure_args", ""); setConfig(mkmfHash, "datadir", new NormalizedFile(normalizedHome, "share").getPath()); setConfig(mkmfHash, "mandir", new NormalizedFile(normalizedHome, "man").getPath()); setConfig(mkmfHash, "sysconfdir", sysConfDir); setConfig(mkmfHash, "localstatedir", new NormalizedFile(normalizedHome, "var").getPath()); if (getRubygemsDir(runtime) != null) { setConfig(mkmfHash, "rubygemsdir", new NormalizedFile(getRubygemsDir(runtime)).getPath()); } setupMakefileConfig(configModule, mkmfHash); runtime.getLoadService().load("jruby/kernel/rbconfig.rb", false); }
public static String getRubygemsDir(Ruby runtime) { // used when integrating JRuby with system RubyGems - example: /usr/share/rubygems return SafePropertyAccessor.getProperty("vendor.dir.rubygems", null); }
public static String getSiteDirGeneral(Ruby runtime) { // siteDirGeneral example: /usr/local/share/jruby/lib/ return new NormalizedFile( SafePropertyAccessor.getProperty("site.dir.general", getLibDir(runtime))) .getPath(); }
public static String getVendorDirGeneral(Ruby runtime) { // vendorDirGeneral example: /usr/share/jruby/lib/ - commonly the same as libdir return new NormalizedFile( SafePropertyAccessor.getProperty("vendor.dir.general", getLibDir(runtime))) .getPath(); }
public int run(String[] args) { try { config.processArguments(args); return run(); } catch (MainExitException mee) { if (!mee.isAborted()) { config.getOutput().println(mee.getMessage()); if (mee.isUsageError()) { printUsage(); } } return mee.getStatus(); } catch (OutOfMemoryError oome) { // produce a nicer error since Rubyists aren't used to seeing this System.gc(); String memoryMax = SafePropertyAccessor.getProperty("jruby.memory.max"); String message = ""; if (memoryMax != null) { message = " of " + memoryMax; } config .getError() .println("Error: Your application used more memory than the safety cap" + message + "."); config.getError().println("Specify -J-Xmx####m to increase it (#### = cap size in MB)."); if (config.getVerbose()) { config.getError().println("Exception trace follows:"); oome.printStackTrace(); } else { config.getError().println("Specify -w for full OutOfMemoryError stack trace"); } return 1; } catch (StackOverflowError soe) { // produce a nicer error since Rubyists aren't used to seeing this System.gc(); String stackMax = SafePropertyAccessor.getProperty("jruby.stack.max"); String message = ""; if (stackMax != null) { message = " of " + stackMax; } config .getError() .println( "Error: Your application used more stack memory than the safety cap" + message + "."); config.getError().println("Specify -J-Xss####k to increase it (#### = cap size in KB)."); if (config.getVerbose()) { config.getError().println("Exception trace follows:"); soe.printStackTrace(); } else { config.getError().println("Specify -w for full StackOverflowError stack trace"); } return 1; } catch (UnsupportedClassVersionError ucve) { config .getError() .println("Error: Some library (perhaps JRuby) was built with a later JVM version."); config .getError() .println( "Please use libraries built with the version you intend to use or an earlier one."); if (config.getVerbose()) { config.getError().println("Exception trace follows:"); ucve.printStackTrace(); } else { config.getError().println("Specify -w for full UnsupportedClassVersionError stack trace"); } return 1; } catch (ThreadKill kill) { return 0; } }
/** * Options defines all configuration settings for JRuby in a consistent form. Loading of individual * settings, printing documentation for settings and their options and defaults, and categorizing * properties by function are all part of the built-in structure. */ public class Options { private static final List<Option> _loadedOptions = new ArrayList<Option>(); private static final boolean INVOKEDYNAMIC_DEFAULT = calculateInvokedynamicDefault(); // This section holds all Options for JRuby. They will be listed in the // --properties output. public static final Option<Boolean> PARSER_DETAILED_SOURCE_POSITIONS = bool(PARSER, "parser.detailed_source_positions", false, "Produce detailed source positions"); public static final Option<Boolean> PARSER_WARN_USELESSS_USE_OF = bool( PARSER, "parser.warn.useless_use_of", true, "Warn about potentially useless expressions in void contents."); public static final Option<Boolean> PARSER_WARN_NOT_REACHED = bool( PARSER, "parser.warn.not_reached", true, "Warn about statements that can never be reached."); public static final Option<Boolean> PARSER_WARN_GROUPED_EXPRESSIONS = bool( PARSER, "parser.warn.grouped_expressions", true, "Warn about interpreting (...) as a grouped expression."); public static final Option<Boolean> PARSER_WARN_LOCAL_SHADOWING = bool(PARSER, "parser.warn.shadowing_local", true, "Warn about shadowing local variables."); public static final Option<Boolean> PARSER_WARN_REGEX_CONDITION = bool(PARSER, "parser.warn.regex_condition", true, "Warn about regex literals in conditions."); public static final Option<Boolean> PARSER_WARN_ARGUMENT_PREFIX = bool( PARSER, "parser.warn.argument_prefix", true, "Warn about splat operators being interpreted as argument prefixes."); public static final Option<Boolean> PARSER_WARN_AMBIGUOUS_ARGUMENTS = bool(PARSER, "parser.warn.ambiguous_argument", true, "Warn about ambiguous arguments."); public static final Option<Boolean> PARSER_WARN_FLAGS_IGNORED = bool( PARSER, "parser.warn.flags_ignored", true, "Warn about ignored regex flags being ignored."); public static final Option<CompileMode> COMPILE_MODE = enumeration( COMPILER, "compile.mode", CompileMode.class, CompileMode.JIT, "Set compilation mode. JIT = at runtime; FORCE = before execution."); public static final Option<Boolean> COMPILE_DUMP = bool(COMPILER, "compile.dump", false, "Dump to console all bytecode generated at runtime."); public static final Option<Boolean> COMPILE_THREADLESS = bool( COMPILER, "compile.threadless", false, "(EXPERIMENTAL) Turn on compilation without polling for \"unsafe\" thread events."); public static final Option<Boolean> COMPILE_FASTOPS = bool(COMPILER, "compile.fastops", true, "Turn on fast operators for Fixnum and Float."); public static final Option<Integer> COMPILE_CHAINSIZE = integer( COMPILER, "compile.chainsize", Constants.CHAINED_COMPILE_LINE_COUNT_DEFAULT, "Set the number of lines at which compiled bodies are \"chained\"."); public static final Option<Boolean> COMPILE_LAZYHANDLES = bool( COMPILER, "compile.lazyHandles", false, "Generate method bindings (handles) for compiled methods lazily."); public static final Option<Boolean> COMPILE_PEEPHOLE = bool(COMPILER, "compile.peephole", true, "Enable or disable peephole optimizations."); public static final Option<Boolean> COMPILE_NOGUARDS = bool( COMPILER, "compile.noguards", false, "Compile calls without guards, for experimentation."); public static final Option<Boolean> COMPILE_FASTEST = bool( COMPILER, "compile.fastest", false, "Compile with all \"mostly harmless\" compiler optimizations."); public static final Option<Boolean> COMPILE_FASTSEND = bool( COMPILER, "compile.fastsend", false, "Compile obj.__send__(<literal>, ...) as obj.<literal>(...)."); public static final Option<Boolean> COMPILE_FASTMASGN = bool( COMPILER, "compile.fastMasgn", false, "Return true from multiple assignment instead of a new array."); public static final Option<Boolean> COMPILE_INVOKEDYNAMIC = bool( COMPILER, "compile.invokedynamic", INVOKEDYNAMIC_DEFAULT, "Use invokedynamic for optimizing Ruby code."); public static final Option<Integer> COMPILE_OUTLINE_CASECOUNT = integer( COMPILER, "compile.outline.casecount", 50, "Outline when bodies when number of cases exceeds this value."); public static final Option<Integer> INVOKEDYNAMIC_MAXFAIL = integer( INVOKEDYNAMIC, "invokedynamic.maxfail", 1000, "Maximum call site failures after which to inline cache."); public static final Option<Integer> INVOKEDYNAMIC_MAXPOLY = integer(INVOKEDYNAMIC, "invokedynamic.maxpoly", 6, "Maximum polymorphism of PIC binding."); public static final Option<Boolean> INVOKEDYNAMIC_LOG_BINDING = bool( INVOKEDYNAMIC, "invokedynamic.log.binding", false, "Log binding of invokedynamic call sites."); public static final Option<Boolean> INVOKEDYNAMIC_LOG_CONSTANTS = bool( INVOKEDYNAMIC, "invokedynamic.log.constants", false, "Log invokedynamic-based constant lookups."); public static final Option<Boolean> INVOKEDYNAMIC_LOG_GLOBALS = bool( INVOKEDYNAMIC, "invokedynamic.log.globals", false, "Log invokedynamic-based global lookups."); public static final Option<Boolean> INVOKEDYNAMIC_ALL = bool(INVOKEDYNAMIC, "invokedynamic.all", false, "Enable all possible uses of invokedynamic."); public static final Option<Boolean> INVOKEDYNAMIC_SAFE = bool( INVOKEDYNAMIC, "invokedynamic.safe", false, "Enable all safe (but maybe not fast) uses of invokedynamic."); public static final Option<Boolean> INVOKEDYNAMIC_INVOCATION = bool( INVOKEDYNAMIC, "invokedynamic.invocation", true, "Enable invokedynamic for method invocations."); public static final Option<Boolean> INVOKEDYNAMIC_INVOCATION_INDIRECT = bool( INVOKEDYNAMIC, "invokedynamic.invocation.indirect", true, "Also bind indirect method invokers to invokedynamic."); public static final Option<Boolean> INVOKEDYNAMIC_INVOCATION_JAVA = bool( INVOKEDYNAMIC, "invokedynamic.invocation.java", true, "Bind Ruby to Java invocations with invokedynamic."); public static final Option<Boolean> INVOKEDYNAMIC_INVOCATION_ATTR = bool( INVOKEDYNAMIC, "invokedynamic.invocation.attr", true, "Bind Ruby attribute invocations directly to invokedynamic."); public static final Option<Boolean> INVOKEDYNAMIC_INVOCATION_FFI = bool( INVOKEDYNAMIC, "invokedynamic.invocation.ffi", true, "Bind Ruby FFI invocations directly to invokedynamic."); public static final Option<Boolean> INVOKEDYNAMIC_INVOCATION_FASTOPS = bool( INVOKEDYNAMIC, "invokedynamic.invocation.fastops", true, "Bind Fixnum and Float math using optimized logic."); public static final Option<Boolean> INVOKEDYNAMIC_CACHE = bool( INVOKEDYNAMIC, "invokedynamic.cache", true, "Use invokedynamic to load cached values like literals and constants."); public static final Option<Boolean> INVOKEDYNAMIC_CACHE_CONSTANTS = bool( INVOKEDYNAMIC, "invokedynamic.cache.constants", true, "Use invokedynamic to load constants."); public static final Option<Boolean> INVOKEDYNAMIC_CACHE_LITERALS = bool( INVOKEDYNAMIC, "invokedynamic.cache.literals", true, "Use invokedynamic to load literals."); public static final Option<Boolean> INVOKEDYNAMIC_CACHE_IVARS = bool( INVOKEDYNAMIC, "invokedynamic.cache.ivars", true, "Use invokedynamic to get/set instance variables."); public static final Option<Boolean> INVOKEDYNAMIC_CLASS_VALUES = bool( INVOKEDYNAMIC, "invokedynamic.class.values", false, "Use ClassValue to store class-specific data."); public static final Option<Integer> INVOKEDYNAMIC_GLOBAL_MAXFAIL = integer( INVOKEDYNAMIC, "invokedynamic.global.maxfail", 100, "Maximum global cache failures after which to use slow path."); public static final Option<Boolean> INVOKEDYNAMIC_HANDLES = bool( INVOKEDYNAMIC, "invokedynamic.handles", false, "Use MethodHandles rather than generated code to bind Ruby methods."); public static final Option<Integer> JIT_THRESHOLD = integer( JIT, "jit.threshold", Constants.JIT_THRESHOLD, "Set the JIT threshold to the specified method invocation count."); public static final Option<Integer> JIT_MAX = integer( JIT, "jit.max", Constants.JIT_MAX_METHODS_LIMIT, "Set the max count of active methods eligible for JIT-compilation."); public static final Option<Integer> JIT_MAXSIZE = integer( JIT, "jit.maxsize", Constants.JIT_MAX_SIZE_LIMIT, "Set the maximum full-class byte size allowed for jitted methods."); public static final Option<Boolean> JIT_LOGGING = bool(JIT, "jit.logging", false, "Enable JIT logging (reports successful compilation)."); public static final Option<Boolean> JIT_LOGGING_VERBOSE = bool( JIT, "jit.logging.verbose", false, "Enable verbose JIT logging (reports failed compilation)."); public static final Option<Boolean> JIT_DUMPING = bool(JIT, "jit.dumping", false, "Enable stdout dumping of JITed bytecode."); public static final Option<Integer> JIT_LOGEVERY = integer(JIT, "jit.logEvery", 0, "Log a message every n methods JIT compiled."); public static final Option<String> JIT_EXCLUDE = string( JIT, "jit.exclude", new String[] {"ClsOrMod", "ClsOrMod::method_name", "-::method_name"}, "", "Exclude methods from JIT. Comma delimited."); public static final Option<String> JIT_CODECACHE = string( JIT, "jit.codeCache", new String[] {"dir"}, "Save jitted methods to <dir> as they're compiled, for future runs."); public static final Option<Boolean> JIT_DEBUG = bool(JIT, "jit.debug", false, "Log loading of JITed bytecode."); public static final Option<Boolean> JIT_BACKGROUND = bool(JIT, "jit.background", true, "Run the JIT compiler in a background thread."); public static final Option<Boolean> IR_DEBUG = bool(IR, "ir.debug", false, "Debug generation of JRuby IR."); public static final Option<Boolean> IR_PROFILE = bool(IR, "ir.profile", false, "[EXPT]: Profile IR code during interpretation."); public static final Option<Boolean> IR_COMPILER_DEBUG = bool(IR, "ir.compiler.debug", false, "Debug compilation of JRuby IR."); public static final Option<Boolean> IR_VISUALIZER = bool(IR, "ir.visualizer", false, "Visualization of JRuby IR."); public static final Option<Boolean> IR_UNBOXING = bool(IR, "ir.unboxing", false, "Implement unboxing opts."); public static final Option<String> IR_COMPILER_PASSES = string(IR, "ir.passes", "Specify comma delimeted list of passes to run."); public static final Option<String> IR_JIT_PASSES = string(IR, "ir.jit.passes", "Specify comma delimeted list of passes to run before JIT."); public static final Option<Boolean> IR_READING = bool(IR, "ir.reading", false, "Read JRuby IR file."); public static final Option<Boolean> IR_READING_DEBUG = bool(IR, "ir.reading.debug", false, "Debug reading JRuby IR file."); public static final Option<Boolean> IR_WRITING = bool(IR, "ir.writing", false, "Write JRuby IR file."); public static final Option<Boolean> IR_WRITING_DEBUG = bool(IR, "ir.writing.debug", false, "Debug writing JRuby IR file."); public static final Option<String> IR_INLINE_COMPILER_PASSES = string( IR, "ir.inline_passes", "Specify comma delimeted list of passes to run after inlining a method."); public static final Option<Boolean> TRUFFLE_PRINT_RUNTIME = bool( TRUFFLE, "truffle.printRuntime", false, "Print the name of the Truffle runtime on startup."); public static final Option<Boolean> TRUFFLE_RUNTIME_VERSION_CHECK = bool( TRUFFLE, "truffle.runtime.version_check", true, "Check the version of Truffle supplied by the JVM before starting."); public static final Option<Integer> TRUFFLE_DISPATCH_POLYMORPHIC_MAX = integer( TRUFFLE, "truffle.dispatch.polymorphic.max", 8, "Maximum size of a polymorphic call site cache."); public static final Option<Integer> TRUFFLE_ARRAYS_UNINITIALIZED_SIZE = integer( TRUFFLE, "truffle.arrays.uninitialized_size", 32, "How large an array to allocate when we have no other information to go on."); public static final Option<Boolean> TRUFFLE_ARRAYS_OPTIMISTIC_LONG = bool( TRUFFLE, "truffle.arrays.optimistic.long", true, "If we allocate an int[] for an Array and it has been converted to a long[], directly allocate a long[] next time."); public static final Option<Integer> TRUFFLE_ARRAYS_SMALL = integer( TRUFFLE, "truffle.arrays.small", 3, "Maximum size of an Array to consider small for optimisations."); public static final Option<Integer> TRUFFLE_HASHES_SMALL = integer( TRUFFLE, "truffle.hashes.small", 3, "Maximum size of a Hash to consider small for optimisations."); public static final Option<Boolean> TRUFFLE_LOAD_CORE = bool(TRUFFLE, "truffle.load_core", true, "Load the Truffle core library."); public static final Option<Integer> TRUFFLE_PASSALOT = integer( TRUFFLE, "truffle.passalot", 0, "Probabilty between 0 and 100 to randomly insert Thread.pass at a given line."); public static final Option<Integer> TRUFFLE_INSTRUMENTATION_SERVER_PORT = integer( TRUFFLE, "truffle.instrumentation_server_port", 0, "Port number to run an HTTP server on that provides instrumentation services"); public static final Option<String> TRUFFLE_TRANSLATOR_PRINT_AST = string( TRUFFLE, "truffle.translator.print_asts", "", "Comma delimited list of method names to print the AST of after translation."); public static final Option<String> TRUFFLE_TRANSLATOR_PRINT_FULL_AST = string( TRUFFLE, "truffle.translator.print_full_asts", "", "Comma delimited list of method names to print the full AST of after translation."); public static final Option<String> TRUFFLE_TRANSLATOR_PRINT_PARSE_TREE = string( TRUFFLE, "truffle.translator.print_parse_trees", "", "Comma delimited list of method names to print the JRuby parse tree of before translation."); public static final Option<Boolean> TRUFFLE_PANIC_ON_JAVA_ASSERT = bool( TRUFFLE, "truffle.debug.panic_on_java_assert", false, "Panic as soon as a Java assertion failure is found."); public static final Option<Boolean> TRUFFLE_EXCEPTIONS_PRINT_JAVA = bool( TRUFFLE, "truffle.exceptions.print_java", false, "Print Java exceptions at the point of translating them to Ruby exceptions."); public static final Option<Boolean> TRUFFLE_ALLOW_SIMPLE_SOURCE_SECTIONS = bool(TRUFFLE, "truffle.allow_simple_source_sections", false, "Allow simple source sections."); public static final Option<Boolean> TRUFFLE_INLINER_ALWAYS_CLONE_YIELD = bool(TRUFFLE, "truffle.inliner.always_clone_yield", true, "Always clone yield call targets."); public static final Option<Boolean> TRUFFLE_INLINER_ALWAYS_INLINE_YIELD = bool( TRUFFLE, "truffle.inliner.always_inline_yield", true, "Always inline yield call targets."); public static final Option<Boolean> TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED = bool( TRUFFLE, "truffle.dispatch.metaprogramming_always_uncached", false, "Always use uncached dispatch for the metaprogramming methods #__send__, #send and #respond_to?, and for any call site that has to use #method_missing or #const_missing."); public static final Option<Boolean> TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT = bool( TRUFFLE, "truffle.dispatch.metaprogramming_always_indirect", false, "Always use indirect calls for the metaprogramming methods #__send__ and #send, and for any call site that has to use #method_missing or #const_missing."); public static final Option<Boolean> TRUFFLE_DISPATCH_METHODMISSING_ALWAYS_CLONED = bool( TRUFFLE, "truffle.call.method_missing_always_cloned", true, "Always clone #method_missing call targets."); public static final Option<Boolean> TRUFFLE_DISPATCH_METHODMISSING_ALWAYS_INLINED = bool( TRUFFLE, "truffle.call.method_missing_always_inlined", true, "Always inline #method_missing call targets."); public static final Option<Boolean> TRUFFLE_RANDOMIZE_STORAGE_ARRAY = bool(TRUFFLE, "truffle.randomize_storage.array", false, "Randomize Array storage strategy."); public static final Option<Integer> TRUFFLE_RANDOMIZE_SEED = integer(TRUFFLE, "truffle.randomize.seed", 0, "Seed for any randomization."); public static final Option<TruffleBridge.BacktraceFormatter> TRUFFLE_BACKTRACE_DISPLAY_FORMAT = enumeration( TRUFFLE, "truffle.backtrace.display_format", TruffleBridge.BacktraceFormatter.class, TruffleBridge.BacktraceFormatter.MRI, "How to format backtraces displayed to the user."); public static final Option<TruffleBridge.BacktraceFormatter> TRUFFLE_BACKTRACE_DEBUG_FORMAT = enumeration( TRUFFLE, "truffle.backtrace.debug_format", TruffleBridge.BacktraceFormatter.class, TruffleBridge.BacktraceFormatter.DEBUG, "How to format backtraces displayed using TruffleDebug.dump_call_stack."); public static final Option<TruffleBridge.BacktraceFormatter> TRUFFLE_BACKTRACE_EXCEPTION_FORMAT = enumeration( TRUFFLE, "truffle.backtrace.exception_format", TruffleBridge.BacktraceFormatter.class, TruffleBridge.BacktraceFormatter.MRI, "How to format backtraces in Exception objects."); public static final Option<TruffleBridge.BacktraceFormatter> TRUFFLE_BACKTRACE_PANIC_FORMAT = enumeration( TRUFFLE, "truffle.backtrace.panic_format", TruffleBridge.BacktraceFormatter.class, TruffleBridge.BacktraceFormatter.IMPL_DEBUG, "How to format backtraces in panics."); public static final Option<Integer> TRUFFLE_BACKTRACE_MAX_VALUE_LENGTH = integer( TRUFFLE, "truffle.backtrace.max_value_length", 20, "Max length for values when displayed in a backtrace."); public static final Option<Boolean> TRUFFLE_BACKTRACE_GENERATE = bool(TRUFFLE, "truffle.backtrace.generate", true, "Generate backtraces on exceptions."); public static final Option<Boolean> NATIVE_ENABLED = bool( NATIVE, "native.enabled", true, "Enable/disable native code, including POSIX features and C exts."); public static final Option<Boolean> NATIVE_VERBOSE = bool(NATIVE, "native.verbose", false, "Enable verbose logging of native extension loading."); public static final Option<Boolean> FFI_COMPILE_DUMP = bool(NATIVE, "ffi.compile.dump", false, "Dump bytecode-generated FFI stubs to console."); public static final Option<Integer> FFI_COMPILE_THRESHOLD = integer( NATIVE, "ffi.compile.threshold", 100, "Number of FFI invocations before generating a bytecode stub."); public static final Option<Boolean> FFI_COMPILE_INVOKEDYNAMIC = bool( NATIVE, "ffi.compile.invokedynamic", false, "Use invokedynamic to bind FFI invocations."); public static final Option<Boolean> FFI_COMPILE_REIFY = bool(NATIVE, "ffi.compile.reify", false, "Reify FFI compiled classes."); public static final Option<Integer> THREADPOOL_MIN = integer( THREADPOOL, "thread.pool.min", 0, "The minimum number of threads to keep alive in the pool."); public static final Option<Integer> THREADPOOL_MAX = integer( THREADPOOL, "thread.pool.max", Integer.MAX_VALUE, "The maximum number of threads to allow in the pool."); public static final Option<Integer> THREADPOOL_TTL = integer( THREADPOOL, "thread.pool.ttl", 60, "The maximum number of seconds to keep alive an idle thread."); public static final Option<Integer> FIBER_THREADPOOL_TTL = integer( THREADPOOL, "fiber.thread.pool.ttl", 60, "The maximum number of seconds to keep alive a pooled fiber thread."); public static final Option<Boolean> CLASSLOADER_DELEGATE = bool( MISCELLANEOUS, "classloader.delegate", true, "In some cases of classloader conflicts it might help not to delegate first to the parent classloader but to load first from the jruby-classloader."); public static final Option<Boolean> OBJECTSPACE_ENABLED = bool( MISCELLANEOUS, "objectspace.enabled", false, "Enable or disable ObjectSpace.each_object."); public static final Option<Boolean> SIPHASH_ENABLED = bool( MISCELLANEOUS, "siphash.enabled", false, "Enable or disable SipHash for String hash function."); public static final Option<Boolean> LAUNCH_INPROC = bool( MISCELLANEOUS, "launch.inproc", false, "Set in-process launching of e.g. system('ruby ...')."); public static final Option<String> BYTECODE_VERSION = string( MISCELLANEOUS, "bytecode.version", new String[] {"1.5", "1.6", "1.7"}, SafePropertyAccessor.getProperty("java.specification.version", "1.5"), "Specify the major Java bytecode version."); public static final Option<Boolean> MANAGEMENT_ENABLED = bool(MISCELLANEOUS, "management.enabled", false, "Set whether JMX management is enabled."); public static final Option<Boolean> JUMP_BACKTRACE = bool( MISCELLANEOUS, "jump.backtrace", false, "Make non-local flow jumps generate backtraces."); public static final Option<Boolean> PROCESS_NOUNWRAP = bool( MISCELLANEOUS, "process.noUnwrap", false, "Do not unwrap process streams (issue on some recent JVMs)."); public static final Option<Boolean> REIFY_CLASSES = bool( MISCELLANEOUS, "reify.classes", false, "Before instantiation, stand up a real Java class for every Ruby class."); public static final Option<Boolean> REIFY_LOGERRORS = bool( MISCELLANEOUS, "reify.logErrors", false, "Log errors during reification (reify.classes=true)."); public static final Option<Boolean> REFLECTED_HANDLES = bool( MISCELLANEOUS, "reflected.handles", false, "Use reflection for binding methods, not generated bytecode."); public static final Option<Boolean> BACKTRACE_COLOR = bool(MISCELLANEOUS, "backtrace.color", false, "Enable colorized backtraces."); public static final Option<String> BACKTRACE_STYLE = string( MISCELLANEOUS, "backtrace.style", new String[] {"normal", "raw", "full", "mri"}, "normal", "Set the style of exception backtraces."); public static final Option<Boolean> BACKTRACE_MASK = bool(MISCELLANEOUS, "backtrace.mask", false, "Mask .java lines in Ruby backtraces."); public static final Option<String> THREAD_DUMP_SIGNAL = string( MISCELLANEOUS, "thread.dump.signal", new String[] {"USR1", "USR2", "etc"}, "USR2", "Set the signal used for dumping thread stacks."); public static final Option<Boolean> NATIVE_NET_PROTOCOL = bool( MISCELLANEOUS, "native.net.protocol", false, "Use native impls for parts of net/protocol."); public static final Option<Boolean> FIBER_COROUTINES = bool(MISCELLANEOUS, "fiber.coroutines", false, "Use JVM coroutines for Fiber."); public static final Option<Boolean> GLOBAL_REQUIRE_LOCK = bool(MISCELLANEOUS, "global.require.lock", false, "Use a single global lock for requires."); public static final Option<Boolean> NATIVE_EXEC = bool( MISCELLANEOUS, "native.exec", true, "Do a true process-obliterating native exec for Kernel#exec."); public static final Option<Boolean> ENUMERATOR_LIGHTWEIGHT = bool( MISCELLANEOUS, "enumerator.lightweight", true, "Use lightweight Enumerator#next logic when possible."); public static final Option<Boolean> CONSISTENT_HASHING = bool( MISCELLANEOUS, "consistent.hashing", false, "Generate consistent object hashes across JVMs"); public static final Option<Boolean> REIFY_VARIABLES = bool( MISCELLANEOUS, "reify.variables", false, "Attempt to expand instance vars into Java fields"); public static final Option<Boolean> PREFER_IPV4 = bool(MISCELLANEOUS, "net.preferIPv4", true, "Prefer IPv4 network stack"); public static final Option<Boolean> FCNTL_LOCKING = bool(MISCELLANEOUS, "file.flock.fcntl", true, "Use fcntl rather than flock for File#flock"); public static final Option<Boolean> DEBUG_LOADSERVICE = bool(DEBUG, "debug.loadService", false, "Log require/load file searches."); public static final Option<Boolean> DEBUG_LOADSERVICE_TIMING = bool(DEBUG, "debug.loadService.timing", false, "Log require/load parse+evaluate times."); public static final Option<Boolean> DEBUG_LAUNCH = bool(DEBUG, "debug.launch", false, "Log externally-launched processes."); public static final Option<Boolean> DEBUG_FULLTRACE = bool( DEBUG, "debug.fullTrace", false, "Set whether full traces are enabled (c-call/c-return)."); public static final Option<Boolean> DEBUG_SCRIPTRESOLUTION = bool(DEBUG, "debug.scriptResolution", false, "Print which script is executed by '-S' flag."); public static final Option<Boolean> DEBUG_PARSER = bool( DEBUG, "debug.parser", false, "disables JRuby impl script loads and prints parse exceptions"); public static final Option<Boolean> ERRNO_BACKTRACE = bool( DEBUG, "errno.backtrace", false, "Generate backtraces for heavily-used Errno exceptions (EAGAIN)."); public static final Option<Boolean> STOPITERATION_BACKTRACE = bool( DEBUG, "stop_iteration.backtrace", false, "Generate backtraces for heavily-used Errno exceptions (EAGAIN)."); public static final Option<Boolean> LOG_EXCEPTIONS = bool(DEBUG, "log.exceptions", false, "Log every time an exception is constructed."); public static final Option<Boolean> LOG_BACKTRACES = bool(DEBUG, "log.backtraces", false, "Log every time an exception backtrace is generated."); public static final Option<Boolean> LOG_CALLERS = bool(DEBUG, "log.callers", false, "Log every time a Kernel#caller backtrace is generated."); public static final Option<Boolean> LOG_WARNINGS = bool( DEBUG, "log.warnings", false, "Log every time a built-in warning backtrace is generated."); public static final Option<String> LOGGER_CLASS = string( DEBUG, "logger.class", new String[] {"class name"}, "org.jruby.util.log.StandardErrorLogger", "Use specified class for logging."); public static final Option<Boolean> DUMP_INSTANCE_VARS = bool( DEBUG, "dump.variables", false, "Dump class + instance var names on first new of Object subclasses."); public static final Option<Boolean> REWRITE_JAVA_TRACE = bool( DEBUG, "rewrite.java.trace", true, "Rewrite stack traces from exceptions raised in Java calls."); public static final Option<Boolean> JI_SETACCESSIBLE = bool( JAVA_INTEGRATION, "ji.setAccessible", true, "Try to set inaccessible Java methods to be accessible."); public static final Option<Boolean> JI_LOGCANSETACCESSIBLE = bool( JAVA_INTEGRATION, "ji.logCanSetAccessible", false, "Log whether setAccessible is working."); public static final Option<Boolean> JI_UPPER_CASE_PACKAGE_NAME_ALLOWED = bool( JAVA_INTEGRATION, "ji.upper.case.package.name.allowed", false, "Allow Capitalized Java pacakge names."); public static final Option<Boolean> INTERFACES_USEPROXY = bool( JAVA_INTEGRATION, "interfaces.useProxy", false, "Use java.lang.reflect.Proxy for interface impl."); public static final Option<Boolean> JAVA_HANDLES = bool( JAVA_INTEGRATION, "java.handles", false, "Use generated handles instead of reflection for calling Java."); public static final Option<Boolean> JI_NEWSTYLEEXTENSION = bool( JAVA_INTEGRATION, "ji.newStyleExtension", false, "Extend Java classes without using a proxy object."); public static final Option<Boolean> JI_OBJECTPROXYCACHE = bool( JAVA_INTEGRATION, "ji.objectProxyCache", false, "Cache Java object wrappers between calls."); public static final Option<String> JI_PROXYCLASSFACTORY = string( JAVA_INTEGRATION, "ji.proxyClassFactory", "Allow external envs to replace JI proxy class factory"); public static final Option<Boolean> AOT_LOADCLASSES = bool( JAVA_INTEGRATION, "aot.loadClasses", false, "Look for .class before .rb to load AOT-compiled code"); public static final Option<Integer> PROFILE_MAX_METHODS = integer( PROFILING, "profile.max.methods", 100000, "Maximum number of methods to consider for profiling."); public static final Option<Boolean> CLI_AUTOSPLIT = bool(CLI, "cli.autosplit", false, "Split $_ into $F for -p or -n. Same as -a."); public static final Option<Boolean> CLI_DEBUG = bool(CLI, "cli.debug", false, "Enable debug mode logging. Same as -d."); public static final Option<Boolean> CLI_PROCESS_LINE_ENDS = bool(CLI, "cli.process.line.ends", false, "Enable line ending processing. Same as -l."); public static final Option<Boolean> CLI_ASSUME_LOOP = bool(CLI, "cli.assume.loop", false, "Wrap execution with a gets() loop. Same as -n."); public static final Option<Boolean> CLI_ASSUME_PRINT = bool(CLI, "cli.assume.print", false, "Print $_ after each execution of script. Same as -p."); public static final Option<Boolean> CLI_VERBOSE = bool( CLI, "cli.verbose", false, "Verbose mode, as -w or -W2. Sets default for cli.warning.level."); public static final Option<Verbosity> CLI_WARNING_LEVEL = enumeration( CLI, "cli.warning.level", Verbosity.class, CLI_VERBOSE.load() ? Verbosity.TRUE : Verbosity.FALSE, "Warning level (off=0,normal=1,on=2). Same as -W."); public static final Option<Boolean> CLI_PARSER_DEBUG = bool(CLI, "cli.parser.debug", false, "Enable parser debug logging. Same as -y."); public static final Option<Boolean> CLI_VERSION = bool(CLI, "cli.version", false, "Print version to stderr. Same as --version."); public static final Option<Boolean> CLI_BYTECODE = bool( CLI, "cli.bytecode", false, "Print target script bytecode to stderr. Same as --bytecode."); public static final Option<Boolean> CLI_COPYRIGHT = bool( CLI, "cli.copyright", false, "Print copyright to stderr. Same as --copyright but runs script."); public static final Option<Boolean> CLI_CHECK_SYNTAX = bool( CLI, "cli.check.syntax", false, "Check syntax of target script. Same as -c but runs script."); public static final Option<String> CLI_AUTOSPLIT_SEPARATOR = string(CLI, "cli.autosplit.separator", "Set autosplit separator. Same as -F."); public static final Option<KCode> CLI_KCODE = enumeration( CLI, "cli.kcode", KCode.class, KCode.NONE, "Set kcode character set. Same as -K (1.8)."); public static final Option<Boolean> CLI_HELP = bool(CLI, "cli.help", false, "Print command-line usage. Same as --help but runs script."); public static final Option<Boolean> CLI_PROPERTIES = bool( CLI, "cli.properties", false, "Print config properties. Same as --properties but runs script."); public static final Option<String> CLI_ENCODING_INTERNAL = string(CLI, "cli.encoding.internal", "Encoding name to use internally."); public static final Option<String> CLI_ENCODING_EXTERNAL = string(CLI, "cli.encoding.external", "Encoding name to treat external data."); public static final Option<String> CLI_ENCODING_SOURCE = string(CLI, "cli.encoding.source", "Encoding name to treat source code."); public static final Option<String> CLI_RECORD_SEPARATOR = string(CLI, "cli.record.separator", "\n", "Default record separator."); public static final Option<String> CLI_BACKUP_EXTENSION = string(CLI, "cli.backup.extension", "Backup extension for in-place ARGV files. Same as -i."); public static final Option<ProfilingMode> CLI_PROFILING_MODE = enumeration( CLI, "cli.profiling.mode", ProfilingMode.class, ProfilingMode.OFF, "Enable instrumented profiling modes."); public static final Option<Boolean> CLI_RUBYGEMS_ENABLE = bool(CLI, "cli.rubygems.enable", true, "Enable/disable RubyGems."); public static final Option<Boolean> CLI_RUBYOPT_ENABLE = bool(CLI, "cli.rubyopt.enable", true, "Enable/disable RUBYOPT processing at start."); public static final Option<Boolean> CLI_STRIP_HEADER = bool(CLI, "cli.strip.header", false, "Strip text before shebang in script. Same as -x."); public static final Option<Boolean> CLI_LOAD_GEMFILE = bool( CLI, "cli.load.gemfile", false, "Load a bundler Gemfile in cwd before running. Same as -G."); public static String dump() { return "# JRuby configuration options with current values\n" + Option.formatValues(_loadedOptions); } public static final Collection<Option> PROPERTIES = Collections.unmodifiableCollection(_loadedOptions); // After PROPERTIES so it doesn't show up in --properties @Deprecated public static final Option<Boolean> JIT_CACHE = bool( JIT, "jit.cache", !COMPILE_INVOKEDYNAMIC.load(), "(DEPRECATED) Cache jitted method in-memory bodies across runtimes and loads."); private static Option<String> string( Category category, String name, String[] options, String defval, String description) { Option<String> option = Option.string("jruby", name, category, options, defval, description); _loadedOptions.add(option); return option; } private static Option<String> string( Category category, String name, String defval, String description) { Option<String> option = Option.string("jruby", name, category, defval, description); _loadedOptions.add(option); return option; } private static Option<String> string( Category category, String name, String[] options, String description) { Option<String> option = Option.string("jruby", name, category, options, description); _loadedOptions.add(option); return option; } private static Option<String> string(Category category, String name, String description) { Option<String> option = Option.string("jruby", name, category, description); _loadedOptions.add(option); return option; } private static Option<Boolean> bool( Category category, String name, Boolean defval, String description) { Option<Boolean> option = Option.bool("jruby", name, category, defval, description); _loadedOptions.add(option); return option; } private static Option<Integer> integer( Category category, String name, Integer defval, String description) { Option<Integer> option = Option.integer("jruby", name, category, defval, description); _loadedOptions.add(option); return option; } private static <T extends Enum<T>> Option<T> enumeration( Category category, String name, Class<T> enumClass, T defval, String description) { Option<T> option = Option.enumeration("jruby", name, category, defval, description); _loadedOptions.add(option); return option; } private static boolean calculateInvokedynamicDefault() { // We were defaulting on for Java 8 and might again later if JEP 210 helps reduce warmup time. return false; } private static enum SearchMode { PREFIX, CONTAINS } public static void listPrefix(String prefix) { list(SearchMode.PREFIX, prefix); } public static void listContains(String substring) { list(SearchMode.CONTAINS, substring); } private static void list(SearchMode mode, String string) { for (Option option : PROPERTIES) { boolean include = false; switch (mode) { case PREFIX: include = option.shortName().startsWith(string); break; case CONTAINS: include = option.shortName().contains(string); break; } if (include) { System.out.printf("%s=%s\n", option.shortName(), option.load()); } } } public static Set<String> getPropertyNames() { final Set<String> propertyNames = new HashSet<String>(); for (Option option : PROPERTIES) { propertyNames.add(option.propertyName()); } return Collections.unmodifiableSet(propertyNames); } }
/** @author headius */ public class SkinnyMethodAdapter extends MethodVisitor implements Opcodes { private static final boolean DEBUG = SafePropertyAccessor.getBoolean("jruby.compile.dump"); private MethodVisitor method; private Printer printer; private String name; private ClassVisitor cv; public SkinnyMethodAdapter( ClassVisitor cv, int flags, String name, String signature, String something, String[] exceptions) { super(flags); setMethodVisitor(cv.visitMethod(flags, name, signature, something, exceptions)); this.cv = cv; this.name = name; } public MethodVisitor getMethodVisitor() { return method; } public void setMethodVisitor(MethodVisitor mv) { if (DEBUG) { this.printer = new Textifier(); this.method = new TraceMethodVisitor(mv, printer); } else { this.method = mv; } } /** * Short-hand for specifying a set of aloads * * @param args list of aloads you want */ public void aloadMany(int... args) { for (int arg : args) { aload(arg); } } public void aload(int arg0) { getMethodVisitor().visitVarInsn(ALOAD, arg0); } public void iload(int arg0) { getMethodVisitor().visitVarInsn(ILOAD, arg0); } public void lload(int arg0) { getMethodVisitor().visitVarInsn(LLOAD, arg0); } public void fload(int arg0) { getMethodVisitor().visitVarInsn(FLOAD, arg0); } public void dload(int arg0) { getMethodVisitor().visitVarInsn(DLOAD, arg0); } public void astore(int arg0) { getMethodVisitor().visitVarInsn(ASTORE, arg0); } public void istore(int arg0) { getMethodVisitor().visitVarInsn(ISTORE, arg0); } public void lstore(int arg0) { getMethodVisitor().visitVarInsn(LSTORE, arg0); } public void fstore(int arg0) { getMethodVisitor().visitVarInsn(FSTORE, arg0); } public void dstore(int arg0) { getMethodVisitor().visitVarInsn(DSTORE, arg0); } public void ldc(Object arg0) { getMethodVisitor().visitLdcInsn(arg0); } public void bipush(int arg) { getMethodVisitor().visitIntInsn(BIPUSH, arg); } public void sipush(int arg) { getMethodVisitor().visitIntInsn(SIPUSH, arg); } public void pushInt(int value) { if (value <= Byte.MAX_VALUE && value >= Byte.MIN_VALUE) { switch (value) { case -1: iconst_m1(); break; case 0: iconst_0(); break; case 1: iconst_1(); break; case 2: iconst_2(); break; case 3: iconst_3(); break; case 4: iconst_4(); break; case 5: iconst_5(); break; default: bipush(value); break; } } else if (value <= Short.MAX_VALUE && value >= Short.MIN_VALUE) { sipush(value); } else { ldc(value); } } public void pushBoolean(boolean bool) { if (bool) iconst_1(); else iconst_0(); } public void invokestatic(String arg1, String arg2, String arg3) { getMethodVisitor().visitMethodInsn(INVOKESTATIC, arg1, arg2, arg3); } public void invokespecial(String arg1, String arg2, String arg3) { getMethodVisitor().visitMethodInsn(INVOKESPECIAL, arg1, arg2, arg3); } public void invokevirtual(String arg1, String arg2, String arg3) { getMethodVisitor().visitMethodInsn(INVOKEVIRTUAL, arg1, arg2, arg3); } public void invokeinterface(String arg1, String arg2, String arg3) { getMethodVisitor().visitMethodInsn(INVOKEINTERFACE, arg1, arg2, arg3); } public void invokedynamic(String arg0, String arg1, Handle arg2, Object... arg3) { getMethodVisitor().visitInvokeDynamicInsn(arg0, arg1, arg2, arg3); } public void aprintln() { dup(); getstatic(p(System.class), "out", ci(PrintStream.class)); swap(); invokevirtual(p(PrintStream.class), "println", sig(void.class, params(Object.class))); } public void iprintln() { dup(); getstatic(p(System.class), "out", ci(PrintStream.class)); swap(); invokevirtual(p(PrintStream.class), "println", sig(void.class, params(int.class))); } public void areturn() { getMethodVisitor().visitInsn(ARETURN); } public void ireturn() { getMethodVisitor().visitInsn(IRETURN); } public void freturn() { getMethodVisitor().visitInsn(FRETURN); } public void lreturn() { getMethodVisitor().visitInsn(LRETURN); } public void dreturn() { getMethodVisitor().visitInsn(DRETURN); } public void newobj(String arg0) { getMethodVisitor().visitTypeInsn(NEW, arg0); } public void dup() { getMethodVisitor().visitInsn(DUP); } public void swap() { getMethodVisitor().visitInsn(SWAP); } public void swap2() { dup2_x2(); pop2(); } public void getstatic(String arg1, String arg2, String arg3) { getMethodVisitor().visitFieldInsn(GETSTATIC, arg1, arg2, arg3); } public void putstatic(String arg1, String arg2, String arg3) { getMethodVisitor().visitFieldInsn(PUTSTATIC, arg1, arg2, arg3); } public void getfield(String arg1, String arg2, String arg3) { getMethodVisitor().visitFieldInsn(GETFIELD, arg1, arg2, arg3); } public void putfield(String arg1, String arg2, String arg3) { getMethodVisitor().visitFieldInsn(PUTFIELD, arg1, arg2, arg3); } public void voidreturn() { getMethodVisitor().visitInsn(RETURN); } public void anewarray(String arg0) { getMethodVisitor().visitTypeInsn(ANEWARRAY, arg0); } public void multianewarray(String arg0, int dims) { getMethodVisitor().visitMultiANewArrayInsn(arg0, dims); } public void newarray(int arg0) { getMethodVisitor().visitIntInsn(NEWARRAY, arg0); } public void iconst_m1() { getMethodVisitor().visitInsn(ICONST_M1); } public void iconst_0() { getMethodVisitor().visitInsn(ICONST_0); } public void iconst_1() { getMethodVisitor().visitInsn(ICONST_1); } public void iconst_2() { getMethodVisitor().visitInsn(ICONST_2); } public void iconst_3() { getMethodVisitor().visitInsn(ICONST_3); } public void iconst_4() { getMethodVisitor().visitInsn(ICONST_4); } public void iconst_5() { getMethodVisitor().visitInsn(ICONST_5); } public void lconst_0() { getMethodVisitor().visitInsn(LCONST_0); } public void aconst_null() { getMethodVisitor().visitInsn(ACONST_NULL); } public void label(Label label) { getMethodVisitor().visitLabel(label); } public void nop() { getMethodVisitor().visitInsn(NOP); } public void pop() { getMethodVisitor().visitInsn(POP); } public void pop2() { getMethodVisitor().visitInsn(POP2); } public void arrayload() { getMethodVisitor().visitInsn(AALOAD); } public void arraystore() { getMethodVisitor().visitInsn(AASTORE); } public void iarrayload() { getMethodVisitor().visitInsn(IALOAD); } public void barrayload() { getMethodVisitor().visitInsn(BALOAD); } public void barraystore() { getMethodVisitor().visitInsn(BASTORE); } public void aaload() { getMethodVisitor().visitInsn(AALOAD); } public void aastore() { getMethodVisitor().visitInsn(AASTORE); } public void iaload() { getMethodVisitor().visitInsn(IALOAD); } public void iastore() { getMethodVisitor().visitInsn(IASTORE); } public void laload() { getMethodVisitor().visitInsn(LALOAD); } public void lastore() { getMethodVisitor().visitInsn(LASTORE); } public void baload() { getMethodVisitor().visitInsn(BALOAD); } public void bastore() { getMethodVisitor().visitInsn(BASTORE); } public void saload() { getMethodVisitor().visitInsn(SALOAD); } public void sastore() { getMethodVisitor().visitInsn(SASTORE); } public void caload() { getMethodVisitor().visitInsn(CALOAD); } public void castore() { getMethodVisitor().visitInsn(CASTORE); } public void faload() { getMethodVisitor().visitInsn(FALOAD); } public void fastore() { getMethodVisitor().visitInsn(FASTORE); } public void daload() { getMethodVisitor().visitInsn(DALOAD); } public void dastore() { getMethodVisitor().visitInsn(DASTORE); } public void fcmpl() { getMethodVisitor().visitInsn(FCMPL); } public void fcmpg() { getMethodVisitor().visitInsn(FCMPG); } public void dcmpl() { getMethodVisitor().visitInsn(DCMPL); } public void dcmpg() { getMethodVisitor().visitInsn(DCMPG); } public void dup_x2() { getMethodVisitor().visitInsn(DUP_X2); } public void dup_x1() { getMethodVisitor().visitInsn(DUP_X1); } public void dup2_x2() { getMethodVisitor().visitInsn(DUP2_X2); } public void dup2_x1() { getMethodVisitor().visitInsn(DUP2_X1); } public void dup2() { getMethodVisitor().visitInsn(DUP2); } public void trycatch(Label arg0, Label arg1, Label arg2, String arg3) { getMethodVisitor().visitTryCatchBlock(arg0, arg1, arg2, arg3); } public void trycatch(String type, Runnable body, Runnable catchBody) { Label before = new Label(); Label after = new Label(); Label catchStart = new Label(); Label done = new Label(); trycatch(before, after, catchStart, type); label(before); body.run(); label(after); go_to(done); if (catchBody != null) { label(catchStart); catchBody.run(); } label(done); } public void go_to(Label arg0) { getMethodVisitor().visitJumpInsn(GOTO, arg0); } public void lookupswitch(Label arg0, int[] arg1, Label[] arg2) { getMethodVisitor().visitLookupSwitchInsn(arg0, arg1, arg2); } public void athrow() { getMethodVisitor().visitInsn(ATHROW); } public void instance_of(String arg0) { getMethodVisitor().visitTypeInsn(INSTANCEOF, arg0); } public void ifeq(Label arg0) { getMethodVisitor().visitJumpInsn(IFEQ, arg0); } public void iffalse(Label arg0) { ifeq(arg0); } public void ifne(Label arg0) { getMethodVisitor().visitJumpInsn(IFNE, arg0); } public void iftrue(Label arg0) { ifne(arg0); } public void if_acmpne(Label arg0) { getMethodVisitor().visitJumpInsn(IF_ACMPNE, arg0); } public void if_acmpeq(Label arg0) { getMethodVisitor().visitJumpInsn(IF_ACMPEQ, arg0); } public void if_icmple(Label arg0) { getMethodVisitor().visitJumpInsn(IF_ICMPLE, arg0); } public void if_icmpgt(Label arg0) { getMethodVisitor().visitJumpInsn(IF_ICMPGT, arg0); } public void if_icmplt(Label arg0) { getMethodVisitor().visitJumpInsn(IF_ICMPLT, arg0); } public void if_icmpne(Label arg0) { getMethodVisitor().visitJumpInsn(IF_ICMPNE, arg0); } public void if_icmpeq(Label arg0) { getMethodVisitor().visitJumpInsn(IF_ICMPEQ, arg0); } public void checkcast(String arg0) { getMethodVisitor().visitTypeInsn(CHECKCAST, arg0); } public void start() { getMethodVisitor().visitCode(); } public void end() { if (DEBUG) { PrintWriter pw = new PrintWriter(System.out); String className = "(unknown class)"; if (cv instanceof ClassWriter) { className = new ClassReader(((ClassWriter) cv).toByteArray()).getClassName(); } if (name != null) { pw.write("*** Dumping " + className + "." + name + " ***\n"); } else { pw.write("*** Dumping ***\n"); } printer.print(pw); pw.flush(); } getMethodVisitor().visitMaxs(1, 1); getMethodVisitor().visitEnd(); } public void line(int line) { Label label = new Label(); label(label); visitLineNumber(line, label); } public void line(int line, Label label) { visitLineNumber(line, label); } public void ifnonnull(Label arg0) { getMethodVisitor().visitJumpInsn(IFNONNULL, arg0); } public void ifnull(Label arg0) { getMethodVisitor().visitJumpInsn(IFNULL, arg0); } public void iflt(Label arg0) { getMethodVisitor().visitJumpInsn(IFLT, arg0); } public void ifle(Label arg0) { getMethodVisitor().visitJumpInsn(IFLE, arg0); } public void ifgt(Label arg0) { getMethodVisitor().visitJumpInsn(IFGT, arg0); } public void ifge(Label arg0) { getMethodVisitor().visitJumpInsn(IFGE, arg0); } public void arraylength() { getMethodVisitor().visitInsn(ARRAYLENGTH); } public void ishr() { getMethodVisitor().visitInsn(ISHR); } public void ishl() { getMethodVisitor().visitInsn(ISHL); } public void iushr() { getMethodVisitor().visitInsn(IUSHR); } public void lshr() { getMethodVisitor().visitInsn(LSHR); } public void lshl() { getMethodVisitor().visitInsn(LSHL); } public void lushr() { getMethodVisitor().visitInsn(LUSHR); } public void lcmp() { getMethodVisitor().visitInsn(LCMP); } public void iand() { getMethodVisitor().visitInsn(IAND); } public void ior() { getMethodVisitor().visitInsn(IOR); } public void ixor() { getMethodVisitor().visitInsn(IXOR); } public void land() { getMethodVisitor().visitInsn(LAND); } public void lor() { getMethodVisitor().visitInsn(LOR); } public void lxor() { getMethodVisitor().visitInsn(LXOR); } public void iadd() { getMethodVisitor().visitInsn(IADD); } public void ladd() { getMethodVisitor().visitInsn(LADD); } public void fadd() { getMethodVisitor().visitInsn(FADD); } public void dadd() { getMethodVisitor().visitInsn(DADD); } public void isub() { getMethodVisitor().visitInsn(ISUB); } public void lsub() { getMethodVisitor().visitInsn(LSUB); } public void fsub() { getMethodVisitor().visitInsn(FSUB); } public void dsub() { getMethodVisitor().visitInsn(DSUB); } public void idiv() { getMethodVisitor().visitInsn(IDIV); } public void irem() { getMethodVisitor().visitInsn(IREM); } public void ineg() { getMethodVisitor().visitInsn(INEG); } public void i2d() { getMethodVisitor().visitInsn(I2D); } public void i2l() { getMethodVisitor().visitInsn(I2L); } public void i2f() { getMethodVisitor().visitInsn(I2F); } public void i2s() { getMethodVisitor().visitInsn(I2S); } public void i2c() { getMethodVisitor().visitInsn(I2C); } public void i2b() { getMethodVisitor().visitInsn(I2B); } public void ldiv() { getMethodVisitor().visitInsn(LDIV); } public void lrem() { getMethodVisitor().visitInsn(LREM); } public void lneg() { getMethodVisitor().visitInsn(LNEG); } public void l2d() { getMethodVisitor().visitInsn(L2D); } public void l2i() { getMethodVisitor().visitInsn(L2I); } public void l2f() { getMethodVisitor().visitInsn(L2F); } public void fdiv() { getMethodVisitor().visitInsn(FDIV); } public void frem() { getMethodVisitor().visitInsn(FREM); } public void fneg() { getMethodVisitor().visitInsn(FNEG); } public void f2d() { getMethodVisitor().visitInsn(F2D); } public void f2i() { getMethodVisitor().visitInsn(F2D); } public void f2l() { getMethodVisitor().visitInsn(F2L); } public void ddiv() { getMethodVisitor().visitInsn(DDIV); } public void drem() { getMethodVisitor().visitInsn(DREM); } public void dneg() { getMethodVisitor().visitInsn(DNEG); } public void d2f() { getMethodVisitor().visitInsn(D2F); } public void d2i() { getMethodVisitor().visitInsn(D2I); } public void d2l() { getMethodVisitor().visitInsn(D2L); } public void imul() { getMethodVisitor().visitInsn(IMUL); } public void lmul() { getMethodVisitor().visitInsn(LMUL); } public void fmul() { getMethodVisitor().visitInsn(FMUL); } public void dmul() { getMethodVisitor().visitInsn(DMUL); } public void iinc(int arg0, int arg1) { getMethodVisitor().visitIincInsn(arg0, arg1); } public void monitorenter() { getMethodVisitor().visitInsn(MONITORENTER); } public void monitorexit() { getMethodVisitor().visitInsn(MONITOREXIT); } public void jsr(Label branch) { getMethodVisitor().visitJumpInsn(JSR, branch); } public void ret(int arg0) { getMethodVisitor().visitVarInsn(RET, arg0); } public AnnotationVisitor visitAnnotationDefault() { return getMethodVisitor().visitAnnotationDefault(); } public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) { return getMethodVisitor().visitAnnotation(arg0, arg1); } public AnnotationVisitor visitParameterAnnotation(int arg0, String arg1, boolean arg2) { return getMethodVisitor().visitParameterAnnotation(arg0, arg1, arg2); } public void visitAnnotationWithFields(String name, boolean visible, Map<String, Object> fields) { AnnotationVisitor visitor = visitAnnotation(name, visible); visitAnnotationFields(visitor, fields); visitor.visitEnd(); } public void visitParameterAnnotationWithFields( int param, String name, boolean visible, Map<String, Object> fields) { AnnotationVisitor visitor = visitParameterAnnotation(param, name, visible); visitAnnotationFields(visitor, fields); visitor.visitEnd(); } @Override public void visitAttribute(Attribute arg0) { getMethodVisitor().visitAttribute(arg0); } @Override public void visitCode() { getMethodVisitor().visitCode(); } @Override public void visitInsn(int arg0) { getMethodVisitor().visitInsn(arg0); } @Override public void visitIntInsn(int arg0, int arg1) { getMethodVisitor().visitIntInsn(arg0, arg1); } @Override public void visitVarInsn(int arg0, int arg1) { getMethodVisitor().visitVarInsn(arg0, arg1); } @Override public void visitTypeInsn(int arg0, String arg1) { getMethodVisitor().visitTypeInsn(arg0, arg1); } @Override public void visitFieldInsn(int arg0, String arg1, String arg2, String arg3) { getMethodVisitor().visitFieldInsn(arg0, arg1, arg2, arg3); } @Override public void visitMethodInsn(int arg0, String arg1, String arg2, String arg3) { getMethodVisitor().visitMethodInsn(arg0, arg1, arg2, arg3); } @Override public void visitInvokeDynamicInsn(String arg0, String arg1, Handle arg2, Object... arg3) { getMethodVisitor().visitInvokeDynamicInsn(arg0, arg1, arg2, arg3); } @Override public void visitJumpInsn(int arg0, Label arg1) { getMethodVisitor().visitJumpInsn(arg0, arg1); } @Override public void visitLabel(Label arg0) { getMethodVisitor().visitLabel(arg0); } @Override public void visitLdcInsn(Object arg0) { getMethodVisitor().visitLdcInsn(arg0); } @Override public void visitIincInsn(int arg0, int arg1) { getMethodVisitor().visitIincInsn(arg0, arg1); } @Override public void visitTableSwitchInsn(int arg0, int arg1, Label arg2, Label[] arg3) { getMethodVisitor().visitTableSwitchInsn(arg0, arg1, arg2, arg3); } @Override public void visitLookupSwitchInsn(Label arg0, int[] arg1, Label[] arg2) { getMethodVisitor().visitLookupSwitchInsn(arg0, arg1, arg2); } @Override public void visitMultiANewArrayInsn(String arg0, int arg1) { getMethodVisitor().visitMultiANewArrayInsn(arg0, arg1); } @Override public void visitTryCatchBlock(Label arg0, Label arg1, Label arg2, String arg3) { getMethodVisitor().visitTryCatchBlock(arg0, arg1, arg2, arg3); } @Override public void visitLocalVariable( String arg0, String arg1, String arg2, Label arg3, Label arg4, int arg5) { getMethodVisitor().visitLocalVariable(arg0, arg1, arg2, arg3, arg4, arg5); } @Override public void visitLineNumber(int arg0, Label arg1) { getMethodVisitor().visitLineNumber(arg0, arg1); } @Override public void visitMaxs(int arg0, int arg1) { if (DEBUG) { PrintWriter pw = new PrintWriter(System.out); pw.write("*** Dumping ***\n"); printer.print(pw); pw.flush(); } getMethodVisitor().visitMaxs(arg0, arg1); } @Override public void visitEnd() { getMethodVisitor().visitEnd(); } public void tableswitch(int min, int max, Label defaultLabel, Label[] cases) { getMethodVisitor().visitTableSwitchInsn(min, max, defaultLabel, cases); } @Override public void visitFrame(int arg0, int arg1, Object[] arg2, int arg3, Object[] arg4) { getMethodVisitor().visitFrame(arg0, arg1, arg2, arg3, arg4); } }