Class MLookupSwitchInsn

  • All Implemented Interfaces:
    Serializable, xyz.cofe.collection.ImTree<ByteCode>, xyz.cofe.collection.ImTreeWalk<ByteCode>, ByteCode, MethodByteCode, MethodWriter

    public class MLookupSwitchInsn
    extends MAbstractBC
    implements MethodWriter
    lookupswitch

    Operation

    Access jump table by key match and jump

    Format

     lookupswitch
     <0-3 byte pad>
     defaultbyte1
     defaultbyte2
     defaultbyte3
     defaultbyte4
     npairs1
     npairs2
     npairs3
     npairs4
     match-offset pairs...
     

    Forms

    lookupswitch = 171 (0xab)

    Operand Stack

    ..., key → ...

    Description

    A lookupswitch is a variable-length instruction. Immediately after the lookupswitch opcode, between zero and three bytes must act as padding, such that defaultbyte1 begins at an address that is a multiple of four bytes from the start of the current method (the opcode of its first instruction). Immediately after the padding follow a series of signed 32-bit values: default, npairs, and then npairs pairs of signed 32-bit values. The npairs must be greater than or equal to 0. Each of the npairs pairs consists of an int match and a signed 32-bit offset. Each of these signed 32-bit values is constructed from four unsigned bytes as (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4.

    The table match-offset pairs of the lookupswitch instruction must be sorted in increasing numerical order by match.

    The key must be of type int and is popped from the operand stack. The key is compared against the match values. If it is equal to one of them, then a target address is calculated by adding the corresponding offset to the address of the opcode of this lookupswitch instruction. If the key does not match any of the match values, the target address is calculated by adding default to the address of the opcode of this lookupswitch instruction. Execution then continues at the target address.

    The target address that can be calculated from the offset of each match-offset pair, as well as the one calculated from default, must be the address of an opcode of an instruction within the method that contains this lookupswitch instruction.

    Notes

    The alignment required of the 4-byte operands of the lookupswitch instruction guarantees 4-byte alignment of those operands if and only if the method that contains the lookupswitch is positioned on a 4-byte boundary.

    The match-offset pairs are sorted to support lookup routines that are quicker than linear search.


    Поисковый переключатель - это инструкция переменной длины. Сразу после кода операции lookupswitch от нуля до трех байтов должны действовать как заполнители, так что defaultbyte1 начинается с адреса, кратного четырем байтам от начала текущего метода (кода операции его первой инструкции). Сразу после заполнения следует ряд 32-битных значений со знаком: default, npairs, а затем npairs пары 32-битных значений со знаком. Число npairs должно быть больше или равно 0. Каждая из пар npairs состоит из соответствия int и 32-битного смещения со знаком. Каждое из этих 32-битных значений со знаком состоит из четырех байтов без знака как (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | байт4.

    Пары совпадения-смещения таблицы инструкции lookupswitch должны быть отсортированы в возрастающем числовом порядке по совпадению.

    Ключ должен иметь тип int и извлекается из стека операндов. Ключ сравнивается со значениями соответствия. Если он равен одному из них, то целевой адрес вычисляется путем добавления соответствующего смещения к адресу кода операции этой инструкции lookupswitch. Если ключ не соответствует ни одному из значений соответствия, целевой адрес вычисляется путем добавления значения по умолчанию к адресу кода операции этой инструкции lookupswitch. Затем выполнение продолжается по целевому адресу.

    Целевой адрес, который может быть вычислен по смещению каждой пары совпадение-смещение, а также адрес, вычисленный по умолчанию, должен быть адресом кода операции инструкции в методе, который содержит эту инструкцию переключателя поиска.

    Примечания

    Выравнивание, необходимое для 4-байтовых операндов инструкции lookupwitch, гарантирует 4-байтовое выравнивание этих операндов тогда и только тогда, когда метод, который содержит lookupswitch, расположен на 4-байтовой границе.

    Пары совпадения-смещения сортируются для поддержки процедур поиска, которые работают быстрее, чем линейный поиск.

    See Also:
    Serialized Form
    • Constructor Detail

      • MLookupSwitchInsn

        public MLookupSwitchInsn()
        Конструктор по умолчанию
      • MLookupSwitchInsn

        public MLookupSwitchInsn​(String defHdl,
                                 int[] keys,
                                 String[] labels)
        Конструктор
        Parameters:
        defHdl - начало блока обработчика по умолчанию.
        keys - значения ключей
        labels - начала блоков обработчика. labels [i] - начало блок-обработчик для ключа keys [i].
      • MLookupSwitchInsn

        public MLookupSwitchInsn​(MLookupSwitchInsn sample)
        Конструктор копирования
        Parameters:
        sample - образец
    • Method Detail

      • getDefaultHandlerLabel

        public String getDefaultHandlerLabel()
        Возвращает начало блока обработчика по умолчанию.
        Returns:
        начало блока обработчика по умолчанию.
      • setDefaultHandlerLabel

        public void setDefaultHandlerLabel​(String defaultHandlerLabel)
        Указывает начало блока обработчика по умолчанию.
        Parameters:
        defaultHandlerLabel - начало блока обработчика по умолчанию.
      • getKeys

        public int[] getKeys()
        Возвращает значения ключей
        Returns:
        значения ключей
      • setKeys

        public void setKeys​(int[] keys)
        Указывает значения ключей
        Parameters:
        keys - значения ключей
      • getLabels

        public String[] getLabels()
        Возвращает начала блоков обработчика. labels [i] - начало блок-обработчик для ключа keys [i].
        Returns:
        начала соответ блока
      • setLabels

        public void setLabels​(String[] labels)
        Указывает начала блоков обработчика. labels [i] - начало блок-обработчик для ключа keys [i].
        Parameters:
        labels - начала соответ блока