Skip to content

Commit

Permalink
Revise creation of objects with ObjectLayout.
Browse files Browse the repository at this point in the history
Since `ObjectLayouts` are class-specific, the guard checks can be performed at cache-time.
  • Loading branch information
fniephaus committed Mar 14, 2022
1 parent b22ac1b commit 782e95b
Showing 1 changed file with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package de.hpi.swa.trufflesqueak.nodes.accessing;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.Specialization;
Expand Down Expand Up @@ -72,17 +71,23 @@ protected static final ClassObject doClassOdd(final SqueakImageContext image, fi
return new ClassObject(image, classObject, classObject.getBasicInstanceSize() + METACLASS.INST_SIZE);
}

@Specialization(guards = {"classObject.isNonIndexableWithInstVars()", "!image.isMetaClass(classObject)", "!classObject.instancesAreClasses()",
"classObject.getLayout() == cachedLayout"}, assumptions = "cachedLayout.getValidAssumption()", limit = "NEW_CACHE_SIZE")
protected static final PointersObject doPointers(final SqueakImageContext image, final ClassObject classObject, final int extraSize,
@Cached(value = "classObject.getLayout()", allowUncached = true) final ObjectLayout cachedLayout) {
assert extraSize == 0;
@Specialization(guards = {"classObject.getLayout() == cachedLayout"}, assumptions = "cachedLayout.getValidAssumption()", limit = "NEW_CACHE_SIZE")
protected static final PointersObject doPointersCached(final SqueakImageContext image, final ClassObject classObject, final int extraSize,
@Cached("getPointersLayoutOrNull(image, classObject)") final ObjectLayout cachedLayout) {
assert extraSize == 0 && instantiatesPointersObject(image, classObject);
return new PointersObject(image, classObject, cachedLayout);
}

@TruffleBoundary
@Specialization(guards = {"classObject.isNonIndexableWithInstVars()", "!image.isMetaClass(classObject)", "!classObject.instancesAreClasses()"})
protected static final PointersObject doPointersFallback(final SqueakImageContext image, final ClassObject classObject, final int extraSize) {
protected static final boolean instantiatesPointersObject(final SqueakImageContext image, final ClassObject classObject) {
return classObject.isNonIndexableWithInstVars() && !image.isMetaClass(classObject) && !classObject.instancesAreClasses();
}

protected static final ObjectLayout getPointersLayoutOrNull(final SqueakImageContext image, final ClassObject classObject) {
return instantiatesPointersObject(image, classObject) ? classObject.getLayout() : null;
}

@Specialization(guards = {"instantiatesPointersObject(image, classObject)"}, replaces = "doPointersCached")
protected static final PointersObject doPointersUncached(final SqueakImageContext image, final ClassObject classObject, final int extraSize) {
assert extraSize == 0;
return new PointersObject(image, classObject);
}
Expand All @@ -105,28 +110,43 @@ protected static final BlockClosureObject doBlockClosure(final SqueakImageContex
return BlockClosureObject.create(image, classObject, extraSize);
}

@Specialization(guards = {"classObject.isIndexableWithInstVars()", "!image.isMethodContextClass(classObject)", "!image.isBlockClosureClass(classObject)",
"!image.isFullBlockClosureClass(classObject)", "classObject.getLayout() == cachedLayout"}, assumptions = "cachedLayout.getValidAssumption()", limit = "NEW_CACHE_SIZE")
protected static final VariablePointersObject doVariablePointers(final SqueakImageContext image, final ClassObject classObject, final int extraSize,
@Cached(value = "classObject.getLayout()", allowUncached = true) final ObjectLayout cachedLayout) {
@Specialization(guards = {"classObject.getLayout() == cachedLayout"}, assumptions = "cachedLayout.getValidAssumption()", limit = "NEW_CACHE_SIZE")
protected static final VariablePointersObject doVariablePointersCached(final SqueakImageContext image, final ClassObject classObject, final int extraSize,
@Cached(value = "getVariablePointersLayoutOrNull(image, classObject)") final ObjectLayout cachedLayout) {
assert instantiatesVariablePointersObject(image, classObject);
return new VariablePointersObject(image, classObject, cachedLayout, extraSize);
}

@TruffleBoundary
@Specialization(guards = {"classObject.isIndexableWithInstVars()", "!image.isMethodContextClass(classObject)", "!image.isBlockClosureClass(classObject)"})
protected static final VariablePointersObject doVariablePointersFallback(final SqueakImageContext image, final ClassObject classObject, final int extraSize) {
protected static final boolean instantiatesVariablePointersObject(final SqueakImageContext image, final ClassObject classObject) {
return classObject.isIndexableWithInstVars() && !image.isMethodContextClass(classObject) && !image.isBlockClosureClass(classObject) && !image.isFullBlockClosureClass(classObject);
}

protected static final ObjectLayout getVariablePointersLayoutOrNull(final SqueakImageContext image, final ClassObject classObject) {
return instantiatesVariablePointersObject(image, classObject) ? classObject.getLayout() : null;
}

@Specialization(guards = {"instantiatesVariablePointersObject(image, classObject)"}, replaces = "doVariablePointersCached")
protected static final VariablePointersObject doVariablePointersUncached(final SqueakImageContext image, final ClassObject classObject, final int extraSize) {
return new VariablePointersObject(image, classObject, extraSize);
}

@Specialization(guards = {"classObject.isWeak()", "classObject.getLayout() == cachedLayout"}, assumptions = "cachedLayout.getValidAssumption()", limit = "NEW_CACHE_SIZE")
protected static final WeakVariablePointersObject doWeakPointers(final SqueakImageContext image, final ClassObject classObject, final int extraSize,
@Cached(value = "classObject.getLayout()", allowUncached = true) final ObjectLayout cachedLayout) {
@Specialization(guards = {"classObject.getLayout() == cachedLayout"}, assumptions = "cachedLayout.getValidAssumption()", limit = "NEW_CACHE_SIZE")
protected static final WeakVariablePointersObject doWeakPointersCached(final SqueakImageContext image, final ClassObject classObject, final int extraSize,
@Cached(value = "getWeakPointersLayoutOrNull(classObject)") final ObjectLayout cachedLayout) {
assert instantiatesWeakVariablePointersObject(classObject);
return new WeakVariablePointersObject(image, classObject, cachedLayout, extraSize);
}

@TruffleBoundary
@Specialization(guards = "classObject.isWeak()")
protected static final WeakVariablePointersObject doWeakPointersFallback(final SqueakImageContext image, final ClassObject classObject, final int extraSize) {
protected static final boolean instantiatesWeakVariablePointersObject(final ClassObject classObject) {
return classObject.isWeak();
}

protected static final ObjectLayout getWeakPointersLayoutOrNull(final ClassObject classObject) {
return instantiatesWeakVariablePointersObject(classObject) ? classObject.getLayout() : null;
}

@Specialization(guards = "instantiatesWeakVariablePointersObject(classObject)", replaces = "doWeakPointersCached")
protected static final WeakVariablePointersObject doWeakPointersUncached(final SqueakImageContext image, final ClassObject classObject, final int extraSize) {
return new WeakVariablePointersObject(image, classObject, extraSize);
}

Expand Down

1 comment on commit 782e95b

@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 (782e95b)

Benchmarks ran on graalvm-ce-java11-22.0.0.2.

Steady (after 50 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 180 275 185.82 181 185.1 37163 0.62
DeltaBlue 309 477 414.2 416 413.77 82840 1.38
Havlak 1716 1874 1783.59 1798 1783.33 356717 5.95
Json 743 805 754.73 752 754.68 150945 2.52
List 890 923 896.07 895 896.05 179213 2.99
Mandelbrot 144 189 145.26 145 145.23 29052 0.48
NBody 583 671 590.4 586 590.32 118080 1.97
Permute 236 269 238.24 237 238.18 47648 0.79
Queens 256 302 263.16 258 262.92 52632 0.88
Richards 1076 1156 1089.1 1078 1088.92 217819 3.63
Sieve 214 272 220.08 215 219.69 44016 0.73
Storage 289 323 292.83 289.5 292.74 58566 0.98
Towers 349 387 351.69 350 351.65 70337 1.17
6985 7923 7225.14 7200.5 7222.56 1445028 24.08

782e95b-2-steady.svg

Warmup (first 50 iterations)

782e95b-3-warmup.svg

Please sign in to comment.