Skip to content

Instantly share code, notes, and snippets.

@schmee
Last active May 16, 2018 22:37
Show Gist options
  • Save schmee/fe0dae7cb9463134679377c9c02b61ab to your computer and use it in GitHub Desktop.
Save schmee/fe0dae7cb9463134679377c9c02b61ab to your computer and use it in GitHub Desktop.
Escape analysis woes
@Specialization(guards = "isLong(vframe)")
public long readLong(VirtualFrame vframe) {
try {
return vframe.getLong(getSlot());
} catch (FrameSlotTypeException e) { }
MaterializedFrame frame = getLexicalScope(vframe);
while (true) {
try {
return frame.getLong(getSlot());
} catch (FrameSlotTypeException e) {
frame = getLexicalScope(frame);
if (frame == null) {
throw new RuntimeException("Undefined variable " + getSlot().getIdentifier());
}
}
}
}
@Specialization(replaces = {"readLong"})
public Object readObject(VirtualFrame vframe) {
Object value = vframe.getValue(getSlot());
if (value != null)
return value;
MaterializedFrame frame = getLexicalScope(vframe);
value = frame.getValue(getSlot());
if (value != null)
return value;
while (value == null) {
frame = getLexicalScope(frame);
if (frame == null) {
throw new RuntimeException("Undefined variable " + getSlot().getIdentifier());
} else {
value = frame.getValue(getSlot());
}
}
return value;
}
@Specialization(guards = "isLong(vframe)")
public long readLong(VirtualFrame vframe) {
Frame frame = vframe;
while (true) {
try {
return frame.getLong(getSlot());
} catch (FrameSlotTypeException e) {
frame = getLexicalScope(frame);
if (frame == null) {
throw new RuntimeException("Undefined variable " + getSlot().getIdentifier());
}
}
}
}
@Specialization(replaces = {"readLong"})
public Object readObject(VirtualFrame vframe) {
Frame frame = vframe;
Object value = frame.getValue(getSlot());
while (value == null) {
frame = getLexicalScope(frame);
if (frame == null) {
throw new RuntimeException("Undefined variable " + getSlot().getIdentifier());
} else {
value = frame.getValue(getSlot());
}
}
return value;
}
public MaterializedFrame getLexicalScope(Frame frame) {
Object[] args = frame.getArguments();
if (args.length > 0)
return (MaterializedFrame) args[0];
else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment