Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into truffle-head
  • Loading branch information
chrisseaton committed Sep 17, 2014
2 parents eecbbdc + e1334fd commit 5a28cf7
Show file tree
Hide file tree
Showing 108 changed files with 691 additions and 18,742 deletions.
89 changes: 12 additions & 77 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -53,10 +53,7 @@
import org.jruby.ast.executable.Script;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.common.RubyWarnings;
import org.jruby.compiler.ASTCompiler;
import org.jruby.compiler.ASTInspector;
import org.jruby.compiler.JITCompiler;
import org.jruby.compiler.impl.StandardASMCompiler;
import org.jruby.embed.Extension;
import org.jruby.exceptions.JumpException;
import org.jruby.exceptions.MainExitException;
Expand Down Expand Up @@ -87,13 +84,10 @@
import org.jruby.javasupport.proxy.JavaProxyClassFactory;
import org.jruby.management.BeanManager;
import org.jruby.management.BeanManagerFactory;
import org.jruby.management.ClassCache;
import org.jruby.management.Config;
import org.jruby.management.ParserStats;
import org.jruby.parser.IRStaticScopeFactory;
import org.jruby.parser.Parser;
import org.jruby.parser.ParserConfiguration;
import org.jruby.parser.StaticScope;
import org.jruby.parser.StaticScopeFactory;
import org.jruby.platform.Platform;
import org.jruby.runtime.Binding;
Expand Down Expand Up @@ -133,7 +127,6 @@
import org.jruby.util.IOInputStream;
import org.jruby.util.IOOutputStream;
import org.jruby.util.JRubyClassLoader;
import org.jruby.util.JavaNameMangler;
import org.jruby.util.KCode;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.cli.Options;
Expand Down Expand Up @@ -226,7 +219,7 @@ private Ruby(RubyInstanceConfig config) {

getJRubyClassLoader(); // force JRubyClassLoader to init if possible

this.staticScopeFactory = new IRStaticScopeFactory(this);
this.staticScopeFactory = new StaticScopeFactory(this);
this.beanManager = BeanManagerFactory.create(this, config.isManagementEnabled());
this.jitCompiler = new JITCompiler(this);
this.parserStats = new ParserStats(this);
Expand All @@ -249,7 +242,6 @@ private Ruby(RubyInstanceConfig config) {
}

this.configBean = new Config(this);
this.classCacheBean = new ClassCache(this);
this.runtimeBean = new org.jruby.management.Runtime(this);

registerMBeans();
Expand All @@ -272,13 +264,12 @@ public void registerMBeans() {
this.beanManager.register(jitCompiler);
this.beanManager.register(configBean);
this.beanManager.register(parserStats);
this.beanManager.register(classCacheBean);
this.beanManager.register(runtimeBean);
}

void reinitialize(boolean reinitCore) {
this.doNotReverseLookupEnabled = true;
this.staticScopeFactory = new IRStaticScopeFactory(this);
this.staticScopeFactory = new StaticScopeFactory(this);
this.in = config.getInput();
this.out = config.getOutput();
this.err = config.getError();
Expand Down Expand Up @@ -450,8 +441,9 @@ public IRubyObject evalScriptlet(String script, DynamicScope scope) {
ThreadContext context = getCurrentContext();
Node rootNode = parseEval(script, "<script>", scope, 0);

context.preEvalScriptlet(scope);

try {
context.preEvalScriptlet(scope);
return Interpreter.getInstance().execute(this, rootNode, context.getFrameSelf());
} catch (JumpException.ReturnJump rj) {
throw newLocalJumpError(RubyLocalJumpError.Reason.RETURN, (IRubyObject)rj.getValue(), "unexpected return");
Expand Down Expand Up @@ -726,7 +718,7 @@ public IRubyObject runNormally(Node scriptNode) {
// IR JIT does not handle all scripts yet, so let those that fail run in interpreter instead
// FIXME: restore error once JIT should handle everything
try {
script = tryCompile(scriptNode, null, new JRubyClassLoader(getJRubyClassLoader()), config.isShowBytecode());
script = tryCompile(scriptNode, new JRubyClassLoader(getJRubyClassLoader()));
} catch (Exception e) {
if (Options.JIT_LOGGING_VERBOSE.load()) {
e.printStackTrace();
Expand Down Expand Up @@ -757,22 +749,7 @@ public IRubyObject runNormally(Node scriptNode) {
* @return an instance of the successfully-compiled Script, or null.
*/
public Script tryCompile(Node node) {
return tryCompile(node, null, new JRubyClassLoader(getJRubyClassLoader()), false);
}

/**
* Try to compile the code associated with the given Node, returning an
* instance of the successfully-compiled Script or null if the script could
* not be compiled. This version accepts an ASTInspector instance assumed to
* have appropriate flags set for compile optimizations, such as to turn
* on heap-based local variables to share an existing scope.
*
* @param node The node to attempt to compiled
* @param inspector The ASTInspector to use for making optimization decisions
* @return an instance of the successfully-compiled Script, or null.
*/
public Script tryCompile(Node node, ASTInspector inspector) {
return tryCompile(node, null, new JRubyClassLoader(getJRubyClassLoader()), inspector, false);
return tryCompile(node, new JRubyClassLoader(getJRubyClassLoader()));
}

private void failForcedCompile(Node scriptNode) throws RaiseException {
Expand All @@ -788,47 +765,9 @@ private void handeCompileError(Node node, Throwable t) {
}
}

private Script tryCompile(Node node, String cachedClassName, JRubyClassLoader classLoader, boolean dump) {
private Script tryCompile(Node node, JRubyClassLoader classLoader) {
return Compiler.getInstance().execute(this, node, classLoader);
}

private Script tryCompile(Node node, String cachedClassName, JRubyClassLoader classLoader, ASTInspector inspector, boolean dump) {
Script script = null;
try {
String filename = node.getPosition().getFile();
String classname = JavaNameMangler.mangledFilenameForStartupClasspath(filename);

StandardASMCompiler asmCompiler = null;
if (RubyInstanceConfig.JIT_CODE_CACHE != null && cachedClassName != null) {
asmCompiler = new StandardASMCompiler(cachedClassName.replace('.', '/'), filename);
} else {
asmCompiler = new StandardASMCompiler(classname, filename);
}
ASTCompiler compiler = config.newCompiler();
if (dump) {
compiler.compileRoot(node, asmCompiler, inspector, false, false);
asmCompiler.dumpClass(System.out);
} else {
compiler.compileRoot(node, asmCompiler, inspector, true, false);
}

script = (Script)asmCompiler.loadClass(classLoader).newInstance();

// __file__ method expects its scope at 0, so prepare that here
// this is only needed for the "gets loop" which skips calling load
StaticScope rootScope = ((RootNode)node).getStaticScope();
if (rootScope.getModule() == null) rootScope.setModule(objectClass);
script.setRootScope(rootScope);

if (config.isJitLogging()) {
LOG.info("compiled: " + node.getPosition().getFile());
}
} catch (Throwable t) {
handeCompileError(node, t);
}

return script;
}

public IRubyObject runScript(Script script) {
return runScript(script, false);
Expand Down Expand Up @@ -915,6 +854,10 @@ public Parser getParser() {
public BeanManager getBeanManager() {
return beanManager;
}

public JITCompiler getJITCompiler() {
return jitCompiler;
}

public synchronized TruffleBridge getTruffleBridge() {
if (truffleBridge == null) {
Expand Down Expand Up @@ -2939,7 +2882,7 @@ public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
// script was not found in cache above, so proceed to compile
Node scriptNode = parseFile(readStream, filename, null);
if (script == null) {
script = tryCompile(scriptNode, className, new JRubyClassLoader(jrubyClassLoader), false);
script = tryCompile(scriptNode, new JRubyClassLoader(jrubyClassLoader));
}

if (script == null) {
Expand Down Expand Up @@ -3229,7 +3172,6 @@ public void tearDown(boolean systemExit) {
getBeanManager().unregisterCompiler();
getBeanManager().unregisterConfig();
getBeanManager().unregisterParserStats();
getBeanManager().unregisterClassCache();
getBeanManager().unregisterMethodCache();
getBeanManager().unregisterRuntime();

Expand Down Expand Up @@ -4330,10 +4272,6 @@ public GlobalVariable getRecordSeparatorVar() {
return recordSeparatorVar;
}

public Set<Script> getJittedMethods() {
return jittedMethods;
}

public ExecutorService getExecutor() {
return executor;
}
Expand Down Expand Up @@ -4733,8 +4671,6 @@ public FilenoUtil getFilenoUtil() {
private volatile boolean objectSpaceEnabled;
private boolean siphashEnabled;

private final Set<Script> jittedMethods = Collections.synchronizedSet(new WeakHashSet<Script>());

private long globalState = 1;

// Default objects
Expand Down Expand Up @@ -5011,7 +4947,6 @@ public void addToObjectSpace(boolean useObjectSpace, IRubyObject object) {
private final int runtimeNumber = RUNTIME_NUMBER.getAndIncrement();

private final Config configBean;
private final ClassCache classCacheBean;
private final org.jruby.management.Runtime runtimeBean;

private final FilenoUtil filenoUtil = new FilenoUtil();
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyClass.java
Expand Up @@ -81,7 +81,7 @@
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;
import org.jruby.runtime.opto.Invalidator;
import org.jruby.util.ClassCache.OneShotClassLoader;
import org.jruby.util.OneShotClassLoader;
import org.jruby.util.ClassDefiningClassLoader;
import org.jruby.util.CodegenUtils;
import org.jruby.util.JavaNameMangler;
Expand Down
39 changes: 7 additions & 32 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Expand Up @@ -29,15 +29,12 @@
package org.jruby;

import jnr.posix.util.Platform;
import org.jruby.ast.executable.Script;
import org.jruby.compiler.ASTCompiler;
import org.jruby.embed.util.SystemPropertyCatcher;
import org.jruby.exceptions.MainExitException;
import org.jruby.runtime.Constants;
import org.jruby.runtime.backtrace.TraceType;
import org.jruby.runtime.load.LoadService;
import org.jruby.runtime.profile.builtin.ProfileOutput;
import org.jruby.util.ClassCache;
import org.jruby.util.InputStreamMarkCursor;
import org.jruby.util.JRubyFile;
import org.jruby.util.KCode;
Expand Down Expand Up @@ -111,8 +108,6 @@ public RubyInstanceConfig() {
jitMaxSize = Options.JIT_MAXSIZE.load();
}

// default ClassCache using jitMax as a soft upper bound
classCache = new ClassCache<Script>(loader, jitMax);
threadDumpSignal = Options.THREAD_DUMP_SIGNAL.load();

try {
Expand Down Expand Up @@ -141,8 +136,6 @@ public RubyInstanceConfig(RubyInstanceConfig parentConfig) {
profilingService = parentConfig.profilingService;
profilingMode = parentConfig.profilingMode;

classCache = new ClassCache<Script>(loader, jitMax);

try {
environment = System.getenv();
} catch (SecurityException se) {
Expand Down Expand Up @@ -465,10 +458,6 @@ public String displayedFileName() {
return getScriptFileName();
}
}

public ASTCompiler newCompiler() {
return new ASTCompiler();
}

////////////////////////////////////////////////////////////////////////////
// Static utilities and global state management methods.
Expand Down Expand Up @@ -695,10 +684,6 @@ public ClassLoader getLoader() {
}

public void setLoader(ClassLoader loader) {
// Setting the loader needs to reset the class cache
if(this.loader != loader) {
this.classCache = new ClassCache<Script>(loader, this.classCache.getMax());
}
this.loader = loader;
}

Expand Down Expand Up @@ -1053,10 +1038,6 @@ public String getRecordSeparator() {
public int getSafeLevel() {
return 0;
}

public ClassCache getClassCache() {
return classCache;
}

/**
* @see Options#CLI_BACKUP_EXTENSION
Expand All @@ -1072,10 +1053,6 @@ public String getInPlaceBackupExtension() {
return inPlaceBackupExtension;
}

public void setClassCache(ClassCache classCache) {
this.classCache = classCache;
}

public Map getOptionGlobals() {
return optionGlobals;
}
Expand Down Expand Up @@ -1439,8 +1416,6 @@ public void setProfilingService( String service ) {
private ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
private ClassLoader loader = contextLoader == null ? RubyInstanceConfig.class.getClassLoader() : contextLoader;

private ClassCache<Script> classCache;

// from CommandlineParser
private List<String> loadPaths = new ArrayList<String>();
private Set<String> excludedMethods = new HashSet<String>();
Expand Down Expand Up @@ -1805,6 +1780,13 @@ private static int initGlobalJavaVersion() {
throw new RuntimeException("unsupported Java version: " + specVersion);
}
}
public void setTruffleHooks(TruffleHooksStub truffleHooks) {
this.truffleHooks = truffleHooks;
}

public TruffleHooksStub getTruffleHooks() {
return truffleHooks;
}

@Deprecated
public void setSafeLevel(int safeLevel) {
Expand Down Expand Up @@ -1974,11 +1956,4 @@ public boolean isCextEnabled() {
@Deprecated public static final boolean INVOKEDYNAMIC_LITERALS = invokedynamicCache&& Options.INVOKEDYNAMIC_CACHE_LITERALS.load();
@Deprecated public static final boolean INVOKEDYNAMIC_IVARS = invokedynamicCache&& Options.INVOKEDYNAMIC_CACHE_IVARS.load();

public void setTruffleHooks(TruffleHooksStub truffleHooks) {
this.truffleHooks = truffleHooks;
}

public TruffleHooksStub getTruffleHooks() {
return truffleHooks;
}
}
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubyKernel.java
Expand Up @@ -45,7 +45,6 @@
import org.jruby.anno.FrameField;
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.exceptions.MainExitException;
import org.jruby.exceptions.RaiseException;
Expand Down Expand Up @@ -960,10 +959,10 @@ public static IRubyObject eval(ThreadContext context, IRubyObject recv, IRubyObj
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE},
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, JUMPTARGET, CLASS, FILENAME, SCOPE})
public static IRubyObject eval19(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
return evalCommon(context, recv, args, block, evalBinding19);
return evalCommon(context, recv, args, evalBinding19);
}

private static IRubyObject evalCommon(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block, EvalBinding evalBinding) {
private static IRubyObject evalCommon(ThreadContext context, IRubyObject recv, IRubyObject[] args, EvalBinding evalBinding) {
// string to eval
RubyString src = args[0].convertToString();

Expand Down

0 comments on commit 5a28cf7

Please sign in to comment.