Skip to content

Commit

Permalink
Add support for the 68533 image format
Browse files Browse the repository at this point in the history
and maintain image format in `SqueakImageContext`.

Fixes #156
  • Loading branch information
fniephaus committed May 22, 2022
1 parent da671d3 commit 10388ec
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ public final class SqueakImageConstants {

/** General. */
public static final int WORD_SIZE = Long.BYTES;
public static final int IMAGE_FORMAT = 68021;
public static final int MULTIPLE_BYTECODE_SETS_BITMASK = 0x200;
public static final int IMAGE_HEADER_SIZE = WORD_SIZE * 16;
public static final int IMAGE_HEADER_MEMORY_SIZE_POSITION = WORD_SIZE;
public static final int IMAGE_HEADER_FIRST_FRAGMENT_SIZE_POSITION = 9 * WORD_SIZE;
public static final int IMAGE_BRIDGE_SIZE = 2 * WORD_SIZE; /* bridge and nextSegmentSize. */
public static final int[] SUPPORTED_IMAGE_FORMATS = new int[]{68021, 68021 | MULTIPLE_BYTECODE_SETS_BITMASK};

/** Object Header. */
public static final long OVERFLOW_SLOTS = 255;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public final class SqueakImageContext {
/* System Information */
public final SqueakImageFlags flags = new SqueakImageFlags();
private String imagePath;
@CompilationFinal public int imageFormat = 0;
private final TruffleFile homePath;
@CompilationFinal(dimensions = 1) private byte[] resourcesDirectoryBytes;
@CompilationFinal(dimensions = 1) private byte[] resourcesPathBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

Expand All @@ -27,6 +28,7 @@
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.SPECIAL_OBJECT;
import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.SPECIAL_OBJECT_TAG;
import de.hpi.swa.trufflesqueak.nodes.accessing.ArrayObjectNodes.ArrayObjectReadNode;
import de.hpi.swa.trufflesqueak.util.ArrayUtils;
import de.hpi.swa.trufflesqueak.util.MiscUtils;
import de.hpi.swa.trufflesqueak.util.UnsafeUtils;

Expand Down Expand Up @@ -155,9 +157,10 @@ private void skipBytes(final long count) {
}

private void readVersion() {
final long version = nextInt();
if (version != SqueakImageConstants.IMAGE_FORMAT) {
throw SqueakException.create(MiscUtils.format("Image format %s not supported. Please supply a 64bit Spur image (format %s).", version, SqueakImageConstants.IMAGE_FORMAT));
image.imageFormat = nextInt();
if (!ArrayUtils.contains(SqueakImageConstants.SUPPORTED_IMAGE_FORMATS, image.imageFormat)) {
throw SqueakException.create(MiscUtils.format("Image format %s not supported. Please supply a compatible 64bit Spur image (%s).", image.imageFormat,
Arrays.toString(SqueakImageConstants.SUPPORTED_IMAGE_FORMATS)));
}
// nextWord(); // magic2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ private void run(final ContextObject thisContext) {
}

private void writeImageHeader() {
assert position == 0;
assert position == 0 && image.imageFormat != 0;
/* Write basic header. */
writeInt(SqueakImageConstants.IMAGE_FORMAT);
writeInt(image.imageFormat);
writeInt(SqueakImageConstants.IMAGE_HEADER_SIZE); // hdr size
assert position == SqueakImageConstants.IMAGE_HEADER_MEMORY_SIZE_POSITION;
writeLong(0); // memory size (yet unknown, see finalizeFileHeader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.oracle.truffle.api.profiles.ConditionProfile;

import de.hpi.swa.trufflesqueak.exceptions.PrimitiveExceptions.PrimitiveFailed;
import de.hpi.swa.trufflesqueak.image.SqueakImageConstants;
import de.hpi.swa.trufflesqueak.image.SqueakImageContext;
import de.hpi.swa.trufflesqueak.model.AbstractPointersObject;
import de.hpi.swa.trufflesqueak.model.AbstractSqueakObject;
Expand Down Expand Up @@ -852,7 +851,7 @@ protected static final Object vmParameterAt(final SqueakImageContext image, fina
case 38: return 0L; // milliseconds taken by current IGC (read-only)
case 39: return MiscUtils.getObjectPendingFinalizationCount(); // Number of finalization signals for Weak Objects pending when current IGC/FGC completed (read-only)
case 40: return 8L; // BytesPerOop for this image
case 41: return (long) SqueakImageConstants.IMAGE_FORMAT; // imageFormatVersion for the VM
case 41: return (long) image.imageFormat; // imageFormatVersion for the VM
case 42: return 50L; // number of stack pages in use (see SmalltalkImage>>isRunningCog)
case 43: return 0L; // desired number of stack pages (stored in image file header, max 65535)
case 44: return 0L; // size of eden, in bytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public static boolean contains(final char[] objects, final char element) {
return false;
}

public static boolean contains(final int[] objects, final int element) {
for (final long object : objects) {
if (object == element) {
return true;
}
}
return false;
}

public static boolean contains(final long[] objects, final long element) {
for (final long object : objects) {
if (object == element) {
Expand Down

0 comments on commit 10388ec

Please sign in to comment.