Skip to content

Commit

Permalink
Merge PR #288: Blocking primitives cannot participate in safepoints
Browse files Browse the repository at this point in the history
  • Loading branch information
smarr committed Jan 16, 2019
2 parents 8f0ee2c + 35c908d commit f4006fb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/som/interpreter/processes/SChannel.java
Expand Up @@ -4,6 +4,7 @@

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;

import som.interpreter.objectstorage.ObjectTransitionSafepoint;
import som.primitives.processes.ChannelPrimitives;
import som.vm.VmSettings;
import som.vmobjects.SAbstractObject;
Expand Down Expand Up @@ -78,7 +79,12 @@ public SChannelInput(final SynchronousQueue<Object> cell,

@TruffleBoundary
public Object read() throws InterruptedException {
return cell.take();
ObjectTransitionSafepoint.INSTANCE.unregister();
try {
return cell.take();
} finally {
ObjectTransitionSafepoint.INSTANCE.register();
}
}

public final Object readAndSuspendWriter(final boolean doSuspend)
Expand Down Expand Up @@ -123,7 +129,12 @@ protected SChannelOutput(final SynchronousQueue<Object> cell, final SChannel cha

@TruffleBoundary
public void write(final Object value) throws InterruptedException {
cell.put(value);
ObjectTransitionSafepoint.INSTANCE.unregister();
try {
cell.put(value);
} finally {
ObjectTransitionSafepoint.INSTANCE.register();
}
}

public final void writeAndSuspendReader(final Object value,
Expand Down
8 changes: 7 additions & 1 deletion src/som/primitives/ActivityJoin.java
Expand Up @@ -10,6 +10,7 @@
import bd.primitives.Primitive;
import som.interpreter.actors.SuspendExecutionNodeGen;
import som.interpreter.nodes.nary.UnaryExpressionNode;
import som.interpreter.objectstorage.ObjectTransitionSafepoint;
import som.primitives.threading.TaskThreads.SomTaskOrThread;
import som.vm.VmSettings;
import tools.concurrency.KomposTrace;
Expand Down Expand Up @@ -38,7 +39,12 @@ public final JoinPrim initialize(final SourceSection source) {

@TruffleBoundary
private static Object doJoin(final SomTaskOrThread task) {
return task.join();
try {
ObjectTransitionSafepoint.INSTANCE.unregister();
return task.join();
} finally {
ObjectTransitionSafepoint.INSTANCE.register();
}
}

@Specialization
Expand Down
15 changes: 12 additions & 3 deletions src/som/primitives/threading/ConditionPrimitives.java
Expand Up @@ -10,6 +10,7 @@
import bd.primitives.Primitive;
import som.interpreter.nodes.nary.BinaryExpressionNode;
import som.interpreter.nodes.nary.UnaryExpressionNode;
import som.interpreter.objectstorage.ObjectTransitionSafepoint;


public final class ConditionPrimitives {
Expand Down Expand Up @@ -42,10 +43,13 @@ public abstract static class AwaitPrim extends UnaryExpressionNode {
@TruffleBoundary
public final Condition doCondition(final Condition cond) {
try {
ObjectTransitionSafepoint.INSTANCE.unregister();
cond.await();
} catch (InterruptedException e) {
/* doesn't tell us a lot at the moment, so it is ignored */
}

ObjectTransitionSafepoint.INSTANCE.register();
return cond;
}
}
Expand All @@ -57,9 +61,14 @@ public abstract static class AwaitForPrim extends BinaryExpressionNode {
@TruffleBoundary
public final boolean doCondition(final Condition cond, final long milliseconds) {
try {
return cond.await(milliseconds, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
return false;
ObjectTransitionSafepoint.INSTANCE.unregister();
try {
return cond.await(milliseconds, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
return false;
}
} finally {
ObjectTransitionSafepoint.INSTANCE.register();
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/som/primitives/threading/DelayPrimitives.java
Expand Up @@ -6,6 +6,7 @@

import bd.primitives.Primitive;
import som.interpreter.nodes.nary.UnaryExpressionNode;
import som.interpreter.objectstorage.ObjectTransitionSafepoint;
import som.vm.constants.Nil;
import som.vmobjects.SObjectWithClass.SObjectWithoutFields;

Expand All @@ -18,10 +19,12 @@ public abstract static class WaitPrim extends UnaryExpressionNode {
@TruffleBoundary
public final SObjectWithoutFields doLong(final long milliseconds) {
try {
ObjectTransitionSafepoint.INSTANCE.unregister();
Thread.sleep(milliseconds);
} catch (InterruptedException e) {
/* Not relevant for the moment */
}
ObjectTransitionSafepoint.INSTANCE.register();
return Nil.nilObject;
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/som/primitives/threading/MutexPrimitives.java
Expand Up @@ -13,6 +13,7 @@
import som.interpreter.nodes.dispatch.BlockDispatchNodeGen;
import som.interpreter.nodes.nary.BinaryExpressionNode;
import som.interpreter.nodes.nary.UnaryExpressionNode;
import som.interpreter.objectstorage.ObjectTransitionSafepoint;
import som.vmobjects.SBlock;
import som.vmobjects.SClass;
import tools.concurrency.Tags.AcquireLock;
Expand All @@ -27,7 +28,12 @@ public abstract static class LockPrim extends UnaryExpressionNode {
@TruffleBoundary
@Specialization
public static final ReentrantLock lock(final ReentrantLock lock) {
lock.lock();
try {
ObjectTransitionSafepoint.INSTANCE.unregister();
lock.lock();
} finally {
ObjectTransitionSafepoint.INSTANCE.register();
}
return lock;
}

Expand Down

0 comments on commit f4006fb

Please sign in to comment.