Skip to content

Commit

Permalink
Merge PR #256: Use CompilerDirectives::castExact instead of ValueProf…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
smarr committed Sep 4, 2018
2 parents 42b4d97 + 75b3595 commit e7c95a9
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 94 deletions.
5 changes: 2 additions & 3 deletions src/som/interpreter/actors/TransferObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import som.vm.NotYetImplementedException;
import som.vm.constants.Nil;
import som.vmobjects.SAbstractObject;
import som.vmobjects.SArray;
import som.vmobjects.SArray.PartiallyEmptyArray;
import som.vmobjects.SArray.STransferArray;
import som.vmobjects.SObject;
Expand Down Expand Up @@ -100,7 +99,7 @@ public static STransferArray transfer(final STransferArray arr,
transferMap.put(arr, newObj);

if (newObj.isObjectType()) {
Object[] storage = newObj.getObjectStorage(SArray.ObjectStorageType);
Object[] storage = newObj.getObjectStorage();

for (int i = 0; i < storage.length; i++) {
Object orgObj = storage[i];
Expand All @@ -115,7 +114,7 @@ public static STransferArray transfer(final STransferArray arr,
}
} else if (newObj.isPartiallyEmptyType()) {
PartiallyEmptyArray parr =
newObj.getPartiallyEmptyStorage(SArray.PartiallyEmptyStorageType);
newObj.getPartiallyEmptyStorage();
Object[] storage = parr.getStorage();

for (int i = 0; i < storage.length; i++) {
Expand Down
14 changes: 6 additions & 8 deletions src/som/primitives/SizeAndLengthPrim.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.instrumentation.Tag;
import com.oracle.truffle.api.profiles.ValueProfile;

import bd.primitives.Primitive;
import som.interpreter.nodes.nary.UnaryBasicOperation;
Expand All @@ -18,7 +17,6 @@
@Primitive(primitive = "stringLength:", selector = "length", receiverType = String.class,
inParser = false)
public abstract class SizeAndLengthPrim extends UnaryBasicOperation {
private final ValueProfile storageType = ValueProfile.createClassProfile();

@Override
protected boolean hasTagIgnoringEagerness(final Class<? extends Tag> tag) {
Expand All @@ -31,32 +29,32 @@ protected boolean hasTagIgnoringEagerness(final Class<? extends Tag> tag) {

@Specialization(guards = "receiver.isEmptyType()")
public final long doEmptySArray(final SArray receiver) {
return receiver.getEmptyStorage(storageType);
return receiver.getEmptyStorage();
}

@Specialization(guards = "receiver.isPartiallyEmptyType()")
public final long doPartialEmptySArray(final SArray receiver) {
return receiver.getPartiallyEmptyStorage(storageType).getLength();
return receiver.getPartiallyEmptyStorage().getLength();
}

@Specialization(guards = "receiver.isObjectType()")
public final long doObjectSArray(final SArray receiver) {
return receiver.getObjectStorage(storageType).length;
return receiver.getObjectStorage().length;
}

@Specialization(guards = "receiver.isLongType()")
public final long doLongSArray(final SArray receiver) {
return receiver.getLongStorage(storageType).length;
return receiver.getLongStorage().length;
}

@Specialization(guards = "receiver.isDoubleType()")
public final long doDoubleSArray(final SArray receiver) {
return receiver.getDoubleStorage(storageType).length;
return receiver.getDoubleStorage().length;
}

@Specialization(guards = "receiver.isBooleanType()")
public final long doBooleanSArray(final SArray receiver) {
return receiver.getBooleanStorage(storageType).length;
return receiver.getBooleanStorage().length;
}

public abstract long executeEvaluated(Object receiver);
Expand Down
2 changes: 1 addition & 1 deletion src/som/primitives/StringPrims.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public ExpressionNode initialize(final SourceSection sourceSection,
public final String doString(final SArray chars) {
VM.thisMethodNeedsToBeOptimized(
"Method not yet optimal for compilation, should speculate or use branch profile in the loop");
Object[] storage = chars.getObjectStorage(SArray.ObjectStorageType);
Object[] storage = chars.getObjectStorage();
StringBuilder sb = new StringBuilder(storage.length);
for (Object o : storage) {
if (o instanceof String) {
Expand Down
7 changes: 2 additions & 5 deletions src/som/primitives/SystemPrims.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.ValueProfile;
import com.oracle.truffle.api.source.SourceSection;

import bd.primitives.Primitive;
Expand Down Expand Up @@ -380,8 +379,6 @@ public final boolean doSymbol(final Object obj, final SSymbol name) {
@GenerateNodeFactory
@Primitive(primitive = "systemApply:with:")
public abstract static class ApplyWithPrim extends BinaryComplexOperation {
private final ValueProfile storageType = ValueProfile.createClassProfile();

@Child protected SizeAndLengthPrim size = SizeAndLengthPrimFactory.create(null);
@Child protected ToSomConversion convert = ToSomConversionNodeGen.create(null);

Expand All @@ -391,13 +388,13 @@ public final Object doApply(final TruffleObject fun, final SArray args) {

Object[] arguments;
if (args.isLongType()) {
long[] arr = args.getLongStorage(storageType);
long[] arr = args.getLongStorage();
arguments = new Object[arr.length];
for (int i = 0; i < arr.length; i++) {
arguments[i] = arr[i];
}
} else if (args.isObjectType()) {
arguments = args.getObjectStorage(storageType);
arguments = args.getObjectStorage();
} else {
CompilerDirectives.transferToInterpreter();
throw new NotYetImplementedException();
Expand Down
15 changes: 6 additions & 9 deletions src/som/primitives/arrays/AtPrim.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrumentation.Tag;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.profiles.ValueProfile;
import com.oracle.truffle.api.source.SourceSection;

import bd.primitives.Primitive;
Expand Down Expand Up @@ -65,8 +64,6 @@ public ExpressionNode create(final Object[] arguments,
}
}

private final ValueProfile storageType = ValueProfile.createClassProfile();

@Child protected ExceptionSignalingNode indexOutOfBounds;

public abstract Object execute(VirtualFrame frame, SArray array, long index);
Expand Down Expand Up @@ -97,7 +94,7 @@ private Object triggerException(final SArray arr, final long idx) {

@Specialization(guards = "receiver.isEmptyType()")
public final Object doEmptySArray(final SArray receiver, final long idx) {
if (idx < 1 || idx > receiver.getEmptyStorage(storageType)) {
if (idx < 1 || idx > receiver.getEmptyStorage()) {
return triggerException(receiver, idx);
}
return Nil.nilObject;
Expand All @@ -106,7 +103,7 @@ public final Object doEmptySArray(final SArray receiver, final long idx) {
@Specialization(guards = "receiver.isPartiallyEmptyType()")
public final Object doPartiallyEmptySArray(final SArray receiver, final long idx) {
try {
return receiver.getPartiallyEmptyStorage(storageType).get(idx - 1);
return receiver.getPartiallyEmptyStorage().get(idx - 1);
} catch (IndexOutOfBoundsException e) {
return triggerException(receiver, idx);
}
Expand All @@ -115,7 +112,7 @@ public final Object doPartiallyEmptySArray(final SArray receiver, final long idx
@Specialization(guards = "receiver.isObjectType()")
public final Object doObjectSArray(final SArray receiver, final long idx) {
try {
return receiver.getObjectStorage(storageType)[(int) idx - 1];
return receiver.getObjectStorage()[(int) idx - 1];
} catch (IndexOutOfBoundsException e) {
return triggerException(receiver, idx);
}
Expand All @@ -124,7 +121,7 @@ public final Object doObjectSArray(final SArray receiver, final long idx) {
@Specialization(guards = "receiver.isLongType()")
public final long doLongSArray(final SArray receiver, final long idx) {
try {
return receiver.getLongStorage(storageType)[(int) idx - 1];
return receiver.getLongStorage()[(int) idx - 1];
} catch (IndexOutOfBoundsException e) {
return (long) triggerException(receiver, idx);
}
Expand All @@ -133,7 +130,7 @@ public final long doLongSArray(final SArray receiver, final long idx) {
@Specialization(guards = "receiver.isDoubleType()")
public final double doDoubleSArray(final SArray receiver, final long idx) {
try {
return receiver.getDoubleStorage(storageType)[(int) idx - 1];
return receiver.getDoubleStorage()[(int) idx - 1];
} catch (IndexOutOfBoundsException e) {
return (double) triggerException(receiver, idx);
}
Expand All @@ -142,7 +139,7 @@ public final double doDoubleSArray(final SArray receiver, final long idx) {
@Specialization(guards = "receiver.isBooleanType()")
public final boolean doBooleanSArray(final SArray receiver, final long idx) {
try {
return receiver.getBooleanStorage(storageType)[(int) idx - 1];
return receiver.getBooleanStorage()[(int) idx - 1];
} catch (IndexOutOfBoundsException e) {
return (boolean) triggerException(receiver, idx);
}
Expand Down
25 changes: 11 additions & 14 deletions src/som/primitives/arrays/AtPutPrim.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.instrumentation.Tag;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.profiles.ValueProfile;
import com.oracle.truffle.api.source.SourceSection;

import bd.primitives.Primitive;
Expand Down Expand Up @@ -70,8 +69,6 @@ public ExpressionNode create(final Object[] arguments,
}
}

private final ValueProfile storageType = ValueProfile.createClassProfile();

@Child protected ExceptionSignalingNode indexOutOfBounds;

@Override
Expand Down Expand Up @@ -135,7 +132,7 @@ private Object transitionAndSet(final SMutableArray receiver,

private void setAndPossiblyTransition(final SMutableArray receiver,
final long index, final Object value, final PartiallyEmptyArray.Type expectedType) {
PartiallyEmptyArray storage = receiver.getPartiallyEmptyStorage(storageType);
PartiallyEmptyArray storage = receiver.getPartiallyEmptyStorage();
setValue(index - 1, value, storage);
if (storage.getType() != expectedType) {
storage.setType(PartiallyEmptyArray.Type.OBJECT);
Expand Down Expand Up @@ -181,7 +178,7 @@ public final boolean doEmptySArray(final SMutableArray receiver, final long inde
public final Object doEmptySArray(final SMutableArray receiver, final long index,
final Object value) {
final int idx = (int) index - 1;
int size = receiver.getEmptyStorage(storageType);
int size = receiver.getEmptyStorage();

// if the value is an object, we transition directly to an Object array
Object[] newStorage = new Object[size];
Expand All @@ -199,7 +196,7 @@ public final Object doEmptySArray(final SMutableArray receiver, final long index
public final Object doEmptySArrayWithNil(final SMutableArray receiver, final long index,
final Object value) {
long idx = index - 1;
if (idx < 0 || idx >= receiver.getEmptyStorage(storageType)) {
if (idx < 0 || idx >= receiver.getEmptyStorage()) {
return triggerException(receiver, index);
}
return Nil.nilObject;
Expand Down Expand Up @@ -242,7 +239,7 @@ public final boolean doPartiallyEmptySArray(final SMutableArray receiver, final
public final Object doPartiallyEmptySArrayWithNil(final SMutableArray receiver,
final long index, final Object value) {
long idx = index - 1;
PartiallyEmptyArray storage = receiver.getPartiallyEmptyStorage(storageType);
PartiallyEmptyArray storage = receiver.getPartiallyEmptyStorage();

try {
if (storage.get(idx) != Nil.nilObject) {
Expand Down Expand Up @@ -270,7 +267,7 @@ public final Object doPartiallyEmptySArray(final SMutableArray receiver, final l
public final Object doObjectSArray(final SMutableArray receiver, final long index,
final Object value) {
try {
receiver.getObjectStorage(storageType)[(int) index - 1] = value;
receiver.getObjectStorage()[(int) index - 1] = value;
return value;
} catch (IndexOutOfBoundsException e) {
return triggerException(receiver, index);
Expand All @@ -281,7 +278,7 @@ public final Object doObjectSArray(final SMutableArray receiver, final long inde
public final long doObjectSArray(final SMutableArray receiver, final long index,
final long value) {
try {
receiver.getLongStorage(storageType)[(int) index - 1] = value;
receiver.getLongStorage()[(int) index - 1] = value;
return value;
} catch (IndexOutOfBoundsException e) {
return (long) triggerException(receiver, index);
Expand All @@ -291,7 +288,7 @@ public final long doObjectSArray(final SMutableArray receiver, final long index,
@Specialization(guards = {"receiver.isLongType()", "valueIsNotLong(value)"})
public final Object doLongSArray(final SMutableArray receiver, final long index,
final Object value) {
long[] storage = receiver.getLongStorage(storageType);
long[] storage = receiver.getLongStorage();
Object[] newStorage = new Object[storage.length];
for (int i = 0; i < storage.length; i++) {
newStorage[i] = storage[i];
Expand All @@ -308,7 +305,7 @@ public final Object doLongSArray(final SMutableArray receiver, final long index,
public final double doDoubleSArray(final SMutableArray receiver, final long index,
final double value) {
try {
receiver.getDoubleStorage(storageType)[(int) index - 1] = value;
receiver.getDoubleStorage()[(int) index - 1] = value;
return value;
} catch (IndexOutOfBoundsException e) {
return (double) triggerException(receiver, index);
Expand All @@ -318,7 +315,7 @@ public final double doDoubleSArray(final SMutableArray receiver, final long inde
@Specialization(guards = {"receiver.isDoubleType()", "valueIsNotDouble(value)"})
public final Object doDoubleSArray(final SMutableArray receiver, final long index,
final Object value) {
double[] storage = receiver.getDoubleStorage(storageType);
double[] storage = receiver.getDoubleStorage();
Object[] newStorage = new Object[storage.length];
for (int i = 0; i < storage.length; i++) {
newStorage[i] = storage[i];
Expand All @@ -334,7 +331,7 @@ public final Object doDoubleSArray(final SMutableArray receiver, final long inde
public final boolean doBooleanSArray(final SMutableArray receiver, final long index,
final boolean value) {
try {
receiver.getBooleanStorage(storageType)[(int) index - 1] = value;
receiver.getBooleanStorage()[(int) index - 1] = value;
return value;
} catch (IndexOutOfBoundsException e) {
return (boolean) triggerException(receiver, index);
Expand All @@ -344,7 +341,7 @@ public final boolean doBooleanSArray(final SMutableArray receiver, final long in
@Specialization(guards = {"receiver.isBooleanType()", "valueIsNotBoolean(value)"})
public final Object doBooleanSArray(final SMutableArray receiver, final long index,
final Object value) {
boolean[] storage = receiver.getBooleanStorage(storageType);
boolean[] storage = receiver.getBooleanStorage();
Object[] newStorage = new Object[storage.length];
for (int i = 0; i < storage.length; i++) {
newStorage[i] = storage[i];
Expand Down
14 changes: 6 additions & 8 deletions src/som/primitives/arrays/CopyPrim.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.profiles.ValueProfile;

import bd.primitives.Primitive;
import som.interpreter.nodes.nary.UnaryExpressionNode;
Expand All @@ -13,52 +12,51 @@
@GenerateNodeFactory
@Primitive(selector = "copy", receiverType = SArray.class, disabled = true)
public abstract class CopyPrim extends UnaryExpressionNode {
private final ValueProfile storageType = ValueProfile.createClassProfile();

@Specialization(guards = "receiver.isEmptyType()")
public final SMutableArray doEmptyArray(final SMutableArray receiver) {
assert !receiver.getSOMClass()
.isTransferObject() : "Not yet supported, need to instantiate another class";
return new SMutableArray(receiver.getEmptyStorage(storageType), receiver.getSOMClass());
return new SMutableArray(receiver.getEmptyStorage(), receiver.getSOMClass());
}

@Specialization(guards = "receiver.isPartiallyEmptyType()")
public final SMutableArray doPartiallyEmptyArray(final SMutableArray receiver) {
assert !receiver.getSOMClass()
.isTransferObject() : "Not yet supported, need to instantiate another class";
return new SMutableArray(receiver.getPartiallyEmptyStorage(storageType).copy(),
return new SMutableArray(receiver.getPartiallyEmptyStorage().copy(),
receiver.getSOMClass());
}

@Specialization(guards = "receiver.isObjectType()")
public final SMutableArray doObjectArray(final SMutableArray receiver) {
assert !receiver.getSOMClass()
.isTransferObject() : "Not yet supported, need to instantiate another class";
return new SMutableArray(receiver.getObjectStorage(storageType).clone(),
return new SMutableArray(receiver.getObjectStorage().clone(),
receiver.getSOMClass());
}

@Specialization(guards = "receiver.isLongType()")
public final SMutableArray doLongArray(final SMutableArray receiver) {
assert !receiver.getSOMClass()
.isTransferObject() : "Not yet supported, need to instantiate another class";
return new SMutableArray(receiver.getLongStorage(storageType).clone(),
return new SMutableArray(receiver.getLongStorage().clone(),
receiver.getSOMClass());
}

@Specialization(guards = "receiver.isDoubleType()")
public final SMutableArray doDoubleArray(final SMutableArray receiver) {
assert !receiver.getSOMClass()
.isTransferObject() : "Not yet supported, need to instantiate another class";
return new SMutableArray(receiver.getDoubleStorage(storageType).clone(),
return new SMutableArray(receiver.getDoubleStorage().clone(),
receiver.getSOMClass());
}

@Specialization(guards = "receiver.isBooleanType()")
public final SMutableArray doBooleanArray(final SMutableArray receiver) {
assert !receiver.getSOMClass()
.isTransferObject() : "Not yet supported, need to instantiate another class";
return new SMutableArray(receiver.getBooleanStorage(storageType).clone(),
return new SMutableArray(receiver.getBooleanStorage().clone(),
receiver.getSOMClass());
}
}
Loading

0 comments on commit e7c95a9

Please sign in to comment.