Skip to content

Commit

Permalink
Move noForeignObject assumption invalidation out of the common tail, …
Browse files Browse the repository at this point in the history
…to usages.
  • Loading branch information
mukel committed May 14, 2021
1 parent 375dce1 commit fa2351f
Show file tree
Hide file tree
Showing 32 changed files with 96 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ public final class BytecodeNode extends EspressoMethodNode {

@Child private volatile InstrumentationSupport instrumentation;

public Assumption getNoForeignObjects() {
return noForeignObjects;
}

private final Assumption noForeignObjects;

// Cheap profile for implicit exceptions e.g. null checks, division by 0, index out of bounds.
Expand Down Expand Up @@ -1381,23 +1385,6 @@ Object executeBody(VirtualFrame frame) {
// Tearing down the VM, no need to report loop count.
throw e;
}
// This check includes newly rewritten QUICK nodes, not just curOpcode == quick
if (noForeignObjects.isValid()) {
int opcode = bs.opcode(curBCI);
if (opcode == QUICK || opcode == SLIM_QUICK) {
BaseQuickNode quickNode;
if (opcode == QUICK) {
quickNode = nodes[readCPI(curBCI)];
} else {
assert opcode == SLIM_QUICK;
quickNode = sparseNodes[curBCI];
}
if (quickNode.producedForeignObject(refs)) {
CompilerDirectives.transferToInterpreterAndInvalidate();
noForeignObjects.invalidate();
}
}
}
assert curOpcode != WIDE && curOpcode != LOOKUPSWITCH && curOpcode != TABLESWITCH;

int targetBCI = curBCI + Bytecodes.lengthOf(curOpcode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
package com.oracle.truffle.espresso.nodes.helper;

import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.CachedContext;
import com.oracle.truffle.api.dsl.Specialization;
Expand Down Expand Up @@ -541,7 +543,13 @@ abstract class ObjectGetFieldNode extends AbstractGetFieldNode {
@Override
public int getField(VirtualFrame frame, long[] primitives, Object[] refs, BytecodeNode root, StaticObject receiver, int at, int statementIndex) {
root.notifyFieldAccess(frame, statementIndex, field, receiver);
BytecodeNode.putObject(refs, at, executeGetField(receiver));
StaticObject result = executeGetField(receiver);
Assumption noForeignObjects = root.getNoForeignObjects();
if (noForeignObjects.isValid() && result.isForeignObject()) {
CompilerDirectives.transferToInterpreterAndInvalidate();
noForeignObjects.invalidate();
}
BytecodeNode.putObject(refs, at, result);
return slotCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public final WrapperNode createWrapper(ProbeNode probeNode) {
return new BaseQuickNodeWrapper(this, probeNode);
}

public abstract boolean producedForeignObject(Object[] refs);

public boolean removedByRedefintion() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public CheckCastNode(Klass typeToCheck, int top, int callerBCI) {
this.typeCheckNode = TypeCheckNodeGen.create(typeToCheck.getContext());
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}

@Override
public final int execute(VirtualFrame frame, long[] primitives, Object[] refs) {
BytecodeNode root = getBytecodeNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,4 @@ public int execute(VirtualFrame frame, long[] primitives, Object[] refs) {
BytecodeNode.putKind(primitives, refs, top - 1, result, JavaKind.Boolean);
return 0; // stack effect -> pop receiver, push boolean
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,4 @@ int doForeign(StaticObject array,
int doEspresso(StaticObject array) {
return InterpreterToVM.arrayLength(array);
}

@Override
public final boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,4 @@ byte doForeign(StaticObject array, int index,
byte doEspresso(StaticObject array, int index) {
return getBytecodeNode().getInterpreterToVM().getArrayByte(index, array);
}

@Override
public final boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,4 @@ void doForeign(StaticObject array, int index, byte value,
void doEspresso(StaticObject array, int index, byte value) {
getBytecodeNode().getInterpreterToVM().setArrayByte(value, index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,4 @@ char doForeign(StaticObject array, int index,
char doEspresso(StaticObject array, int index) {
return getBytecodeNode().getInterpreterToVM().getArrayChar(index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,4 @@ void doForeign(StaticObject array, int index, char value,
void doEspresso(StaticObject array, int index, char value) {
getBytecodeNode().getInterpreterToVM().setArrayChar(value, index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,4 @@ public final int execute(VirtualFrame frame, long[] primitives, Object[] refs) {
double doEspresso(StaticObject array, int index) {
return getBytecodeNode().getInterpreterToVM().getArrayDouble(index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,4 @@ void doForeign(StaticObject array, int index, double value,
void doEspresso(StaticObject array, int index, double value) {
getBytecodeNode().getInterpreterToVM().setArrayDouble(value, index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,4 @@ float doForeign(StaticObject array, int index,
float doEspresso(StaticObject array, int index) {
return getBytecodeNode().getInterpreterToVM().getArrayFloat(index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,4 @@ void doForeign(StaticObject array, int index, float value,
void doEspresso(StaticObject array, int index, float value) {
getBytecodeNode().getInterpreterToVM().setArrayFloat(value, index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,4 @@ int doForeign(StaticObject array, int index,
int doEspresso(StaticObject array, int index) {
return getBytecodeNode().getInterpreterToVM().getArrayInt(index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,4 @@ void doForeign(StaticObject array, int index, int value,
void doEspresso(StaticObject array, int index, int value) {
getBytecodeNode().getInterpreterToVM().setArrayInt(value, index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,4 @@ long doForeign(StaticObject array, int index,
long doEspresso(StaticObject array, int index) {
return getBytecodeNode().getInterpreterToVM().getArrayLong(index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,4 @@ void doForeign(StaticObject array, int index, long value,
void doEspresso(StaticObject array, int index, long value) {
getBytecodeNode().getInterpreterToVM().setArrayLong(value, index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.oracle.truffle.espresso.runtime.StaticObject;

public final class QuickenedGetFieldNode extends QuickNode {
private final Field field;
private final int statementIndex;

@Child AbstractGetFieldNode getFieldNode;
Expand All @@ -39,7 +38,6 @@ public QuickenedGetFieldNode(int top, int callerBCI, int statementIndex, Field f
super(top, callerBCI);
assert !field.isStatic();
this.getFieldNode = AbstractGetFieldNode.create(field);
this.field = field;
this.statementIndex = statementIndex;
}

Expand All @@ -49,9 +47,4 @@ public int execute(VirtualFrame frame, long[] primitives, Object[] refs) {
StaticObject receiver = nullCheck(BytecodeNode.popObject(refs, top - 1));
return getFieldNode.getField(frame, primitives, refs, root, receiver, top - 1, statementIndex) - 1; // -receiver
}

@Override
public boolean producedForeignObject(Object[] refs) {
return field.getKind().isObject() && BytecodeNode.peekObject(refs, top - 1).isForeignObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,4 @@ public int execute(VirtualFrame frame, long[] primitives, Object[] refs) {
setFieldNode.setField(frame, primitives, refs, root, receiver, top, statementIndex);
return -slotCount - 1; // -receiver
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

package com.oracle.truffle.espresso.nodes.quick.interop;

import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.CachedContext;
import com.oracle.truffle.api.dsl.Specialization;
Expand Down Expand Up @@ -52,7 +54,13 @@ protected ReferenceArrayLoadNode(int top, int callerBCI) {
public final int execute(VirtualFrame frame, long[] primitives, Object[] refs) {
StaticObject array = nullCheck(BytecodeNode.popObject(refs, top - 2));
int index = BytecodeNode.popInt(primitives, top - 1);
BytecodeNode.putObject(refs, top - 2, executeLoad(array, index));
StaticObject result = executeLoad(array, index);
Assumption noForeignObjects = getBytecodeNode().getNoForeignObjects();
if (noForeignObjects.isValid() && result.isForeignObject()) {
CompilerDirectives.transferToInterpreterAndInvalidate();
noForeignObjects.invalidate();
}
BytecodeNode.putObject(refs, top - 2, result);
return Bytecodes.stackEffectOf(Bytecodes.AALOAD);
}

Expand Down Expand Up @@ -80,9 +88,4 @@ StaticObject doForeign(StaticObject array, int index,
StaticObject doEspresso(StaticObject array, int index) {
return getBytecodeNode().getInterpreterToVM().getArrayObject(index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return BytecodeNode.peekObject(refs, top - 2).isForeignObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,4 @@ void doForeign(StaticObject array, int index, StaticObject value,
void doEspresso(StaticObject array, int index, StaticObject value) {
getBytecodeNode().getInterpreterToVM().setArrayObject(value, index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,4 @@ short doForeign(StaticObject array, int index,
short doEspresso(StaticObject array, int index) {
return getBytecodeNode().getInterpreterToVM().getArrayShort(index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,4 @@ void doForeign(StaticObject array, int index, short value,
void doEspresso(StaticObject array, int index, short value) {
getBytecodeNode().getInterpreterToVM().setArrayShort(value, index, array);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ public int execute(VirtualFrame frame, long[] primitives, Object[] refs) {
return (getResultAt() - top) + getFieldNode.getField(frame, primitives, refs, root, receiver, getResultAt(), statementIndex);
}

@Override
public boolean producedForeignObject(Object[] refs) {
return field.getKind().isObject() && BytecodeNode.peekObject(refs, getResultAt()).isForeignObject();
}

private int getResultAt() {
return inlinedMethod.isStatic() ? top : (top - 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ public int execute(VirtualFrame frame, long[] primitives, Object[] refs) {
return -slotCount + stackEffect;
}

@Override
public boolean producedForeignObject(Object[] refs) {
return false;
}

private static Field getInlinedField(Method inlinedMethod) {
BytecodeStream code = new BytecodeStream(inlinedMethod.getOriginalCode());
if (inlinedMethod.isStatic()) {
Expand Down
Loading

0 comments on commit fa2351f

Please sign in to comment.