Skip to content

Commit

Permalink
Showing 219 changed files with 4,859 additions and 1,625 deletions.
15 changes: 8 additions & 7 deletions COPYING
Original file line number Diff line number Diff line change
@@ -105,13 +105,14 @@ lib/ruby/1.9, and lib/ruby/site_ruby/1.8/rubygems*.
The "yecht" library is Copyright (c) 2009-2011 Ola Bini, and released
under the MIT license.

The Rubinius API implementation in core/src/main/ruby/jruby/truffle/core/rubinius/api
and core/src/main/java/org/jruby/truffle/runtime/rubinius is copyright (c) 2011,
Evan Phoenix, and released under the 3-clause BSD license.

The Rubinius core library implementation in core/src/main/ruby/jruby/truffle/core/rubinius/kernel
is copyright (c) 2007-2014, Evan Phoenix and contributors, and released under
the 3-clause BSD license.
The Rubinius API implementation in truffle/src/main/ruby/core/rubinius/api
is copyright (c) 2011, Evan Phoenix, and released under the 3-clause BSD license.

The Rubinius core library implementation
in truffle/src/main/ruby/core/rubinius/bootstrap
and truffle/src/main/ruby/core/rubinius/common is
copyright (c) 2007-2014, Evan Phoenix and contributors,
and released under the 3-clause BSD license.

The complete text of the Eclipse Public License is as follows:

12 changes: 6 additions & 6 deletions antlib/extra.xml
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.20-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
@@ -137,7 +137,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.19-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.20-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
@@ -153,7 +153,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.20-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
@@ -169,7 +169,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.20-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
@@ -461,7 +461,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.19-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.20-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
@@ -515,4 +515,4 @@ build jruby-complete.jar
<!--arg value='-v'/-->
</exec>
</target>
<target description='test using jruby-complete or jruby-core/jruby-stdlib jars' name='test-jruby-jars' depends='mvn,test-jruby-jars-jruby.1.9,test-jruby-complete-slow,test-jruby-jars-objectspace,test-jruby-jars-mri.1.9,test-jruby-complete-rubicon.1.9'/></project>
<target description='test using jruby-complete or jruby-core/jruby-stdlib jars' name='test-jruby-jars' depends='mvn,test-jruby-jars-jruby.1.9,test-jruby-complete-slow,test-jruby-jars-objectspace,test-jruby-jars-mri.1.9,test-jruby-complete-rubicon.1.9'/></project>
28 changes: 18 additions & 10 deletions core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
@@ -178,6 +178,9 @@ private static IRubyObject asRubyStringList(Ruby runtime, List<ByteList> dirs) {
}

