Skip to content

Commit

Permalink
Minor performance-related cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Jun 6, 2019
1 parent 7377642 commit bec8c61
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ private ContextObject(final ContextObject original) {
final int numStackSlots = code.getNumStackSlots();
for (int i = 0; i < numStackSlots; i++) {
final FrameSlot slot = code.getStackSlot(i);
FrameAccess.setStackSlot(truffleFrame, slot, original.truffleFrame.getValue(slot));
final Object value = original.truffleFrame.getValue(slot);
if (value != null) {
FrameAccess.setStackSlot(truffleFrame, slot, value);
} else {
break; // This and all following slots are not in use.
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ protected final Object doVirtualized(final VirtualFrame frame, @SuppressWarnings
@Fallback
protected final Object doNonVirtualized(final VirtualFrame frame, final ContextObject context) {
// maybe persist newContext, so there's no need to lookup the context to update its pc.
assert code == context.getBlockOrMethod();
assert context.getMethod() == FrameAccess.getMethod(frame);
assert frame.getFrameDescriptor() == code.getFrameDescriptor();
try {
triggerInterruptHandlerNode.executeGeneric(frame, code.hasPrimitive(), bytecodeNodes.length);
final long initialPC = context.getInstructionPointerForBytecodeLoop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ protected final void writeDouble(final Frame frame, final double value) {

@Specialization(replaces = {"writeBool", "writeLong", "writeDouble"})
protected final void writeObject(final Frame frame, final Object value) {
assert !(value instanceof Byte || value instanceof Integer || value instanceof Float) : "Illegal write operation";

/* Initialize type on first write. No-op if kind is already Object. */
frame.getFrameDescriptor().setFrameSlotKind(frameSlot, FrameSlotKind.Object);

assert value != null;
assert verifyWrite(value) : "Illegal write operation: " + value;
frame.setObject(frameSlot, value);
}

Expand All @@ -66,4 +64,8 @@ protected final boolean isDoubleOrIllegal(final Frame frame) {
final FrameSlotKind kind = frame.getFrameDescriptor().getFrameSlotKind(frameSlot);
return kind == FrameSlotKind.Double || kind == FrameSlotKind.Illegal;
}

private static boolean verifyWrite(final Object value) {
return value != null && !(value instanceof Byte || value instanceof Integer || value instanceof Float);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ public static void setStackPointer(final Frame frame, final CompiledCodeObject c
/** Write to a frame slot (slow operation), prefer {@link FrameStackWriteNode}. */
public static void setStackSlot(final Frame frame, final FrameSlot frameSlot, final Object value) {
final FrameDescriptor frameDescriptor = frame.getFrameDescriptor();
if (value instanceof Boolean) {
final Class<? extends Object> valueClass = value.getClass();
if (valueClass == Boolean.class) {
frameDescriptor.setFrameSlotKind(frameSlot, FrameSlotKind.Boolean);
frame.setBoolean(frameSlot, (boolean) value);
} else if (value instanceof Long) {
} else if (valueClass == Long.class) {
frameDescriptor.setFrameSlotKind(frameSlot, FrameSlotKind.Long);
frame.setLong(frameSlot, (long) value);
} else if (value instanceof Double) {
} else if (valueClass == Double.class) {
frameDescriptor.setFrameSlotKind(frameSlot, FrameSlotKind.Double);
frame.setDouble(frameSlot, (double) value);
} else {
Expand Down

0 comments on commit bec8c61

Please sign in to comment.