Skip to content

Commit

Permalink
Showing 79 changed files with 4,629 additions and 4,201 deletions.
4 changes: 2 additions & 2 deletions bin/ast
Original file line number Diff line number Diff line change
@@ -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
@@ -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
4 changes: 2 additions & 2 deletions core/pom.rb
Original file line number Diff line number Diff line change
@@ -45,15 +45,15 @@
jar 'com.github.jnr:jnr-enxio:0.10', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-x86asm:1.0.2', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-unixsocket:0.10', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-posix:3.0.23', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-posix:3.0.27', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-constants:0.9.0', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-ffi:2.0.7'
jar 'com.github.jnr:jffi:${jffi.version}'
jar 'com.github.jnr:jffi:${jffi.version}:native'

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'
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.0.23</version>
<version>3.0.27</version>
<exclusions>
<exclusion>
<artifactId>jnr-ffi</artifactId>
@@ -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>
33 changes: 17 additions & 16 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -2838,31 +2838,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;
}
@@ -2887,7 +2886,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();

@@ -2898,7 +2897,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);
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -1703,6 +1703,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);
}
17 changes: 16 additions & 1 deletion core/src/main/java/org/jruby/ext/thread/SizedQueue.java
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
* rights and limitations under the License.
*
* Copyright (C) 2006 MenTaLguY <mental@rydia.net>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
@@ -101,4 +101,19 @@ public synchronized IRubyObject initialize(ThreadContext context, IRubyObject ar

return this;
}

@JRubyMethod(name = {"push", "<<", "enq"}, required = 1, optional = 1)
@Override
public IRubyObject push(ThreadContext context, final IRubyObject[] args) {
checkShutdown();
numWaiting.incrementAndGet();
try {
context.getThread().executeTask(context, args, putTask);
return this;
} catch (InterruptedException ie) {
throw context.runtime.newThreadError("interrupted in " + getMetaClass().getName() + "#push");
} finally {
numWaiting.decrementAndGet();
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
@@ -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.
*/
@@ -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() {
@@ -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;
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
Original file line number Diff line number Diff line change
@@ -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;
@@ -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");

@@ -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
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
@@ -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;
@@ -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
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
@@ -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.

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;
@@ -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;
@@ -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;

@@ -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;

Original file line number Diff line number Diff line change
@@ -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_";
Loading

0 comments on commit a6d9e07

Please sign in to comment.