Skip to content

Commit

Permalink
Integrate feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
daumayr committed Oct 24, 2018
1 parent fc63e8b commit 8e4cd2e
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 187 deletions.
3 changes: 1 addition & 2 deletions core-lib/TestSuite/Serialization.ns
Expand Up @@ -19,8 +19,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*)
class SerializationTests usingPlatform: platform testFramework: minitest = Value(
| private TestContext = minitest TestContext.
private AsyncTestContext = minitest AsyncTestContext.
| private AsyncTestContext = minitest AsyncTestContext.
private actors = platform actors.
private String = platform kernel String.
private Array = platform kernel Array.
Expand Down
11 changes: 6 additions & 5 deletions src/som/interpreter/actors/EventualMessage.java
Expand Up @@ -2,6 +2,7 @@

import java.util.Arrays;

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.source.SourceSection;

Expand Down Expand Up @@ -215,10 +216,10 @@ public boolean getHaltOnPromiseMessageResolution() {
* after the promise is resolved.
*/
public abstract static class AbstractPromiseSendMessage extends PromiseMessage {
private final SSymbol selector;
protected Actor target;
protected Actor finalSender;
protected SPromise originalTarget;
private final SSymbol selector;
protected Actor target;
protected Actor finalSender;
@CompilationFinal protected SPromise originalTarget;

protected AbstractPromiseSendMessage(final SSymbol selector,
final Object[] arguments, final Actor originalSender,
Expand Down Expand Up @@ -308,7 +309,7 @@ public abstract static class AbstractPromiseCallbackMessage extends PromiseMessa
/**
* The promise on which this callback is registered on.
*/
protected SPromise promise;
@CompilationFinal protected SPromise promise;

protected AbstractPromiseCallbackMessage(final Actor owner, final SBlock callback,
final SResolver resolver, final RootCallTarget onReceive,
Expand Down
12 changes: 6 additions & 6 deletions src/som/interpreter/actors/SPromise.java
Expand Up @@ -304,37 +304,37 @@ public int getNumOnError() {
}
}

/** Do not use for things other than serializing Promises */
/** Do not use for things other than serializing Promises. */
public PromiseMessage getWhenResolved() {
assert VmSettings.SNAPSHOTS_ENABLED;
return whenResolved;
}

/** Do not use for things other than serializing Promises */
/** Do not use for things other than serializing Promises. */
public ArrayList<PromiseMessage> getWhenResolvedExt() {
assert VmSettings.SNAPSHOTS_ENABLED;
return whenResolvedExt;
}

/** Do not use for things other than serializing Promises */
/** Do not use for things other than serializing Promises. */
public PromiseMessage getOnError() {
assert VmSettings.SNAPSHOTS_ENABLED;
return onError;
}

/** Do not use for things other than serializing Promises */
/** Do not use for things other than serializing Promises. */
public ArrayList<PromiseMessage> getOnErrorExt() {
assert VmSettings.SNAPSHOTS_ENABLED;
return onErrorExt;
}

/** Do not use for things other than serializing Promises */
/** Do not use for things other than serializing Promises. */
public SPromise getChainedPromise() {
assert VmSettings.SNAPSHOTS_ENABLED;
return chainedPromise;
}

/** Do not use for things other than serializing Promises */
/** Do not use for things other than serializing Promises. */
public ArrayList<SPromise> getChainedPromiseExt() {
assert VmSettings.SNAPSHOTS_ENABLED;
return chainedPromiseExt;
Expand Down
Expand Up @@ -100,7 +100,7 @@ public void installFixup(final FixupInformation fi) {

private void fixUpIfNecessary(final long reference, final Object result) {
Object ref = deserialized.get(reference);
if (ref != null && ref instanceof FixupList) {
if (ref instanceof FixupList) {
// we have fixup information, this means that this object is part of a circular
// relationship
for (FixupInformation fi : (FixupList) ref) {
Expand Down
74 changes: 38 additions & 36 deletions src/tools/snapshot/nodes/BlockSerializationNode.java
Expand Up @@ -139,43 +139,45 @@ public Object deserialize(final DeserializationBuffer bb) {
MaterializedFrame frame = Truffle.getRuntime().createMaterializedFrame(args, fd);

int numSlots = bb.get();
assert numSlots == fd.getSlots().size();

for (int i = 0; i < numSlots; i++) {
FrameSlot slot = fd.getSlots().get(i);

Object o = bb.getReference();

if (DeserializationBuffer.needsFixup(o)) {
bb.installFixup(new FrameSlotFixup(frame, slot));
} else {

switch (fd.getFrameSlotKind(slot)) {
case Boolean:
frame.setBoolean(slot, (boolean) o);
break;
case Double:
frame.setDouble(slot, (double) o);
break;
case Long:
frame.setLong(slot, (long) o);
break;
case Object:
if (slot.getIdentifier() instanceof Internal) {
FrameOnStackMarker fosm = new FrameOnStackMarker();
if (!(boolean) o) {
fosm.frameNoLongerOnStack();
if (numSlots > 0) {
assert numSlots == fd.getSlots().size();

for (int i = 0; i < numSlots; i++) {
FrameSlot slot = fd.getSlots().get(i);

Object o = bb.getReference();

if (DeserializationBuffer.needsFixup(o)) {
bb.installFixup(new FrameSlotFixup(frame, slot));
} else {

switch (fd.getFrameSlotKind(slot)) {
case Boolean:
frame.setBoolean(slot, (boolean) o);
break;
case Double:
frame.setDouble(slot, (double) o);
break;
case Long:
frame.setLong(slot, (long) o);
break;
case Object:
if (slot.getIdentifier() instanceof Internal) {
FrameOnStackMarker fosm = new FrameOnStackMarker();
if (!(boolean) o) {
fosm.frameNoLongerOnStack();
}
o = fosm;
}
o = fosm;
}
frame.setObject(slot, o);
break;
case Illegal:
// uninitialized variable, uses default
frame.setObject(slot, o);
break;
default:
throw new IllegalArgumentException("Unexpected SlotKind");
frame.setObject(slot, o);
break;
case Illegal:
// uninitialized variable, uses default
frame.setObject(slot, o);
break;
default:
throw new IllegalArgumentException("Unexpected SlotKind");
}
}
}
}
Expand Down
189 changes: 102 additions & 87 deletions src/tools/snapshot/nodes/MessageSerializationNode.java
Expand Up @@ -96,8 +96,7 @@ protected final void doArguments(final Object[] args, final int base,
}

/**
*
* Takes 7 bytes in the buffer
* Takes 7 bytes in the buffer.
*/
protected final void doCommonalities(final MessageType type, final SSymbol selector,
final TracingActor sender, final int base,
Expand Down Expand Up @@ -297,110 +296,126 @@ public EventualMessage deserialize(final DeserializationBuffer bb) {
MessageType type = MessageType.getMessageType(bb.get());
SSymbol selector = SnapshotBackend.getSymbolForId(bb.getShort());
Actor sender = SnapshotBackend.lookupActor(bb.getInt());
SResolver resolver = null;

if (type == MessageType.DirectMessage || type == MessageType.CallbackMessage
|| type == MessageType.PromiseMessage
|| type == MessageType.UndeliveredPromiseMessage) {
resolver = (SResolver) bb.getReference();
}

Object[] args;
SPromise prom;
Object promObj;
PromiseMessageFixup pmf = null;
switch (type) {
case CallbackMessage:
return deserializeCallback(selector, sender, bb, (SResolver) bb.getReference());
case CallbackMessageNR:
promObj = bb.getReference();
return deserializeCallback(selector, sender, bb, null);
case DirectMessage:
return deserializeDirect(selector, sender, bb, (SResolver) bb.getReference());
case DirectMessageNR:
return deserializeDirect(selector, sender, bb, null);
case PromiseMessage:
return deserializeDelivered(selector, sender, bb, (SResolver) bb.getReference());
case PromiseMessageNR:
return deserializeDelivered(selector, sender, bb, null);
case UndeliveredPromiseMessage:
return deserializeUndelivered(selector, sender, bb, (SResolver) bb.getReference());
case UndeliveredPromiseMessageNR:
return deserializeUndelivered(selector, sender, bb, null);
default:
throw new UnsupportedOperationException();
}
}

if (DeserializationBuffer.needsFixup(promObj)) {
pmf = new PromiseMessageFixup();
bb.installFixup(pmf);
prom = null;
} else {
prom = (SPromise) promObj;
}
args = parseArguments(bb);
private PromiseCallbackMessage deserializeCallback(final SSymbol selector,
final Actor sender, final DeserializationBuffer bb, final SResolver resolver) {

RootCallTarget onReceive = PromisePrims.createReceived((SBlock) args[0]);
PromiseCallbackMessage pcm =
new PromiseCallbackMessage(sender, (SBlock) args[0], resolver,
onReceive, false, false, prom);
PromiseMessageFixup pmf = null;
SPromise prom = null;

Object promObj = bb.getReference();
if (DeserializationBuffer.needsFixup(promObj)) {
pmf = new PromiseMessageFixup();
bb.installFixup(pmf);
} else {
prom = (SPromise) promObj;
}
Object[] args = parseArguments(bb);

if (pmf != null) {
pmf.setMessage(pcm);
}
RootCallTarget onReceive = PromisePrims.createReceived((SBlock) args[0]);
PromiseCallbackMessage pcm =
new PromiseCallbackMessage(sender, (SBlock) args[0], resolver,
onReceive, false, false, prom);

// set the remaining arg, i.e. the value passed to the callback block
pcm.getArgs()[1] = args[1];
return pcm;
case DirectMessage:
case DirectMessageNR:
args = parseArguments(bb);
onReceive = EventualSendNode.createOnReceiveCallTarget(selector, null,
SomLanguage.getLanguage(getRootNode()));
if (pmf != null) {
pmf.setMessage(pcm);
}

DirectMessage dm =
new DirectMessage(EventualMessage.getActorCurrentMessageIsExecutionOn(), selector,
args, sender, resolver,
onReceive, false, false);
// set the remaining arg, i.e. the value passed to the callback block
pcm.getArgs()[1] = args[1];
return pcm;
}

return dm;
case PromiseMessage:
case PromiseMessageNR:
promObj = bb.getReference();
private DirectMessage deserializeDirect(final SSymbol selector, final Actor sender,
final DeserializationBuffer bb, final SResolver resolver) {
Object[] args = parseArguments(bb);
RootCallTarget onReceive = EventualSendNode.createOnReceiveCallTarget(selector, null,
SomLanguage.getLanguage(getRootNode()));

if (DeserializationBuffer.needsFixup(promObj)) {
pmf = new PromiseMessageFixup();
bb.installFixup(pmf);
prom = null;
} else {
prom = (SPromise) promObj;
}
DirectMessage dm =
new DirectMessage(EventualMessage.getActorCurrentMessageIsExecutionOn(), selector,
args, sender, resolver,
onReceive, false, false);

Actor finalSender = SnapshotBackend.lookupActor(bb.getInt());
args = parseArguments(bb);
onReceive = EventualSendNode.createOnReceiveCallTarget(selector, null,
SomLanguage.getLanguage(getRootNode()));
return dm;
}

// backup value for resolution.
Object value = args[0];
private PromiseSendMessage deserializeDelivered(final SSymbol selector, final Actor sender,
final DeserializationBuffer bb, final SResolver resolver) {
Object promObj = bb.getReference();
PromiseMessageFixup pmf = null;
SPromise prom = null;

if (!(args[0] instanceof SPromise)) {
// expects args[0] to be a promise, which may not be the case with a circular
// dependency. We therefore use this placeholder as a workaround...
args[0] = SPromise.createPromise(sender, false, false, null);
}
if (DeserializationBuffer.needsFixup(promObj)) {
pmf = new PromiseMessageFixup();
bb.installFixup(pmf);
} else {
prom = (SPromise) promObj;
}

PromiseSendMessage psm =
new PromiseSendMessage(selector, args, sender, resolver, onReceive, false, false);
Actor finalSender = SnapshotBackend.lookupActor(bb.getInt());
Object[] args = parseArguments(bb);
RootCallTarget onReceive = EventualSendNode.createOnReceiveCallTarget(selector, null,
SomLanguage.getLanguage(getRootNode()));

if (pmf != null) {
pmf.setMessage(psm);
}
psm.resolve(value, EventualMessage.getActorCurrentMessageIsExecutionOn(),
finalSender);
// backup value for resolution.
Object value = args[0];

return psm;
case UndeliveredPromiseMessage:
case UndeliveredPromiseMessageNR:
args = parseArguments(bb);
onReceive = EventualSendNode.createOnReceiveCallTarget(selector,
SomLanguage.getSyntheticSource("Deserialized Message", "Trace").createSection(1),
SomLanguage.getLanguage(this.getRootNode()));

if (!(args[0] instanceof SPromise)) {
// expects args[0] to be a promise
args[0] = SPromise.createPromise(sender, false, false, null);
}
args[0] = prom;
if (!(args[0] instanceof SPromise)) {
// expects args[0] to be a promise
args[0] = SPromise.createPromise(sender, false, false, null);
}

psm =
new PromiseSendMessage(selector, args, sender, resolver, onReceive, false, false);
return psm;
default:
throw new UnsupportedOperationException();
PromiseSendMessage psm =
new PromiseSendMessage(selector, args, sender, resolver, onReceive, false, false);

if (pmf != null) {
pmf.setMessage(psm);
}
psm.resolve(value, EventualMessage.getActorCurrentMessageIsExecutionOn(),
finalSender);

return psm;
}

private PromiseSendMessage deserializeUndelivered(final SSymbol selector, final Actor sender,
final DeserializationBuffer bb, final SResolver resolver) {
Object[] args = parseArguments(bb);
RootCallTarget onReceive = EventualSendNode.createOnReceiveCallTarget(selector,
SomLanguage.getSyntheticSource("Deserialized Message", "Trace").createSection(1),
SomLanguage.getLanguage(this.getRootNode()));

if (!(args[0] instanceof SPromise)) {
// expects args[0] to be a promise
args[0] = SPromise.createPromise(sender, false, false, null);
}

PromiseSendMessage psm =
new PromiseSendMessage(selector, args, sender, resolver, onReceive, false, false);
return psm;
}

/**
Expand Down

0 comments on commit 8e4cd2e

Please sign in to comment.