All Projects β†’ kelthuzadx β†’ Yvm

kelthuzadx / Yvm

Licence: mit
[yvm] low performance garbage-collectable jvm

Programming Languages

java
68154 projects - #9 most used programming language
cpp14
131 projects

Labels

Projects that are alternatives of or similar to Yvm

Kivm
🌟This is a pure C++ implementation of Java Virtual Machine (only Java 8 is supported). Inspired by Hotspot In Action.
Stars: ✭ 137 (-20.81%)
Mutual labels:  jvm
Play Scala Isolated Slick Example
Example Play Slick Project
Stars: ✭ 155 (-10.4%)
Mutual labels:  jvm
Clj Docker Client
An idiomatic, data-driven, REPL friendly Clojure Docker client
Stars: ✭ 162 (-6.36%)
Mutual labels:  jvm
Ore Infinium
Ore Infinium, Open Source multiplayer Terraria-inspired Sci-fi game, focused on technology, devices and researching. Written in Kotlin (JVM), LibGDX. Cross platform
Stars: ✭ 139 (-19.65%)
Mutual labels:  jvm
Nd4j
Fast, Scientific and Numerical Computing for the JVM (NDArrays)
Stars: ✭ 1,742 (+906.94%)
Mutual labels:  jvm
Dumpclass
Dump classes from running JVM process.
Stars: ✭ 156 (-9.83%)
Mutual labels:  jvm
Inspectit Ocelot
inspectIT Ocelot - Java agent for collecting application performance, tracing and behavior data
Stars: ✭ 135 (-21.97%)
Mutual labels:  jvm
Bouncy Gpg
Make using Bouncy Castle with OpenPGP fun again!
Stars: ✭ 164 (-5.2%)
Mutual labels:  jvm
Nudge4j
Get inside your JVM
Stars: ✭ 144 (-16.76%)
Mutual labels:  jvm
Webtau
Webtau (short for web test automation) is a testing API, command line tool and a framework to write unit, integration and end-to-end tests. Test across REST-API, Graph QL, Browser, Database, CLI and Business Logic with consistent set of matchers and concepts. REPL mode speeds-up tests development. Rich reporting cuts down investigation time.
Stars: ✭ 156 (-9.83%)
Mutual labels:  jvm
Chymyst Core
Declarative concurrency in Scala - The implementation of the chemical machine
Stars: ✭ 142 (-17.92%)
Mutual labels:  jvm
Xmlutil
XML Serialization library for Kotlin
Stars: ✭ 143 (-17.34%)
Mutual labels:  jvm
Playframework
Play Framework
Stars: ✭ 12,041 (+6860.12%)
Mutual labels:  jvm
Tyrian
Full-featured TypeScript on JVM
Stars: ✭ 138 (-20.23%)
Mutual labels:  jvm
Appbundle Maven Plugin
Maven plugin that creates an Application Bundle for OS X containing all your project dependencies and the necessary metadata
Stars: ✭ 163 (-5.78%)
Mutual labels:  jvm
Kotlinx Benchmark
Kotlin multiplatform benchmarking toolkit
Stars: ✭ 137 (-20.81%)
Mutual labels:  jvm
Fxgl
Stars: ✭ 2,378 (+1274.57%)
Mutual labels:  jvm
Node Jvm
java virtual machine in pure node.js
Stars: ✭ 2,053 (+1086.71%)
Mutual labels:  jvm
Play Java Starter Example
Play starter project in Java (ideal for new users!)
Stars: ✭ 164 (-5.2%)
Mutual labels:  jvm
Vert.x
Vert.x is a tool-kit for building reactive applications on the JVM
Stars: ✭ 12,544 (+7150.87%)
Mutual labels:  jvm

δΈ­ζ–‡ | English | Build Status | Codacy Badge | |

This is a homemade Java virtual machine written in c++, it supports most Java language features and includes a mark-sweep-based concurrent garbage collector. The main components of this VM are conforming to Java Virtual Machine Specification 8. It is runnable and various language features will add into this VM progressively. I don't have enough time to write a full coverage unit tests to ensure that all aspects of yvm work well, so if you find any bugs, you can open an Issue or fix up in place and pull request directly.

Available language features

Advanced language features will support later, you can also PR to contribute your awesome code.

Build and run

  • Prerequisite
    • Boost(>=1.65) Please set Boost root directory in CMakeLists.txt manually if automatic cmake detecting failed
    • C++14
    • gcc/msvc/mingw
  • Stereotype
