October 22, 2024
Chicago 12, Melborne City, USA
java

java bytecode exception catch block's boundary


I got a class which generated by dex2jar, the bytecode like this

  public boolean a(com.google.android.exoplayer2.metadata.Metadata);
    descriptor: (Lcom/google/android/exoplayer2/metadata/Metadata;)Z
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=6, args_size=2
         0: iconst_0
         1: istore_2
         2: aload_1
         3: getfield      #38                 // Field com/google/android/exoplayer2/metadata/Metadata.d:[Lcom/google/android/exoplayer2/metadata/Metadata$Entry;
         6: astore        5
         8: iload_2
         9: aload         5
        11: arraylength
        12: if_icmpge     134
        15: aload         5
        17: iload_2
        18: aaload
        19: astore        5
        21: aload         5
        23: instanceof    #40                 // class com/google/android/exoplayer2/metadata/id3/CommentFrame
        26: ifeq          128
        29: aload         5
        31: checkcast     #40                 // class com/google/android/exoplayer2/metadata/id3/CommentFrame
        34: astore        5
        36: ldc           #42                 // String iTunSMPB
        38: aload         5
        40: getfield      #46                 // Field com/google/android/exoplayer2/metadata/id3/CommentFrame.f:Ljava/lang/String;
        43: invokevirtual #52                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
        46: ifne          54
        49: iconst_0
        50: istore_3
        51: goto          122
        54: getstatic     #21                 // Field c:Ljava/util/regex/Pattern;
        57: aload         5
        59: getfield      #55                 // Field com/google/android/exoplayer2/metadata/id3/CommentFrame.g:Ljava/lang/String;
        62: invokevirtual #59                 // Method java/util/regex/Pattern.matcher:(Ljava/lang/CharSequence;)Ljava/util/regex/Matcher;
        65: astore        5
        67: aload         5
        69: invokevirtual #65                 // Method java/util/regex/Matcher.find:()Z
        72: ifeq          49
        75: aload         5
        77: iconst_1
        78: invokevirtual #69                 // Method java/util/regex/Matcher.group:(I)Ljava/lang/String;
        81: bipush        16
        83: invokestatic  #75                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
        86: istore_3
        87: aload         5
        89: iconst_2
        90: invokevirtual #69                 // Method java/util/regex/Matcher.group:(I)Ljava/lang/String;
        93: bipush        16
        95: invokestatic  #75                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
        98: istore        4
       100: iload_3
       101: ifgt          109
       104: iload         4
       106: ifle          49
       109: aload_0
       110: iload_3
       111: putfield      #27                 // Field a:I
       114: aload_0
       115: iload         4
       117: putfield      #29                 // Field b:I
       120: iconst_1
       121: istore_3
       122: iload_3
       123: ifeq          128
       126: iconst_1
       127: ireturn
       128: iinc          2, 1
       131: goto          2
       134: iconst_0
       135: ireturn
       136: astore        5
       138: goto          49
      Exception table:
         from    to  target type
            75   100   136   Class java/lang/NumberFormatException
           109   120   136   Class java/lang/NumberFormatException

in my opinion: the exception try block’s last instruction’s next must be the catch block’s start instruction.

but this example broke my mind, and the logical is correct!

try block: from 75 to 120, catch block: 136

I want to know is there any other java compiler or non-java compiler optimize instructions like this example.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video