ClassFileAnalyzer (Can)
Home

 

Example: TestCanTableswitch

Test jvm instruction tableswitch

 

/* TestCanTableswitch.java */

public class TestCanTableswitch {
  
  public static void main(String[] args)   {
    int a = 4;
    int b = 0;
    switch (a) {
      case 3: b++; 
              break;
      case 4: b += 2; 
              break;
      case 6: b += 3; 
              break;
      default: b += 5;
    }  
    b--;
  }
}

 

> javac TestCanTableswitch.java
> java ClassFileAnalyzer TestCanTableswitch.class

 

; TestCanTableswitch.j

; Generated by ClassFileAnalyzer (Can)
; Analyzer and Disassembler for Java class files
; (Jasmin syntax 2, http://jasmin.sourceforge.net)
;
; ClassFileAnalyzer, version 0.7.0 


.bytecode 50.0
.source TestCanTableswitch.java
.class public TestCanTableswitch
.super java/lang/Object

.method public <init>()V
  .limit stack 1
  .limit locals 1
  .line 3
  0: aload_0
  1: invokespecial java/lang/Object/<init>()V
  4: return
.end method

.method public static main([Ljava/lang/String;)V
  .limit stack 1
  .limit locals 3
  .line 6
  0: iconst_4
  1: istore_1
  .line 7
  2: iconst_0
  3: istore_2
  .line 8
  4: iload_1
  5: tableswitch 3 6
         Label36
         Label42
         Label54
         Label48
         default : Label54
Label36:
  .line 9
  36: iinc 2 1
  .line 10
  39: goto Label57
Label42:
  .line 11
  42: iinc 2 2
  .line 12
  45: goto Label57
Label48:
  .line 13
  48: iinc 2 3
  .line 14
  51: goto Label57
Label54:
  .line 15
  54: iinc 2 5
Label57:
  .line 17
  57: iinc 2 -1
  .line 18
  60: return
  ; append_frame (frameNumber = 0)
  ; frame_type = 253, offset_delta = 36
  ; frame bytes: 253 0 36 1 1 
  .stack 
    offset 36
    locals Integer
    locals Integer
    .end stack
  ; same_frame (frameNumber = 1)
  ; frame_type = 5, offset_delta = 5
  ; frame bytes: 5 
  .stack 
    offset 42
    locals Integer
    locals Integer
    .end stack
  ; same_frame (frameNumber = 2)
  ; frame_type = 5, offset_delta = 5
  ; frame bytes: 5 
  .stack 
    offset 48
    locals Integer
    locals Integer
    .end stack
  ; same_frame (frameNumber = 3)
  ; frame_type = 5, offset_delta = 5
  ; frame bytes: 5 
  .stack 
    offset 54
    locals Integer
    locals Integer
    .end stack
  ; same_frame (frameNumber = 4)
  ; frame_type = 2, offset_delta = 2
  ; frame bytes: 2 
  .stack 
    offset 57
    locals Integer
    locals Integer
    .end stack
.end method