@@ -711,32 +711,37 @@ public static void emitJumpTable(CompilationResultBuilder crb, AMD64MacroAssembl
711
711
masm .addq (scratchReg , idxScratchReg );
712
712
masm .jmp (scratchReg );
713
713
714
- // Inserting padding so that jump table address is 4-byte aligned
715
- masm .align (4 );
716
-
717
- // Patch LEA instruction above now that we know the position of the jump table
718
- // this is ugly but there is no better way to do this given the assembler API
719
- final int jumpTablePos = masm .position ();
720
- final int leaDisplacementPosition = afterLea - 4 ;
721
- masm .emitInt (jumpTablePos - afterLea , leaDisplacementPosition );
722
-
723
- // Emit jump table entries
724
- targets .forEach (label -> {
725
- int offsetToJumpTableBase = masm .position () - jumpTablePos ;
726
- if (label .isBound ()) {
727
- int imm32 = label .position () - jumpTablePos ;
728
- masm .emitInt (imm32 );
729
- } else {
730
- label .addPatchAt (masm .position (), masm );
731
-
732
- masm .emitByte (0 ); // pseudo-opcode for jump table entry
733
- masm .emitShort (offsetToJumpTableBase );
734
- masm .emitByte (0 ); // padding to make jump table entry 4 bytes wide
735
- }
714
+ crb .getLIR ().addSlowPath (null , () -> {
715
+ // Insert halt so that static analyzers do not continue decoding past this point
716
+ masm .hlt ();
717
+ // Insert ud2 so the CPU does not continue decoding past this point
718
+ masm .ud2 ();
719
+ // Inserting padding so that jump table address is 4-byte aligned
720
+ masm .align (4 );
721
+ // Patch LEA instruction above now that we know the position of the jump table
722
+ // this is ugly but there is no better way to do this given the assembler API
723
+ int jumpTablePos = masm .position ();
724
+ int leaDisplacementPosition = afterLea - 4 ;
725
+ masm .emitInt (jumpTablePos - afterLea , leaDisplacementPosition );
726
+
727
+ // Emit jump table entries
728
+ targets .forEach (label -> {
729
+ int offsetToJumpTableBase = masm .position () - jumpTablePos ;
730
+ if (label .isBound ()) {
731
+ int imm32 = label .position () - jumpTablePos ;
732
+ masm .emitInt (imm32 );
733
+ } else {
734
+ label .addPatchAt (masm .position (), masm );
735
+
736
+ masm .emitByte (0 ); // pseudo-opcode for jump table entry
737
+ masm .emitShort (offsetToJumpTableBase );
738
+ masm .emitByte (0 ); // padding to make jump table entry 4 bytes wide
739
+ }
740
+ });
741
+
742
+ JumpTable jt = new JumpTable (jumpTablePos , lowKey , highKey , EntryFormat .OFFSET_ONLY );
743
+ crb .compilationResult .addAnnotation (jt );
736
744
});
737
-
738
- JumpTable jt = new JumpTable (jumpTablePos , lowKey , highKey , EntryFormat .OFFSET_ONLY );
739
- crb .compilationResult .addAnnotation (jt );
740
745
}
741
746
}
742
747
@@ -794,38 +799,43 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
794
799
masm .addq (scratchReg , entryScratchReg );
795
800
masm .jmp (scratchReg );
796
801
797
- // Inserting padding so that jump the table address is aligned
798
- EntryFormat entryFormat = defaultTarget == null ? EntryFormat .OFFSET_ONLY : EntryFormat .VALUE_AND_OFFSET ;
799
- masm .align (entryFormat .size );
800
-
801
- // Patch LEA instruction above now that we know the position of the jump table
802
- // this is ugly but there is no better way to do this given the assembler API
803
- final int jumpTablePos = masm .position ();
804
- final int leaDisplacementPosition = afterLea - 4 ;
805
- masm .emitInt (jumpTablePos - afterLea , leaDisplacementPosition );
806
-
807
- // Emit jump table entries
808
- for (int i = 0 ; i < targets .length ; i ++) {
809
-
810
- Label label = targets [i ].label ();
811
-
812
- if (defaultTarget != null ) {
813
- masm .emitInt (keys [i ].asInt ());
802
+ crb .getLIR ().addSlowPath (this , () -> {
803
+ // Insert halt so that static analyzers do not continue decoding past this point
804
+ masm .hlt ();
805
+ // Insert ud2 so the CPU does not continue decoding past this point
806
+ masm .ud2 ();
807
+ // Inserting padding so that jump the table address is aligned
808
+ EntryFormat entryFormat = defaultTarget == null ? EntryFormat .OFFSET_ONLY : EntryFormat .VALUE_AND_OFFSET ;
809
+ masm .align (entryFormat .size );
810
+
811
+ // Patch LEA instruction above now that we know the position of the jump table
812
+ // this is ugly but there is no better way to do this given the assembler API
813
+ final int jumpTablePos = masm .position ();
814
+ final int leaDisplacementPosition = afterLea - 4 ;
815
+ masm .emitInt (jumpTablePos - afterLea , leaDisplacementPosition );
816
+
817
+ // Emit jump table entries
818
+ for (int i = 0 ; i < targets .length ; i ++) {
819
+ Label label = targets [i ].label ();
820
+
821
+ if (defaultTarget != null ) {
822
+ masm .emitInt (keys [i ].asInt ());
823
+ }
824
+ if (label .isBound ()) {
825
+ int imm32 = label .position () - jumpTablePos ;
826
+ masm .emitInt (imm32 );
827
+ } else {
828
+ int offsetToJumpTableBase = masm .position () - jumpTablePos ;
829
+ label .addPatchAt (masm .position (), masm );
830
+ masm .emitByte (0 ); // pseudo-opcode for jump table entry
831
+ masm .emitShort (offsetToJumpTableBase );
832
+ masm .emitByte (0 ); // padding to make jump table entry 4 bytes wide
833
+ }
814
834
}
815
- if (label .isBound ()) {
816
- int imm32 = label .position () - jumpTablePos ;
817
- masm .emitInt (imm32 );
818
- } else {
819
- int offsetToJumpTableBase = masm .position () - jumpTablePos ;
820
- label .addPatchAt (masm .position (), masm );
821
- masm .emitByte (0 ); // pseudo-opcode for jump table entry
822
- masm .emitShort (offsetToJumpTableBase );
823
- masm .emitByte (0 ); // padding to make jump table entry 4 bytes wide
824
- }
825
- }
826
835
827
- JumpTable jt = new JumpTable (jumpTablePos , 0 , keys .length - 1 , entryFormat );
828
- crb .compilationResult .addAnnotation (jt );
836
+ JumpTable jt = new JumpTable (jumpTablePos , 0 , keys .length - 1 , entryFormat );
837
+ crb .compilationResult .addAnnotation (jt );
838
+ });
829
839
}
830
840
}
831
841
0 commit comments