∟AsmTools/JCOD Disassembler: "jdec"

This section provides a tutorial example on how to disassemble a JVM bytecode using the AsmTools/JCOD disassembler.

What Is AsmTools/JCOD Disassembler? AsmTools/JCOD disassembler is a tool provided in the AsmTools/JASM package that allows you to disassemble JVM bytecode back into AsmTools/JCOD assembly code. JCOD disassembler can be invoked by the "jdec" sub-command.

Let's try it with HelloWorld.class generated in the last tutorial.

1. Disassemble HelloWorld.class back to JCOD format and save it in "out" sub-directory:

herong> mkdir out

herong> java -jar asmtools-core-7.0.b10-ea.jar jdec HelloWorld.class \
  > out/HelloWorld.jcod

herong> ls -l out
  -rw-r--r--  1 herong  staff  1436 Nov 12 22:21 HelloWorld.jcod

2. Review the disassembled JCOD code.

herong> more out/HelloWorld.jcod

class HelloWorld {
  0xCAFEBABE;
  0; // minor version
  55; // version
  [] { // Constant Pool
    ; // first element is empty
    Field #2 #3; // #1
    class #4; // #2
    NameAndType #5 #6; // #3
    Utf8 "java/lang/System"; // #4
    Utf8 "out"; // #5
    Utf8 "Ljava/io/PrintStream;"; // #6
    String #8; // #7
    Utf8 "Hello, World from JCOD!"; // #8
    Method #10 #11; // #9
    class #12; // #10
    NameAndType #13 #14; // #11
    Utf8 "java/io/PrintStream"; // #12
    Utf8 "println"; // #13
    Utf8 "(Ljava/lang/String;)V"; // #14
    class #16; // #15
    Utf8 "HelloWorld"; // #16
    Utf8 "Code"; // #17
    Utf8 "main"; // #18
    Utf8 "([Ljava/lang/String;)V"; // #19
    class #21; // #20
    Utf8 "java/lang/Object"; // #21
  } // Constant Pool

  0x0021; // access
  #15;// this_cpx
  #20;// super_cpx

  [] { // Interfaces
  } // Interfaces

  [] { // Fields
  } // Fields

  [] { // Methods
    {  // method
      0x0009; // access
      #18; // name_index
      #19; // descriptor_index
      [] { // Attributes
        Attr(#17) { // Code
          2; // max_stack
          1; // max_locals
          Bytes[]{
            0xB200011207B60009;
            0xB1;
          }
          [] { // Traps
          } // end Traps
          [] { // Attributes
          } // Attributes
        } // end Code
      } // Attributes
    }
  } // Methods

  [] { // Attributes
  } // Attributes
} // end class HelloWorld

The disassembled version looks almost the same as the original JCOD version. The main difference is that the bytecode sequence is merged into a single hexadecimal string. It will be nice if bytecode sequence is separated into segments of JVM instructions.

3. Re-compile the disassembled JCOD code. The new bytecode file is identical to the original bytecode file.

herong> cd out

herong> java -jar ../asmtools-core-7.0.b10-ea.jar jcoder HelloWorld.jcod

herong> diff HelloWorld.class ../HelloWorld.class

Table of Contents

 About This Book

 JVM (Java Virtual Machine) Specification

 Java HotSpot VM - JVM by Oracle/Sun

 java.lang.Runtime Class - The JVM Instance

 java.lang.System Class - The Operating System

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

 JVM Runtime Data Areas

 JVM Stack, Frame and Stack Overflow

 Thread Testing Program and Result

 CPU Impact of Multi-Thread Applications

 I/O Impact of Multi-Thread Applications

 CDS (Class Data Sharing)

 Micro Benchmark Runner and JVM Options

 Micro Benchmark Tests on "int" Operations

 Micro Benchmark Tests on "long" Operations

 Micro Benchmark Tests in JIT Compilation Mode

 Micro Benchmark Tests on "float" and "double" Operations

 OpenJ9 by Eclipse Foundation

 JRockit JVM 28.2.7 by Oracle Corporation

 JVM Bytecode and Instruction Set

►JVM Assembler/Disassembler Tools

 What Is JVM Assembler

 What Is Jasmin

 Compare HelloWorld.j with "javap" Output

 Jasmin Assembly Statements

 Jasmin Example - Empty.j

 Jasmin Example - Calculator.j

 What Is JASM

 JASM Assembly Statements

 JASM Example - Calculator.jasm

 JASM Disassembler: "jasm -d"

 What Is AsmTools

 AsmTools/JASM Assembly Statements

 AsmTools/JASM Example - Calculator.jasm

 AsmTools/JASM Disassembler: "jdis"

 AsmTools/JCOD Assembly File Format

 AsmTools/JCOD Example - HelloWorld.jcod

►AsmTools/JCOD Disassembler: "jdec"

 What Is Lilac

 Lilac Assembly Statements

 Lilac Macro Example - HelloWorldMacro.jasm

 Lilac Disassembler: "jdasm"

 Archived Tutorials

 References

 Index

 Full Version in PDF/EPUB