├── .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) [](https://gitter.im/guxingke/mini-jvm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
2 | 
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 |
13 |
14 | 
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