Skip to content

Commit

Permalink
Various cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Apr 20, 2022
1 parent 542cdc5 commit f75d54a
Show file tree
Hide file tree
Showing 27 changed files with 58 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,5 @@ jobs:
run: |
mx --env trufflesqueak-svm build --dependencies GRAALVM_TRUFFLESQUEAK_SVM_JAVA17
echo "$(mx --env trufflesqueak-svm graalvm-home)/bin" >> $GITHUB_PATH
- name: Run Cuis-Smalltalk tests on TruffleSqueak
- name: Run Cuis-Smalltalk tests on TruffleSqueak in native mode
run: trufflesqueak --native --headless --experimental-options --engine.CompilationFailureAction=ExitVM --engine.TreatPerformanceWarningsAsErrors=all images/Cuis6.0-????.image -s src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/runCuisTests.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public abstract class AbstractSqueakTestCase {
protected static SqueakImageContext image;
protected static PointersObject nilClassBinding;

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

protected static CompiledCodeObject makeMethod(final Object[] literals, final int... intbytes) {
protected static final CompiledCodeObject makeMethod(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 @@ -55,15 +55,15 @@ protected static CompiledCodeObject makeMethod(final Object[] literals, final in
return makeMethod(bytes, literals);
}

protected static long makeHeader(final int numArgs, final int numTemps, final int numLiterals, final boolean hasPrimitive, final boolean needsLargeFrame) { // shortcut
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);
}

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

protected static Object runMethod(final CompiledCodeObject code, final Object receiver, final Object... arguments) {
protected static final Object runMethod(final CompiledCodeObject code, final Object receiver, final Object... arguments) {
final VirtualFrame frame = createTestFrame(code);
Object result = null;
try {
Expand All @@ -74,11 +74,11 @@ protected static Object runMethod(final CompiledCodeObject code, final Object re
return result;
}

protected ExecuteTopLevelContextNode createContext(final CompiledCodeObject code, final Object receiver) {
protected static final ExecuteTopLevelContextNode createContext(final CompiledCodeObject code, final Object receiver) {
return createContext(code, receiver, ArrayUtils.EMPTY_ARRAY);
}

protected static ExecuteTopLevelContextNode createContext(final CompiledCodeObject code, final Object receiver, final Object[] arguments) {
protected static final ExecuteTopLevelContextNode createContext(final CompiledCodeObject code, final Object receiver, final Object[] arguments) {
final ContextObject testContext = ContextObject.create(image, code.getSqueakContextSize());
testContext.setReceiver(receiver);
testContext.setCodeObject(code);
Expand All @@ -96,34 +96,34 @@ protected static ExecuteTopLevelContextNode createContext(final CompiledCodeObje
return ExecuteTopLevelContextNode.create(image, null, testContext, false);
}

protected Object runMethod(final Object receiver, final int... intbytes) {
protected static final Object runMethod(final Object receiver, final int... intbytes) {
return runMethod(receiver, new AbstractSqueakObject[0], intbytes);
}

protected Object runMethod(final Object receiver, final Object[] arguments, final int... intbytes) {
protected static final Object runMethod(final Object receiver, final Object[] arguments, final int... intbytes) {
final CompiledCodeObject method = makeMethod(intbytes);
return runMethod(method, receiver, arguments);
}

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

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

protected Object runPrim(final Object[] literals, final int primCode, final Object rcvr, final Object... 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);
return runMethod(method, rcvr, arguments);
}

protected static VirtualFrame createTestFrame(final CompiledCodeObject code) {
protected static final VirtualFrame createTestFrame(final CompiledCodeObject code) {
final Object[] arguments = FrameAccess.newWith(code, NilObject.SINGLETON, null, new Object[]{NilObject.SINGLETON});
return Truffle.getRuntime().createVirtualFrame(arguments, code.getFrameDescriptor());
}

protected static SqueakImage loadImageContext(final String imagePath) {
protected static final SqueakImage loadImageContext(final String imagePath) {
assert context == null && image == null;
final Builder contextBuilder = Context.newBuilder();
contextBuilder.allowAllAccess(true);
Expand All @@ -150,7 +150,7 @@ protected static SqueakImage loadImageContext(final String imagePath) {
}
}

protected static void destroyImageContext() {
protected static final void destroyImageContext() {
// Close context if existing (for reloading mechanism).
context.close(true);
context = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import de.hpi.swa.trufflesqueak.model.LargeIntegerObject;
import de.hpi.swa.trufflesqueak.model.NilObject;

@SuppressWarnings("static-method")
public final class SqueakPrimitiveTest extends AbstractSqueakTestCaseWithDummyImage {
@Test
public void testPrimEquivalent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

public final class SqueakExceptions {

@SuppressWarnings("static-method")
@ExportLibrary(InteropLibrary.class)
protected abstract static class AbstractSqueakException extends AbstractTruffleException {
private static final long serialVersionUID = 1L;
Expand All @@ -51,17 +52,17 @@ protected AbstractSqueakException(final String message, final Node location) {

@ExportMessage
@TruffleBoundary
protected Object toDisplayString(@SuppressWarnings("unused") final boolean allowSideEffects) {
protected final Object toDisplayString(@SuppressWarnings("unused") final boolean allowSideEffects) {
return toString();
}

@ExportMessage
protected boolean hasLanguage() {
protected final boolean hasLanguage() {
return true;
}

@ExportMessage
protected Class<? extends TruffleLanguage<?>> getLanguage() {
protected final Class<? extends TruffleLanguage<?>> getLanguage() {
return SqueakLanguage.class;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import static com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
Expand Down Expand Up @@ -84,21 +83,4 @@ private static boolean isPrimitiveOrFromOtherLanguage(final Object value) {
throw shouldNotReachHere(e);
}
}

@TruffleBoundary
public static Object forValue(final Object value) {
if (value == null) {
return null;
}
final InteropLibrary lib = InteropLibrary.getFactory().getUncached(value);
try {
if (lib.hasLanguage(value) && lib.getLanguage(value) == SqueakLanguage.class) {
return value;
} else {
return create(value);
}
} catch (final UnsupportedMessageException e) {
throw shouldNotReachHere(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public final Object[] executeObjects(final Object... values) {
return wrappedElements;
}

public final ArrayObject executeList(final Object... values) {
return (ArrayObject) executeWrap(values);
}

@Specialization
protected static final boolean doBoolean(final boolean value) {
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
*/
package de.hpi.swa.trufflesqueak.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerDirectives;
Expand Down Expand Up @@ -238,7 +236,7 @@ public boolean isCompiledMethodClass() {
return this == image.compiledMethodClass;
}

public boolean includesBehavior(final ClassObject squeakClass) {
private boolean includesBehavior(final ClassObject squeakClass) {
ClassObject current = this;
while (current != null) {
if (current == squeakClass) {
Expand Down Expand Up @@ -413,23 +411,6 @@ public CompiledCodeObject lookupMethodInMethodDictSlow(final NativeObject select
return (CompiledCodeObject) lookupInMethodDictSlow(selector);
}

@TruffleBoundary
public Object[] listInteropMembers() {
final List<String> methodNames = new ArrayList<>();
ClassObject lookupClass = this;
while (lookupClass != null) {
final VariablePointersObject methodDictObject = lookupClass.getMethodDict();
final Object[] methodDictVariablePart = methodDictObject.getVariablePart();
for (final Object methodSelector : methodDictVariablePart) {
if (methodSelector instanceof NativeObject) {
methodNames.add(((NativeObject) methodSelector).asStringUnsafe().replace(':', '_'));
}
}
lookupClass = lookupClass.getSuperclassOrNull();
}
return methodNames.toArray(new String[0]);
}

public int getBasicInstanceSize() {
return (int) (format & 0xffff);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public final class CompiledCodeObject extends AbstractSqueakObjectWithClassAndHa
* Literals are cached in the AST and bytes are represented by nodes, so this should not affect
* performance. Find out why it does affect performance.
*/
@CompilationFinal(dimensions = 1) protected Object[] literals;
@CompilationFinal(dimensions = 1) protected byte[] bytes;
@CompilationFinal protected int numArgs;
@CompilationFinal protected int numLiterals;
@CompilationFinal protected boolean hasPrimitive;
@CompilationFinal protected boolean needsLargeFrame;
@CompilationFinal protected int numTemps;
@CompilationFinal(dimensions = 1) private Object[] literals;
@CompilationFinal(dimensions = 1) private byte[] bytes;
@CompilationFinal private int numArgs;
@CompilationFinal private int numLiterals;
@CompilationFinal private boolean hasPrimitive;
@CompilationFinal private boolean needsLargeFrame;
@CompilationFinal private int numTemps;

private AbstractSqueakBytecodeDecoder decoder;

Expand Down Expand Up @@ -103,14 +103,14 @@ public CompiledCodeObject(final SqueakImageContext image, final byte[] bc, final
bytes = bc;
}

protected CompiledCodeObject(final CompiledCodeObject original) {
private CompiledCodeObject(final CompiledCodeObject original) {
super(original);
frameDescriptor = original.frameDescriptor;
setLiteralsAndBytes(original.literals.clone(), original.bytes.clone());
decoder = original.decoder;
}

protected CompiledCodeObject(final CompiledCodeObject outerCode, final int startPC) {
private CompiledCodeObject(final CompiledCodeObject outerCode, final int startPC) {
super(outerCode);
outerCode.shadowBlocks.put(startPC, this);

Expand Down Expand Up @@ -222,7 +222,7 @@ private void renewCallTarget() {
initializeCallTargetUnsafe();
}

protected void initializeCallTargetUnsafe() {
private void initializeCallTargetUnsafe() {
CompilerAsserts.neverPartOfCompilation();
final SqueakLanguage language = SqueakImageContext.getSlow().getLanguage();
final RootNode rootNode;
Expand Down Expand Up @@ -322,7 +322,7 @@ public int findLineNumber(final int index) {
return decoder.findLineNumber(this, index);
}

protected void decodeHeader() {
private void decodeHeader() {
CompilerDirectives.transferToInterpreterAndInvalidate();
final long header = (long) literals[0];
numLiterals = CompiledCodeHeaderDecoder.getNumLiterals(header);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,6 @@ public int compareTo(final long b) {
}
}

@TruffleBoundary(transferToInterpreterOnException = false)
public double doubleValue() {
return integer.doubleValue();
}

/** {@link BigInteger#signum()} does not need a {@link TruffleBoundary}. */
public boolean isZero() {
return integer.signum() == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public static Object nullToNil(final Object object) {
return object == null ? SINGLETON : object;
}

public static Object nullToNil(final Object object, final ConditionProfile profile) {
return profile.profile(object == null) ? SINGLETON : object;
}

@Override
public long getSqueakHash() {
return SQUEAK_HASH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public final void unset(final AbstractPointersObject object) {
}
}

protected static int getPrimitiveUsedMask(final int index) {
private static int getPrimitiveUsedMask(final int index) {
assert 0 <= index && index < Integer.SIZE;
return 1 << index;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import de.hpi.swa.trufflesqueak.model.NilObject;

public final class DoItRootNode extends RootNode {
@Child protected WrapToSqueakNode wrapNode = WrapToSqueakNode.create();
@Child private WrapToSqueakNode wrapNode = WrapToSqueakNode.create();
private final SqueakImageContext image;
private final Object maybeClosure;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public final class ExecuteBytecodeNode extends AbstractExecuteContextNode {
private static final int LOCAL_RETURN_PC = -2;

protected final CompiledCodeObject code;
private final CompiledCodeObject code;
private final int initialPC;
private SourceSection section;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Object execute(final VirtualFrame frame) {
}

@ExplodeLoop
public void initializeFrame(final VirtualFrame frame) {
private void initializeFrame(final VirtualFrame frame) {
if (writeTempNodes == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
final BlockClosureObject closure = FrameAccess.getClosure(frame);
Expand All @@ -88,8 +88,8 @@ public void initializeFrame(final VirtualFrame frame) {

// TODO: avoid nilling out of temp slots to allow slot specializations
// Initialize remaining temporary variables with nil in newContext.
for (int i = 0; i < writeTempNodes.length; i++) {
writeTempNodes[i].executeWrite(frame, NilObject.SINGLETON);
for (final FrameStackWriteNode node : writeTempNodes) {
node.executeWrite(frame, NilObject.SINGLETON);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public static ArrayObjectCopyIntoObjectArrayNode create(final int offset) {
}

public static ArrayObjectCopyIntoObjectArrayNode createForFrameArguments() {
return ArrayObjectCopyIntoObjectArrayNodeGen.create(FrameAccess.getArgumentStartIndex());
return create(FrameAccess.getArgumentStartIndex());
}

public abstract void execute(Object[] target, ArrayObject obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ private static Object getPushValue(final Object literal) {
}

public static final class PushNewArrayNode extends AbstractPushNode {
@Child protected ArrayNode arrayNode;
@Child private ArrayNode arrayNode;

protected PushNewArrayNode(final CompiledCodeObject code, final int index, final int numBytecodes, final byte param) {
super(code, index, numBytecodes);
Expand Down Expand Up @@ -469,7 +469,7 @@ public ArrayNode(final int arraySize) {
}

protected static final class ArrayFromStackNode extends ArrayNode {
@Child protected FrameStackPopNNode popNNode;
@Child private FrameStackPopNNode popNNode;

public ArrayFromStackNode(final int arraySize) {
super(arraySize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final Object executeReturn(final VirtualFrame frame) {
}

public abstract static class AbstractNormalReturnNode extends AbstractReturnNode {
@Child protected AbstractReturnKindNode returnNode;
@Child private AbstractReturnKindNode returnNode;

protected AbstractNormalReturnNode(final VirtualFrame frame, final CompiledCodeObject code, final int index) {
super(code, index);
Expand Down

0 comments on commit f75d54a

Please sign in to comment.