Skip to content

Commit

Permalink
Various code improvements (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarr authored Dec 17, 2024
2 parents f97f168 + b37e33c commit e9d8032
Show file tree
Hide file tree
Showing 42 changed files with 118 additions and 106 deletions.
29 changes: 13 additions & 16 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ variables:
mx sforceimport
mx --env libgraal build

ensure_labsjdk: &ENSURE_LABSJDK_AND_GRAAL_VERSION |
./som --setup labsjdk
mx sforceimport
rm libs/jvmci || true
./som --setup labsjdk

before_script:
- (cd core-lib && git remote add smarr https://github.com/smarr/SOM.git || true; git fetch --all)
- git submodule update --init
Expand Down Expand Up @@ -52,10 +58,8 @@ test:
stage: build-and-test
tags: [yuria4]
script:
- ./som --setup labsjdk
- mx sforceimport
- rm libs/jvmci || true
- ./som --setup labsjdk
- *ENSURE_LABSJDK_AND_GRAAL_VERSION

- mx build
- mx tests-junit
- mx tests-som
Expand All @@ -73,10 +77,8 @@ build:native-interp-ast:
stage: build-and-test
tags: [yuria2]
script:
- ./som --setup labsjdk
- mx sforceimport
- rm libs/jvmci || true
- ./som --setup labsjdk
- *ENSURE_LABSJDK_AND_GRAAL_VERSION

- mx build
- mx build-native --no-jit -t AST -bn
- ./som-native-interp-ast -cp Smalltalk TestSuite/TestHarness.som
Expand All @@ -98,10 +100,8 @@ build:native-interp-bc:
stage: build-and-test
tags: [yuria3]
script:
- ./som --setup labsjdk
- mx sforceimport
- rm libs/jvmci || true
- ./som --setup labsjdk
- *ENSURE_LABSJDK_AND_GRAAL_VERSION

- mx build
- mx build-native --no-jit -t BC -bn
- ./som-native-interp-bc -cp Smalltalk TestSuite/TestHarness.som
Expand All @@ -125,10 +125,7 @@ build:aarch64-test-and-rebench:
- pmset -g live
- pmset -g systemstate

- ./som --setup labsjdk
- mx sforceimport
- rm libs/jvmci || true
- ./som --setup labsjdk
- *ENSURE_LABSJDK_AND_GRAAL_VERSION

- mx build
- mx --env libgraal build
Expand Down
12 changes: 5 additions & 7 deletions mx.trufflesom/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,11 @@
"exports": [
"trufflesom.* to org.graalvm.truffle",
],
"requires": ["jdk.unsupported"], # sun.misc.Unsafe
"requiresConcealed": {
"org.graalvm.truffle": [
"com.oracle.truffle.api",
"com.oracle.truffle.api.instrumentation",
],
},
"requires": [
"jdk.unsupported",
"org.graalvm.collections",
"org.graalvm.polyglot",
],
},
"dependencies": ["trufflesom"],
"distDependencies": [
Expand Down
5 changes: 4 additions & 1 deletion som
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ TWEAK_INLINING = ['-Dpolyglot.engine.CompilationThreshold=191',
'-Dpolyglot.engine.InliningMaxCallerSize=10000',
'-Dpolyglot.engine.SplittingMaxCalleeSize=100000']

JAVA_ARGS = ['-server', '-XX:+UseParallelGC']
JAVA_ARGS = [
'-server', '-XX:+UseParallelGC',
'--enable-native-access=org.graalvm.truffle'
]

##
## Processing Parameters and Assembling Command Line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
package trufflesom.interpreter.nodes;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
Expand All @@ -47,8 +50,16 @@ public final boolean accessesOuterContext() {
return contextLevel > 0;
}

@ExplodeLoop
protected final MaterializedFrame determineContext(final VirtualFrame frame) {
return determineContext(frame, contextLevel);
}

@ExplodeLoop
@InliningCutoff
public static final MaterializedFrame determineContext(final VirtualFrame frame,
final int contextLevel) {
CompilerAsserts.partialEvaluationConstant(contextLevel);

SBlock self = (SBlock) frame.getArguments()[0];
int i = contextLevel - 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import static trufflesom.interpreter.bc.Bytecodes.SUPER_SEND;
import static trufflesom.interpreter.bc.Bytecodes.getBytecodeLength;
import static trufflesom.interpreter.bc.Bytecodes.getBytecodeName;
import static trufflesom.interpreter.nodes.ContextualNode.determineContext;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -233,23 +234,6 @@ private static VirtualFrame determineOuterContext(final VirtualFrame frame) {
}
}

@ExplodeLoop
@InliningCutoff
private static MaterializedFrame determineContext(final VirtualFrame frame,
final int contextLevel) {
SBlock self = (SBlock) frame.getArguments()[0];
int i = contextLevel - 1;

while (i > 0) {
self = (SBlock) self.getOuterSelf();
i--;
}

// Graal needs help here to see that this is always a MaterializedFrame
// so, we record explicitly a class profile
return frameType.profile(self.getContext());
}

@InliningCutoff
private AbstractReadFieldNode createRead(final int bytecodeIndex, final int fieldIndex) {
CompilerDirectives.transferToInterpreterAndInvalidate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package trufflesom.interpreter.nodes.nary;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.frame.VirtualFrame;

import com.oracle.truffle.api.nodes.Node;
import trufflesom.vmobjects.SSymbol;


Expand All @@ -12,10 +14,11 @@ public abstract class BinaryMsgExprNode extends BinaryExpressionNode {
public abstract SSymbol getSelector();

@Fallback
public final Object makeGenericSend(final VirtualFrame frame,
final Object receiver, final Object argument) {
public static final Object makeGenericSend(final VirtualFrame frame,
final Object receiver, final Object argument, @Bind Node s) {
CompilerDirectives.transferToInterpreterAndInvalidate();
return makeGenericSend(getSelector()).doPreEvaluated(frame,
BinaryMsgExprNode self = (BinaryMsgExprNode) s;
return self.makeGenericSend(self.getSelector()).doPreEvaluated(frame,
new Object[] {receiver, argument});
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package trufflesom.interpreter.nodes.nary;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.frame.VirtualFrame;

import com.oracle.truffle.api.nodes.Node;
import trufflesom.vmobjects.SSymbol;


public abstract class QuaternaryMsgExprNode extends QuaternaryExpressionNode {
public abstract SSymbol getSelector();

@Fallback
public final Object makeGenericSend(final VirtualFrame frame,
final Object receiver, final Object arg1, final Object arg2, final Object arg3) {
public static final Object makeGenericSend(final VirtualFrame frame,
final Object receiver, final Object arg1, final Object arg2, final Object arg3,
@Bind Node s) {
CompilerDirectives.transferToInterpreterAndInvalidate();
return makeGenericSend(getSelector()).doPreEvaluated(frame,
QuaternaryMsgExprNode self = (QuaternaryMsgExprNode) s;
return self.makeGenericSend(self.getSelector()).doPreEvaluated(frame,
new Object[] {receiver, arg1, arg2, arg3});
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package trufflesom.interpreter.nodes.nary;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.frame.VirtualFrame;

import com.oracle.truffle.api.nodes.Node;
import trufflesom.vmobjects.SSymbol;


Expand All @@ -12,10 +14,11 @@ public abstract class TernaryMsgExprNode extends TernaryExpressionNode {
public abstract SSymbol getSelector();

@Fallback
public final Object makeGenericSend(final VirtualFrame frame,
final Object receiver, final Object arg1, final Object arg2) {
public static final Object makeGenericSend(final VirtualFrame frame,
final Object receiver, final Object arg1, final Object arg2, @Bind Node s) {
CompilerDirectives.transferToInterpreterAndInvalidate();
return makeGenericSend(getSelector()).doPreEvaluated(frame,
TernaryMsgExprNode self = (TernaryMsgExprNode) s;
return self.makeGenericSend(self.getSelector()).doPreEvaluated(frame,
new Object[] {receiver, arg1, arg2});
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package trufflesom.interpreter.nodes.nary;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.frame.VirtualFrame;

import com.oracle.truffle.api.nodes.Node;
import trufflesom.vmobjects.SSymbol;


public abstract class UnaryMsgExprNode extends UnaryExpressionNode {
public abstract SSymbol getSelector();

@Fallback
public final Object makeGenericSend(final VirtualFrame frame, final Object receiver) {
public static final Object makeGenericSend(final VirtualFrame frame, final Object receiver,
@Bind Node s) {
CompilerDirectives.transferToInterpreterAndInvalidate();
return makeGenericSend(getSelector()).doPreEvaluated(frame, new Object[] {receiver});
UnaryMsgExprNode self = (UnaryMsgExprNode) s;
return self.makeGenericSend(self.getSelector()).doPreEvaluated(frame,
new Object[] {receiver});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static final boolean doAnd(final boolean receiver, final boolean argument
}

@Override
public SSymbol getSelector() {
public final SSymbol getSelector() {
if (getSourceChar(0) == '&') {
return SymbolTable.symbolFor("&&");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public final boolean doAnd(final boolean receiver, final SBlock argument) {
}

@Override
public SSymbol getSelector() {
public final SSymbol getSelector() {
if (getSourceChar(0) == '&') {
return SymbolTable.symbolFor("&&");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public IfTrueMessageNode() {
}

@Override
public SSymbol getSelector() {
public final SSymbol getSelector() {
return SymbolTable.symbolFor("ifTrue:");
}
}
Expand All @@ -44,7 +44,7 @@ public IfFalseMessageNode() {
}

@Override
public SSymbol getSelector() {
public final SSymbol getSelector() {
return SymbolTable.symbolFor("ifFalse:");
}
}
Expand All @@ -66,7 +66,7 @@ public final Object cachedBlock(final boolean rcvr, final SBlock arg,
@SuppressWarnings("unused") @Cached("arg.getMethod()") final SInvokable method,
@Cached("create(method.getCallTarget())") final DirectCallNode callTarget,
@Shared("all") @Cached final InlinedCountingConditionProfile condProf,
@Bind("this") final Node node) {
@Bind final Node node) {
if (condProf.profile(node, rcvr == expected)) {
return callTarget.call(new Object[] {arg});
} else {
Expand All @@ -78,7 +78,7 @@ public final Object cachedBlock(final boolean rcvr, final SBlock arg,
public final Object fallback(final boolean rcvr, final SBlock arg,
@Cached final IndirectCallNode callNode,
@Shared("all") @Cached final InlinedCountingConditionProfile condProf,
@Bind("this") final Node node) {
@Bind final Node node) {
if (condProf.profile(node, rcvr == expected)) {
return callNode.call(arg.getMethod().getCallTarget(), new Object[] {arg});
} else {
Expand All @@ -91,10 +91,10 @@ protected static final boolean notABlock(final Object arg) {
}

@Specialization(guards = {"notABlock(arg)"})
public final Object literal(final boolean rcvr, final Object arg,
public static final Object literal(final boolean rcvr, final Object arg,
@Shared("all") @Cached final InlinedCountingConditionProfile condProf,
@Bind("this") final Node node) {
if (condProf.profile(node, rcvr == expected)) {
@Bind final Node node) {
if (condProf.profile(node, rcvr == ((IfMessageNode) node).expected)) {
return arg;
} else {
return Nil.nilObject;
Expand Down
Loading

0 comments on commit e9d8032

Please sign in to comment.