Skip to content

Commit

Permalink
Migrate to new index-based Frame API
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Nov 29, 2021
1 parent 2293985 commit 2e456e1
Show file tree
Hide file tree
Showing 36 changed files with 304 additions and 481 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright (c) 2017-2021 Software Architecture Group, Hasso Plattner Institute
* Copyright (c) 2021 Oracle and/or its affiliates
*
* Licensed under the MIT License.
*/
package de.hpi.swa.trufflesqueak;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.TruffleObject;
Expand Down Expand Up @@ -43,7 +43,7 @@ public Object execute(final VirtualFrame frame) {
}

public RootCallTarget asCallTarget() {
return Truffle.getRuntime().createCallTarget(new SqueakImageNode(this));
return new SqueakImageNode(this).getCallTarget();
}

public String getName() {
Expand All @@ -62,7 +62,7 @@ public Object execute(final Object... arguments) {
assert arguments.length == 0;
image.interrupt.start();
image.attachDisplayIfNecessary();
return Truffle.getRuntime().createCallTarget(image.getActiveContextNode()).call();
return image.getActiveContextNode().getCallTarget().call();
}

@SuppressWarnings("static-method")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2017-2021 Software Architecture Group, Hasso Plattner Institute
* Copyright (c) 2021 Oracle and/or its affiliates
*
* Licensed under the MIT License.
*/
Expand All @@ -8,7 +9,6 @@
import org.graalvm.options.OptionDescriptors;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.debug.DebuggerTags;
import com.oracle.truffle.api.instrumentation.ProvidedTags;
Expand Down Expand Up @@ -59,7 +59,7 @@ protected CallTarget parse(final ParsingRequest request) throws Exception {
if (source.isInternal()) {
image.printToStdOut(MiscUtils.format("Evaluating '%s'...", source.getCharacters().toString()));
}
return Truffle.getRuntime().createCallTarget(image.getDoItContextNode(request));
return image.getDoItContextNode(request).getCallTarget();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleFile;
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
import com.oracle.truffle.api.TruffleLanguage.ParsingRequest;
Expand Down Expand Up @@ -239,7 +238,7 @@ public SqueakImage getSqueakImage() {

@TruffleBoundary
public Object evaluate(final String sourceCode) {
return Truffle.getRuntime().createCallTarget(getDoItContextNode(sourceCode, false)).call();
return getDoItContextNode(sourceCode, false).getCallTarget().call();
}

@TruffleBoundary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.FrameDescriptor.Builder;
import com.oracle.truffle.api.frame.FrameSlotKind;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.RootNode;
Expand Down Expand Up @@ -55,19 +55,9 @@ public final class CompiledCodeObject extends AbstractSqueakObjectWithClassAndHa
public static final String SOURCE_UNAVAILABLE_CONTENTS = "Source unavailable";
private static final long NEGATIVE_METHOD_HEADER_MASK = -1L << 60;

public enum SLOT_IDENTIFIER {
THIS_MARKER,
THIS_CONTEXT,
INSTRUCTION_POINTER,
STACK_POINTER,
}

// frame info
private final FrameDescriptor frameDescriptor;
private final FrameSlot thisMarkerSlot;
private final FrameSlot thisContextSlot;
private final FrameSlot instructionPointerSlot;
private final FrameSlot stackPointerSlot;
@CompilationFinal private FrameDescriptor frameDescriptor;

// header info and data
/*
* TODO: literals and bytes can change (and probably more?) and should not be @CompilationFinal.
Expand Down Expand Up @@ -104,11 +94,6 @@ public enum SLOT_IDENTIFIER {
@TruffleBoundary
public CompiledCodeObject(final SqueakImageContext image, final long hash, final ClassObject classObject) {
super(image, hash, classObject);
frameDescriptor = new FrameDescriptor();
thisMarkerSlot = frameDescriptor.addFrameSlot(SLOT_IDENTIFIER.THIS_MARKER, FrameSlotKind.Object);
thisContextSlot = frameDescriptor.addFrameSlot(SLOT_IDENTIFIER.THIS_CONTEXT, FrameSlotKind.Illegal);
instructionPointerSlot = frameDescriptor.addFrameSlot(SLOT_IDENTIFIER.INSTRUCTION_POINTER, FrameSlotKind.Int);
stackPointerSlot = frameDescriptor.addFrameSlot(SLOT_IDENTIFIER.STACK_POINTER, FrameSlotKind.Int);
}

public CompiledCodeObject(final SqueakImageContext image, final byte[] bc, final Object[] lits, final ClassObject classObject) {
Expand All @@ -121,10 +106,6 @@ public CompiledCodeObject(final SqueakImageContext image, final byte[] bc, final
protected CompiledCodeObject(final CompiledCodeObject original) {
super(original);
frameDescriptor = original.frameDescriptor;
thisMarkerSlot = original.thisMarkerSlot;
thisContextSlot = original.thisContextSlot;
instructionPointerSlot = original.instructionPointerSlot;
stackPointerSlot = original.stackPointerSlot;
setLiteralsAndBytes(original.literals.clone(), original.bytes.clone());
decoder = original.decoder;
}
Expand All @@ -141,12 +122,6 @@ protected CompiledCodeObject(final CompiledCodeObject outerCode, final int start
assert currentOuterCode.isCompiledMethod();
outerMethod = currentOuterCode;

frameDescriptor = new FrameDescriptor();
thisMarkerSlot = frameDescriptor.addFrameSlot(SLOT_IDENTIFIER.THIS_MARKER, FrameSlotKind.Object);
thisContextSlot = frameDescriptor.addFrameSlot(SLOT_IDENTIFIER.THIS_CONTEXT, FrameSlotKind.Illegal);
instructionPointerSlot = frameDescriptor.addFrameSlot(SLOT_IDENTIFIER.INSTRUCTION_POINTER, FrameSlotKind.Int);
stackPointerSlot = frameDescriptor.addFrameSlot(SLOT_IDENTIFIER.STACK_POINTER, FrameSlotKind.Int);

// header info and data
literals = outerCode.literals;
bytes = outerCode.bytes;
Expand Down Expand Up @@ -258,7 +233,7 @@ protected void initializeCallTargetUnsafe() {
} else {
rootNode = new StartContextRootNode(language, this);
}
callTarget = Truffle.getRuntime().createCallTarget(rootNode);
callTarget = rootNode.getCallTarget();
}

public void flushCache() {
Expand All @@ -274,7 +249,7 @@ public Assumption getCallTargetStable() {
public RootCallTarget getResumptionCallTarget(final ContextObject context) {
if (resumptionCallTarget == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
resumptionCallTarget = Truffle.getRuntime().createCallTarget(ResumeContextRootNode.create(SqueakImageContext.getSlow().getLanguage(), context));
resumptionCallTarget = ResumeContextRootNode.create(SqueakImageContext.getSlow().getLanguage(), context).getCallTarget();
} else {
final ResumeContextRootNode resumeNode = (ResumeContextRootNode) resumptionCallTarget.getRootNode();
if (resumeNode.getActiveContext() != context) {
Expand All @@ -293,25 +268,19 @@ public Assumption getDoesNotNeedSenderAssumption() {
}

public FrameDescriptor getFrameDescriptor() {
if (frameDescriptor == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
final Builder builder = FrameDescriptor.newBuilder();
builder.addSlot(FrameSlotKind.Object, null, null); // SLOT_IDENTIFIER.THIS_MARKER
builder.addSlot(FrameSlotKind.Illegal, null, null); // SLOT_IDENTIFIER.THIS_CONTEXT
builder.addSlot(FrameSlotKind.Int, null, null); // SLOT_IDENTIFIER.INSTRUCTION_POINTER
builder.addSlot(FrameSlotKind.Int, null, null); // SLOT_IDENTIFIER.STACK_POINTER
builder.addSlots(getSqueakContextSize(), FrameSlotKind.Illegal);
frameDescriptor = builder.build();
}
return frameDescriptor;
}

public FrameSlot getThisMarkerSlot() {
return thisMarkerSlot;
}

public FrameSlot getThisContextSlot() {
return thisContextSlot;
}

public FrameSlot getInstructionPointerSlot() {
return instructionPointerSlot;
}

public FrameSlot getStackPointerSlot() {
return stackPointerSlot;
}

public int getNumArgs() {
return numArgs;
}
Expand Down
Loading

0 comments on commit 2e456e1

Please sign in to comment.