Skip to content

Commit

Permalink
Start using @Bind.DefaultExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Jan 28, 2025
1 parent 8b5e911 commit 561ff6d
Show file tree
Hide file tree
Showing 22 changed files with 264 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.oracle.truffle.api.TruffleFile;
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
import com.oracle.truffle.api.TruffleLanguage.ParsingRequest;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrumentation.AllocationReporter;
Expand Down Expand Up @@ -77,6 +78,7 @@
import de.hpi.swa.trufflesqueak.util.MethodCacheEntry;
import de.hpi.swa.trufflesqueak.util.MiscUtils;

@Bind.DefaultExpression("get($node)")
public final class SqueakImageContext {
private static final ContextReference<SqueakImageContext> REFERENCE = ContextReference.create(SqueakLanguage.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package de.hpi.swa.trufflesqueak.interop;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
Expand Down Expand Up @@ -43,9 +44,9 @@ protected static final boolean doBoolean(final Object value,
}

@Specialization(guards = "lib.isString(value)", limit = "1")
protected final NativeObject doString(final Object value,
protected static final NativeObject doString(final Object value,
@Bind final SqueakImageContext image,
@CachedLibrary("value") final InteropLibrary lib) {
final SqueakImageContext image = getContext();
try {
return image.asByteString(lib.asString(value));
} catch (final UnsupportedMessageException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package de.hpi.swa.trufflesqueak.nodes;

import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
Expand All @@ -14,6 +15,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;

import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
import de.hpi.swa.trufflesqueak.model.ClassObject;
import de.hpi.swa.trufflesqueak.model.NativeObject;
import de.hpi.swa.trufflesqueak.util.MethodCacheEntry;
Expand Down Expand Up @@ -42,8 +44,9 @@ protected static final Object doCached(final ClassObject classObject, final Nati

@ReportPolymorphism.Megamorphic
@Specialization(replaces = "doCached")
protected final Object doUncached(final ClassObject classObject, final NativeObject selector) {
final MethodCacheEntry cachedEntry = getContext().findMethodCacheEntry(classObject, selector);
protected static final Object doUncached(final ClassObject classObject, final NativeObject selector,
@Bind final SqueakImageContext image) {
final MethodCacheEntry cachedEntry = image.findMethodCacheEntry(classObject, selector);
if (cachedEntry.getResult() == null) {
cachedEntry.setResult(classObject.lookupInMethodDictSlow(selector));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ public static MaterializeContextOnMethodExitNode create() {

public abstract void execute(VirtualFrame frame);

@Specialization(guards = {"getSqueakImageContext(frame).lastSeenContext == null", "hasEscapedContext(frame)"})
protected final void doStartMaterialization(final VirtualFrame frame) {
getContext().lastSeenContext = FrameAccess.getContext(frame);
@Specialization(guards = {"image.lastSeenContext == null", "hasEscapedContext(frame)"})
protected static final void doStartMaterialization(final VirtualFrame frame,
@Bind final SqueakImageContext image) {
image.lastSeenContext = FrameAccess.getContext(frame);
}

@Specialization(guards = {"getSqueakImageContext(frame).lastSeenContext != null"})
protected final void doMaterialize(final VirtualFrame frame,
@Specialization(guards = {"image.lastSeenContext != null"})
protected static final void doMaterialize(final VirtualFrame frame,
@Bind final Node node,
@Bind final SqueakImageContext image,
@Cached final InlinedConditionProfile isNotLastSeenContextProfile,
@Cached final InlinedConditionProfile continueProfile,
@Cached(inline = true) final GetOrCreateContextNode getOrCreateContextNode) {
final SqueakImageContext image = getContext();
final ContextObject lastSeenContext = image.lastSeenContext;
final ContextObject context = getOrCreateContextNode.executeGet(frame, node);
if (isNotLastSeenContextProfile.profile(node, context != lastSeenContext)) {
Expand All @@ -56,15 +57,10 @@ protected final void doMaterialize(final VirtualFrame frame,
}

@Specialization(guards = {"!hasEscapedContext(frame)"})
protected final void doNothing(@SuppressWarnings("unused") final VirtualFrame frame) {
protected static final void doNothing(@SuppressWarnings("unused") final VirtualFrame frame) {
/*
* Nothing to do because neither was a child context materialized nor has this context been
* requested and allocated.
*/
}

/* Avoid that the DSL generates an assertion for this. */
protected final SqueakImageContext getSqueakImageContext(@SuppressWarnings("unused") final VirtualFrame frame) {
return getContext();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
*/
package de.hpi.swa.trufflesqueak.nodes.accessing;

import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;

import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
import de.hpi.swa.trufflesqueak.model.FloatObject;
import de.hpi.swa.trufflesqueak.nodes.AbstractNode;
import de.hpi.swa.trufflesqueak.nodes.accessing.FloatObjectNodesFactory.AsFloatObjectIfNessaryNodeGen;
Expand All @@ -37,8 +39,8 @@ protected static final double doFinite(final double value) {
}

@Specialization(guards = "!isFinite(value)")
protected final FloatObject doNaNOrInfinite(final double value) {
return new FloatObject(getContext(), value);
protected static final FloatObject doNaNOrInfinite(final double value, @Bind final SqueakImageContext image) {
return new FloatObject(image, value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package de.hpi.swa.trufflesqueak.nodes.accessing;

import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
Expand All @@ -14,6 +15,7 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.InlinedBranchProfile;

import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
import de.hpi.swa.trufflesqueak.model.ArrayObject;
import de.hpi.swa.trufflesqueak.model.BlockClosureObject;
import de.hpi.swa.trufflesqueak.model.ClassObject;
Expand Down Expand Up @@ -67,8 +69,9 @@ protected static final void doVariablePointers(final Node node, final VariablePo
}

@Specialization
protected final void doLargeInteger(final LargeIntegerObject receiver, final long index, final long value) {
receiver.setNativeAt0(getContext(), index, value);
protected static final void doLargeInteger(final LargeIntegerObject receiver, final long index, final long value,
@Bind final SqueakImageContext image) {
receiver.setNativeAt0(image, index, value);
}

@Specialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
*/
package de.hpi.swa.trufflesqueak.nodes.accessing;

import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;

import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
import de.hpi.swa.trufflesqueak.model.AbstractSqueakObject;
import de.hpi.swa.trufflesqueak.model.AbstractSqueakObjectWithClassAndHash;
import de.hpi.swa.trufflesqueak.model.CharacterObject;
Expand Down Expand Up @@ -39,48 +41,48 @@ public static final ClassObject executeUncached(final Object receiver) {
}

@Specialization
protected final ClassObject doNil(@SuppressWarnings("unused") final NilObject value) {
return getContext().nilClass;
protected static final ClassObject doNil(@SuppressWarnings("unused") final NilObject value, @Bind final SqueakImageContext image) {
return image.nilClass;
}

@Specialization(guards = "value == TRUE")
protected final ClassObject doTrue(@SuppressWarnings("unused") final boolean value) {
return getContext().trueClass;
protected static final ClassObject doTrue(@SuppressWarnings("unused") final boolean value, @Bind final SqueakImageContext image) {
return image.trueClass;
}

@Specialization(guards = "value != TRUE")
protected final ClassObject doFalse(@SuppressWarnings("unused") final boolean value) {
return getContext().falseClass;
protected static final ClassObject doFalse(@SuppressWarnings("unused") final boolean value, @Bind final SqueakImageContext image) {
return image.falseClass;
}

@Specialization
protected final ClassObject doSmallInteger(@SuppressWarnings("unused") final long value) {
return getContext().smallIntegerClass;
protected static final ClassObject doSmallInteger(@SuppressWarnings("unused") final long value, @Bind final SqueakImageContext image) {
return image.smallIntegerClass;
}

@Specialization
protected final ClassObject doChar(@SuppressWarnings("unused") final char value) {
return getContext().characterClass;
protected static final ClassObject doChar(@SuppressWarnings("unused") final char value, @Bind final SqueakImageContext image) {
return image.characterClass;
}

@Specialization
protected final ClassObject doDouble(@SuppressWarnings("unused") final double value) {
return getContext().smallFloatClass;
protected static final ClassObject doDouble(@SuppressWarnings("unused") final double value, @Bind final SqueakImageContext image) {
return image.smallFloatClass;
}

@Specialization
protected final ClassObject doCharacter(@SuppressWarnings("unused") final CharacterObject value) {
return getContext().characterClass;
protected static final ClassObject doCharacter(@SuppressWarnings("unused") final CharacterObject value, @Bind final SqueakImageContext image) {
return image.characterClass;
}

@Specialization
protected final ClassObject doContext(@SuppressWarnings("unused") final ContextObject value) {
return getContext().methodContextClass;
protected static final ClassObject doContext(@SuppressWarnings("unused") final ContextObject value, @Bind final SqueakImageContext image) {
return image.methodContextClass;
}

@Specialization
protected final ClassObject doFloat(@SuppressWarnings("unused") final FloatObject value) {
return getContext().floatClass;
protected static final ClassObject doFloat(@SuppressWarnings("unused") final FloatObject value, @Bind final SqueakImageContext image) {
return image.floatClass;
}

@Specialization
Expand All @@ -89,7 +91,7 @@ protected static final ClassObject doAbstractSqueakObjectWithClassAndHash(final
}

@Specialization(guards = {"!isAbstractSqueakObject(value)", "!isUsedJavaPrimitive(value)"})
protected final ClassObject doForeignObject(@SuppressWarnings("unused") final Object value) {
return getContext().getForeignObjectClass();
protected static final ClassObject doForeignObject(@SuppressWarnings("unused") final Object value, @Bind final SqueakImageContext image) {
return image.getForeignObjectClass();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ protected static final long doLong(final long lhs, final long rhs) {
}

@Specialization(replaces = "doLong")
protected final Object doLongWithOverflow(final long lhs, final long rhs) {
return LargeIntegerObject.add(getContext(), lhs, rhs);
protected static final Object doLongWithOverflow(final long lhs, final long rhs, @Bind final SqueakImageContext image) {
return LargeIntegerObject.add(image, lhs, rhs);
}

@Specialization
Expand All @@ -428,8 +428,8 @@ protected static final long doLong(final long lhs, final long rhs) {
}

@Specialization(replaces = "doLong")
protected final Object doLongWithOverflow(final long lhs, final long rhs) {
return LargeIntegerObject.subtract(getContext(), lhs, rhs);
protected static final Object doLongWithOverflow(final long lhs, final long rhs, @Bind final SqueakImageContext image) {
return LargeIntegerObject.subtract(image, lhs, rhs);
}

@Specialization
Expand Down Expand Up @@ -559,8 +559,8 @@ protected static final long doLong(final long lhs, final long rhs) {
}

@Specialization(replaces = "doLong")
protected final Object doLongWithOverflow(final long lhs, final long rhs) {
return LargeIntegerObject.multiply(getContext(), lhs, rhs);
protected static final Object doLongWithOverflow(final long lhs, final long rhs, @Bind final SqueakImageContext image) {
return LargeIntegerObject.multiply(image, lhs, rhs);
}

@Specialization(rewriteOn = RespecializeException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;

import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
import de.hpi.swa.trufflesqueak.model.ClassObject;
import de.hpi.swa.trufflesqueak.model.NativeObject;
import de.hpi.swa.trufflesqueak.model.PointersObject;
Expand All @@ -26,9 +27,10 @@ abstract class CreateDoesNotUnderstandMessageNode extends AbstractNode {
@Specialization
protected static final PointersObject doCreate(final NativeObject selector, final Object receiver, final Object[] arguments,
@Bind final Node node,
@Bind final SqueakImageContext image,
@Cached final AbstractPointersObjectWriteNode writeNode,
@Cached final SqueakObjectClassNode classNode) {
final ClassObject receiverClass = classNode.executeLookup(node, receiver);
return getContext(node).newMessage(writeNode, node, selector, receiverClass, arguments);
return image.newMessage(writeNode, node, selector, receiverClass, arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,15 @@ public abstract static class DispatchIndirect0Node extends AbstractNode {
@Specialization
protected static final Object doIndirect(final VirtualFrame frame, final NativeObject selector, final Object receiver,
@Bind final Node node,
@Bind final SqueakImageContext image,
@Cached final SqueakObjectClassNode classNode,
@Cached final ResolveMethodNode methodNode,
@Cached final TryPrimitive0Node tryPrimitiveNode,
@Cached final CreateFrameArgumentsForIndirectCall0Node argumentsNode,
@Cached final IndirectCallNode callNode) {
final ClassObject receiverClass = classNode.executeLookup(node, receiver);
final Object lookupResult = getContext(node).lookup(receiverClass, selector);
final CompiledCodeObject method = methodNode.execute(node, getContext(node), receiverClass, lookupResult);
final Object lookupResult = image.lookup(receiverClass, selector);
final CompiledCodeObject method = methodNode.execute(node, image, receiverClass, lookupResult);
final Object result = tryPrimitiveNode.execute(frame, method, receiver);
if (result != null) {
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,15 @@ public abstract static class DispatchIndirect1Node extends AbstractNode {
@Specialization
protected static final Object doIndirect(final VirtualFrame frame, final NativeObject selector, final Object receiver, final Object arg1,
@Bind final Node node,
@Bind final SqueakImageContext image,
@Cached final SqueakObjectClassNode classNode,
@Cached final ResolveMethodNode methodNode,
@Cached final TryPrimitive1Node tryPrimitiveNode,
@Cached final CreateFrameArgumentsForIndirectCall1Node argumentsNode,
@Cached final IndirectCallNode callNode) {
final ClassObject receiverClass = classNode.executeLookup(node, receiver);
final Object lookupResult = getContext(node).lookup(receiverClass, selector);
final CompiledCodeObject method = methodNode.execute(node, getContext(node), receiverClass, lookupResult);
final Object lookupResult = image.lookup(receiverClass, selector);
final CompiledCodeObject method = methodNode.execute(node, image, receiverClass, lookupResult);
final Object result = tryPrimitiveNode.execute(frame, method, receiver, arg1);
if (result != null) {
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,15 @@ public abstract static class DispatchIndirect2Node extends AbstractNode {
@Specialization
protected static final Object doIndirect(final VirtualFrame frame, final NativeObject selector, final Object receiver, final Object arg1, final Object arg2,
@Bind final Node node,
@Bind final SqueakImageContext image,
@Cached final SqueakObjectClassNode classNode,
@Cached final ResolveMethodNode methodNode,
@Cached final TryPrimitive2Node tryPrimitiveNode,
@Cached final CreateFrameArgumentsForIndirectCall2Node argumentsNode,
@Cached final IndirectCallNode callNode) {
final ClassObject receiverClass = classNode.executeLookup(node, receiver);
final Object lookupResult = getContext(node).lookup(receiverClass, selector);
final CompiledCodeObject method = methodNode.execute(node, getContext(node), receiverClass, lookupResult);
final Object lookupResult = image.lookup(receiverClass, selector);
final CompiledCodeObject method = methodNode.execute(node, image, receiverClass, lookupResult);
final Object result = tryPrimitiveNode.execute(frame, method, receiver, arg1, arg2);
if (result != null) {
return result;
Expand Down
Loading

0 comments on commit 561ff6d

Please sign in to comment.