-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from zhaohuXing/master
第五次
- Loading branch information
Showing
21 changed files
with
900 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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 @@ | ||
apply plugin: 'java' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile("commons-io:commons-io:2.4") | ||
//compile("commons-lang:commons-lang:2.6") | ||
compile("org.apache.commons:commons-lang3:3.4") | ||
testCompile("junit:junit:4.12") | ||
} | ||
|
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,12 @@ | ||
## 讲课内容: | ||
- 17-03-29 :JVM之classLoader | ||
|
||
## 第七周作业(04-03 至 04-09) | ||
- 实现对一个.class文件的常量池读取 | ||
- 实现StackUtil | ||
- [文章](http://www.jianshu.com/p/502c1e5caa97) | ||
## 完成情况: | ||
|
||
|
||
## 我的收获: | ||
|
25 changes: 25 additions & 0 deletions
25
group11/1178243325/week07/src/main/java/com/sprint/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,25 @@ | ||
package com.sprint.jvm.clz; | ||
|
||
public class AccessFlag { | ||
private int flagValue; | ||
|
||
public AccessFlag(int value) { | ||
this.flagValue = value; | ||
} | ||
|
||
public int getFlagValue() { | ||
return flagValue; | ||
} | ||
|
||
public void setFlagValue(int flagValue) { | ||
this.flagValue = flagValue; | ||
} | ||
|
||
public boolean isPublicClass() { | ||
return (this.flagValue & 0x0001) != 0; | ||
} | ||
|
||
public boolean isFinalClass() { | ||
return (this.flagValue & 0x0010) != 0; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
group11/1178243325/week07/src/main/java/com/sprint/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,71 @@ | ||
package com.sprint.jvm.clz; | ||
|
||
import com.sprint.jvm.constant.ConstantPool; | ||
import com.sprint.jvm.constant.ClassInfo; | ||
public class ClassFile { | ||
private int minorVersion; | ||
private int majorVersion; | ||
|
||
private AccessFlag accessFlag; | ||
private ClassIndex clzIndex; | ||
private ConstantPool pool; | ||
|
||
public int getMinorVersion() { | ||
return minorVersion; | ||
} | ||
|
||
public void setMinorVersion(int minorVersion) { | ||
this.minorVersion = minorVersion; | ||
} | ||
|
||
public int getMajorVersion() { | ||
return majorVersion; | ||
} | ||
|
||
public void setMajorVersion(int majorVersion) { | ||
this.majorVersion = majorVersion; | ||
} | ||
|
||
public AccessFlag getAccessFlag() { | ||
return accessFlag; | ||
} | ||
|
||
public void setAccessFlag(AccessFlag accessFlag) { | ||
this.accessFlag = accessFlag; | ||
} | ||
|
||
public ClassIndex getClassIndex() { | ||
return clzIndex; | ||
} | ||
|
||
public void setClassIndex(ClassIndex clzIndex) { | ||
this.clzIndex = clzIndex; | ||
} | ||
|
||
public ConstantPool getConstantPool() { | ||
return pool; | ||
} | ||
|
||
public void setConstantPool(ConstantPool pool) { | ||
this.pool = pool; | ||
} | ||
|
||
public void print() { | ||
if (this.accessFlag.isPublicClass()) { | ||
System.out.println("Access flag : public "); | ||
} | ||
System.out.println("Class Name:" + getClassName() ); | ||
System.out.println("Super Class Name:" + getSuperClassName()); | ||
} | ||
|
||
private String getClassName() { | ||
int thisClassIndex = this.clzIndex.getThisClassIndex(); | ||
ClassInfo thisClass = (ClassInfo)this.getConstantPool().getConstantInfo(thisClassIndex); | ||
return thisClass.getClassName(); | ||
} | ||
|
||
private String getSuperClassName() { | ||
ClassInfo superClass = (ClassInfo)this.getConstantPool().getConstantInfo(this.clzIndex.getSuperClassIndex()); | ||
return superClass.getClassName(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
group11/1178243325/week07/src/main/java/com/sprint/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,22 @@ | ||
package com.sprint.jvm.clz; | ||
|
||
public class ClassIndex { | ||
private int thisClassIndex; | ||
private int superClassIndex; | ||
|
||
public int getThisClassIndex() { | ||
return thisClassIndex; | ||
} | ||
|
||
public void setThisClassIndex(int index) { | ||
this.thisClassIndex = index; | ||
} | ||
|
||
public int getSuperClassIndex() { | ||
return superClassIndex; | ||
} | ||
|
||
public void setSuperClassIndex(int index) { | ||
this.superClassIndex = index; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
group11/1178243325/week07/src/main/java/com/sprint/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,28 @@ | ||
package com.sprint.jvm.constant; | ||
|
||
public class ClassInfo extends ConstantInfo { | ||
private int type = ConstantInfo.CLASS_INFO; | ||
private int utf8Index; | ||
|
||
public ClassInfo(ConstantPool pool) { | ||
super(pool); | ||
} | ||
|
||
public void setUtf8Index(int index) { | ||
this.utf8Index = index; | ||
} | ||
|
||
public int getUtf8Index() { | ||
return utf8Index; | ||
} | ||
|
||
public int getType() { | ||
return type; | ||
} | ||
|
||
public String getClassName() { | ||
int index = getUtf8Index(); | ||
UTF8Info utf8Info = (UTF8Info)constantPool.getConstantInfo(index); | ||
return utf8Info.getValue(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
group11/1178243325/week07/src/main/java/com/sprint/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,29 @@ | ||
package com.sprint.jvm.constant; | ||
|
||
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 pool) { | ||
this.constantPool = pool; | ||
} | ||
|
||
public abstract int getType(); | ||
|
||
public ConstantPool getConstantPool() { | ||
return constantPool; | ||
} | ||
|
||
public ConstantInfo getConstantInfo(int index) { | ||
return this.constantPool.getConstantInfo(index); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
group11/1178243325/week07/src/main/java/com/sprint/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,28 @@ | ||
package com.sprint.jvm.constant; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ConstantPool { | ||
private List<ConstantInfo> constantInfos = new ArrayList<ConstantInfo>(); | ||
|
||
public ConstantPool() { | ||
|
||
} | ||
|
||
public void addConstantInfo(ConstantInfo info) { | ||
this.constantInfos.add(info); | ||
} | ||
|
||
public ConstantInfo getConstantInfo(int index) { | ||
return this.constantInfos.get(index); | ||
} | ||
|
||
public String getUTF8String(int index) { | ||
return ((UTF8Info)this.constantInfos.get(index)).getValue(); | ||
} | ||
|
||
public Object getSize() { | ||
return this.constantInfos.size() - 1; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
group11/1178243325/week07/src/main/java/com/sprint/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,52 @@ | ||
package com.sprint.jvm.constant; | ||
|
||
public class FieldRefInfo extends ConstantInfo { | ||
private int type = ConstantInfo.FIELD_INFO; | ||
private int classInfoIndex; | ||
private int nameAndTypeIndex; | ||
|
||
public FieldRefInfo(ConstantPool pool) { | ||
super(pool); | ||
} | ||
|
||
public int getType() { | ||
return type; | ||
} | ||
|
||
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; | ||
} | ||
|
||
public String toString() { | ||
NameAndTypeInfo typeInfo = (NameAndTypeInfo)this.getConstantInfo(this.getNameAndTypeIndex()); | ||
return getClassName() + ":" + typeInfo.getName() + ":" + typeInfo.getTypeInfo() + "]"; | ||
} | ||
|
||
public String getClassName() { | ||
ClassInfo classInfo = (ClassInfo)this.getConstantInfo(this.getClassInfoIndex()); | ||
UTF8Info utf8Info = (UTF8Info)this.getConstantInfo(classInfo.getUtf8Index()); | ||
return utf8Info.getValue(); | ||
} | ||
|
||
public String getFieldName() { | ||
NameAndTypeInfo typeInfo = (NameAndTypeInfo)this.getConstantInfo(this.getNameAndTypeIndex()); | ||
return typeInfo.getName(); | ||
} | ||
|
||
public String getFieldType() { | ||
NameAndTypeInfo typeInfo = (NameAndTypeInfo)this.getConstantInfo(this.getNameAndTypeIndex()); | ||
return typeInfo.getTypeInfo(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
group11/1178243325/week07/src/main/java/com/sprint/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,55 @@ | ||
package com.sprint.jvm.constant; | ||
|
||
public class MethodRefInfo extends ConstantInfo { | ||
private int type = ConstantInfo.METHOD_INFO; | ||
|
||
private int classInfoIndex; | ||
private int nameAndTypeIndex; | ||
|
||
public MethodRefInfo(ConstantPool pool) { | ||
super(pool); | ||
} | ||
|
||
public int getType() { | ||
return type; | ||
} | ||
|
||
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; | ||
} | ||
|
||
public String toString() { | ||
return getClassName() + ":" + this.getMethodName() + ":" + this.getParamAndReturnType(); | ||
} | ||
|
||
public String getClassName() { | ||
ConstantPool pool = this.getConstantPool(); | ||
ClassInfo clzInfo = (ClassInfo)pool.getConstantInfo(this.getClassInfoIndex()); | ||
return clzInfo.getClassName(); | ||
} | ||
|
||
public String getMethodName() { | ||
ConstantPool pool = this.getConstantPool(); | ||
NameAndTypeInfo typeInfo = (NameAndTypeInfo)pool.getConstantInfo(this.getNameAndTypeIndex()); | ||
return typeInfo.getName(); | ||
} | ||
|
||
public String getParamAndReturnType() { | ||
ConstantPool pool = this.getConstantPool(); | ||
NameAndTypeInfo typeInfo = (NameAndTypeInfo)pool.getConstantInfo(this.getNameAndTypeIndex()); | ||
return typeInfo.getTypeInfo(); | ||
} | ||
} | ||
|
52 changes: 52 additions & 0 deletions
52
group11/1178243325/week07/src/main/java/com/sprint/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,52 @@ | ||
package com.sprint.jvm.constant; | ||
|
||
public class NameAndTypeInfo extends ConstantInfo { | ||
public int type = ConstantInfo.NAME_AND_TYPE_INFO; | ||
|
||
private int index1; | ||
private int index2; | ||
|
||
public NameAndTypeInfo(ConstantPool pool) { | ||
super(pool); | ||
} | ||
|
||
public int getType() { | ||
return type; | ||
} | ||
|
||
public int getIndex1() { | ||
return index1; | ||
} | ||
|
||
public void setIndex1(int index1) { | ||
this.index1 = index1; | ||
} | ||
|
||
public int getIndex2() { | ||
return index2; | ||
} | ||
|
||
public void setIndex2(int index2) { | ||
this.index2 = index2; | ||
} | ||
|
||
public String getName() { | ||
ConstantPool pool = this.getConstantPool(); | ||
UTF8Info utf8Info1 = (UTF8Info)pool.getConstantInfo(index1); | ||
return utf8Info1.getValue(); | ||
} | ||
|
||
public String getTypeInfo() { | ||
ConstantPool pool = this.getConstantPool(); | ||
UTF8Info utf8Info2 = (UTF8Info)pool.getConstantInfo(index2); | ||
return utf8Info2.getValue(); | ||
} | ||
|
||
public String toString() { | ||
return "(" + getName() + "," + getTypeInfo() + ")"; | ||
} | ||
|
||
|
||
} | ||
|
||
|
Oops, something went wrong.