forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 15
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 #34 from yanghaitao0410/master
aaa
- Loading branch information
Showing
46 changed files
with
2,438 additions
and
528 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="lib" path="C:/Users/yanght/Downloads/dom4j-1.6.1.jar"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | ||
<attributes> | ||
<attribute name="owner.project.facets" value="java"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | ||
<attributes> | ||
<attribute name="owner.project.facets" value="java"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="lib" path="C:/Users/yanght/Downloads/dom4j-1.6.1.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
22 changes: 12 additions & 10 deletions
22
group06/1454385822/src/com/coding/basic/homework_02/litestruts/struts.xml
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<struts> | ||
<action name="login" class="com.coding.basic.homework_02.litestruts.LoginAction"> | ||
<result name="success">/jsp/homepage.jsp</result> | ||
<result name="fail">/jsp/showLogin.jsp</result> | ||
</action> | ||
<action name="logout" class="com.coding.basic.homework_02.litestruts.LogoutAction"> | ||
<result name = "success">/jsp/welcome.jsp</result> | ||
<result name = "error">/jsp/error.jsp</result> | ||
</action> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<struts> | ||
<action name="login" | ||
class="com.coding.basic.homework_02.litestruts.LoginAction"> | ||
<result name="success">/jsp/homepage.jsp</result> | ||
<result name="fail">/jsp/showLogin.jsp</result> | ||
</action> | ||
<action name="logout" | ||
class="com.coding.basic.homework_02.litestruts.LogoutAction"> | ||
<result name="success">/jsp/welcome.jsp</result> | ||
<result name="error">/jsp/error.jsp</result> | ||
</action> | ||
</struts> |
19 changes: 19 additions & 0 deletions
19
group06/1454385822/src/com/coding/basic/homework_04/jvm/attr/AttributeInfo.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,19 @@ | ||
package com.coding.basic.homework_04.jvm.attr; | ||
|
||
public abstract class AttributeInfo { | ||
public static final String CODE = "Code"; | ||
public static final String CONST_VALUE = "ConstantValue"; | ||
public static final String EXCEPTIONS = "Exceptions"; | ||
public static final String LINE_NUM_TABLE = "LineNumberTable"; | ||
public static final String LOCAL_VAR_TABLE = "LocalVariableTable"; | ||
public static final String STACK_MAP_TABLE = "StackMapTable"; | ||
int attrNameIndex; | ||
int attrLen ; | ||
public AttributeInfo(int attrNameIndex, int attrLen) { | ||
|
||
this.attrNameIndex = attrNameIndex; | ||
this.attrLen = attrLen; | ||
} | ||
|
||
|
||
} |
153 changes: 153 additions & 0 deletions
153
group06/1454385822/src/com/coding/basic/homework_04/jvm/attr/CodeAttr.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,153 @@ | ||
package com.coding.basic.homework_04.jvm.attr; | ||
|
||
import com.coding.basic.homework_04.jvm.clz.ClassFile; | ||
import com.coding.basic.homework_04.jvm.cmd.ByteCodeCommand; | ||
import com.coding.basic.homework_04.jvm.cmd.CommandParser; | ||
import com.coding.basic.homework_04.jvm.constant.ConstantPool; | ||
import com.coding.basic.homework_04.jvm.util.ByteCodeIterator; | ||
|
||
public class CodeAttr extends AttributeInfo{ | ||
|
||
private int attrNameIndex; | ||
private int attrLength; | ||
private int maxStack; | ||
private int maxLocals; | ||
private int codeLen; | ||
private String code; | ||
private ByteCodeCommand[] cmds ; | ||
|
||
|
||
|
||
private ClassFile clzFile; | ||
private LineNumberTable lineNumberTable; | ||
private LocalVariableTable localVariableTable; | ||
|
||
public ByteCodeCommand[] getCmds() { | ||
return cmds; | ||
} | ||
|
||
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; | ||
} | ||
public String toString(ConstantPool pool){ | ||
StringBuilder buffer = new StringBuilder(); | ||
// buffer.append("Code:").append(code).append("\n"); | ||
for(int i=0;i<cmds.length;i++){ | ||
buffer.append(cmds[i].toString(pool)).append("\n"); | ||
} | ||
buffer.append("\n"); | ||
buffer.append(this.lineNumberTable.toString()); | ||
buffer.append(this.localVariableTable.toString(pool)); | ||
return buffer.toString(); | ||
} | ||
|
||
public static CodeAttr parse(ClassFile clzFile, ByteCodeIterator iterator) { | ||
CodeAttr codeAttr = null; | ||
int attrNameIndex = iterator.nextU2ToInt(); | ||
int attrLength = iterator.nextU4ToInt(); | ||
int maxStack = iterator.nextU2ToInt(); | ||
int maxLocals = iterator.nextU2ToInt(); | ||
int codeLength = iterator.nextU4ToInt(); | ||
String code = iterator.nextUxToHexString(codeLength); | ||
ByteCodeCommand[] cmds = CommandParser.parse(clzFile, code); | ||
|
||
codeAttr = new CodeAttr(attrNameIndex, attrLength, maxStack, maxLocals, codeLength, code, cmds); | ||
|
||
int exceptionTableLength = iterator.nextU2ToInt(); | ||
if(exceptionTableLength > 0){ | ||
throw new RuntimeException("ExceptionTable has not been implemented"); | ||
} | ||
parseSubAttr(codeAttr, iterator, clzFile); | ||
return codeAttr; | ||
} | ||
|
||
private static void parseSubAttr(CodeAttr codeAttr, ByteCodeIterator iterator, ClassFile clzFile){ | ||
int attributeCount = iterator.nextU2ToInt(); | ||
for(int i=0; i<attributeCount; i++){ | ||
int subAttrNameIndex = iterator.nextU2ToInt(); | ||
String subAttrName = clzFile.getConstantPool().getUTF8String(subAttrNameIndex); | ||
iterator.back(2); | ||
if(AttributeInfo.LINE_NUM_TABLE.equals(subAttrName)){ | ||
LineNumberTable lineNumberTable = LineNumberTable.parse(iterator); | ||
codeAttr.setLineNumberTable(lineNumberTable); | ||
}else if(AttributeInfo.LOCAL_VAR_TABLE.equals(subAttrName)){ | ||
LocalVariableTable localVariableTable = LocalVariableTable.parse(iterator); | ||
codeAttr.setLocalVariableTable(localVariableTable); | ||
}else{ | ||
throw new RuntimeException("this subAttribute has not been implemented"); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
public LocalVariableTable getLocalVariableTable() { | ||
return localVariableTable; | ||
} | ||
|
||
public void setLocalVariableTable(LocalVariableTable localVariableTable) { | ||
this.localVariableTable = localVariableTable; | ||
} | ||
|
||
public LineNumberTable getLineNumberTable() { | ||
return lineNumberTable; | ||
} | ||
|
||
public void setLineNumberTable(LineNumberTable lineNumberTable) { | ||
this.lineNumberTable = lineNumberTable; | ||
} | ||
|
||
public int getAttrNameIndex() { | ||
return attrNameIndex; | ||
} | ||
|
||
public void setAttrNameIndex(int attrNameIndex) { | ||
this.attrNameIndex = attrNameIndex; | ||
} | ||
|
||
public int getAttrLength() { | ||
return attrLength; | ||
} | ||
|
||
public void setAttrLength(int attrLength) { | ||
this.attrLength = attrLength; | ||
} | ||
|
||
public int getMaxStack() { | ||
return maxStack; | ||
} | ||
|
||
public void setMaxStack(int maxStack) { | ||
this.maxStack = maxStack; | ||
} | ||
|
||
public int getMaxLocals() { | ||
return maxLocals; | ||
} | ||
|
||
public void setMaxLocals(int maxLocals) { | ||
this.maxLocals = maxLocals; | ||
} | ||
|
||
public String getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(String code) { | ||
this.code = code; | ||
} | ||
|
||
public ClassFile getClzFile() { | ||
return clzFile; | ||
} | ||
|
||
public void setClzFile(ClassFile clzFile) { | ||
this.clzFile = clzFile; | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
group06/1454385822/src/com/coding/basic/homework_04/jvm/attr/LineNumberTable.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,65 @@ | ||
package com.coding.basic.homework_04.jvm.attr; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.coding.basic.homework_04.jvm.util.ByteCodeIterator; | ||
|
||
public class LineNumberTable extends AttributeInfo { | ||
List<LineNumberItem> items = new ArrayList<LineNumberItem>(); | ||
|
||
private static class LineNumberItem{ | ||
int startPC; | ||
int lineNum; | ||
public int getStartPC() { | ||
return startPC; | ||
} | ||
public void setStartPC(int startPC) { | ||
this.startPC = startPC; | ||
} | ||
public int getLineNum() { | ||
return lineNum; | ||
} | ||
public void setLineNum(int lineNum) { | ||
this.lineNum = lineNum; | ||
} | ||
} | ||
public void addLineNumberItem(LineNumberItem item){ | ||
this.items.add(item); | ||
} | ||
public LineNumberTable(int attrNameIndex, int attrLen) { | ||
super(attrNameIndex, attrLen); | ||
|
||
} | ||
|
||
public static LineNumberTable parse(ByteCodeIterator iter){ | ||
int attrNameIndex = iter.nextU2ToInt(); | ||
int attrLength = iter.nextU4ToInt(); | ||
LineNumberTable table = new LineNumberTable(attrNameIndex, attrLength); | ||
int lineNumberTableLength = iter.nextU2ToInt(); | ||
for(int i=0; i<lineNumberTableLength; i++){ | ||
int startPC = iter.nextU2ToInt(); | ||
int lineNumber = iter.nextU2ToInt(); | ||
LineNumberItem item = new LineNumberItem(); | ||
item.setStartPC(startPC); | ||
item.setLineNum(lineNumber); | ||
table.addLineNumberItem(item); | ||
} | ||
return table; | ||
} | ||
|
||
public String toString(){ | ||
StringBuilder buffer = new StringBuilder(); | ||
buffer.append("Line Number Table:\n"); | ||
for(LineNumberItem item : items){ | ||
buffer.append("startPC:"+item.getStartPC()).append(","); | ||
buffer.append("lineNum:"+item.getLineNum()).append("\n"); | ||
} | ||
buffer.append("\n"); | ||
return buffer.toString(); | ||
|
||
} | ||
|
||
|
||
|
||
} |
98 changes: 98 additions & 0 deletions
98
group06/1454385822/src/com/coding/basic/homework_04/jvm/attr/LocalVariableTable.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 com.coding.basic.homework_04.jvm.attr; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.coding.basic.homework_04.jvm.constant.ConstantPool; | ||
import com.coding.basic.homework_04.jvm.util.ByteCodeIterator; | ||
|
||
public class LocalVariableTable extends AttributeInfo{ | ||
|
||
List<LocalVariableItem> items = new ArrayList<LocalVariableItem>(); | ||
|
||
public LocalVariableTable(int attrNameIndex, int attrLen) { | ||
super(attrNameIndex, attrLen); | ||
} | ||
|
||
|
||
private void addLocalVariableItem(LocalVariableItem item) { | ||
this.items.add(item); | ||
} | ||
|
||
public static LocalVariableTable parse(ByteCodeIterator iter){ | ||
int attrNameIndex = iter.nextU2ToInt(); | ||
int attrLength = iter.nextU4ToInt(); | ||
LocalVariableTable table = new LocalVariableTable(attrNameIndex, attrLength); | ||
int localVariableTableLength = iter.nextU2ToInt(); | ||
for(int i=0; i<localVariableTableLength; i++){ | ||
int startPC = iter.nextU2ToInt(); | ||
int length = iter.nextU2ToInt(); | ||
int nameIndex = iter.nextU2ToInt(); | ||
int descriptorIndex = iter.nextU2ToInt(); | ||
int index = iter.nextU2ToInt(); | ||
LocalVariableItem item = new LocalVariableItem(startPC, length, nameIndex, descriptorIndex, index); | ||
table.addLocalVariableItem(item); | ||
} | ||
return table; | ||
} | ||
|
||
private static class LocalVariableItem{ | ||
int startPC; | ||
int length; | ||
int nameIndex; | ||
int descriptorIndex; | ||
int index; | ||
public LocalVariableItem(int startPC, int length, int nameIndex, int descriptorIndex, int index) { | ||
this.startPC = startPC; | ||
this.length = length; | ||
this.nameIndex = nameIndex; | ||
this.descriptorIndex = descriptorIndex; | ||
this.index = index; | ||
} | ||
public int getStartPC() { | ||
return startPC; | ||
} | ||
public void setStartPC(int startPC) { | ||
this.startPC = startPC; | ||
} | ||
public int getLength() { | ||
return length; | ||
} | ||
public void setLength(int length) { | ||
this.length = length; | ||
} | ||
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; | ||
} | ||
public int getIndex() { | ||
return index; | ||
} | ||
public void setIndex(int index) { | ||
this.index = index; | ||
} | ||
|
||
} | ||
|
||
|
||
public String toString(ConstantPool pool){ | ||
StringBuilder buffer = new StringBuilder(); | ||
buffer.append("Local Variable Table:\n"); | ||
for(LocalVariableItem item : items){ | ||
buffer.append("startPC:"+item.getStartPC()).append(","); | ||
buffer.append("name:"+pool.getUTF8String(item.getNameIndex())).append(","); | ||
buffer.append("desc:"+pool.getUTF8String(item.getDescriptorIndex())).append(","); | ||
buffer.append("slotIndex:"+ item.getIndex()).append("\n"); | ||
} | ||
buffer.append("\n"); | ||
return buffer.toString(); | ||
} | ||
} |
Oops, something went wrong.