# HG changeset patch # User Andreas Woess # Date 1450444850 -3600 # Node ID 8d5a558f427968d65ef67429341f11ba208c77cd # Parent 81c021e5448de02206093b22039821d61f41bafc turn FrameDescriptor assertions into checks that throw IllegalArgumentException diff -r 81c021e5448d -r 8d5a558f4279 truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java --- 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 identifierToNotInFrameAssumptionMap; + private static final String NEVER_PART_OF_COMPILATION_MESSAGE = "interpreter-only. includes hashmap operations."; + /** * Constructs empty descriptor. The {@link #getDefaultValue()} is null. */ @@ -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 null */ 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();