KOPI
PrevChapter 1. Classfile HandlingNext

KOPI Assembly Language

The syntax was designed to be both readable and fully functional (It keep a total power of expression). The primary goal was to let the assembler (the classfile API) do as much work as possible, making for example unnecessary to specify the maximum amount of stack used or the number of local variables, since this information can be deduced from the program to assemble. The instructions opcodes are limited to the strict minimum, and all the instructions defined to optimize a program (such as load_1) will be replaced by the assembler from generics instructions (from load 1).

File structure

The file structure is similar to a Java compilation unit. The syntax looks like a normal Java program for the member's definition. Only the method body is described in assembler. Some special information found in classfiles such as LineNumberTable, LocalVariableTable and attributes are also defined in the method body, but all of this information is optional.

The code of methods is pure Java assembler as defined at http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions.doc.html.

The easiest way to understand KOPI assembler is to look at an example or to decompile your own classes with DIS.

Example

  // compiler version: 45.3
  
  @source "HelloWorldApp.java"
  class HelloWorldApp extends java.lang.Object {
  
      /**
       * main
       *
       * @stack   2
       * @locals  1
       */
      public static void main(java.lang.String[]) {
          @line   3
                  @getstatic      java.io.PrintStream java.lang.System.out
                  @const          "Hello World!"
                  @invokevirtual  void java.io.PrintStream.println(java.lang.String)
          @line   2
                  @return
      }
  
      /**
       * init
       *
       * @stack   1
       * @locals  1
       */
      void init() {
          @line   1
                  @aload          0
                  @invokespecial  void java.lang.Object.init()
                  @return
      }
  }
          

The KOPI Assembler (KSM)

License type: KSM is distributed under the terms of the the GNU General Public License. Appendix B

To launch KSM from the command line, type Java at.dms.ksm.Main. The command line parameters are:

  java at.dms.ksm.Main [dhV] file.ksm+
    -d dir (--destination) to select the output directory for classfiles
    -h (--help) to show the help
    -V (--version) to show the version number
    file the files to assemble
	

The KOPI Disassembler (DIS)

License type: DIS is distributed under the terms of the the GNU PUBLIC License. Appendix B

This tool allows you to see the code actually generated by your compiler and may help you to optimize or understand a portion of the code. This tool may also help you modify some classes from their bytecode in conjunction with KSM(to regenerate them).

To launch KSM from the command line, type:

  java at.dms.dis.Main
	
The command line parameters are:
  java at.dms.dis.Main [cdhisxV] (file.class | class)+
    -c (--stdout) output to stdout instead of a ksm files
    -d dir (--destination) to select the output directory for ksm files
    -h (--help) to show the help
    -i (--interface) to display only the interface 
              of classes (remove method body)
    -s (--sorted) to sort members
    -x (--stack) to display the stack height in front of each instruction
    -V (--version) to show the version number file the files 
 	   to disassemble (prefix must be .classfile)
    class a class (fully qualified name) accessible from the 
           current classpath
	


PrevHomeNext
Classfile HandlingUpKOPI Classfile API