diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/clz/ClassFile.java b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/clz/ClassFile.java index 3a267144af..861e2417ea 100644 --- a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/clz/ClassFile.java +++ b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/clz/ClassFile.java @@ -93,6 +93,7 @@ public String getSuperClassName(){ public Method getMethod(String methodName, String paramAndReturnType){ List list = getMethods(); for(Method m : list){ + String name = ((UTF8Info)pool.getConstantInfo(m.getNameIndex())).getValue(); String desc = ((UTF8Info)pool.getConstantInfo(m.getDescriptorIndex())).getValue(); if(name.equalsIgnoreCase(methodName) && desc.equalsIgnoreCase(paramAndReturnType)){ diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/cmd/InvokeVirtualCmd.java b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/cmd/InvokeVirtualCmd.java index 0fe36e278e..f4aa2b403c 100644 --- a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/cmd/InvokeVirtualCmd.java +++ b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/cmd/InvokeVirtualCmd.java @@ -41,7 +41,7 @@ public void execute(StackFrame frame, ExecutionResult result) { String currentClassName = javaObject.getClassName(); while(null != currentClassName){ ClassFile currentClassFile = methodArea.findClassFile(currentClassName); - m = currentClassFile.getMethod(methodRefInfo.getClassName(), methodRefInfo.getParamAndReturnType()); + m = currentClassFile.getMethod(methodRefInfo.getMethodName(), methodRefInfo.getParamAndReturnType()); if(null != m){ break; }else{ diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/engine/ExecutorEngine.java b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/engine/ExecutorEngine.java index 3933323574..6906922ee4 100644 --- a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/engine/ExecutorEngine.java +++ b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/engine/ExecutorEngine.java @@ -30,6 +30,8 @@ public void execute(Method mainMethod){ nextFrame.setCallerFrame(frame); setupFunctionCallParams(frame,nextFrame); stack.push(nextFrame); + }else{ + stack.pop(); } } } diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/engine/MethodArea.java b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/engine/MethodArea.java index a204180875..a4041c88bd 100644 --- a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/engine/MethodArea.java +++ b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/engine/MethodArea.java @@ -1,5 +1,6 @@ package com.github.ipk2015.coding2017.minijvm.engine; +import java.io.File; import java.util.HashMap; import java.util.Map; @@ -42,7 +43,7 @@ public Method getMainMethod(String className){ public ClassFile findClassFile(String className){ - + className = className.replace('.', File.separatorChar); if(map.get(className) != null){ return map.get(className); } diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/loader/ClassFileLoader.java b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/loader/ClassFileLoader.java index 2f854174dd..0f6e9ed144 100644 --- a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/loader/ClassFileLoader.java +++ b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/loader/ClassFileLoader.java @@ -28,12 +28,10 @@ public class ClassFileLoader { public byte[] readBinaryCode(String className) { className = className.replace('.', File.separatorChar) +".class"; - for(String path : this.clzPaths){ - String clzFileName = path + File.separatorChar + className; byte[] codes = loadClassFile(clzFileName); - if(codes != null){ + if(codes != null && codes.length>0){ return codes; } } @@ -53,7 +51,7 @@ private byte[] loadClassFile(String clzFileName) { return IOUtils.toByteArray(new FileInputStream(f)); } catch (IOException e) { - e.printStackTrace(); +// e.printStackTrace(); return null; } } diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/loader/ClassFileParser.java b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/loader/ClassFileParser.java index b12e564b88..1c77ba1bfe 100644 --- a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/loader/ClassFileParser.java +++ b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/loader/ClassFileParser.java @@ -164,7 +164,7 @@ private void meetUTF8Info(ConstantPool pool,ByteCodeIterator iter){ private void parseInterfaces(ByteCodeIterator iter) { int interfaceCount = iter.nextUNToInt(2); - System.out.println("interfaceCount:" + interfaceCount); +// System.out.println("interfaceCount:" + interfaceCount); // TODO : 如果实现了interface, 这里需要解析 } diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/test/ClassFileloaderTest.java b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/test/ClassFileloaderTest.java index 213046188c..a39c797c26 100644 --- a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/test/ClassFileloaderTest.java +++ b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/test/ClassFileloaderTest.java @@ -47,7 +47,7 @@ public class ClassFileloaderTest { // String className = "com.coderising.jvm.test.EmployeeV1"; String className = "EmployeeV1";//老师的class文件单独放在这里,只有类名 - clzFile = loader.loadClass(className); + clzFile = loader.loadClass(FULL_QUALIFIED_CLASS_NAME); clzFile.print(); } @@ -79,9 +79,7 @@ public void testClassFileLength() { ClassFileLoader loader = new ClassFileLoader(); loader.addClassPath(path3); - String className = "EmployeeV1"; - - byte[] byteCodes = loader.readBinaryCode(className); + byte[] byteCodes = loader.readBinaryCode(FULL_QUALIFIED_CLASS_NAME); // 注意:这个字节数可能和你的JVM版本有关系, 你可以看看编译好的类到底有多大 Assert.assertEquals(1056, byteCodes.length); @@ -93,8 +91,7 @@ public void testClassFileLength() { public void testMagicNumber(){ ClassFileLoader loader = new ClassFileLoader(); loader.addClassPath(path3); - String className = "EmployeeV1"; - byte[] byteCodes = loader.readBinaryCode(className); + byte[] byteCodes = loader.readBinaryCode(FULL_QUALIFIED_CLASS_NAME); byte[] codes = new byte[]{byteCodes[0],byteCodes[1],byteCodes[2],byteCodes[3]}; @@ -137,7 +134,7 @@ public void testConstantPool(){ ConstantPool pool = clzFile.getConstantPool(); - System.out.println(""+pool.getSize()); + System.out.println("pool size:"+pool.getSize()); Assert.assertEquals(53, pool.getSize()); { diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/test/MiniJVMTest.java b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/test/MiniJVMTest.java new file mode 100644 index 0000000000..16019f78ce --- /dev/null +++ b/group24/121111914/src/com/github/ipk2015/coding2017/minijvm/test/MiniJVMTest.java @@ -0,0 +1,43 @@ +package com.github.ipk2015.coding2017.minijvm.test; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.github.ipk2015.coding2017.minijvm.engine.MiniJVM; + +public class MiniJVMTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void test() { + MiniJVM jvm = new MiniJVM(); + String[] classPaths = new String[3]; + classPaths[0] = ClassFileloaderTest.path1; + classPaths[1] = ClassFileloaderTest.path2; + classPaths[2] = ClassFileloaderTest.path3; + String className = "com.coderising.jvm.test.EmployeeV1"; + try { + jvm.run(classPaths, className); + Assert.assertEquals(0,0); + } catch (IOException e) { + // TODO Auto-generated catch block + + e.printStackTrace(); + Assert.assertEquals(0,1); + } + } + +}