Mercurial > hg > truffle
changeset 20023:cef214c6d74a
extract methods to avoid code duplication
author | Christian Wirth <christian.wirth@oracle.com> |
---|---|
date | Tue, 24 Mar 2015 17:33:15 +0100 |
parents | eebf140fa6e4 |
children | d8275b3e1bd3 |
files | graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java |
diffstat | 2 files changed, 18 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java Tue Mar 24 17:19:23 2015 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java Tue Mar 24 17:33:15 2015 +0100 @@ -274,24 +274,24 @@ } private void verifySet(int slotIndex, byte tag) { - if (CompilerDirectives.inInterpreter() && slotIndex >= getTags().length) { - if (!resize()) { - throw new IllegalArgumentException(String.format("The frame slot '%s' is not known by the frame descriptor.", slotIndex)); - } - } + checkSlotIndex(slotIndex); getTags()[slotIndex] = tag; } private void verifyGet(int slotIndex, byte tag) throws FrameSlotTypeException { + checkSlotIndex(slotIndex); + if (getTags()[slotIndex] != tag) { + CompilerDirectives.transferToInterpreter(); + throw new FrameSlotTypeException(); + } + } + + private void checkSlotIndex(int slotIndex) { if (CompilerDirectives.inInterpreter() && slotIndex >= getTags().length) { if (!resize()) { throw new IllegalArgumentException(String.format("The frame slot '%s' is not known by the frame descriptor.", slotIndex)); } } - if (getTags()[slotIndex] != tag) { - CompilerDirectives.transferToInterpreter(); - throw new FrameSlotTypeException(); - } } private static long getPrimitiveOffset(int slotIndex) {
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java Tue Mar 24 17:19:23 2015 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java Tue Mar 24 17:33:15 2015 +0100 @@ -150,32 +150,27 @@ @Override public Object getValue(FrameSlot slot) { + int slotIndex = getSlotIndexChecked(slot); + return locals[slotIndex]; + } + + private int getSlotIndexChecked(FrameSlot slot) { int slotIndex = slot.getIndex(); if (slotIndex >= tags.length) { if (!resize()) { throw new IllegalArgumentException(String.format("The frame slot '%s' is not known by the frame descriptor.", slot)); } } - return locals[slotIndex]; + return slotIndex; } private void verifySet(FrameSlot slot, FrameSlotKind accessKind) { - int slotIndex = slot.getIndex(); - if (slotIndex >= tags.length) { - if (!resize()) { - throw new IllegalArgumentException(String.format("The frame slot '%s' is not known by the frame descriptor.", slot)); - } - } + int slotIndex = getSlotIndexChecked(slot); tags[slotIndex] = (byte) accessKind.ordinal(); } private void verifyGet(FrameSlot slot, FrameSlotKind accessKind) throws FrameSlotTypeException { - int slotIndex = slot.getIndex(); - if (slotIndex >= tags.length) { - if (!resize()) { - throw new IllegalArgumentException(String.format("The frame slot '%s' is not known by the frame descriptor.", slot)); - } - } + int slotIndex = getSlotIndexChecked(slot); byte tag = tags[slotIndex]; if (accessKind == FrameSlotKind.Object ? tag != 0 : tag != accessKind.ordinal()) { throw new FrameSlotTypeException(); @@ -195,12 +190,7 @@ } private byte getTag(FrameSlot slot) { - int slotIndex = slot.getIndex(); - if (slotIndex >= tags.length) { - if (!resize()) { - throw new IllegalArgumentException(String.format("The frame slot '%s' is not known by the frame descriptor.", slot)); - } - } + int slotIndex = getSlotIndexChecked(slot); return tags[slotIndex]; }