Skip to content

Commit

Permalink
Treat "truffle-sharing" warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 6, 2023
1 parent 87ba326 commit 34709ea
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NeverDefault;
Expand Down Expand Up @@ -70,26 +71,26 @@ protected static final long doLong(final long value) {

@Specialization
protected static final Object doFloat(final float value,
@Cached final AsFloatObjectIfNessaryNode boxNode) {
@Shared("boxNode") @Cached final AsFloatObjectIfNessaryNode boxNode) {
return boxNode.execute(value);
}

@Specialization
protected static final Object doDouble(final double value,
@Cached final AsFloatObjectIfNessaryNode boxNode) {
@Shared("boxNode") @Cached final AsFloatObjectIfNessaryNode boxNode) {
return boxNode.execute(value);
}

@Specialization
protected final NativeObject doString(final String value,
@Cached final ConditionProfile wideStringProfile) {
@Shared("wideStringProfile") @Cached final ConditionProfile wideStringProfile) {
return getContext().asString(value, wideStringProfile);
}

@Specialization
protected final NativeObject doTruffleString(final TruffleString value,
@Cached final TruffleString.ToJavaStringNode toJavaString,
@Cached final ConditionProfile wideStringProfile) {
@Shared("wideStringProfile") @Cached final ConditionProfile wideStringProfile) {
return doString(toJavaString.execute(value), wideStringProfile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.ReportPolymorphism;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.InteropLibrary;
Expand Down Expand Up @@ -59,12 +60,12 @@ protected static class Send {
@Specialization(guards = {"message == cachedMessage", "classNode.executeLookup(receiver) == cachedClass", "cachedMethod != null"}, limit = "8", //
assumptions = {"cachedClass.getClassHierarchyStable()", "cachedClass.getMethodDictStable()", "cachedMethod.getCallTargetStable()"})
protected static final Object doSendCached(final AbstractSqueakObject receiver, final Message message, final Object[] arguments,
@Cached final SqueakObjectClassNode classNode,
@Shared("classNode") @Cached final SqueakObjectClassNode classNode,
@Cached("message") final Message cachedMessage,
@Cached("classNode.executeLookup(receiver)") final ClassObject cachedClass,
@Cached("lookupMethod(cachedClass, cachedMessage)") final CompiledCodeObject cachedMethod,
@Cached("create(cachedMethod.getCallTarget())") final DirectCallNode callNode,
@Cached final WrapToSqueakNode wrapNode) {
@Shared("wrapNode") @Cached final WrapToSqueakNode wrapNode) {
final int numArgs = cachedMessage.getParameterCount() - 1;
assert numArgs == arguments.length;
final Object[] frameArguments = FrameAccess.newWith(NilObject.SINGLETON, null, cachedMessage.getParameterCount());
Expand All @@ -87,9 +88,9 @@ protected static final CompiledCodeObject lookupMethod(final ClassObject clazz,
@Specialization(replaces = "doSendCached")
protected static final Object doSendGeneric(final AbstractSqueakObject receiver, final Message message, final Object[] arguments,
@Cached final LookupMethodNode lookupNode,
@Cached final SqueakObjectClassNode classNode,
@Shared("classNode") @Cached final SqueakObjectClassNode classNode,
@Cached final DispatchUneagerlyNode dispatchNode,
@Cached final WrapToSqueakNode wrapNode) throws Exception {
@Shared("wrapNode") @Cached final WrapToSqueakNode wrapNode) throws Exception {
final SqueakImageContext image = SqueakImageContext.get(lookupNode);
if (message.getLibraryClass() == InteropLibrary.class) {
final NativeObject selector = image.toInteropSelector(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Exclusive;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NeverDefault;
Expand Down Expand Up @@ -177,14 +178,14 @@ public abstract static class VariablePointersObjectReadNode extends Node {
protected static final Object doReadCached(final VariablePointersObject object, @SuppressWarnings("unused") final long index,
@Cached("index") final long cachedIndex,
@SuppressWarnings("unused") @Cached("object.getLayout()") final ObjectLayout cachedLayout,
@Cached final AbstractPointersObjectReadNode readNode) {
@Exclusive @Cached final AbstractPointersObjectReadNode readNode) {
return readNode.execute(object, cachedIndex);
}

@ReportPolymorphism.Megamorphic
@Specialization(guards = "index < object.instsize()", replaces = "doReadCached")
protected static final Object doReadGeneric(final VariablePointersObject object, final long index,
@Cached final AbstractPointersObjectReadNode readNode) {
@Exclusive @Cached final AbstractPointersObjectReadNode readNode) {
return readNode.execute(object, index);
}

Expand Down Expand Up @@ -222,14 +223,14 @@ public abstract static class VariablePointersObjectWriteNode extends Node {
protected static final void doWriteCached(final VariablePointersObject object, @SuppressWarnings("unused") final long index, final Object value,
@Cached("index") final long cachedIndex,
@SuppressWarnings("unused") @Cached("object.getLayout()") final ObjectLayout cachedLayout,
@Cached final AbstractPointersObjectWriteNode writeNode) {
@Exclusive @Cached final AbstractPointersObjectWriteNode writeNode) {
writeNode.execute(object, cachedIndex, value);
}

@ReportPolymorphism.Megamorphic
@Specialization(guards = "index < object.instsize()", replaces = "doWriteCached")
protected static final void doWriteGeneric(final VariablePointersObject object, final long index, final Object value,
@Cached final AbstractPointersObjectWriteNode writeNode) {
@Exclusive @Cached final AbstractPointersObjectWriteNode writeNode) {
writeNode.execute(object, index, value);
}

Expand Down Expand Up @@ -267,14 +268,14 @@ public abstract static class WeakVariablePointersObjectReadNode extends Node {
protected static final Object doReadCached(final WeakVariablePointersObject object, @SuppressWarnings("unused") final long index,
@Cached("index") final long cachedIndex,
@SuppressWarnings("unused") @Cached("object.getLayout()") final ObjectLayout cachedLayout,
@Cached final AbstractPointersObjectReadNode readNode) {
@Exclusive @Cached final AbstractPointersObjectReadNode readNode) {
return readNode.execute(object, cachedIndex);
}

@ReportPolymorphism.Megamorphic
@Specialization(guards = "index < object.instsize()", replaces = "doReadCached")
protected static final Object doReadGeneric(final WeakVariablePointersObject object, final long index,
@Cached final AbstractPointersObjectReadNode readNode) {
@Exclusive @Cached final AbstractPointersObjectReadNode readNode) {
return readNode.execute(object, index);
}

Expand All @@ -283,22 +284,22 @@ protected static final Object doReadGeneric(final WeakVariablePointersObject obj
protected static final Object doReadFromVariablePartCachedIndex(final WeakVariablePointersObject object, @SuppressWarnings("unused") final long index,
@Cached("index") final long cachedIndex,
@Cached("object.getLayout()") final ObjectLayout cachedLayout,
@Cached final ConditionProfile weakRefProfile) {
@Exclusive @Cached final ConditionProfile weakRefProfile) {
return object.getFromVariablePart(cachedIndex - cachedLayout.getInstSize(), weakRefProfile);
}

@Specialization(guards = {"object.getLayout() == cachedLayout", "index >= cachedLayout.getInstSize()"}, assumptions = "cachedLayout.getValidAssumption()", //
replaces = "doReadFromVariablePartCachedIndex", limit = "VARIABLE_PART_LAYOUT_CACHE_LIMIT")
protected static final Object doReadFromVariablePartCachedLayout(final WeakVariablePointersObject object, final long index,
@Cached("object.getLayout()") final ObjectLayout cachedLayout,
@Cached final ConditionProfile weakRefProfile) {
@Exclusive @Cached final ConditionProfile weakRefProfile) {
return object.getFromVariablePart(index - cachedLayout.getInstSize(), weakRefProfile);
}

@ReportPolymorphism.Megamorphic
@Specialization(guards = "index >= object.instsize()", replaces = {"doReadFromVariablePartCachedIndex", "doReadFromVariablePartCachedLayout"})
protected static final Object doReadFromVariablePartGeneric(final WeakVariablePointersObject object, final long index,
@Cached final ConditionProfile weakRefProfile) {
@Exclusive @Cached final ConditionProfile weakRefProfile) {
return object.getFromVariablePart(index - object.instsize(), weakRefProfile);
}
}
Expand All @@ -315,14 +316,14 @@ public abstract static class WeakVariablePointersObjectWriteNode extends Node {
protected static final void doWriteCached(final WeakVariablePointersObject object, @SuppressWarnings("unused") final long index, final Object value,
@Cached("index") final long cachedIndex,
@SuppressWarnings("unused") @Cached("object.getLayout()") final ObjectLayout cachedLayout,
@Cached final AbstractPointersObjectWriteNode writeNode) {
@Exclusive @Cached final AbstractPointersObjectWriteNode writeNode) {
writeNode.execute(object, cachedIndex, value);
}

@ReportPolymorphism.Megamorphic
@Specialization(guards = "index < object.instsize()", replaces = "doWriteCached")
protected static final void doWriteGeneric(final WeakVariablePointersObject object, final long index, final Object value,
@Cached final AbstractPointersObjectWriteNode writeNode) {
@Exclusive @Cached final AbstractPointersObjectWriteNode writeNode) {
writeNode.execute(object, index, value);
}

Expand All @@ -331,22 +332,22 @@ protected static final void doWriteGeneric(final WeakVariablePointersObject obje
protected static final void doWriteIntoVariablePartCachedIndex(final WeakVariablePointersObject object, @SuppressWarnings("unused") final long index, final Object value,
@Cached("index") final long cachedIndex,
@Cached("object.getLayout()") final ObjectLayout cachedLayout,
@Cached final ConditionProfile primitiveProfile) {
@Exclusive @Cached final ConditionProfile primitiveProfile) {
object.putIntoVariablePart(cachedIndex - cachedLayout.getInstSize(), value, primitiveProfile);
}

@Specialization(guards = {"object.getLayout() == cachedLayout", "index >= cachedLayout.getInstSize()"}, assumptions = "cachedLayout.getValidAssumption()", //
replaces = "doWriteIntoVariablePartCachedIndex", limit = "VARIABLE_PART_LAYOUT_CACHE_LIMIT")
protected static final void doWriteIntoVariablePartCachedLayout(final WeakVariablePointersObject object, final long index, final Object value,
@Cached("object.getLayout()") final ObjectLayout cachedLayout,
@Cached final ConditionProfile primitiveProfile) {
@Exclusive @Cached final ConditionProfile primitiveProfile) {
object.putIntoVariablePart(index - cachedLayout.getInstSize(), value, primitiveProfile);
}

@ReportPolymorphism.Megamorphic
@Specialization(guards = "index >= object.instsize()", replaces = {"doWriteIntoVariablePartCachedIndex", "doWriteIntoVariablePartCachedLayout"})
protected static final void doWriteIntoVariablePartGeneric(final WeakVariablePointersObject object, final long index, final Object value,
@Cached final ConditionProfile primitiveProfile) {
@Exclusive @Cached final ConditionProfile primitiveProfile) {
object.putIntoVariablePart(index - object.instsize(), value, primitiveProfile);
}
}
Expand Down
Loading

1 comment on commit 34709ea

@TruffleSqueak-Bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance Report (34709ea)

Benchmarks ran on graalvm-jdk-21+35.1.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 548 671 585.45 576 584.83 117089 1.95
CD 443 455 446.93 445 446.92 89386 1.49
DeltaBlue 276 466 410.98 401 409.39 82195 1.37
Havlak 1129 1182 1161.52 1167 1161.45 232304 3.87
Json 362 371 364.72 363 364.71 72944 1.22
List 292 302 293.08 293 293.08 58617 0.98
Mandelbrot 125 136 125.73 125 125.72 25146 0.42
NBody 249 264 251.71 250 251.69 50341 0.84
Permute 149 161 150.69 150 150.67 30137 0.5
Queens 232 304 241.35 237 241.13 48270 0.8
Richards 1221 1341 1262.69 1261.5 1262.41 252538 4.21
Sieve 163 173 164.12 164 164.1 32823 0.55
Storage 159 342 180.11 173.5 179.15 36022 0.6
Towers 195 206 196.11 196 196.1 39222 0.65
5543 6374 5835.17 5802 5831.35 1167034 19.45

34709ea-2-steady.svg

Warmup (first 100 iterations)

34709ea-3-warmup.svg

Please sign in to comment.