Skip to content

Commit

Permalink
Store CompiledCodeObject header in long field
Browse files Browse the repository at this point in the history
Reduces Long allocations, for the test image:
- before: 174,723 (6.8%) / 4,193,352 B (2.7%)
- after: 45,499 (1.9%) / 1,091,976 B (0.7%)
  • Loading branch information
fniephaus committed Oct 19, 2024
1 parent 4251359 commit c92e331
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public abstract class AbstractSqueakTestCase {
protected static SqueakImageContext image;
protected static PointersObject nilClassBinding;

protected static final CompiledCodeObject makeMethod(final byte[] bytes, final Object[] literals) {
return new CompiledCodeObject(image, bytes, literals, image.compiledMethodClass);
protected static final CompiledCodeObject makeMethod(final byte[] bytes, final long header, final Object[] literals) {
return new CompiledCodeObject(image, bytes, header, literals, image.compiledMethodClass);
}

protected static final CompiledCodeObject makeMethod(final Object[] literals, final int... intbytes) {
protected static final CompiledCodeObject makeMethod(final long header, final Object[] literals, final int... intbytes) {
final byte[] bytes = new byte[intbytes.length + 1];
for (int i = 0; i < intbytes.length; i++) {
bytes[i] = (byte) intbytes[i];
Expand All @@ -53,15 +53,15 @@ protected static final CompiledCodeObject makeMethod(final Object[] literals, fi
final Object[] allLiterals = Arrays.copyOf(literals, literals.length + 2);
allLiterals[allLiterals.length - 2] = image.asByteString("DoIt"); // compiledInSelector
allLiterals[allLiterals.length - 1] = nilClassBinding; // methodClassAssociation
return makeMethod(bytes, allLiterals);
return makeMethod(bytes, header, allLiterals);
}

protected static final long makeHeader(final int numArgs, final int numTemps, final int numLiterals, final boolean hasPrimitive, final boolean needsLargeFrame) { // shortcut
return CompiledCodeObject.makeHeader(true, numArgs, numTemps, numLiterals, hasPrimitive, needsLargeFrame);
}

private static CompiledCodeObject makeMethod(final int... intbytes) {
return makeMethod(new Object[]{makeHeader(0, 5, 14, false, true)}, intbytes);
return makeMethod(makeHeader(0, 5, 14, false, true), new Object[0], intbytes);
}

protected static final Object runMethod(final CompiledCodeObject code, final Object receiver, final Object... arguments) {
Expand Down Expand Up @@ -106,15 +106,15 @@ protected static final Object runMethod(final Object receiver, final Object[] ar
}

protected static final Object runBinaryPrimitive(final int primCode, final Object rcvr, final Object... arguments) {
return runPrim(new Object[]{17104899L}, primCode, rcvr, arguments);
return runPrim(17104899L, new Object[0], primCode, rcvr, arguments);
}

protected static final Object runQuinaryPrimitive(final int primCode, final Object rcvr, final Object... arguments) {
return runPrim(new Object[]{68222979L}, primCode, rcvr, arguments);
return runPrim(68222979L, new Object[0], primCode, rcvr, arguments);
}

protected static final Object runPrim(final Object[] literals, final int primCode, final Object rcvr, final Object... arguments) {
final CompiledCodeObject method = makeMethod(literals, 139, primCode & 0xFF, (primCode & 0xFF00) >> 8);
protected static final Object runPrim(final long header, final Object[] literals, final int primCode, final Object rcvr, final Object... arguments) {
final CompiledCodeObject method = makeMethod(header, literals, 139, primCode & 0xFF, (primCode & 0xFF00) >> 8);
return runMethod(method, rcvr, arguments);
}

Expand Down
Loading

1 comment on commit c92e331

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

Benchmarks ran on 22.0.2-graal.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 515 524 517.69 516 517.68 103538 1.73
CD 488 501 491.91 490 491.89 98381 1.64
DeltaBlue 280 481 415.1 413 413.54 83019 1.38
Havlak 1134 1187 1166.59 1171 1166.52 233318 3.89
Json 378 394 381.06 379 381.05 76212 1.27
List 309 319 309.87 310 309.87 61974 1.03
Mandelbrot 127 137 127.48 127 127.47 25495 0.42
NBody 255 265 258.26 257 258.24 51652 0.86
Permute 154 168 155.57 155 155.57 31115 0.52
Queens 230 242 231.12 231 231.11 46224 0.77
Richards 1219 1227 1222.47 1223 1222.47 244494 4.07
Sieve 177 193 178.02 178 178.01 35604 0.59
Storage 141 149 142.57 141 142.55 28513 0.48
Towers 200 212 201.18 201 201.17 40235 0.67
5607 5999 5798.87 5792 5797.13 1159774 19.33

c92e331-2-steady.svg

Warmup (first 100 iterations)

c92e331-3-warmup.svg

Please sign in to comment.