Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduction to the class File Format
- Loading branch information
1 parent
bfb804d
commit 6ab1b0a
Showing
10 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
03_projects/pjba/01_src/main/java/org/isk/jvmhardcore/pjba/structure/ClassFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.isk.jvmhardcore.pjba.structure; | ||
|
||
import org.isk.jvmhardcore.pjba.structure.attribute.Attribute; | ||
|
||
public class ClassFile { | ||
final private int magic = 0xcafebabe; | ||
final private int version = 0x30; // 48.0 = 0x00 (version mineure) | 0x30 (version majeur) | ||
private int constantPoolCount; | ||
private Constant.ConstantPoolEntry[] constantPool; | ||
final private int accessFlags = 0x0001 | 0x0020; // public super; | ||
private int thisClass; | ||
private int superClass; | ||
private int interfacesCount; | ||
private int[] interfaces; | ||
private int fieldsCount; | ||
private Field[] fields; | ||
private int methodsCount; | ||
private Method[] methods; | ||
private int attributesCount; | ||
private Attribute[] attributes; | ||
} |
98 changes: 98 additions & 0 deletions
98
03_projects/pjba/01_src/main/java/org/isk/jvmhardcore/pjba/structure/Constant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.isk.jvmhardcore.pjba.structure; | ||
|
||
public class Constant { | ||
public static abstract class ConstantPoolEntry { | ||
final private int tag; | ||
|
||
public ConstantPoolEntry(ConstantPoolTag tag) { | ||
this.tag = tag.getValue(); | ||
} | ||
} | ||
|
||
public static class UTF8 extends ConstantPoolEntry { | ||
final private java.lang.String value; | ||
|
||
public UTF8(final java.lang.String value) { | ||
super(ConstantPoolTag.UTF8); | ||
this.value = value; | ||
} | ||
} | ||
|
||
public static class Integer extends ConstantPoolEntry { | ||
final private int integer; | ||
|
||
public Integer(int integer) { | ||
super(ConstantPoolTag.INTEGER); | ||
this.integer = integer; | ||
} | ||
} | ||
|
||
public static class Float extends ConstantPoolEntry { | ||
final private float floatValue; | ||
|
||
public Float(float floatValue) { | ||
super(ConstantPoolTag.FLOAT); | ||
this.floatValue = floatValue; | ||
} | ||
} | ||
|
||
public static class Long extends ConstantPoolEntry { | ||
final private long longValue; | ||
|
||
public Long(long longValue) { | ||
super(ConstantPoolTag.LONG); | ||
this.longValue = longValue; | ||
} | ||
} | ||
|
||
public static class Double extends ConstantPoolEntry { | ||
final private double doubleValue; | ||
|
||
public Double(double doubleValue) { | ||
super(ConstantPoolTag.DOUBLE); | ||
this.doubleValue = doubleValue; | ||
} | ||
} | ||
|
||
public static class Class extends ConstantPoolEntry { | ||
final private int nameIndex; | ||
|
||
public Class(final int nameIndex) { | ||
super(ConstantPoolTag.CLASS); | ||
this.nameIndex = nameIndex; | ||
} | ||
} | ||
|
||
public static class String extends ConstantPoolEntry { | ||
final private int utf8Index; | ||
|
||
public String(int stringIndex) { | ||
super(ConstantPoolTag.STRING); | ||
this.utf8Index = stringIndex; | ||
} | ||
} | ||
|
||
public static enum ConstantPoolTag { | ||
UTF8(1), | ||
INTEGER(3), | ||
FLOAT(4), | ||
LONG(5), | ||
DOUBLE(6), | ||
CLASS(7), | ||
STRING(8), | ||
FIELDREF(9), | ||
METHODREF(10), | ||
INTERFACE_METHODREF(11), | ||
NAME_AND_TYPE(12); | ||
|
||
private int value; | ||
|
||
private ConstantPoolTag(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return this.value; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
03_projects/pjba/01_src/main/java/org/isk/jvmhardcore/pjba/structure/Exception.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.isk.jvmhardcore.pjba.structure; | ||
|
||
public class Exception { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
03_projects/pjba/01_src/main/java/org/isk/jvmhardcore/pjba/structure/Field.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.isk.jvmhardcore.pjba.structure; | ||
|
||
public class Field { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
03_projects/pjba/01_src/main/java/org/isk/jvmhardcore/pjba/structure/Method.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.isk.jvmhardcore.pjba.structure; | ||
|
||
import org.isk.jvmhardcore.pjba.structure.attribute.Attribute; | ||
|
||
public class Method { | ||
private int accessFlags = 0x0001 | 0x0008; // public static | ||
private int nameIndex; | ||
private int descriptorIndex; | ||
private int attributesCount; | ||
private Attribute[] attributes; | ||
} |
10 changes: 10 additions & 0 deletions
10
...rojects/pjba/01_src/main/java/org/isk/jvmhardcore/pjba/structure/attribute/Attribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.isk.jvmhardcore.pjba.structure.attribute; | ||
|
||
public abstract class Attribute { | ||
final private int nameIndex; | ||
private int attributeLength; | ||
|
||
public Attribute(final int nameIndex) { | ||
this.nameIndex = nameIndex; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
03_projects/pjba/01_src/main/java/org/isk/jvmhardcore/pjba/structure/attribute/Code.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.isk.jvmhardcore.pjba.structure.attribute; | ||
|
||
import org.isk.jvmhardcore.pjba.structure.Exception; | ||
|
||
public class Code extends Attribute { | ||
public final static String ATTRIBUTE_NAME = "Code"; | ||
|
||
private int maxStack; | ||
private int maxLocals; | ||
private int codeLength; | ||
private byte[] code; | ||
private int exceptionsCount; | ||
private Exception[] exceptions; | ||
private int attributesCount; | ||
private Attribute[] attributes; | ||
|
||
public Code(final int attributeNameIndex) { | ||
super(attributeNameIndex); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<project name="pjba" default="archive" xmlns:plume="http://blog.soat.fr/ant-macros"> | ||
<import file="../../01_conf/targets.xml" /> | ||
<description>Plume Java Bytecode Assembler</description> | ||
|
||
<target name="compile" depends="-init"> | ||
<echo>Compiling Main</echo> | ||
<plume:compiler srcDir="${src.main.java.dir}" destDir="${build.classes.dir}" /> | ||
</target> | ||
|
||
<target name="test" depends="compile"> | ||
<!-- Do nothing for now --> | ||
</target> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters