@@ -436,13 +436,14 @@ public Object executeBodyFromOffset(WasmContext context, WasmInstance instance,
436
436
int index = popInt (frame , stackPointer );
437
437
final int size = rawPeekU8 (bytecode , offset );
438
438
final int counterOffset = offset + 1 ;
439
- if (index < 0 || index >= size ) {
440
- // If unsigned index is larger or equal to the table size use the
441
- // default (last) index.
442
- index = size - 1 ;
443
- }
444
439
445
440
if (CompilerDirectives .inInterpreter ()) {
441
+ if (index < 0 || index >= size ) {
442
+ // If unsigned index is larger or equal to the table size use the
443
+ // default (last) index.
444
+ index = size - 1 ;
445
+ }
446
+
446
447
final int indexOffset = offset + 3 + index * 6 ;
447
448
updateBranchTableProfile (bytecode , counterOffset , indexOffset + 4 );
448
449
final int offsetDelta = rawPeekI32 (bytecode , indexOffset );
@@ -454,28 +455,28 @@ public Object executeBodyFromOffset(WasmContext context, WasmInstance instance,
454
455
// time constants, since the loop is unrolled.
455
456
for (int i = 0 ; i < size ; i ++) {
456
457
final int indexOffset = offset + 3 + i * 6 ;
457
- if (profileBranchTable (bytecode , counterOffset , indexOffset + 4 , i == index )) {
458
+ if (profileBranchTable (bytecode , counterOffset , indexOffset + 4 , i == index || i == size - 1 )) {
458
459
final int offsetDelta = rawPeekI32 (bytecode , indexOffset );
459
460
offset = indexOffset + offsetDelta ;
460
461
continue loop ;
461
462
}
462
463
}
464
+ throw CompilerDirectives .shouldNotReachHere ("br_table" );
463
465
}
464
- enterErrorBranch ();
465
- throw WasmException .create (Failure .UNSPECIFIED_INTERNAL , this , "Should not reach here" );
466
466
}
467
467
case Bytecode .BR_TABLE_I32 : {
468
468
stackPointer --;
469
469
int index = popInt (frame , stackPointer );
470
470
final int size = rawPeekI32 (bytecode , offset );
471
471
final int counterOffset = offset + 4 ;
472
- if (index < 0 || index >= size ) {
473
- // If unsigned index is larger or equal to the table size use the
474
- // default (last) index.
475
- index = size - 1 ;
476
- }
477
472
478
473
if (CompilerDirectives .inInterpreter ()) {
474
+ if (index < 0 || index >= size ) {
475
+ // If unsigned index is larger or equal to the table size use the
476
+ // default (last) index.
477
+ index = size - 1 ;
478
+ }
479
+
479
480
final int indexOffset = offset + 6 + index * 6 ;
480
481
updateBranchTableProfile (bytecode , counterOffset , indexOffset + 4 );
481
482
final int offsetDelta = rawPeekI32 (bytecode , indexOffset );
@@ -487,15 +488,14 @@ public Object executeBodyFromOffset(WasmContext context, WasmInstance instance,
487
488
// time constants, since the loop is unrolled.
488
489
for (int i = 0 ; i < size ; i ++) {
489
490
final int indexOffset = offset + 6 + i * 6 ;
490
- if (profileBranchTable (bytecode , counterOffset , indexOffset + 4 , i == index )) {
491
+ if (profileBranchTable (bytecode , counterOffset , indexOffset + 4 , i == index || i == size - 1 )) {
491
492
final int offsetDelta = rawPeekI32 (bytecode , indexOffset );
492
493
offset = indexOffset + offsetDelta ;
493
494
continue loop ;
494
495
}
495
496
}
497
+ throw CompilerDirectives .shouldNotReachHere ("br_table" );
496
498
}
497
- enterErrorBranch ();
498
- throw WasmException .create (Failure .UNSPECIFIED_INTERNAL , this , "Should not reach here" );
499
499
}
500
500
case Bytecode .CALL_U8 :
501
501
case Bytecode .CALL_I32 : {
0 commit comments