private static String getCWD(Ruby runtime) {
if (runtime.getCurrentDirectory().startsWith("uri:")) {
return runtime.getCurrentDirectory();
}
try {
return new org.jruby.util.NormalizedFile(runtime.getCurrentDirectory()).getCanonicalPath();
} catch (Exception e) {
@@ -297,17 +300,22 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
RubyFile.get_path(context, args[0]) : getHomeDirectoryPath(context);
String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null);
checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
JRubyFile dir = getDir(runtime, adjustedPath, true);
String realPath;
String realPath = null;
String oldCwd = runtime.getCurrentDirectory();
if (adjustedPath.startsWith("uri:")){
realPath = adjustedPath;
}
else {
JRubyFile dir = getDir(runtime, adjustedPath, true);

// We get canonical path to try and flatten the path out.
// a dir '/subdir/..' should return as '/'
// cnutter: Do we want to flatten path out?
try {
realPath = dir.getCanonicalPath();
} catch (IOException e) {
realPath = dir.getAbsolutePath();
// We get canonical path to try and flatten the path out.
// a dir '/subdir/..' should return as '/'
// cnutter: Do we want to flatten path out?
try {
realPath = dir.getCanonicalPath();
} catch (IOException e) {
realPath = dir.getAbsolutePath();
}
}

IRubyObject result = null;
@@ -317,7 +325,7 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
try {
result = block.yield(context, path);
} finally {
getDir(runtime, oldCwd, true); // ENEBO: Needed in case exception is thrown???
getDir(runtime, oldCwd, true); // needed in case the block deleted the oldCwd
runtime.setCurrentDirectory(oldCwd);
}
} else {
12 changes: 9 additions & 3 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -5804,11 +5804,17 @@ public static ByteList encodeBytelist(CharSequence value, Encoding encoding) {
public Object toJava(Class target) {
if (target.isAssignableFrom(String.class)) {
return decodeString();
} else if (target.isAssignableFrom(ByteList.class)) {
}
if (target.isAssignableFrom(ByteList.class)) {
return value;
} else {
return super.toJava(target);
}
if (target == Character.class || target == Character.TYPE) {
if ( strLength() != 1 ) {
throw getRuntime().newArgumentError("could not coerce string of length " + strLength() + " (!= 1) into a char");
}
return decodeString().charAt(0);
}
return super.toJava(target);
}

/**
24 changes: 12 additions & 12 deletions core/src/main/java/org/jruby/RubyStruct.java
Original file line number Diff line number Diff line change
@@ -547,37 +547,37 @@ public IRubyObject call(IRubyObject obj, boolean recur) {
private IRubyObject inspectStruct(final ThreadContext context, boolean recur) {
Ruby runtime = context.runtime;
RubyArray member = __member__();
ByteList buffer = new ByteList("#<struct ".getBytes());
RubyString buffer = RubyString.newString(getRuntime(), new ByteList("#<struct ".getBytes()));
String cpath = getMetaClass().getRealClass().getName();
char first = cpath.charAt(0);

if (recur || first != '#') {
buffer.append(cpath.getBytes());
buffer.append(' ');
buffer.cat(cpath.getBytes());
buffer.cat(' ');
}

if (recur) {
buffer.append(":...>".getBytes());
return runtime.newString(buffer);
buffer.cat(":...>".getBytes());
return buffer.dup();
}

for (int i = 0,k=member.getLength(); i < k; i++) {
if (i > 0) {
buffer.append(',').append(' ');
buffer.cat(',').cat(' ');
}
RubySymbol slot = (RubySymbol)member.eltInternal(i);
String name = slot.toString();
if (IdUtil.isLocal(name) || IdUtil.isConstant(name)) {
buffer.append(RubyString.objAsString(context, slot).getByteList());
buffer.cat19(RubyString.objAsString(context, slot));
} else {
buffer.append(((RubyString) slot.inspect(context)).getByteList());
buffer.cat19(((RubyString) slot.inspect(context)));
}
buffer.append('=');
buffer.append(inspect(context, values[i]).getByteList());
buffer.cat('=');
buffer.cat19(inspect(context, values[i]));
}

buffer.append('>');
return getRuntime().newString(buffer); // OBJ_INFECT
buffer.cat('>');
return buffer.dup(); // OBJ_INFECT
}

@JRubyMethod(name = {"inspect", "to_s"})
17 changes: 13 additions & 4 deletions core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
Original file line number Diff line number Diff line change
@@ -877,7 +877,7 @@ private IRubyObject op_quo19_20(ThreadContext context, IRubyObject other) {
int len = value.precision() + preciseOther.value.precision();
int pow = len / 4;
int precision = (pow + 1) * 4 * 2;

return op_div(context, preciseOther, getRuntime().newFixnum(precision));
}

@@ -929,9 +929,18 @@ public IRubyObject op_div(ThreadContext context, IRubyObject other, IRubyObject
// MRI behavior: "If digits is 0, the result is the same as the / operator."
if (scale == 0) return op_quo(context, other);

MathContext mathContext = new MathContext(scale, getRoundingMode(context.runtime));
return new RubyBigDecimal(context.runtime,
value.divide(val.value, mathContext)).setResult(scale);
if (isZero()) {
return newZero(getRuntime(), zeroSign * val.value.signum());
}

if (scale == 0) {
// MRI behavior: "If digits is 0, the result is the same as the / operator."
return op_quo(context, other);
} else {
MathContext mathContext = new MathContext(scale, getRoundingMode(context.runtime));
return new RubyBigDecimal(getRuntime(),
value.divide(val.value, mathContext)).setResult(scale);
}
}

@JRubyMethod(name = "div")
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.jruby.internal.runtime.methods;

import java.util.ArrayList;
import java.util.List;
import org.jruby.RubyModule;
import org.jruby.ir.IRScope;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;

/**
* Created by enebo on 2/6/15.
*/
public class InterpretedIRBodyMethod extends InterpretedIRMethod {
public InterpretedIRBodyMethod(IRScope method, RubyModule implementationClass) {
super(method, Visibility.PUBLIC, implementationClass);

this.box.callCount = -1;
}

@Override
public List<String[]> getParameterList() {
return new ArrayList<String[]>();
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
return call(context, self, clazz, name, block);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
if (IRRuntimeHelpers.isDebug()) doDebug();

InterpreterContext ic = ensureInstrsReady();
return ic.engine.interpret(context, self, ic, getImplementationClass().getMethodLocation(), name, block, null);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
return call(context, self, clazz, name, block);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
return call(context, self, clazz, name, block);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
return call(context, self, clazz, name, block);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
return call(context, self, clazz, name, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
return call(context, self, clazz, name, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) {
return call(context, self, clazz, name, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) {
return call(context, self, clazz, name, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return call(context, self, clazz, name, Block.NULL_BLOCK);
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
package org.jruby.internal.runtime.methods;

import java.util.ArrayList;
import java.util.List;

import org.jruby.RubyModule;
import org.jruby.ir.*;
import org.jruby.ir.interpreter.Interpreter;
import org.jruby.ir.IRScope;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;

public class InterpretedIRMetaClassBody extends InterpretedIRMethod {
public class InterpretedIRMetaClassBody extends InterpretedIRBodyMethod {
public InterpretedIRMetaClassBody(IRScope metaClassBody, RubyModule implementationClass) {
super(metaClassBody, Visibility.PUBLIC, implementationClass);
}

public List<String[]> getParameterList() {
return new ArrayList<String[]>();
super(metaClassBody, implementationClass);
}

protected void post(InterpreterContext ic, ThreadContext context) {
@@ -44,23 +35,23 @@ protected void pre(InterpreterContext ic, ThreadContext context, IRubyObject sel
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
DynamicMethodBox box = this.box;
if (box.callCount >= 0) tryJit(context, box);
DynamicMethod actualMethod = box.actualMethod;
if (actualMethod != null) return actualMethod.call(context, self, clazz, name, args, block);
if (actualMethod != null) return actualMethod.call(context, self, clazz, name, block);

InterpreterContext ic = ensureInstrsReady();

if (IRRuntimeHelpers.isDebug()) doDebug();

if (ic.hasExplicitCallProtocol()) {
return Interpreter.INTERPRET_METHOD(context, this, self, name, args, block);
return ic.engine.interpret(context, self, ic, getImplementationClass().getMethodLocation(), name, block, null);
} else {
try {
pre(ic, context, self, name, block);

return Interpreter.INTERPRET_METHOD(context, this, self, name, args, block);
return ic.engine.interpret(context, self, ic, getImplementationClass().getMethodLocation(), name, block, null);
} finally {
post(ic, context);
}
Original file line number Diff line number Diff line change
@@ -9,13 +9,11 @@
import org.jruby.RubyModule;
import org.jruby.ir.*;
import org.jruby.ir.representations.CFG;
import org.jruby.ir.interpreter.Interpreter;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.PositionAware;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
@@ -32,10 +30,6 @@ public class InterpretedIRMethod extends DynamicMethod implements IRMethodArgs,

protected final IRScope method;

// For synthetic methods and for module/class bodies we do not want these added to
// our backtraces.
private boolean isSynthetic;

protected static class DynamicMethodBox {
public DynamicMethod actualMethod;
public int callCount = 0;
@@ -49,18 +43,11 @@ public InterpretedIRMethod(IRScope method, Visibility visibility, RubyModule imp
this.method.getStaticScope().determineModule();
this.arity = calculateArity();

// disable JIT for anything that's not an IRMethod, or if JIT is turned off
// FIXME: kinda hacky, but I use IRMethod data in JITCompiler, and module/class/script bodies generally only run once
if (!(method instanceof IRMethod) ||
!implementationClass.getRuntime().getInstanceConfig().getCompileMode().shouldJIT()) {
// disable JIT if JIT is disabled
// FIXME: kinda hacky, but I use IRMethod data in JITCompiler.
if (!implementationClass.getRuntime().getInstanceConfig().getCompileMode().shouldJIT()) {
this.box.callCount = -1;
}

isSynthetic = method instanceof IRModuleBody;
}

public boolean isSynthetic() {
return isSynthetic;
}

public IRScope getIRMethod() {
@@ -81,7 +68,7 @@ public StaticScope getStaticScope() {

public List<String[]> getParameterList() {
method.prepareForInterpretation(); // We might not have parsed the method yet.
return (method instanceof IRMethod) ? ((IRMethod)method).getArgDesc() : new ArrayList<String[]>();
return ((IRMethod) method).getArgDesc();
}

private Arity calculateArity() {
@@ -114,7 +101,18 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
if (jittedMethod != null) {
return jittedMethod.call(context, self, clazz, name, args, block);
} else {
return Interpreter.INTERPRET_METHOD(context, this, self, name, args, block);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass().getMethodLocation(), self, name, args, block);
}
}

private static IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass,
IRubyObject self, String name, IRubyObject[] args, Block block) {
try {
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

return ic.engine.interpret(context, self, ic, implClass, name, args, block, null);
} finally {
ThreadContext.popBacktrace(context);
}
}

@@ -129,7 +127,18 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
if (jittedMethod != null) {
return jittedMethod.call(context, self, clazz, name, block);
} else {
return Interpreter.INTERPRET_METHOD(context, this, self, name, IRubyObject.NULL_ARRAY, block);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass().getMethodLocation(), self, name, block);
}
}

private static IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass,
IRubyObject self, String name, Block block) {
try {
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

return ic.engine.interpret(context, self, ic, implClass, name, block, null);
} finally {
ThreadContext.popBacktrace(context);
}
}

@@ -144,7 +153,18 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
if (jittedMethod != null) {
return jittedMethod.call(context, self, clazz, name, arg0, block);
} else {
return Interpreter.INTERPRET_METHOD(context, this, self, name, Helpers.arrayOf(arg0), block);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass().getMethodLocation(), self, name, arg0, block);
}
}

private static IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass,
IRubyObject self, String name, IRubyObject arg1, Block block) {
try {
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

return ic.engine.interpret(context, self, ic, implClass, name, arg1, block, null);
} finally {
ThreadContext.popBacktrace(context);
}
}

@@ -159,7 +179,18 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
if (jittedMethod != null) {
return jittedMethod.call(context, self, clazz, name, arg0, arg1, block);
} else {
return Interpreter.INTERPRET_METHOD(context, this, self, name, Helpers.arrayOf(arg0, arg1), block);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass().getMethodLocation(), self, name, arg0, arg1, block);
}
}

private static IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass,
IRubyObject self, String name, IRubyObject arg1, IRubyObject arg2, Block block) {
try {
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

return ic.engine.interpret(context, self, ic, implClass, name, arg1, arg2, block, null);
} finally {
ThreadContext.popBacktrace(context);
}
}

@@ -174,8 +205,20 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
if (jittedMethod != null) {
return jittedMethod.call(context, self, clazz, name, arg0, arg1, arg2, block);
} else {
return Interpreter.INTERPRET_METHOD(context, this, self, name, Helpers.arrayOf(arg0, arg1, arg2), block);
return INTERPRET_METHOD(context, ensureInstrsReady(), getImplementationClass().getMethodLocation(), self, name, arg0, arg1, arg2, block);
}
}

private static IRubyObject INTERPRET_METHOD(ThreadContext context, InterpreterContext ic, RubyModule implClass,
IRubyObject self, String name, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, Block block) {
try {
ThreadContext.pushBacktrace(context, name, ic.getFileName(), context.getLine());

return ic.engine.interpret(context, self, ic, implClass, name, arg1, arg2, arg3, block, null);
} finally {
ThreadContext.popBacktrace(context);
}

}

protected void doDebug() {
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ir/IRFlags.java
Original file line number Diff line number Diff line change
@@ -55,4 +55,5 @@ public enum IRFlags {

DYNSCOPE_ELIMINATED, // local var load/stores have been converted to tmp var accesses
REUSE_PARENT_DYNSCOPE, // for closures -- reuse parent's dynscope
SIMPLE_METHOD, // probably temporary flag. Can this method scope fit into a simple method interpreter
}
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import org.jruby.ir.dataflow.DataFlowProblem;
import org.jruby.ir.instructions.*;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.interpreter.SimpleMethodInterpreterEngine;
import org.jruby.ir.operands.*;
import org.jruby.ir.operands.Float;
import org.jruby.ir.operands.Boolean;
@@ -462,6 +463,8 @@ public CFG getCFG() {
protected Instr[] prepareInstructions() {
setupLinearization();

boolean simple_method = this instanceof IRMethod;

SimpleCloneInfo cloneInfo = new SimpleCloneInfo(this, false);

// FIXME: If CFG (or linearizedBBList) knew number of instrs we could end up allocing better
@@ -482,6 +485,7 @@ protected Instr[] prepareInstructions() {
// FIXME: Can be replaced with System.arrayCopy or clone() once we stop cloning individual instrs
for (int i = 0; i < bbInstrsLength; i++) {
Instr instr = bbInstrs.get(i);
if (simple_method && SimpleMethodInterpreterEngine.OPERATIONS.get(instr.getOperation()) == null) simple_method = false;
if (!(instr instanceof ReceiveSelfInstr)) {
// FIXME: Can be removed once ipc and rpc are stored in table(s) in IC
Instr newInstr = instr.clone(cloneInfo);
@@ -493,6 +497,8 @@ protected Instr[] prepareInstructions() {
}
}

if (simple_method) flags.add(IRFlags.SIMPLE_METHOD);

cfg().getExitBB().getLabel().setTargetPC(ipc + 1); // Exit BB ipc

// System.out.println("SCOPE: " + getName());
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/ir/instructions/BreakInstr.java
Original file line number Diff line number Diff line change
@@ -55,6 +55,11 @@ public boolean computeScopeFlags(IRScope scope) {
return true;
}

@Override
public String[] toStringNonOperandArgs() {
return new String[] {"scope_name: " + scopeName};
}

@Override
public Instr clone(CloneInfo info) {
if (info instanceof SimpleCloneInfo) return new BreakInstr(getReturnValue().cloneForInlining(info), scopeName);
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ public void visit(IRVisitor visitor) {
}

@Override
public String toString() {
return result + " = " + (isArgsPush ? "ArgsPush[" : "ArgsCat:[") + getAppendingArg() + ", " + getAppendedArg() + "]";
public String[] toStringNonOperandArgs() {
return new String[] { "type: " + (isArgsPush ? "push" : "cat")};
}
}
Original file line number Diff line number Diff line change
@@ -40,8 +40,8 @@ public RubyRegexp getRegexp() {
}

@Override
public String toString() {
return getOperation() + "(" + java.util.Arrays.toString(getPieces()) + "," + options + ")";
public String[] toStringNonOperandArgs() {
return new String[] {"options: " + options};
}

@Override
@@ -62,7 +62,7 @@ private RubyString[] retrievePieces(ThreadContext context, IRubyObject self, Sta
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
// FIXME (from RegexpNode.java): 1.9 should care about internal or external encoding and not kcode.
// If we have a constant regexp string or if the regexp patterns asks for caching, cache the regexp
if ((rubyRegexp == null) || !options.isOnce() || context.runtime.getKCode() != rubyRegexp.getKCode()) {
if (rubyRegexp == null || !options.isOnce() || context.runtime.getKCode() != rubyRegexp.getKCode()) {
RubyString[] pieces = retrievePieces(context, self, currScope, currDynScope, temp);
RubyString pattern = RubyRegexp.preprocessDRegexp(context.runtime, pieces, options);
RubyRegexp re = RubyRegexp.newDRegexp(context.runtime, pattern, options);
Original file line number Diff line number Diff line change
@@ -38,8 +38,8 @@ public boolean isExclusive() {
}

@Override
public String toString() {
return result + " = " + getBegin() + (exclusive ? ".." : "...") + getEnd();
public String[] toStringNonOperandArgs() {
return new String[] { "type: " + (exclusive ? "exclusive" : "inclusive")};
}

@Override
8 changes: 3 additions & 5 deletions core/src/main/java/org/jruby/ir/instructions/CallBase.java
Original file line number Diff line number Diff line change
@@ -346,10 +346,8 @@ public boolean targetRequiresCallersFrame() {
}

@Override
public String toString() {
return "" + getOperation() + "(" + callType + ", " + getName() + ", " + getReceiver() +
", " + Arrays.toString(getCallArgs()) +
(getClosureArg() == null ? "" : ", &" + getClosureArg()) + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "n:" + getName(), "t:" + callType.toString().substring(0, 2), "cl:"+ hasClosure};
}

public static boolean containsArgSplat(Operand[] arguments) {
@@ -431,4 +429,4 @@ public Block prepareBlock(ThreadContext context, IRubyObject self, StaticScope c

return IRRuntimeHelpers.getBlockFromObject(context, getClosureArg().retrieve(context, self, currScope, currDynScope, temp));
}
}
}
5 changes: 0 additions & 5 deletions core/src/main/java/org/jruby/ir/instructions/CallInstr.java
Original file line number Diff line number Diff line change
@@ -77,11 +77,6 @@ public Instr clone(CloneInfo ii) {
cloneCallArgs(ii), getClosureArg() == null ? null : getClosureArg().cloneForInlining(ii));
}

@Override
public String toString() {
return "" + result + " = " + super.toString();
}

@Override
public void visit(IRVisitor visitor) {
visitor.CallInstr(this);
Original file line number Diff line number Diff line change
@@ -29,8 +29,8 @@ public Operand getArgsArray() {
}

@Override
public String toString() {
return getOperation() + "(" + getArgsArray() + ", " + required + ", " + opt + ", " + rest + ")";
public String[] toStringNonOperandArgs() {
return new String[] {"req: " + required, "opt: " + opt, "*r: " + rest};
}

@Override
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@ public CheckArityInstr(int required, int opt, int rest, boolean receivesKeywords
}

@Override
public String toString() {
return super.toString() + " req: " + required + ", opt: " + opt + ", *r: " + rest + ", kw: " + receivesKeywords + ", **r: " + restKey;
public String[] toStringNonOperandArgs() {
return new String[] {"req: " + required, "opt: " + opt, "*r: " + rest, "kw: " + receivesKeywords};
}

@Override
Original file line number Diff line number Diff line change
@@ -32,6 +32,11 @@ public void visit(IRVisitor visitor) {
visitor.CheckForLJEInstr(this);
}

@Override
public String[] toStringNonOperandArgs() {
return new String[] { "maybe_lambda: " + maybeLambda};
}

public void check(ThreadContext context, DynamicScope dynamicScope, Block.Type blockType) {
IRRuntimeHelpers.checkForLJE(context, dynamicScope, maybeLambda, blockType);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jruby.ir.instructions;

import java.util.Arrays;
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.RubyModule;
import org.jruby.ir.IRVisitor;
@@ -34,8 +35,13 @@ public Instr clone(CloneInfo ii) {
}

@Override
public String toString() {
return getOperation() + "(" + getReceiver() + "," + missingConst + ")";
public String[] toStringNonOperandArgs() {
String[] base = super.toStringNonOperandArgs();
String[] args = Arrays.copyOf(base, base.length + 1);

args[args.length - 1] = "missing: " + missingConst;

return args;
}

@Override
Original file line number Diff line number Diff line change
@@ -42,6 +42,11 @@ public Instr clone(CloneInfo ii) {
getContainer().cloneForInlining(ii), getSuperClass().cloneForInlining(ii));
}

@Override
public String[] toStringNonOperandArgs() {
return new String[] {"name: " + newIRClassBody.getName() };
}

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
Object container = getContainer().retrieve(context, self, currScope, currDynScope, temp);
Original file line number Diff line number Diff line change
@@ -28,9 +28,10 @@ public IRMethod getMethod() {
return method;
}


@Override
public String toString() {
return getOperation() + "(" + getContainer() + ", " + method.getName() + ", " + method.getFileName() + ")";
public String[] toStringNonOperandArgs() {
return new String[] {"name: " + method.getName() };
}

@Override
Original file line number Diff line number Diff line change
@@ -19,8 +19,8 @@ public DefineInstanceMethodInstr(IRMethod method) {
}

@Override
public String toString() {
return getOperation() + "(" + method.getName() + ", " + method.getFileName() + ")";
public String[] toStringNonOperandArgs() {
return new String[] {"name: " + method.getName() };
}

@Override
Original file line number Diff line number Diff line change
@@ -42,8 +42,8 @@ public boolean computeScopeFlags(IRScope scope) {
}

@Override
public String toString() {
return super.toString() + "(" + metaClassBody.getName() + ", " + getObject() + ", " + metaClassBody.getFileName() + ")";
public String[] toStringNonOperandArgs() {
return new String[] {"name: " + metaClassBody.getName() };
}

@Override
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ public Operand getContainer() {
}

@Override
public String toString() {
return super.toString() + "(" + newIRModuleBody.getName() + ", " + getContainer() + ", " + newIRModuleBody.getFileName() + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "name: " + newIRModuleBody.getName() };
}

@Override
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ public Encoding getEncoding() {
}

@Override
public String toString() {
return super.toString() + "(" + encoding + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "name: " + encoding };
}

@Override
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/GetInstr.java
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ public Operand getSource() {
}

@Override
public String toString() {
return super.toString() + "(" + getSource() + (ref == null ? "" : ", " + ref) + ")";
public String[] toStringNonOperandArgs() {
return new String[] {"name: " + ref};
}
}
Original file line number Diff line number Diff line change
@@ -53,8 +53,8 @@ public Instr clone(CloneInfo ii) {
}

@Override
public String toString() {
return super.toString() + "(" + getCurrentModule() + ", " + constName + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "name: " + constName, "no_priv: " + noPrivateConsts};
}

private Object cache(Ruby runtime, RubyModule module) {
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jruby.ir.instructions;

import java.util.Arrays;
import org.jruby.ir.IRScope;
import org.jruby.ir.transformations.inlining.CloneInfo;

@@ -17,6 +18,16 @@ public InlinedLineNumberInstr(IRScope scope, int lineNumber) {
this.scope = scope;
}

@Override
public String[] toStringNonOperandArgs() {
String[] base = super.toStringNonOperandArgs();
String[] args = Arrays.copyOf(base, base.length + 1);

args[args.length - 1] = "scope_name: " + scope.getName();

return args;
}

@Override
public Instr clone(CloneInfo ii) {
return this; // Always retain the scope it originally came from
40 changes: 32 additions & 8 deletions core/src/main/java/org/jruby/ir/instructions/Instr.java
Original file line number Diff line number Diff line change
@@ -49,26 +49,50 @@ public Instr(Operation operation, Operand[] operands) {
this.operands = operands;
}

private String[] EMPTY_STRINGS = new String[0];
public String[] toStringNonOperandArgs() {
return EMPTY_STRINGS;
}

/**
* Instructions are meant to be in a machine-readable format so offline tooling can parse the
* debugging output. The format is:
*
* (result_op '=')? instr '(' (operand ',' )* operand? ';' (extra_arg ',')* extra_arg? ')'
* extra_arg can either be plain value or in a key: value format.
* @return
*/
@Override
public String toString() {
StringBuilder buf = new StringBuilder(isDead() ? "[DEAD]" : "");

if (this instanceof ResultInstr) buf.append(((ResultInstr) this).getResult()).append(" = ");

buf.append(operation);

if (operands.length > 0) {
buf.append("(");
for (int i = 0; i < operands.length-1; i++) {
buf.append(operands[i]).append(", ");
}
buf.append(operation).append('(');
toArgList(buf, operands);

buf.append(operands[operands.length-1]).append(")");
String[] extraArgs = toStringNonOperandArgs();
if (extraArgs.length >= 1) {
if (operands.length > 0) buf.append(' ');
buf.append(';');
toArgList(buf, extraArgs);
}
buf.append(')');

return buf.toString();
}

private StringBuilder toArgList(StringBuilder buf, Object[] args) {
if (args.length <= 0) return buf;

for (int i = 0; i < args.length - 1; i++) {
buf.append(args[i]).append(", ");
}
buf.append(args[args.length - 1]);

return buf;
}

@Interp
public Operation getOperation() {
return operation;
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/ir/instructions/LabelInstr.java
Original file line number Diff line number Diff line change
@@ -15,10 +15,6 @@ public Label getLabel() {
return (Label) operands[0];
}

public String toString() {
return getLabel() + ":";
}

@Override
public Instr clone(CloneInfo ii) {
return new LabelInstr(ii.getRenamedLabel(getLabel()));
Original file line number Diff line number Diff line change
@@ -41,8 +41,8 @@ public String getConstName() {
}

@Override
public String toString() {
return super.toString() + "(" + getDefiningScope() + ", " + constName + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "name: " + constName };
}

@Override
Original file line number Diff line number Diff line change
@@ -19,8 +19,8 @@ public int getLineNumber() {
}

@Override
public String toString() {
return super.toString() + "(" + lineNumber + ")";
public String[] toStringNonOperandArgs() {
return new String[] {"n: " + lineNumber};
}

@Override
Original file line number Diff line number Diff line change
@@ -48,8 +48,8 @@ public void decrementLVarScopeDepth() {
}

@Override
public String toString() {
return result + " = load_lvar(" + scope.getName() + ", " + getLocalVar() + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "scope: " + scope.getName() };
}

@Override
Original file line number Diff line number Diff line change
@@ -46,9 +46,8 @@ public int getExpectedVersion() {
}

@Override
public String toString() {
return super.toString() + "(" + getCandidateObject() + ", " + getExpectedVersion() + "[" + module.getName() + "], " +
getFailurePathLabel() + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "name: " + module.getName(), "expected_version: " + expectedVersion};
}

@Override
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@ public Operand[] getOperands() {
}

@Override
public String toString() {
return getOperation() + "(" + getReturnValue() + ", <" + methodName + ">" + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "name: " + methodName };
}

public boolean computeScopeFlags(IRScope scope) {
Original file line number Diff line number Diff line change
@@ -30,8 +30,8 @@ public int getMinArgsLength() {
}

@Override
public String toString() {
return super.toString() + "(" + getArray() + "," + index + "," + minArgsLength + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "index: " + index, "min_length: " + minArgsLength};
}

@Override
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jruby.ir.instructions;

import org.jruby.RubyModule;
import org.jruby.internal.runtime.methods.InterpretedIRBodyMethod;
import org.jruby.internal.runtime.methods.InterpretedIRMethod;
import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
@@ -36,11 +37,11 @@ public Instr clone(CloneInfo ii) {

@Override
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) {
InterpretedIRMethod bodyMethod = (InterpretedIRMethod) getModuleBody().retrieve(context, self, currScope, currDynScope, temp);
InterpretedIRBodyMethod bodyMethod = (InterpretedIRBodyMethod) getModuleBody().retrieve(context, self, currScope, currDynScope, temp);
Block b = (Block) getBlock().retrieve(context, self, currScope, currDynScope, temp);
RubyModule implClass = bodyMethod.getImplementationClass();

return bodyMethod.call(context, implClass, implClass, null, new IRubyObject[]{}, b);
return bodyMethod.call(context, implClass, implClass, null, b);
}

@Override
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/PutInstr.java
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public Operand getValue() {
}

@Override
public String toString() {
return getOperation() + "(" + getTarget() + (ref == null ? "" : ", " + ref) + ") = " + getValue();
public String[] toStringNonOperandArgs() {
return new String[] {"name: " + ref};
}
}
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ public int getOpt() {
}

@Override
public String toString() {
return super.toString() + "(" + required + ", " + opt + ", " + rest + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "req: " + required, "o: " + opt, "*r: " + rest};
}

public int getRequired() {
Original file line number Diff line number Diff line change
@@ -23,11 +23,6 @@ public int getArgIndex() {
return argIndex;
}

@Override
public String toString() {
return super.toString() + "(" + argIndex + ")";
}

public IRubyObject receiveArg(ThreadContext context, IRubyObject[] args, boolean keywordArgumentSupplied) {
throw new RuntimeException("ReceiveArgBase.interpret called! " + this.getClass().getName() + " does not define receiveArg");
}
Original file line number Diff line number Diff line change
@@ -21,8 +21,8 @@ public ReceiveKeywordArgInstr(Variable result, String argName, int required) {
}

@Override
public String toString() {
return (isDead() ? "[DEAD]" : "") + getResult() + " = " + getOperation() + "(" + required + ", " + argName + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "name: " + argName, "req: " + required};
}

@Override
Original file line number Diff line number Diff line change
@@ -19,8 +19,8 @@ public ReceiveKeywordRestArgInstr(Variable result, int required) {
}

@Override
public String toString() {
return (isDead() ? "[DEAD]" : "") + getResult() + " = " + getOperation() + "(" + required + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "req: " + required };
}

@Override
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ public ReceiveOptArgInstr(Variable result, int requiredArgs, int preArgs, int op
}

@Override
public String toString() {
return (isDead() ? "[DEAD]" : "") + getResult() + " = " + getOperation() + "(" + requiredArgs + "," + preArgs + "," + argIndex + ")";
public String[] toStringNonOperandArgs() {
return new String[] {"index:" + getArgIndex(), "req: " + requiredArgs, "pre: " + preArgs};
}

public int getPreArgs() {
Original file line number Diff line number Diff line change
@@ -30,8 +30,8 @@ public ReceivePostReqdArgInstr(Variable result, int argIndex, int preReqdArgsCou
}

@Override
public String toString() {
return (isDead() ? "[DEAD]" : "") + getResult() + " = " + getOperation() + "(" + argIndex + ", " + preReqdArgsCount + ", " + postReqdArgsCount + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "index: " + getArgIndex(), "pre: " + preReqdArgsCount, "post: " + postReqdArgsCount};
}

@Override
Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Fixnum;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.CloneInfo;
@@ -25,13 +23,8 @@ public ReceiveRestArgInstr(Variable result, int required, int argIndex) {
}

@Override
public String toString() {
return (isDead() ? "[DEAD]" : "") + getResult() + " = " + getOperation() + "(" + required + ", " + argIndex + ")";
}

@Override
public Operand[] getOperands() {
return new Operand[] { new Fixnum(required), new Fixnum(argIndex) };
public String[] toStringNonOperandArgs() {
return new String[] { "index: " + getArgIndex(), "req: " + required };
}

@Override
Original file line number Diff line number Diff line change
@@ -34,8 +34,8 @@ public ReqdArgMultipleAsgnInstr(Variable result, Operand array, int index) {
public int getPostArgsCount() { return postArgsCount; }

@Override
public String toString() {
return getOperation() + "(" + getArray() + ", " + index + ", " + preArgsCount + ", " + postArgsCount + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "index: " + index, "pre: " + preArgsCount, "post: " + postArgsCount};
}

@Override
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
import org.jruby.RubyArray;
import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Fixnum;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.transformations.inlining.CloneInfo;
@@ -36,8 +35,8 @@ public int getPostArgsCount() {
}

@Override
public String toString() {
return super.toString() + "(" + getArray() + ", " + index + ", " + preArgsCount + ", " + postArgsCount + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "index: " + index, "pre: " + preArgsCount, "post: " + postArgsCount};
}

@Override
Original file line number Diff line number Diff line change
@@ -14,8 +14,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;

import java.util.Arrays;

import static org.jruby.ir.IRFlags.REQUIRES_FRAME;

public class RuntimeHelperCall extends ResultBaseInstr {
@@ -67,8 +65,8 @@ public Instr clone(CloneInfo ii) {
}

@Override
public String toString() {
return (getResult() == null ? "" : (getResult() + " = ")) + getOperation() + "(" + helperMethod + ", " + Arrays.toString(getArgs()) + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "method: " + helperMethod};
}

public IRubyObject callHelper(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block.Type blockType) {
Original file line number Diff line number Diff line change
@@ -55,8 +55,8 @@ public Instr clone(CloneInfo ii) {
}

@Override
public String toString() {
return super.toString() + "(" + constName + ", " + getStartingScope() + ", no-private-consts=" + noPrivateConsts + ")";
public String[] toStringNonOperandArgs() {
return new String[] {"name: " + constName, "no_priv: " + noPrivateConsts};
}

public ConstantCache getConstantCache() {
Original file line number Diff line number Diff line change
@@ -32,8 +32,8 @@ public String getVarName() {
}

@Override
public String toString() {
return result + " = set_captured_var(" + getMatch2Result() + ", '" + varName + "')";
public String[] toStringNonOperandArgs() {
return new String[] { "name: " + varName };
}

@Override
Original file line number Diff line number Diff line change
@@ -38,8 +38,8 @@ public IRScope getScope() {
}

@Override
public String toString() {
return "store_lvar(" + getValue() + ", " + scope.getName() + ", " + getLocalVar() + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "scope_name: " + scope.getName()};
}

// SSS FIXME: This feels dirty
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/instructions/TraceInstr.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jruby.ir.instructions;

import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.runtime.RubyEvent;

@@ -46,7 +45,8 @@ public int getLinenumber() {
return linenumber;
}

public String toString() {
return getOperation() + "(" + event + ", " + name + ", " + filename + ", " + linenumber + ")";
@Override
public String[] toStringNonOperandArgs() {
return new String[] {"ev: " + event, "name: " + name, "file: " + filename, "line: " + linenumber};
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/instructions/YieldInstr.java
Original file line number Diff line number Diff line change
@@ -42,8 +42,8 @@ public Instr clone(CloneInfo ii) {
}

@Override
public String toString() {
return getResult() + " = " + getOperation() + "(" + getBlockArg() + ", " + (unwrapArray ? "UNWRAP=" : "") + getYieldArg() + ")";
public String[] toStringNonOperandArgs() {
return new String[] { "unwrap: " + unwrapArray};
}

public boolean isUnwrapArray() {
Original file line number Diff line number Diff line change
@@ -31,11 +31,6 @@ public Instr clone(CloneInfo ii) {
cloneCallArgs(ii));
}

@Override
public String toString() {
return super.toString() + "{1F}";
}

public long getFixnumArg() {
return fixNum;
}
Original file line number Diff line number Diff line change
@@ -31,11 +31,6 @@ public Instr clone(CloneInfo ii) {
getReceiver().cloneForInlining(ii), cloneCallArgs(ii));
}

@Override
public String toString() {
return super.toString() + "{1F}";
}

public double getFloatArg() {
return flote;
}
240 changes: 240 additions & 0 deletions core/src/main/java/org/jruby/ir/interpreter/BodyInterpreterEngine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
package org.jruby.ir.interpreter;

import org.jruby.RubyModule;
import org.jruby.common.IRubyWarnings;
import org.jruby.ir.IRScope;
import org.jruby.ir.OpClass;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.CopyInstr;
import org.jruby.ir.instructions.GetFieldInstr;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.instructions.JumpInstr;
import org.jruby.ir.instructions.LineNumberInstr;
import org.jruby.ir.instructions.NonlocalReturnInstr;
import org.jruby.ir.instructions.ResultInstr;
import org.jruby.ir.instructions.ReturnBase;
import org.jruby.ir.instructions.RuntimeHelperCall;
import org.jruby.ir.instructions.SearchConstInstr;
import org.jruby.ir.instructions.TraceInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockCallInstr;
import org.jruby.ir.instructions.specialized.OneOperandArgNoBlockNoResultCallInstr;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.TemporaryFixnumVariable;
import org.jruby.ir.operands.TemporaryFloatVariable;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.ivars.VariableAccessor;
import org.jruby.runtime.opto.ConstantCache;

/**
* Created by enebo on 2/5/15.
*/
public class BodyInterpreterEngine extends InterpreterEngine {
@Override
public IRubyObject interpret(ThreadContext context, IRubyObject self, InterpreterContext interpreterContext, RubyModule implClass, String name, Block block, Block.Type blockType) {
Instr[] instrs = interpreterContext.getInstructions();
Object[] temp = interpreterContext.allocateTemporaryVariables();
int n = instrs.length;
int ipc = 0;
Object exception = null;

StaticScope currScope = interpreterContext.getStaticScope();
DynamicScope currDynScope = context.getCurrentScope();
IRScope scope = currScope.getIRScope();

// Init profiling this scope
boolean debug = IRRuntimeHelpers.isDebug();

// Enter the looooop!
while (ipc < n) {
Instr instr = instrs[ipc];

ipc++;

Operation operation = instr.getOperation();
if (debug) {
Interpreter.LOG.info("I: {}", instr);
Interpreter.interpInstrsCount++;
}

try {
switch (operation) {
case RETURN:
return (IRubyObject) retrieveOp(((ReturnBase) instr).getReturnValue(), context, self, currDynScope, currScope, temp);
case NONLOCAL_RETURN: {
NonlocalReturnInstr ri = (NonlocalReturnInstr)instr;
IRubyObject rv = (IRubyObject)retrieveOp(ri.getReturnValue(), context, self, currDynScope, currScope, temp);
return IRRuntimeHelpers.initiateNonLocalReturn(context, currDynScope, blockType, rv);
}
case LINE_NUM:
context.setLine(((LineNumberInstr) instr).lineNumber);
break;
case RECV_SELF:
break;
case RECV_JRUBY_EXC:
setResult(temp, currDynScope, ((ResultInstr) instr).getResult(), exception);
break;
case THROW:
instr.interpret(context, currScope, currDynScope, self, temp);
break;
case PUSH_FRAME:
context.preMethodFrameOnly(implClass, name, self, block);
// Only the top-level script scope has PRIVATE visibility.
// This is already handled as part of Interpreter.execute above.
// Everything else is PUBLIC by default.
context.setCurrentVisibility(Visibility.PUBLIC);
break;
case POP_FRAME:
context.popFrame();
break;
case PUSH_BINDING:
// IMPORTANT: Preserve this update of currDynScope.
// This affects execution of all instructions in this scope
// which will now use the updated value of currDynScope.
currDynScope = interpreterContext.newDynamicScope(context);
context.pushScope(currDynScope);
break;
case POP_BINDING:
context.popScope();
break;
case LOAD_FRAME_CLOSURE:
setResult(temp, currDynScope, instr, context.getFrameBlock());
break;
case DEF_INST_METH:
instr.interpret(context, currScope, currDynScope, self, temp);
break;
case PUT_CONST:
instr.interpret(context, currScope, currDynScope, self, temp);
break;
case NORESULT_CALL_1O: {
OneOperandArgNoBlockNoResultCallInstr call = (OneOperandArgNoBlockNoResultCallInstr) instr;
IRubyObject r = (IRubyObject) retrieveOp(call.getReceiver(), context, self, currDynScope, currScope, temp);
IRubyObject o = (IRubyObject) call.getArg1().retrieve(context, self, currScope, currDynScope, temp);
call.getCallSite().call(context, self, r, o);
break;
}
case SEARCH_CONST: {
SearchConstInstr sci = (SearchConstInstr) instr;
ConstantCache cache = sci.getConstantCache();
Object result;
if (!ConstantCache.isCached(cache)) {
result = sci.cache(context, currScope, currDynScope, self, temp);
} else {
result = cache.value;
}
setResult(temp, currDynScope, sci.getResult(), result);
break;
}
case PROCESS_MODULE_BODY:
setResult(temp, currDynScope, ((ResultInstr) instr).getResult(),
instr.interpret(context, currScope, currDynScope, self, temp));
break;
case DEF_CLASS:
setResult(temp, currDynScope, ((ResultInstr) instr).getResult(),
instr.interpret(context, currScope, currDynScope, self, temp));
break;
case INHERITANCE_SEARCH_CONST:
setResult(temp, currDynScope, ((ResultInstr) instr).getResult(),
instr.interpret(context, currScope, currDynScope, self, temp));
break;
case DEF_MODULE:
setResult(temp, currDynScope, ((ResultInstr) instr).getResult(),
instr.interpret(context, currScope, currDynScope, self, temp));
break;
case CALL_1O: {
OneOperandArgNoBlockCallInstr call = (OneOperandArgNoBlockCallInstr) instr;
IRubyObject r = (IRubyObject) retrieveOp(call.getReceiver(), context, self, currDynScope, currScope, temp);
IRubyObject o = (IRubyObject) call.getArg1().retrieve(context, self, currScope, currDynScope, temp);
setResult(temp, currDynScope, call.getResult(), call.getCallSite().call(context, self, r, o));
break;
}
case BNE:
ipc = instr.interpretAndGetNewIPC(context, currDynScope, currScope, self, temp, ipc);
break;
case DEF_CLASS_METH:
instr.interpret(context, currScope, currDynScope, self, temp);
break;
case LOAD_IMPLICIT_CLOSURE:
setResult(temp, currDynScope, ((ResultInstr) instr).getResult(), block);
break;
case RECV_RUBY_EXC: // NO INTERP
setResult(temp, currDynScope, ((ResultInstr) instr).getResult(), IRRuntimeHelpers.unwrapRubyException(exception));
break;
case COPY: // NO INTERP
setResult(temp, currDynScope, ((CopyInstr) instr).getResult(),
retrieveOp(((CopyInstr) instr).getSource(), context, self, currDynScope, currScope, temp));
break;
case JUMP: // NO INTERP
ipc = ((JumpInstr)instr).getJumpTarget().getTargetPC();
break;
case RUNTIME_HELPER: { // NO INTERP
RuntimeHelperCall rhc = (RuntimeHelperCall)instr;
setResult(temp, currDynScope, rhc.getResult(),
rhc.callHelper(context, currScope, currDynScope, self, temp, blockType));
break;
}
case GET_FIELD: { // NO INTERP
GetFieldInstr gfi = (GetFieldInstr)instr;
IRubyObject object = (IRubyObject)gfi.getSource().retrieve(context, self, currScope, currDynScope, temp);
VariableAccessor a = gfi.getAccessor(object);
Object result = a == null ? null : (IRubyObject)a.get(object);
if (result == null) {
if (context.runtime.isVerbose()) {
context.runtime.getWarnings().warning(IRubyWarnings.ID.IVAR_NOT_INITIALIZED, "instance variable " + gfi.getRef() + " not initialized");
}
result = context.nil;
}
setResult(temp, currDynScope, gfi.getResult(), result);
break;
}
case TRACE: {
if (context.runtime.hasEventHooks()) {
TraceInstr trace = (TraceInstr) instr;
// FIXME: Try and statically generate END linenumber instead of hacking it.
int linenumber = trace.getLinenumber() == -1 ? context.getLine()+1 : trace.getLinenumber();

context.trace(trace.getEvent(), trace.getName(), context.getFrameKlazz(),
trace.getFilename(), linenumber);
}
break;
}
default:
if (instr.getOperation().opClass == OpClass.BRANCH_OP) {
ipc = instr.interpretAndGetNewIPC(context, currDynScope, currScope, self, temp, ipc);
} else {
Object result = instr.interpret(context, currScope, currDynScope, self, temp);

if (instr instanceof ResultInstr) {
setResult(temp, currDynScope, ((ResultInstr) instr).getResult(), result);
}
}
}
} catch (Throwable t) {
ipc = instr.getRPC();
if (debug) {
Interpreter.LOG.info("in : " + interpreterContext.getStaticScope().getIRScope() + ", caught Java throwable: " + t + "; excepting instr: " + instr);
Interpreter.LOG.info("ipc for rescuer: " + ipc);
}

if (ipc == -1) {
Helpers.throwException(t);
} else {
exception = t;
}
}
}
throw context.runtime.newRuntimeError("BUG: interpreter fell through to end unexpectedly");
}

@Override
public IRubyObject interpret(ThreadContext context, IRubyObject self, InterpreterContext interpreterContext, RubyModule implClass, String name, IRubyObject[] args, Block block, Block.Type blockType) {
return interpret(context, self, interpreterContext, implClass, name, block, blockType);
}
}
572 changes: 26 additions & 546 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.jruby.ir.interpreter;

import org.jruby.ir.IRClassBody;
import org.jruby.ir.IREvalScript;
import org.jruby.ir.IRFlags;
import org.jruby.ir.IRMetaClassBody;
import org.jruby.ir.IRMethod;
import org.jruby.ir.IRModuleBody;
import org.jruby.ir.IRScope;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.representations.CFG;
@@ -31,6 +35,11 @@ public class InterpreterContext {
private final boolean receivesKeywordArguments;
private final boolean metaClassBodyScope;

private final static InterpreterEngine BODY_INTERPRETER = new BodyInterpreterEngine();
private final static InterpreterEngine DEFAULT_INTERPRETER = new InterpreterEngine();
private final static InterpreterEngine SIMPLE_METHOD_INTERPRETER = new InterpreterEngine();
public final InterpreterEngine engine;

// FIXME: Hack this should be a clone eventually since JIT might change this. Comment for it reflects what it should be.
// View of CFG at time of creating this context.
private CFG cfg = null;
@@ -39,6 +48,15 @@ public InterpreterContext(IRScope scope, Instr[] instructions) {
//FIXME: Remove once we conditionally plug in CFG on debug-only
this.cfg = scope.getCFG();

if (scope instanceof IRModuleBody || scope instanceof IRClassBody) {
engine = BODY_INTERPRETER;
// ENEBO: Playing with unboxable and subset instruction sets
//} else if (scope instanceof IRMethod && scope.getFlags().contains(IRFlags.SIMPLE_METHOD)) {
// engine = SIMPLE_METHOD_INTERPRETER;
} else {
engine = DEFAULT_INTERPRETER;
}

this.name = scope.getName();
this.fileName = scope.getFileName();
this.lineNumber = scope.getLineNumber();
612 changes: 612 additions & 0 deletions core/src/main/java/org/jruby/ir/interpreter/InterpreterEngine.java

Large diffs are not rendered by default.

1,076 changes: 1,076 additions & 0 deletions core/src/main/java/org/jruby/ir/interpreter/SimpleMethodInterpreterEngine.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jruby.ir.passes;

import org.jruby.ir.IRClosure;
import org.jruby.ir.IRScope;
import org.jruby.ir.IRScriptBody;
import org.jruby.ir.representations.CFG;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;
@@ -32,7 +34,8 @@ public void endExecute(CompilerPass pass, IRScope scope, Object data, boolean ch

if (c != null) {
LOG.info("\nGraph:\n" + c.toStringGraph());
LOG.info("\nInstructions:\n" + c.toStringInstrs());
LOG.info("\nInstructions[" + getScopeUUID(scope) + "," + scope.getClass().getSimpleName() + "," +
pass.getClass().getSimpleName() + "]:\n" + c.toStringInstrs() + "\n:Instructions");
} else {
LOG.info("\n instrs:\n" + scope.toStringInstrs());
}
@@ -44,4 +47,12 @@ public void endExecute(CompilerPass pass, IRScope scope, Object data, boolean ch
LOG.info("Finished " + pass.getLabel() + " on scope " + scope);
}
}

private String getScopeUUID(IRScope scope) {
if (scope instanceof IRScriptBody || scope instanceof IRClosure) {
return "" + scope.getFileName() + "#" + scope.getLineNumber() + "#";
}

return "" + scope.getFileName() + "#" + scope.getLineNumber() + "#" + scope.getName();
}
}
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
import org.jruby.internal.runtime.methods.CompiledIRMetaClassBody;
import org.jruby.internal.runtime.methods.CompiledIRMethod;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.InterpretedIRBodyMethod;
import org.jruby.internal.runtime.methods.InterpretedIRMetaClassBody;
import org.jruby.internal.runtime.methods.InterpretedIRMethod;
import org.jruby.internal.runtime.methods.UndefinedMethod;
@@ -1082,7 +1083,7 @@ private static RubyClass newMetaClassFromIR(Ruby runtime, IRScope metaClassBody,
@Interp
public static DynamicMethod newInterpretedModuleBody(ThreadContext context, IRScope irModule, Object rubyContainer) {
RubyModule newRubyModule = newRubyModuleFromIR(context, irModule, rubyContainer);
return new InterpretedIRMethod(irModule, Visibility.PUBLIC, newRubyModule);
return new InterpretedIRBodyMethod(irModule, newRubyModule);
}

@JIT
@@ -1105,7 +1106,7 @@ private static RubyModule newRubyModuleFromIR(ThreadContext context, IRScope irM
public static DynamicMethod newInterpretedClassBody(ThreadContext context, IRScope irClassBody, Object container, Object superClass) {
RubyModule newRubyClass = newRubyClassFromIR(context.runtime, irClassBody, superClass, container);

return new InterpretedIRMethod(irClassBody, Visibility.PUBLIC, newRubyClass);
return new InterpretedIRBodyMethod(irClassBody, newRubyClass);
}

@JIT
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/runtime/backtrace/FrameType.java
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import java.util.Map;
import java.util.Set;

import org.jruby.internal.runtime.methods.InterpretedIRMethod;
import org.jruby.ir.interpreter.Interpreter;

public enum FrameType {
@@ -14,6 +15,7 @@ public enum FrameType {

static {
INTERPRETED_CLASSES.add(Interpreter.class.getName());
INTERPRETED_CLASSES.add(InterpretedIRMethod.class.getName());

INTERPRETED_FRAMES.put("INTERPRET_METHOD", FrameType.METHOD);
INTERPRETED_FRAMES.put("INTERPRET_EVAL", FrameType.EVAL);
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.jruby.embed;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import java.net.URL;
import java.net.URLClassLoader;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class IsolatedScriptingContainerTest {

static ClassLoader cl;

@BeforeClass
public static void setupClassLoader() {
cl = Thread.currentThread().getContextClassLoader();
// make sure we have classloader which does not find jruby
ClassLoader c = new URLClassLoader( new URL[] {}, null );
try {
c.loadClass( "org.jruby.embed.ScriptingContainer" );
fail( "this classloader shall not find jruby" );
}
catch( ClassNotFoundException expected){}
// set it as context classloader
Thread.currentThread().setContextClassLoader( c );
}

@AfterClass
public static void restClassLoader() {
Thread.currentThread().setContextClassLoader( cl );
}

@Test
public void testIsolatedScriptingContainer() throws Exception {
// we do have an instance of "jruby" loaded via some other classloader
//System.setProperty("jruby.debug.loadService", "true");
ScriptingContainer instance = new IsolatedScriptingContainer();
String result = instance.runScriptlet( "$LOAD_PATH" ).toString();
assertNotNull(result);

assertEquals(instance.runScriptlet("JRuby.runtime.jruby_class_loader.parent" ), cl );
assertEquals(ScriptingContainer.class.getClassLoader(), cl);
}
}
9 changes: 9 additions & 0 deletions core/src/test/resources/rubygems/defaults/jruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# dummy to run IsolatedScriptingContainerTest
module Gem
class Specification
def self.reset
end
def self.add_dir *args
end
end
end
2 changes: 1 addition & 1 deletion ext/pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-parent</artifactId>
<version>9.0.0.0.pre1</version>
<version>9.0.0.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-ext</artifactId>
<packaging>pom</packaging>
2 changes: 1 addition & 1 deletion ext/ripper/pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-ext</artifactId>
<version>9.0.0.0.pre1</version>
<version>9.0.0.0-SNAPSHOT</version>
</parent>
<groupId>rubygems</groupId>
<artifactId>jruby-ripper</artifactId>
4 changes: 2 additions & 2 deletions lib/ruby/stdlib/rubygems/defaults/jruby.rb
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ def self.win_platform?
# Allow specifying jar and classpath type gem path entries
def self.path_separator
return File::PATH_SEPARATOR unless File::PATH_SEPARATOR == ':'
/(?<!jar:file|jar|file|classpath):/
/(?<!jar:file|jar|file|classpath|uri:classloader|uri):/
end
end

@@ -85,7 +85,7 @@ def dirs
elsif File.directory?(File.join(dir, "specifications")) || dir =~ /^file:/
File.join(dir, "specifications")
end
}.compact + spec_directories_from_classpath
}.compact + ['uri:classloader://specifications'] + spec_directories_from_classpath
end

def add_dir dir
1 change: 1 addition & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg
4 changes: 4 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/.jrubydir
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.
config.ru
gems
specifications
80 changes: 80 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/Mavenfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#-*- mode: ruby -*-

# it is war-file
packaging 'war'

# get jruby dependencies
properties( 'jruby.version' => '@project.version@',
'jruby.plugins.version' => '1.0.7',
'project.build.sourceEncoding' => 'utf-8',
'public.dir' => '${basedir}/public' )

pom( 'org.jruby:jruby', '${jruby.version}' )

jar( 'org.jruby.rack:jruby-rack', '1.1.18',
:exclusions => [ 'org.jruby:jruby-complete' ] )


# ruby-maven will dump an equivalent pom.xml
properties[ 'tesla.dump.pom' ] = 'pom.xml'

# a gem to be used
gem 'flickraw', '0.9.7'

repository( :url => 'http://rubygems-proxy.torquebox.org/releases',
:id => 'rubygems-releases' )

jruby_plugin :gem, :includeRubygemsInResources => true, :includeLibDirectoryInResources => true, :jrubyVersion => '1.7.19' do
execute_goal :initialize
end

# not really needed but for completeness:
# pack the war with that ruby-like directory layout
plugin( :war, '2.2',
:warSourceDirectory => '${public.dir}' )

resource :directory => '${basedir}', :includes => [ 'config.ru', '.jrubydir' ]

# start jetty for the tests
plugin( 'org.eclipse.jetty:jetty-maven-plugin', '9.1.3.v20140225',
:path => '/',
:webAppSourceDirectory => '${public.dir}',
:stopPort => 9999,
:stopKey => 'foo' ) do
execute_goal( 'start', :id => 'start jetty', :phase => 'pre-integration-test', :daemon => true )
execute_goal( 'stop', :id => 'stop jetty', :phase => 'post-integration-test' )
end

# download files during the tests
result = nil
execute 'download', :phase => 'integration-test' do
require 'open-uri'
result = open( 'http://localhost:8080' ).string
puts result
end

# verify the downloads
execute 'check download', :phase => :verify do
expected = 'hello world:'
unless result.match( /^#{expected}/ )
raise "missed expected string in download: #{expected}"
end
expected = 'self: uri:classloader://config.ru'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
expected = 'PWD: uri:classloader://'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
expected = 'Gem.path: ."uri:classloader://",'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
# TODO get rid off this over normalization
expected = 'uri:classloader:/gems/flickraw-0.9.7'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
end
# vim: syntax=Ruby
19 changes: 19 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#-*- mode: ruby -*-

use Rack::ShowExceptions

require 'hello_world'

run lambda { |env|
require 'flickraw'
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
[ "self: #{__FILE__}\n", "PWD: #{Dir.pwd}\n", "Gem.path: #{Gem.path.inspect}\n", Gem.loaded_specs['flickraw'].gem_dir + "\n", HelloWorld.new + "\n" ]
]
}

# vim: syntax=Ruby
7 changes: 7 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/lib/hello_world.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'openssl'

class HelloWorld < String
def initialize
super "hello world: #{OpenSSL::Random.random_bytes( 16 ).inspect}"
end
end
152 changes: 152 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>no_group_id_given</groupId>
<artifactId>j2ee_jetty_rack</artifactId>
<version>0.0.0</version>
<packaging>war</packaging>
<name>j2ee_jetty_rack</name>
<properties>
<jruby.version>@project.version@</jruby.version>
<jruby.plugins.version>1.0.7</jruby.plugins.version>
<tesla.dump.pom>pom.xml</tesla.dump.pom>
<public.dir>${basedir}/public</public.dir>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<tesla.version>0.1.1</tesla.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby</artifactId>
<version>${jruby.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jruby.rack</groupId>
<artifactId>jruby-rack</artifactId>
<version>1.1.18</version>
<exclusions>
<exclusion>
<artifactId>jruby-complete</artifactId>
<groupId>org.jruby</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>flickraw</artifactId>
<version>0.9.7</version>
<type>gem</type>
</dependency>
</dependencies>
<repositories>
<repository>
<id>rubygems-releases</id>
<url>http://rubygems-proxy.torquebox.org/releases</url>
</repository>
</repositories>
<build>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>config.ru</include>
<include>.jrubydir</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
<version>${jruby.plugins.version}</version>
<executions>
<execution>
<goals>
<goal>initialize</goal>
</goals>
</execution>
</executions>
<configuration>
<includeRubygemsInResources>true</includeRubygemsInResources>
<includeLibDirectoryInResources>true</includeLibDirectoryInResources>
<jrubyVersion>1.7.19</jrubyVersion>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<warSourceDirectory>${public.dir}</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.1.3.v20140225</version>
<executions>
<execution>
<id>start jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<path>/</path>
<webAppSourceDirectory>${public.dir}</webAppSourceDirectory>
<stopPort>9999</stopPort>
<stopKey>foo</stopKey>
</configuration>
</plugin>
<plugin>
<groupId>io.tesla.polyglot</groupId>
<artifactId>tesla-polyglot-maven-plugin</artifactId>
<version>${tesla.version}</version>
<executions>
<execution>
<id>download</id>
<phase>integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<taskId>download</taskId>
<nativePom>Mavenfile</nativePom>
</configuration>
</execution>
<execution>
<id>check download</id>
<phase>verify</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<taskId>check download</taskId>
<nativePom>Mavenfile</nativePom>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.tesla.polyglot</groupId>
<artifactId>tesla-polyglot-ruby</artifactId>
<version>${tesla.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
2 changes: 2 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/public/WEB-INF/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
classes
config.ru
22 changes: 22 additions & 0 deletions maven/jruby/src/it/j2ee_jetty_rack/public/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>jruby.rack.layout_class</param-name>
<param-value>JRuby::Rack::ClassPathLayout</param-value>
</context-param>

<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>org.jruby.rack.RackServletContextListener</listener-class>
</listener>
</web-app>
1 change: 1 addition & 0 deletions maven/jruby/src/it/j2ee_tomcat_rack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg
4 changes: 4 additions & 0 deletions maven/jruby/src/it/j2ee_tomcat_rack/.jrubydir
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.
config.ru
gems
specifications
83 changes: 83 additions & 0 deletions maven/jruby/src/it/j2ee_tomcat_rack/Mavenfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#-*- mode: ruby -*-

# it is war-file
packaging 'war'

# get jruby dependencies
properties( 'jruby.version' => '@project.version@',
'jruby.home' => '../../../../../',
'jruby.plugins.version' => '1.0.3',
'project.build.sourceEncoding' => 'utf-8',
'public.dir' => '${basedir}/public' )

pom( 'org.jruby:jruby', '${jruby.version}' )

jar( 'org.jruby.rack:jruby-rack', '1.1.18',
:exclusions => [ 'org.jruby:jruby-complete' ] )


# ruby-maven will dump an equivalent pom.xml
properties[ 'tesla.dump.pom' ] = 'pom.xml'

# a gem to be used
gem 'flickraw', '0.9.7'

repository( :url => 'http://rubygems-proxy.torquebox.org/releases',
:id => 'rubygems-releases' )

jruby_plugin :gem, :includeRubygemsInResources => true, :includeLibDirectoryInResources => true, :jrubyVersion => '1.7.19' do
execute_goal :initialize
end

# not really needed but for completeness:
# pack the war with that ruby-like directory layout
plugin( :war, '2.2',
:warSourceDirectory => '${public.dir}' )

resource :directory => '${basedir}', :includes => [ 'config.ru', '.jrubydir' ]

# start tomcat for the tests
plugin( 'org.codehaus.mojo:tomcat-maven-plugin', '1.1',
:fork => true, :path => '/',
:warSourceDirectory => '${public.dir}' ) do
execute_goals( 'run',
:id => 'run-tomcat',
:phase => 'pre-integration-test' )
end

# download files during the tests
execute 'download', :phase => 'integration-test' do
require 'open-uri'
result = open( 'http://localhost:8080' ).string
File.open( 'result', 'w' ) { |f| f.puts result }
puts result
end

# verify the downloads
execute 'check download', :phase => :verify do
result = File.read( 'result' )
expected = 'hello world:'
unless result.match( /^#{expected}/ )
raise "missed expected string in download: #{expected}"
end
expected = 'self: uri:classloader://config.ru'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
expected = 'PWD: uri:classloader://'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
expected = 'Gem.path: ."uri:classloader://",'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
# TODO get rid off this over normalization
#expected = 'uri:classloader:/gems/flickraw-0.9.7'
# TODO find out why travis find the gem on filesystem
expected = 'target/classes/gems/flickraw-0.9.7'
unless result.match( /#{expected}/ )
raise "missed expected string in download: #{expected}"
end
end
# vim: syntax=Ruby
19 changes: 19 additions & 0 deletions maven/jruby/src/it/j2ee_tomcat_rack/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#-*- mode: ruby -*-

use Rack::ShowExceptions

require 'hello_world'

run lambda { |env|
require 'flickraw'
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
[ "self: #{__FILE__}\n", "PWD: #{Dir.pwd}\n", "Gem.path: #{Gem.path.inspect}\n","Gem::Specification.dirs: #{Gem::Specification.dirs.inspect}\n", Gem.loaded_specs['flickraw'].gem_dir + "\n", HelloWorld.new + "\n" ]
]
}

# vim: syntax=Ruby
7 changes: 7 additions & 0 deletions maven/jruby/src/it/j2ee_tomcat_rack/lib/hello_world.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'openssl'

class HelloWorld < String
def initialize
super "hello world: #{OpenSSL::Random.random_bytes( 16 ).inspect}"
end
end
141 changes: 141 additions & 0 deletions maven/jruby/src/it/j2ee_tomcat_rack/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>no_group_id_given</groupId>
<artifactId>j2ee_tomcat_rack</artifactId>
<version>0.0.0</version>
<packaging>war</packaging>
<name>j2ee_tomcat_rack</name>
<properties>
<jruby.home>../../../../../</jruby.home>
<jruby.version>@project.version@</jruby.version>
<jruby.plugins.version>1.0.3</jruby.plugins.version>
<tesla.dump.pom>pom.xml</tesla.dump.pom>
<public.dir>${basedir}/public</public.dir>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<tesla.version>0.1.1</tesla.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby</artifactId>
<version>${jruby.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jruby.rack</groupId>
<artifactId>jruby-rack</artifactId>
<version>1.1.18</version>
<exclusions>
<exclusion>
<artifactId>jruby-complete</artifactId>
<groupId>org.jruby</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>flickraw</artifactId>
<version>0.9.7</version>
<type>gem</type>
</dependency>
</dependencies>
<repositories>
<repository>
<id>rubygems-releases</id>
<url>http://rubygems-proxy.torquebox.org/releases</url>
</repository>
</repositories>
<build>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>config.ru</include>
<include>.jrubydir</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
<version>${jruby.plugins.version}</version>
<executions>
<execution>
<goals>
<goal>initialize</goal>
</goals>
</execution>
</executions>
<configuration>
<includeRubygemsInResources>true</includeRubygemsInResources>
<includeLibDirectoryInResources>true</includeLibDirectoryInResources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<warSourceDirectory>${public.dir}</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>run-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<path>/</path>
<warSourceDirectory>${public.dir}</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>io.tesla.polyglot</groupId>
<artifactId>tesla-polyglot-maven-plugin</artifactId>
<version>${tesla.version}</version>
<executions>
<execution>
<id>download</id>
<phase>integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<taskId>download</taskId>
<nativePom>Mavenfile</nativePom>
</configuration>
</execution>
<execution>
<id>check download</id>
<phase>verify</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<taskId>check download</taskId>
<nativePom>Mavenfile</nativePom>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.tesla.polyglot</groupId>
<artifactId>tesla-polyglot-ruby</artifactId>
<version>${tesla.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
2 changes: 2 additions & 0 deletions maven/jruby/src/it/j2ee_tomcat_rack/public/WEB-INF/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
classes
config.ru
22 changes: 22 additions & 0 deletions maven/jruby/src/it/j2ee_tomcat_rack/public/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>jruby.rack.layout_class</param-name>
<param-value>JRuby::Rack::ClassPathLayout</param-value>
</context-param>

<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>org.jruby.rack.RackServletContextListener</listener-class>
</listener>
</web-app>
57 changes: 33 additions & 24 deletions maven/jruby/src/it/runnable/Mavenfile
Original file line number Diff line number Diff line change
@@ -2,45 +2,54 @@

properties( 'tesla.dump.pom' => 'pom.xml',
'tesla.dump.readOnly' => true,
'jruby.version' => '@project.version@' )
'jruby.version' => '@project.version@',
'jruby.plugins.version' => '1.0.8' )
gemfile

gem 'bundler', '1.7.7'

pom 'org.jruby:jruby', '${jruby.version}'

jar 'de.saumya.mojo:jruby-mains', '0.1.0'

files = [ 'config.ru', '*file', '*file.lock', '.jbundler/classpath.rb',
'lib/**', 'app/**', 'config/**', 'vendor/**', 'spec/**' ]

resource :directory => '${basedir}' do
includes( files )
end
# resource :directory => '${basedir}' do
# includes( files )
# end

execute 'create jrubydir info', :phase => 'process-resources' do |ctx|
target = ctx.project.build.output_directory.to_pathname
entries = files.collect { |f| Dir[ f.sub( /\/.*$/, '') ] }.flatten.uniq
File.write( File.join( target, '.jrubydir' ),
(['.'] + entries + [ '' ]).join( "\n" ) )
require (ctx.basedir.to_pathname + '/../../../../../core/src/main/ruby/jruby/commands.rb')
files.select do |f|
f =~ /\//
end.collect do |f|
f.sub( /\/.*$/, '')
end.each do |f|
JRuby::Commands.generate_dir_info( File.join( target, f ), false )
end
end
# execute 'create jrubydir info', :phase => 'process-resources' do |ctx|
# target = ctx.project.build.output_directory.to_pathname
# entries = files.collect { |f| Dir[ f.sub( /\/.*$/, '') ] }.flatten.uniq
# File.write( File.join( target, '.jrubydir' ),
# (['.'] + entries + [ '' ]).join( "\n" ) )
# require (ctx.basedir.to_pathname + '/../../../../../core/src/main/ruby/jruby/commands.rb')
# files.select do |f|
# f =~ /\//
# end.collect do |f|
# f.sub( /\/.*$/, '')
# end.each do |f|
# JRuby::Commands.generate_dir_info( File.join( target, f ), false )
# end
# end

resource :directory => '${project.build.directory}/rubygems/bin' do
includes '*'
target_path 'META-INF/jruby.home/bin'
end
# resource :directory => '${project.build.directory}/rubygems/bin' do
# includes '*'
# target_path 'META-INF/jruby.home/bin'
# end

build do
directory 'pkg'
end

jruby_plugin!( :gem, :includeRubygemsInResources => true )
jruby_plugin!( :gem,
# need a jruby-complete from maven central here
:jrubyVersion => '1.7.19',
:includeRubygemsInResources => true ) do
execute_goals( 'generate-resources', 'process-resources', :includeBinStubs => true, :includeRubyResources => files )
end


if File.file?('Jarfile.lock')
phase :package do
@@ -69,7 +78,7 @@ plugin :shade do
:id => 'pack',
:artifactSet => { :excludes => ['rubygems:*'] },
:transformers => [ { :@implementation => 'org.apache.maven.plugins.shade.resource.ManifestResourceTransformer',
:mainClass => 'Main' } ] )
:mainClass => 'de.saumya.mojo.mains.JarMain' } ] )
end

# test bits
311 changes: 311 additions & 0 deletions maven/jruby/src/it/runnable/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>no_group_id_given</groupId>
<artifactId>runnable</artifactId>
<version>0.0.0</version>
<name>runnable</name>
<properties>
<tesla.dump.readOnly>true</tesla.dump.readOnly>
<jruby.version>@project.version@</jruby.version>
<jruby.plugins.version>1.0.8</jruby.plugins.version>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<tesla.dump.pom>pom.xml</tesla.dump.pom>
</properties>
<dependencies>
<dependency>
<groupId>rubygems</groupId>
<artifactId>bundler</artifactId>
<version>1.7.7</version>
<type>gem</type>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby</artifactId>
<version>${jruby.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>de.saumya.mojo</groupId>
<artifactId>jruby-mains</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>rubygems-releases</id>
<url>http://rubygems-proxy.torquebox.org/releases</url>
</repository>
</repositories>
<build>
<directory>pkg</directory>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>.</outputDirectory>
<finalName>runnable</finalName>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4</version>
<configuration>
<filesets>
<fileset>
<directory>.</directory>
<includes>
<include>runnable.jar</include>
<include>*/**/*.jar</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
<version>${jruby.plugins.version}</version>
<executions>
<execution>
<id>install gems</id>
<goals>
<goal>initialize</goal>
</goals>
</execution>
<execution>
<goals>
<goal>generate-resources</goal>
<goal>process-resources</goal>
</goals>
<configuration>
<includeBinStubs>true</includeBinStubs>
<includeRubyResources>
<includeRubyResource>config.ru</includeRubyResource>
<includeRubyResource>*file</includeRubyResource>
<includeRubyResource>*file.lock</includeRubyResource>
<includeRubyResource>.jbundler/classpath.rb</includeRubyResource>
<includeRubyResource>lib/**</includeRubyResource>
<includeRubyResource>app/**</includeRubyResource>
<includeRubyResource>config/**</includeRubyResource>
<includeRubyResource>vendor/**</includeRubyResource>
<includeRubyResource>spec/**</includeRubyResource>
</includeRubyResources>
</configuration>
</execution>
</executions>
<configuration>
<jrubyVersion>1.7.19</jrubyVersion>
<includeRubygemsInResources>true</includeRubygemsInResources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy jar dependencies</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<type>jar</type>
<version>1.49</version>
<classifier />
<outputDirectory>${project.build.outputDirectory}/org/bouncycastle/bcpkix-jdk15on/1.49</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<type>jar</type>
<version>1.6.4</version>
<classifier />
<outputDirectory>${project.build.outputDirectory}/org/slf4j/slf4j-simple/1.6.4</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<type>jar</type>
<version>1.49</version>
<classifier />
<outputDirectory>${project.build.outputDirectory}/org/bouncycastle/bcprov-jdk15on/1.49</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<type>jar</type>
<version>1.6.4</version>
<classifier />
<outputDirectory>${project.build.outputDirectory}/org/slf4j/slf4j-api/1.6.4</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>pack</id>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>rubygems:*</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>de.saumya.mojo.mains.JarMain</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>rake -T</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-jar</argument>
<argument>runnable.jar</argument>
<argument>-S</argument>
<argument>rake</argument>
<argument>-T</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>rspec</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-jar</argument>
<argument>runnable.jar</argument>
<argument>-S</argument>
<argument>rspec</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<executable>java</executable>
<environmentVariables>
<PATH>${basedir}</PATH>
<HOME>${basedir}</HOME>
<GEM_PATH>${basedir}</GEM_PATH>
<GEM_HOME>${basedir}</GEM_HOME>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>gemfile</id>
<activation>
<file>
<missing>Gemfile.lock</missing>
</file>
</activation>
<dependencies>
<dependency>
<groupId>rubygems</groupId>
<artifactId>rspec</artifactId>
<version>[2.14,2.99999]</version>
<type>gem</type>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>rake</artifactId>
<version>[10.3,10.99999]</version>
<type>gem</type>
</dependency>
<dependency>
<groupId>rubygems</groupId>
<artifactId>jbundler</artifactId>
<version>0.7.1</version>
<type>gem</type>
</dependency>
</dependencies>
</profile>
<profile>
<id>gemfile_lock</id>
<activation>
<file>
<exists>Gemfile.lock</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>gem-maven-plugin</artifactId>
<version>${jruby.plugins.version}</version>
<executions>
<execution>
<id>install gem sets for compile</id>
<phase>initialize</phase>
<goals>
<goal>sets</goal>
</goals>
<configuration>
<scope>compile</scope>
<gems>
<rspec>2.99.0</rspec>
<rspec-core>2.99.2</rspec-core>
<rspec-expectations>2.99.2</rspec-expectations>
<diff-lcs>1.2.5</diff-lcs>
<rspec-mocks>2.99.2</rspec-mocks>
<rake>10.3.2</rake>
<jbundler>0.7.1</jbundler>
<jar-dependencies>0.1.7</jar-dependencies>
<maven-tools>1.0.7</maven-tools>
<virtus>1.0.3</virtus>
<axiom-types>0.1.1</axiom-types>
<descendants_tracker>0.0.4</descendants_tracker>
<thread_safe>0.3.4</thread_safe>
<ice_nine>0.11.0</ice_nine>
<coercible>1.0.0</coercible>
<equalizer>0.0.9</equalizer>
<ruby-maven>3.1.1.0.8</ruby-maven>
<ruby-maven-libs>3.1.1</ruby-maven-libs>
</gems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
4 changes: 2 additions & 2 deletions maven/jruby/src/it/runnable/src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -30,9 +30,9 @@ private Main(org.jruby.RubyInstanceConfig config) {
config.setHardExit(true);
config.setCurrentDirectory( "uri:classloader://" );
config.setJRubyHome( "uri:classloader://META-INF/jruby.home" );
config.setLoadPaths( java.util.Arrays.asList("uri:classloader://") );
config.setLoadPaths( java.util.Arrays.asList("uri:classloader:/") );
java.util.Map env = new java.util.HashMap( System.getenv() );
env.put( "JARS_HOME", "uri:classloader://" );
env.put( "JARS_HOME", "uri:classloader:/" );
// needed for jruby version before 1.7.19
env.put( "BUNDLE_DISABLE_SHARED_GEMS", "true" );
config.setEnvironment( env );
12 changes: 11 additions & 1 deletion rakelib/test.rake
Original file line number Diff line number Diff line change
@@ -63,6 +63,15 @@ namespace :test do
:all => [:int, :jit, :aot]
}

def files_in_file(filename)
files = []
File.readlines(filename).each do |line|
filename = "test/#{line.chomp}.rb"
files << filename if File.exist? filename
end
files
end

namespace :mri do
mri_test_files = File.readlines('test/mri.index').grep(/^[^#]\w+/).map(&:chomp).join(' ')
task :int do
@@ -107,7 +116,8 @@ namespace :test do
end
t.test_files = files
t.verbose = true
t.ruby_opts << '-J-ea'
t.test_files = files_in_file 'test/slow.index'
t.ruby_opts << '-J-ea' << '--1.8'
t.ruby_opts << '-J-cp target/test-classes'
end

24 changes: 24 additions & 0 deletions spec/regression/GH-2182_struct_inspect_has_ascii_encoding_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-

# https://github.com/jruby/jruby/issues/2182
if RUBY_VERSION > '1.9'
describe 'Struct#inspect' do
it 'returns correct value' do
s1 = Struct.new(:aa).new("ΆἅἇἈ")
s1.inspect.should == "#<struct aa=\"ΆἅἇἈ\">"
s1.inspect.encoding.should == Encoding::UTF_8

s2 = Struct.new(:a, :b).new("ΆἅἇἈ", "abc")
s2.inspect.should == "#<struct a=\"ΆἅἇἈ\", b=\"abc\">"
s2.inspect.encoding.should == Encoding::UTF_8

s3 = Struct.new(:b).new("abc")
s3.inspect.should == "#<struct b=\"abc\">"
s3.inspect.encoding.should == Encoding::ASCII_8BIT

s4 = Struct.new(:"ΆἅἇἈ").new("aa")
s4.inspect.should == "#<struct ΆἅἇἈ=\"aa\">"
s4.inspect.encoding.should == Encoding::UTF_8
end
end
end
Original file line number Diff line number Diff line change
@@ -9,4 +9,3 @@
expect(r1).to eq(r2)
end
end

4 changes: 2 additions & 2 deletions spec/ruby/core/binding/shared/clone.rb
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
@b2 = @b1.send(@method)
end

it "returns a copy of the Bind object" do
it "returns a copy of the Binding object" do
@b1.should_not == @b2

eval("@secret", @b1).should == eval("@secret", @b2)
@@ -13,7 +13,7 @@
eval("a", @b1).should == eval("a", @b2)
end

it "is a shallow copy of the Bind object" do
it "is a shallow copy of the Binding object" do
eval("a = false", @b1)
eval("a", @b2).should == false
end
28 changes: 28 additions & 0 deletions spec/ruby/language/fixtures/super.rb
Original file line number Diff line number Diff line change
@@ -153,6 +153,34 @@ def baz(a)
end
end

module MultiSuperTargets
module M
def foo
super
end
end

class BaseA
def foo
:BaseA
end
end

class BaseB
def foo
:BaseB
end
end

class A < BaseA
include M
end

class B < BaseB
include M
end
end

module MS3
module ModA
def foo(a)
5 changes: 5 additions & 0 deletions spec/ruby/language/super_spec.rb
Original file line number Diff line number Diff line change
@@ -39,6 +39,11 @@
Super::MS2::C.new.foo([]).should == ["ModB#foo","C#baz","A#baz"]
end

it "can resolve to different methods in an included module method" do
Super::MultiSuperTargets::A.new.foo.should == :BaseA
Super::MultiSuperTargets::B.new.foo.should == :BaseB
end

it "searches class methods including modules" do
Super::MS3::A.new.foo([]).should == ["A#foo"]
Super::MS3::A.foo([]).should == ["ModA#foo"]
10 changes: 0 additions & 10 deletions spec/truffle/tags/core/array/compact_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/binding/clone_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/binding/dup_tags.txt

This file was deleted.

15 changes: 0 additions & 15 deletions spec/truffle/tags/core/kernel/catch_tags.txt

This file was deleted.

8 changes: 0 additions & 8 deletions spec/truffle/tags/core/kernel/throw_tags.txt

This file was deleted.

10 changes: 0 additions & 10 deletions spec/truffle/tags/core/string/each_line_tags.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
fails:String#each_line splits using default newline separator when none is specified
fails:String#each_line splits self using the supplied record separator and passes each substring to the block
fails:String#each_line taints substrings that are passed to the block if self is tainted
fails:String#each_line passes self as a whole to the block if the separator is nil
fails:String#each_line yields paragraphs (broken by 2 or more successive newlines) when passed ''
fails:String#each_line uses $/ as the separator when none is given
fails:String#each_line yields subclass instances for subclasses
fails:String#each_line returns self
fails:String#each_line tries to convert the separator to a string using to_str
fails:String#each_line does not care if the string is modified while substituting
fails:String#each_line raises a TypeError when the separator can't be converted to a string
fails:String#each_line accepts a string separator
fails:String#each_line raises a TypeError when the separator is a symbol
fails:String#each_line returns an enumerator when no block given
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/string/element_reference_tags.txt
Original file line number Diff line number Diff line change
@@ -7,12 +7,9 @@ fails:String#[] with Range always taints resulting strings when self is tainted
fails:String#[] with Range returns subclass instances
fails:String#[] with Range calls to_int on range arguments
fails:String#[] with Range works with Range subclasses
fails:String#[] with Regexp returns the matching portion of self
fails:String#[] with Regexp returns nil if there is no match
fails:String#[] with Regexp always taints resulting strings when self or regexp is tainted
fails:String#[] with Regexp returns an untrusted string if the regexp is untrusted
fails:String#[] with Regexp returns subclass instances
fails:String#[] with Regexp sets $~ to MatchData when there is a match and nil when there's none
fails:String#[] with Regexp, index returns the capture for the given index
fails:String#[] with Regexp, index always taints resulting strings when self or regexp is tainted
fails:String#[] with Regexp, index returns an untrusted string if the regexp is untrusted
3 changes: 0 additions & 3 deletions spec/truffle/tags/language/super_tags.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
fails:The super keyword calls the correct method when the method visibility is modified
fails:The super keyword supers up appropriate name even if used for multiple method names
fails:The super keyword passes along modified rest args when they weren't originally empty
fails:The super keyword passes along modified rest args when they were originally empty
fails:The super keyword raises a RuntimeError when called with implicit arguments from a method defined with define_method
fails:The super keyword invokes methods from a chain of anonymous modules
fails:The super keyword calls method_missing when a superclass method is not found
fails:The super keyword sees the included version of a module a method is alias from
2 changes: 2 additions & 0 deletions spec/truffle/tags/rubysl/rubysl-erb/spec/filename_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:ERB#filename raises an exception if there are errors processing content
fails:ERB#filename uses '(erb)' as filename when filename is not set
1 change: 1 addition & 0 deletions spec/truffle/tags/rubysl/rubysl-erb/spec/new_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:ERB.new forget local variables defined previous one
1 change: 1 addition & 0 deletions spec/truffle/tags/rubysl/rubysl-erb/spec/result_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:ERB#result is able to h() or u() if ERB::Util is included
3 changes: 3 additions & 0 deletions spec/truffle/tags/rubysl/rubysl-erb/spec/run_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:ERB#run print the result of compiled ruby code
fails:ERB#run is able to h() or u() if ERB::Util is included
fails:ERB#run use TOPLEVEL_BINDING if binding is not passed
5 changes: 5 additions & 0 deletions spec/truffle/tags/rubysl/rubysl-erb/spec/util/h_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fails:ERB::Util.h escape (& < > " ') to (&amp; &lt; &gt; &quot; &#39;)
fails:ERB::Util.h not escape characters except (& < > " ')
fails:ERB::Util.h return empty string when argument is nil
fails:ERB::Util.h returns string when argument is number
fails:ERB::Util.h returns string when argument is boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fails:ERB::Util.html_escape escape (& < > " ') to (&amp; &lt; &gt; &quot; &#39;)
fails:ERB::Util.html_escape not escape characters except (& < > " ')
fails:ERB::Util.html_escape return empty string when argument is nil
fails:ERB::Util.html_escape returns string when argument is number
fails:ERB::Util.html_escape returns string when argument is boolean
5 changes: 5 additions & 0 deletions spec/truffle/tags/rubysl/rubysl-erb/spec/util/u_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fails:ERB::Util.u encode characters
fails:ERB::Util.u encode unicode string
fails:ERB::Util.u returns empty string when argument is nil
fails:ERB::Util.u returns string when argument is number
fails:ERB::Util.u returns string when argument is boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fails:ERB::Util.url_encode encode characters
fails:ERB::Util.url_encode encode unicode string
fails:ERB::Util.url_encode returns empty string when argument is nil
fails:ERB::Util.url_encode returns string when argument is number
fails:ERB::Util.url_encode returns string when argument is boolean
3 changes: 1 addition & 2 deletions spec/truffle/truffle.mspec
Original file line number Diff line number Diff line change
@@ -88,11 +88,10 @@ class MSpecScript
set :rubysl, [
"spec/truffle/spec/rubysl/rubysl-erb/spec",
"spec/truffle/spec/rubysl/rubysl-set/spec",
"spec/truffle/spec/rubysl/rubysl-erb/spec",

# Can't load these - so tags aren't enough to exclude them. The problem is
# either fixtures or 'before' blocks.

"^spec/truffle/spec/rubysl/rubysl-erb/spec"
]

set :tags_patterns, [
26 changes: 25 additions & 1 deletion test/jruby/test_primitive_to_java.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
# encoding: UTF-8
require 'test/unit'
require 'java'

class TestPrimitiveToJava < Test::Unit::TestCase

def setup; super; require 'java' end

def test_primitive_conversion
t = Time.now
date = t.to_java(java.util.Date)

assert_equal(t.to_i, date.time / 1000, "Ruby time #{t} not converted to java date correctly: #{date}")
end

def test_char_conversion
str = 'a'
char = str.to_java(:char)
assert_instance_of Java::JavaLang::Character, char

str = ' '
char = str.to_java(Java::char)
assert_equal 32, char.charValue

str = '0'
char = str.to_java(java.lang.Character)
assert_equal 48.to_java(:char), char

assert_equal 228, 'ä'.to_java(:char).charValue unless RUBY_VERSION.index('1.8') == 0

assert_raises(ArgumentError) { ''.to_java(:char) }
assert_raises(ArgumentError) { 'už'.to_java('java.lang.Character') }
'už'[1].to_java('java.lang.Character') unless RUBY_VERSION.index('1.8') == 0
end

end
Loading

0 comments on commit 87b9356

Please sign in to comment.