forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
610 additions
and
25 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
group24/626451284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/clz/AccessFlag.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,7 @@ | ||
package com.github.wdn.coding2017.jvm.clz; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/6 0006. | ||
*/ | ||
public class AccessFlag { | ||
} |
60 changes: 60 additions & 0 deletions
60
group24/626451284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/clz/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,60 @@ | ||
package com.github.wdn.coding2017.jvm.clz; | ||
|
||
import com.github.wdn.coding2017.jvm.constant.ConstantPool; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/6 0006. | ||
*/ | ||
public class ClassFile { | ||
private int minorVersion; | ||
private int majorVersion; | ||
private ConstantPool constantPool; | ||
private AccessFlag accessFlag; | ||
private ClassIndex classIndex; | ||
public void print() { | ||
} | ||
|
||
public int getMinorVersion() { | ||
return minorVersion; | ||
} | ||
|
||
public int getMajorVersion() { | ||
return majorVersion; | ||
} | ||
|
||
public void setMinorVersion(int minorVersion) { | ||
this.minorVersion = minorVersion; | ||
} | ||
|
||
public void setMajorVersion(int majorVersion) { | ||
this.majorVersion = majorVersion; | ||
} | ||
|
||
public ConstantPool getConstantPool() { | ||
return constantPool; | ||
} | ||
|
||
public void setConstantPool(ConstantPool constantPool) { | ||
this.constantPool = constantPool; | ||
} | ||
|
||
public AccessFlag getAccessFlag() { | ||
return accessFlag; | ||
} | ||
|
||
public void setAccessFlag(AccessFlag accessFlag) { | ||
this.accessFlag = accessFlag; | ||
} | ||
|
||
public ClassIndex getClassIndex() { | ||
return classIndex; | ||
} | ||
|
||
public void setClassIndex(ClassIndex classIndex) { | ||
this.classIndex = classIndex; | ||
} | ||
|
||
public ClassIndex getClzIndex() { | ||
return null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
group24/626451284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/clz/ClassIndex.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 com.github.wdn.coding2017.jvm.clz; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/6 0006. | ||
*/ | ||
public class ClassIndex { | ||
private int thisClassIndex; | ||
private int superClassIndex; | ||
public ClassIndex(int thisClassIndex,int superClassIndex){ | ||
this.thisClassIndex = thisClassIndex; | ||
this.superClassIndex = superClassIndex; | ||
} | ||
public int getThisClassIndex() { | ||
return thisClassIndex; | ||
} | ||
|
||
public int getSuperClassIndex() { | ||
return superClassIndex; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...24/626451284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/constant/ClassInfo.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,35 @@ | ||
package com.github.wdn.coding2017.jvm.constant; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/6 0006. | ||
*/ | ||
public class ClassInfo extends ConstantInfo{ | ||
private int nameIndex; | ||
public ClassInfo(ConstantPool constantPool){ | ||
super(constantPool); | ||
} | ||
@Override | ||
public int getType() { | ||
return CLASS_INFO; | ||
} | ||
@Override | ||
public String getValue() { | ||
return getConstantPool().getConstantInfo(nameIndex).getValue(); | ||
} | ||
|
||
public int getNameIndex() { | ||
return nameIndex; | ||
} | ||
|
||
public void setNameIndex(int nameIndex) { | ||
this.nameIndex = nameIndex; | ||
} | ||
|
||
public int getUtf8Index() { | ||
return 0; | ||
} | ||
|
||
public String getClassName() { | ||
return getConstantPool().getConstantInfo(nameIndex).getValue(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...626451284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/constant/ConstantInfo.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,30 @@ | ||
package com.github.wdn.coding2017.jvm.constant; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/6 0006. | ||
*/ | ||
public abstract class ConstantInfo { | ||
public static final int UTF8_INFO = 1; | ||
public static final int FLOAT_INFO = 4; | ||
public static final int CLASS_INFO = 7; | ||
public static final int STRING_INFO = 8; | ||
public static final int FIELD_INFO = 9; | ||
public static final int METHOD_INFO = 10; | ||
public static final int NAME_AND_TYPE_INFO = 12; | ||
protected ConstantPool constantPool; | ||
public ConstantInfo(){ | ||
|
||
} | ||
public ConstantInfo(ConstantPool constantPool){ | ||
this.constantPool = constantPool; | ||
} | ||
public abstract int getType(); | ||
public abstract String getValue(); | ||
public ConstantPool getConstantPool(){ | ||
return constantPool; | ||
} | ||
public ConstantInfo getConstantInfo(int index){ | ||
return constantPool.getConstantInfo(index); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...626451284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/constant/ConstantPool.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,32 @@ | ||
package com.github.wdn.coding2017.jvm.constant; | ||
|
||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/6 0006. | ||
*/ | ||
public class ConstantPool { | ||
public static ArrayList<ConstantInfo> constantPool = new ArrayList<ConstantInfo>(); | ||
static{ | ||
constantPool.add(new NullConstantInfo()); | ||
} | ||
public void put(ConstantInfo info){ | ||
constantPool.add(info); | ||
} | ||
public int getSize() { | ||
return constantPool.size()-1; | ||
} | ||
|
||
public ConstantInfo getConstantInfo(int i) { | ||
return constantPool.get(i); | ||
} | ||
@Override | ||
public String toString(){ | ||
StringBuffer stringBuffer = new StringBuffer(); | ||
for (int i = 1; i < constantPool.size(); i++) { | ||
stringBuffer.append("#"+i+"=>"+constantPool.get(i).getValue()); | ||
} | ||
return stringBuffer.toString(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...626451284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/constant/FieldRefInfo.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,39 @@ | ||
package com.github.wdn.coding2017.jvm.constant; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/8 0008. | ||
*/ | ||
public class FieldRefInfo extends ConstantInfo { | ||
private int classInfoIndex; | ||
private int nameAndTypeIndex; | ||
|
||
public FieldRefInfo(ConstantPool constantPool) { | ||
super(constantPool); | ||
} | ||
|
||
@Override | ||
public int getType() { | ||
return FIELD_INFO; | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return getConstantPool().getConstantInfo(classInfoIndex).getValue()+getConstantPool().getConstantInfo(nameAndTypeIndex).getValue(); | ||
} | ||
|
||
public int getClassInfoIndex() { | ||
return classInfoIndex; | ||
} | ||
|
||
public void setClassInfoIndex(int classInfoIndex) { | ||
this.classInfoIndex = classInfoIndex; | ||
} | ||
|
||
public int getNameAndTypeIndex() { | ||
return nameAndTypeIndex; | ||
} | ||
|
||
public void setNameAndTypeIndex(int nameAndTypeIndex) { | ||
this.nameAndTypeIndex = nameAndTypeIndex; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...26451284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/constant/MethodRefInfo.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,37 @@ | ||
package com.github.wdn.coding2017.jvm.constant; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/8 0008. | ||
*/ | ||
public class MethodRefInfo extends ConstantInfo { | ||
private int classInfoIndex; | ||
private int nameAndTypeIndex; | ||
|
||
public MethodRefInfo(ConstantPool constantPool) { | ||
super(constantPool); | ||
} | ||
@Override | ||
public int getType() { | ||
return METHOD_INFO; | ||
} | ||
@Override | ||
public String getValue() { | ||
return getConstantPool().getConstantInfo(classInfoIndex).getValue()+getConstantPool().getConstantInfo(nameAndTypeIndex).getValue(); | ||
} | ||
|
||
public int getClassInfoIndex() { | ||
return classInfoIndex; | ||
} | ||
|
||
public void setClassInfoIndex(int classInfoIndex) { | ||
this.classInfoIndex = classInfoIndex; | ||
} | ||
|
||
public int getNameAndTypeIndex() { | ||
return nameAndTypeIndex; | ||
} | ||
|
||
public void setNameAndTypeIndex(int nameAndTypeIndex) { | ||
this.nameAndTypeIndex = nameAndTypeIndex; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...451284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/constant/NameAndTypeInfo.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,38 @@ | ||
package com.github.wdn.coding2017.jvm.constant; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/8 0008. | ||
*/ | ||
public class NameAndTypeInfo extends ConstantInfo{ | ||
private int nameIndex; | ||
private int descriptorIndex; | ||
|
||
public NameAndTypeInfo(ConstantPool constantPool) { | ||
super(constantPool); | ||
} | ||
|
||
@Override | ||
public int getType() { | ||
return 0; | ||
} | ||
@Override | ||
public String getValue() { | ||
return getConstantPool().getConstantInfo(nameIndex).getValue()+getConstantPool().getConstantInfo(descriptorIndex).getValue(); | ||
} | ||
|
||
public int getNameIndex() { | ||
return nameIndex; | ||
} | ||
|
||
public void setNameIndex(int nameIndex) { | ||
this.nameIndex = nameIndex; | ||
} | ||
|
||
public int getDescriptorIndex() { | ||
return descriptorIndex; | ||
} | ||
|
||
public void setDescriptorIndex(int descriptorIndex) { | ||
this.descriptorIndex = descriptorIndex; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...51284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/constant/NullConstantInfo.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,14 @@ | ||
package com.github.wdn.coding2017.jvm.constant; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/8 0008. | ||
*/ | ||
public class NullConstantInfo extends ConstantInfo { | ||
public int getType() { | ||
return 0; | ||
} | ||
|
||
public String getValue() { | ||
return null; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...4/626451284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/constant/StringInfo.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,30 @@ | ||
package com.github.wdn.coding2017.jvm.constant; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/8 0008. | ||
*/ | ||
public class StringInfo extends ConstantInfo { | ||
public StringInfo(ConstantPool constantPool) { | ||
super(constantPool); | ||
} | ||
|
||
private int stringIndex; | ||
|
||
@Override | ||
public int getType() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return getConstantPool().getConstantInfo(stringIndex).getValue(); | ||
} | ||
|
||
public int getStringIndex() { | ||
return stringIndex; | ||
} | ||
|
||
public void setStringIndex(int stringIndex) { | ||
this.stringIndex = stringIndex; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...p24/626451284/mini-jvm/src/main/java/com/github/wdn/coding2017/jvm/constant/UTF8Info.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,23 @@ | ||
package com.github.wdn.coding2017.jvm.constant; | ||
|
||
/** | ||
* Created by Administrator on 2017/4/8 0008. | ||
*/ | ||
public class UTF8Info extends ConstantInfo{ | ||
private String value; | ||
public UTF8Info(ConstantPool constantPool){ | ||
super(constantPool); | ||
} | ||
@Override | ||
public int getType() { | ||
return UTF8_INFO; | ||
} | ||
@Override | ||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
} |
Oops, something went wrong.