Jasml

The Java Assembling Language


Jasml Home

User Guide

A Simple Example

Jasml Syntax

Attributes

Java Macro Instructions

Java Macro Instruction Index

Javadoc

Download

 

SourceForge.net Logo

 

Attributes

In JASML, attributes are enclosed between '[' and ']', the following attributes are supported:
Synthetic ,Deprecated ,SourceFile, Code, InnerClasses, LineNumberTable, LocalVariableTable.

Besides, the Exceptions attribute are not enclosed with "[" and "]", but are defined in throws clause of the method declaration. And the ConstantValue attribute are part of the field declaration.

Besides, the exception_table,max_stack,max_locals structure of Code attribute are also enclosed between '[' and ']'.


1.Synthetic and Deprecated

These two attributes are simply :

[Synthetic]
[Deprecated]

2.SourceFile

SourceFile attribute should be in the format of "[SourceFile : filename]". Generally, the filename is only the name without the parth, but a filename with path in it is also supported.

3.Code

Code attribute is composed of labels and macro instructions. Label names must be valid java names, and can not be the same with any of the macro instruction names.

When generating .jasm files, for each instruction which is referred elsewhere in the method(the brach instructions, LocalVariableTable etc.), a label is inserted before the instruction. The label is named as lable[line number]. When naming your own labels, you dose not need to follow this rule, only remember that the label name must be unique in the the method.

The Code attribute also has exception_table,max_stack,max_locals structure and it's own attributes, these should be defined as different attributes in the same method where this code attribute is located.

4.max_stack and max_locals of Code attribute

max_stack and max_locals are part of Code attribute, but they should be defined separately as attribute in the same method where the Code attribute is located, such that:
[MaxStack : max_stack_num]
[MaxLocal : max_local_num]

5.exception_table of Code attribute

exception_table is part of the code attribute, but should be defined separately as attribute in the same method where the code attribute is located.

exception_table attribute must start with "[Exceptions:", and followed by exception_table entries, then end with "]".

Each exception_table entry in the .class file has the structure like :


exception_table
{
u2 start_pc;
u2 end_pc;
u2 handler_pc;
u2 catch_type;
}

Each entry maps to a line in exception_table attribute, such that:

start=start_label , end=end_label , handler=handler_label , catch_type=exception_type

These label must have aready been defined in the insctructions, and each entry can only, and must, occupy one line.
Note: the catch_type sometimes can be '0', means this is a finally clause.

6.InnerClasses

InnerClass attribute must start with "[InnerClasses:", followed by innter class entries, then end with "]".

Each inner class are defined such that:

access = inner class access flags , name = inner class name(without the package name) , fullname = fully qualfied inner class name(outername+"$"+name) , outername = fully qualified outer class name with the package name

Each Inner class entry can only, and must, occupy one line.
Note: the name and outername sometimes can be '0', means this is an anonymous inner class.

7.LineNumberTable

When generating .jasm files, with the "-l" option, line number will be outputed.

LineNumberTable attribute must start with "[LineNumber:", followed by line number mappings, then end with "]".
Each line number mappings is defined such that:

labelname -> lineNumber

This lineNumber is the line number of the source .java files, when compiling from .jasm to .class, lineNumbers will be ignored.

8.LocalVariableTable
LocalVariableTable attribute must start with "[LocalVariables:", followed by local variable entries, then end with "]".

Each local variable entry in the .class file are of such a structure:

localvariable
{
u2 start_pc;
u2 length;
u2 name_index;
u2 descriptor_index;
u2 index;
}

Each entry maps to a line in LocalVariableTable attribute, such that:

localvariable-type localvariable-name start=start_label, end=end_label, index=index_number

For example, an int local variable may be defined as

int c start=line0, end=line3, index=1

And for each instance method, there must be an local variable named "this", of the same type to which this method is belongs, and of index 0.

For example, for each instance method in testpackage.SimpleClass, there must be such an local variable entry defined:

testpackage.SimpleClass this start=line_start, end=line_end, index=0

The labels referred here must have aready been defined in the insctructions, and each entry can only, and must, occupy one line.

Note: LocalVariableTable is not a necessary attribute. Some compilers even do not generate a LocalVariableTable in .class files, e.g. the jdk 1.4.2_11.

Also, remember if a local variable is of type double or long, it must occupy two index. Although this is out of the scope of this document, but most people often forget this.



Copyright 2006 - Jiang Yang , All Rights Reserved