├── .circleci └── config.yml ├── .gitignore ├── HelloWorld.class ├── HelloWorld.java ├── LICENSE ├── README.md ├── bin ├── asmgen ├── asmint ├── java ├── jdb └── test ├── docs ├── .nojekyll ├── CNAME ├── README.md ├── _coverpage.md ├── _sidebar.md ├── aot.md ├── assets │ ├── imgs │ │ ├── mini-jvm-logo.png │ │ └── wechat.jpeg │ └── styles.css ├── changelog.md ├── contributor.md ├── dev.md ├── favicon.ico ├── index.html ├── note.md └── quickstart.md ├── example ├── pom.xml └── src │ └── main │ └── java │ ├── AddN.java │ ├── AddTwoInt.java │ ├── AtomicIntegerTest.java │ ├── BitOpTest.java │ ├── BufferedOutputStreamTest.java │ ├── CharsetTest.java │ ├── Curry2Args.java │ ├── Curry3Args.java │ ├── FdTest.java │ ├── FdTest2.java │ ├── FdTest3.java │ ├── Fibonacci.java │ ├── FileTest.java │ ├── FileTest2.java │ ├── FileTest3.java │ ├── FileTest4.java │ ├── FileTest5.java │ ├── FileTest6.java │ ├── FileTest7.java │ ├── Hello.java │ ├── Hello2.java │ ├── Hello3.java │ ├── Hello4.java │ ├── HelloWorld.java │ ├── Int1.java │ ├── Int2.java │ ├── Int2Impl.java │ ├── Int3.java │ ├── Int3Impl.java │ ├── Int3Impl2.java │ ├── Int4.java │ ├── Int4Impl.java │ ├── Int4Impl2.java │ ├── IoTest0.java │ ├── JarTest.java │ ├── Loop1.java │ ├── Loop100.java │ ├── Loop2.java │ ├── Loop3.java │ ├── Loop4.java │ ├── PassObject.java │ ├── PrintStreamTest.java │ ├── Stack.java │ ├── Sum10.java │ ├── SwitchTest0.java │ ├── SwitchTest1.java │ ├── SystemOutTest.java │ ├── TestArray.java │ ├── TestArray2.java │ ├── TestArrayList.java │ ├── TestClass.java │ ├── TestClass2.java │ ├── TestClass3.java │ ├── TestClass4.java │ ├── TestClass5.java │ ├── TestClosure.java │ ├── TestClosure2.java │ ├── TestException.java │ ├── TestException2.java │ ├── TestException3.java │ ├── TestException4.java │ ├── TestFunctionComposition.java │ ├── TestFunctionComposition2.java │ ├── TestFunctionComposition3.java │ ├── TestFunctionComposition4.java │ ├── TestLambda.java │ ├── TestLambda2.java │ ├── TestLambda3.java │ ├── TestLambda4.java │ ├── TestLambda5.java │ ├── TestList.java │ ├── TestList2.java │ ├── TestLoop.java │ ├── TestMap.java │ ├── TestMap2.java │ ├── TestObject.java │ ├── TestObject2.java │ ├── TestObject3.java │ ├── TestObject4.java │ ├── TestObject5.java │ ├── TestObject6.java │ ├── TestRandom.java │ ├── TestSet.java │ ├── TestStack.java │ ├── TestStack2.java │ ├── TestStatic.java │ ├── TestStatic1.java │ └── TrueFalse.java ├── jvm-core ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── gxk │ │ └── jvm │ │ ├── Args.java │ │ ├── Main.java │ │ ├── VirtualMachine.java │ │ ├── classfile │ │ ├── Attribute.java │ │ ├── AttributeEnum.java │ │ ├── Attributes.java │ │ ├── ClassFile.java │ │ ├── ClassReader.java │ │ ├── CodeAttribute.java │ │ ├── CodeFromByte.java │ │ ├── ConstantInfo.java │ │ ├── ConstantPool.java │ │ ├── ConstantPoolInfoEnum.java │ │ ├── Descriptor.java │ │ ├── Exception.java │ │ ├── ExceptionTable.java │ │ ├── FieldInfo.java │ │ ├── Fields.java │ │ ├── InstructionReader.java │ │ ├── Interface.java │ │ ├── Interfaces.java │ │ ├── MethodInfo.java │ │ ├── Methods.java │ │ ├── MyByteArrayInputStream.java │ │ ├── MyDataInputStream.java │ │ ├── attribute │ │ │ ├── BootstrapMethods.java │ │ │ ├── Code.java │ │ │ ├── ConstantValue.java │ │ │ ├── LineNumberTable.java │ │ │ └── SourceFile.java │ │ └── cp │ │ │ ├── ClassCp.java │ │ │ ├── DoubleCp.java │ │ │ ├── FieldDef.java │ │ │ ├── FloatCp.java │ │ │ ├── IntegerCp.java │ │ │ ├── InterfaceMethodDef.java │ │ │ ├── InvokeDynamic.java │ │ │ ├── LongCp.java │ │ │ ├── MethodDef.java │ │ │ ├── MethodHandle.java │ │ │ ├── MethodType.java │ │ │ ├── NameAndType.java │ │ │ ├── StringCp.java │ │ │ └── Utf8.java │ │ ├── classloader │ │ └── ClassLoader.java │ │ ├── classpath │ │ ├── Classpath.java │ │ ├── CompositeEntry.java │ │ ├── DirEntry.java │ │ ├── Entry.java │ │ └── JarEntry.java │ │ ├── instruction │ │ ├── Instruction.java │ │ ├── comparisons │ │ │ ├── DCmpGInst.java │ │ │ ├── DCmpLInst.java │ │ │ ├── FCmpGInst.java │ │ │ ├── FCmpLInst.java │ │ │ ├── IfACmpEqInst.java │ │ │ ├── IfACmpNeInst.java │ │ │ ├── IfEqInst.java │ │ │ ├── IfGeInst.java │ │ │ ├── IfGtInst.java │ │ │ ├── IfICmpEqInst.java │ │ │ ├── IfICmpGeInst.java │ │ │ ├── IfICmpGtInst.java │ │ │ ├── IfICmpLeInst.java │ │ │ ├── IfICmpLtInst.java │ │ │ ├── IfICmpNeInst.java │ │ │ ├── IfLeInst.java │ │ │ ├── IfLtInst.java │ │ │ ├── IfNeInst.java │ │ │ └── LCmpInst.java │ │ ├── constants │ │ │ ├── AconstNullInst.java │ │ │ ├── BiPushInst.java │ │ │ ├── DConst0Inst.java │ │ │ ├── DConst1Inst.java │ │ │ ├── FConst0Inst.java │ │ │ ├── FConst1Inst.java │ │ │ ├── FConst2Inst.java │ │ │ ├── IConst0Inst.java │ │ │ ├── IConst1Inst.java │ │ │ ├── IConst2Inst.java │ │ │ ├── IConst3Inst.java │ │ │ ├── IConst4Inst.java │ │ │ ├── IConst5Inst.java │ │ │ ├── IConstM1Inst.java │ │ │ ├── Lconst0Inst.java │ │ │ ├── Lconst1Inst.java │ │ │ ├── Ldc2wInst.java │ │ │ ├── LdcInst.java │ │ │ ├── LdcWInst.java │ │ │ ├── NopInst.java │ │ │ └── SiPushInst.java │ │ ├── control │ │ │ ├── AReturnInst.java │ │ │ ├── DReturnInst.java │ │ │ ├── FReturnInst.java │ │ │ ├── IReturnInst.java │ │ │ ├── LReturnInst.java │ │ │ ├── LookupSwitchInst.java │ │ │ ├── ReturnInst.java │ │ │ └── TableSwitchInst.java │ │ ├── conversions │ │ │ ├── D2fInst.java │ │ │ ├── D2iInst.java │ │ │ ├── D2lInst.java │ │ │ ├── F2dInst.java │ │ │ ├── F2iInst.java │ │ │ ├── F2lInst.java │ │ │ ├── I2bInst.java │ │ │ ├── I2cInst.java │ │ │ ├── I2dInst.java │ │ │ ├── I2fInst.java │ │ │ ├── I2lInst.java │ │ │ ├── I2sInst.java │ │ │ ├── L2dInst.java │ │ │ ├── L2fInst.java │ │ │ └── L2iInst.java │ │ ├── extended │ │ │ ├── GotoInst.java │ │ │ ├── GotoWInst.java │ │ │ ├── IfNonNullInst.java │ │ │ ├── IfNullInst.java │ │ │ ├── MultiANewArrayInst.java │ │ │ └── WideInst.java │ │ ├── loads │ │ │ ├── AALoadInst.java │ │ │ ├── ALoad0Inst.java │ │ │ ├── ALoad1Inst.java │ │ │ ├── ALoad2Inst.java │ │ │ ├── ALoad3Inst.java │ │ │ ├── ALoadInst.java │ │ │ ├── BAloadInst.java │ │ │ ├── CAloadInst.java │ │ │ ├── DALoadInst.java │ │ │ ├── DLoad0Inst.java │ │ │ ├── DLoad1Inst.java │ │ │ ├── DLoad2Inst.java │ │ │ ├── DLoad3Inst.java │ │ │ ├── DLoadInst.java │ │ │ ├── FALoadInst.java │ │ │ ├── FLoad0Inst.java │ │ │ ├── FLoad1Inst.java │ │ │ ├── FLoad2Inst.java │ │ │ ├── FLoad3Inst.java │ │ │ ├── FLoadInst.java │ │ │ ├── IALoadInst.java │ │ │ ├── ILoad0Inst.java │ │ │ ├── ILoad1Inst.java │ │ │ ├── ILoad2Inst.java │ │ │ ├── ILoad3Inst.java │ │ │ ├── ILoadNInst.java │ │ │ ├── LALoadInst.java │ │ │ ├── LLoad0Inst.java │ │ │ ├── LLoad1Inst.java │ │ │ ├── LLoad2Inst.java │ │ │ ├── LLoad3Inst.java │ │ │ ├── LLoadInst.java │ │ │ └── SALoadInst.java │ │ ├── math │ │ │ ├── DAddInst.java │ │ │ ├── DDivInst.java │ │ │ ├── DMulInst.java │ │ │ ├── DNegInst.java │ │ │ ├── DRemInst.java │ │ │ ├── DSubInst.java │ │ │ ├── FAddInst.java │ │ │ ├── FDivInst.java │ │ │ ├── FMulInst.java │ │ │ ├── FNegInst.java │ │ │ ├── FRemInst.java │ │ │ ├── FSubInst.java │ │ │ ├── IAddInst.java │ │ │ ├── IAndInst.java │ │ │ ├── IDivInst.java │ │ │ ├── IIncInst.java │ │ │ ├── IMulInst.java │ │ │ ├── INegInst.java │ │ │ ├── IOrInst.java │ │ │ ├── IRemInst.java │ │ │ ├── IShlInst.java │ │ │ ├── IShrInst.java │ │ │ ├── ISubInst.java │ │ │ ├── IUShrInst.java │ │ │ ├── IXOrInst.java │ │ │ ├── LAddInst.java │ │ │ ├── LAndInst.java │ │ │ ├── LDivInst.java │ │ │ ├── LMulInst.java │ │ │ ├── LNegInst.java │ │ │ ├── LOrInst.java │ │ │ ├── LRemInst.java │ │ │ ├── LShlInst.java │ │ │ ├── LShrInst.java │ │ │ ├── LSubInst.java │ │ │ ├── LUShrInst.java │ │ │ └── LXOrInst.java │ │ ├── references │ │ │ ├── ANewArrayInst.java │ │ │ ├── AThrowInst.java │ │ │ ├── ArrayLengthInst.java │ │ │ ├── CheckcastInst.java │ │ │ ├── GetFieldInst.java │ │ │ ├── GetStaticInst.java │ │ │ ├── InstanceofInst.java │ │ │ ├── InvokeDynamicInst.java │ │ │ ├── InvokeInterfaceInst.java │ │ │ ├── InvokeSpecialInst.java │ │ │ ├── InvokeStaticInst.java │ │ │ ├── InvokeVirtualInst.java │ │ │ ├── MonitorEnterInst.java │ │ │ ├── MonitorExitInst.java │ │ │ ├── NewArrayInst.java │ │ │ ├── NewInst.java │ │ │ ├── PutFieldInst.java │ │ │ └── PutStaticInst.java │ │ ├── stack │ │ │ ├── Dup2Inst.java │ │ │ ├── Dup2X1Inst.java │ │ │ ├── Dup2X2Inst.java │ │ │ ├── DupInst.java │ │ │ ├── DupX1Inst.java │ │ │ ├── DupX2Inst.java │ │ │ ├── Pop2Inst.java │ │ │ ├── PopInst.java │ │ │ └── SwapInst.java │ │ └── stores │ │ │ ├── AAStoreInst.java │ │ │ ├── AStore0Inst.java │ │ │ ├── AStore1Inst.java │ │ │ ├── AStore2Inst.java │ │ │ ├── AStore3Inst.java │ │ │ ├── AStoreInst.java │ │ │ ├── BAStoreInst.java │ │ │ ├── CAStoreInst.java │ │ │ ├── DAStoreInst.java │ │ │ ├── DStore0Inst.java │ │ │ ├── DStore1Inst.java │ │ │ ├── DStore2Inst.java │ │ │ ├── DStore3Inst.java │ │ │ ├── DStoreNInst.java │ │ │ ├── FAStoreInst.java │ │ │ ├── FStore0Inst.java │ │ │ ├── FStore1Inst.java │ │ │ ├── FStore2Inst.java │ │ │ ├── FStore3Inst.java │ │ │ ├── FStoreNInst.java │ │ │ ├── IAStoreInst.java │ │ │ ├── IStore0Inst.java │ │ │ ├── IStore1Inst.java │ │ │ ├── IStore2Inst.java │ │ │ ├── IStore3Inst.java │ │ │ ├── IStoreNInst.java │ │ │ ├── LAStoreInst.java │ │ │ ├── LStore0Inst.java │ │ │ ├── LStore1Inst.java │ │ │ ├── LStore2Inst.java │ │ │ ├── LStore3Inst.java │ │ │ ├── LStoreNInst.java │ │ │ └── SAStoreInst.java │ │ ├── interpret │ │ └── Interpreter.java │ │ ├── nativebridge │ │ ├── java │ │ │ ├── io │ │ │ │ ├── FileDescriptorBridge.java │ │ │ │ ├── FileInputStreamBridge.java │ │ │ │ ├── FileOutputStreamBridge.java │ │ │ │ ├── NativeInputStreamBridge.java │ │ │ │ └── UnixFileSystemBridge.java │ │ │ ├── lang │ │ │ │ ├── ClassBridge.java │ │ │ │ ├── ClassLoaderBridge.java │ │ │ │ ├── DoubleBridge.java │ │ │ │ ├── ExceptionBridge.java │ │ │ │ ├── FloatBridge.java │ │ │ │ ├── IntegerBridge.java │ │ │ │ ├── MathBridge.java │ │ │ │ ├── ObjectBridge.java │ │ │ │ ├── StringBridge.java │ │ │ │ ├── SystemBridge.java │ │ │ │ ├── ThreadBridge.java │ │ │ │ └── ThrowableBridge.java │ │ │ ├── nio │ │ │ │ └── charset │ │ │ │ │ └── CharsetBridge.java │ │ │ ├── security │ │ │ │ └── AccessControllerBridge.java │ │ │ ├── sum │ │ │ │ └── misc │ │ │ │ │ └── ReflectionBridge.java │ │ │ └── util │ │ │ │ ├── PropertiesBridge.java │ │ │ │ ├── RandomBridge.java │ │ │ │ ├── ZipFileBridge.java │ │ │ │ └── concurrent │ │ │ │ └── AtomicLongBridge.java │ │ └── sun │ │ │ └── misc │ │ │ └── UnsafeBridge.java │ │ ├── rtda │ │ ├── Frame.java │ │ ├── LocalVars.java │ │ ├── MetaSpace.java │ │ ├── OperandStack.java │ │ ├── Slot.java │ │ ├── Stack.java │ │ ├── Thread.java │ │ ├── UnionSlot.java │ │ └── heap │ │ │ ├── ArrayInstance.java │ │ │ ├── Class.java │ │ │ ├── Field.java │ │ │ ├── Heap.java │ │ │ ├── Instance.java │ │ │ ├── InstanceArray.java │ │ │ ├── LambdaObject.java │ │ │ ├── Method.java │ │ │ ├── NativeMethod.java │ │ │ └── PrimitiveArray.java │ │ └── util │ │ ├── Const.java │ │ ├── DebugContextHolder.java │ │ ├── EnvHolder.java │ │ ├── Logger.java │ │ └── Utils.java │ └── test │ └── java │ └── com │ └── gxk │ └── jvm │ ├── ArgsTest.java │ ├── builtin │ └── JavaIoTest.java │ ├── classfile │ └── ClassReaderTest.java │ ├── classloader │ └── ClassLoaderTest.java │ ├── classpath │ └── ClasspathTest.java │ ├── interpret │ ├── BaseInterpreterTest.java │ ├── collection │ │ └── CollectionInterpreterTest.java │ ├── exception │ │ └── InterpreterExceptionTest.java │ ├── method │ │ ├── InterpreterLambdaTest.java │ │ └── InterpreterMethodInfoTest.java │ ├── misc │ │ ├── InterpreterMiscTest.java │ │ └── InterpreterSimpleTest.java │ ├── oo │ │ └── InterpreterOoTest.java │ ├── primitive │ │ └── InterpreterPrimitiveTest.java │ └── reflect │ │ └── ReflectionInterpreterTest.java │ ├── rtda │ ├── LocalVarsTest.java │ ├── OperandStackTest.java │ └── StackTest.java │ └── util │ └── UtilsTest.java ├── jvm-native └── build_native.sh ├── jvm-tools ├── ext │ ├── Sum.class │ ├── Sum.java │ ├── Sum10.class │ ├── Sum10.java │ ├── sum.bc │ └── sum10.bc ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── gxk │ └── jvm │ ├── ext │ └── bc │ │ ├── ByteCodeGenerator.java │ │ ├── ByteCodeInterpreter.java │ │ ├── IReturnInst.java │ │ └── package-info.java │ └── tools │ ├── AsmGen.java │ ├── AsmInt.java │ └── Jdb.java ├── mini-jdk ├── pom.xml └── src │ └── main │ └── java │ └── java │ ├── io │ ├── NativeInputStream.java │ └── PrintStream.java │ └── util │ └── zip │ └── ZipFile.java ├── pom.xml ├── test.jar └── tests ├── array_test ├── ArrayTest.class ├── ArrayTest.java ├── ArrayTest2.class ├── ArrayTest2.java ├── AtObj.class ├── test.expect └── test.sh ├── basic ├── Test.class ├── TestM.class ├── test.expect ├── test.result └── test.sh ├── class_init ├── ClassInitTest1.class ├── ClassInitTest1.java ├── ClassInitTest2.class ├── ClassInitTest3.class ├── test.expect ├── test.result └── test.sh ├── comparisons ├── Comparisons.class ├── test.expect ├── test.result └── test.sh ├── constants ├── Constants.class ├── test.expect ├── test.result └── test.sh ├── hello ├── Hello.class ├── test.expect ├── test.result └── test.sh ├── instance_array ├── InstanceArray.class ├── InstanceArray.java ├── InstanceArrayObj.class ├── test.expect ├── test.result └── test.sh ├── interface_init ├── Interface1.class ├── Interface2.class ├── InterfaceImpl1.class ├── InterfaceImpl2.class ├── InterfaceInit.java ├── InterfaceObj.class ├── test.expect ├── test.result └── test.sh ├── interface_override ├── Interface11.class ├── Interface12.class ├── Interface13.class ├── Interface14.class ├── InterfaceImpl11.class ├── InterfaceImpl12.class ├── InterfaceImpl13.class ├── InterfaceImpl14.class ├── InterfaceImpl15.class ├── InterfaceOverride.java ├── InterfaceOverrideObj.class ├── test.expect ├── test.result └── test.sh ├── load_store ├── DLoadStore.class ├── FLoadStore.class ├── ILoadStore.class ├── LLoadStore.class ├── dtest.expect ├── dtest.result ├── ftest.expect ├── ftest.result ├── itest.expect ├── itest.result ├── ltest.expect ├── ltest.result ├── test.result └── test.sh ├── math ├── Math.class ├── test.expect ├── test.result └── test.sh ├── native_call ├── MyJVM.class ├── test.expect ├── test.result └── test.sh ├── npe ├── NullPointerExceptions.class ├── test.expect ├── test.result └── test.sh ├── object_field ├── ObjectField.java ├── ObjectField1.class ├── ObjectField2.class ├── test.expect ├── test.result └── test.sh ├── object_init ├── ClassInitTest1.java ├── ObjectInit.java ├── ObjectInit1.class ├── ObjectInit2.class ├── ObjectInit3.class ├── test.expect ├── test.result └── test.sh ├── object_override ├── Override.class ├── Override.java ├── Override1.class ├── Override2.class ├── Override3.class ├── test.expect ├── test.result └── test.sh ├── primitive_array ├── PrimitiveArray.class ├── PrimitiveArray.java ├── test.expect ├── test.result └── test.sh ├── static_call ├── Fibonacci.class ├── test.expect ├── test.result └── test.sh ├── static_field ├── StaticField.class ├── StaticField.java ├── test.expect ├── test.result └── test.sh ├── string ├── Hello.class ├── Hello.java ├── test.expect └── test.sh └── sum10 ├── Sum10.class ├── Sum10M.class ├── test.expect ├── test.result └── test.sh /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea 3 | *.iml 4 | 5 | temp/ 6 | 7 | bin/jvm 8 | 9 | dependency-reduced-pom.xml 10 | -------------------------------------------------------------------------------- /HelloWorld.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/HelloWorld.class -------------------------------------------------------------------------------- /HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { public static void main(String[] args) { System.out.println("hello world"); } } 2 | -------------------------------------------------------------------------------- /bin/asmgen: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | exec java -cp jvm-tools/target/tools.jar com.gxk.jvm.tools.AsmGen "$@" 4 | -------------------------------------------------------------------------------- /bin/asmint: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | exec java -cp jvm-tools/target/tools.jar com.gxk.jvm.tools.AsmInt "$@" 4 | -------------------------------------------------------------------------------- /bin/java: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ROOT_PATH=$(cd "$(dirname "$0")"; cd ../;pwd) 3 | export MINI_JVM_HOME="$ROOT_PATH" 4 | exec java -jar ${ROOT_PATH}/jvm-core/target/mini-jvm.jar "$@" 5 | 6 | -------------------------------------------------------------------------------- /bin/jdb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | exec java -cp jvm-tools/target/tools.jar com.gxk.jvm.tools.Jdb "$@" 4 | -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/docs/.nojekyll -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | jvm.guxingke.com -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # [Mini-jvm](https://jvm.guxingke.com) [![Gitter](https://badges.gitter.im/guxingke/mini-jvm.svg)](https://gitter.im/guxingke/mini-jvm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) 2 | ![CircleCI](https://img.shields.io/circleci/build/github/guxingke/mini-jvm/master?style=for-the-badge&token=f20bab2e6e06b66e96f9440f31fa391524a8ed60)![GitHub](https://img.shields.io/github/license/guxingke/mini-jvm?style=for-the-badge)![GitHub commit activity](https://img.shields.io/github/commit-activity/w/guxingke/mini-jvm?style=for-the-badge)![GitHub last commit](https://img.shields.io/github/last-commit/guxingke/mini-jvm?style=for-the-badge) 3 | ------ 4 | 使用 JDK 8 实现 jvm. 5 | 6 | [REPO](https://github.com/guxingke/mini-jvm) -------------------------------------------------------------------------------- /docs/_coverpage.md: -------------------------------------------------------------------------------- 1 | > 特性 2 | 3 | - 🚀 实现 ClassFile 解析. 4 | - 🚀 追求可读性,可测试性. 5 | - 🚀 支持 AOT 编译(graalvm) 6 | - 🚀 项目很小, 便于理解基本原理. 7 | - 🚀 刚起步,正在开发中. 8 | - 🚀 欢迎共建 9 | 10 |
11 | 了解更多 12 |
13 | 14 | ![color](#ffffff) 15 | -------------------------------------------------------------------------------- /docs/_sidebar.md: -------------------------------------------------------------------------------- 1 | * [快速开始](quickstart.md) 2 | * [本地开发](dev.md) 3 | * [AOT 编译](aot.md) 4 | * [参与共建](contributor.md) 5 | * [变更记录](changelog.md) 6 | -------------------------------------------------------------------------------- /docs/aot.md: -------------------------------------------------------------------------------- 1 | # AOT 编译[可选] 2 | 3 | 用于生成二进制可执行文件 4 | 5 | 依赖 Graalvm 19.1.1 6 | 7 | ## 构建 8 | 正常 maven package 之后 9 | ```bash 10 | cd jvm-native 11 | ./build_native.sh 12 | ``` 13 | 生成 ../bin/jvm 即正常 14 | 15 | ## 验证 16 | ```bash 17 | ./bin/jvm -cp example/target/example.jar Hello 18 | ``` 19 | 输出 hello 即正常. 20 | -------------------------------------------------------------------------------- /docs/assets/imgs/mini-jvm-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/docs/assets/imgs/mini-jvm-logo.png -------------------------------------------------------------------------------- /docs/assets/imgs/wechat.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/docs/assets/imgs/wechat.jpeg -------------------------------------------------------------------------------- /docs/changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 20191011 4 | - 使用 docsify 初始化 5 | -------------------------------------------------------------------------------- /docs/contributor.md: -------------------------------------------------------------------------------- 1 | # 贡献 2 | 与项目有关的均可贡献 3 | 4 | ## 项目相关问题 5 | 如, 构建失败, 实现逻辑有疑问等. 6 | 7 | ## 项目文档 8 | 1. 文档描述不清晰 9 | 2. 文档过时 10 | 3. 补充文档 11 | 12 | ## 代码 13 | 1. 添加测试 14 | 2. 添加注释 15 | 3. 实现一些功能 16 | 4. CI 相关 17 | 18 | ## 其他 19 | 有的没的, 均可. 20 | -------------------------------------------------------------------------------- /docs/dev.md: -------------------------------------------------------------------------------- 1 | 本地开发 2 | 3 | ## 环境要求 4 | 1. JDK1.8 5 | 2. Maven3.3+ 6 | 3. Graalvm 19.1.1+ (可选) 7 | 8 | ## 下载源码 9 | ```bash 10 | git clone git@github.com:guxingke/mini-jvm.git 11 | ``` 12 | 如果是 fork, 请自行替换 13 | 14 | ## 构建 15 | ```bash 16 | cd mini-jvm 17 | mvn clean package 18 | ``` 19 | 20 | ## 简单测试 21 | ```bash 22 | ./bin/java -cp example/target/example.jar Hello 23 | ``` 24 | 输出 hello 即为正常 25 | 26 | ## 导入 IDE 27 | 仅推荐 Idea. 28 | 29 | idea -> File -> open 打开即可. 30 | 31 | -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/docs/favicon.ico -------------------------------------------------------------------------------- /docs/note.md: -------------------------------------------------------------------------------- 1 | 一些开发问题记录 2 | 3 | ## 浮点数实现有点麻烦, 暂时略过. 4 | 5 | ## onjava8 GreenhouseController, 数组初始化, 延后实现. 6 | ``` 7 | -cp onjava8 GreenhouseController 8 | ``` 9 | 10 | ## lambda 相关 11 | lambda 实现没有采用推荐方式, 可能会有问题. 暂时略过. 12 | -------------------------------------------------------------------------------- /docs/quickstart.md: -------------------------------------------------------------------------------- 1 | 快速开始 2 | 3 | TODO 4 | 5 | [本地开发](dev.md) 6 | -------------------------------------------------------------------------------- /example/src/main/java/AddN.java: -------------------------------------------------------------------------------- 1 | public class AddN{ 2 | 3 | public static void main(String[] args) { 4 | int ret = addN(3); 5 | System.out.println(ret); 6 | } 7 | 8 | public static int addN(int n) { 9 | if(n==0) return 0; 10 | if(n==1) return 1; 11 | 12 | return n + addN(n-1); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/src/main/java/AddTwoInt.java: -------------------------------------------------------------------------------- 1 | public class AddTwoInt { 2 | public static void main(String[] args){ 3 | int sum = add(10, 20); 4 | System.out.println(sum); 5 | } 6 | 7 | public static int add(int left, int right) { 8 | int sum = left + right; 9 | return sum; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /example/src/main/java/AtomicIntegerTest.java: -------------------------------------------------------------------------------- 1 | import java.util.concurrent.atomic.AtomicInteger; 2 | 3 | public class AtomicIntegerTest { 4 | 5 | public static void main(String[] args) { 6 | AtomicInteger ai = new AtomicInteger(); 7 | int x = ai.get(); 8 | System.out.println(x); 9 | 10 | int x2 = ai.incrementAndGet(); 11 | System.out.println(x2); 12 | 13 | int x3 = ai.incrementAndGet(); 14 | System.out.println(x3); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/src/main/java/BufferedOutputStreamTest.java: -------------------------------------------------------------------------------- 1 | import java.io.FileOutputStream; 2 | import java.io.FileDescriptor; 3 | import java.io.IOException; 4 | import java.io.BufferedOutputStream; 5 | 6 | 7 | public class BufferedOutputStreamTest { 8 | 9 | public static void main(String[] args) throws IOException { 10 | FileOutputStream out = new FileOutputStream(FileDescriptor.out); 11 | BufferedOutputStream o2 = new BufferedOutputStream(out, 1024); 12 | 13 | for (int i = 0; i < 10240; i++) { 14 | o2.write(i % 26 + 'a'); 15 | if (i % 1024 == 0) { 16 | o2.write('\n'); 17 | } 18 | } 19 | 20 | o2.flush(); 21 | o2.close(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/src/main/java/CharsetTest.java: -------------------------------------------------------------------------------- 1 | import java.nio.charset.Charset; 2 | 3 | public class CharsetTest { 4 | 5 | public static void main(String[] args) { 6 | Charset charset = Charset.defaultCharset(); 7 | String name = charset.name(); 8 | System.out.println(name); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/src/main/java/Curry2Args.java: -------------------------------------------------------------------------------- 1 | import java.util.function.*; 2 | 3 | public class Curry2Args { 4 | public static void main(String[] args) { 5 | Function> sum = a -> b -> a + b; 6 | Function hi = sum.apply("Hi "); 7 | String val = hi.apply("Ho "); 8 | 9 | System.out.println(val); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /example/src/main/java/FdTest.java: -------------------------------------------------------------------------------- 1 | import java.io.FileOutputStream; 2 | import java.io.FileDescriptor; 3 | import java.io.IOException; 4 | 5 | 6 | public class FdTest { 7 | 8 | public static void main(String[] args) throws IOException { 9 | FileOutputStream out = new FileOutputStream(FileDescriptor.out); 10 | byte[] bytes = new byte[6]; 11 | bytes[0] = 'h'; 12 | bytes[1] = 'e'; 13 | bytes[2] = 'l'; 14 | bytes[3] = 'l'; 15 | bytes[4] = 'o'; 16 | bytes[5] = '\n'; 17 | out.write(bytes); 18 | out.flush(); 19 | out.close(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/src/main/java/FdTest2.java: -------------------------------------------------------------------------------- 1 | import java.io.FileOutputStream; 2 | import java.io.FileDescriptor; 3 | import java.io.IOException; 4 | 5 | 6 | public class FdTest2 { 7 | 8 | public static void main(String[] args) throws IOException { 9 | FileOutputStream out = new FileOutputStream(FileDescriptor.out); 10 | out.write('a'); 11 | out.write('b'); 12 | out.flush(); 13 | out.close(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/src/main/java/FdTest3.java: -------------------------------------------------------------------------------- 1 | import java.io.FileOutputStream; 2 | import java.io.FileDescriptor; 3 | import java.io.IOException; 4 | 5 | 6 | public class FdTest3 { 7 | 8 | public static void main(String[] args) throws IOException { 9 | FileOutputStream err = new FileOutputStream(FileDescriptor.err); 10 | byte[] bytes = new byte[6]; 11 | bytes[0] = 'h'; 12 | bytes[1] = 'e'; 13 | bytes[2] = 'l'; 14 | bytes[3] = 'l'; 15 | bytes[4] = 'o'; 16 | bytes[5] = '\n'; 17 | err.write(bytes); 18 | err.flush(); 19 | err.close(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/src/main/java/Fibonacci.java: -------------------------------------------------------------------------------- 1 | public class Fibonacci { 2 | public static void main(String[] args){ 3 | int ret = fib(10); 4 | System.out.println(ret); 5 | } 6 | 7 | public static int fib(int n) { 8 | if (n == 0) { 9 | return 0; 10 | } 11 | if (n == 1 || n == 2) { 12 | return 1; 13 | } 14 | return fib(n-1) + fib(n-2); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/src/main/java/FileTest6.java: -------------------------------------------------------------------------------- 1 | import java.io.FileDescriptor; 2 | import java.io.FileInputStream; 3 | import java.io.IOException; 4 | 5 | public class FileTest6 { 6 | 7 | public static void main(String[] args) throws IOException { 8 | 9 | try (FileInputStream fis = new FileInputStream(FileDescriptor.in)) { 10 | while (true) { 11 | int read = fis.read(); 12 | System.out.println(read); 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/src/main/java/FileTest7.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.IOException; 3 | 4 | public class FileTest7 { 5 | 6 | public static void main(String[] args) throws IOException { 7 | String userDir = System.getProperty("user.dir"); 8 | File file = new File(userDir); 9 | boolean directory = file.isDirectory(); 10 | System.out.println(directory); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /example/src/main/java/Hello.java: -------------------------------------------------------------------------------- 1 | public class Hello { 2 | public static void main(String[] args) { 3 | System.out.println("hello"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /example/src/main/java/Hello2.java: -------------------------------------------------------------------------------- 1 | public class Hello2 { 2 | public static void main(String[] args) { 3 | int x = 1, y = 2, z = 3; 4 | int a = x + y - 2/2 + z; // [1] 5 | int b = x + (y - 2)/(2 + z); // [2] 6 | System.out.println("a = " + a); 7 | System.out.println("b = " + b); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/src/main/java/Hello3.java: -------------------------------------------------------------------------------- 1 | public class Hello3 { 2 | public static void main(String[] args) { 3 | String a = "a "; 4 | String b = "b "; 5 | String c = a + b; 6 | 7 | System.out.println(c); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/src/main/java/Hello4.java: -------------------------------------------------------------------------------- 1 | public class Hello4 { 2 | public static void main(String[] args) { 3 | long bll = 0b00101111101011111010111110101111; 4 | String bs = Long.toBinaryString(bll); 5 | System.out.println(bs); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /example/src/main/java/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | public static void main(String[] args) { 3 | if (args.length == 0) { 4 | System.out.println("hello"); 5 | return; 6 | } 7 | 8 | for(int i = 0; i < args.length; i ++) { 9 | System.out.println(args[i]); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /example/src/main/java/Int1.java: -------------------------------------------------------------------------------- 1 | public interface Int1 { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /example/src/main/java/Int2.java: -------------------------------------------------------------------------------- 1 | public interface Int2 { 2 | int level = 10000000; 3 | TestObject obj = new TestObject(100000); 4 | } 5 | -------------------------------------------------------------------------------- /example/src/main/java/Int2Impl.java: -------------------------------------------------------------------------------- 1 | public class Int2Impl implements Int2 { 2 | public static void main(String[] args) { 3 | System.out.println(level); 4 | System.out.println(obj.getLevel()); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/src/main/java/Int3.java: -------------------------------------------------------------------------------- 1 | public interface Int3 { 2 | void test(); 3 | } 4 | -------------------------------------------------------------------------------- /example/src/main/java/Int3Impl.java: -------------------------------------------------------------------------------- 1 | public class Int3Impl implements Int3 { 2 | @Override 3 | public void test(){ 4 | System.out.println("test"); 5 | } 6 | 7 | public static void main(String[] args) { 8 | new Int3Impl().test(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/src/main/java/Int3Impl2.java: -------------------------------------------------------------------------------- 1 | public class Int3Impl2 implements Int3 { 2 | @Override 3 | public void test(){ 4 | System.out.println("test2"); 5 | } 6 | 7 | public static void main(String[] args) { 8 | Int3 obj = new Int3Impl2(); 9 | obj.test(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /example/src/main/java/Int4.java: -------------------------------------------------------------------------------- 1 | public interface Int4 { 2 | default void test() { 3 | System.out.println("defualt test method"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /example/src/main/java/Int4Impl.java: -------------------------------------------------------------------------------- 1 | public class Int4Impl implements Int4 { 2 | public static void main(String[] args) { 3 | new Int4Impl().test(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /example/src/main/java/Int4Impl2.java: -------------------------------------------------------------------------------- 1 | public class Int4Impl2 implements Int4 { 2 | public static void main(String[] args) { 3 | Int4 obj = new Int4Impl2(); 4 | obj.test(); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/src/main/java/IoTest0.java: -------------------------------------------------------------------------------- 1 | import java.nio.charset.Charset; 2 | 3 | public class IoTest0 { 4 | public static void main(String[] args) { 5 | Charset charset = Charset.defaultCharset(); 6 | System.out.println(charset.name()); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /example/src/main/java/Loop1.java: -------------------------------------------------------------------------------- 1 | public class Loop1 { 2 | public static void main(String[] args){ 3 | int sum = 0; 4 | for (int i = 1; i <= 10; i++) { 5 | sum += i; 6 | } 7 | return; 8 | } 9 | 10 | public int sum10() { 11 | int sum = 0; 12 | for (int i = 1; i <= 10; i++) { 13 | sum += i; 14 | } 15 | return sum; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /example/src/main/java/Loop100.java: -------------------------------------------------------------------------------- 1 | public class Loop100 { 2 | public static void main(String[] args){ 3 | int sum = 0; 4 | for (int i = 1; i <= 100000; i++) { 5 | sum += i; 6 | } 7 | System.out.println(sum); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/src/main/java/Loop2.java: -------------------------------------------------------------------------------- 1 | public class Loop2 { 2 | public static void main(String[] args){ 3 | int sum = 0; 4 | for (int i = 1; i <= 10; i++) { 5 | sum += i; 6 | } 7 | System.out.println(sum); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/src/main/java/Loop3.java: -------------------------------------------------------------------------------- 1 | public class Loop3 { 2 | public static void main(String[] args){ 3 | int sum = sum(10); 4 | System.out.println(sum); 5 | } 6 | 7 | public static int sum(int n) { 8 | int sum = 0; 9 | for (int i = 1; i <= n; i++) { 10 | sum += i; 11 | } 12 | return sum; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/src/main/java/Loop4.java: -------------------------------------------------------------------------------- 1 | public class Loop4 { 2 | public static void main(String[] args){ 3 | int sum = sum(); 4 | System.out.println(sum); 5 | } 6 | 7 | public static int sum() { 8 | int sum = 0; 9 | for (int i = 1; i <= 100; i++) { 10 | sum += i; 11 | } 12 | return sum; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/src/main/java/PassObject.java: -------------------------------------------------------------------------------- 1 | // operators/PassObject.java 2 | // (c)2017 MindView LLC: see Copyright.txt 3 | // We make no guarantees that this code is fit for any purpose. 4 | // Visit http://OnJava8.com for more book information. 5 | // Passing objects to methods might not be 6 | // what you're used to 7 | 8 | class Letter { 9 | char c; 10 | } 11 | 12 | public class PassObject { 13 | static void f(Letter y) { 14 | y.c = 'z'; 15 | } 16 | public static void main(String[] args) { 17 | Letter x = new Letter(); 18 | x.c = 'a'; 19 | System.out.println("1: x.c: " + x.c); 20 | f(x); 21 | System.out.println("2: x.c: " + x.c); 22 | } 23 | } 24 | /* Output: 25 | 1: x.c: a 26 | 2: x.c: z 27 | */ -------------------------------------------------------------------------------- /example/src/main/java/PrintStreamTest.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedOutputStream; 2 | import java.io.FileDescriptor; 3 | import java.io.FileOutputStream; 4 | import java.io.PrintStream; 5 | 6 | public class PrintStreamTest { 7 | 8 | public static void main(String[] args) { 9 | PrintStream err = new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err)), true); 10 | err.println(1); 11 | err.println("xxxxxxxx"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/src/main/java/Stack.java: -------------------------------------------------------------------------------- 1 | import java.util.Deque; 2 | import java.util.ArrayDeque; 3 | 4 | public class Stack { 5 | private Deque storage = new ArrayDeque<>(); 6 | public void push(T v) { storage.push(v); } 7 | public T peek() { return storage.peek(); } 8 | public T pop() { return storage.pop(); } 9 | public boolean isEmpty() { return storage.isEmpty(); } 10 | @Override 11 | public String toString() { 12 | return storage.toString(); 13 | } 14 | } -------------------------------------------------------------------------------- /example/src/main/java/Sum10.java: -------------------------------------------------------------------------------- 1 | public class Sum10 { 2 | 3 | public static int sum10() { 4 | int sum = 0; 5 | for (int i = 1; i <= 10; i++) { 6 | sum += i; 7 | } 8 | return sum; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/src/main/java/SwitchTest0.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | 3 | public class SwitchTest0 { 4 | 5 | public static void main(String[] args) { 6 | int arg = new Random().nextInt(10); 7 | switch (arg) { 8 | case 0: 9 | System.out.println(0); 10 | break; 11 | case 1: 12 | System.out.println(1); 13 | break; 14 | case 2: 15 | System.out.println(2); 16 | break; 17 | default: 18 | System.out.println(arg); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/src/main/java/SwitchTest1.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | 3 | public class SwitchTest1 { 4 | 5 | public static void main(String[] args) { 6 | int arg = new Random().nextInt(1000); 7 | switch (arg) { 8 | case 0: 9 | System.out.println(0); 10 | break; 11 | case 100: 12 | System.out.println(100); 13 | break; 14 | case 200: 15 | System.out.println(200); 16 | break; 17 | case 900: 18 | System.out.println(900); 19 | break; 20 | default: 21 | System.out.println(arg); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /example/src/main/java/SystemOutTest.java: -------------------------------------------------------------------------------- 1 | public class SystemOutTest { 2 | public static void main(String[] args) { 3 | System.out.println("out"); 4 | System.err.println("err"); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/src/main/java/TestArray.java: -------------------------------------------------------------------------------- 1 | public class TestArray { 2 | public static void main(String[] args) { 3 | int[] a = new int[10]; 4 | a[0] = 100; 5 | 6 | int x = a[0]; 7 | System.out.println(x); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/src/main/java/TestArray2.java: -------------------------------------------------------------------------------- 1 | public class TestArray2 { 2 | public static void main(String[] args) { 3 | long[] a = new long[10]; 4 | a[0] = 100L; 5 | 6 | long x = a[0]; 7 | System.out.println(x); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/src/main/java/TestArrayList.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class TestArrayList { 4 | public static void main(String[] args) { 5 | ArrayList list = new ArrayList<>(2); 6 | list.add("1"); 7 | list.add("2"); 8 | 9 | int size = list.size(); 10 | String l1 = list.get(0); 11 | 12 | System.out.println(size); 13 | System.out.println(l1); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/src/main/java/TestClass.java: -------------------------------------------------------------------------------- 1 | public class TestClass { 2 | public static void main(String[] args) { 3 | TestClass test = new TestClass(); 4 | Class clazz = test.getClass(); 5 | 6 | String name = clazz.getName(); 7 | 8 | System.out.println(name); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/src/main/java/TestClass2.java: -------------------------------------------------------------------------------- 1 | public class TestClass2 { 2 | public static void main(String[] args) { 3 | String name = String.class.getName(); 4 | System.out.println(name); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/src/main/java/TestClass3.java: -------------------------------------------------------------------------------- 1 | public class TestClass3 { 2 | 3 | public static void main(String[] args) { 4 | System.out.println(char.class.getName()); 5 | System.out.println(boolean.class.getName()); 6 | System.out.println(byte.class.getName()); 7 | System.out.println(short.class.getName()); 8 | System.out.println(int.class.getName()); 9 | System.out.println(long.class.getName()); 10 | System.out.println(float.class.getName()); 11 | System.out.println(double.class.getName()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/src/main/java/TestClass4.java: -------------------------------------------------------------------------------- 1 | public class TestClass4 { 2 | 3 | public static void main(String[] args) { 4 | Class cls = null; 5 | try { 6 | cls = Class.forName("TestClass"); 7 | } catch (Exception e) { 8 | System.out.println(-1); 9 | } 10 | 11 | String name = cls.getSimpleName(); 12 | System.out.println(name); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/src/main/java/TestClass5.java: -------------------------------------------------------------------------------- 1 | public class TestClass5 { 2 | 3 | public static void main(String[] args) { 4 | Object obj = null; 5 | try { 6 | Class cls = Class.forName("TestClass"); 7 | 8 | obj = cls.newInstance(); 9 | } catch (Exception e) { 10 | System.out.println(-1); 11 | } 12 | 13 | String name = obj.getClass().getName(); 14 | System.out.println(name); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/src/main/java/TestClosure.java: -------------------------------------------------------------------------------- 1 | import java.util.function.Supplier; 2 | 3 | public class TestClosure { 4 | 5 | Supplier makeFun() { 6 | String xx = "x"; 7 | return () -> xx; 8 | } 9 | 10 | public static void main(String[] args) { 11 | 12 | TestClosure tc = new TestClosure(); 13 | String f1 = tc.makeFun().get(); 14 | String f2 = tc.makeFun().get(); 15 | 16 | System.out.println(f1); 17 | System.out.println(f2); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /example/src/main/java/TestClosure2.java: -------------------------------------------------------------------------------- 1 | import java.util.function.Supplier; 2 | 3 | public class TestClosure2 { 4 | 5 | Supplier makeFun() { 6 | Integer xx = 10; 7 | return () -> xx; 8 | } 9 | 10 | public static void main(String[] args) { 11 | 12 | TestClosure2 tc = new TestClosure2(); 13 | int f1 = tc.makeFun().get(); 14 | int f2 = tc.makeFun().get(); 15 | 16 | System.out.println(f1); 17 | System.out.println(f2); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /example/src/main/java/TestException.java: -------------------------------------------------------------------------------- 1 | public class TestException { 2 | public static void main(String[] args) { 3 | try { 4 | System.out.println(0); 5 | throw new Exception("hello"); 6 | } catch (Exception e) { 7 | System.out.println(e.getMessage()); 8 | System.out.println(1); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /example/src/main/java/TestException2.java: -------------------------------------------------------------------------------- 1 | 2 | public class TestException2 { 3 | public static void main(String[] args) { 4 | try { 5 | System.out.println(0); 6 | throw new Exception("hello"); 7 | } catch (Exception e) { 8 | System.out.println(e.getMessage()); 9 | System.out.println(1); 10 | } finally { 11 | System.out.println(2); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/src/main/java/TestException3.java: -------------------------------------------------------------------------------- 1 | public class TestException3 { 2 | public static void main(String[] args) { 3 | try { 4 | f3(); 5 | } catch (Exception e) { 6 | System.out.println(e.getMessage()); 7 | } 8 | } 9 | 10 | public static void f1() throws Exception { 11 | throw new Exception("hello"); 12 | } 13 | 14 | public static void f2() throws Exception { 15 | f1(); 16 | } 17 | 18 | public static void f3() throws Exception { 19 | f2(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/src/main/java/TestException4.java: -------------------------------------------------------------------------------- 1 | public class TestException4 { 2 | public static void main(String[] args) throws Exception { 3 | f3(); 4 | } 5 | 6 | public static void f1() throws Exception { 7 | throw new Exception("hello"); 8 | } 9 | 10 | public static void f2() throws Exception { 11 | f1(); 12 | } 13 | 14 | public static void f3() throws Exception { 15 | f2(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /example/src/main/java/TestFunctionComposition.java: -------------------------------------------------------------------------------- 1 | import java.util.function.Function; 2 | 3 | public class TestFunctionComposition { 4 | 5 | public static void main(String[] args) { 6 | Function f1 = it -> { System.out.println(it); return it + 1; }; 7 | Function f2 = it -> { System.out.println(it); return it - 10; }; 8 | Function f3 = it -> { System.out.println(it); return it + 10; }; 9 | 10 | Function f4 = f1.compose(f2).andThen(f3); 11 | 12 | int ret = f4.apply(0); 13 | 14 | System.out.println(ret); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/src/main/java/TestFunctionComposition2.java: -------------------------------------------------------------------------------- 1 | import java.util.function.Function; 2 | 3 | public class TestFunctionComposition2 { 4 | 5 | public static void main(String[] args) { 6 | Function f1 = it -> { return it + 1; }; 7 | Function f2 = it -> { return it - 10; }; 8 | 9 | Function f4 = f1.andThen(f2); 10 | 11 | int ret = f4.apply(0); 12 | 13 | System.out.println(ret); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/src/main/java/TestFunctionComposition3.java: -------------------------------------------------------------------------------- 1 | import java.util.function.Function; 2 | 3 | public class TestFunctionComposition3 { 4 | 5 | public static void main(String[] args) { 6 | Function f1 = it -> { return it + 1; }; 7 | Function f2 = it -> { return it - 10; }; 8 | 9 | Function f4 = it -> {int val = f1.apply(it); int val2 = f2.apply(val); return val2; }; 10 | 11 | int ret = f4.apply(0); 12 | 13 | System.out.println(ret); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/src/main/java/TestFunctionComposition4.java: -------------------------------------------------------------------------------- 1 | import java.util.function.Function; 2 | 3 | public class TestFunctionComposition4 { 4 | 5 | public static void main(String[] args) { 6 | Function f1 = it -> { return it + 1; }; 7 | Function f2 = it -> { return it - 10; }; 8 | 9 | Function f4 = it -> f2.apply(f1.apply(it)); 10 | 11 | int ret = f4.apply(0); 12 | 13 | System.out.println(ret); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/src/main/java/TestLambda.java: -------------------------------------------------------------------------------- 1 | public class TestLambda { 2 | public static void main(String[] args) { 3 | Runnable r = () ->System.out.println("hello lambda"); 4 | 5 | r.run(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /example/src/main/java/TestLambda2.java: -------------------------------------------------------------------------------- 1 | import java.util.function.Consumer; 2 | 3 | public class TestLambda2 { 4 | public static void main(String[] args) { 5 | 6 | Consumer cs = it -> System.out.println(it); 7 | cs.accept("hello lambda"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/src/main/java/TestLambda3.java: -------------------------------------------------------------------------------- 1 | import java.util.function.Supplier; 2 | 3 | public class TestLambda3 { 4 | public static void main(String[] args) { 5 | 6 | Supplier supplier = () -> "hello supplier"; 7 | String test = supplier.get(); 8 | System.out.println(test); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/src/main/java/TestLambda4.java: -------------------------------------------------------------------------------- 1 | import java.util.function.Supplier; 2 | 3 | public class TestLambda4 { 4 | public static void main(String[] args) { 5 | 6 | Supplier supplier = () -> new Integer(10); 7 | int test = supplier.get(); 8 | System.out.println(test); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/src/main/java/TestLambda5.java: -------------------------------------------------------------------------------- 1 | import java.util.function.Function; 2 | 3 | public class TestLambda5 { 4 | public static void main(String[] args) { 5 | Function d = (it) -> it + " " + it; 6 | String test = d.apply("test"); 7 | System.out.println(test); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/src/main/java/TestList.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class TestList { 4 | public static void main(String[] args) { 5 | ArrayList list = new ArrayList<>(1); 6 | list.add(new Integer(1)); 7 | 8 | int size = list.size(); 9 | System.out.println(size); 10 | 11 | Integer tmp = list.get(0); 12 | System.out.println(tmp); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/src/main/java/TestList2.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class TestList2 { 4 | public static void main(String[] args) { 5 | ArrayList list = new ArrayList<>(); 6 | for (int i = 0; i < 20; i++) { 7 | list.add(new Integer(i)); 8 | } 9 | int size = list.size(); 10 | System.out.println(size); 11 | 12 | Integer tmp = list.get(10); 13 | System.out.println(tmp); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/src/main/java/TestLoop.java: -------------------------------------------------------------------------------- 1 | public class TestLoop { 2 | 3 | public int sum(int n) { 4 | int sum = 0; 5 | for (int i = 1; i <= n; i++) { 6 | sum += i; 7 | } 8 | return sum; 9 | } 10 | 11 | public int sum10() { 12 | int sum = 0; 13 | for (int i = 1; i <= 10; i++) { 14 | sum += i; 15 | } 16 | return sum; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /example/src/main/java/TestMap.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class TestMap { 4 | 5 | public static void main(String[] args) { 6 | HashMap map = new HashMap(); 7 | 8 | Integer key1 = new Integer(1); 9 | Integer key2 = new Integer(2); 10 | 11 | map.put(key1, key1); 12 | map.put(key2, key2); 13 | 14 | int size = map.size(); 15 | Integer tmp = map.get(key1); 16 | 17 | System.out.println(size); 18 | System.out.println(tmp); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /example/src/main/java/TestMap2.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class TestMap2 { 4 | 5 | public static void main(String[] args) { 6 | HashMap map = new HashMap<>(); 7 | map.put(1,"11"); 8 | map.put(2,"22"); 9 | 10 | String tmp = map.get(1); 11 | 12 | System.out.println(tmp); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/src/main/java/TestObject.java: -------------------------------------------------------------------------------- 1 | public class TestObject { 2 | 3 | private int level; 4 | 5 | public TestObject(int level){ 6 | this.level = level; 7 | } 8 | 9 | public int getLevel() { 10 | return this.level; 11 | } 12 | 13 | public void setLevel(int level) { 14 | this.level = level; 15 | } 16 | 17 | public static void main(String[] args) { 18 | TestObject object = new TestObject(10); 19 | int level = object.getLevel(); 20 | System.out.println(level); 21 | 22 | TestObject obj2 = new TestObject(20); 23 | int newLevel = obj2.getLevel(); 24 | System.out.println(newLevel); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /example/src/main/java/TestObject2.java: -------------------------------------------------------------------------------- 1 | public class TestObject2 { 2 | 3 | public static void main(String[] args) { 4 | TestObject object = new TestObject(10); 5 | int level = object.getLevel(); 6 | System.out.println(level); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /example/src/main/java/TestObject3.java: -------------------------------------------------------------------------------- 1 | public class TestObject3 extends TestObject { 2 | 3 | TestObject3(int num) { 4 | super(num); 5 | } 6 | 7 | public static void main(String[] args) { 8 | TestObject3 object = new TestObject3(10); 9 | int level = object.getLevel(); 10 | System.out.println(level); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /example/src/main/java/TestObject4.java: -------------------------------------------------------------------------------- 1 | public class TestObject4 extends TestObject { 2 | 3 | TestObject4(int num) { 4 | super(num); 5 | } 6 | 7 | public static void main(String[] args) { 8 | TestObject4 object = new TestObject4(10); 9 | int code = object.hashCode(); 10 | System.out.println(code); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /example/src/main/java/TestObject5.java: -------------------------------------------------------------------------------- 1 | public class TestObject5 { 2 | public boolean zv; 3 | public char cv; 4 | public byte bv; 5 | public short sv; 6 | public int iv; 7 | public float fv; 8 | public long lv; 9 | public double dv; 10 | 11 | public static void main(String[] args) { 12 | TestObject5 obj = new TestObject5(); 13 | System.out.println(obj.zv); 14 | System.out.println(obj.cv); 15 | System.out.println(obj.bv); 16 | System.out.println(obj.sv); 17 | System.out.println(obj.iv); 18 | System.out.println(obj.fv); 19 | System.out.println(obj.lv); 20 | System.out.println(obj.dv); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /example/src/main/java/TestRandom.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | 3 | public class TestRandom { 4 | public static void main(String[] args) { 5 | Random rdm = new Random(); 6 | int tmp = rdm.nextInt(); 7 | System.out.println(tmp); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/src/main/java/TestSet.java: -------------------------------------------------------------------------------- 1 | import java.util.HashSet; 2 | 3 | public class TestSet { 4 | 5 | public static void main(String[] args) { 6 | HashSet set= new HashSet(); 7 | 8 | Integer key1 = new Integer(1); 9 | Integer key2 = new Integer(2); 10 | 11 | set.add(key1); 12 | set.add(key2); 13 | set.add(key2); 14 | 15 | 16 | int size = set.size(); 17 | 18 | boolean tmp = set.contains(key1); 19 | 20 | System.out.println(size); 21 | System.out.println(tmp); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/src/main/java/TestStack.java: -------------------------------------------------------------------------------- 1 | import java.util.Deque; 2 | import java.util.ArrayDeque; 3 | 4 | public class TestStack { 5 | 6 | public static void main(String[] args) { 7 | Deque stack = new ArrayDeque<>(); 8 | 9 | Integer k1 = new Integer(1); 10 | stack.push(k1); 11 | 12 | int size = stack.size(); 13 | Integer tmp = stack.pop(); 14 | System.out.println(size); 15 | System.out.println(tmp); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /example/src/main/java/TestStack2.java: -------------------------------------------------------------------------------- 1 | public class TestStack2 { 2 | 3 | public static void main(String[] args) { 4 | Stack stack = new Stack<>(); 5 | 6 | Integer k1 = new Integer(1); 7 | stack.push(k1); 8 | 9 | boolean isEmpty = stack.isEmpty(); 10 | Integer tmp = stack.pop(); 11 | System.out.println(isEmpty); 12 | System.out.println(tmp); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/src/main/java/TestStatic.java: -------------------------------------------------------------------------------- 1 | public class TestStatic { 2 | public static int val = 10; 3 | public static void main(String[] args) { 4 | int sum = 0; 5 | for(int i = 1; i<= val; i++) { 6 | sum +=i; 7 | } 8 | System.out.println(sum); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/src/main/java/TestStatic1.java: -------------------------------------------------------------------------------- 1 | public class TestStatic1 { 2 | public static boolean zv; 3 | public static char cv; 4 | public static byte bv; 5 | public static short sv; 6 | public static int iv; 7 | public static float fv; 8 | public static long lv; 9 | public static double dv; 10 | 11 | public static void main(String[] args) { 12 | System.out.println(zv); 13 | System.out.println(cv); 14 | System.out.println(bv); 15 | System.out.println(sv); 16 | System.out.println(iv); 17 | System.out.println(fv); 18 | System.out.println(lv); 19 | System.out.println(dv); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/src/main/java/TrueFalse.java: -------------------------------------------------------------------------------- 1 | public class TrueFalse { 2 | public static void main(String[] args) { 3 | System.out.println(1 == 1); 4 | System.out.println(1 == 2); 5 | } 6 | } -------------------------------------------------------------------------------- /jvm-core/README.md: -------------------------------------------------------------------------------- 1 | ### jvm-core|JVM核心代码 2 | 3 | ``` 4 | └─src 5 | ├─main 6 | │ └─java 7 | │ └─com 8 | │ └─gxk 9 | │ └─jvm 10 | │ │ Args.java 11 | │ │ Main.java 12 | │ │ VirtualMachine.java 13 | │ ├─classfile 14 | │ │ ├─attribute 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/Attribute.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | 4 | public class Attribute { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/Attributes.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | /** 4 | * 将jvm的属性表进行封装 5 | */ 6 | public class Attributes { 7 | 8 | public final Attribute[] attributes; 9 | 10 | public Attributes(int size) { 11 | this.attributes = new Attribute[size]; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/CodeAttribute.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | public class CodeAttribute { 4 | public final CodeFromByte code; 5 | public final int maxLocals; 6 | public final int maxStacks; 7 | 8 | public CodeAttribute(CodeFromByte code, int maxLocals, int maxStacks) { 9 | this.code = code; 10 | this.maxLocals = maxLocals; 11 | this.maxStacks = maxStacks; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/CodeFromByte.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | import java.util.Map; 6 | 7 | public class CodeFromByte { 8 | 9 | private final Map instructions; 10 | 11 | public CodeFromByte(Map instructions) { 12 | this.instructions = instructions; 13 | } 14 | 15 | public Instruction getInst(int pc) { 16 | return this.instructions.get(pc); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/ConstantInfo.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | public class ConstantInfo { 4 | 5 | public final int infoEnum; 6 | 7 | public ConstantInfo(int infoEnum) { 8 | this.infoEnum = infoEnum; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/ConstantPool.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | public class ConstantPool { 4 | public final ConstantInfo[] infos; 5 | 6 | public ConstantPool(int size) { 7 | this.infos = new ConstantInfo[size]; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/Descriptor.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | public class Descriptor { 4 | 5 | public final String descriptor; 6 | 7 | public Descriptor(String descriptor) { 8 | 9 | this.descriptor = descriptor; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/Exception.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | public class Exception { 4 | 5 | public final int startPc; 6 | public final int endPc; 7 | public final int handlerPc; 8 | public final String clazz; 9 | 10 | public Exception(int startPc, int endPc, int handlerPc, String clazz) { 11 | this.startPc = startPc; 12 | this.endPc = endPc; 13 | this.handlerPc = handlerPc; 14 | this.clazz = clazz; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/ExceptionTable.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | public final class ExceptionTable { 4 | 5 | public final Exception[] exceptions; 6 | 7 | public ExceptionTable(Exception[] exceptions) { 8 | this.exceptions = exceptions; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/Fields.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | public class Fields { 4 | public final FieldInfo[] fieldInfos; 5 | 6 | public Fields(FieldInfo[] fieldInfos) { 7 | this.fieldInfos = fieldInfos; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/Interface.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | public class Interface { 4 | public final String name; 5 | 6 | public Interface(String name) { 7 | this.name = name; 8 | } 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/Interfaces.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | public class Interfaces { 4 | 5 | public final Interface[] interfaces; 6 | 7 | public Interfaces(Interface[] interfaces) { 8 | this.interfaces = interfaces; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/Methods.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | public class Methods { 4 | 5 | public final MethodInfo[] methodInfos; 6 | public Methods(int methodCount) { 7 | this.methodInfos = new MethodInfo[methodCount]; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/MyByteArrayInputStream.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | import java.io.ByteArrayInputStream; 4 | 5 | public class MyByteArrayInputStream extends ByteArrayInputStream { 6 | public MyByteArrayInputStream(byte[] buf) { 7 | super(buf); 8 | } 9 | 10 | public int getPosition() { 11 | return this.pos; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/MyDataInputStream.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.IOException; 5 | 6 | public class MyDataInputStream extends DataInputStream { 7 | 8 | public MyDataInputStream(MyByteArrayInputStream in) { 9 | super(in); 10 | } 11 | 12 | public int readPadding() { 13 | int offset = 0; 14 | while (((MyByteArrayInputStream) in).getPosition() % 4 != 0) { 15 | try { 16 | in.read(); 17 | offset++; 18 | } catch (IOException e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | return offset; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/attribute/BootstrapMethods.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.attribute; 2 | 3 | import com.gxk.jvm.classfile.Attribute; 4 | 5 | public class BootstrapMethods extends Attribute { 6 | 7 | public final BootstrapMethod[] methods; 8 | 9 | public BootstrapMethods(BootstrapMethod[] methods) { 10 | this.methods = methods; 11 | } 12 | 13 | public static class BootstrapMethod { 14 | public final Integer bootstrapMethodRefInx; 15 | public final Integer[] argsRefs; 16 | 17 | public BootstrapMethod(Integer bootstrapMethodRefInx, Integer[] argsRefs) { 18 | this.bootstrapMethodRefInx = bootstrapMethodRefInx; 19 | this.argsRefs = argsRefs; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/attribute/ConstantValue.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.attribute; 2 | 3 | import com.gxk.jvm.classfile.Attribute; 4 | 5 | public class ConstantValue extends Attribute { 6 | 7 | public final Object val; 8 | 9 | // onstantValue_attribute { 10 | // u2 attribute_name_index; 11 | // u4 attribute_length; 12 | // u2 constantvalue_index; 13 | // } 14 | public ConstantValue(Object val) { 15 | this.val = val; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/attribute/SourceFile.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.attribute; 2 | 3 | import com.gxk.jvm.classfile.Attribute; 4 | 5 | public class SourceFile extends Attribute { 6 | 7 | public final String name; 8 | 9 | //SourceFile_attribute { 10 | // u2 attribute_name_index; 11 | // u4 attribute_length; 12 | // u2 sourcefile_index; 13 | // } 14 | public SourceFile(String name) { 15 | this.name = name; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/ClassCp.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class ClassCp extends ConstantInfo { 6 | 7 | public final int nameIndex; 8 | 9 | public ClassCp(int infoEnum, int nameIndex) { 10 | super(infoEnum); 11 | this.nameIndex = nameIndex; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/DoubleCp.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class DoubleCp extends ConstantInfo { 6 | 7 | public final double val; 8 | 9 | public DoubleCp(int infoEnum, double val) { 10 | super(infoEnum); 11 | this.val = val; 12 | } 13 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/FieldDef.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class FieldDef extends ConstantInfo { 6 | 7 | public final int classIndex; 8 | public final int nameAndTypeIndex; 9 | 10 | public FieldDef(int infoEnum, int classIndex, int nameAndTypeIndex) { 11 | super(infoEnum); 12 | this.classIndex = classIndex; 13 | this.nameAndTypeIndex = nameAndTypeIndex; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/FloatCp.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class FloatCp extends ConstantInfo { 6 | 7 | public final float val; 8 | 9 | public FloatCp(int infoEnum, float val) { 10 | super(infoEnum); 11 | this.val = val; 12 | } 13 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/IntegerCp.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class IntegerCp extends ConstantInfo { 6 | 7 | public final int val; 8 | 9 | public IntegerCp(int infoEnum, int val) { 10 | super(infoEnum); 11 | this.val = val; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/InterfaceMethodDef.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | public class InterfaceMethodDef extends MethodDef { 4 | 5 | public InterfaceMethodDef(int infoEnum, int classIndex, int nameAndTypeIndex) { 6 | super(infoEnum, classIndex, nameAndTypeIndex); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/InvokeDynamic.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class InvokeDynamic extends ConstantInfo { 6 | 7 | public final int bootstrapMethodAttrIndex; 8 | public final int nameAndTypeIndex; 9 | 10 | public InvokeDynamic(int infoEnum, int bootstrapMethodAttrIndex, int nameAndTypeIndex) { 11 | super(infoEnum); 12 | this.bootstrapMethodAttrIndex = bootstrapMethodAttrIndex; 13 | this.nameAndTypeIndex = nameAndTypeIndex; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/LongCp.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class LongCp extends ConstantInfo { 6 | 7 | public final long val; 8 | 9 | public LongCp(int infoEnum, long val) { 10 | super(infoEnum); 11 | this.val = val; 12 | } 13 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/MethodDef.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class MethodDef extends ConstantInfo { 6 | 7 | public final int classIndex; 8 | public final int nameAndTypeIndex; 9 | 10 | public MethodDef(int infoEnum, int classIndex, int nameAndTypeIndex) { 11 | super(infoEnum); 12 | this.classIndex = classIndex; 13 | this.nameAndTypeIndex = nameAndTypeIndex; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/MethodHandle.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class MethodHandle extends ConstantInfo { 6 | 7 | public final int referenceKind; 8 | public final int referenceIndex; 9 | 10 | public MethodHandle(int infoEnum, int referenceKind, int referenceIndex) { 11 | super(infoEnum); 12 | this.referenceKind = referenceKind; 13 | this.referenceIndex = referenceIndex; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/MethodType.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class MethodType extends ConstantInfo { 6 | 7 | public final int descriptorIndex; 8 | 9 | public MethodType(int infoEnum, int descriptorIndex) { 10 | super(infoEnum); 11 | this.descriptorIndex = descriptorIndex; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/NameAndType.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class NameAndType extends ConstantInfo { 6 | 7 | public final int nameIndex; 8 | public final int descriptionIndex; 9 | 10 | public NameAndType(int infoEnum, int nameIndex, int descriptionIndex) { 11 | super(infoEnum); 12 | this.nameIndex = nameIndex; 13 | this.descriptionIndex = descriptionIndex; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classfile/cp/StringCp.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classfile.cp; 2 | 3 | import com.gxk.jvm.classfile.ConstantInfo; 4 | 5 | public class StringCp extends ConstantInfo { 6 | 7 | public final int stringIndex; 8 | 9 | public StringCp(int infoEnum, int stringIndex) { 10 | super(infoEnum); 11 | this.stringIndex = stringIndex; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classpath/CompositeEntry.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classpath; 2 | 3 | import com.gxk.jvm.classfile.ClassFile; 4 | import java.util.List; 5 | 6 | /** 组合模式 7 | * 多个类路径 搜索实现类 8 | * 把每个小路径都转换成具体的搜索实例 9 | */ 10 | public class CompositeEntry implements Entry { 11 | 12 | private final List entries; 13 | 14 | public CompositeEntry(List entries) { 15 | this.entries = entries; 16 | } 17 | 18 | @Override 19 | public ClassFile findClass(String name) { 20 | for (Entry entry : entries) { 21 | ClassFile cf = entry.findClass(name); 22 | if (cf != null) { 23 | return cf; 24 | } 25 | } 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/classpath/Entry.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.classpath; 2 | 3 | import com.gxk.jvm.classfile.ClassFile; 4 | 5 | /** 6 | * 类搜索接口,有不同的实现类 7 | */ 8 | public interface Entry { 9 | 10 | /** 11 | * 负责寻找和加载class文件 12 | * 13 | * @param name 类名或者类路径 14 | * @return 一个类结构文件对象 15 | */ 16 | ClassFile findClass(String name); 17 | } 18 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/Instruction.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction; 2 | 3 | import com.gxk.jvm.rtda.Frame; 4 | 5 | public interface Instruction { 6 | 7 | default int offset() { 8 | return 1; 9 | } 10 | 11 | void execute(Frame frame); 12 | 13 | default String debug(String prefix){ 14 | return prefix.concat(this.format()); 15 | } 16 | 17 | default String format() { 18 | return this.getClass().getSimpleName(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/DCmpGInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DCmpGInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double v2 = frame.popDouble(); 11 | double v1 = frame.popDouble(); 12 | if (v1 == v2) { 13 | frame.pushInt(0); 14 | return; 15 | } 16 | if (v1 < v2) { 17 | frame.pushInt(-1); 18 | return; 19 | } 20 | frame.pushInt(1); 21 | } 22 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/DCmpLInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DCmpLInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | Double v2 = frame.popDouble(); 11 | Double v1 = frame.popDouble(); 12 | if (v1.equals(v2)) { 13 | frame.pushInt(0); 14 | return; 15 | } 16 | if (v1 < v2) { 17 | frame.pushInt(-1); 18 | return; 19 | } 20 | frame.pushInt(1); 21 | } 22 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/FCmpGInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class FCmpGInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | float v2 = frame.popFloat(); 11 | float v1 = frame.popFloat(); 12 | if (v1 == v2) { 13 | frame.pushInt(0); 14 | return; 15 | } 16 | if (v1 < v2) { 17 | frame.pushInt(-1); 18 | return; 19 | } 20 | frame.pushInt(1); 21 | } 22 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/FCmpLInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class FCmpLInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | float v2 = frame.popFloat(); 11 | float v1 = frame.popFloat(); 12 | if (v1 == v2) { 13 | frame.pushInt(0); 14 | return; 15 | } 16 | if (v1 < v2) { 17 | frame.pushInt(-1); 18 | return; 19 | } 20 | frame.pushInt(1); 21 | } 22 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/IfACmpEqInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IfACmpEqInst implements Instruction { 7 | public final int offset; 8 | 9 | public IfACmpEqInst(int offset) { 10 | this.offset = offset; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 3; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | Object val2= frame.popRef(); 21 | Object val1= frame.popRef(); 22 | if (val1 == val2) { 23 | frame.nextPc = frame.getPc() + offset; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/IfEqInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IfEqInst implements Instruction { 7 | public final int offset; 8 | 9 | public IfEqInst(int offset) { 10 | this.offset = offset; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 3; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | Integer val= frame.popInt(); 21 | if (val == 0) { 22 | frame.nextPc = frame.getPc() + offset; 23 | } 24 | } 25 | 26 | @Override 27 | public String format() { 28 | return "if_eq " + offset; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/IfGeInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IfGeInst implements Instruction { 7 | public final int offset; 8 | 9 | public IfGeInst(int offset) { 10 | this.offset = offset; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 3; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | Integer val= frame.popInt(); 21 | if (val >= 0) { 22 | frame.nextPc = frame.getPc() + offset; 23 | } 24 | } 25 | 26 | @Override 27 | public String format() { 28 | return "if_ge " + offset; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/IfGtInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IfGtInst implements Instruction { 7 | public final int offset; 8 | 9 | public IfGtInst(int offset) { 10 | this.offset = offset; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 3; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | Integer val= frame.popInt(); 21 | if (val > 0) { 22 | frame.nextPc = frame.getPc() + offset; 23 | } 24 | } 25 | 26 | @Override 27 | public String format() { 28 | return "if_gt " + offset; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/IfICmpEqInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IfICmpEqInst implements Instruction { 7 | public final int offset; 8 | 9 | public IfICmpEqInst(int offset) { 10 | this.offset = offset; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 3; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | Integer val2= frame.popInt(); 21 | Integer val1= frame.popInt(); 22 | if (val1.equals(val2)) { 23 | frame.nextPc = frame.getPc() + offset; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/IfLeInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IfLeInst implements Instruction { 7 | public final int offset; 8 | 9 | public IfLeInst(int offset) { 10 | this.offset = offset; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 3; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | Integer val= frame.popInt(); 21 | if (val <= 0) { 22 | frame.nextPc = frame.getPc() + offset; 23 | } 24 | } 25 | 26 | @Override 27 | public String format() { 28 | return "if_le " + offset; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/IfLtInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IfLtInst implements Instruction { 7 | public final int offset; 8 | 9 | public IfLtInst(int offset) { 10 | this.offset = offset; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 3; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | Integer val= frame.popInt(); 21 | if (val < 0) { 22 | frame.nextPc = frame.getPc() + offset; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/IfNeInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IfNeInst implements Instruction { 7 | public final int offset; 8 | 9 | public IfNeInst(int offset) { 10 | this.offset = offset; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 3; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | Integer val= frame.popInt(); 21 | if (val != 0) { 22 | frame.nextPc = frame.getPc() + offset; 23 | } 24 | } 25 | 26 | @Override 27 | public String format() { 28 | return "if_ne " + offset; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/comparisons/LCmpInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.comparisons; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class LCmpInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | Long v2 = frame.popLong(); 11 | Long v1 = frame.popLong(); 12 | if (v1.equals(v2)) { 13 | frame.pushInt(0); 14 | return; 15 | } 16 | if (v1 < v2) { 17 | frame.pushInt(-1); 18 | return; 19 | } 20 | frame.pushInt(1); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/BiPushInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class BiPushInst implements Instruction { 7 | 8 | public final byte val; 9 | 10 | public BiPushInst(byte val) { 11 | this.val = val; 12 | } 13 | 14 | @Override 15 | public int offset() { 16 | return 2; 17 | } 18 | 19 | @Override 20 | public void execute(Frame frame) { 21 | frame.pushInt((int) (this.val)); 22 | } 23 | 24 | @Override 25 | public String format() { 26 | return "bipush " + val; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/DConst0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DConst0Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | frame.pushDouble(0.0d); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/DConst1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DConst1Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | frame.pushDouble(1.0d); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/FConst0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FConst0Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.pushFloat(0.0f); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/FConst1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FConst1Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.pushFloat(1.0f); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/FConst2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FConst2Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.pushFloat(2.0f); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/IConst1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | /** 9 | * @see IConst0Inst 10 | */ 11 | public class IConst1Inst implements Instruction { 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | frame.pushInt(1); 16 | } 17 | 18 | @Override 19 | public String format() { 20 | return "iconst_1"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/IConst2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IConst2Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.pushInt(2); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "iconst_2"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/IConst3Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IConst3Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.pushInt(3); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "iconst_3"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/IConst4Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IConst4Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.pushInt(4); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "iconst_4"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/IConst5Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IConst5Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.pushInt(5); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "iconst_5"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/IConstM1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IConstM1Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.pushInt(-1); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "iconst_m1"; 18 | } 19 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/Lconst0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class Lconst0Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.pushLong(0L); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/Lconst1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class Lconst1Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.pushLong(1L); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/NopInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | /** 9 | *

nop

10 | *

Do nothing.

11 | *

Operand Stack

12 | *
13 |  * No change
14 |  * 
15 | */ 16 | public class NopInst implements Instruction { 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/constants/SiPushInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.constants; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class SiPushInst implements Instruction { 7 | 8 | public final short val; 9 | 10 | public SiPushInst(short val) { 11 | this.val = val; 12 | } 13 | 14 | @Override 15 | public int offset() { 16 | return 3; 17 | } 18 | 19 | @Override 20 | public void execute(Frame frame) { 21 | frame.pushInt((int) (this.val)); 22 | } 23 | 24 | @Override 25 | public String format() { 26 | return "sipush " + val; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/control/AReturnInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.control; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.util.Utils; 6 | 7 | public class AReturnInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | // Object tmp = frame.popRef(); 12 | // frame.thread.popFrame(); 13 | // if (!frame.thread.empty()) { 14 | // frame.thread.currentFrame().pushRef(tmp); 15 | // } 16 | // System.out.println("do ret " + tmp); 17 | Utils.doReturn1(); 18 | } 19 | 20 | @Override 21 | public String format() { 22 | return "areturn"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/control/DReturnInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.control; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.util.Utils; 6 | 7 | public class DReturnInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | // double tmp = frame.popDouble(); 12 | // frame.thread.popFrame(); 13 | // if (!frame.thread.empty()) { 14 | // frame.thread.currentFrame().pushDouble(tmp); 15 | // } 16 | // System.out.println("do ret " + tmp); 17 | Utils.doReturn2(); 18 | } 19 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/control/FReturnInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.control; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | import com.gxk.jvm.util.Utils; 8 | 9 | public class FReturnInst implements Instruction { 10 | 11 | @Override 12 | public void execute(Frame frame) { 13 | // float tmp = frame.popFloat(); 14 | // frame.thread.popFrame(); 15 | // if (!frame.thread.empty()) { 16 | // frame.thread.currentFrame().pushFloat(tmp); 17 | // } 18 | // System.out.println("do ret " + tmp); 19 | Utils.doReturn1(); 20 | } 21 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/control/IReturnInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.control; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | import com.gxk.jvm.util.Utils; 8 | 9 | public class IReturnInst implements Instruction { 10 | 11 | @Override 12 | public void execute(Frame frame) { 13 | // Integer tmp = frame.popInt(); 14 | // frame.thread.popFrame(); 15 | // if (!frame.thread.empty()) { 16 | // frame.thread.currentFrame().pushInt(tmp); 17 | // } 18 | // System.out.println("do ret " + tmp); 19 | Utils.doReturn1(); 20 | } 21 | 22 | @Override 23 | public String format() { 24 | return "ireturn"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/control/LReturnInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.control; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | import com.gxk.jvm.util.Utils; 8 | 9 | public class LReturnInst implements Instruction { 10 | 11 | @Override 12 | public void execute(Frame frame) { 13 | // Long tmp = frame.popLong(); 14 | // frame.thread.popFrame(); 15 | // if (!frame.thread.empty()) { 16 | // frame.thread.currentFrame().pushLong(tmp); 17 | // } 18 | // System.out.println("do ret " + tmp); 19 | 20 | Utils.doReturn2(); 21 | } 22 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/control/ReturnInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.control; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | import com.gxk.jvm.util.Utils; 8 | 9 | public class ReturnInst implements Instruction { 10 | 11 | @Override 12 | public void execute(Frame frame) { 13 | // do nothing 14 | // frame.thread.popFrame(); 15 | Utils.doReturn0(); 16 | } 17 | 18 | @Override 19 | public String format() { 20 | return "return"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/D2fInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class D2fInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | double tmp = frame.popDouble(); 16 | frame.pushFloat(((float) tmp)); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/D2iInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class D2iInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | double tmp = frame.popDouble(); 16 | frame.pushInt(((int) tmp)); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/D2lInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class D2lInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | double tmp = frame.popDouble(); 16 | frame.pushLong((long) tmp); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/F2dInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class F2dInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | float tmp = frame.popFloat(); 16 | frame.pushDouble(((double) tmp)); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/F2iInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class F2iInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | float tmp = frame.popFloat(); 16 | frame.pushInt(((int) tmp)); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/F2lInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class F2lInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | float tmp = frame.popFloat(); 16 | frame.pushLong((long) tmp); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/I2bInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class I2bInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | // do nothings 16 | } 17 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/I2cInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class I2cInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | // do nothings 16 | } 17 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/I2dInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class I2dInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | Integer tmp = frame.popInt(); 16 | frame.pushDouble(((double) tmp)); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/I2fInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class I2fInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | Integer tmp = frame.popInt(); 16 | frame.pushFloat(((float) tmp)); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/I2lInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class I2lInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | Integer tmp = frame.popInt(); 16 | frame.pushLong(tmp.longValue()); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/I2sInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class I2sInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | Integer integer = frame.popInt(); 16 | short val = integer.shortValue(); 17 | frame.pushInt(((int) val)); 18 | } 19 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/L2dInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class L2dInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | long tmp = frame.popLong(); 16 | frame.pushDouble((double) tmp); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/L2fInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class L2fInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | long tmp = frame.popLong(); 16 | frame.pushFloat((float) tmp); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/conversions/L2iInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.conversions; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class L2iInst implements Instruction { 7 | 8 | @Override 9 | public int offset() { 10 | return 1; 11 | } 12 | 13 | @Override 14 | public void execute(Frame frame) { 15 | long tmp = frame.popLong(); 16 | frame.pushInt((int) tmp); 17 | } 18 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/extended/GotoInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.extended; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class GotoInst implements Instruction { 9 | 10 | public final short offset; 11 | 12 | public GotoInst(short offset) { 13 | this.offset = offset; 14 | } 15 | 16 | @Override 17 | public int offset() { 18 | return 3; 19 | } 20 | 21 | @Override 22 | public void execute(Frame frame) { 23 | frame.nextPc = frame.getPc() + offset; 24 | } 25 | 26 | @Override 27 | public String format() { 28 | return "goto " + offset; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/extended/GotoWInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.extended; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class GotoWInst implements Instruction { 9 | 10 | public final int offset; 11 | 12 | public GotoWInst(int offset) { 13 | this.offset = offset; 14 | } 15 | 16 | @Override 17 | public int offset() { 18 | return 5; 19 | } 20 | 21 | @Override 22 | public void execute(Frame frame) { 23 | frame.nextPc = frame.getPc() + offset; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/extended/MultiANewArrayInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.extended; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class MultiANewArrayInst implements Instruction{ 9 | 10 | public final int index; 11 | public final int dimensions; 12 | 13 | public MultiANewArrayInst(int index, int dimensions) { 14 | this.index = index; 15 | this.dimensions = dimensions; 16 | } 17 | 18 | @Override 19 | public int offset() { 20 | return 4; 21 | } 22 | 23 | @Override 24 | public void execute(Frame frame) { 25 | throw new UnsupportedOperationException(MultiANewArrayInst.class.getName()); 26 | } 27 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/extended/WideInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.extended; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class WideInst implements Instruction { 9 | 10 | public final int offset; 11 | public final Instruction inst; 12 | 13 | public WideInst(int offset, Instruction inst) { 14 | this.offset = offset; 15 | this.inst = inst; 16 | } 17 | 18 | @Override 19 | public int offset() { 20 | return offset; 21 | } 22 | 23 | @Override 24 | public void execute(Frame frame) { 25 | inst.execute(frame); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/AALoadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | import com.gxk.jvm.rtda.heap.InstanceArray; 7 | 8 | public class AALoadInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | int index = frame.popInt(); 13 | InstanceArray array = (InstanceArray) frame.popRef(); 14 | Object item = array.items[index]; 15 | frame.pushRef((Instance) item); 16 | } 17 | 18 | @Override 19 | public String format() { 20 | return "aaload"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/ALoad0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public class ALoad0Inst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | Instance tmp = frame.getRef(0); 12 | frame.pushRef(tmp); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "aload_0"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/ALoad1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public class ALoad1Inst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | Instance tmp = frame.getRef(1); 12 | frame.pushRef(tmp); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "aload_1"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/ALoad2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public class ALoad2Inst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | Instance tmp = frame.getRef(2); 12 | frame.pushRef(tmp); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "aload_2"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/ALoad3Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public class ALoad3Inst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | Instance tmp = frame.getRef(3); 12 | frame.pushRef(tmp); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "aload_3"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/ALoadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public class ALoadInst implements Instruction { 8 | 9 | public final int index; 10 | 11 | public ALoadInst(int index) { 12 | this.index = index; 13 | } 14 | 15 | @Override 16 | public int offset() { 17 | return 2; 18 | } 19 | 20 | @Override 21 | public void execute(Frame frame) { 22 | Instance tmp = frame.getRef(index); 23 | frame.pushRef(tmp); 24 | } 25 | 26 | @Override 27 | public String format() { 28 | return "aload " + index; 29 | } 30 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/BAloadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class BAloadInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | int index = frame.popInt(); 12 | PrimitiveArray array = (PrimitiveArray) frame.popRef(); 13 | frame.pushInt(array.ints[index]); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/CAloadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class CAloadInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | int index = frame.popInt(); 12 | PrimitiveArray array = (PrimitiveArray) frame.popRef(); 13 | frame.pushInt(array.ints[index]); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "caload"; 19 | } 20 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/DALoadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class DALoadInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | int index = frame.popInt(); 12 | PrimitiveArray array = (PrimitiveArray) frame.popRef(); 13 | frame.pushDouble(array.doubles[index]); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/DLoad0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DLoad0Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double tmp = frame.getDouble(0); 11 | frame.pushDouble(tmp); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/DLoad1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DLoad1Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double tmp = frame.getDouble(1); 11 | frame.pushDouble(tmp); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/DLoad2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DLoad2Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double tmp = frame.getDouble(2); 11 | frame.pushDouble(tmp); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/DLoad3Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DLoad3Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double tmp = frame.getDouble(3); 11 | frame.pushDouble(tmp); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/DLoadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DLoadInst implements Instruction { 7 | public final int index; 8 | 9 | public DLoadInst(int index) { 10 | this.index = index; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 2; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | double tmp = frame.getDouble(index); 21 | frame.pushDouble(tmp); 22 | } 23 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/FALoadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class FALoadInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | int index = frame.popInt(); 12 | PrimitiveArray array = (PrimitiveArray) frame.popRef(); 13 | frame.pushFloat(array.floats[index]); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/FLoad0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FLoad0Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float tmp = frame.getFloat(0); 13 | frame.pushFloat(tmp); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/FLoad1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FLoad1Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float tmp = frame.getFloat(1); 13 | frame.pushFloat(tmp); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/FLoad2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FLoad2Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float tmp = frame.getFloat(2); 13 | frame.pushFloat(tmp); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/FLoad3Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FLoad3Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float tmp = frame.getFloat(3); 13 | frame.pushFloat(tmp); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/FLoadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FLoadInst implements Instruction { 9 | public final int index; 10 | 11 | public FLoadInst(int index) { 12 | this.index = index; 13 | } 14 | 15 | @Override 16 | public int offset() { 17 | return 2; 18 | } 19 | 20 | @Override 21 | public void execute(Frame frame) { 22 | float tmp = frame.getFloat(index); 23 | frame.pushFloat(tmp); 24 | } 25 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/IALoadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class IALoadInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | int index = frame.popInt(); 12 | PrimitiveArray array = (PrimitiveArray) frame.popRef(); 13 | frame.pushInt(array.ints[index]); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "iaload"; 19 | } 20 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/ILoad0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class ILoad0Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | int tmp = frame.getInt(0); 13 | frame.pushInt(tmp); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "iload_0"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/ILoad1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class ILoad1Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Integer tmp = frame.getInt(1); 13 | frame.pushInt(tmp); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "iload_1"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/ILoad2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class ILoad2Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Integer tmp = frame.getInt(2); 13 | frame.pushInt(tmp); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "iload_2"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/ILoad3Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class ILoad3Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Integer tmp = frame.getInt(3); 13 | frame.pushInt(tmp); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "iload_3"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/ILoadNInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class ILoadNInst implements Instruction { 7 | public final int n; 8 | 9 | public ILoadNInst(int n) { 10 | this.n = n; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 2; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | Integer tmp = frame.getInt(n); 21 | frame.pushInt(tmp); 22 | } 23 | 24 | @Override 25 | public String format() { 26 | return "iload " + n; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/LALoadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class LALoadInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | int index = frame.popInt(); 12 | PrimitiveArray array = (PrimitiveArray) frame.popRef(); 13 | frame.pushLong(array.longs[index]); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "laload"; 19 | } 20 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/LLoad0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LLoad0Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Long tmp = frame.getLong(0); 13 | frame.pushLong(tmp); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/LLoad1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LLoad1Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Long tmp = frame.getLong(1); 13 | frame.pushLong(tmp); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/LLoad2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LLoad2Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Long tmp = frame.getLong(2); 13 | frame.pushLong(tmp); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "lload2"; 19 | } 20 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/LLoad3Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LLoad3Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Long tmp = frame.getLong(3); 13 | frame.pushLong(tmp); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/LLoadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class LLoadInst implements Instruction { 7 | public final int index; 8 | 9 | public LLoadInst(int index) { 10 | this.index = index; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 2; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | Long tmp = frame.getLong(index); 21 | frame.pushLong(tmp); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/loads/SALoadInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.loads; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class SALoadInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | int index = frame.popInt(); 12 | PrimitiveArray array = (PrimitiveArray) frame.popRef(); 13 | frame.pushInt(array.ints[index]); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/DAddInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DAddInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double a1 = frame.popDouble(); 11 | double a2 = frame.popDouble(); 12 | frame.pushDouble(a1 + a2); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/DDivInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DDivInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double v2 = frame.popDouble(); 11 | double v1 = frame.popDouble(); 12 | frame.pushDouble(v1 / v2); 13 | } 14 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/DMulInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | 7 | public class DMulInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | double v2 = frame.popDouble(); 12 | double v1 = frame.popDouble(); 13 | frame.pushDouble(v1 * v2); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/DNegInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DNegInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double tmp = frame.popDouble(); 11 | frame.pushDouble(-tmp); 12 | } 13 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/DRemInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DRemInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double v2 = frame.popDouble(); 11 | double v1 = frame.popDouble(); 12 | frame.pushDouble(v1 % v2); 13 | } 14 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/DSubInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DSubInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double v2 = frame.popDouble(); 11 | double v1 = frame.popDouble(); 12 | frame.pushDouble(v1 - v2); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/FAddInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FAddInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float a1 = frame.popFloat(); 13 | float a2 = frame.popFloat(); 14 | frame.pushFloat(a1 + a2); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/FDivInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FDivInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float v2 = frame.popFloat(); 13 | float v1 = frame.popFloat(); 14 | frame.pushFloat(v1 / v2); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/FMulInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | 9 | public class FMulInst implements Instruction { 10 | 11 | @Override 12 | public void execute(Frame frame) { 13 | float v2 = frame.popFloat(); 14 | float v1 = frame.popFloat(); 15 | frame.pushFloat(v1 * v2); 16 | } 17 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/FNegInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FNegInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float tmp = frame.popFloat(); 13 | frame.pushFloat(-tmp); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/FRemInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FRemInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float v2 = frame.popFloat(); 13 | float v1 = frame.popFloat(); 14 | frame.pushFloat(v1 % v2); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/FSubInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FSubInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float v2 = frame.popFloat(); 13 | float v1 = frame.popFloat(); 14 | frame.pushFloat(v1 - v2); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/IAddInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IAddInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Integer a1 = frame.popInt(); 13 | Integer a2 = frame.popInt(); 14 | frame.pushInt(a1 + a2); 15 | } 16 | 17 | @Override 18 | public String format() { 19 | return "iadd"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/IAndInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IAndInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Integer v2 = frame.popInt(); 13 | Integer v1 = frame.popInt(); 14 | int val = v1 & v2; 15 | frame.pushInt(val); 16 | } 17 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/IDivInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IDivInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Integer v2 = frame.popInt(); 13 | Integer v1 = frame.popInt(); 14 | frame.pushInt(v1 / v2); 15 | } 16 | 17 | @Override 18 | public String format() { 19 | return "idiv"; 20 | } 21 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/IMulInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | 9 | public class IMulInst implements Instruction { 10 | 11 | @Override 12 | public void execute(Frame frame) { 13 | Integer v2 = frame.popInt(); 14 | Integer v1 = frame.popInt(); 15 | frame.pushInt(v1 * v2); 16 | } 17 | 18 | @Override 19 | public String format() { 20 | return "imul"; 21 | } 22 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/INegInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class INegInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | int tmp = frame.popInt(); 13 | frame.pushInt(-tmp); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/IOrInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IOrInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | int v2 = frame.popInt(); 13 | int v1 = frame.popInt(); 14 | frame.pushInt(v1 | v2); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/IRemInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IRemInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Integer v2 = frame.popInt(); 13 | Integer v1 = frame.popInt(); 14 | frame.pushInt(v1 % v2); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/IShlInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IShlInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | int v2 = frame.popInt(); 11 | int v1 = frame.popInt(); 12 | int s = v2 & 0x1f; 13 | int ret = v1 << s; 14 | frame.pushInt(ret); 15 | } 16 | 17 | @Override 18 | public String format() { 19 | return "ishl"; 20 | } 21 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/IShrInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IShrInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | int v2 = frame.popInt(); 11 | int v1 = frame.popInt(); 12 | int s = v2 & 0x1f; 13 | int ret = v1 >> s; 14 | frame.pushInt(ret); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/ISubInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class ISubInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Integer v2 = frame.popInt(); 13 | Integer v1 = frame.popInt(); 14 | frame.pushInt(v1 - v2); 15 | } 16 | 17 | @Override 18 | public String format() { 19 | return "isub"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/IUShrInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IUShrInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | int v2 = frame.popInt(); 11 | int v1 = frame.popInt(); 12 | int s = v2 & 0x1f; 13 | 14 | if (v1 >= 0) { 15 | int ret = v1 >> s; 16 | frame.pushInt(ret); 17 | return; 18 | } 19 | int ret = (v1 >> s) + (2 << ~s); 20 | frame.pushInt(ret); 21 | } 22 | 23 | @Override 24 | public String format() { 25 | return "iushr"; 26 | } 27 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/IXOrInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IXOrInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | final int v2 = frame.popInt(); 13 | final int v1 = frame.popInt(); 14 | frame.pushInt(v1 ^ v2); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LAddInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LAddInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Long a1 = frame.popLong(); 13 | Long a2 = frame.popLong(); 14 | frame.pushLong(a1 + a2); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LAndInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LAndInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | long a1 = frame.popLong(); 13 | long a2 = frame.popLong(); 14 | frame.pushLong(a2 & a1); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LDivInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LDivInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | long v2 = frame.popLong(); 13 | long v1 = frame.popLong(); 14 | frame.pushLong(v1 / v2); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LMulInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | 9 | public class LMulInst implements Instruction { 10 | 11 | @Override 12 | public void execute(Frame frame) { 13 | long v2 = frame.popLong(); 14 | long v1 = frame.popLong(); 15 | frame.pushLong(v1 * v2); 16 | } 17 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LNegInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LNegInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Long tmp = frame.popLong(); 13 | frame.pushLong(-tmp); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LOrInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LOrInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Long v2 = frame.popLong(); 13 | Long v1 = frame.popLong(); 14 | frame.pushLong(v1 | v2); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LRemInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LRemInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | long v2 = frame.popLong(); 13 | long v1 = frame.popLong(); 14 | frame.pushLong(v1 % v2); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LShlInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class LShlInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | int v2 = frame.popInt(); 11 | long v1 = frame.popLong(); 12 | int s = v2 & 0x1f; 13 | long ret = v1 << s; 14 | frame.pushLong(ret); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LShrInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LShrInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | final int v2 = frame.popInt(); 13 | final long v1 = frame.popLong(); 14 | frame.pushLong(v1 >> v2); 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LSubInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LSubInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | long v2 = frame.popLong(); 13 | long v1 = frame.popLong(); 14 | frame.pushLong(v1 - v2); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LUShrInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LUShrInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | int v2 = frame.popInt(); 13 | long v1 = frame.popLong(); 14 | int s = v2 & 0x3f; 15 | 16 | if (v1 >= 0) { 17 | long ret = v1 >> s; 18 | frame.pushLong(ret); 19 | return; 20 | } 21 | long ret = (v1 >> s) + (2L << ~s); 22 | frame.pushLong(ret); 23 | } 24 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/math/LXOrInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.math; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class LXOrInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | long v2 = frame.popLong(); 11 | long v1 = frame.popLong(); 12 | frame.pushLong(v1 ^ v2); 13 | } 14 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/references/ArrayLengthInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.references; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.ArrayInstance; 6 | 7 | public class ArrayLengthInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | ArrayInstance arr = (ArrayInstance) frame.popRef(); 12 | frame.pushInt(arr.len); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "arraylength"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/references/CheckcastInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.references; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class CheckcastInst implements Instruction { 7 | 8 | public final String clazz; 9 | 10 | public CheckcastInst(String clazz) { 11 | this.clazz = clazz; 12 | } 13 | 14 | @Override 15 | public int offset() { 16 | return 3; 17 | } 18 | 19 | @Override 20 | public void execute(Frame frame) { 21 | //FIXME throw new UnsupportedOperationException(); 22 | } 23 | 24 | @Override 25 | public String format() { 26 | return "checkcast " + clazz; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/references/MonitorEnterInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.references; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class MonitorEnterInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | // TODO ... 13 | frame.popRef(); 14 | // throw new UnsupportedOperationException(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/references/MonitorExitInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.references; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class MonitorExitInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | // TODO ... 13 | frame.popRef(); 14 | // throw new UnsupportedOperationException(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stack/Dup2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stack; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.Slot; 6 | 7 | public class Dup2Inst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | final Slot v2 = frame.pop(); 12 | final Slot v1 = frame.pop(); 13 | frame.push(v1); 14 | frame.push(v2); 15 | frame.push(v1); 16 | frame.push(v2); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stack/Dup2X1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stack; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class Dup2X1Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | throw new UnsupportedOperationException(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stack/Dup2X2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stack; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class Dup2X2Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | throw new UnsupportedOperationException(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stack/DupInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stack; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.Slot; 6 | 7 | public class DupInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | final Slot val = frame.pop(); 12 | frame.push(val); 13 | frame.push(val); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "dup"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stack/DupX1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stack; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.Slot; 6 | 7 | public class DupX1Inst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | Slot s1 = frame.popSlot(); 12 | Slot s2 = frame.popSlot(); 13 | frame.pushSlot(s1); 14 | frame.pushSlot(s2); 15 | frame.pushSlot(s1); 16 | } 17 | 18 | @Override 19 | public String format() { 20 | return "dupx1"; 21 | } 22 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stack/DupX2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stack; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DupX2Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | throw new UnsupportedOperationException(); 11 | } 12 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stack/Pop2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stack; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class Pop2Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.popRef(); 13 | frame.popRef(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stack/PopInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stack; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class PopInst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | frame.popRef(); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "pop"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stack/SwapInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stack; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public class SwapInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | Object v2 = frame.popRef(); 12 | Object v1 = frame.popRef(); 13 | frame.pushRef((Instance) v2); 14 | frame.pushRef((Instance) v1); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/AAStoreInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.InstanceArray; 6 | 7 | public class AAStoreInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | Object val = frame.popRef(); 12 | Integer index = frame.popInt(); 13 | InstanceArray array = (InstanceArray) frame.popRef(); 14 | array.items[index] = val; 15 | } 16 | 17 | @Override 18 | public String format() { 19 | return "aastore"; 20 | } 21 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/AStore0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public class AStore0Inst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | Object tmp = frame.popRef(); 12 | frame.setRef(0, (Instance) tmp); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "astore_0"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/AStore1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public class AStore1Inst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | Object tmp = frame.popRef(); 12 | frame.setRef(1, (Instance) tmp); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "astore_1"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/AStore2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public class AStore2Inst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | Object tmp = frame.popRef(); 12 | frame.setRef(2, (Instance) tmp); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "astore_2"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/AStore3Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public class AStore3Inst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | Object tmp = frame.popRef(); 12 | frame.setRef(3, (Instance) tmp); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "astore_3"; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/AStoreInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public class AStoreInst implements Instruction { 8 | 9 | public final int index; 10 | 11 | public AStoreInst(int index) { 12 | this.index = index; 13 | } 14 | 15 | @Override 16 | public int offset() { 17 | return 2; 18 | } 19 | 20 | @Override 21 | public void execute(Frame frame) { 22 | Object tmp = frame.popRef(); 23 | frame.setRef(index, (Instance) tmp); 24 | } 25 | 26 | @Override 27 | public String format() { 28 | return "astore " + index; 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/BAStoreInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class BAStoreInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | int val = frame.popInt(); 12 | int index = frame.popInt(); 13 | PrimitiveArray array = (PrimitiveArray) frame.popRef(); 14 | array.ints[index] = val; 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/CAStoreInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class CAStoreInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | int val = frame.popInt(); 12 | int index = frame.popInt(); 13 | PrimitiveArray array = (PrimitiveArray) frame.popRef(); 14 | array.ints[index] = val; 15 | } 16 | 17 | @Override 18 | public String format() { 19 | return "castore"; 20 | } 21 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/DAStoreInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class DAStoreInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | double val = frame.popDouble(); 12 | int index = frame.popInt(); 13 | final PrimitiveArray array = (PrimitiveArray) frame.popRef(); 14 | array.doubles[index] = val; 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/DStore0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DStore0Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double tmp = frame.popDouble(); 11 | frame.setDouble(0, tmp); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/DStore1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DStore1Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double tmp = frame.popDouble(); 11 | frame.setDouble(1, tmp); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/DStore2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DStore2Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double tmp = frame.popDouble(); 11 | frame.setDouble(2, tmp); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/DStore3Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DStore3Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | double tmp = frame.popDouble(); 11 | frame.setDouble(3, tmp); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/DStoreNInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class DStoreNInst implements Instruction { 7 | public final int n; 8 | 9 | public DStoreNInst(int n) { 10 | this.n = n; 11 | } 12 | 13 | @Override 14 | public int offset() { 15 | return 2; 16 | } 17 | 18 | @Override 19 | public void execute(Frame frame) { 20 | double tmp = frame.popDouble(); 21 | frame.setDouble(n, tmp); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/FAStoreInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class FAStoreInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | float val = frame.popFloat(); 12 | int index = frame.popInt(); 13 | final PrimitiveArray array = (PrimitiveArray) frame.popRef(); 14 | array.floats[index] = val; 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/FStore0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FStore0Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float tmp = frame.popFloat(); 13 | frame.setFloat(0, tmp); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/FStore1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FStore1Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float tmp = frame.popFloat(); 13 | frame.setFloat(1, tmp); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/FStore2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FStore2Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float tmp = frame.popFloat(); 13 | frame.setFloat(2, tmp); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/FStore3Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FStore3Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | float tmp = frame.popFloat(); 13 | frame.setFloat(3, tmp); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/FStoreNInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class FStoreNInst implements Instruction { 9 | public final int n; 10 | 11 | public FStoreNInst(int n) { 12 | this.n = n; 13 | } 14 | 15 | @Override 16 | public int offset() { 17 | return 2; 18 | } 19 | 20 | @Override 21 | public void execute(Frame frame) { 22 | Float tmp = frame.popFloat(); 23 | frame.setFloat(n, tmp); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/IAStoreInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class IAStoreInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | int val = frame.popInt(); 12 | int index = frame.popInt(); 13 | final PrimitiveArray array = (PrimitiveArray) frame.popRef(); 14 | array.ints[index] = val; 15 | } 16 | 17 | @Override 18 | public String format() { 19 | return "iastore"; 20 | } 21 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/IStore0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IStore0Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Integer tmp = frame.popInt(); 13 | frame.setInt(0, tmp); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "istore_0"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/IStore1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IStore1Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Integer tmp = frame.popInt(); 13 | frame.setInt(1, tmp); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "istore_1"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/IStore2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class IStore2Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Integer tmp = frame.popInt(); 13 | frame.setInt(2, tmp); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "istore_2"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/IStore3Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IStore3Inst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | int tmp = frame.popInt(); 11 | frame.setInt(3, tmp); 12 | } 13 | 14 | @Override 15 | public String format() { 16 | return "istore_3"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/LAStoreInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class LAStoreInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | long val = frame.popLong(); 12 | int index = frame.popInt(); 13 | final PrimitiveArray array = (PrimitiveArray) frame.popRef(); 14 | array.longs[index] = val; 15 | } 16 | 17 | @Override 18 | public String format() { 19 | return "lastore"; 20 | } 21 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/LStore0Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LStore0Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Long tmp = frame.popLong(); 13 | frame.setLong(0, tmp); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/LStore1Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LStore1Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Long tmp = frame.popLong(); 13 | frame.setLong(1, tmp); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/LStore2Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LStore2Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Long tmp = frame.popLong(); 13 | frame.setLong(2, tmp); 14 | } 15 | 16 | @Override 17 | public String format() { 18 | return "lstore_2"; 19 | } 20 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/LStore3Inst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LStore3Inst implements Instruction { 9 | 10 | @Override 11 | public void execute(Frame frame) { 12 | Long tmp = frame.popLong(); 13 | frame.setLong(3, tmp); 14 | } 15 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/LStoreNInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | 5 | 6 | import com.gxk.jvm.rtda.Frame; 7 | 8 | public class LStoreNInst implements Instruction { 9 | public final int n; 10 | 11 | public LStoreNInst(int n) { 12 | this.n = n; 13 | } 14 | 15 | @Override 16 | public int offset() { 17 | return 2; 18 | } 19 | 20 | @Override 21 | public void execute(Frame frame) { 22 | Long tmp = frame.popLong(); 23 | frame.setLong(n, tmp); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/instruction/stores/SAStoreInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.instruction.stores; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | import com.gxk.jvm.rtda.heap.PrimitiveArray; 6 | 7 | public class SAStoreInst implements Instruction { 8 | 9 | @Override 10 | public void execute(Frame frame) { 11 | int val = frame.popInt(); 12 | int index = frame.popInt(); 13 | final PrimitiveArray array = (PrimitiveArray) frame.popRef(); 14 | array.ints[index] = val; 15 | } 16 | } -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/nativebridge/java/io/FileDescriptorBridge.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.nativebridge.java.io; 2 | 3 | import com.gxk.jvm.rtda.heap.Heap; 4 | 5 | public abstract class FileDescriptorBridge { 6 | 7 | public static void registerNative0() { 8 | Heap.registerMethod("java/io/FileDescriptor_initIDs_()V", frame -> { 9 | }); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/nativebridge/java/lang/ExceptionBridge.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.nativebridge.java.lang; 2 | 3 | import com.gxk.jvm.rtda.UnionSlot; 4 | import com.gxk.jvm.rtda.heap.Heap; 5 | import com.gxk.jvm.rtda.heap.Field; 6 | import com.gxk.jvm.rtda.heap.Instance; 7 | 8 | public abstract class ExceptionBridge { 9 | 10 | public static void registerNatives0() { 11 | Heap.registerMethod("java/lang/Exception__(Ljava/lang/String;)V", frame -> { 12 | Instance str = (Instance) frame.popRef(); 13 | Instance thisObj = (Instance) frame.popRef(); 14 | Field msgField = thisObj.getField("detailMessage", "Ljava/lang/String;"); 15 | msgField.val = UnionSlot.of(str); 16 | }); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/nativebridge/java/lang/FloatBridge.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.nativebridge.java.lang; 2 | 3 | import com.gxk.jvm.rtda.heap.Heap; 4 | 5 | public abstract class FloatBridge { 6 | 7 | public static void registerNatives0() { 8 | Heap.registerMethod("java/lang/Float_intBitsToFloat_(I)F", frame -> { 9 | java.lang.Integer tmp = frame.popInt(); 10 | float v = java.lang.Float.intBitsToFloat(tmp); 11 | frame.pushFloat(v); 12 | }); 13 | Heap.registerMethod("java/lang/Float_floatToRawIntBits_(F)I", frame -> { 14 | float tmp = frame.popFloat(); 15 | int v = java.lang.Float.floatToRawIntBits(tmp); 16 | frame.pushInt(v); 17 | }); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/nativebridge/java/lang/ThreadBridge.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.nativebridge.java.lang; 2 | 3 | public abstract class ThreadBridge { 4 | 5 | public static void registerNatives0() { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/nativebridge/java/nio/charset/CharsetBridge.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.nativebridge.java.nio.charset; 2 | 3 | import com.gxk.jvm.rtda.heap.Heap; 4 | 5 | public abstract class CharsetBridge { 6 | 7 | public static void registerNative0() { 8 | // static 9 | Heap.registerMethod("java/nio/charset/Charset_atBugLevel_(Ljava/lang/String;)Z", frame -> { 10 | frame.popRef(); 11 | // false 12 | frame.pushInt(0); 13 | }); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/nativebridge/java/sum/misc/ReflectionBridge.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.nativebridge.java.sum.misc; 2 | 3 | import com.gxk.jvm.rtda.Frame; 4 | import com.gxk.jvm.rtda.heap.Heap; 5 | import com.gxk.jvm.rtda.heap.Instance; 6 | 7 | public abstract class ReflectionBridge { 8 | 9 | public static void registerNatives0() { 10 | Heap.registerMethod("sun/reflect/Reflection_getCallerClass_()Ljava/lang/Class;", frame -> { 11 | Frame callerFrame = frame.thread.callerFrame(); 12 | Object cls = callerFrame.method.clazz.getRuntimeClass(); 13 | frame.pushRef((Instance) cls); 14 | }); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/nativebridge/java/util/concurrent/AtomicLongBridge.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.nativebridge.java.util.concurrent; 2 | 3 | import com.gxk.jvm.rtda.heap.Heap; 4 | 5 | public abstract class AtomicLongBridge { 6 | 7 | public static void registerNatives0() { 8 | Heap.registerMethod("java/util/concurrent/atomic/AtomicLong_VMSupportsCS8_()Z", frame -> { 9 | frame.pushInt(0); 10 | }); 11 | Heap.registerMethod("java/util/concurrent/atomic/AtomicLong__()V", frame -> { 12 | }); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/rtda/MetaSpace.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.rtda; 2 | 3 | import com.gxk.jvm.rtda.heap.Heap; 4 | import com.gxk.jvm.rtda.heap.NativeMethod; 5 | 6 | public class MetaSpace { 7 | 8 | public static Thread main; 9 | 10 | public static Thread getMainEnv() { 11 | return main; 12 | } 13 | 14 | public static NativeMethod findNativeMethod(String key) { 15 | return Heap.findMethod(key); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/rtda/Slot.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.rtda; 2 | 3 | import com.gxk.jvm.rtda.heap.Instance; 4 | 5 | public class Slot { 6 | public Integer num; 7 | public Instance ref; 8 | 9 | public Slot(int num) { 10 | this.num = num; 11 | this.ref = null; 12 | } 13 | 14 | public Slot(Instance ref) { 15 | this.num = null; 16 | this.ref = ref; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | final StringBuilder sb = new StringBuilder("Slot{"); 22 | sb.append("num=").append(num); 23 | sb.append(", ref=").append(ref); 24 | sb.append('}'); 25 | return sb.toString(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/rtda/heap/ArrayInstance.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.rtda.heap; 2 | 3 | public class ArrayInstance extends Instance { 4 | 5 | public final int len; 6 | 7 | public ArrayInstance(Class clazz, int len) { 8 | super(clazz); 9 | this.len = len; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/rtda/heap/InstanceArray.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.rtda.heap; 2 | 3 | public class InstanceArray extends ArrayInstance { 4 | 5 | public final Object[] items; 6 | 7 | public InstanceArray(Class clazz, Object[] items) { 8 | super(clazz, items.length); 9 | this.items = items; 10 | } 11 | 12 | @Override 13 | public String toString() { 14 | return "KArray{items=" + items.length + "}@" + this.hashCode(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/rtda/heap/LambdaObject.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.rtda.heap; 2 | 3 | import java.util.List; 4 | 5 | public class LambdaObject extends Instance { 6 | public final List args; 7 | 8 | public LambdaObject(Class clazz, List vars) { 9 | super(clazz); 10 | this.args = vars; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/rtda/heap/NativeMethod.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.rtda.heap; 2 | 3 | import com.gxk.jvm.rtda.Frame; 4 | 5 | public interface NativeMethod { 6 | // do all things 7 | void invoke(Frame frame); 8 | } 9 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/util/Const.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.util; 2 | 3 | public class Const { 4 | 5 | // class stat 6 | public static final int CLASS_LOADED = 1; 7 | public static final int CLASS_LINKED = 2; 8 | public static final int CLASS_INITING = 3; 9 | public static final int CLASS_INITED = 4; 10 | 11 | // ACCESS 12 | public static final int ACC_STATIC = 0x0008; 13 | public static final int ACC_NATIVE = 0x0100; 14 | public static final int ACC_INTERFACE = 0x0200; 15 | public static final int ACC_ABSTRACT = 0x0400; 16 | 17 | // FRAME 18 | public static final int FAKE_FRAME = 1; 19 | public static final int FAKE_FRAME_END = 2; 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/main/java/com/gxk/jvm/util/DebugContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.util; 2 | 3 | import java.util.Scanner; 4 | 5 | public abstract class DebugContextHolder { 6 | 7 | public static Scanner scanner; 8 | public static boolean next; 9 | public static boolean running; 10 | public static String mainClass; 11 | public static boolean step; 12 | 13 | public static boolean isContinue() { 14 | if (step) { 15 | step = false; 16 | return true; 17 | } 18 | return next; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jvm-core/src/test/java/com/gxk/jvm/interpret/exception/InterpreterExceptionTest.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.interpret.exception; 2 | 3 | import com.gxk.jvm.interpret.BaseInterpreterTest; 4 | import org.junit.Test; 5 | 6 | public class InterpreterExceptionTest extends BaseInterpreterTest { 7 | 8 | @Test 9 | public void test_simple() { 10 | testMain("TestException"); 11 | } 12 | 13 | @Test 14 | public void test_exception_finally() { 15 | testMain("TestException2"); 16 | } 17 | 18 | @Test 19 | public void test_exception_chain() { 20 | testMain("TestException3"); 21 | } 22 | 23 | @Test(expected = RuntimeException.class) 24 | public void test_exception_chain2() { 25 | testMain("TestException4"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jvm-core/src/test/java/com/gxk/jvm/interpret/primitive/InterpreterPrimitiveTest.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.interpret.primitive; 2 | 3 | import com.gxk.jvm.interpret.BaseInterpreterTest; 4 | import org.junit.Test; 5 | 6 | public class InterpreterPrimitiveTest extends BaseInterpreterTest { 7 | 8 | @Test 9 | public void test_hello_bool() { 10 | testMain("TrueFalse"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /jvm-core/src/test/java/com/gxk/jvm/interpret/reflect/ReflectionInterpreterTest.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.interpret.reflect; 2 | 3 | import com.gxk.jvm.interpret.BaseInterpreterTest; 4 | import org.junit.Test; 5 | 6 | public class ReflectionInterpreterTest extends BaseInterpreterTest { 7 | 8 | @Test 9 | public void test_class() { 10 | testMain("TestClass"); 11 | } 12 | 13 | @Test 14 | public void test_class2() { 15 | testMain("TestClass2"); 16 | } 17 | 18 | @Test 19 | public void test_class3() { 20 | testMain("TestClass3"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jvm-core/src/test/java/com/gxk/jvm/rtda/StackTest.java: -------------------------------------------------------------------------------- 1 | //package com.gxk.jvm.rtda; 2 | // 3 | //import com.gxk.jvm.rtda.heap.Method; 4 | //import org.junit.Test; 5 | // 6 | //import static org.junit.Assert.*; 7 | // 8 | //public class StackTest { 9 | // 10 | // @Test 11 | // public void test() { 12 | // Stack stack = new Stack<>(1024); 13 | // Method method = new Method(1, "x", "x", 1, 1, null, null, null); 14 | // stack.push(new Frame(method)); 15 | // 16 | // assertEquals(1, stack.size()); 17 | // assertEquals(1024, stack.maxSize); 18 | // } 19 | //} -------------------------------------------------------------------------------- /jvm-native/build_native.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | native-image -cp ../jvm-core/target/mini-jvm.jar \ 4 | -H:Name=../bin/jvm \ 5 | -H:+ReportUnsupportedElementsAtRuntime \ 6 | --no-server \ 7 | com.gxk.jvm.Main 8 | -------------------------------------------------------------------------------- /jvm-tools/ext/Sum.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/jvm-tools/ext/Sum.class -------------------------------------------------------------------------------- /jvm-tools/ext/Sum.java: -------------------------------------------------------------------------------- 1 | public class Sum { 2 | 3 | public static int sum(int n) { 4 | int sum = 0; 5 | for (int i = 1; i <= n; i++) { 6 | sum += i; 7 | } 8 | return sum; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /jvm-tools/ext/Sum10.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/jvm-tools/ext/Sum10.class -------------------------------------------------------------------------------- /jvm-tools/ext/Sum10.java: -------------------------------------------------------------------------------- 1 | public class Sum10 { 2 | 3 | public static int sum10() { 4 | int sum = 0; 5 | for (int i = 1; i <= 10; i++) { 6 | sum += i; 7 | } 8 | return sum; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /jvm-tools/ext/sum.bc: -------------------------------------------------------------------------------- 1 | main 2 3 1 2 | 0 iconst_0 3 | 1 istore_1 4 | 2 iconst_1 5 | 3 istore_2 6 | 4 iload_2 7 | 5 iload_0 8 | 6 if_icmpgt 13 9 | 9 iload_1 10 | 10 iload_2 11 | 11 iadd 12 | 12 istore_1 13 | 13 iinc 2 1 14 | 16 goto -12 15 | 19 iload_1 16 | 20 ireturn 17 | -------------------------------------------------------------------------------- /jvm-tools/ext/sum10.bc: -------------------------------------------------------------------------------- 1 | main 2 2 0 2 | 0 iconst_0 3 | 1 istore_0 4 | 2 iconst_1 5 | 3 istore_1 6 | 4 iload_1 7 | 5 bipush 10 8 | 7 if_icmpgt 13 9 | 10 iload_0 10 | 11 iload_1 11 | 12 iadd 12 | 13 istore_0 13 | 14 iinc 1 1 14 | 17 goto -13 15 | 20 iload_0 16 | 21 ireturn 17 | -------------------------------------------------------------------------------- /jvm-tools/src/main/java/com/gxk/jvm/ext/bc/IReturnInst.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.ext.bc; 2 | 3 | import com.gxk.jvm.instruction.Instruction; 4 | import com.gxk.jvm.rtda.Frame; 5 | 6 | public class IReturnInst implements Instruction { 7 | 8 | @Override 9 | public void execute(Frame frame) { 10 | Integer tmp = frame.popInt(); 11 | frame.thread.popFrame(); 12 | System.out.println(tmp); 13 | } 14 | 15 | @Override 16 | public String format() { 17 | return "ireturn"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jvm-tools/src/main/java/com/gxk/jvm/ext/bc/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 字节码解释 DEMO 3 | */ 4 | package com.gxk.jvm.ext.bc; -------------------------------------------------------------------------------- /jvm-tools/src/main/java/com/gxk/jvm/tools/AsmGen.java: -------------------------------------------------------------------------------- 1 | package com.gxk.jvm.tools; 2 | 3 | import com.gxk.jvm.ext.bc.ByteCodeGenerator; 4 | 5 | /** 6 | * generate simple asm code from class file method. 7 | * 8 | * java -cp target/tools.jar com.gxk.jvm.tools.AsmGen [class file] [method] 9 | * e.g 10 | * java -cp target/tools.jar com.gxk.jvm.tools.AsmGen ext/Sum.class sum 11 | */ 12 | public class AsmGen { 13 | 14 | public static void main(String[] args) { 15 | String clazzPath = args[0]; 16 | String methodName = "bc"; 17 | if (args.length == 2) { 18 | methodName = args[1]; 19 | } 20 | 21 | ByteCodeGenerator.gen(clazzPath, methodName); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mini-jdk/src/main/java/java/io/NativeInputStream.java: -------------------------------------------------------------------------------- 1 | package java.io; 2 | 3 | public class NativeInputStream extends InputStream { 4 | 5 | @Override 6 | public native int read() throws IOException; 7 | 8 | @Override 9 | public native int available() throws IOException; 10 | 11 | @Override 12 | public native void close() throws IOException; 13 | } 14 | -------------------------------------------------------------------------------- /mini-jdk/src/main/java/java/util/zip/ZipFile.java: -------------------------------------------------------------------------------- 1 | package java.util.zip; 2 | 3 | import java.io.InputStream; 4 | 5 | public class ZipFile { 6 | public native void init(String path); 7 | 8 | public ZipFile(String path) { 9 | init(path); 10 | } 11 | 12 | public native ZipEntry getEntry(String name); 13 | 14 | public native InputStream getInputStream(ZipEntry entry); 15 | } -------------------------------------------------------------------------------- /test.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/test.jar -------------------------------------------------------------------------------- /tests/array_test/ArrayTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/array_test/ArrayTest.class -------------------------------------------------------------------------------- /tests/array_test/ArrayTest2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/array_test/ArrayTest2.class -------------------------------------------------------------------------------- /tests/array_test/ArrayTest2.java: -------------------------------------------------------------------------------- 1 | public class ArrayTest2 { 2 | public static void main(String[] args) { 3 | AtObj[] arr = new AtObj[1]; 4 | arr[0] = new AtObj(); 5 | arr[0].i = 2; 6 | System.out.println(arr[0].i); 7 | 8 | System.out.println(arr.length); 9 | } 10 | } 11 | 12 | class AtObj { 13 | int i; 14 | } -------------------------------------------------------------------------------- /tests/array_test/AtObj.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/array_test/AtObj.class -------------------------------------------------------------------------------- /tests/array_test/test.expect: -------------------------------------------------------------------------------- 1 | true 2 |  3 | 1 4 | 1 5 | 1 6 | 1 7 | 1.0 8 | 1.0 9 | 2 10 | 1 11 | -------------------------------------------------------------------------------- /tests/array_test/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe ArrayTest > test.result 5 | $exe ArrayTest2 >> test.result 6 | diff test.result test.expect 2>&1 > /dev/null 7 | -------------------------------------------------------------------------------- /tests/basic/Test.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/basic/Test.class -------------------------------------------------------------------------------- /tests/basic/TestM.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/basic/TestM.class -------------------------------------------------------------------------------- /tests/basic/test.expect: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /tests/basic/test.result: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /tests/basic/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | exe=$1 5 | 6 | $exe -cp . TestM > test.result 7 | 8 | diff test.result test.expect 2>&1 > /dev/null 9 | -------------------------------------------------------------------------------- /tests/class_init/ClassInitTest1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/class_init/ClassInitTest1.class -------------------------------------------------------------------------------- /tests/class_init/ClassInitTest1.java: -------------------------------------------------------------------------------- 1 | public class ClassInitTest1 { 2 | static { 3 | System.out.println(1); 4 | } 5 | public static void main(String[] args) { 6 | System.out.println(2); 7 | } 8 | } 9 | class ClassInitTest2 extends ClassInitTest1{ 10 | static { 11 | System.out.println(2); 12 | } 13 | public static void main(String[] args) { 14 | System.out.println(3); 15 | } 16 | } 17 | class ClassInitTest3 extends ClassInitTest2 { 18 | static { 19 | System.out.println(3); 20 | } 21 | public static void main(String[] args) { 22 | System.out.println(4); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/class_init/ClassInitTest2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/class_init/ClassInitTest2.class -------------------------------------------------------------------------------- /tests/class_init/ClassInitTest3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/class_init/ClassInitTest3.class -------------------------------------------------------------------------------- /tests/class_init/test.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | -------------------------------------------------------------------------------- /tests/class_init/test.result: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /tests/class_init/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe ClassInitTest3 > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/comparisons/Comparisons.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/comparisons/Comparisons.class -------------------------------------------------------------------------------- /tests/comparisons/test.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 1 5 | 4 6 | 5 7 | 1 8 | 1.0 9 | 1.0 10 | 1.0 11 | 1.0 12 | -------------------------------------------------------------------------------- /tests/comparisons/test.result: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 1 5 | 4 6 | 5 7 | 4294967296 8 | -------------------------------------------------------------------------------- /tests/comparisons/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe Comparisons > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/constants/Constants.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/constants/Constants.class -------------------------------------------------------------------------------- /tests/constants/test.expect: -------------------------------------------------------------------------------- 1 | -1 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | 5 8 | 0 9 | 1 10 | -128 11 | -2 12 | 6 13 | 127 14 | -32768 15 | -129 16 | 128 17 | 32767 18 | -------------------------------------------------------------------------------- /tests/constants/test.result: -------------------------------------------------------------------------------- 1 | -1 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | 5 8 | 0 9 | 1 10 | -128 11 | -2 12 | 6 13 | 127 14 | -32768 15 | -129 16 | 128 17 | 32767 18 | -------------------------------------------------------------------------------- /tests/constants/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe -cp . Constants > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/hello/Hello.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/hello/Hello.class -------------------------------------------------------------------------------- /tests/hello/test.expect: -------------------------------------------------------------------------------- 1 | build 2 | jvm 3 | from 4 | scratch 5 | -------------------------------------------------------------------------------- /tests/hello/test.result: -------------------------------------------------------------------------------- 1 | build 2 | jvm 3 | from 4 | scratch 5 | -------------------------------------------------------------------------------- /tests/hello/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe -cp . Hello build jvm from scratch > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/instance_array/InstanceArray.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/instance_array/InstanceArray.class -------------------------------------------------------------------------------- /tests/instance_array/InstanceArray.java: -------------------------------------------------------------------------------- 1 | class InstanceArray { 2 | public static void main(String[] args) { 3 | InstanceArrayObj[] arr = new InstanceArrayObj[1]; 4 | System.out.println(arr.length); 5 | 6 | arr[0] = new InstanceArrayObj(); 7 | arr[0].val = 2; 8 | System.out.println(arr[0].val); 9 | } 10 | } 11 | 12 | class InstanceArrayObj { 13 | int val; 14 | } 15 | -------------------------------------------------------------------------------- /tests/instance_array/InstanceArrayObj.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/instance_array/InstanceArrayObj.class -------------------------------------------------------------------------------- /tests/instance_array/test.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -------------------------------------------------------------------------------- /tests/instance_array/test.result: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -------------------------------------------------------------------------------- /tests/instance_array/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe -cp . InstanceArray > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/interface_init/Interface1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_init/Interface1.class -------------------------------------------------------------------------------- /tests/interface_init/Interface2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_init/Interface2.class -------------------------------------------------------------------------------- /tests/interface_init/InterfaceImpl1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_init/InterfaceImpl1.class -------------------------------------------------------------------------------- /tests/interface_init/InterfaceImpl2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_init/InterfaceImpl2.class -------------------------------------------------------------------------------- /tests/interface_init/InterfaceObj.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_init/InterfaceObj.class -------------------------------------------------------------------------------- /tests/interface_init/test.expect: -------------------------------------------------------------------------------- 1 | 2 2 | 1 3 | 10 4 | 3 5 | 1 6 | 10 7 | -------------------------------------------------------------------------------- /tests/interface_init/test.result: -------------------------------------------------------------------------------- 1 | 2 2 | 1 3 | 10 4 | 3 5 | 1 6 | 10 7 | -------------------------------------------------------------------------------- /tests/interface_init/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | rm -f test.result 5 | $exe InterfaceImpl1 >> test.result 6 | $exe InterfaceImpl2 >> test.result 7 | diff test.result test.expect 2>&1 > /dev/null 8 | -------------------------------------------------------------------------------- /tests/interface_override/Interface11.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_override/Interface11.class -------------------------------------------------------------------------------- /tests/interface_override/Interface12.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_override/Interface12.class -------------------------------------------------------------------------------- /tests/interface_override/Interface13.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_override/Interface13.class -------------------------------------------------------------------------------- /tests/interface_override/Interface14.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_override/Interface14.class -------------------------------------------------------------------------------- /tests/interface_override/InterfaceImpl11.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_override/InterfaceImpl11.class -------------------------------------------------------------------------------- /tests/interface_override/InterfaceImpl12.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_override/InterfaceImpl12.class -------------------------------------------------------------------------------- /tests/interface_override/InterfaceImpl13.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_override/InterfaceImpl13.class -------------------------------------------------------------------------------- /tests/interface_override/InterfaceImpl14.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_override/InterfaceImpl14.class -------------------------------------------------------------------------------- /tests/interface_override/InterfaceImpl15.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_override/InterfaceImpl15.class -------------------------------------------------------------------------------- /tests/interface_override/InterfaceOverrideObj.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/interface_override/InterfaceOverrideObj.class -------------------------------------------------------------------------------- /tests/interface_override/test.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 5 4 | 4 5 | 1 6 | 5 7 | 4 8 | 1 9 | 5 10 | 4 11 | 4 12 | -------------------------------------------------------------------------------- /tests/interface_override/test.result: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 1 4 | 1 5 | 4 6 | xxxxxxxxxxxxxxxx 7 | 5 8 | 5 9 | 5 10 | 4 11 | -------------------------------------------------------------------------------- /tests/interface_override/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | rm -f test.result 5 | $exe -cp . InterfaceImpl11 >> test.result 6 | $exe -cp . InterfaceImpl12 >> test.result 7 | $exe -cp . InterfaceImpl13 >> test.result 8 | $exe -cp . InterfaceImpl14 >> test.result 9 | $exe -cp . InterfaceImpl15 >> test.result 10 | diff test.result test.expect 2>&1 > /dev/null 11 | -------------------------------------------------------------------------------- /tests/load_store/DLoadStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/load_store/DLoadStore.class -------------------------------------------------------------------------------- /tests/load_store/FLoadStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/load_store/FLoadStore.class -------------------------------------------------------------------------------- /tests/load_store/ILoadStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/load_store/ILoadStore.class -------------------------------------------------------------------------------- /tests/load_store/LLoadStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/load_store/LLoadStore.class -------------------------------------------------------------------------------- /tests/load_store/dtest.expect: -------------------------------------------------------------------------------- 1 | 1.0 2 | 0.0 3 | 1.0 4 | 0.0 5 | -------------------------------------------------------------------------------- /tests/load_store/dtest.result: -------------------------------------------------------------------------------- 1 | 1.0 2 | 0.0 3 | 1.0 4 | 0.0 5 | -------------------------------------------------------------------------------- /tests/load_store/ftest.expect: -------------------------------------------------------------------------------- 1 | 0.0 2 | 1.0 3 | 0.0 4 | 1.0 5 | -------------------------------------------------------------------------------- /tests/load_store/ftest.result: -------------------------------------------------------------------------------- 1 | 0.0 2 | 1.0 3 | 0.0 4 | 1.0 5 | -------------------------------------------------------------------------------- /tests/load_store/itest.expect: -------------------------------------------------------------------------------- 1 | 4 2 | 3 3 | 2 4 | 1 5 | -------------------------------------------------------------------------------- /tests/load_store/itest.result: -------------------------------------------------------------------------------- 1 | 4 2 | 3 3 | 2 4 | 1 5 | -------------------------------------------------------------------------------- /tests/load_store/ltest.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 0 3 | 1 4 | 0 5 | -------------------------------------------------------------------------------- /tests/load_store/ltest.result: -------------------------------------------------------------------------------- 1 | 1 2 | 0 3 | 1 4 | 0 5 | -------------------------------------------------------------------------------- /tests/load_store/test.result: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/load_store/test.result -------------------------------------------------------------------------------- /tests/load_store/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe -cp . ILoadStore > itest.result 5 | diff itest.result itest.expect 2>&1 > /dev/null 6 | 7 | $exe -cp . LLoadStore > ltest.result 8 | diff ltest.result ltest.expect 2>&1 > /dev/null 9 | 10 | #$exe FLoadStore > ftest.result 11 | #diff ftest.result ftest.expect 2>&1 > /dev/null 12 | 13 | #$exe DLoadStore > dtest.result 14 | #diff dtest.result dtest.expect 2>&1 > /dev/null 15 | -------------------------------------------------------------------------------- /tests/math/Math.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/math/Math.class -------------------------------------------------------------------------------- /tests/math/test.expect: -------------------------------------------------------------------------------- 1 | 3 2 | 1 3 | 1.0 4 | 1.0 5 | 1 6 | 1 7 | 1.0 8 | 1.0 9 | 4 10 | 1 11 | 1.0 12 | 1.0 13 | 3 14 | 1 15 | 1.0 16 | 1.0 17 | 0 18 | 0 19 | 0.0 20 | 0.0 21 | -1 22 | 0 23 | -0.0 24 | -0.0 25 | 2 26 | 0 27 | 0 28 | 0 29 | 0 30 | 0 31 | 1 32 | 0 33 | 1 34 | 1 35 | 0 36 | 1 37 | 3 38 | -------------------------------------------------------------------------------- /tests/math/test.result: -------------------------------------------------------------------------------- 1 | 3 2 | 4294967296 3 | -------------------------------------------------------------------------------- /tests/math/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe Math > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/native_call/MyJVM.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/native_call/MyJVM.class -------------------------------------------------------------------------------- /tests/native_call/test.expect: -------------------------------------------------------------------------------- 1 | 52 2 | -------------------------------------------------------------------------------- /tests/native_call/test.result: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/native_call/test.result -------------------------------------------------------------------------------- /tests/native_call/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe MyJVM > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/npe/NullPointerExceptions.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/npe/NullPointerExceptions.class -------------------------------------------------------------------------------- /tests/npe/test.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/npe/test.expect -------------------------------------------------------------------------------- /tests/npe/test.result: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/npe/test.result -------------------------------------------------------------------------------- /tests/npe/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe -cp . NullPointerExceptions > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/object_field/ObjectField1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/object_field/ObjectField1.class -------------------------------------------------------------------------------- /tests/object_field/ObjectField2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/object_field/ObjectField2.class -------------------------------------------------------------------------------- /tests/object_field/test.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 5 3 | 1 4 | 1 5 | 4 6 | 3 7 | -------------------------------------------------------------------------------- /tests/object_field/test.result: -------------------------------------------------------------------------------- 1 | 1 2 | 5 3 | 1 4 | 1 5 | 4 6 | 3 7 | -------------------------------------------------------------------------------- /tests/object_field/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe -cp . ObjectField2 > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/object_init/ClassInitTest1.java: -------------------------------------------------------------------------------- 1 | public class ClassInitTest1 { 2 | static { 3 | System.out.println(1); 4 | } 5 | public static void main(String[] args) { 6 | System.out.println(2); 7 | } 8 | } 9 | class ClassInitTest2 extends ClassInitTest1{ 10 | static { 11 | System.out.println(2); 12 | } 13 | public static void main(String[] args) { 14 | System.out.println(3); 15 | } 16 | } 17 | class ClassInitTest3 extends ClassInitTest2 { 18 | static { 19 | System.out.println(3); 20 | } 21 | public static void main(String[] args) { 22 | System.out.println(4); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/object_init/ObjectInit1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/object_init/ObjectInit1.class -------------------------------------------------------------------------------- /tests/object_init/ObjectInit2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/object_init/ObjectInit2.class -------------------------------------------------------------------------------- /tests/object_init/ObjectInit3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/object_init/ObjectInit3.class -------------------------------------------------------------------------------- /tests/object_init/test.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | -------------------------------------------------------------------------------- /tests/object_init/test.result: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | -------------------------------------------------------------------------------- /tests/object_init/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe -cp . ObjectInit2 > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/object_override/Override.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/object_override/Override.class -------------------------------------------------------------------------------- /tests/object_override/Override1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/object_override/Override1.class -------------------------------------------------------------------------------- /tests/object_override/Override2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/object_override/Override2.class -------------------------------------------------------------------------------- /tests/object_override/Override3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/object_override/Override3.class -------------------------------------------------------------------------------- /tests/object_override/test.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 1 5 | 0 6 | 3 7 | 1 8 | 0 9 | 0 10 | -------------------------------------------------------------------------------- /tests/object_override/test.result: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 1 5 | 0 6 | 3 7 | 1 8 | 0 9 | 0 10 | -------------------------------------------------------------------------------- /tests/object_override/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe -cp . Override > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/primitive_array/PrimitiveArray.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/primitive_array/PrimitiveArray.class -------------------------------------------------------------------------------- /tests/primitive_array/test.expect: -------------------------------------------------------------------------------- 1 | true 2 |  3 | 1 4 | 1 5 | 1 6 | 1 7 | 1.0 8 | 1.0 9 | -------------------------------------------------------------------------------- /tests/primitive_array/test.result: -------------------------------------------------------------------------------- 1 | true 2 |  3 | 1 4 | 1 5 | 1 6 | 1 7 | -------------------------------------------------------------------------------- /tests/primitive_array/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe -cp . PrimitiveArray > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/static_call/Fibonacci.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/static_call/Fibonacci.class -------------------------------------------------------------------------------- /tests/static_call/test.expect: -------------------------------------------------------------------------------- 1 | 55 2 | -------------------------------------------------------------------------------- /tests/static_call/test.result: -------------------------------------------------------------------------------- 1 | 55 2 | -------------------------------------------------------------------------------- /tests/static_call/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe -cp . Fibonacci > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/static_field/StaticField.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/static_field/StaticField.class -------------------------------------------------------------------------------- /tests/static_field/test.expect: -------------------------------------------------------------------------------- 1 | false 2 | 3 | 0 4 | 0 5 | 0 6 | 0 7 | 0.0 8 | 0.0 9 | false 10 | 1 11 | 3 12 | 4 13 | 5 14 | 0 15 | 1.0 16 | 0.0 17 | -------------------------------------------------------------------------------- /tests/static_field/test.result: -------------------------------------------------------------------------------- 1 | false 2 | 3 | 0 4 | 0 5 | 0 6 | 0 7 | 0.0 8 | 0.0 9 | false 10 | 1 11 | 3 12 | 4 13 | 5 14 | 0 15 | -------------------------------------------------------------------------------- /tests/static_field/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe -cp . StaticField > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/string/Hello.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/string/Hello.class -------------------------------------------------------------------------------- /tests/string/Hello.java: -------------------------------------------------------------------------------- 1 | public class Hello { 2 | public static void main(String[] args) { 3 | for(String arg: args) { 4 | System.out.println(arg); 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/string/test.expect: -------------------------------------------------------------------------------- 1 | build 2 | jvm 3 | from 4 | scratch 5 | ! 6 | -------------------------------------------------------------------------------- /tests/string/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | exe=$1 4 | $exe Hello build jvm from scratch ! > test.result 5 | diff test.result test.expect 2>&1 > /dev/null 6 | -------------------------------------------------------------------------------- /tests/sum10/Sum10.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/sum10/Sum10.class -------------------------------------------------------------------------------- /tests/sum10/Sum10M.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guxingke/mini-jvm/cf4b7b992360466c6f3a551f13f7265b955d202d/tests/sum10/Sum10M.class -------------------------------------------------------------------------------- /tests/sum10/test.expect: -------------------------------------------------------------------------------- 1 | 55 2 | -------------------------------------------------------------------------------- /tests/sum10/test.result: -------------------------------------------------------------------------------- 1 | 55 2 | -------------------------------------------------------------------------------- /tests/sum10/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | exe=$1 5 | 6 | $exe -cp . Sum10M > test.result 7 | 8 | diff test.result test.expect 2>&1 > /dev/null 9 | --------------------------------------------------------------------------------