Mercurial > hg > truffle
changeset 22513:8d5a558f4279
turn FrameDescriptor assertions into checks that throw IllegalArgumentException
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Fri, 18 Dec 2015 14:20:50 +0100 |
parents | 81c021e5448d |
children | 6fe6d2cb7cc1 |
files | truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java |
diffstat | 1 files changed, 17 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java Fri Dec 18 11:04:27 2015 +0100 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java Fri Dec 18 14:20:50 2015 +0100 @@ -24,15 +24,16 @@ */ package com.oracle.truffle.api.frame; -import com.oracle.truffle.api.Assumption; -import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.Truffle; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Set; +import com.oracle.truffle.api.Assumption; +import com.oracle.truffle.api.CompilerAsserts; +import com.oracle.truffle.api.Truffle; + /** * Descriptor of the slots of frame objects. Multiple frame instances are associated with one such * descriptor. @@ -45,6 +46,8 @@ private Assumption version; private HashMap<Object, Assumption> identifierToNotInFrameAssumptionMap; + private static final String NEVER_PART_OF_COMPILATION_MESSAGE = "interpreter-only. includes hashmap operations."; + /** * Constructs empty descriptor. The {@link #getDefaultValue()} is <code>null</code>. */ @@ -123,10 +126,13 @@ * @param info additional {@link FrameSlot#getInfo() information for the slot} * @param kind the kind of the new slot * @return the newly created slot + * @throws IllegalArgumentException if a frame slot with the same identifier exists */ public FrameSlot addFrameSlot(Object identifier, Object info, FrameSlotKind kind) { - CompilerAsserts.neverPartOfCompilation("interpreter-only. includes hashmap operations."); - assert !identifierToSlotMap.containsKey(identifier); + CompilerAsserts.neverPartOfCompilation(NEVER_PART_OF_COMPILATION_MESSAGE); + if (identifierToSlotMap.containsKey(identifier)) { + throw new IllegalArgumentException("duplicate frame slot: " + identifier); + } FrameSlot slot = new FrameSlot(this, identifier, info, slots.size(), kind); slots.add(slot); identifierToSlotMap.put(identifier, slot); @@ -142,7 +148,7 @@ * @return the slot or <code>null</code> */ public FrameSlot findFrameSlot(Object identifier) { - CompilerAsserts.neverPartOfCompilation("interpreter-only. includes hashmap operations."); + CompilerAsserts.neverPartOfCompilation(NEVER_PART_OF_COMPILATION_MESSAGE); return identifierToSlotMap.get(identifier); } @@ -196,10 +202,13 @@ * a slow operation. * * @param identifier identifies the slot to remove + * @throws IllegalArgumentException if no such frame slot exists */ public void removeFrameSlot(Object identifier) { - CompilerAsserts.neverPartOfCompilation("interpreter-only. includes hashmap operations."); - assert identifierToSlotMap.containsKey(identifier); + CompilerAsserts.neverPartOfCompilation(NEVER_PART_OF_COMPILATION_MESSAGE); + if (!identifierToSlotMap.containsKey(identifier)) { + throw new IllegalArgumentException("no such frame slot: " + identifier); + } slots.remove(identifierToSlotMap.get(identifier)); identifierToSlotMap.remove(identifier); updateVersion();