ClassFileAnalyzer (Can)
Home

 

Example: TestCanStack

Test directive .stack

 

/* TestCanStack.java */

public class TestCanStack implements Runnable {
 
  public void run() {
    System.out.println("run...");
  }  
  
  public static void main(String[] args) {
    TestCanStack tcs = new TestCanStack(); 
    
    Thread t = new Thread(tcs);
    t.start();
    try {
      Thread.sleep(2000);
    } catch (InterruptedException e) {
      System.out.println(e.toString());
    }
  }
}

 

> javac TestCanStack.java
> java ClassFileAnalyzer TestCanStack.class

 

; TestCanStack.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 TestCanStack.java
.class public TestCanStack
.super java/lang/Object
.implements java/lang/Runnable

.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 run()V
  .limit stack 2
  .limit locals 1
  .line 6
  0: getstatic java/lang/System/out Ljava/io/PrintStream;
  3: ldc "run..."
  5: invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
  .line 7
  8: return
.end method

.method public static main([Ljava/lang/String;)V
  .limit stack 3
  .limit locals 4
  .line 10
  0: new TestCanStack
  3: dup
  4: invokespecial TestCanStack/<init>()V
  7: astore_1
  .line 12
  8: new java/lang/Thread
  11: dup
  12: aload_1
  13: invokespecial java/lang/Thread/<init>(Ljava/lang/Runnable;)V
  16: astore_2
  .line 13
  17: aload_2
  18: invokevirtual java/lang/Thread/start()V
Label21:
  .line 15
  21: ldc2_w 2000
  24: invokestatic java/lang/Thread/sleep(J)V
Label27:
  .line 18
  27: goto Label41
Label30:
  .line 16
  30: astore_3
  .line 17
  31: getstatic java/lang/System/out Ljava/io/PrintStream;
  34: aload_3
  35: invokevirtual java/lang/InterruptedException/toString()Ljava/lang/String;
  38: invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
Label41:
  .line 19
  41: return
  .catch java/lang/InterruptedException from Label21 to Label27 using Label30
  ; full_frame (frameNumber = 0)
  ; frame_type = 255, offset_delta = 30
  ; frame bytes: 255 0 30 0 3 7 0 25 7 0 26 7 0 27 0 1 7 0 28 
  .stack 
    offset 30
    locals Object [Ljava/lang/String;
    locals Object TestCanStack
    locals Object java/lang/Thread
    stack Object java/lang/InterruptedException
    .end stack
  ; same_frame (frameNumber = 1)
  ; frame_type = 10, offset_delta = 10
  ; frame bytes: 10 
  .stack 
    offset 41
    locals Object [Ljava/lang/String;
    locals Object TestCanStack
    locals Object java/lang/Thread
    .end stack
.end method

 

 

 

 

> java Jasmin TestCanStack.j
  --> TestCanStack.class

  
  
Attribute StackMapTable within TestCanStack.class:

StackMapTable_attribute = 
0 26 0 0 0 22 0 2 255 0 30 0 3 7 0 4 
7 0 33 7 0 20 0 1 7 0 37 10 



Structure of StackMapTable_attribute:

StackMapTable_attribute {
    u2 attribute_name_index;
    u4 attribute_length
    u2 number_of_entries;
    stack_map_frame entries[number_of_entries];
}



    union { 
            same_frame;
            same_locals_1_stack_item_frame;
            same_locals_1_stack_item_frame_extended;
            chop_frame;
            same_frame_extended;
            append_frame;
            full_frame;
            
    } stack_map_frame

    
    
        same_frame {
            u1 frame_type = SAME; /* 0-63 */
        }
        same_locals_1_stack_item_frame {
            u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
            verification_type_info stack[1];
        }
        same_locals_1_stack_item_frame_extended {
            u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
            u2 offset_delta;
            verification_type_info stack[1];
        }
        chop_frame {
            u1 frame_type=CHOP; /* 248-250 */
            u2 offset_delta;
        }
        same_frame_extended {
            u1 frame_type = SAME_FRAME_EXTENDED; /* 251 */
            u2 offset_delta;
        }
        append_frame {
            u1 frame_type = APPEND; /* 252-254 */
            u2 offset_delta;
            verification_type_info locals[frame_type -251];
        }
        full_frame {
            u1 frame_type = FULL_FRAME; /* 255 */
            u2 offset_delta;
            u2 number_of_locals;
            verification_type_info locals[number_of_locals];
            u2 number_of_stack_items;
            verification_type_info stack[number_of_stack_items];
        }
        
        
        
        
            union {
                    Top_variable_info;
                    Integer_variable_info;
                    Float_variable_info;
                    Long_variable_info;
                    Double_variable_info;
                    Null_variable_info;
                    UninitializedThis_variable_info;
                    Object_variable_info;
                    Uninitialized_variable_info;
                    
            } verification_type_info
                        
            
            
                Top_variable_info {
                    u1 tag = ITEM_Top; /* 0 */
                }
                Integer_variable_info {
                    u1 tag = ITEM_Integer; /* 1 */
                }
                Float_variable_info {
                    u1 tag = ITEM_Float; /* 2 */
                }
                Long_variable_info {
                    u1 tag = ITEM_Long; /* 4 */
                }
                Double_variable_info {
                    u1 tag = ITEM_Double; /* 3 */
                }
                Null_variable_info {
                    u1 tag = ITEM_Null; /* 5 */
                }
                UninitializedThis_variable_info {
                    u1 tag = ITEM_UninitializedThis; /* 6 */
                }
                Object_variable_info {
                    u1 tag = ITEM_Object; /* 7 */
                    u2 cpool_index;
                }
                Uninitialized_variable_info {
                    u1 tag = ITEM_Uninitialized /* 8 */
                    u2 offset;
                }