# HG changeset patch # User Christian Wirth # Date 1427214795 -3600 # Node ID cef214c6d74accbc8d536862ad1706fae0532884 # Parent eebf140fa6e4682a550de2fb6f2f4a094f53c506 extract methods to avoid code duplication diff -r eebf140fa6e4 -r cef214c6d74a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java --- 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) { diff -r eebf140fa6e4 -r cef214c6d74a graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java --- 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]; }