Skip to content

Commit

Permalink
Fix invalid layout handling
Browse files Browse the repository at this point in the history
Cached cases always only contain valid layouts. Objects with invalid layout caused the caches to overflow, which in turn resulted in a lot of megamorphic reports and with that a lot of splitting. For the same reason, AbstractPointersObjectGuard is dropped.
  • Loading branch information
fniephaus committed Feb 23, 2025
1 parent 57fb986 commit c991ed9
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,9 @@ public final ObjectLayout getLayout() {
return layout;
}

public final boolean matchesLayout(final ObjectLayout expectedLayout) {
if (!getLayout().isValid()) {
CompilerDirectives.transferToInterpreterAndInvalidate();
updateLayout();
}
assert layout.isValid() : "Should only ever match valid layout (invalid expectedLayout will be replaced in PIC)";
return layout == expectedLayout;
public final ObjectLayout getValidLayoutOrNull() {
CompilerAsserts.neverPartOfCompilation();
return layout.isValid() ? layout : null;
}

public final void changeClassTo(final ClassObject newClass) {
Expand All @@ -161,14 +157,15 @@ public final void updateLayout() {
@TruffleBoundary
public final ObjectLayout updateLayout(final long index, final Object value) {
assert !layout.getLocation(index).canStore(value);
ObjectLayout latestLayout = getSqueakClass().getLayout();
final ClassObject squeakClass = getSqueakClass();
ObjectLayout latestLayout = squeakClass.getLayout();
if (!latestLayout.getLocation(index).canStore(value)) {
latestLayout = latestLayout.evolveLocation(index, value);
latestLayout = latestLayout.evolveLocation(squeakClass, index, value);
} else {
assert !layout.isValid() && layout != latestLayout : "Layout must have changed";
}
migrateToLayout(latestLayout);
return getSqueakClass().getLayout(); /* Layout may have evolved again during migration. */
return squeakClass.getLayout(); /* Layout may have evolved again during migration. */
}

@TruffleBoundary
Expand All @@ -178,6 +175,7 @@ private void migrateToLayout(final ObjectLayout targetLayout) {
final ObjectLayout oldLayout = layout;
assert oldLayout.getInstSize() == newLayout.getInstSize();
final int instSize = oldLayout.getInstSize();
final ClassObject squeakClass = getSqueakClass();
final Object[] values = new Object[instSize];
for (int i = 0; i < instSize; i++) {
final SlotLocation oldLocation = oldLayout.getLocation(i);
Expand All @@ -186,7 +184,7 @@ private void migrateToLayout(final ObjectLayout targetLayout) {
final Object oldValue = oldLocation.read(this);
oldLocation.unset(this);
if (!newLocation.canStore(oldValue)) {
newLayout = newLayout.evolveLocation(i, oldValue);
newLayout = newLayout.evolveLocation(squeakClass, i, oldValue);
}
values[i] = oldValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import de.hpi.swa.trufflesqueak.util.UnsafeUtils;

public final class ObjectLayout {
private final ClassObject squeakClass;
@CompilationFinal(dimensions = 1) private final SlotLocation[] locations;
private final int numPrimitiveExtension;
private final int numObjectExtension;
Expand All @@ -30,7 +29,6 @@ public final class ObjectLayout {

public ObjectLayout(final ClassObject classObject, final int instSize) {
slowPathOperation();
squeakClass = classObject;
classObject.updateLayout(this);
locations = new SlotLocation[instSize];
Arrays.fill(locations, SlotLocation.UNINITIALIZED_LOCATION);
Expand All @@ -40,14 +38,13 @@ public ObjectLayout(final ClassObject classObject, final int instSize) {

public ObjectLayout(final ClassObject classObject, final SlotLocation[] locations) {
slowPathOperation();
squeakClass = classObject;
classObject.updateLayout(this);
this.locations = locations;
numPrimitiveExtension = countPrimitiveExtension(locations);
numObjectExtension = countObjectExtension(locations);
}

public ObjectLayout evolveLocation(final long longIndex, final Object value) {
public ObjectLayout evolveLocation(final ClassObject squeakClass, final long longIndex, final Object value) {
slowPathOperation();
final int index = Math.toIntExact(longIndex);
if (!isValid()) {
Expand Down Expand Up @@ -210,10 +207,6 @@ public boolean isValid() {
return isValidAssumption.isValid();
}

public ClassObject getSqueakClass() {
return squeakClass;
}

public SlotLocation getLocation(final long index) {
return (SlotLocation) UnsafeUtils.getObject(locations, index);
}
Expand Down Expand Up @@ -268,6 +261,6 @@ private static int countObjectExtension(final SlotLocation[] locations) {
@Override
public String toString() {
CompilerAsserts.neverPartOfCompilation();
return (isValid() ? "valid" : "invalid") + " ObjectLayout for " + squeakClass + " @" + Integer.toHexString(hashCode());
return (isValid() ? "valid" : "invalid") + " ObjectLayout @" + Integer.toHexString(hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public final class CacheLimits {
public static final int INLINE_BLOCK_CACHE_LIMIT = 4;
public static final int INLINE_METHOD_CACHE_LIMIT = 4;
public static final int PERFORM_SELECTOR_CACHE_LIMIT = 4;
public static final int POINTERS_LAYOUT_CACHE_LIMIT = 4;
public static final int POINTERS_VARIABLE_PART_CACHE_LIMIT = 3;
}
Loading

2 comments on commit c991ed9

@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 (c991ed9)

Benchmarks ran on 23.0.2-graal.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 548 563 552.3 549 552.28 110460 1.84
CD 607 627 612.44 608 612.4 122488 2.04
DeltaBlue 303 474 427.47 423 426.57 85494 1.42
Havlak 1094 1144 1121.92 1121 1121.88 224383 3.74
Json 335 351 338.8 336 338.76 67759 1.13
List 351 381 353.53 352 353.49 70706 1.18
Mandelbrot 129 153 130.64 130 130.59 26128 0.44
NBody 252 273 256.67 253 256.61 51333 0.86
Permute 164 179 165.26 165 165.23 33051 0.55
Queens 235 264 238.5 237 238.45 47700 0.8
Richards 896 914 901.01 898 900.99 180202 3
Sieve 170 185 171.17 170 171.14 34233 0.57
Storage 143 211 146.6 144 146.46 29321 0.49
Towers 205 228 207.08 206 207.03 41416 0.69
5432 5947 5623.37 5592 5621.89 1124674 18.74

c991ed9-2-steady.svg

Warmup (first 100 iterations)

c991ed9-3-warmup.svg

@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 (c991ed9)

Benchmarks ran on 23.0.2-graal.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 554 569 558.71 555 558.69 111742 1.86
CD 609 635 614.48 610 614.42 122895 2.05
DeltaBlue 308 503 454.95 466 453.38 90989 1.52
Havlak 1105 1154 1126.63 1126 1126.6 225325 3.76
Json 338 354 341.51 339 341.47 68301 1.14
List 354 376 357 355 356.96 71400 1.19
Mandelbrot 129 160 130.85 130 130.79 26169 0.44
NBody 252 276 256.77 253 256.71 51355 0.86
Permute 163 177 164.37 164 164.35 32874 0.55
Queens 230 260 233.79 232 233.73 46757 0.78
Richards 904 1014 913.26 915 913.2 182652 3.04
Sieve 172 190 173.23 173 173.21 34646 0.58
Storage 144 161 146.54 144 146.48 29309 0.49
Towers 206 229 208.36 207 208.31 41672 0.69
5468 6058 5680.43 5669 5678.29 1136086 18.93

c991ed9-2-steady.svg

Warmup (first 100 iterations)

c991ed9-3-warmup.svg

Please sign in to comment.