$ cd yvm
$ cmake .
$ make -j4
$ make test
$ ./yvm --help
Usage:
  --help                List help documentations and usages.
  --runtime arg         Attach java runtime libraries where yvm would lookup 
                        classes at
  --run arg             Program which would be executed soon
You must specify the "runtime" flag to tell yvm where it could find jdk classes, and also program name is required.
$ ./yvm --runtime=C:\Users\Cthulhu\Desktop\yvm\bytecode ydk.test.QuickSort

Running snapshots

  • helloworld
  • quick sort
  • print stack trace when exception occurred
  • native multithreading
  • multithreading with synchronized(){}
  • Garbage Collection

Developing and hacking

1. From bytecode to an object

MethodArea used to handle a complete lifecycle of JavaClass, its APIs are self-explanatory:

class MethodArea {
public:
    // Pass runtime libraries paths to tell virutal machine searches 
    // where to lookup dependent classes
    MethodArea(const vector<string>& libPaths);
    ~MethodArea();

    // check whether it already exists or absents
    JavaClass* findJavaClass(const string& jcName);
    // load class which specified by jcName
    bool loadJavaClass(const string& jcName);
    // remove class which specified by jcName(Used for gc onlyοΌ‰
    bool removeJavaClass(const string& jcName);
    // link class which specified by jcName,initialize its fields
    void linkJavaClass(const string& jcName);
    // initialize class specified by jcName,call the static{} block
    void initJavaClass(Interpreter& exec, const string& jcName);

public:
    //auxiliary functions
    JavaClass* loadClassIfAbsent(const string& jcName);
    void linkClassIfAbsent(const string& jcName);
    void initClassIfAbsent(Interpreter& exec, const string& jcName);
}

For example, we have a bytecode file named Test.class,it would be available for jvm only if the following steps finished:

Test.class[in the disk]-> loadJavaClass("Test.class")[in memory] -> linkJavaClass("Test.class")->initJavaClass("Test.class")

Now we can create corresponding objects as soon as above steps accomplished:

// yrt is a global runtime variable,ma stands for MethodArea module,jheap stands for JavaHeap module
JavaClass* testClass = yrt.ma->findJavaClass("Test.class");
JObject* testInstance = yrt.jheap->createObject(*testClass);
2.1 Inside the object

jvm stack only holds basic numeric data and object/array reference, which we call the JObject/JArray, they have the following structure:

struct JObject {
    std::size_t offset = 0; 
    const JavaClass* jc{}; 
};

offset stands for an object,all operations of object in heap required this offset。jc references to the JavaClass。 Every object in heap constructed with <offset, fields> pair

[1]  ->  [field_a, field_b, field_c]
[2]  ->  []
[3]  ->  [field_a,field_b]
[4]  ->  [field_a]
[..] ->  [...]

If we get the object's offset, we can do anything of that indirectly.

Array is almost the same as object, it has a length field instead of jc since it's unnecessary for array to hold a meta class reference.

struct JArray {
    int length = 0;
    std::size_t offset = 0; 
};
[1]  ->   <3, [field_a, field_b, field_c]>
[2]  ->   <0, []>
[3]  ->   <2, [field_a,field_b]>
[4]  ->   <1, [field_a]>
[..] ->   <..,[...]>
2.2 From object creation to extinction

As above mentioned, a JObject holdsoffset and jc. MethodArea has responsible to manage JavaClass which referenced by jc, another offset field referenced to JObject, which in control of JavaHeap. JavaHeap provides a large number of self-explanatory APIs:

class JavaHeap {
public:
    // create and object/array
    JObject* createObject(const JavaClass& javaClass);
    JArray* createObjectArray(const JavaClass& jc, int length);

    // get/set field
    auto getFieldByName(const JavaClass* jc, const string& name,
                        const string& descriptor, JObject* object);
    void putFieldByName(const JavaClass* jc, const string& name,
                        const string& descriptor, JObject* object,
                        JType* value);
    // get/set specific element in the array
    void putElement(const JArray& array, size_t index, JType* value);
    auto getElement(const JArray& array, size_t index);
    
