Skip to content

Commit

Permalink
Use even more node inlining.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 9, 2023
1 parent fcc8289 commit c21281f
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected static final Object doSendGeneric(final AbstractSqueakObject receiver,
final SqueakImageContext image = SqueakImageContext.get(lookupNode);
if (message.getLibraryClass() == InteropLibrary.class) {
final NativeObject selector = image.toInteropSelector(message);
final Object methodObject = lookupNode.executeLookup(classNode.executeLookup(node, receiver), selector);
final Object methodObject = lookupNode.executeLookup(node, classNode.executeLookup(node, receiver), selector);
if (methodObject instanceof final CompiledCodeObject method) {
assert message.getLibraryClass() == InteropLibrary.class;
final Object[] receiverAndArguments = new Object[message.getParameterCount()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public boolean isDoesNotUnderstand(final SqueakImageContext image) {
public Object executeAsSymbolSlow(final VirtualFrame frame, final Object... receiverAndArguments) {
CompilerAsserts.neverPartOfCompilation();
assert SqueakImageContext.getSlow().isByteSymbolClass(getSqueakClass());
final Object method = LookupMethodNode.getUncached().executeLookup(SqueakObjectClassNode.executeUncached(receiverAndArguments[0]), this);
final Object method = LookupMethodNode.executeUncached(SqueakObjectClassNode.executeUncached(receiverAndArguments[0]), this);
if (method instanceof CompiledCodeObject) {
return DispatchUneagerlyNode.executeUncached((CompiledCodeObject) method, receiverAndArguments, GetOrCreateContextNode.getOrCreateUncached(frame));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,29 @@
package de.hpi.swa.trufflesqueak.nodes;

import com.oracle.truffle.api.dsl.Cached;
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.NeverDefault;
import com.oracle.truffle.api.dsl.ReportPolymorphism;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;

import de.hpi.swa.trufflesqueak.model.ClassObject;
import de.hpi.swa.trufflesqueak.model.NativeObject;
import de.hpi.swa.trufflesqueak.util.MethodCacheEntry;

@GenerateInline
@GenerateUncached
@GenerateCached(false)
public abstract class LookupMethodNode extends AbstractNode {
protected static final int LOOKUP_CACHE_SIZE = 6;

@NeverDefault
public static LookupMethodNode create() {
return LookupMethodNodeGen.create();
}
public abstract Object executeLookup(Node node, ClassObject sqClass, NativeObject selector);

public static LookupMethodNode getUncached() {
return LookupMethodNodeGen.getUncached();
public static final Object executeUncached(final ClassObject sqClass, final NativeObject selector) {
return LookupMethodNodeGen.getUncached().executeLookup(null, sqClass, selector);
}

public abstract Object executeLookup(ClassObject sqClass, NativeObject selector);

@SuppressWarnings("unused")
@Specialization(limit = "LOOKUP_CACHE_SIZE", guards = {"classObject == cachedClass", "selector == cachedSelector"}, //
assumptions = {"cachedClass.getClassHierarchyStable()", "cachedClass.getMethodDictStable()"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected final Object doSend(final VirtualFrame frame, final Object[] receiverA
@Cached final LookupMethodNode lookupMethodNode,
@Cached final DispatchEagerlyNode dispatchNode) {
final ClassObject rcvrClass = lookupClassNode.executeLookup(node, receiverAndArguments[0]);
final CompiledCodeObject method = (CompiledCodeObject) lookupMethodNode.executeLookup(rcvrClass, selector);
final CompiledCodeObject method = (CompiledCodeObject) lookupMethodNode.executeLookup(node, rcvrClass, selector);
final Object result = dispatchNode.executeDispatch(frame, method, receiverAndArguments);
assert result != null : "Result of a message send should not be null";
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ protected PrimFillFromToWithNode(final CompiledCodeObject code, final int index)
super(code, index);
}

public static AbstractBytecodeNode create(CompiledCodeObject code, int index) {
public static AbstractBytecodeNode create(final CompiledCodeObject code, final int index) {
return PrimFillFromToWithNodeGen.create(code, index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static SqueakObjectAtPutAndMarkContextsNode create(final long index) {
return SqueakObjectAtPutAndMarkContextsNodeGen.create(index);
}

public abstract void executeWrite(final Object object, final Object value);
public abstract void executeWrite(Object object, Object value);

@Specialization
public void doWrite(final Object object, final Object value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected static final CachedDispatchNode create(final VirtualFrame frame, final
return AbstractCachedDispatchMethodNode.create(frame, argumentCount, lookupMethod);
} else {
final ClassObject lookupResultClass = SqueakObjectClassNode.executeUncached(lookupResult);
final Object runWithInMethod = LookupMethodNode.getUncached().executeLookup(lookupResultClass, image.runWithInSelector);
final Object runWithInMethod = LookupMethodNode.executeUncached(lookupResultClass, image.runWithInSelector);
if (runWithInMethod instanceof final CompiledCodeObject method) {
return AbstractCachedDispatchObjectAsMethodNode.create(frame, selector, argumentCount, lookupResult, method);
} else {
Expand All @@ -67,7 +67,7 @@ protected static final CachedDispatchNode create(final VirtualFrame frame, final
}

private static CachedDispatchNode createDNUNode(final VirtualFrame frame, final NativeObject selector, final int argumentCount, final SqueakImageContext image, final ClassObject receiverClass) {
final Object dnuMethod = LookupMethodNode.getUncached().executeLookup(receiverClass, image.doesNotUnderstand);
final Object dnuMethod = LookupMethodNode.executeUncached(receiverClass, image.doesNotUnderstand);
if (dnuMethod instanceof final CompiledCodeObject method) {
return AbstractCachedDispatchDoesNotUnderstandNode.create(frame, selector, argumentCount, method);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateCached;
import com.oracle.truffle.api.dsl.GenerateInline;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
import com.oracle.truffle.api.dsl.Specialization;
Expand All @@ -34,7 +36,6 @@
import de.hpi.swa.trufflesqueak.nodes.context.frame.GetOrCreateContextNode;
import de.hpi.swa.trufflesqueak.nodes.dispatch.CreateFrameArgumentNodesFactory.CreateFrameArgumentsForDNUNodeGen;
import de.hpi.swa.trufflesqueak.nodes.dispatch.CreateFrameArgumentNodesFactory.CreateFrameArgumentsForIndirectCallNodeGen;
import de.hpi.swa.trufflesqueak.nodes.dispatch.CreateFrameArgumentNodesFactory.GetOrCreateContextOrMarkerNodeGen;
import de.hpi.swa.trufflesqueak.util.FrameAccess;

public final class CreateFrameArgumentNodes {
Expand Down Expand Up @@ -116,7 +117,6 @@ public Object[] execute(final VirtualFrame frame, final Object cachedObject, fin
protected abstract static class CreateFrameArgumentsForIndirectCallNode extends AbstractNode {
private final NativeObject selector;
@Children private FrameStackReadNode[] argumentNodes;
@Child private GetOrCreateContextOrMarkerNode senderNode = GetOrCreateContextOrMarkerNode.create();

protected CreateFrameArgumentsForIndirectCallNode(final VirtualFrame frame, final NativeObject selector, final int argumentCount) {
this.selector = selector;
Expand All @@ -139,24 +139,30 @@ protected static CreateFrameArgumentsForIndirectCallNode create(final VirtualFra
@Specialization
@SuppressWarnings("unused")
protected final Object[] doMethod(final VirtualFrame frame, final Object receiver, final ClassObject receiverClass, @SuppressWarnings("unused") final CompiledCodeObject lookupResult,
final CompiledCodeObject method) {
return FrameAccess.newWith(frame, senderNode.execute(frame, method), receiver, argumentNodes);
final CompiledCodeObject method,
@Bind("this") final Node node,
@Shared("senderNode") @Cached final GetOrCreateContextOrMarkerNode senderNode) {
return FrameAccess.newWith(frame, senderNode.execute(frame, node, method), receiver, argumentNodes);
}

@Specialization(guards = "lookupResult == null")
protected final Object[] doDoesNotUnderstand(final VirtualFrame frame, final Object receiver, final ClassObject receiverClass, @SuppressWarnings("unused") final Object lookupResult,
final CompiledCodeObject method,
@Cached final AbstractPointersObjectWriteNode writeNode) {
@Bind("this") final Node node,
@Cached final AbstractPointersObjectWriteNode writeNode,
@Shared("senderNode") @Cached final GetOrCreateContextOrMarkerNode senderNode) {
final Object[] arguments = getArguments(frame, argumentNodes);
final PointersObject message = getContext().newMessage(writeNode, selector, receiverClass, arguments);
return FrameAccess.newDNUWith(senderNode.execute(frame, method), receiver, message);
return FrameAccess.newDNUWith(senderNode.execute(frame, node, method), receiver, message);
}

@Specialization(guards = {"targetObject != null", "!isCompiledCodeObject(targetObject)"})
protected final Object[] doObjectAsMethod(final VirtualFrame frame, final Object receiver, @SuppressWarnings("unused") final ClassObject receiverClass, final Object targetObject,
final CompiledCodeObject method) {
final CompiledCodeObject method,
@Bind("this") final Node node,
@Shared("senderNode") @Cached final GetOrCreateContextOrMarkerNode senderNode) {
final Object[] arguments = getArguments(frame, argumentNodes);
return FrameAccess.newOAMWith(senderNode.execute(frame, method), targetObject, selector, getContext().asArrayOfObjects(arguments), receiver);
return FrameAccess.newOAMWith(senderNode.execute(frame, node, method), targetObject, selector, getContext().asArrayOfObjects(arguments), receiver);
}
}

Expand All @@ -171,29 +177,24 @@ private static Object[] getArguments(final VirtualFrame frame, final FrameStackR
return arguments;
}

@GenerateInline
@GenerateCached(false)
@NodeInfo(cost = NodeCost.NONE)
protected abstract static class GetOrCreateContextOrMarkerNode extends AbstractNode {

@NeverDefault
protected static GetOrCreateContextOrMarkerNode create() {
return GetOrCreateContextOrMarkerNodeGen.create();
}

protected abstract Object execute(VirtualFrame frame, CompiledCodeObject code);
protected abstract Object execute(VirtualFrame frame, Node node, CompiledCodeObject code);

@Specialization(guards = "doesNotNeedSender(code, assumptionProfile, node)")
protected static final Object doGetContextOrMarker(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledCodeObject code,
@SuppressWarnings("unused") @Bind("this") final Node node,
protected static final Object doGetContextOrMarker(final VirtualFrame frame, @SuppressWarnings("unused") final Node node, @SuppressWarnings("unused") final CompiledCodeObject code,
@SuppressWarnings("unused") @Shared("assumptionProfile") @Cached final InlinedExactClassProfile assumptionProfile,
@Cached final GetContextOrMarkerNode getContextOrMarkerNode) {
return getContextOrMarkerNode.execute(frame);
}

@Specialization(guards = "!doesNotNeedSender(code, assumptionProfile, node)")
protected static final ContextObject doGetOrCreateContext(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledCodeObject code,
@SuppressWarnings("unused") @Bind("this") final Node node,
protected static final ContextObject doGetOrCreateContext(final VirtualFrame frame, @SuppressWarnings("unused") final Node node, @SuppressWarnings("unused") final CompiledCodeObject code,
@SuppressWarnings("unused") @Shared("assumptionProfile") @Cached final InlinedExactClassProfile assumptionProfile,
@Cached(inline = true) final GetOrCreateContextNode getOrCreateContextNode) {
@Cached final GetOrCreateContextNode getOrCreateContextNode) {
return getOrCreateContextNode.executeGet(frame, node);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ protected final Object doDispatch(final VirtualFrame frame, @SuppressWarnings("u
@Specialization(guards = {"lookupResult == null"})
protected final Object doDoesNotUnderstand(final VirtualFrame frame, final NativeObject selector, @SuppressWarnings("unused") final Object lookupResult, final ClassObject rcvrClass,
final Object[] rcvrAndArgs,
@Bind("this") final Node node,
@Shared("writeNode") @Cached final AbstractPointersObjectWriteNode writeNode,
@Shared("lookupNode") @Cached final LookupMethodNode lookupNode) {
final SqueakImageContext image = getContext();
final CompiledCodeObject doesNotUnderstandMethod = (CompiledCodeObject) lookupNode.executeLookup(rcvrClass, image.doesNotUnderstand);
final CompiledCodeObject doesNotUnderstandMethod = (CompiledCodeObject) lookupNode.executeLookup(node, rcvrClass, image.doesNotUnderstand);
final PointersObject message = image.newMessage(writeNode, selector, rcvrClass, ArrayUtils.allButFirst(rcvrAndArgs));
return dispatchNode.executeDispatch(frame, doesNotUnderstandMethod, new Object[]{rcvrAndArgs[0], message});
}
Expand All @@ -74,9 +75,9 @@ protected final Object doObjectAsMethod(final VirtualFrame frame, final NativeOb
final SqueakImageContext image = getContext(node);
final Object[] arguments = ArrayUtils.allButFirst(rcvrAndArgs);
final ClassObject targetClass = classNode.executeLookup(node, targetObject);
final Object newLookupResult = lookupNode.executeLookup(targetClass, image.runWithInSelector);
final Object newLookupResult = lookupNode.executeLookup(node, targetClass, image.runWithInSelector);
if (isDoesNotUnderstandProfile.profile(node, newLookupResult == null)) {
final Object doesNotUnderstandMethod = lookupNode.executeLookup(targetClass, image.doesNotUnderstand);
final Object doesNotUnderstandMethod = lookupNode.executeLookup(node, targetClass, image.doesNotUnderstand);
return dispatchNode.executeDispatch(frame, (CompiledCodeObject) doesNotUnderstandMethod,
new Object[]{targetObject, image.newMessage(writeNode, selector, targetClass, arguments)});
} else {
Expand Down
Loading

0 comments on commit c21281f

Please sign in to comment.