@@ -299,7 +299,6 @@ public static int align(int n) {
299
299
private int nextBci ;
300
300
private int bci ;
301
301
private int opcode ;
302
- private boolean isWide ;
303
302
304
303
public static CodeRange of (byte [] array ) {
305
304
return new CodeRange (array , array .length );
@@ -341,14 +340,14 @@ public void reset(int nextBci) {
341
340
* be valid and can be accessed unchecked.
342
341
*/
343
342
public int opcode () {
344
- return opcode ;
343
+ return opcode & 0xFF ;
345
344
}
346
345
347
346
/**
348
347
* Returns whether the current functional opcode is in wide.
349
348
*/
350
349
public boolean isWide () {
351
- return isWide ;
350
+ return ( opcode & ( WIDE << 8 )) != 0 ;
352
351
}
353
352
354
353
/**
@@ -411,7 +410,7 @@ public int destW() {
411
410
412
411
// *load, *store, iinc
413
412
public int getIndex () {
414
- return isWide ? getU2Unchecked (bci + 2 ) : getIndexU1 ();
413
+ return isWide () ? getU2Unchecked (bci + 2 ) : getIndexU1 ();
415
414
}
416
415
417
416
// ldc
@@ -443,12 +442,11 @@ public boolean next() {
443
442
int len = LENGTHS [code & 0xFF ]; // & 0xFF eliminates bound check
444
443
this .bci = bci ;
445
444
opcode = code ;
446
- isWide = false ;
447
445
if (len <= 0 ) {
448
446
len = checkSpecialInstruction (bci , end , code ); // sets opcode
449
447
}
450
448
451
- if (len <= 0 || (nextBci += len ) > end ) {
449
+ if ((nextBci += len ) > end ) {
452
450
opcode = ILLEGAL ;
453
451
}
454
452
@@ -457,37 +455,34 @@ public boolean next() {
457
455
458
456
// Put rarely used code in another method to reduce code size
459
457
private int checkSpecialInstruction (int bci , int end , int code ) {
458
+ int len = -1 ;
460
459
if (code == WIDE ) {
461
- if (bci + 1 >= end ) {
462
- return -1 ;
460
+ if (bci + 1 < end ) {
461
+ opcode = (WIDE << 8 ) | (code = getIndexU1 ());
462
+ // Validated in UtilTest.testOpcodeLengthTable
463
+ len = LENGTHS [code ] * 2 ;
463
464
}
464
- opcode = code = getIndexU1 ();
465
- isWide = true ;
466
- // Validated in UtilTest.testOpcodeLengthTable
467
- return LENGTHS [code ] * 2 ;
468
- }
469
- if (code == TABLESWITCH ) {
465
+ } else if (code == TABLESWITCH ) {
470
466
int alignedBci = align (bci + 1 );
471
- if (alignedBci + 3 * 4 >= end ) {
472
- return -1 ;
467
+ if (alignedBci + 3 * 4 < end ) {
468
+ int lo = getIntUnchecked (alignedBci + 1 * 4 );
469
+ int hi = getIntUnchecked (alignedBci + 2 * 4 );
470
+ long l = alignedBci - bci + (3L + (long ) hi - lo + 1L ) * 4L ;
471
+ len = l > 0 && ((int ) l == l ) ? (int ) l : -1 ;
473
472
}
474
- int lo = getIntUnchecked (alignedBci + 1 * 4 );
475
- int hi = getIntUnchecked (alignedBci + 2 * 4 );
476
- long l = alignedBci - bci + (3L + (long ) hi - lo + 1L ) * 4L ;
477
- return l > 0 && ((int ) l == l ) ? (int ) l : -1 ;
478
- }
479
- if (code == LOOKUPSWITCH ) {
473
+ } else if (code == LOOKUPSWITCH ) {
480
474
int alignedBci = align (bci + 1 );
481
- if (alignedBci + 2 * 4 >= end ) {
482
- return - 1 ;
483
- }
484
- int npairs = getIntUnchecked ( alignedBci + 4 ) ;
485
- if ( npairs < 0 ) {
486
- return - 1 ;
475
+ if (alignedBci + 2 * 4 < end ) {
476
+ int npairs = getIntUnchecked ( alignedBci + 4 ) ;
477
+ if ( npairs >= 0 ) {
478
+ long l = alignedBci - bci + ( 2L + 2L * npairs ) * 4L ;
479
+ len = l > 0 && (( int ) l == l ) ? ( int ) l : - 1 ;
480
+ }
487
481
}
488
- long l = alignedBci - bci + (2L + 2L * npairs ) * 4L ;
489
- return l > 0 && ((int ) l == l ) ? (int ) l : -1 ;
490
482
}
491
- return -1 ;
483
+ if (len <= 0 ) {
484
+ opcode = ILLEGAL ;
485
+ }
486
+ return len ;
492
487
}
493
488
}
0 commit comments