    // remove an array/object from heap
    void removeArray(size_t offset;
    void removeObject(size_t offset);
};

Back to the above example again, assume its corresponding Java class structure is as follows:

public class Test{
    public int k;
    private String hello;
}

In the first step, we've already got testClass, now we can do more things via it:

const JavaClass* testClass = yrt.ma->findJavaClass("Test.class");
JObject* testInstance = yrt.jheap->createObject(*testClass);
// get the field hello
JObject*  helloField = yrt.jheap->getFieldByName(testClass,"hello","Ljava/lang/String;",testInstance);
//set the field k
yrt.jheap->putFieldByName(testClass,"k","I",testInstance);
β… . About JDK

Any java virtual machines can not run a Java program without Java libraries. As you may know, some opcodes like ldc,monitorenter/monitorexit,athrow are internally requiring our virtual machine to operate JDK classes(java.lang.Class,java.lang.String,java.lang.Throwable,etc). Hence, I have to rewrite some JDK classes for building a runnable VM , because original JDK classes are so complicated that it's inconvenient for early developing. Rewrote JDK classes are as follows:

  • java.lang.String
  • java.lang.StringBuilder
  • java.lang.Throwable
  • java.lang.Math(::random())
  • java.lang.Runnable
  • java.lang.Thread
II. Structure of source code
[email protected]:~/yvm/src$ tree .
.
β”œβ”€β”€ classfile               
β”‚   β”œβ”€β”€ AccessFlag.h        # Access flag of class, method, field
β”‚   β”œβ”€β”€ ClassFile.h         # Corresponding structures for .class file
β”‚   └── FileReader.h        # Read .class file
β”œβ”€β”€ gc
β”‚   β”œβ”€β”€ Concurrent.cpp      # Concurrency utilities
β”‚   β”œβ”€β”€ Concurrent.hpp
β”‚   β”œβ”€β”€ GC.cpp              # Garbage collector
β”‚   └── GC.h
β”œβ”€β”€ interpreter
β”‚   β”œβ”€β”€ CallSite.cpp        # Call site to denote a concrete calling
β”‚   β”œβ”€β”€ CallSite.h
β”‚   β”œβ”€β”€ Internal.h          # Types that widely used within internal vm
β”‚   β”œβ”€β”€ Interpreter.cpp     # Interprete opcode
β”‚   β”œβ”€β”€ Interpreter.hpp
β”‚   β”œβ”€β”€ MethodResolve.cpp   # Resolve calling memthod
β”‚   └── MethodResolve.h
β”œβ”€β”€ misc
β”‚   β”œβ”€β”€ Debug.cpp            # Debuggin utilities
β”‚   β”œβ”€β”€ Debug.h
β”‚   β”œβ”€β”€ NativeMethod.cpp    # Implementations of java native methods
β”‚   β”œβ”€β”€ NativeMethod.h
β”‚   β”œβ”€β”€ Option.h            # VM arguments and options
β”‚   β”œβ”€β”€ Utils.cpp           # Tools and utilities
β”‚   └── Utils.h
β”œβ”€β”€ runtime
β”‚   β”œβ”€β”€ JavaClass.cpp       # Representation of java class
β”‚   β”œβ”€β”€ JavaClass.h
β”‚   β”œβ”€β”€ JavaException.cpp   # Exception handling
β”‚   β”œβ”€β”€ JavaException.h
β”‚   β”œβ”€β”€ JavaFrame.cpp       # Runtime frame
β”‚   β”œβ”€β”€ JavaFrame.hpp
β”‚   β”œβ”€β”€ JavaHeap.cpp        # Runtime heap, used to manage objects and arrays
β”‚   β”œβ”€β”€ JavaHeap.hpp
β”‚   β”œβ”€β”€ JavaType.h          # Java primitive types and reference type definitions
β”‚   β”œβ”€β”€ MethodArea.cpp      # Method area has responsible to manage JavaClass objects
β”‚   β”œβ”€β”€ MethodArea.h
β”‚   β”œβ”€β”€ ObjectMonitor.cpp   # synchronized syntax implementation
β”‚   β”œβ”€β”€ ObjectMonitor.h
β”‚   β”œβ”€β”€ RuntimeEnv.cpp      # Definitions of runtime structures
β”‚   └── RuntimeEnv.h
└── vm
    β”œβ”€β”€ Main.cpp             # Parse command line arguments
    β”œβ”€β”€ YVM.cpp              # Abstraction of virtual machine
    └── YVM.h

6 directories, 39 files

For more development documentations, see its Wiki or source code comments(recommend), which contains various contents with regard to its structures, usages, and design principles, etc.

License

Code licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].