Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/main/java/org/jruby/truffle/runtime/core/RubyRegexp.java
  • Loading branch information
chrisseaton committed Dec 4, 2014
2 parents e5247d3 + 0f281bc commit e2a3b8c
Show file tree
Hide file tree
Showing 138 changed files with 2,117 additions and 1,150 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -86,5 +86,5 @@ notifications:
urls:
- "https://rubies.travis-ci.org/rebuild/jruby-head"
# we are on a branch
#on_success: always
on_success: always
on_failure: never
2 changes: 1 addition & 1 deletion bin/jirb
Expand Up @@ -9,7 +9,7 @@

require "irb"

if __FILE__.sub(/file:/, '') == $0.sub(/file:/, '')
if __FILE__.sub(/file:/, '').gsub(/ /,'%20') == $0.gsub(/file:/, '').gsub(/ /,'%20')
IRB.start(__FILE__)
else
# check -e option
Expand Down
2 changes: 1 addition & 1 deletion core/pom.rb
Expand Up @@ -37,7 +37,7 @@
jar 'com.github.jnr:jnr-unixsocket:0.3'
jar 'com.github.jnr:jnr-posix:3.0.7'
jar 'com.github.jnr:jnr-constants:0.8.6-SNAPSHOT'
jar 'com.github.jnr:jnr-ffi:2.0.0-SNAPSHOT'
jar 'com.github.jnr:jnr-ffi:2.0.0'
jar 'com.github.jnr:jffi:${jffi.version}'
jar 'com.github.jnr:jffi:${jffi.version}:native'

Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -81,7 +81,7 @@
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-ffi</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.github.jnr</groupId>
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Expand Up @@ -1690,6 +1690,8 @@ public IRubyObject instance_exec19(ThreadContext context, IRubyObject[] args, Bl
protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under, IRubyObject[] args, Block block, EvalType evalType) {
context.preExecuteUnder(under, block);

IRubyObject savedBindingSelf = block.getBinding().getSelf();
IRubyObject savedFrameSelf = block.getBinding().getFrame().getSelf();
Visibility savedVisibility = block.getBinding().getVisibility();
block.getBinding().setVisibility(PUBLIC);

Expand All @@ -1706,6 +1708,8 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,
return (IRubyObject) bj.getValue();
} finally {
block.getBinding().setVisibility(savedVisibility);
block.getBinding().setSelf(savedBindingSelf);
block.getBinding().getFrame().setSelf(savedFrameSelf);

context.postExecuteUnder();
}
Expand All @@ -1728,6 +1732,8 @@ private Block setupBlock(Block block, EvalType evalType) {
protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under, Block block, EvalType evalType) {
context.preExecuteUnder(under, block);

IRubyObject savedBindingSelf = block.getBinding().getSelf();
IRubyObject savedFrameSelf = block.getBinding().getFrame().getSelf();
Visibility savedVisibility = block.getBinding().getVisibility();
block.getBinding().setVisibility(PUBLIC);

Expand All @@ -1738,6 +1744,8 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,
return (IRubyObject) bj.getValue();
} finally {
block.getBinding().setVisibility(savedVisibility);
block.getBinding().setSelf(savedBindingSelf);
block.getBinding().getFrame().setSelf(savedFrameSelf);

context.postExecuteUnder();
}
Expand Down
9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/RubyClassPathVariable.java
Expand Up @@ -66,10 +66,15 @@ public IRubyObject append(ThreadContext context, IRubyObject obj) {
paths = context.runtime.newArray(obj).toJavaArray();
}

