Skip to content

Commit

Permalink
Showing 96 changed files with 6,903 additions and 5,236 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ It aims to be a complete, correct and fast implementation of Ruby, at the same
time as providing powerful new features such as concurrency without a
[global-interpreter-lock](http://en.wikipedia.org/wiki/Global_Interpreter_Lock),
true parallelism, and tight integration to the Java language to allow you to
uses Java classes in your Ruby program and to allow JRuby to be embedded into a
use Java classes in your Ruby program and to allow JRuby to be embedded into a
Java application.

You can use JRuby simply as a faster version of Ruby, you can use it to run Ruby
2 changes: 1 addition & 1 deletion core/pom.rb
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@
jar 'org.jruby:dirgra:0.3'

jar 'com.headius:invokebinder:1.5'
jar 'com.headius:options:1.3'
jar 'com.headius:options:1.4-SNAPSHOT'
jar 'com.headius:coro-mock:1.0', :scope => 'provided'
jar 'com.headius:unsafe-mock', '${unsafe.version}', :scope => 'provided'
jar 'com.headius:jsr292-mock:1.1', :scope => 'provided'
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
@@ -199,7 +199,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>com.headius</groupId>
<artifactId>options</artifactId>
<version>1.3</version>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.headius</groupId>
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -5094,8 +5094,8 @@ public FilenoUtil getFilenoUtil() {
private final Random random;

/** The runtime-local seed for hash randomization */
private long hashSeedK0;
private long hashSeedK1;
private final long hashSeedK0;
private final long hashSeedK1;

private StaticScopeFactory staticScopeFactory;

34 changes: 17 additions & 17 deletions core/src/main/java/org/jruby/RubyClass.java
Original file line number Diff line number Diff line change
@@ -159,27 +159,27 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
* Set a reflective allocator that calls the "standard" Ruby object
* constructor (Ruby, RubyClass) on the given class.
*
* @param cls The class from which to grab a standard Ruby constructor
* @param clazz The class from which to grab a standard Ruby constructor
*/
public void setRubyClassAllocator(final Class cls) {
public void setRubyClassAllocator(final Class<? extends IRubyObject> clazz) {
try {
final Constructor constructor = cls.getConstructor(Ruby.class, RubyClass.class);
final Constructor<? extends IRubyObject> constructor = clazz.getConstructor(Ruby.class, RubyClass.class);

this.allocator = new ObjectAllocator() {
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
try {
return (IRubyObject)constructor.newInstance(runtime, klazz);
return constructor.newInstance(runtime, klazz);
} catch (InvocationTargetException ite) {
throw runtime.newTypeError("could not allocate " + cls + " with (Ruby, RubyClass) constructor:\n" + ite);
throw runtime.newTypeError("could not allocate " + clazz + " with (Ruby, RubyClass) constructor:\n" + ite);
} catch (InstantiationException ie) {
throw runtime.newTypeError("could not allocate " + cls + " with (Ruby, RubyClass) constructor:\n" + ie);
throw runtime.newTypeError("could not allocate " + clazz + " with (Ruby, RubyClass) constructor:\n" + ie);
} catch (IllegalAccessException iae) {
throw runtime.newSecurityError("could not allocate " + cls + " due to inaccessible (Ruby, RubyClass) constructor:\n" + iae);
throw runtime.newSecurityError("could not allocate " + clazz + " due to inaccessible (Ruby, RubyClass) constructor:\n" + iae);
}
}
};

this.reifiedClass = cls;
this.reifiedClass = clazz;
} catch (NoSuchMethodException nsme) {
throw new RuntimeException(nsme);
}
@@ -190,26 +190,26 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
* constructor (Ruby, RubyClass) on the given class via a static
* __allocate__ method intermediate.
*
* @param cls The class from which to grab a standard Ruby __allocate__
* @param clazz The class from which to grab a standard Ruby __allocate__
* method.
*/
public void setRubyStaticAllocator(final Class cls) {
public void setRubyStaticAllocator(final Class<?> clazz) {
try {
final Method method = cls.getDeclaredMethod("__allocate__", Ruby.class, RubyClass.class);
final Method method = clazz.getDeclaredMethod("__allocate__", Ruby.class, RubyClass.class);

this.allocator = new ObjectAllocator() {
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
try {
return (IRubyObject)method.invoke(null, runtime, klazz);
return (IRubyObject) method.invoke(null, runtime, klazz);
} catch (InvocationTargetException ite) {
throw runtime.newTypeError("could not allocate " + cls + " with (Ruby, RubyClass) constructor:\n" + ite);
throw runtime.newTypeError("could not allocate " + clazz + " with (Ruby, RubyClass) constructor:\n" + ite);
} catch (IllegalAccessException iae) {
throw runtime.newSecurityError("could not allocate " + cls + " due to inaccessible (Ruby, RubyClass) constructor:\n" + iae);
throw runtime.newSecurityError("could not allocate " + clazz + " due to inaccessible (Ruby, RubyClass) constructor:\n" + iae);
}
}
};

this.reifiedClass = cls;
this.reifiedClass = clazz;
} catch (NoSuchMethodException nsme) {
throw new RuntimeException(nsme);
}
@@ -1578,11 +1578,11 @@ public synchronized void reify(String classDumpDir, boolean useChildLoader) {
}
}

public void setReifiedClass(Class newReifiedClass) {
public void setReifiedClass(Class<? extends IRubyObject> newReifiedClass) {
this.reifiedClass = newReifiedClass;
}

public Class getReifiedClass() {
public Class<? extends IRubyObject> getReifiedClass() {
return reifiedClass;
}

15 changes: 11 additions & 4 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -3314,7 +3314,6 @@ public static RubyIO convertToIO(ThreadContext context, IRubyObject obj) {
@JRubyMethod(name = "select", required = 1, optional = 3, meta = true)
public static IRubyObject select(ThreadContext context, IRubyObject recv, IRubyObject[] argv) {
IRubyObject read, write, except, _timeout;
Long timeout;
read = write = except = _timeout = context.nil;

switch (argv.length) {
@@ -3327,13 +3326,21 @@ public static IRubyObject select(ThreadContext context, IRubyObject recv, IRubyO
case 1:
read = argv[0];
}
final Long timeout;
if (_timeout.isNil()) {
timeout = null;
}
else {
double tmp = _timeout.convertToFloat().getDoubleValue();
if (tmp < 0) throw context.runtime.newArgumentError("negative timeout");
timeout = (long)(tmp * 1000); // ms
try { // MRI calls to_f even if not respond_to? (or respond_to_missing?) :to_f
_timeout = _timeout.callMethod(context, "to_f");
}
catch (RaiseException e) {
TypeConverter.handleUncoercibleObject(true, _timeout, context.runtime.getFloat());
throw e; // won't happen
}
final double t = _timeout.convertToFloat().getDoubleValue();
if ( t < 0 ) throw context.runtime.newArgumentError("negative timeout");
timeout = (long) (t * 1000); // ms
}

SelectExecutor args = new SelectExecutor(read, write, except, timeout);
48 changes: 17 additions & 31 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -59,7 +59,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -114,12 +113,7 @@ public RubyInstanceConfig() {

threadDumpSignal = Options.THREAD_DUMP_SIGNAL.load();

environment = new HashMap<String,String>();
try {
environment.putAll(System.getenv());
} catch (SecurityException se) {
}
setupEnvironment(getJRubyHome());
initEnvironment();
}

public RubyInstanceConfig(RubyInstanceConfig parentConfig) {
@@ -141,11 +135,15 @@ public RubyInstanceConfig(RubyInstanceConfig parentConfig) {
profilingService = parentConfig.profilingService;
profilingMode = parentConfig.profilingMode;

environment = new HashMap<String, String>();
initEnvironment();
}

private void initEnvironment() {
environment = new HashMap<String,String>();
try {
environment.putAll(System.getenv());
} catch (SecurityException se) {
}
catch (SecurityException se) { /* ignore missing getenv permission */ }
setupEnvironment(getJRubyHome());
}

@@ -1611,15 +1609,6 @@ public boolean shouldPrecompileAll() {
// Static configuration fields, used as defaults for new JRuby instances.
////////////////////////////////////////////////////////////////////////////

// NOTE: These BigDecimal fields must be initialized before calls to initGlobalJavaVersion

/** A BigDecimal representing 1.5, for Java spec version matching */
private static final BigDecimal BIGDECIMAL_1_5 = new BigDecimal("1.5");
/** A BigDecimal representing 1.6, for Java spec version matching */
private static final BigDecimal BIGDECIMAL_1_6 = new BigDecimal("1.6");
/** A BigDecimal representing 1.7, for Java spec version matching */
private static final BigDecimal BIGDECIMAL_1_7 = new BigDecimal("1.7");

/**
* The version to use for generated classes. Set to current JVM version by default
*/
@@ -1853,19 +1842,16 @@ public boolean shouldPrecompileAll() {
////////////////////////////////////////////////////////////////////////////

private static int initGlobalJavaVersion() {
String specVersion = Options.BYTECODE_VERSION.load();

// stack map calculation is failing for some compilation scenarios, so
// forcing both 1.5 and 1.6 to use 1.5 bytecode for the moment.
if (specVersion.equals("1.5")) {// || specVersion.equals("1.6")) {
return Opcodes.V1_5;
} else if (specVersion.equals("1.6")) {
return Opcodes.V1_6;
} else if (specVersion.equals("1.7") || specVersion.equals("1.8") || specVersion.equals("1.9") || specVersion.equals("9")) {
return Opcodes.V1_7;
} else {
System.err.println("unsupported Java version \"" + specVersion + "\", defaulting to 1.5");
return Opcodes.V1_5;
final String specVersion = Options.BYTECODE_VERSION.load();
switch ( specVersion ) {
case "1.6" : return Opcodes.V1_6;
case "1.7" : return Opcodes.V1_7;
case "1.8" : return Opcodes.V1_8;
// NOTE: JDK 9 now returns "9" instead of "1.9"
case "1.9" : case "9" : return Opcodes.V1_8; // +1
default :
System.err.println("unsupported Java version \"" + specVersion + "\", defaulting to 1.7");
return Opcodes.V1_7;
}
}

38 changes: 38 additions & 0 deletions core/src/main/java/org/jruby/ast/executable/RuntimeCache.java
Original file line number Diff line number Diff line change
@@ -425,6 +425,44 @@ private DynamicMethod cacheAndGet(ThreadContext context, RubyClass selfType, int
return method;
}

private DynamicMethod searchWithCacheNoMethodMissing(RubyClass clazz, int index, String name1) {
CacheEntry entry = clazz.searchWithCache(name1);
DynamicMethod method = entry.method;
if (entry.method == UndefinedMethod.INSTANCE) {
return null;
}
methodCache[index] = entry;
return method;
}

private DynamicMethod searchWithCacheNoMethodMissing(RubyClass clazz, int index, String name1, String name2) {
CacheEntry entry = clazz.searchWithCache(name1);
DynamicMethod method = entry.method;
if (entry.method == UndefinedMethod.INSTANCE) {
return searchWithCacheNoMethodMissing(clazz, index, name2);
}
methodCache[index] = entry;
return method;
}

// used from byte-code generated by RealClassGenerator
public final DynamicMethod searchWithCacheNoMethodMissing(IRubyObject obj, int index, String name1) {
CacheEntry myCache = getCacheEntry(index);
if (CacheEntry.typeOk(myCache, obj.getMetaClass())) {
return myCache.method;
}
return searchWithCacheNoMethodMissing(obj.getMetaClass(), index, name1);
}

// used from byte-code generated by RealClassGenerator
public final DynamicMethod searchWithCacheNoMethodMissing(IRubyObject obj, int index, String name1, String name2) {
CacheEntry myCache = getCacheEntry(index);
if (CacheEntry.typeOk(myCache, obj.getMetaClass())) {
return myCache.method;
}
return searchWithCacheNoMethodMissing(obj.getMetaClass(), index, name1, name2);
}

public DynamicMethod searchWithCache(RubyClass clazz, int index, String name1) {
CacheEntry entry = clazz.searchWithCache(name1);
DynamicMethod method = entry.method;
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/compiler/JITCompiler.java
Original file line number Diff line number Diff line change
@@ -418,8 +418,8 @@ public MethodJITClassGenerator(String className, String methodName, String key,
} else {
digestString = key;
}
this.className = packageName + "/" + className.replace('.', '/') + CLASS_METHOD_DELIMITER + JavaNameMangler.mangleMethodName(methodName) + "_" + digestString;
this.name = this.className.replaceAll("/", ".");
this.className = packageName + '/' + className.replace('.', '/') + CLASS_METHOD_DELIMITER + JavaNameMangler.mangleMethodName(methodName) + '_' + digestString;
this.name = this.className.replace('/', '.');
this.methodName = methodName;
this.method = method;
this.visitor = visitor;
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -2086,8 +2086,7 @@ private void handleBreakAndReturnsInLambdas() {
// --> IRRuntimeHelpers.handleBreakAndReturnsInLambdas(context, scope, bj, blockType)
Variable ret = createTemporaryVariable();
addInstr(new RuntimeHelperCall(ret, RuntimeHelperCall.Methods.HANDLE_BREAK_AND_RETURNS_IN_LAMBDA, new Operand[]{exc} ));
addInstr(new RethrowSavedExcInLambdaInstr());
addInstr(new ReturnInstr(ret));
addInstr(new ReturnOrRethrowSavedExcInstr(ret));

// End
addInstr(new LabelInstr(rEndLabel));
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/IRMethod.java
Original file line number Diff line number Diff line change
@@ -42,10 +42,10 @@ public synchronized InterpreterContext lazilyAcquireInterpreterContext() {
return interpreterContext;
}

public synchronized BasicBlock[] prepareForInitialCompilation() {
public synchronized BasicBlock[] prepareForCompilation() {
if (!hasBeenBuilt()) lazilyAcquireInterpreterContext();

return super.prepareForInitialCompilation();
return super.prepareForCompilation();
}

@Override
Loading

0 comments on commit b13e65e

Please sign in to comment.