Skip to content

Commit

Permalink
Merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Jan 21, 2016
2 parents 4a79bca + e699ba3 commit 8d092c6
Show file tree
Hide file tree
Showing 76 changed files with 5,087 additions and 4,743 deletions.
4 changes: 2 additions & 2 deletions bin/ast
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def print_passes_on(scope, passes)
end

scope.lexical_scopes.each do |child_scope|
child_scope.prepare_for_initial_compilation
child_scope.prepare_for_compilation
print_passes_on(child_scope, passes)
end
end
Expand All @@ -195,7 +195,7 @@ def ir_setup(root)
builder = org.jruby.ir.IRBuilder

scope = builder.build_root(manager, root).scope
scope.prepare_for_initial_compilation
scope.prepare_for_compilation
passes = manager.get_compiler_passes(scope)
[scope, passes]
end
Expand Down
2 changes: 1 addition & 1 deletion core/pom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

jar 'org.jruby.joni:joni:2.1.9'
jar 'org.jruby.extras:bytelist:1.0.13'
jar 'org.jruby.jcodings:jcodings:1.0.16'
jar 'org.jruby.jcodings:jcodings:1.0.17-SNAPSHOT'
jar 'org.jruby:dirgra:0.3'

jar 'com.headius:invokebinder:1.7'
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>org.jruby.jcodings</groupId>
<artifactId>jcodings</artifactId>
<version>1.0.16</version>
<version>1.0.17-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
Expand Down
33 changes: 17 additions & 16 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -2857,31 +2857,30 @@ public PrintStream getOutputStream() {
return new PrintStream(new IOOutputStream(getGlobalVariables().get("$stdout")));
}

public RubyModule getClassFromPath(String path) {
RubyModule c = getObject();
public RubyModule getClassFromPath(final String path) {
if (path.length() == 0 || path.charAt(0) == '#') {
throw newTypeError("can't retrieve anonymous class " + path);
}

RubyModule c = getObject();
int pbeg = 0, p = 0;
for(int l=path.length(); p<l; ) {
while(p<l && path.charAt(p) != ':') {
p++;
}
String str = path.substring(pbeg, p);
for ( final int l = path.length(); p < l; ) {
while ( p < l && path.charAt(p) != ':' ) p++;

final String str = path.substring(pbeg, p);

if(p<l && path.charAt(p) == ':') {
if(p+1 < l && path.charAt(p+1) != ':') {
throw newTypeError("undefined class/module " + path.substring(pbeg,p));
if ( p < l && path.charAt(p) == ':' ) {
if ( ++p < l && path.charAt(p) != ':' ) {
throw newTypeError("undefined class/module " + str);
}
p += 2;
pbeg = p;
pbeg = ++p;
}

IRubyObject cc = c.getConstant(str);
if(!(cc instanceof RubyModule)) {
if ( ! ( cc instanceof RubyModule ) ) {
throw newTypeError(path + " does not refer to class/module");
}
c = (RubyModule)cc;
c = (RubyModule) cc;
}
return c;
}
Expand All @@ -2906,7 +2905,7 @@ public void printError(RubyException excp) {
}

public void loadFile(String scriptName, InputStream in, boolean wrap) {
IRubyObject self = wrap ? TopSelfFactory.createTopSelf(this, true) : getTopSelf();
IRubyObject self = wrap ? getTopSelf().rbClone() : getTopSelf();
ThreadContext context = getCurrentContext();
String file = context.getFile();

Expand All @@ -2917,7 +2916,9 @@ public void loadFile(String scriptName, InputStream in, boolean wrap) {

if (wrap) {
// toss an anonymous module into the search path
((RootNode) parseResult).getStaticScope().setModule(RubyModule.newModule(this));
RubyModule wrapper = RubyModule.newModule(this);
((RubyBasicObject)self).extend(new IRubyObject[] {wrapper});
((RootNode) parseResult).getStaticScope().setModule(wrapper);
}

runInterpreter(context, parseResult, self);
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,12 @@ else if (protocol.find()) {
}
if (postFix.contains("..")) {
postFix = "!" + canonicalizePath(postFix.substring(1));
if (Platform.IS_WINDOWS && postFix.startsWith("!")) {
postFix = postFix.replace("\\", "/");
if (startsWithDriveLetterOnWindows(postFix.substring(1))) {
postFix = "!" + postFix.substring(3);
}
}
}
return runtime.newString(preFix + realPath + postFix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jruby.ir.IRMethod;
import org.jruby.ir.IRScope;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.persistence.IRDumper;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.ArgumentDescriptor;
Expand All @@ -22,6 +23,8 @@
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;

import java.io.ByteArrayOutputStream;

/**
* Method for -X-C (interpreted only execution). See MixedModeIRMethod for inter/JIT method impl.
*/
Expand All @@ -44,6 +47,11 @@ public InterpretedIRMethod(IRScope method, Visibility visibility, RubyModule imp

// -1 jit.threshold is way of having interpreter not promote full builds.
if (Options.JIT_THRESHOLD.load() == -1) callCount = -1;

// If we are printing, do the build right at creation time so we can see it
if (Options.IR_PRINT.load()) {
ensureInstrsReady();
}
}

public IRScope getIRScope() {
Expand Down Expand Up @@ -96,6 +104,12 @@ public InterpreterContext ensureInstrsReady() {
interpreterContext = ((IRMethod) method).lazilyAcquireInterpreterContext();
}
interpreterContext = method.getInterpreterContext();

if (Options.IR_PRINT.load()) {
ByteArrayOutputStream baos = IRDumper.printIR(method, false, true);

LOG.info("Printing simple IR for " + method.getName(), "\n" + new String(baos.toByteArray()));
}
}

return interpreterContext;
Expand All @@ -106,7 +120,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
if (IRRuntimeHelpers.isDebug()) doDebug();

if (callCount >= 0) promoteToFullBuild(context);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass().getMethodLocation(), self, name, args, block);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, args, block);
}

private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass,
Expand Down Expand Up @@ -135,7 +149,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz

if (callCount >= 0) promoteToFullBuild(context);

return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass().getMethodLocation(), self, name, block);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, block);
}

private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass,
Expand Down Expand Up @@ -163,7 +177,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
if (IRRuntimeHelpers.isDebug()) doDebug();

if (callCount >= 0) promoteToFullBuild(context);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass().getMethodLocation(), self, name, arg0, block);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, arg0, block);
}

