Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 368758e05b9e
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 689f75a21918
Choose a head ref
  • 2 commits
  • 9 files changed
  • 1 contributor

Commits on Mar 22, 2015

  1. Copy the full SHA
    f160800 View commit details
  2. Copy the full SHA
    689f75a View commit details
4 changes: 0 additions & 4 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -145,10 +145,6 @@ public RubyModule executeRubyModule(VirtualFrame frame) throws UnexpectedResultE
return RubyTypesGen.RUBYTYPES.expectRubyModule(execute(frame));
}

public RubyMutex executeRubyMutex(VirtualFrame frame) throws UnexpectedResultException {
return RubyTypesGen.RUBYTYPES.expectRubyMutex(execute(frame));
}

public RubyNilClass executeRubyNilClass(VirtualFrame frame) throws UnexpectedResultException {
return RubyTypesGen.RUBYTYPES.expectRubyNilClass(execute(frame));
}
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@
RubyHash.class, //
RubyMatchData.class, //
RubyModule.class, //
RubyMutex.class, //
RubyNilClass.class, //
RubyProc.class, //
RubyRange.class, //
73 changes: 60 additions & 13 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/MutexNodes.java
Original file line number Diff line number Diff line change
@@ -11,9 +11,12 @@

import java.util.concurrent.locks.ReentrantLock;

import com.oracle.truffle.api.object.HiddenKey;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode;
import org.jruby.truffle.nodes.objectstorage.WriteHeadObjectFieldNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyMutex;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyThread;
import org.jruby.truffle.runtime.subsystems.ThreadManager.BlockingActionWithoutGlobalLock;

@@ -24,20 +27,49 @@
@CoreClass(name = "Mutex")
public abstract class MutexNodes {

private static final HiddenKey LOCK_IDENTIFIER = new HiddenKey("lock");

@CoreMethod(names = "initialize")
public abstract static class InitializeNode extends UnaryCoreMethodNode {

@Child private WriteHeadObjectFieldNode writeLock;

public InitializeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
writeLock = new WriteHeadObjectFieldNode(LOCK_IDENTIFIER);
}

public InitializeNode(InitializeNode prev) {
super(prev);
writeLock = prev.writeLock;
}

@Specialization
public RubyBasicObject lock(RubyBasicObject mutex) {
writeLock.execute(mutex, new ReentrantLock());
return mutex;
}

}

@CoreMethod(names = "lock")
public abstract static class LockNode extends UnaryCoreMethodNode {

@Child private ReadHeadObjectFieldNode readLock;

public LockNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readLock = new ReadHeadObjectFieldNode(LOCK_IDENTIFIER);
}

public LockNode(LockNode prev) {
super(prev);
readLock = prev.readLock;
}

