public JITCompiler(Ruby runtime) { this.runtime = runtime; this.config = runtime.getInstanceConfig(); this.executor = new ThreadPoolExecutor( 0, // don't start threads until needed 2, // two max 60, // stop then if no jitting for 60 seconds TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new DaemonThreadFactory("Ruby-" + runtime.getRuntimeNumber() + "-JIT", Thread.MIN_PRIORITY)); }
private void doSetContextClassLoader(Ruby runtime) { // set thread context JRuby classloader here, for the main thread try { Thread.currentThread().setContextClassLoader(runtime.getJRubyClassLoader()); } catch (SecurityException se) { // can't set TC classloader if (runtime.getInstanceConfig().isVerbose()) { config.getError().println("WARNING: Security restrictions disallowed setting context classloader for main thread."); } } }
public void prepareBacktrace(ThreadContext context) { // if it's null, build a backtrace if (backtraceData == null) { backtraceData = context.runtime.getInstanceConfig().getTraceType().getBacktrace(context); } }
public void prepareBacktrace(ThreadContext context) { // if it's null, build a backtrace if (backtraceData == null) { backtraceData = context.runtime.getInstanceConfig().getTraceType().getBacktrace(context); } }
RubyInstanceConfig getGlobalRuntimeConfig(AbstractLocalContextProvider provider) { // make sure we do not yet initialize the runtime here if ( isGlobalRuntimeReady() ) { return getGlobalRuntime(provider).getInstanceConfig(); } return provider.config; }
/** * Returns the environment as a hash of Ruby strings. * * @param runtime */ public static Map<RubyString, RubyString> environmentVariableMap(Ruby runtime) { @SuppressWarnings("unchecked") Map<String, String> env = runtime.getInstanceConfig().getEnvironment(); if ( env != null ) return asMapOfRubyStrings(runtime, env); if ( Ruby.isSecurityRestricted() ) return Collections.emptyMap(); return asMapOfRubyStrings(runtime, System.getenv()); }
@Deprecated // un-used public static void rewriteStackTrace(final Ruby runtime, final Throwable e) { final StackTraceElement[] javaTrace = e.getStackTrace(); BacktraceData backtraceData = runtime.getInstanceConfig().getTraceType().getIntegratedBacktrace(runtime.getCurrentContext(), javaTrace); e.setStackTrace(RaiseException.javaTraceFromRubyTrace(backtraceData.getBacktrace(runtime))); }
@Deprecated // un-used public static void rewriteStackTrace(final Ruby runtime, final Throwable e) { final StackTraceElement[] javaTrace = e.getStackTrace(); BacktraceData backtraceData = runtime.getInstanceConfig().getTraceType().getIntegratedBacktrace(runtime.getCurrentContext(), javaTrace); e.setStackTrace(RaiseException.javaTraceFromRubyTrace(backtraceData.getBacktrace(runtime))); }
@JRubyMethod(meta = true) // for RubyGems' JRuby defaults public static IRubyObject classpath_launcher(ThreadContext context, IRubyObject recv) { final Ruby runtime = context.runtime; String launcher = runtime.getInstanceConfig().getEnvironment().get("RUBY"); if ( launcher == null ) launcher = ClasspathLauncher.jrubyCommand(runtime); return runtime.newString(launcher); }
public BacktraceData getBacktraceData(ThreadContext context, StackTraceElement[] javaTrace) { return new BacktraceData( javaTrace, context.getBacktrace(), false, context.runtime.getInstanceConfig().getBacktraceMask(), false); } },
public static IRubyObject rewriteStackTraceAndThrow(ThreadContext context, Throwable t) { Ruby runtime = context.runtime; StackTraceElement[] javaTrace = t.getStackTrace(); BacktraceData backtraceData = runtime.getInstanceConfig().getTraceType().getIntegratedBacktrace(context, javaTrace); t.setStackTrace(RaiseException.javaTraceFromRubyTrace(backtraceData.getBacktrace(runtime))); throwException(t); return null; // not reached }
@JRubyMethod(name = "extra_gem_paths", meta = true) // used from RGs' JRuby defaults public static IRubyObject extra_gem_paths(ThreadContext context, IRubyObject recv) { final Ruby runtime = context.runtime; final List<String> extraGemPaths = runtime.getInstanceConfig().getExtraGemPaths(); IRubyObject[] extra_gem_paths = new IRubyObject[extraGemPaths.size()]; int i = 0; for (String gemPath : extraGemPaths) { extra_gem_paths[i++] = runtime.newString(gemPath); } return RubyArray.newArrayNoCopy(runtime, extra_gem_paths); }
public static IRubyObject rewriteStackTraceAndThrow(ThreadContext context, Throwable t) { Ruby runtime = context.runtime; StackTraceElement[] javaTrace = t.getStackTrace(); BacktraceData backtraceData = runtime.getInstanceConfig().getTraceType().getIntegratedBacktrace(context, javaTrace); t.setStackTrace(RaiseException.javaTraceFromRubyTrace(backtraceData.getBacktrace(runtime))); throwException(t); return null; // not reached }
@JRubyMethod(name = "did_you_mean_disabled?") public static IRubyObject did_you_mean_disabled_p(ThreadContext context, IRubyObject self) { return context.runtime.newBoolean(context.runtime.getInstanceConfig().isDisableDidYouMean()); } }
static RubyInstanceConfig getGlobalRuntimeConfigOrNew() { return Ruby.isGlobalRuntimeReady() ? Ruby.getGlobalRuntime().getInstanceConfig() : new RubyInstanceConfig(); }
public MixedModeIRMethod(IRScope method, Visibility visibility, RubyModule implementationClass) { super(method, visibility, implementationClass); // disable JIT if JIT is disabled if (!implementationClass.getRuntime().getInstanceConfig().getCompileMode().shouldJIT() || Options.JIT_THRESHOLD.load() < 0) { callCount = -1; } // This is so profiled callsite can access the sites original method (callsites has IRScope in it). method.compilable = this; }
/** * Render the current backtrace as a string to the given StringBuilder. This will honor the currently-configured * backtrace format and content. * * @param sb the StringBuilder to which to render the backtrace */ public void renderCurrentBacktrace(StringBuilder sb) { TraceType traceType = runtime.getInstanceConfig().getTraceType(); BacktraceData backtraceData = traceType.getBacktrace(this); traceType.getFormat().renderBacktrace(backtraceData.getBacktrace(runtime), sb, false); }
public static int matcherSearch(ThreadContext context, Matcher matcher, int start, int range, int option) { if (!context.runtime.getInstanceConfig().isInterruptibleRegexps()) return matcher.search(start, range, option); try { RubyThread thread = context.getThread(); SearchMatchTask task = new SearchMatchTask(thread, start, range, option, false); return thread.executeTask(context, matcher, task); } catch (InterruptedException e) { throw context.runtime.newInterruptedRegexpError("Regexp Interrupted"); } }
@JIT @Interp public static RubyString freezeLiteralString(RubyString string, ThreadContext context, String file, int line) { Ruby runtime = context.runtime; if (runtime.getInstanceConfig().isDebuggingFrozenStringLiteral()) { // stuff location info into the string and then freeze it RubyArray info = (RubyArray) runtime.newArray(runtime.newString(file).freeze(context), runtime.newFixnum(line)).freeze(context); string.setInstanceVariable(RubyString.DEBUG_INFO_FIELD, info); } string.setFrozen(true); return string; }
@JIT @Interp public static RubyString freezeLiteralString(RubyString string, ThreadContext context, String file, int line) { Ruby runtime = context.runtime; if (runtime.getInstanceConfig().isDebuggingFrozenStringLiteral()) { // stuff location info into the string and then freeze it RubyArray info = (RubyArray) runtime.newArray(runtime.newString(file).freeze(context), runtime.newFixnum(line)).freeze(context); string.setInstanceVariable(RubyString.DEBUG_INFO_FIELD, info); } string.setFrozen(true); return string; }