Giter VIP home page Giter VIP logo

mini-jvm's Introduction

CircleCIGitHubGitHub commit activityGitHub last commit

使用 Java 8 实现 JVM

动机

  1. 尝试了解 JVM 原理, Learning by doing
  2. 纸上得来终觉浅, 实践
  3. 用简单的代码帮助 Javaer 理解 JVM

快速体验 [Macos 用户]

Hello world

brew tap guxingke/repo && brew install mini-jvm

cat <<EOF > HelloWorld.java
public class HelloWorld {
  public static void main(String[] args) {
    if (args.length == 0) {
      System.out.println("hello");
      return;
    }

    for(int i = 0; i < args.length; i ++) {
      System.out.println(args[i]);
    }
  }
}
EOF

javac HelloWorld.java

# no args
mini-jvm HelloWold
# => hello

# with program args
mini-jvm HelloWold hello mini-jvm
# =>  hello
# =>  mini-jvm

# 输入 mini-jvm -help 了解更多.

彩蛋 1 , 理解 JVM 基于栈的解释器.

cat <<EOF > Sum10.java
public class Sum10 {
  public static void main(String[] args) {
    int sum = sum10();
    System.out.println(sum);
  }
  
  public static int sum10() {
    int sum = 0;
    for (int i = 1; i <= 10; i++) {
      sum += i;
    }
    return sum;
  }
}
EOF

javac Sum10.java
java Sum10
# => 55

# 生成类汇编语言
# mini-jvm --bc [classfile] [method]
mini-jvm --bc Sum10.class sum10 > sum10.bc

# 解释上一步生成的 sum10.bc
# mini-jvm -- [bytecode file]
mini-jvm -- sum10.bc
# => 55

# ================================

快速体验 [其他操作系统]

需要自行下载打包. Dev

规划

  • Class 文件解析 90%
  • 字节码执行 90%
  • 类加载 90%
  • 方法调用 90%
  • 实例化 90%
  • native 方法 70%
  • 异常处理 0%
  • 多线程 0%
  • self-booting 10%

局限

  1. 不实现 GC

变更记录

  • 支持 Lambda 调用, closure, currying 可用.
  • Hello World 级别可用

参考

mini-jvm's People

Contributors

deepbreath avatar guxingke avatar hesherya avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.