@Specialization
public RubyMutex lock(RubyMutex mutex) {
final ReentrantLock lock = mutex.getReentrantLock();
public RubyBasicObject lock(RubyBasicObject mutex) {
final ReentrantLock lock = (ReentrantLock) readLock.execute(mutex);

if (lock.isHeldByCurrentThread()) {
CompilerDirectives.transferToInterpreter();
@@ -63,18 +95,21 @@ public Boolean block() throws InterruptedException {
@CoreMethod(names = "locked?")
public abstract static class IsLockedNode extends UnaryCoreMethodNode {

@Child private ReadHeadObjectFieldNode readLock;

public IsLockedNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readLock = new ReadHeadObjectFieldNode(LOCK_IDENTIFIER);
}

public IsLockedNode(IsLockedNode prev) {
super(prev);
readLock = prev.readLock;
}

@Specialization
public boolean isLocked(RubyMutex mutex) {
final ReentrantLock lock = mutex.getReentrantLock();

public boolean isLocked(RubyBasicObject mutex) {
final ReentrantLock lock = (ReentrantLock) readLock.execute(mutex);
return lock.isLocked();
}

@@ -83,18 +118,21 @@ public boolean isLocked(RubyMutex mutex) {
@CoreMethod(names = "owned?")
public abstract static class IsOwnedNode extends UnaryCoreMethodNode {

@Child private ReadHeadObjectFieldNode readLock;

public IsOwnedNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readLock = new ReadHeadObjectFieldNode(LOCK_IDENTIFIER);
}

public IsOwnedNode(IsOwnedNode prev) {
super(prev);
readLock = prev.readLock;
}

@Specialization
public boolean isOwned(RubyMutex mutex) {
final ReentrantLock lock = mutex.getReentrantLock();

public boolean isOwned(RubyBasicObject mutex) {
final ReentrantLock lock = (ReentrantLock) readLock.execute(mutex);
return lock.isHeldByCurrentThread();
}

@@ -103,17 +141,21 @@ public boolean isOwned(RubyMutex mutex) {
@CoreMethod(names = "try_lock")
public abstract static class TryLockNode extends UnaryCoreMethodNode {

@Child private ReadHeadObjectFieldNode readLock;

public TryLockNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readLock = new ReadHeadObjectFieldNode(LOCK_IDENTIFIER);
}

public TryLockNode(TryLockNode prev) {
super(prev);
readLock = prev.readLock;
}

@Specialization
public boolean tryLock(RubyMutex mutex) {
final ReentrantLock lock = mutex.getReentrantLock();
public boolean tryLock(RubyBasicObject mutex) {
final ReentrantLock lock = (ReentrantLock) readLock.execute(mutex);

if (lock.isHeldByCurrentThread()) {
return false;
@@ -133,17 +175,22 @@ public boolean tryLock(RubyMutex mutex) {
@CoreMethod(names = "unlock")
public abstract static class UnlockNode extends UnaryCoreMethodNode {

@Child private ReadHeadObjectFieldNode readLock;

public UnlockNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readLock = new ReadHeadObjectFieldNode(LOCK_IDENTIFIER);
}

public UnlockNode(UnlockNode prev) {
super(prev);
readLock = prev.readLock;
}

@Specialization
public RubyMutex unlock(RubyMutex mutex) {
final ReentrantLock lock = mutex.getReentrantLock();
public RubyBasicObject unlock(RubyBasicObject mutex) {
final ReentrantLock lock = (ReentrantLock) readLock.execute(mutex);

final RubyThread thread = getContext().getThreadManager().getCurrentThread();

try {
Original file line number Diff line number Diff line change
@@ -14,15 +14,13 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.core.FixnumOrBignumNode;
import org.jruby.truffle.nodes.objects.IsTaintedNode;
import org.jruby.truffle.nodes.objects.IsTaintedNodeFactory;
import org.jruby.truffle.nodes.objects.TaintNode;
import org.jruby.truffle.nodes.objects.TaintNodeFactory;
import org.jruby.truffle.runtime.ObjectIDOperations;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyNilClass;

/**
@@ -95,7 +93,8 @@ public Object objectID(double value) {

@Specialization
public long objectID(RubyBasicObject object) {
return object.getObjectID();
// TODO: CS 22-Mar-15 need to write this using nodes
return object.verySlowGetObjectID();
}

protected boolean isSmallFixnum(long fixnum) {
Original file line number Diff line number Diff line change
@@ -272,7 +272,7 @@ public CoreLibrary(RubyContext context) {
hashClass = defineClass("Hash", new RubyHash.HashAllocator());
matchDataClass = defineClass("MatchData");
methodClass = defineClass("Method");
defineClass("Mutex", new RubyMutex.MutexAllocator());
defineClass("Mutex");
nilClass = defineClass("NilClass");
procClass = defineClass("Proc", new RubyProc.ProcAllocator());
processModule = defineModule("Process");
Original file line number Diff line number Diff line change
@@ -110,7 +110,7 @@ public RubyClass getSingletonClass(Node currentNode) {
}

metaClass = RubyClass.createSingletonClassOfObject(getContext(), logicalClass, attached,
String.format("#<Class:#<%s:0x%x>>", logicalClass.getName(), getObjectID()));
String.format("#<Class:#<%s:0x%x>>", logicalClass.getName(), verySlowGetObjectID()));

if (DebugOperations.verySlowIsFrozen(this)) {
DebugOperations.verySlowFreeze(metaClass);
@@ -120,7 +120,7 @@ public RubyClass getSingletonClass(Node currentNode) {
}

@CompilerDirectives.TruffleBoundary
public long getObjectID() {
public long verySlowGetObjectID() {
// TODO(CS): we should specialise on reading this in the #object_id method and anywhere else it's used
Property property = dynamicObject.getShape().getProperty(OBJECT_ID_IDENTIFIER);

Original file line number Diff line number Diff line change
@@ -353,7 +353,7 @@ public String getName() {
if (name != null) {
return name;
} else {
return "#<" + logicalClass.getName() + ":0x" + Long.toHexString(getObjectID()) + ">";
return "#<" + logicalClass.getName() + ":0x" + Long.toHexString(verySlowGetObjectID()) + ">";
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.core.RubyThread;
import org.jruby.truffle.runtime.subsystems.ThreadManager.BlockingActionWithoutGlobalLock;
import org.jruby.truffle.runtime.util.Consumer;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -156,7 +155,7 @@ public Map<Long, RubyBasicObject> collectLiveObjects() {

@Override
public boolean visit(RubyBasicObject object) {
return liveObjects.put(object.getObjectID(), object) == null;
return liveObjects.put(object.verySlowGetObjectID(), object) == null;
}

};