@@ -256,11 +256,23 @@ private static int rawIndexToConstantPoolCacheIndex(int rawIndex, int opcode) {
256256 if (opcode == Bytecodes .INVOKEDYNAMIC ) {
257257 index = rawIndex ;
258258 // See: ConstantPool::is_invokedynamic_index
259- assert index < 0 : "not an invokedynamic constant pool index " + index ;
259+ if (index >= 0 ) {
260+ throw new IllegalArgumentException ("not an invokedynamic constant pool index " + index );
261+ }
260262 } else {
261- assert opcode == Bytecodes .GETFIELD || opcode == Bytecodes .PUTFIELD || opcode == Bytecodes .GETSTATIC || opcode == Bytecodes .PUTSTATIC || opcode == Bytecodes .INVOKEINTERFACE ||
262- opcode == Bytecodes .INVOKEVIRTUAL || opcode == Bytecodes .INVOKESPECIAL || opcode == Bytecodes .INVOKESTATIC : "unexpected invoke opcode " + opcode ;
263- index = rawIndex + config ().constantPoolCpCacheIndexTag ;
263+ if (opcode == Bytecodes .GETFIELD ||
264+ opcode == Bytecodes .PUTFIELD ||
265+ opcode == Bytecodes .GETSTATIC ||
266+ opcode == Bytecodes .PUTSTATIC ||
267+ opcode == Bytecodes .INVOKEINTERFACE ||
268+ opcode == Bytecodes .INVOKEVIRTUAL ||
269+ opcode == Bytecodes .INVOKESPECIAL ||
270+ opcode == Bytecodes .INVOKESTATIC ) {
271+ index = rawIndex + config ().constantPoolCpCacheIndexTag ;
272+ } else {
273+ throw new IllegalArgumentException ("unexpected opcode " + opcode );
274+
275+ }
264276 }
265277 return index ;
266278 }
@@ -292,7 +304,9 @@ private static boolean isInvokedynamicIndex(int index) {
292304 * See {@code ConstantPool::decode_invokedynamic_index}.
293305 */
294306 private static int decodeInvokedynamicIndex (int i ) {
295- assert isInvokedynamicIndex (i ) : i ;
307+ if (!isInvokedynamicIndex (i )) {
308+ throw new IllegalArgumentException ("not an invokedynamic index: " + i );
309+ }
296310 return ~i ;
297311 }
298312
@@ -315,7 +329,7 @@ public long getMetadataHandle() {
315329 * @return constant pool tag
316330 */
317331 private JvmConstant getTagAt (int index ) {
318- assert checkBounds (index );
332+ checkBounds (index );
319333 HotSpotVMConfig config = config ();
320334 final long metaspaceConstantPoolTags = UNSAFE .getAddress (getConstantPoolPointer () + config .constantPoolTagsOffset );
321335 final int tag = UNSAFE .getByteVolatile (null , metaspaceConstantPoolTags + config .arrayU1DataOffset + index );
@@ -332,7 +346,7 @@ private JvmConstant getTagAt(int index) {
332346 * @return constant pool entry
333347 */
334348 long getEntryAt (int index ) {
335- assert checkBounds (index );
349+ checkBounds (index );
336350 int offset = index * runtime ().getHostJVMCIBackend ().getTarget ().wordSize ;
337351 return UNSAFE .getAddress (getConstantPoolPointer () + config ().constantPoolSize + offset );
338352 }
@@ -344,7 +358,7 @@ long getEntryAt(int index) {
344358 * @return integer constant pool entry at index
345359 */
346360 private int getIntAt (int index ) {
347- assert checkTag (index , constants .jvmInteger );
361+ checkTag (index , constants .jvmInteger );
348362 int offset = index * runtime ().getHostJVMCIBackend ().getTarget ().wordSize ;
349363 return UNSAFE .getInt (getConstantPoolPointer () + config ().constantPoolSize + offset );
350364 }
@@ -356,7 +370,7 @@ private int getIntAt(int index) {
356370 * @return long constant pool entry
357371 */
358372 private long getLongAt (int index ) {
359- assert checkTag (index , constants .jvmLong );
373+ checkTag (index , constants .jvmLong );
360374 int offset = index * runtime ().getHostJVMCIBackend ().getTarget ().wordSize ;
361375 return UNSAFE .getLong (getConstantPoolPointer () + config ().constantPoolSize + offset );
362376 }
@@ -368,7 +382,7 @@ private long getLongAt(int index) {
368382 * @return float constant pool entry
369383 */
370384 private float getFloatAt (int index ) {
371- assert checkTag (index , constants .jvmFloat );
385+ checkTag (index , constants .jvmFloat );
372386 int offset = index * runtime ().getHostJVMCIBackend ().getTarget ().wordSize ;
373387 return UNSAFE .getFloat (getConstantPoolPointer () + config ().constantPoolSize + offset );
374388 }
@@ -380,7 +394,7 @@ private float getFloatAt(int index) {
380394 * @return float constant pool entry
381395 */
382396 private double getDoubleAt (int index ) {
383- assert checkTag (index , constants .jvmDouble );
397+ checkTag (index , constants .jvmDouble );
384398 int offset = index * runtime ().getHostJVMCIBackend ().getTarget ().wordSize ;
385399 return UNSAFE .getDouble (getConstantPoolPointer () + config ().constantPoolSize + offset );
386400 }
@@ -392,7 +406,7 @@ private double getDoubleAt(int index) {
392406 * @return {@code JVM_CONSTANT_NameAndType} constant pool entry
393407 */
394408 private int getNameAndTypeAt (int index ) {
395- assert checkTag (index , constants .jvmNameAndType );
409+ checkTag (index , constants .jvmNameAndType );
396410 int offset = index * runtime ().getHostJVMCIBackend ().getTarget ().wordSize ;
397411 return UNSAFE .getInt (getConstantPoolPointer () + config ().constantPoolSize + offset );
398412 }
@@ -474,7 +488,7 @@ private int getKlassRefIndexAt(int index) {
474488 * @return klass reference index
475489 */
476490 private int getUncachedKlassRefIndexAt (int index ) {
477- assert checkTagIsFieldOrMethod (index );
491+ checkTagIsFieldOrMethod (index );
478492 int offset = index * runtime ().getHostJVMCIBackend ().getTarget ().wordSize ;
479493 final int refIndex = UNSAFE .getInt (getConstantPoolPointer () + config ().constantPoolSize + offset );
480494 // klass ref index is in the low 16-bits.
@@ -485,24 +499,26 @@ private int getUncachedKlassRefIndexAt(int index) {
485499 * Checks that the constant pool index {@code index} is in the bounds of the constant pool.
486500 *
487501 * @param index constant pool index
488- * @throws AssertionError if the check fails
502+ * @throws IndexOutOfBoundsException if the check fails
489503 */
490- private boolean checkBounds (int index ) {
491- assert 0 <= index && index < length () : "index " + index + " not between 0 and " + length ();
492- return true ;
504+ private void checkBounds (int index ) {
505+ if (index < 1 || index >= length ()) {
506+ throw new IndexOutOfBoundsException ("index " + index + " not between 1 and " + length ());
507+ }
493508 }
494509
495510 /**
496511 * Checks that the constant pool tag at index {@code index} is equal to {@code tag}.
497512 *
498513 * @param index constant pool index
499514 * @param tag expected tag
500- * @throws AssertionError if the check fails
515+ * @throws IllegalArgumentException if the check fails
501516 */
502- private boolean checkTag (int index , JvmConstant tag ) {
517+ private void checkTag (int index , JvmConstant tag ) {
503518 final JvmConstant tagAt = getTagAt (index );
504- assert tagAt == tag : "constant pool tag at index " + index + " is " + tagAt + " but expected " + tag ;
505- return true ;
519+ if (tagAt != tag ) {
520+ throw new IllegalArgumentException ("constant pool tag at index " + index + " is " + tagAt + " but expected " + tag );
521+ }
506522 }
507523
508524 /**
@@ -511,12 +527,13 @@ private boolean checkTag(int index, JvmConstant tag) {
511527 * {@link JvmConstants#jvmInterfaceMethodref}.
512528 *
513529 * @param index constant pool index
514- * @throws AssertionError if the check fails
530+ * @throws IllegalArgumentException if the check fails
515531 */
516- private boolean checkTagIsFieldOrMethod (int index ) {
532+ private void checkTagIsFieldOrMethod (int index ) {
517533 final JvmConstant tagAt = getTagAt (index );
518- assert tagAt == constants .jvmFieldref || tagAt == constants .jvmMethodref || tagAt == constants .jvmInterfaceMethodref : tagAt ;
519- return true ;
534+ if (tagAt != constants .jvmFieldref && tagAt != constants .jvmMethodref && tagAt != constants .jvmInterfaceMethodref ) {
535+ throw new IllegalArgumentException ("constant pool tag at index " + index + " is " + tagAt );
536+ }
520537 }
521538
522539 @ Override
@@ -642,7 +659,6 @@ JavaConstant getStaticFieldConstantValue(int cpi) {
642659
643660 @ Override
644661 public Object lookupConstant (int cpi ) {
645- assert cpi != 0 ;
646662 final JvmConstant tag = getTagAt (cpi );
647663 switch (tag .name ) {
648664 case "Integer" :
@@ -679,7 +695,7 @@ public Object lookupConstant(int cpi) {
679695
680696 @ Override
681697 public String lookupUtf8 (int cpi ) {
682- assert checkTag (cpi , constants .jvmUtf8 );
698+ checkTag (cpi , constants .jvmUtf8 );
683699 return compilerToVM ().getSymbol (getEntryAt (cpi ));
684700 }
685701
@@ -690,7 +706,10 @@ public Signature lookupSignature(int cpi) {
690706
691707 @ Override
692708 public JavaConstant lookupAppendix (int cpi , int opcode ) {
693- assert Bytecodes .isInvoke (opcode );
709+ if (!Bytecodes .isInvoke (opcode )) {
710+ throw new IllegalArgumentException ("expected an invoke bytecode at " + cpi + ", got " + opcode );
711+ }
712+
694713 final int index = rawIndexToConstantPoolCacheIndex (cpi , opcode );
695714 return compilerToVM ().lookupAppendixInPool (this , index );
696715 }
@@ -822,10 +841,14 @@ public JavaField lookupField(int cpi, ResolvedJavaMethod method, int opcode) {
822841 public int rawIndexToConstantPoolIndex (int rawIndex , int opcode ) {
823842 int index ;
824843 if (isInvokedynamicIndex (rawIndex )) {
825- assert opcode == Bytecodes .INVOKEDYNAMIC ;
844+ if (opcode != Bytecodes .INVOKEDYNAMIC ) {
845+ throw new IllegalArgumentException ("expected INVOKEDYNAMIC at " + rawIndex + ", got " + opcode );
846+ }
826847 index = decodeInvokedynamicIndex (rawIndex ) + config ().constantPoolCpCacheIndexTag ;
827848 } else {
828- assert opcode != Bytecodes .INVOKEDYNAMIC ;
849+ if (opcode == Bytecodes .INVOKEDYNAMIC ) {
850+ throw new IllegalArgumentException ("unexpected INVOKEDYNAMIC at " + rawIndex );
851+ }
829852 index = rawIndexToConstantPoolCacheIndex (rawIndex , opcode );
830853 }
831854 return compilerToVM ().constantPoolRemapInstructionOperandFromCache (this , index );
@@ -898,7 +921,7 @@ public void loadReferencedType(int cpi, int opcode, boolean initialize) {
898921 if (tag == constants .jvmMethodref ) {
899922 if (Bytecodes .isInvokeHandleAlias (opcode ) && isSignaturePolymorphicHolder (type )) {
900923 final int methodRefCacheIndex = rawIndexToConstantPoolCacheIndex (cpi , opcode );
901- assert checkTag (compilerToVM ().constantPoolRemapInstructionOperandFromCache (this , methodRefCacheIndex ), constants .jvmMethodref );
924+ checkTag (compilerToVM ().constantPoolRemapInstructionOperandFromCache (this , methodRefCacheIndex ), constants .jvmMethodref );
902925 compilerToVM ().resolveInvokeHandleInPool (this , methodRefCacheIndex );
903926 }
904927 }
@@ -950,7 +973,7 @@ static boolean isSignaturePolymorphicHolder(final ResolvedJavaType type) {
950973 public boolean isResolvedDynamicInvoke (int cpi , int opcode ) {
951974 if (Bytecodes .isInvokeHandleAlias (opcode )) {
952975 final int methodRefCacheIndex = rawIndexToConstantPoolCacheIndex (cpi , opcode );
953- assert checkTag (compilerToVM ().constantPoolRemapInstructionOperandFromCache (this , methodRefCacheIndex ), constants .jvmMethodref );
976+ checkTag (compilerToVM ().constantPoolRemapInstructionOperandFromCache (this , methodRefCacheIndex ), constants .jvmMethodref );
954977 int op = compilerToVM ().isResolvedInvokeHandleInPool (this , methodRefCacheIndex );
955978 return op == opcode ;
956979 }
0 commit comments