Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions group24/494800949/EmployeeV1-javap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
$ javap -verbose EmployeeV1
警告: 二进制文件EmployeeV1包含com.coderising.jvm.test.EmployeeV1
Classfile /H:/sourceCode/coding2017/group24/494800949/EmployeeV1.class
Last modified 2017-4-9; size 1056 bytes
MD5 checksum 8454b8999ccc9a2ae26a405d47558825
Compiled from "EmployeeV1.java"
public class com.coderising.jvm.test.EmployeeV1
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Class #2 // com/coderising/jvm/test/EmployeeV1
#2 = Utf8 com/coderising/jvm/test/EmployeeV1
#3 = Class #4 // java/lang/Object
#4 = Utf8 java/lang/Object
#5 = Utf8 name
#6 = Utf8 Ljava/lang/String;
#7 = Utf8 age
#8 = Utf8 I
#9 = Utf8 <init>
#10 = Utf8 (Ljava/lang/String;I)V
#11 = Utf8 Code
#12 = Methodref #3.#13 // java/lang/Object."<init>":()V
#13 = NameAndType #9:#14 // "<init>":()V
#14 = Utf8 ()V
#15 = Fieldref #1.#16 // com/coderising/jvm/test/EmployeeV1.name:Ljava/lang/String;
#16 = NameAndType #5:#6 // name:Ljava/lang/String;
#17 = Fieldref #1.#18 // com/coderising/jvm/test/EmployeeV1.age:I
#18 = NameAndType #7:#8 // age:I
#19 = Utf8 LineNumberTable
#20 = Utf8 LocalVariableTable
#21 = Utf8 this
#22 = Utf8 Lcom/coderising/jvm/test/EmployeeV1;
#23 = Utf8 setName
#24 = Utf8 (Ljava/lang/String;)V
#25 = Utf8 setAge
#26 = Utf8 (I)V
#27 = Utf8 sayHello
#28 = Fieldref #29.#31 // java/lang/System.out:Ljava/io/PrintStream;
#29 = Class #30 // java/lang/System
#30 = Utf8 java/lang/System
#31 = NameAndType #32:#33 // out:Ljava/io/PrintStream;
#32 = Utf8 out
#33 = Utf8 Ljava/io/PrintStream;
#34 = String #35 // Hello , this is class Employee
#35 = Utf8 Hello , this is class Employee
#36 = Methodref #37.#39 // java/io/PrintStream.println:(Ljava/lang/String;)V
#37 = Class #38 // java/io/PrintStream
#38 = Utf8 java/io/PrintStream
#39 = NameAndType #40:#24 // println:(Ljava/lang/String;)V
#40 = Utf8 println
#41 = Utf8 main
#42 = Utf8 ([Ljava/lang/String;)V
#43 = String #44 // Andy
#44 = Utf8 Andy
#45 = Methodref #1.#46 // com/coderising/jvm/test/EmployeeV1."<init>":(Ljava/lang/String;I)V
#46 = NameAndType #9:#10 // "<init>":(Ljava/lang/String;I)V
#47 = Methodref #1.#48 // com/coderising/jvm/test/EmployeeV1.sayHello:()V
#48 = NameAndType #27:#14 // sayHello:()V
#49 = Utf8 args
#50 = Utf8 [Ljava/lang/String;
#51 = Utf8 p
#52 = Utf8 SourceFile
#53 = Utf8 EmployeeV1.java
{
public com.coderising.jvm.test.EmployeeV1(java.lang.String, int);
descriptor: (Ljava/lang/String;I)V
flags: ACC_PUBLIC
Code:
stack=2, locals=3, args_size=3
0: aload_0
1: invokespecial #12 // Method java/lang/Object."<init>":()V
4: aload_0
5: aload_1
6: putfield #15 // Field name:Ljava/lang/String;
9: aload_0
10: iload_2
11: putfield #17 // Field age:I
14: return
LineNumberTable:
line 9: 0
line 10: 4
line 11: 9
line 12: 14
LocalVariableTable:
Start Length Slot Name Signature
0 15 0 this Lcom/coderising/jvm/test/EmployeeV1;
0 15 1 name Ljava/lang/String;
0 15 2 age I

public void setName(java.lang.String);
descriptor: (Ljava/lang/String;)V
flags: ACC_PUBLIC
Code:
stack=2, locals=2, args_size=2
0: aload_0
1: aload_1
2: putfield #15 // Field name:Ljava/lang/String;
5: return
LineNumberTable:
line 15: 0
line 16: 5
LocalVariableTable:
Start Length Slot Name Signature
0 6 0 this Lcom/coderising/jvm/test/EmployeeV1;
0 6 1 name Ljava/lang/String;

public void setAge(int);
descriptor: (I)V
flags: ACC_PUBLIC
Code:
stack=2, locals=2, args_size=2
0: aload_0
1: iload_1
2: putfield #17 // Field age:I
5: return
LineNumberTable:
line 18: 0
line 19: 5
LocalVariableTable:
Start Length Slot Name Signature
0 6 0 this Lcom/coderising/jvm/test/EmployeeV1;
0 6 1 age I

public void sayHello();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: getstatic #28 // Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc #34 // String Hello , this is class Employee
5: invokevirtual #36 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
8: return
LineNumberTable:
line 21: 0
line 22: 8
LocalVariableTable:
Start Length Slot Name Signature
0 9 0 this Lcom/coderising/jvm/test/EmployeeV1;

public static void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=4, locals=2, args_size=1
0: new #1 // class com/coderising/jvm/test/EmployeeV1
3: dup
4: ldc #43 // String Andy
6: bipush 29
8: invokespecial #45 // Method "<init>":(Ljava/lang/String;I)V
11: astore_1
12: aload_1
13: invokevirtual #47 // Method sayHello:()V
16: return
LineNumberTable:
line 24: 0
line 25: 12
line 27: 16
LocalVariableTable:
Start Length Slot Name Signature
0 17 0 args [Ljava/lang/String;
12 5 1 p Lcom/coderising/jvm/test/EmployeeV1;
}
SourceFile: "EmployeeV1.java"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


import com.coding.mini_jvm.src.com.coderising.jvm.clz.ClassFile;
import com.coding.mini_jvm.src.com.coderising.jvm.cmd.ByteCodeCommand;
import com.coding.mini_jvm.src.com.coderising.jvm.cmd.CommandParser;
import com.coding.mini_jvm.src.com.coderising.jvm.loader.ByteCodeIterator;

public class CodeAttr extends AttributeInfo {
Expand All @@ -13,21 +15,23 @@ public String getCode() {
return code;
}

//private ByteCodeCommand[] cmds ;
//public ByteCodeCommand[] getCmds() {
// return cmds;
//}
private LineNumberTable lineNumTable;
private ByteCodeCommand[] cmds;

public ByteCodeCommand[] getCmds() {
return cmds;
}

private LineNumberTable lineNumTable;
private LocalVariableTable localVarTable;
private StackMapTable stackMapTable;
public CodeAttr(int attrNameIndex, int attrLen, int maxStack, int maxLocals, int codeLen,String code /*ByteCodeCommand[] cmds*/) {
private StackMapTable stackMapTable;

public CodeAttr(int attrNameIndex, int attrLen, int maxStack, int maxLocals, int codeLen, String code ,ByteCodeCommand[] cmds) {
super(attrNameIndex, attrLen);
this.maxStack = maxStack;
this.maxLocals = maxLocals;
this.codeLen = codeLen;
this.code = code;
//this.cmds = cmds;
this.cmds = cmds;
}

public void setLineNumberTable(LineNumberTable t) {
Expand All @@ -47,9 +51,9 @@ public static CodeAttr parse(ClassFile clzFile, ByteCodeIterator iter){
int maxStack = iter.readTwoBytesToInt();
int maxLocal = iter.readTwoBytesToInt();
int codeLen = iter.readFourBytesToInt();
String code = iter.readBytesToString(codeLen);
CodeAttr codeAttr = new CodeAttr(attrNameIndex, attrLen, maxStack, maxLocal, codeLen, code);

String code = iter.readBytesToHexString(codeLen);
ByteCodeCommand[] cmds = CommandParser.parse(clzFile, code);
CodeAttr codeAttr = new CodeAttr(attrNameIndex, attrLen, maxStack, maxLocal, codeLen, code, cmds);
//异常表长度
int exceptionTableLen = iter.readTwoBytesToInt();
if (exceptionTableLen > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class ClassFile {

private static final String MAIN_METHOD_NAME = "main";
private int minorVersion;
private int majorVersion;

Expand Down Expand Up @@ -79,13 +80,33 @@ public void print(){
System.out.println("Super Class Name:"+ getSuperClassName());
}

private String getClassName(){
public String getClassName(){
int thisClassIndex = this.clzIndex.getThisClassIndex();
ClassInfo thisClass = (ClassInfo)this.getConstantPool().getConstantInfo(thisClassIndex);
return thisClass.getClassName();
}
private String getSuperClassName(){
public String getSuperClassName(){
ClassInfo superClass = (ClassInfo)this.getConstantPool().getConstantInfo(this.clzIndex.getSuperClassIndex());
return superClass.getClassName();
}

public Method getMethod(String methodName, String paramAndReturnType){
for (Method method : methods) {
String name = method.getClzFile().getConstantPool().getUTF8String(method.getNameIndex());
if (methodName.equals(name)) {
return method;
}
}

return null;
}
public Method getMainMethod(){
for (Method method : methods) {
String name = method.getClzFile().getConstantPool().getUTF8String(method.getNameIndex());
if (MAIN_METHOD_NAME.equals(name)) {
return method;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.coding.mini_jvm.src.com.coderising.jvm.cmd;

import com.coding.mini_jvm.src.com.coderising.jvm.clz.ClassFile;
import com.coding.mini_jvm.src.com.coderising.jvm.constant.ConstantPool;

public class BiPushCmd extends OneOperandCmd {

public BiPushCmd(ClassFile clzFile,String opCode) {
super(clzFile,opCode);

}

@Override
public String toString(ConstantPool pool) {

return this.getOffset()+": "+ this.getOpCode()+" " + this.getReadableCodeText() + " " + this.getOperand();
}



}
Loading