Skip to content

Commit

Permalink
Merge branch 'master' into ruby-2.3 sans parser tweaks.
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/main/java/org/jruby/parser/RubyParser.java
	core/src/main/java/org/jruby/parser/RubyParser.y
	core/src/main/java/org/jruby/parser/YyTables.java
headius committed Jan 12, 2016
2 parents f1d645c + cb8f537 commit de5821e
Showing 167 changed files with 5,546 additions and 1,732 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
13 changes: 7 additions & 6 deletions bin/jruby.bash
Original file line number Diff line number Diff line change
@@ -146,12 +146,6 @@ for j in "$JRUBY_HOME"/lib/jruby.jar "$JRUBY_HOME"/lib/jruby-complete.jar; do
JRUBY_ALREADY_ADDED=true
done

# The Truffle jar always needs to be on the boot classpath, if it exists, so
# that the VM can substitute classes.
if [ -e "$JRUBY_HOME/lib/jruby-truffle.jar" ]; then
JRUBY_CP="$JRUBY_CP$CP_DELIMITER$JRUBY_HOME/lib/jruby-truffle.jar"
fi

if $cygwin; then
JRUBY_CP=`cygpath -p -w "$JRUBY_CP"`
fi
@@ -167,6 +161,9 @@ else
if [ "$j" == "$JRUBY_HOME"/lib/jruby.jar ]; then
continue
fi
if [ "$j" == "$JRUBY_HOME"/lib/jruby-truffle.jar ]; then
continue
fi
if [ "$j" == "$JRUBY_HOME"/lib/jruby-complete.jar ]; then
continue
fi
@@ -257,6 +254,10 @@ do
-X*\.\.\.|-X*\?)
ruby_args=("${ruby_args[@]}" "$1") ;;
# Match -Xa.b.c=d to translate to -Da.b.c=d as a java option
-X+T)
JRUBY_CP="$JRUBY_CP$CP_DELIMITER$JRUBY_HOME/lib/jruby-truffle.jar"
ruby_args=("${ruby_args[@]}" "-X+T")
;;
-X*)
val=${1:2}
if expr "$val" : '.*[.]' > /dev/null; then
13 changes: 7 additions & 6 deletions bin/jruby.sh
Original file line number Diff line number Diff line change
@@ -107,12 +107,6 @@ for j in "$JRUBY_HOME"/lib/jruby.jar "$JRUBY_HOME"/lib/jruby-complete.jar; do
JRUBY_ALREADY_ADDED=true
done

# The Truffle jar always needs to be on the boot classpath, if it exists, so
# that the VM can substitute classes.
if [ -e "$JRUBY_HOME/lib/jruby-truffle.jar" ]; then
JRUBY_CP="$JRUBY_CP$CP_DELIMITER$JRUBY_HOME/lib/jruby-truffle.jar"
fi

# ----- Set Up The System Classpath -------------------------------------------

if [ "$JRUBY_PARENT_CLASSPATH" != "" ]; then
@@ -124,6 +118,9 @@ else
if [ "$j" == "$JRUBY_HOME"/lib/jruby.jar ]; then
continue
fi
if [ "$j" == "$JRUBY_HOME"/lib/jruby-truffle.jar ]; then
continue
fi
if [ "$j" == "$JRUBY_HOME"/lib/jruby-complete.jar ]; then
continue
fi
@@ -200,6 +197,10 @@ do
-X*\.\.\.|-X*\?)
ruby_args="${ruby_args} $1" ;;
# Match -Xa.b.c=d to translate to -Da.b.c=d as a java option
-X+T)
JRUBY_CP="$JRUBY_CP$CP_DELIMITER$JRUBY_HOME/lib/jruby-truffle.jar"
ruby_args="${ruby_args} -X+T"
;;
-X*)
val=${1:2}
if expr "$val" : '.*[.]' > /dev/null; then
6 changes: 3 additions & 3 deletions core/pom.rb
Original file line number Diff line number Diff line change
@@ -53,11 +53,11 @@

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

jar 'com.headius:invokebinder:1.5'
jar 'com.headius:options:1.3'
jar 'com.headius:invokebinder:1.7-SNAPSHOT'
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'
6 changes: 3 additions & 3 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -184,7 +184,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>org.jruby.jcodings</groupId>
<artifactId>jcodings</artifactId>
<version>1.0.13</version>
<version>1.0.16-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
@@ -194,12 +194,12 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>com.headius</groupId>
<artifactId>invokebinder</artifactId>
<version>1.5</version>
<version>1.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.headius</groupId>
<artifactId>options</artifactId>
<version>1.3</version>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.headius</groupId>
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -2740,7 +2740,7 @@ private Node parseFileFromMainAndGetAST(InputStream in, String file, DynamicScop

private Node parseFileAndGetAST(InputStream in, String file, DynamicScope scope, int lineNumber, boolean isFromMain) {
ParserConfiguration parserConfig =
new ParserConfiguration(this, lineNumber, false, true, config);
new ParserConfiguration(this, lineNumber, false, true, isFromMain, config);
setupSourceEncoding(parserConfig, UTF8Encoding.INSTANCE);
return parser.parse(file, in, scope, parserConfig);
}
@@ -5111,8 +5111,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;
}

6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@
import java.net.URI;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.LinkOption;
@@ -269,6 +270,11 @@ public RubyFile(Ruby runtime, String path, InputStream in) {
this.setPath(path);
}

public RubyFile(Ruby runtime, String path, FileChannel channel) {
super(runtime, runtime.getFile(), channel);
this.setPath(path);
}

@Override
protected IRubyObject rbIoClose(Ruby runtime) {
// Make sure any existing lock is released before we try and close the file
15 changes: 11 additions & 4 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -3307,7 +3307,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) {
@@ -3320,13 +3319,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);
50 changes: 18 additions & 32 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());
}

@@ -402,7 +400,7 @@ public InputStream getScriptSource() {
// return the script between shebang and __END__ or CTRL-Z (0x1A)
return findScript(resource.inputStream());
}
return new BufferedInputStream(resource.inputStream(), 8192);
return resource.inputStream();
}
else {
throw new FileNotFoundException(script + " (Not a file)");
@@ -1626,15 +1624,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
*/
@@ -1868,19 +1857,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;
}
}

Loading

0 comments on commit de5821e

Please sign in to comment.