Skip to content

Commit

Permalink
Various refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 16, 2023
1 parent 8efac83 commit 7c48444
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private static PointersObject instantiate(final ClassObject dummyClass) {
}

private static void writeAndValidate(final AbstractPointersObject obj, final int index, final Object value) {
AbstractPointersObjectWriteNode.getUncached().execute(null, obj, index, value);
assertEquals("Write failed", AbstractPointersObjectReadNode.getUncached().execute(null, obj, index), value);
AbstractPointersObjectWriteNode.executeUncached(obj, index, value);
assertEquals("Write failed", AbstractPointersObjectReadNode.executeUncached(obj, index), value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ private void run(final ContextObject thisContext) {
final PointersObject activeProcess = image.getActiveProcessSlow();
try {
/* Mark thisContext as suspended during tracing and writing. */
AbstractPointersObjectWriteNode.getUncached().execute(null, activeProcess, PROCESS.SUSPENDED_CONTEXT, thisContext);
AbstractPointersObjectWriteNode.executeUncached(activeProcess, PROCESS.SUSPENDED_CONTEXT, thisContext);
traceObjects();
writeImageHeader();
writeBody();
} finally {
/* Unmark thisContext as suspended. */
AbstractPointersObjectWriteNode.getUncached().executeNil(null, activeProcess, PROCESS.SUSPENDED_CONTEXT);
AbstractPointersObjectWriteNode.executeUncached(activeProcess, PROCESS.SUSPENDED_CONTEXT, NilObject.SINGLETON);
closeStream();
finalizeImageHeader();
}
Expand Down Expand Up @@ -242,7 +242,7 @@ public long toWord(final Object object) {
return toTaggedSmallInteger((long) object);
} else if (object instanceof Double) {
return toTaggedSmallFloat((double) object);
} else if (object instanceof AbstractSqueakObject aso) {
} else if (object instanceof AbstractSqueakObjectWithClassAndHash aso) {
final Long oop = oopMap.get(aso);
if (oop != null) {
return oop;
Expand All @@ -252,6 +252,7 @@ public long toWord(final Object object) {
}
} else {
/* Nil out any foreign objects. */
assert !(object instanceof AbstractSqueakObject);
return nilOop;
}
}
Expand Down Expand Up @@ -384,7 +385,7 @@ public void writeObjects(final Object[] objects) {
}

public void writeObjectIfTracedElseNil(final Object object) {
writeLong(toWord(object instanceof AbstractSqueakObject aso && oopMap.containsKey(aso) ? object : NilObject.SINGLETON));
writeLong(toWord(object instanceof AbstractSqueakObjectWithClassAndHash aso && oopMap.containsKey(aso) ? object : NilObject.SINGLETON));
}

private static long toTaggedCharacter(final long value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private void setSqueakDisplay(final PointersObject squeakDisplay) {

@TruffleBoundary
public void showDisplayRect(final int left, final int right, final int top, final int bottom) {
assert left < right && top < bottom;
assert left <= right && top <= bottom;
canvas.paintImmediately(left, top, right, bottom);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ public final int instsize() {

public final Object instVarAt0Slow(final long index) {
CompilerAsserts.neverPartOfCompilation();
return AbstractPointersObjectReadNode.getUncached().execute(null, this, index);
return AbstractPointersObjectReadNode.executeUncached(this, index);
}

public final void instVarAtPut0Slow(final long index, final Object value) {
CompilerAsserts.neverPartOfCompilation();
AbstractPointersObjectWriteNode.getUncached().execute(null, this, index, value);
AbstractPointersObjectWriteNode.executeUncached(this, index, value);
}

protected final boolean layoutValuesPointTo(final SqueakObjectIdentityNode identityNode, final Node inlineTarget, final Object thang) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ObjectLayout evolveLocation(final long longIndex, final Object value) {
throw SqueakException.create("Only the latest layout should be evolved");
}
final SlotLocation oldLocation = locations[index];
assert index < locations.length && !oldLocation.isGeneric();
assert !oldLocation.isGeneric();
invalidate();
final SlotLocation[] newLocations = locations.clone();
newLocations[index] = SlotLocation.UNINITIALIZED_LOCATION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public static AbstractPointersObjectReadNode getUncached() {

public abstract Object execute(Node node, AbstractPointersObject obj, long index);

public static final Object executeUncached(final AbstractPointersObject obj, final long index) {
return getUncached().execute(null, obj, index);
}

public abstract long executeLong(Node node, AbstractPointersObject obj, long index);

public abstract ArrayObject executeArray(Node node, AbstractPointersObject obj, long index);
Expand Down Expand Up @@ -95,6 +99,10 @@ public static AbstractPointersObjectWriteNode getUncached() {

public abstract void execute(Node node, AbstractPointersObject obj, long index, Object value);

public static final void executeUncached(final AbstractPointersObject obj, final long index, final Object value) {
getUncached().execute(null, obj, index, value);
}

public final void executeNil(final Node node, final AbstractPointersObject obj, final long index) {
execute(node, obj, index, NilObject.SINGLETON);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ protected static final void doArrayOfChars(final ArrayObject obj, final long ind
@Specialization(guards = {"obj.isCharType()", "isCharNilTag(value)"})
protected static final void doArrayOfCharsNilTagClash(final Node node, final ArrayObject obj, final long index, final char value,
@Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) {
/** `value` happens to be char nil tag, need to despecialize to be able store it. */
/** `value` happens to be char nil tag, need to despecialize to be able to store it. */
obj.transitionFromCharsToObjects(isNilTagProfile, node);
doArrayOfObjects(obj, index, value);
}
Expand All @@ -517,7 +517,7 @@ protected static final void doArrayOfLongs(final ArrayObject obj, final long ind
@Specialization(guards = {"obj.isLongType()", "isLongNilTag(value)"})
protected static final void doArrayOfLongsNilTagClash(final Node node, final ArrayObject obj, final long index, final long value,
@Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) {
/** `value` happens to be long nil tag, need to despecialize to be able store it. */
/** `value` happens to be long nil tag, need to despecialize to be able to store it. */
obj.transitionFromLongsToObjects(isNilTagProfile, node);
doArrayOfObjects(obj, index, value);
}
Expand All @@ -542,7 +542,7 @@ protected static final void doArrayOfDoubles(final ArrayObject obj, final long i
@Specialization(guards = {"obj.isDoubleType()", "isDoubleNilTag(value)"})
protected static final void doArrayOfDoublesNilTagClash(final Node node, final ArrayObject obj, final long index, final double value,
@Shared("isNilTagProfile") @Cached final InlinedConditionProfile isNilTagProfile) {
// `value` happens to be double nil tag, need to despecialize to be able store it.
// `value` happens to be double nil tag, need to despecialize to be able to store it.
obj.transitionFromDoublesToObjects(isNilTagProfile, node);
doArrayOfObjects(obj, index, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected static final CompiledCodeObject doObjectAsMethod(final Node node, fina
return method;
} else {
assert runWithInMethod == null : "runWithInMethod should not be another Object";
return doDoesNotUnderstand(image, targetObjectClass, runWithInMethod);
return doDoesNotUnderstand(image, targetObjectClass, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1304,11 +1304,7 @@ private void computeFinalWideBezierValueswidth(final int bezier, final int lineW
rightX = temp;
}
edgeXValueOfput(bezier, leftX);
if (rightX - leftX > lineWidth) {
wideBezierWidthOfput(bezier, rightX - leftX);
} else {
wideBezierWidthOfput(bezier, lineWidth);
}
wideBezierWidthOfput(bezier, Math.max(rightX - leftX, lineWidth));
}

/* BalloonEngineBase>>#computeSqrt: */
Expand Down Expand Up @@ -2497,16 +2493,8 @@ private boolean fillSpanfromto(final int fill, final int leftX, final int rightX
}
int x0;
int x1;
if (leftX < spanEndAAGet()) {
x0 = spanEndAAGet();
} else {
x0 = leftX;
}
if (rightX > shl(spanSizeGet(), aaShiftGet())) {
x1 = shl(spanSizeGet(), aaShiftGet());
} else {
x1 = rightX;
}
x0 = Math.max(leftX, spanEndAAGet());
x1 = Math.min(rightX, shl(spanSizeGet(), aaShiftGet()));
if (x0 < fillMinXGet()) {
x0 = fillMinXGet();
}
Expand Down Expand Up @@ -5695,7 +5683,7 @@ private void quickSortGlobalEdgeTablefromto(final int[] array, final int i, fina
di = dj;
dj = tt;
}
if (n <= 2) {
if (n == 2) {
return;
}
/* ij is the midpoint of i and j. */
Expand All @@ -5721,7 +5709,7 @@ private void quickSortGlobalEdgeTablefromto(final int[] array, final int i, fina
array[ij] = tmp;
dij = di;
}
if (n <= 3) {
if (n == 3) {
return;
}
int k = i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ public final class BitBlt {
private Object destBits;
private int destBitsBaseOffset;
private int destBitsIndexScale;
private long destDelta;
private int destDelta;
private int destDepth;
private PointersObject destForm;
private int destHeight;
private long destIndex;
private int destIndex;
private long destMask;
private boolean destMSB;
private int destPitch;
Expand Down Expand Up @@ -176,8 +176,8 @@ public final class BitBlt {
private long[] gammaLookupTable;
private AbstractSqueakObject halftoneForm;
private int[] halftoneBits;
private long halftoneHeight;
private long hDir;
private int halftoneHeight;
private int hDir;
private int height;
@SuppressWarnings("unused") private boolean isWarping;
private long mask1;
Expand All @@ -197,7 +197,7 @@ public final class BitBlt {
private Object sourceBits;
private int sourceBitsBaseOffset;
private int sourceBitsIndexScale;
private long sourceDelta;
private int sourceDelta;
private int sourceDepth;
private PointersObject sourceForm;
private int sourceHeight;
Expand All @@ -208,7 +208,7 @@ public final class BitBlt {
private int sourceWidth;
private int sourceX;
private int sourceY;
private long srcBitShift;
private int srcBitShift;
private int sx;
private int sy;
private long[] ungammaLookupTable;
Expand Down Expand Up @@ -880,7 +880,7 @@ private void copyLoop() {
assert -32 <= skew && skew <= 32; // Modified (image uses 31 instead of 32).

/* Byte delta */
final long hInc = hDir * 4;
final int hInc = hDir * 4;
final long unskew;
final long skewMask;
if (skew < 0) {
Expand Down Expand Up @@ -915,7 +915,7 @@ private void copyLoop() {
}
}

private void copyLoopCombinationRule3(final long initialHalftoneWord, final long hInc, final long notSkewMask, final long skewMask, final long unskew) {
private void copyLoopCombinationRule3(final long initialHalftoneWord, final int hInc, final long notSkewMask, final long skewMask, final long unskew) {
long halftoneWord = initialHalftoneWord;
int y = dy;
for (int i = 1; i <= bbH; i++) {
Expand Down Expand Up @@ -998,7 +998,7 @@ private void copyLoopCombinationRule3(final long initialHalftoneWord, final long
}
}

private void copyLoopGeneralCase(final long initialHalftoneWord, final long hInc, final long notSkewMask, final long skewMask, final long unskew) {
private void copyLoopGeneralCase(final long initialHalftoneWord, final int hInc, final long notSkewMask, final long skewMask, final long unskew) {
long halftoneWord = initialHalftoneWord;
int y = dy;
final LongBinaryOperator mergeFnwith = opTable[combinationRule + 1];
Expand Down Expand Up @@ -1625,7 +1625,7 @@ private boolean loadBitBltDestForm() {
}
destPPW = div(32, destDepth);
destPitch = div(destWidth + destPPW - 1, destPPW) * 4;
final long destBitsSize;
final int destBitsSize;
if (isWords(destBitsNative)) {
destBits = destBitsNative.getIntStorage();
destBitsSize = destBitsNative.getIntLength() * Integer.BYTES;
Expand Down Expand Up @@ -2235,13 +2235,13 @@ private void performCopyLoop() {
*/

/* BitBltSimulation>>#pickSourcePixels:flags:srcMask:destMask:srcShiftInc:dstShiftInc: */
private long pickSourcePixelsflagssrcMaskdestMasksrcShiftIncdstShiftInc(final long nPixels, final int mapperFlags, final long srcMask, final long dstMask, final long srcShiftInc,
final long dstShiftInc) {
private long pickSourcePixelsflagssrcMaskdestMasksrcShiftIncdstShiftInc(final long nPixels, final int mapperFlags, final long srcMask, final long dstMask, final int srcShiftInc,
final int dstShiftInc) {
long destWord = 0;
/* Hint: Keep in register */
long srcShift = srcBitShift;
int srcShift = srcBitShift;
/* Hint: Keep in register */
long dstShift = dstBitShift;
int dstShift = dstBitShift;
/* always > 0 so we can use do { } while(--nPix); */
long nPix = nPixels;
if (mapperFlags == (COLOR_MAP_PRESENT | COLOR_MAP_INDEXED_PART)) {
Expand Down Expand Up @@ -2289,7 +2289,7 @@ private long pickSourcePixelsflagssrcMaskdestMasksrcShiftIncdstShiftInc(final lo
*/

/* BitBltSimulation>>#pickWarpPixelAtX:y: */
private long pickWarpPixelAtXy(final long xx, final long yy) {
private int pickWarpPixelAtXy(final long xx, final long yy) {
/*
* note: it would be much faster if we could just avoid these stupid tests for being inside
* sourceForm.
Expand All @@ -2303,7 +2303,7 @@ private long pickWarpPixelAtXy(final long xx, final long yy) {
/* Extract pixel from word */
final long sourceWord = srcLongAt(srcIndex);
srcBitShift = warpBitShiftTable[(int) (x & warpAlignMask)];
return shr(sourceWord, srcBitShift) & warpSrcMask;
return (int) shr(sourceWord, srcBitShift) & warpSrcMask;
}

/*
Expand Down Expand Up @@ -2955,7 +2955,7 @@ private long rgbDiffwith(final long sourceWord, final long destinationWord) {
*/

/* BitBltSimulation>>#rgbMap16To32: */
private static long rgbMap16To32(final long sourcePixel) {
private static int rgbMap16To32(final int sourcePixel) {
return (sourcePixel & 0x1F) << 3 | (sourcePixel & 0x3E0) << 6 | (sourcePixel & 0x7C00) << 9;
}

Expand All @@ -2965,7 +2965,7 @@ private static long rgbMap16To32(final long sourcePixel) {
*/

/* BitBltSimulation>>#rgbMap32To32: */
private static long rgbMap32To32(final long sourcePixel) {
private static int rgbMap32To32(final int sourcePixel) {
return sourcePixel;
}

Expand Down Expand Up @@ -3642,31 +3642,29 @@ private long warpPickSmoothPixelsxDeltahyDeltahxDeltavyDeltavsourceMapsmoothingd
int x = sx;
int y = sy;
/* Pick and average n*n subpixels */
long a = 0;
long r = 0;
long g = 0;
long b = 0;
int a = 0;
int r = 0;
int g = 0;
int b = 0;
/* actual number of pixels (not clipped and not transparent) */
long nPix = 0;
int nPix = 0;
long j = n;
do {
int xx = x;
int yy = y;
long k = n;
do {
long rgb = pickWarpPixelAtXy(xx, yy);
int rgb = pickWarpPixelAtXy(xx, yy);
if (!(combinationRule == 25 && rgb == 0)) {
/* If not clipped and not transparent, then tally rgb values */
nPix++;
if (sourceDepth < 16) {
/* Get RGBA values from sourcemap table */
final int rawValue;
if (sourceMapIsWords) {
rawValue = UnsafeUtils.getInt((int[]) sourceMap, rgb);
rgb = UnsafeUtils.getInt((int[]) sourceMap, rgb);
} else {
rawValue = VarHandleUtils.getInt((byte[]) sourceMap, (int) rgb);
rgb = VarHandleUtils.getInt((byte[]) sourceMap, rgb);
}
rgb = Integer.toUnsignedLong(rawValue);
} else {
/* Already in RGB format */
if (sourceDepth == 16) {
Expand Down Expand Up @@ -3818,6 +3816,10 @@ private static boolean failed() {
return false;
}

private static int div(final int a, final int b) {
return a / b;
}

private static int div(final long a, final long b) {
return (int) (a / b);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ protected static final long doReadInts(@SuppressWarnings("unused") final Object
for (int index = 0; index < readInts; index++) {
target.setInt(startIndex - 1 + index, VarHandleUtils.getInt(bytes, index));
}
return Math.max(readInts, 0L); // `read` can be `-1`, Squeak expects zero.
return readInts;
}

@TruffleBoundary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ protected static final Object doConvert(final Object receiver, final NativeObjec
@Bind("aByteArray.getByteLength()") final int aByteArrayLength) {
for (int i = 0; i < aByteArrayLength; i++) {
final int wordIndex = i / 2;
final long value = aByteArray.getByteUnsigned(i) << 8;
final long value = (long) aByteArray.getByteUnsigned(i) << 8;
final int intValue;
if (i % 2 == 0) {
intValue = aSoundBuffer.getInt(wordIndex) & 0xffff0000 | (int) value & 0xffff;
Expand Down

0 comments on commit 7c48444

Please sign in to comment.