private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass,
Expand Down Expand Up @@ -191,7 +205,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
if (IRRuntimeHelpers.isDebug()) doDebug();

if (callCount >= 0) promoteToFullBuild(context);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass().getMethodLocation(), self, name, arg0, arg1, block);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, arg0, arg1, block);
}

private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass,
Expand Down Expand Up @@ -219,7 +233,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
if (IRRuntimeHelpers.isDebug()) doDebug();

if (callCount >= 0) promoteToFullBuild(context);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass().getMethodLocation(), self, name, arg0, arg1, arg2, block);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass(), self, name, arg0, arg1, arg2, block);
}

private IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.jruby.compiler.Compilable;
import org.jruby.ir.*;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.persistence.IRDumper;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.ArgumentDescriptor;
Expand All @@ -21,6 +22,8 @@
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;

import java.io.ByteArrayOutputStream;

public class MixedModeIRMethod extends DynamicMethod implements IRMethodArgs, PositionAware, Compilable<DynamicMethod> {
private static final Logger LOG = LoggerFactory.getLogger("InterpretedIRMethod");

Expand Down Expand Up @@ -97,7 +100,16 @@ public InterpreterContext ensureInstrsReady() {
if (method instanceof IRMethod) {
return ((IRMethod) method).lazilyAcquireInterpreterContext();
}
return method.getInterpreterContext();

InterpreterContext ic = method.getInterpreterContext();

if (Options.IR_PRINT.load()) {
ByteArrayOutputStream baos = IRDumper.printIR(method, false);

LOG.info("Printing simple IR for " + method.getName(), "\n" + new String(baos.toByteArray()));
}

return ic;
}

@Override
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/org/jruby/ir/IRMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import org.jruby.ast.DefNode;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.operands.LocalVariable;
import org.jruby.ir.persistence.IRDumper;
import org.jruby.ir.representations.BasicBlock;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.util.cli.Options;

import java.io.ByteArrayOutputStream;

public class IRMethod extends IRScope {
public final boolean isInstanceMethod;
Expand Down Expand Up @@ -45,7 +49,9 @@ public synchronized InterpreterContext lazilyAcquireInterpreterContext() {
public synchronized BasicBlock[] prepareForCompilation() {
if (!hasBeenBuilt()) lazilyAcquireInterpreterContext();

return super.prepareForCompilation();
BasicBlock[] bbs = super.prepareForCompilation();

return bbs;
}

@Override
Expand Down
10 changes: 0 additions & 10 deletions core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -584,19 +584,9 @@ public synchronized BasicBlock[] prepareForCompilation() {

BasicBlock[] bbs = fullInterpreterContext.linearizeBasicBlocks();

if (Options.IR_PRINT.load()) printIR();

return bbs;
}

public void printIR() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
IRDumper dumper = new IRDumper(ps, Options.IR_PRINT_COLOR.load());
dumper.visit(this, false);
LOG.info("Printing final IR for " + getName(), "\n" + new String(baos.toByteArray()));
}

// FIXME: For inlining, culmulative or extra passes run based on profiled execution we need to re-init data or even
// construct a new fullInterpreterContext. Primary obstacles is JITFlags and linearization of BBs.

Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jruby.ir.interpreter;

import java.io.ByteArrayOutputStream;
import java.util.List;
import org.jruby.EvalType;
import org.jruby.Ruby;
Expand All @@ -15,6 +16,7 @@
import org.jruby.ir.IRTranslator;
import org.jruby.ir.operands.IRException;
import org.jruby.ir.operands.WrappedIRClosure;
import org.jruby.ir.persistence.IRDumper;
import org.jruby.ir.runtime.IRBreakJump;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
Expand All @@ -26,6 +28,7 @@
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.scope.ManyVarsDynamicScope;
import org.jruby.util.cli.Options;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;

Expand Down Expand Up @@ -58,6 +61,13 @@ public static void runBeginBlocks(List<IRClosure> beBlocks, ThreadContext contex
@Override
protected IRubyObject execute(Ruby runtime, IRScriptBody irScope, IRubyObject self) {
BeginEndInterpreterContext ic = (BeginEndInterpreterContext) irScope.getInterpreterContext();

if (Options.IR_PRINT.load()) {
ByteArrayOutputStream baos = IRDumper.printIR(irScope, false);

LOG.info("Printing simple IR for " + irScope.getName(), "\n" + new String(baos.toByteArray()));
}

ThreadContext context = runtime.getCurrentContext();
String name = ROOT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;

/**
* Represents a temporary variable for an unboxed Float operand.
* Represents a temporary variable for an unboxed Fixnum operand.
*/
public class TemporaryFixnumVariable extends TemporaryLocalVariable {
public static final String PREFIX = "%i_";
Expand Down

0 comments on commit 8d092c6

Please sign in to comment.