boolean is1_8 = context.getRuntime().is1_8();
for (IRubyObject path: paths) {
String ss = path.convertToString().toString();
try {
URL url = getURL(ss);
URL url = getURL(path.convertToString().toString());
if (url.getProtocol().equals("file")) {
path = is1_8 ? RubyFile.expand_path(context, null, new IRubyObject[]{ path })
: RubyFile.expand_path19(context, null, new IRubyObject[]{ path });
url = getURL(path.convertToString().toString());
}
getRuntime().getJRubyClassLoader().addURL(url);
} catch (MalformedURLException mue) {
throw getRuntime().newArgumentError(mue.getLocalizedMessage());
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/org/jruby/RubyFile.java
Expand Up @@ -934,7 +934,10 @@ public static IRubyObject rename(ThreadContext context, IRubyObject recv, IRubyO
JRubyFile oldFile = JRubyFile.create(runtime.getCurrentDirectory(), oldNameJavaString);
JRubyFile newFile = JRubyFile.create(runtime.getCurrentDirectory(), newNameJavaString);

if (!oldFile.exists() || !newFile.getParentFile().exists()) {
boolean isOldSymlink = RubyFileTest.symlink_p(recv, oldNameString).isTrue();
// Broken symlinks considered by exists() as non-existing,
// so we need to check for symlinks explicitly.
if (!(oldFile.exists() || isOldSymlink) || !newFile.getParentFile().exists()) {
throw runtime.newErrnoENOENTError(oldNameJavaString + " or " + newNameJavaString);
}

Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/RubyFileTest.java
Expand Up @@ -197,8 +197,7 @@ public static IRubyObject readable_p(ThreadContext context, IRubyObject recv, IR
filename = get_path(context, filename);
}

FileStat stat = fileResource(filename).stat();
return runtime.newBoolean(stat != null && stat.isReadable());
return runtime.newBoolean(fileResource(filename).canRead());
}

// Not exposed by filetest, but so similiar in nature that it is stored here
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyThread.java
Expand Up @@ -1259,10 +1259,10 @@ public <Data, Return> Return executeTask(ThreadContext context, Data data, Task<
this.unblockFunc = task;
this.unblockArg = data;

enterSleep();

// check for interrupt before going into blocking call
context.pollThreadEvents();
pollThreadEvents(context);

enterSleep();

return task.run(context, data);
} finally {
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/ast/DXStrNode.java
Expand Up @@ -31,6 +31,7 @@
***** END LICENSE BLOCK *****/
package org.jruby.ast;

import org.jcodings.Encoding;
import org.jruby.ast.types.ILiteralNode;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
Expand All @@ -44,6 +45,10 @@ public DXStrNode(ISourcePosition position, DStrNode node) {
super(position);
addAll(node);
}

public DXStrNode(ISourcePosition position, Encoding encoding) {
super(position, encoding);
}

public DXStrNode(ISourcePosition position) {
super(position);
Expand Down
56 changes: 41 additions & 15 deletions core/src/main/java/org/jruby/ext/ffi/Enum.java
Expand Up @@ -30,7 +30,7 @@

import java.util.IdentityHashMap;
import java.util.Map;
import org.jcodings.util.IntHash;
import java.util.concurrent.ConcurrentHashMap;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.Ruby;
Expand All @@ -52,12 +52,12 @@
*/
@JRubyClass(name="FFI::Enum", parent="Object")
public final class Enum extends RubyObject {
private final IRubyObject nativeType;
private IRubyObject nativeType;
private final RubyHash kv_map;
private volatile IRubyObject tag;

private volatile Map<RubySymbol, RubyInteger> symbolToValue = new IdentityHashMap<RubySymbol, RubyInteger>();
private volatile IntHash<RubySymbol> valueToSymbol = new IntHash<RubySymbol>();
private volatile ConcurrentHashMap<Long, RubySymbol> valueToSymbol = new ConcurrentHashMap<Long, RubySymbol>();

public static RubyClass createEnumClass(Ruby runtime, RubyModule ffiModule) {
RubyClass enumClass = ffiModule.defineClassUnder("Enum", runtime.getObject(),
Expand All @@ -79,27 +79,53 @@ public final IRubyObject allocate(Ruby runtime, RubyClass klass) {

private Enum(Ruby runtime, RubyClass klass) {
super(runtime, klass);
nativeType = runtime.getModule("FFI").getClass("Type").getConstant("INT");
kv_map = RubyHash.newHash(runtime);
tag = runtime.getNil();
}

@JRubyMethod(name = "initialize", visibility = Visibility.PRIVATE)
public final IRubyObject initialize(ThreadContext context, IRubyObject values, IRubyObject tag) {
this.tag = tag;
return initialize(context, values);
public final IRubyObject initialize(ThreadContext context, IRubyObject arg) {
return initialize(context, null, null, arg);
}

@JRubyMethod(name = "initialize", visibility = Visibility.PRIVATE)
public final IRubyObject initialize(ThreadContext context, IRubyObject values) {
public final IRubyObject initialize(ThreadContext context, IRubyObject arg0, IRubyObject arg1) {
if (arg0 instanceof org.jruby.ext.ffi.Type)
return initialize(context, arg0, arg1, null);

if (arg1.isNil())
return initialize(context, null, arg0, null);

// Handles bad args and tag, values case.
return initialize(context, null, arg0, arg1);
}

@JRubyMethod(name = "initialize", visibility = Visibility.PRIVATE)
public final IRubyObject initialize(ThreadContext context, IRubyObject type, IRubyObject values, IRubyObject tag) {
int offset = 0;
if (type instanceof org.jruby.ext.ffi.Type) {
nativeType = type;
} else {
if (!(type == null || type.isNil()))
throw context.runtime.newTypeError(type, context.runtime.getModule("FFI").getClass("Type"));

nativeType = context.runtime.getModule("FFI").getClass("Type").getConstant("INT");
}

if (!(tag == null || tag.isNil() || tag instanceof RubySymbol))
throw context.runtime.newTypeError(tag, context.runtime.getSymbol());

this.tag = tag;

if (!(values instanceof RubyArray)) {
throw context.runtime.newTypeError(values, context.runtime.getArray());
}

RubyArray ary = (RubyArray) values;

Map<RubySymbol, RubyInteger> s2v = new IdentityHashMap<RubySymbol, RubyInteger>();
IRubyObject prevConstant = null;
int nextValue = 0;
long nextValue = 0;

for (int i = 0; i < ary.size(); i++) {
IRubyObject v = ary.entry(i);
Expand All @@ -109,24 +135,24 @@ public final IRubyObject initialize(ThreadContext context, IRubyObject values) {
prevConstant = v;
nextValue++;

} else if (v instanceof RubyFixnum) {
} else if (v instanceof RubyInteger) {
if (prevConstant == null) {
throw context.runtime.newArgumentError("invalid enum sequence - no symbol for value "
+ v);
}
s2v.put((RubySymbol) prevConstant, (RubyFixnum) v);
nextValue = (int) ((RubyInteger) v).getLongValue() + 1;
nextValue = ((RubyInteger) v).getLongValue() + 1;

} else {
throw context.runtime.newTypeError(v, context.runtime.getSymbol());
}
}

symbolToValue = new IdentityHashMap<RubySymbol, RubyInteger>(s2v);
valueToSymbol = new IntHash<RubySymbol>(symbolToValue.size());
valueToSymbol = new ConcurrentHashMap<Long, RubySymbol>(symbolToValue.size());
for (Map.Entry<RubySymbol, RubyInteger> e : symbolToValue.entrySet()) {
kv_map.fastASet(e.getKey(), e.getValue());
valueToSymbol.put((int) e.getValue().getLongValue(), e.getKey());
valueToSymbol.put(e.getValue().getLongValue(), e.getKey());
}

return this;
Expand All @@ -139,7 +165,7 @@ public final IRubyObject find(ThreadContext context, IRubyObject query) {
return value != null ? value : context.runtime.getNil();

} else if (query instanceof RubyInteger) {
RubySymbol symbol = valueToSymbol.get((int) ((RubyInteger) query).getLongValue());
RubySymbol symbol = valueToSymbol.get((Long)((RubyInteger) query).getLongValue());
return symbol != null ? symbol : context.runtime.getNil();

} else {
Expand Down Expand Up @@ -194,7 +220,7 @@ public final IRubyObject from_native(ThreadContext context, IRubyObject value, I

RubySymbol sym;

if (value instanceof RubyInteger && (sym = valueToSymbol.get((int) ((RubyInteger) value).getLongValue())) != null) {
if (value instanceof RubyInteger && (sym = valueToSymbol.get((Long)((RubyInteger) value).getLongValue())) != null) {
return sym;
}

Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/ext/ffi/Enums.java
Expand Up @@ -93,7 +93,9 @@ public IRubyObject append(final ThreadContext context, IRubyObject item){
}
allEnums.append(item);
if (!(item == null || item == context.nil)){
taggedEnums.fastASet(((Enum)item).tag(context), item);
IRubyObject tag = ((Enum)item).tag(context);
if (tag != null && !tag.isNil())
taggedEnums.fastASet(tag, item);
}
symbolMap.merge_bang(context, ((Enum)item).symbol_map(context), Block.NULL_BLOCK);
return item;
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/Frame.java
Expand Up @@ -253,7 +253,7 @@ public String getName() {
*
* @return The self for the frame
*/
IRubyObject getSelf() {
public IRubyObject getSelf() {
return self;
}

Expand Down
22 changes: 22 additions & 0 deletions core/src/main/java/org/jruby/runtime/callsite/CachingCallSite.java
Expand Up @@ -65,6 +65,8 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject... args) {
RubyClass selfType = getClass(self);
// This must be retrieved *once* to avoid racing with other threads.
CacheEntry cache = this.cache;
if (CacheEntry.typeOk(cache, selfType)) {
return cache.method.call(context, self, selfType, methodName, args);
}
Expand All @@ -73,6 +75,8 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

private IRubyObject callBlock(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject[] args, Block block) {
RubyClass selfType = getClass(self);
// This must be retrieved *once* to avoid racing with other threads.
CacheEntry cache = this.cache;
if (CacheEntry.typeOk(cache, selfType)) {
return cache.method.call(context, self, selfType, methodName, args, block);
}
Expand Down Expand Up @@ -123,6 +127,8 @@ public IRubyObject callVarargsIter(ThreadContext context, IRubyObject caller, IR

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self) {
RubyClass selfType = getClass(self);
// This must be retrieved *once* to avoid racing with other threads.
CacheEntry cache = this.cache;
if (CacheEntry.typeOk(cache, selfType)) {
return cache.method.call(context, self, selfType, methodName);
}
Expand All @@ -131,6 +137,8 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

private IRubyObject callBlock(ThreadContext context, IRubyObject caller, IRubyObject self, Block block) {
RubyClass selfType = getClass(self);
// This must be retrieved *once* to avoid racing with other threads.
CacheEntry cache = this.cache;
if (CacheEntry.typeOk(cache, selfType)) {
return cache.method.call(context, self, selfType, methodName, block);
}
Expand All @@ -151,6 +159,8 @@ public IRubyObject callIter(ThreadContext context, IRubyObject caller, IRubyObje

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1) {
RubyClass selfType = getClass(self);
// This must be retrieved *once* to avoid racing with other threads.
CacheEntry cache = this.cache;
if (CacheEntry.typeOk(cache, selfType)) {
return cache.method.call(context, self, selfType, methodName, arg1);
}
Expand All @@ -159,6 +169,8 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

private IRubyObject callBlock(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1, Block block) {
RubyClass selfType = getClass(self);
// This must be retrieved *once* to avoid racing with other threads.
CacheEntry cache = this.cache;
if (CacheEntry.typeOk(cache, selfType)) {
return cache.method.call(context, self, selfType, methodName, arg1, block);
}
Expand All @@ -179,6 +191,8 @@ public IRubyObject callIter(ThreadContext context, IRubyObject caller, IRubyObje

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1, IRubyObject arg2) {
RubyClass selfType = getClass(self);
// This must be retrieved *once* to avoid racing with other threads.
CacheEntry cache = this.cache;
if (CacheEntry.typeOk(cache, selfType)) {
return cache.method.call(context, self, selfType, methodName, arg1, arg2);
}
Expand All @@ -187,6 +201,8 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

private IRubyObject callBlock(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1, IRubyObject arg2, Block block) {
RubyClass selfType = getClass(self);
// This must be retrieved *once* to avoid racing with other threads.
CacheEntry cache = this.cache;
if (CacheEntry.typeOk(cache, selfType)) {
return cache.method.call(context, self, selfType, methodName, arg1, arg2, block);
}
Expand All @@ -207,6 +223,8 @@ public IRubyObject callIter(ThreadContext context, IRubyObject caller, IRubyObje

public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3) {
RubyClass selfType = getClass(self);
// This must be retrieved *once* to avoid racing with other threads.
CacheEntry cache = this.cache;
if (CacheEntry.typeOk(cache, selfType)) {
return cache.method.call(context, self, selfType, methodName, arg1, arg2, arg3);
}
Expand All @@ -215,6 +233,8 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s

private IRubyObject callBlock(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, Block block) {
RubyClass selfType = getClass(self);
// This must be retrieved *once* to avoid racing with other threads.
CacheEntry cache = this.cache;
if (CacheEntry.typeOk(cache, selfType)) {
return cache.method.call(context, self, selfType, methodName, arg1, arg2, arg3, block);
}
Expand All @@ -234,6 +254,8 @@ public IRubyObject callIter(ThreadContext context, IRubyObject caller, IRubyObje
}

public CacheEntry retrieveCache(RubyClass selfType, String methodName) {
// This must be retrieved *once* to avoid racing with other threads.
CacheEntry cache = this.cache;
if (CacheEntry.typeOk(cache, selfType)) {
return cache;
}
Expand Down

0 comments on commit e2a3b8c

Please sign in to comment.