├── img.png
├── img_1.png
├── img_2.png
├── img_3.png
├── img_4.png
├── img_5.png
├── img_6.png
├── img_7.png
├── .gitignore
├── src
└── main
│ └── java
│ └── com
│ └── cover
│ └── jvm
│ ├── jdk
│ └── classes
│ │ ├── java
│ │ └── lang
│ │ │ └── Class.java
│ │ ├── sun
│ │ ├── launcher
│ │ │ └── LauncherHelper.java
│ │ └── misc
│ │ │ ├── AppClassLoader.java
│ │ │ ├── Unsafe.java
│ │ │ └── ClassLoader.java
│ │ ├── Threads.java
│ │ ├── JniEnv.java
│ │ └── Handle.java
│ ├── hotspot
│ └── src
│ │ └── share
│ │ ├── vm
│ │ ├── oops
│ │ │ ├── Klass.java
│ │ │ ├── Annotation.java
│ │ │ ├── FieldInfo.java
│ │ │ ├── AttributeInfo.java
│ │ │ ├── InterfaceInfo.java
│ │ │ ├── RuntimeVisibleAnnotations.java
│ │ │ ├── RuntimeInvisibleAnnotations.java
│ │ │ ├── LineNumberTable.java
│ │ │ ├── LocalVariableTable.java
│ │ │ ├── InnerClasses.java
│ │ │ ├── BootstrapMethods.java
│ │ │ ├── CodeAttributeInfo.java
│ │ │ ├── MethodInfo.java
│ │ │ ├── DescriptorInfo.java
│ │ │ ├── ArrayOop.java
│ │ │ ├── InstanceKlass.java
│ │ │ └── ConstantPool.java
│ │ ├── runtime
│ │ │ ├── Thread.java
│ │ │ ├── VFrame.java
│ │ │ ├── JavaThread.java
│ │ │ ├── JavaVFrame.java
│ │ │ ├── Threads.java
│ │ │ ├── StackValue.java
│ │ │ └── StackValueCollection.java
│ │ ├── memory
│ │ │ ├── AllocateObj.java
│ │ │ ├── StackObj.java
│ │ │ ├── AllStatic.java
│ │ │ └── ResourceObj.java
│ │ ├── classfile
│ │ │ ├── StackMapTable.java
│ │ │ ├── BootClassLoader.java
│ │ │ ├── DescriptorStream.java
│ │ │ ├── DescriptorStream2.java
│ │ │ └── ClassFileParser.java
│ │ ├── utilities
│ │ │ ├── AccessFlags.java
│ │ │ └── BasicType.java
│ │ ├── interpreter
│ │ │ ├── BytecodeStream.java
│ │ │ ├── BaseBytecodeStream.java
│ │ │ ├── LambdaEngine.java
│ │ │ └── Bytecodes.java
│ │ └── prims
│ │ │ └── JavaNativeInterface.java
│ │ └── tools
│ │ ├── Stream.java
│ │ └── DataTranslate.java
│ ├── example
│ └── java
│ │ └── lang
│ │ ├── lambda
│ │ ├── CustomLambda.java
│ │ ├── CustomLambda1.java
│ │ ├── CustomLambda2.java
│ │ ├── CustomLambdaParams.java
│ │ └── TestLambda.java
│ │ ├── operation
│ │ ├── BitCount.java
│ │ ├── InstanceOf.java
│ │ ├── Else.java
│ │ ├── SubSub.java
│ │ ├── Div.java
│ │ ├── Mul.java
│ │ ├── Rem.java
│ │ ├── Sub.java
│ │ ├── Add.java
│ │ └── AddAdd.java
│ │ ├── HelloWorld.java
│ │ ├── compare
│ │ └── Integer.java
│ │ ├── array
│ │ └── Array.java
│ │ └── condition
│ │ ├── IfNull.java
│ │ ├── IfOther.java
│ │ └── IfInt.java
│ └── Main.java
├── .idea
├── vcs.xml
├── encodings.xml
├── .gitignore
├── compiler.xml
├── jarRepositories.xml
└── uiDesigner.xml
├── pom.xml
└── README.md
/img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2over/XVM/HEAD/img.png
--------------------------------------------------------------------------------
/img_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2over/XVM/HEAD/img_1.png
--------------------------------------------------------------------------------
/img_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2over/XVM/HEAD/img_2.png
--------------------------------------------------------------------------------
/img_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2over/XVM/HEAD/img_3.png
--------------------------------------------------------------------------------
/img_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2over/XVM/HEAD/img_4.png
--------------------------------------------------------------------------------
/img_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2over/XVM/HEAD/img_5.png
--------------------------------------------------------------------------------
/img_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2over/XVM/HEAD/img_6.png
--------------------------------------------------------------------------------
/img_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/2over/XVM/HEAD/img_7.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | target/
3 | target/classes/com/jvm/Main.class
4 | *.iml
5 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/jdk/classes/java/lang/Class.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.jdk.classes.java.lang;
2 |
3 | public class Class {
4 | }
5 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/Klass.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | public class Klass {
4 | }
5 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/runtime/Thread.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.runtime;
2 |
3 | public class Thread {
4 | }
5 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/runtime/VFrame.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.runtime;
2 |
3 | public class VFrame {
4 | }
5 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/memory/AllocateObj.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.memory;
2 |
3 | public class AllocateObj {
4 | }
5 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/memory/StackObj.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.memory;
2 |
3 | public class StackObj extends AllocateObj{
4 | }
5 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/memory/AllStatic.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.memory;
2 |
3 | public class AllStatic extends AllocateObj {
4 | }
5 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/memory/ResourceObj.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.memory;
2 |
3 | public class ResourceObj extends AllocateObj{
4 | }
5 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/jdk/classes/sun/launcher/LauncherHelper.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.jdk.classes.sun.launcher;
2 |
3 | public class LauncherHelper {
4 | // test
5 | }
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/lambda/CustomLambda.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.lambda;
2 |
3 |
4 | @FunctionalInterface
5 | public interface CustomLambda {
6 | void run();
7 | }
8 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/lambda/CustomLambda1.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.lambda;
2 |
3 |
4 | @FunctionalInterface
5 | public interface CustomLambda1 {
6 | public void run(int x);
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/lambda/CustomLambda2.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.lambda;
2 |
3 |
4 | @FunctionalInterface
5 | public interface CustomLambda2 {
6 | public void run(int x, int y);
7 | }
8 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 | /compiler.xml
10 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/lambda/CustomLambdaParams.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.lambda;
2 |
3 |
4 | @FunctionalInterface
5 | public interface CustomLambdaParams {
6 |
7 | public void run(int x, int y);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/jdk/classes/sun/misc/AppClassLoader.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.jdk.classes.sun.misc;
2 |
3 | import com.cover.jvm.jdk.classes.Handle;
4 |
5 | public class AppClassLoader {
6 | public native static Handle loadKlass(String name);
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/runtime/JavaThread.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.runtime;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Stack;
6 |
7 | @Data
8 | public class JavaThread extends Thread{
9 |
10 | private Stack stack = new Stack<>();
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/Annotation.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class Annotation {
7 |
8 | private int typeIndex;
9 |
10 | private int elementsNum;
11 |
12 | private String typeStr;
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/jdk/classes/sun/misc/Unsafe.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.jdk.classes.sun.misc;
2 |
3 | public class Unsafe {
4 |
5 | public static native long allocateMemory(long bytes);
6 |
7 | public static native long allocateObject();
8 |
9 | public static native void initMemoryModel();
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/operation/BitCount.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.operation;
2 |
3 |
4 | public class BitCount {
5 |
6 | public static void main(String[] args) {
7 | int v1 = 0x11;
8 | int v2 = 0xff;
9 |
10 | System.out.println(v1 & v2);
11 | }
12 |
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/operation/InstanceOf.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.operation;
2 |
3 |
4 | public class InstanceOf {
5 |
6 | public static void main(String[] args) {
7 | InstanceOf obj = new InstanceOf();
8 |
9 | System.out.println(obj instanceof InstanceOf);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/operation/Else.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.operation;
2 |
3 |
4 | public class Else {
5 |
6 | public static void main(String[] args) {
7 | int v1 = 10;
8 | int v2 = 20;
9 | int v3 = 30;
10 |
11 | System.out.println((v1 + v2) * v3);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/classfile/StackMapTable.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.classfile;
2 |
3 | import com.cover.jvm.hotspot.src.share.vm.oops.AttributeInfo;
4 | import lombok.Data;
5 |
6 | @Data
7 | public class StackMapTable extends AttributeInfo {
8 |
9 | private int attrNameIndex;
10 |
11 | private int attrLength;
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/jdk/classes/Threads.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.jdk.classes;
2 |
3 | import java.util.HashMap;
4 |
5 | public class Threads {
6 |
7 | private static HashMap container = new HashMap<>();
8 |
9 | public native static void createVM();
10 |
11 | public native static void gc();
12 |
13 | public native static void fullGc();
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/FieldInfo.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class FieldInfo {
7 |
8 | private int accessFlags;
9 |
10 | private int nameIndex;
11 |
12 | private int descriptorIndex;
13 |
14 | private int attributesCount;
15 |
16 | private CodeAttributeInfo[] attributes;
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/utilities/AccessFlags.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.utilities;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class AccessFlags {
7 |
8 | private int flag;
9 |
10 | public AccessFlags(int flag) {
11 | this.flag = flag;
12 | }
13 |
14 | public boolean isStatic() {
15 | return (flag & BasicType.JVM_ACC_STATIC) != 0;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/AttributeInfo.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class AttributeInfo {
7 |
8 | private int attrNameIndex;
9 |
10 | private int attrLength;
11 |
12 | // 用于存储klass的attribute
13 | private byte[] container;
14 |
15 | public void initContainer() {
16 | container = new byte[attrLength];
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/InterfaceInfo.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class InterfaceInfo {
7 | private int constantPoolIndex;
8 |
9 | private String interfaceName;
10 |
11 | public InterfaceInfo(int index, String name) {
12 | this.constantPoolIndex = index;
13 |
14 | this.interfaceName = name;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/RuntimeVisibleAnnotations.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | @Data
9 | public class RuntimeVisibleAnnotations extends AttributeInfo {
10 |
11 | private int annotationsNum;
12 |
13 | private List annotations = new ArrayList<>();
14 |
15 | private String attrName;
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/RuntimeInvisibleAnnotations.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | @Data
9 | public class RuntimeInvisibleAnnotations extends AttributeInfo {
10 |
11 | private int annotationsNum;
12 |
13 | private List annotations = new ArrayList<>();
14 |
15 | private String attrName;
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/jdk/classes/sun/misc/ClassLoader.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.jdk.classes.sun.misc;
2 |
3 | import cn.hutool.core.io.FileUtil;
4 | import cn.hutool.core.lang.Assert;
5 |
6 | import java.io.File;
7 |
8 | public class ClassLoader {
9 |
10 | public byte[] readFile(String filepath) {
11 | Assert.isNull(filepath);
12 |
13 | File file = new File(filepath);
14 |
15 | return FileUtil.readBytes(file);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/HelloWorld.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang;
2 |
3 | public class HelloWorld {
4 |
5 | private static final int a = 1;
6 |
7 | private static final int b = 2;
8 | public static void main(String[] args) {
9 | System.out.println("Hello Wolrd!");
10 |
11 | System.out.println(add(a, b));
12 | }
13 |
14 | public static int add(int a, int b) {
15 | return a + b;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/operation/SubSub.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.operation;
2 |
3 |
4 | public class SubSub {
5 |
6 | public static void main(String[] args) {
7 | test1();
8 | test2();
9 | }
10 |
11 | public static void test1() {
12 | int v = 1;
13 | System.out.println(v--);
14 | }
15 |
16 | public static void test2() {
17 | int v = 1;
18 | System.out.println(--v);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/lambda/TestLambda.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.lambda;
2 |
3 |
4 | public class TestLambda {
5 |
6 | public static void main(String[] args) {
7 | CustomLambda2 obj = (x, y) -> {
8 | System.out.println("hello#" + x + "#" + y);
9 | };
10 |
11 | obj.run(1, 2);
12 |
13 | //====
14 | CustomLambda1 obj1 = (x) -> {
15 | System.out.println("hello#" + x);
16 | };
17 |
18 | obj1.run(1);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/LineNumberTable.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class LineNumberTable extends AttributeInfo{
7 |
8 | private int tableLength;
9 |
10 | private Item[] table;
11 |
12 | public void initTable() {
13 | table = new Item[tableLength];
14 | }
15 |
16 | @Data
17 | public class Item {
18 | private int startPc;
19 |
20 | private int lineNumber;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/jdk/classes/JniEnv.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.jdk.classes;
2 |
3 |
4 | /**
5 | * 生成java 头文件
6 | * 1. 进入到该目录 /home/ziya/IdeaProjects/XVM/src/main/java
7 | * 2.javac com/cover/jvm/jdk/classes/Handle.java
8 | * 3.javac -h /home/ziya/IdeaProjects/XVM/jni com/cover/jvm/jdk/classes/JniEnv.java
9 | *
10 | */
11 | public class JniEnv {
12 |
13 | public native static Handle getMethodID(Handle klass, String name, String descriptorName);
14 |
15 | public native static void CallStaticVoidMethod(Handle klass, Handle method);
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/interpreter/BytecodeStream.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.interpreter;
2 |
3 | import com.cover.jvm.hotspot.src.share.vm.oops.CodeAttributeInfo;
4 | import com.cover.jvm.hotspot.src.share.vm.oops.MethodInfo;
5 |
6 | public class BytecodeStream extends BaseBytecodeStream{
7 |
8 | public BytecodeStream(MethodInfo belongMethod, CodeAttributeInfo belongCode) {
9 | this.belongMethod = belongMethod;
10 | this.belongCode = belongCode;
11 | this.length = belongCode.getCodeLength();
12 | this.index = 0;
13 | this.codes = new byte[this.length];
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/compare/Integer.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.compare;
2 |
3 |
4 | public class Integer {
5 |
6 | public static void main(String[] args) {
7 | testLong();
8 | }
9 |
10 | public static void test1() {
11 | byte v1 = 10;
12 | byte v2 = 20;
13 |
14 | System.out.println(v1 == v2);
15 | }
16 |
17 | public static void testLong() {
18 | long v1 = 10;
19 | long v2 = 20;
20 |
21 | System.out.println(v1 != v2);
22 | }
23 |
24 | public static void test() {
25 | Object obj = null;
26 |
27 | System.out.println(obj == null);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/LocalVariableTable.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class LocalVariableTable extends AttributeInfo{
7 |
8 | private int tableLength;
9 |
10 | private Item[] table;
11 |
12 | public void initTable() {
13 | table = new Item[tableLength];
14 | }
15 |
16 | @Data
17 | public class Item {
18 | private int startPc;
19 |
20 | private int length;
21 |
22 | private int nameIndex;
23 |
24 | private int descriptorIndex;
25 |
26 | private int index;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/array/Array.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.array;
2 |
3 |
4 | public class Array {
5 |
6 | public static void main(String[] args) {
7 | int[] arr;
8 | }
9 |
10 | public static void test1() {
11 | int[] arr = new int[3];
12 |
13 | arr[0] = 10;
14 |
15 | System.out.println(arr[0]);
16 | }
17 |
18 | public static void test2() {
19 | int[] arr = {1, 2, 3};
20 |
21 | System.out.println(arr[0]);
22 | }
23 |
24 | public static void test3() {
25 | Object[] objects = new Object[3];
26 |
27 | objects[0] = new Array();
28 |
29 | System.out.println(objects[0]);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/condition/IfNull.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.condition;
2 |
3 |
4 | public class IfNull {
5 |
6 | public static void main(String[] args) {
7 | ifNonNull();
8 | }
9 |
10 | public static void ifNull() {
11 | Object obj = null;
12 |
13 | if (null == obj) {
14 | System.out.println("null");
15 | } else {
16 | System.out.println("not null");
17 | }
18 | }
19 |
20 | public static void ifNonNull() {
21 | Object obj = null;
22 |
23 | if (null != obj) {
24 | System.out.println("null");
25 | } else {
26 | System.out.println("not null");
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/runtime/JavaVFrame.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.runtime;
2 |
3 | import com.cover.jvm.hotspot.src.share.vm.oops.MethodInfo;
4 | import lombok.Data;
5 |
6 | @Data
7 | public class JavaVFrame extends VFrame {
8 |
9 | private StackValueCollection locals;
10 |
11 | private StackValueCollection stack = new StackValueCollection();
12 |
13 | private MethodInfo ownerMethod;
14 |
15 | public JavaVFrame(int maxLocals) {
16 | locals = new StackValueCollection(maxLocals);
17 | }
18 |
19 | public JavaVFrame(int maxLocals, MethodInfo methodInfo) {
20 | locals = new StackValueCollection(maxLocals);
21 | ownerMethod = methodInfo;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/InnerClasses.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import com.cover.jvm.hotspot.src.share.vm.utilities.AccessFlags;
4 | import lombok.Data;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | @Data
10 | public class InnerClasses extends AttributeInfo {
11 |
12 | private String attrName;
13 |
14 | private int numOfClasses;
15 |
16 | private List- classes = new ArrayList<>();
17 |
18 |
19 | @Data
20 | public class Item {
21 | private int interClassInfoIndex;
22 |
23 | private int outerClassInfoIndex;
24 |
25 | private int innerNameIndex;
26 |
27 | private AccessFlags accessFlags;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/BootstrapMethods.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | @Data
9 | public class BootstrapMethods extends AttributeInfo{
10 |
11 | private String attrName;
12 |
13 | private int numBootstrapMethods;
14 |
15 | private List
- bootstrapMethods = new ArrayList<>();
16 |
17 | @Data
18 | public class Item {
19 | private int bootstrapMethodRef;
20 |
21 | private int numBootstrapArguments;
22 |
23 | private int[] bootstrapArguments;
24 |
25 | public void initContainer() {
26 | bootstrapArguments = new int[numBootstrapArguments];
27 | }
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/jdk/classes/Handle.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.jdk.classes;
2 |
3 | public final class Handle {
4 |
5 | //oop/klass memory address
6 | private long p;
7 |
8 | /**
9 | * 1.klass
10 | * 2.oop
11 | * 3.method
12 | */
13 | private int type;
14 |
15 | // 对应的Java类的全限定名
16 | private String className;
17 |
18 | public long getP() {
19 | return p;
20 | }
21 |
22 | public void setP(long p) {
23 | this.p = p;
24 | }
25 |
26 | public int getType() {
27 | return type;
28 | }
29 |
30 | public void setType(int type) {
31 | this.type = type;
32 | }
33 |
34 | public String getClassName() {
35 | return className;
36 | }
37 |
38 | public void setClassName(String className) {
39 | this.className = className;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/CodeAttributeInfo.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import com.cover.jvm.hotspot.src.share.vm.interpreter.BytecodeStream;
4 | import lombok.Data;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | @Data
10 | public class CodeAttributeInfo {
11 | private int attrNameIndex;
12 |
13 | private int attrLength;
14 |
15 | private int maxStack;
16 |
17 | private int maxLocals;
18 |
19 | private int codeLength;
20 |
21 | private BytecodeStream code;
22 |
23 | private int exceptionTableLength;
24 |
25 | // 如局部变量、操作数栈
26 | private int attributesCount;
27 |
28 | private Map attributes = new HashMap<>();
29 |
30 | @Override
31 | public String toString() {
32 | return "CodeAttributeInfo{ }";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/operation/Div.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.operation;
2 |
3 |
4 | public class Div {
5 |
6 | public static void main(String[] args) {
7 | divInt();
8 | divFloat();
9 | divLong();
10 | divDouble();
11 | }
12 |
13 | public static void divInt() {
14 | int a = 4;
15 | int b = 2;
16 |
17 | System.out.println(a / b);
18 | }
19 |
20 | public static void divFloat() {
21 | float a = 4;
22 | float b = 2;
23 |
24 | System.out.println(a / b);
25 | }
26 |
27 | public static void divLong() {
28 | long a = 4;
29 | long b = 2;
30 |
31 | System.out.println(a / b);
32 | }
33 |
34 | public static void divDouble() {
35 | double a = 4;
36 | double b = 2;
37 |
38 | System.out.println(a / b);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/operation/Mul.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.operation;
2 |
3 |
4 | public class Mul {
5 |
6 | public static void main(String[] args) {
7 | mulInt();
8 | mulFloat();
9 | mulLong();
10 | mulDouble();
11 | }
12 |
13 | public static void mulInt() {
14 | int a = 1;
15 | int b = 2;
16 |
17 | System.out.println(a * b);
18 | }
19 |
20 | public static void mulFloat() {
21 | float a = 1;
22 | float b = 2;
23 |
24 | System.out.println(a * b);
25 | }
26 |
27 | public static void mulLong() {
28 | long a = 1;
29 | long b = 2;
30 |
31 | System.out.println(a * b);
32 | }
33 |
34 | public static void mulDouble() {
35 | double a = 1;
36 | double b = 2;
37 |
38 | System.out.println(a * b);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/operation/Rem.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.operation;
2 |
3 |
4 | public class Rem {
5 |
6 | public static void main(String[] args) {
7 | remInt();
8 | remFloat();
9 | remLong();
10 | remDouble();
11 | }
12 |
13 | public static void remInt() {
14 | int a = 1;
15 | int b = 2;
16 |
17 | System.out.println(a % b);
18 | }
19 |
20 | public static void remFloat() {
21 | float a = 1;
22 | float b = 2;
23 |
24 | System.out.println(a % b);
25 | }
26 |
27 | public static void remLong() {
28 | long a = 1;
29 | long b = 2;
30 |
31 | System.out.println(a % b);
32 | }
33 |
34 | public static void remDouble() {
35 | double a = 1;
36 | double b = 2;
37 |
38 | System.out.println(a % b);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/operation/Sub.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.operation;
2 |
3 |
4 | public class Sub {
5 |
6 | public static void main(String[] args) {
7 | subInt();
8 | subFloat();
9 | subLong();
10 | subDouble();
11 | }
12 |
13 | public static void subInt() {
14 | int a = 1;
15 | int b = 2;
16 |
17 | System.out.println(a - b);
18 | }
19 |
20 | public static void subFloat() {
21 | float a = 1;
22 | float b = 2;
23 |
24 | System.out.println(a - b);
25 | }
26 |
27 | public static void subLong() {
28 | long a = 1;
29 | long b = 2;
30 |
31 | System.out.println(a - b);
32 | }
33 |
34 | public static void subDouble() {
35 | double a = 1;
36 | double b = 2;
37 |
38 | System.out.println(a - b);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/runtime/Threads.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.runtime;
2 |
3 | import com.cover.jvm.hotspot.src.share.vm.memory.AllStatic;
4 | import lombok.Data;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | @Data
10 | public class Threads extends AllStatic {
11 |
12 |
13 | /**
14 | * 所有的Java线程基本全部存储在这个list中
15 | */
16 | private static List threadList;
17 |
18 | private static Thread currentThread;
19 |
20 | static {
21 | threadList = new ArrayList<>();
22 | }
23 |
24 | public static List getThreadList() {
25 | return threadList;
26 | }
27 |
28 | public static JavaThread currentThread() {
29 | return (JavaThread) currentThread;
30 | }
31 |
32 | public static void setCurrentThread(Thread thread) {
33 | currentThread = thread;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/MethodInfo.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import com.cover.jvm.hotspot.src.share.vm.classfile.DescriptorStream2;
4 | import com.cover.jvm.hotspot.src.share.vm.utilities.AccessFlags;
5 | import lombok.Data;
6 |
7 | @Data
8 | public class MethodInfo {
9 |
10 | private InstanceKlass belongKlass;
11 |
12 | private AccessFlags accessFlags;
13 |
14 | private int nameIndex;
15 |
16 | private int descriptorIndex;
17 |
18 | private int attributesCount;
19 |
20 | private CodeAttributeInfo[] attributes;
21 |
22 | private String methodName;
23 |
24 | private DescriptorStream2 descriptor;
25 |
26 | public void initAttributeContainer() {
27 | attributes = new CodeAttributeInfo[attributesCount];
28 | }
29 |
30 | @Override
31 | public String toString() {
32 | return "MethodInfo{ }";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/DescriptorInfo.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class DescriptorInfo {
7 |
8 | /**
9 | * 是否完成解析并赋值
10 | * 默认false
11 | */
12 | private boolean isResolved = false;
13 |
14 | // 类型
15 | private int type;
16 |
17 | // 数组维度
18 | private int arrayDimension;
19 |
20 | // 类型
21 | private String typeDesc;
22 |
23 | public void incArrayDimension() {
24 | arrayDimension++;
25 | }
26 |
27 | public DescriptorInfo() {
28 |
29 | }
30 |
31 | public DescriptorInfo(boolean isResolved, int type) {
32 | this.isResolved = isResolved;
33 | this.type = type;
34 | }
35 |
36 | public DescriptorInfo(boolean isResolved, int type, String typeDesc) {
37 | this.isResolved = isResolved;
38 | this.type = type;
39 | this.typeDesc = typeDesc;
40 | }
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/example/java/lang/condition/IfOther.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.example.java.lang.condition;
2 |
3 |
4 | public class IfOther {
5 |
6 | public static void main(String[] args) {
7 | IntVSFloat();
8 | }
9 |
10 | public static void floatCompare() {
11 | float f = 10;
12 |
13 | if (10 == f) {
14 | System.out.println("相等");
15 | } else {
16 | System.out.println("不相等");
17 | }
18 |
19 | if (f == 10) {
20 | System.out.println("相等");
21 | } else {
22 | System.out.println("不相等");
23 | }
24 |
25 | if (f > 10) {
26 | System.out.println("大于10");
27 | } else {
28 | System.out.println("不大于10");
29 | }
30 | }
31 |
32 | public static void IntVSFloat() {
33 | int i = 10;
34 | float f = 10;
35 |
36 | if (i == f) {
37 | System.out.println("相等");
38 | } else {
39 | System.out.println("不相等");
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/cover/jvm/hotspot/src/share/vm/oops/ArrayOop.java:
--------------------------------------------------------------------------------
1 | package com.cover.jvm.hotspot.src.share.vm.oops;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | @Data
9 | public class ArrayOop {
10 |
11 | /**
12 | * 数组类型
13 | */
14 | private int type;
15 |
16 | /**
17 | * 如果是引用类型数组,数组元素对应的类型
18 | */
19 | private String className;
20 |
21 | /**
22 | * 数组大小
23 | */
24 | private int size;
25 |
26 | private List