Coder Social home page Coder Social logo

digitalgust / minijvm Goto Github PK

View Code? Open in Web Editor NEW
322.0 19.0 91.0 60.52 MB

Develop iOS Android app in java, Cross platform java virtual machine , the minimal jvm .

License: MIT License

CMake 0.04% C 99.21% Swift 0.02% Objective-C 0.66% Batchfile 0.03% Shell 0.03% HTML 0.02%
minijvm cross-platform android ios java jvm java-virtual-machine awtk-minijvm janino-compiler opengl

minijvm's Introduction


miniJVM

Develop iOS Android app in java, Cross platform java virtual machine , the minimal jvm .

Features
Architecture
Build for iOS/Android platform
Build for Windows/Linux/MacOS platform
How to debug source
Using miniJVM in project
Documentation
License

Features

  • Jvm Build pass: iOS / Android / mingw-w64 32|64bit / MSVC 32|64bit / MacOS / Linux
  • No dependence Library
  • Minimal memory footprint
  • Minimal binary, embedded jvm
  • Minimal bootstrap classlib , So the classes is NOT FULL of jdk 1.8
  • Support java source compiler(janino compiler)
  • Jit support
  • Low latency java garbage collection
  • Java remote debug supported, JDWP Spec
  • Translate minijvm classes to C source code to improve execute speed.

iOS/Android Platform Extended Features

  • OpenGL ES 3.0
  • Swing like gui lib, HTML like XML layout
  • Audio/Video Playback and Capture
  • Take photo from Camera or Album
  • Save and Load file from mobile device
  • Api compatible with miniJVM desktop platform, app can running on desktop platform

MiniJVM on Web

MiniJVM on web build by Starcommander. Source Web demo

MiniJVM gui Demo

  • Instant Message app Demo , Source
  • 3D game app Demo, Source

Architecture:

Changelog:

2023.09. Rebound the glfw and glfm graphics jni and separated the GUI java class into the xgui package .
2022.11. Add documentation.
2021.03. Add j2c module, it 's a tool for convert minijvm java source code to c source code , then build it as native application , support desktop and mobile platform .
2020.12. Add build script and release v2.1.
2020.10. Refactor source and remove binary in repository.
2020.10. Https supported.
2020.03. Add xml layout for gui system, add 3D game demo for minijvm, fix jdwp debug for jetbrain idea.
2019.12. Bind cross-platform awtk ui system , see awtk-minijvm
2019.12. Jit enabled, it based on sljit project
2019.10. Jit is developing
2018.12. Optimize performance
2017.09. miniJVM start

Build for iOS/Android platform:

Write java code once , running on all of iOS / Android / MacOSX / Win / Linux platforms
There were not essential jar file pre-built, so build these jar file first
Develop IDE: Eclipse, Netbeans or JetBrains Intelli Idea

  1. Run script /binary/build_jar.sh or /binary/build_jar.bat to generted jars.
    Or

    Build maven projects /minijvm/java copy to /mobile/assets/resfiles/minijvm_rt.jar
    Build maven projects /mobile/java/glfm_gui, copy to /mobile/assets/resfiles/glfm_gui.jar
    Build maven projects /mobile/java/ExApp, copy to /mobile/assets/resfiles/ExApp.jar
    Maybe you can change /mobile/java/ExApp/src/main/java/test/MyApp.java , Add your resource to /mobile/java/ExApp/src/main/resource/res/ , such as audio or image etc, Configure /mobile/java/ExApp/src/main/config.txt for icon ,version, boot class, etc

  2. XCode open /mobile/iosapp ,setup developer account in Signing&Capabilities , build and install app to Device , verify app before running app (Setting->General->Device Management->{Developer account}->Verify App->Trust)

  3. Android Studio open /mobile/androidapp build and install app to Android device

  4. The AppManager is running

Build for Windows/Linux/MacOS platform

  1. Run script /binary/build_jar.sh or /binary/build_jar.bat to generted jars
    Or

    Build java bootstrap classes /minijvm/java , Maven build jar and copy to /binary/lib/minijvm_rt.jar
    Build gui classes /desktop/glfw_gui/java , Maven build jar and copy to /binary/libex/glfw_gui.jar
    Build console test case classes /test/minijvm_test , Maven build jar and copy to /binary/libex/minijvm_test.jar
    Build gui test app classes /mobile/java/ExApp , Maven built jar and copy to /binary/{platform}/apps/ExApp.jar

  2. Run /binary/build_mac_linux.sh or /binary/build_wini686.bat or /binary/build_winx64.bat to generted binaries
    Or

    Build gui jni c dynamic library /desktop/glfw_gui/c by cmake
    Build minijvm /minijvm/c by cmake

  3. Run test script /binary/{platform}/test.sh | test.bat

How to debug source

Almost all Java IDEs support remote debugging. The IDE connects to the debug port of the miniJVM through TCP, and then enters the debugging state. The miniJVM has two options, one is to enable the debugging function, and the other is to wait for the IDE to connect to the debug port after the VM is started, and execute the bytecode only after that. These two options need to be setup before initializing the VM.
These two options defined in jvm.h

struct _MiniJVM {
    ...
    s32 jdwp_enable;// 0:disable java debug , 1:enable java debug and disable jit
    s32 jdwp_suspend_on_start;
    ...
};
  1. Open miniJVM debug mode, mini_jvm jdwp listen on port 8000
    Desktop platform : Run mini_jvm with flag: -Xdebug for debug mode ,Or change source before build.
    /minijvm/c/main.c 134: jvm->jdwp_enable = 1; //change "jdwp" to 1
    iOS/Android : change source before build
    /mobile/c/glfmapp/main.c 50: refers.jvm->jdwp_enable = 1; //change 0 to 1
    If debug on phone device, check the device ip address from General Setting -> wifi ->(i)

  2. Run the VM with jars eg:
    mini_jvm.exe -Xdebug -bootclasspath ../lib/minijvm_rt.jar -cp ../libex/glfw_gui.jar org.mini.glfw.GlfwMain

  3. IDE open project , eg: /mobile/java/ExApp
    Intelli idea : menu Run -> Edit Configurations , + remote , Transport : socket , Debugger mode : attach , host is your mini_jvm running on host ip and port ,ex "127.0.0.1:8000" or "192.168.0.32:8000"
    Eclipse : configuration like as idea
    Netbeans : menu Debug -> connect to Debugger, Connector : SocketAttach , host is your mini_jvm running on the host and port, ex. "localhost:8000" , Timeout: 10000

  4. Then you can set breakpoints and pause vm and watch variables

Project based miniJVM

Awtk-minijvm :AWTK cross platform native ui bind to minijvm
LWJGUI-Mobile : java LWJGL UI library
BiBiX : java instantial messager
G3d : java 3d game demo
MiniJVM web demo : miniJVM on web demo

miniJVM referenced project and technology

Oracle CLDC :referenced cldc api
OpenJDK : referenced java api
Miniz :for read jar files
Glfm :for cross platform (android/ios) GUI
Nanovg :for GUI paint function
Stb :for GUI truetype font and image
Glad :for replace openGL/GLES head file
Glfw :for pc cross platform GUI
Dirent :for linux style on win vc file and directory access
Tinycthread :for cross platform thread
JRegex :for java String regex match
Janino :for compile java source file
MiniAudio :for java audio playback and capture
Sljit :Platform independent low-level JIT compiler
Mbedtls :Https support by mbedtls
Avian :referenced java api

Development IDE usage

C / ObjC: JetBrains CLion, Xcode, Virtual studio
Swift : XCode
Java : Jetbrain Idea, Netbeans
Android : Android Studio

Using miniJVM in project

Copy C source /minijvm/c to your project source folder, copy built jar minijvm_rt.jar to you projec resource folder

#include "jvm/jvm.h"

int main(int argc, char **argv) {
    char *bootclasspath = "../../binary/lib/minijvm_rt.jar";
    char *classpath = "../../binary/libex/minijvm_test.jar;./";
    char *main_name = "test.Foo3";

    s32 ret = 1;
    MiniJVM *jvm = jvm_create();
    if (jvm != NULL) {
        jvm->jdwp_enable = 0; //value 1 for java remote debug enable
        jvm->jdwp_suspend_on_start = 0;
        jvm->max_heap_size = 25 * 1024 * 1024; //

        ret = jvm_init(jvm, bootclasspath, classpath);
        if (ret) {
            printf("[ERROR]minijvm init error.\n");
        } else {
            ret = call_main(jvm, main_name, NULL);
        }
        jvm_destroy(jvm);
    }
    return ret;
}

Third liberies

  • Janino java compiler

Project: Janino
Janino is a super-small, super-fast Java compiler.
Janino can not only compile a set of source files to a set of class files like JAVAC, but also compile a Java expression, a block, a class body, one .java file or a set of .java files in memory, load the bytecode and execute it directly in the same JVM. Janino compiler is not the full java compiler, see limitation , like :

List<String> list=new ArrayList();
list.add("abc");
String s=(String)list.get(0);//can't ignore (String) cast qualifier.

Download jars :
janino.jar
commons-compiler.jar

#compile /binary/res/BpDeepTest.java
mini_jvm -bootclasspath ../lib/minijvm_rt.jar -cp ../libex/janino.jar:../libex/commons-compiler.jar   org.codehaus.janino.Compiler  ../res/BpDeepTest.java
  • Luaj

Project: Luaj
miniJVM adapted : [Luaj minijvm] https://github.com/digitalgust/minijvm_third_lib Lightweight, fast, Java-centric Lua interpreter written for JME and JSE, with string, table, package, math, io, os, debug, coroutine & luajava libraries, JSR-223 bindings, all metatags, weak tables and unique direct lua-to-java-bytecode compiling. Download jars :
luaj.jar

mini_jvm -bootclasspath ../lib/minijvm_rt.jar -cp ../libex/luaj.jar Sample

Screen shot

Windows mini_jvm gui
Macos mini_jvm gui
Linux mini_jvm gui
Web mini_jvm gui

Directorie struct

.
├── binary              miniJVM binary  for build(win32/win64/mac/linux/
├── desktop
│   ├── awtk_gui        open source gui frame awtk jni
│   └── glfw_gui        desktop openGL, glfw, miniaudio, native module
├── j2c                 miniJVM java source translate to c tools
│   ├── app
│   └── translator
├── minijvm             Core source
│   ├── c               miniJVM c source 
│   └── java            miniJVM runtime library
├── mobile
│   ├── androidapp      Android launcher
│   ├── assets          mobile app resource, font files, jar files ,pic ,audio etc.
│   ├── c               mobile native lib, openGLES, glfm framework, gui jni, glfmapp
│   ├── iosapp          iOS launcher
│   └── java            mobile java lib, GUI, AppManager, app example
├── doc
└── test                miniJVM test case 

< Back

Star History Chart

License

License: MIT

Gust , [email protected] .

minijvm's People

Contributors

digitalgust avatar ohayoyogi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minijvm's Issues

'mbedtls/config.h' file not found

I opened the test ios project in xcode on two of my laptops. This error is in almost every class:
"'mbedtls/config.h' file not found"
when trying to import:
#include "mbedtls/config.h"

build warning and failure in mac m1

Got 2 kinds of errors/warnings:

  1. miniaudio is warned as using deprecated api
  2. ../desktop/glfw_gui/c/deps/lib/mac/libglfw3.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
  3. Undefined symbols for architecture arm64 (perhaps due to -2 ?)
uname -a
Darwin GQMFHNX6F9 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 arm64
./build_mac_linux.sh
Mac
compile mini_jvm
compile glfw_gui
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:31157:35: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddressDevices.mElement = kAudioObjectPropertyElementMaster;
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                  kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:31190:28: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement = kAudioObjectPropertyElementMaster;
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:31230:28: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement = kAudioObjectPropertyElementMaster;
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:31258:28: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement = kAudioObjectPropertyElementMaster;
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:31311:28: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement = kAudioObjectPropertyElementMaster;
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:31349:28: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement = kAudioObjectPropertyElementMaster;
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:31438:28: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement = kAudioObjectPropertyElementMaster;
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:31559:28: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement = kAudioObjectPropertyElementMaster;
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:31596:28: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddress.mElement = kAudioObjectPropertyElementMaster;
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:31624:41: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    propAddressDefaultDevice.mElement = kAudioObjectPropertyElementMaster;
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                        kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:32686:36: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
            propAddress.mElement = kAudioObjectPropertyElementMaster;
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                   kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:32715:36: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
            propAddress.mElement = kAudioObjectPropertyElementMaster;
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                   kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
In file included from ../desktop/glfw_gui/c/jni_minial.c:12:
../desktop/glfw_gui/c/deps/include/minial/miniaudio.h:33163:36: warning: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
            propAddress.mElement = kAudioObjectPropertyElementMaster;
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                   kAudioObjectPropertyElementMain
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
    kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
    ^
13 warnings generated.
ld: warning: ignoring file ../desktop/glfw_gui/c/deps/lib/mac/libglfw3.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
  "_glfwCreateWindow", referenced from:
      _org_mini_glfw_Glfw_glfwCreateWindow in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwCreateWindow)
  "_glfwDestroyWindow", referenced from:
      _org_mini_glfw_Glfw_glfwDestroyWindow in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwDestroyWindow)
  "_glfwExtensionSupported", referenced from:
      _org_mini_glfw_Glfw_glfwExtensionSupported in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwExtensionSupported)
  "_glfwGetClipboardString", referenced from:
      _org_mini_glfw_Glfw_glfwGetClipboardString in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwGetClipboardString)
  "_glfwGetCurrentContext", referenced from:
      _org_mini_glfw_Glfw_glfwGetCurrentContext in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwGetCurrentContext)
  "_glfwGetCursorPos", referenced from:
      _org_mini_glfw_Glfw_glfwGetCursorPosX in jni_glfw-cd559a.o
      _org_mini_glfw_Glfw_glfwGetCursorPosY in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwGetCursorPosX, _org_mini_glfw_Glfw_glfwGetCursorPosY )
  "_glfwGetFramebufferSize", referenced from:
      _org_mini_glfw_Glfw_glfwGetFramebufferWidth in jni_glfw-cd559a.o
      _org_mini_glfw_Glfw_glfwGetFramebufferHeight in jni_glfw-cd559a.o
  "_glfwGetInputMode", referenced from:
      _org_mini_glfw_Glfw_glfwGetInputMode in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwGetInputMode)
  "_glfwGetJoystickAxes", referenced from:
      _org_mini_glfw_Glfw_glfwGetJoystickAxes in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwGetJoystickAxes)
  "_glfwGetJoystickButtons", referenced from:
      _org_mini_glfw_Glfw_glfwGetJoystickButtons in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwGetJoystickButtons)
  "_glfwGetJoystickName", referenced from:
      _org_mini_glfw_Glfw_glfwGetJoystickName in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwGetJoystickName)
  "_glfwGetKey", referenced from:
      _org_mini_glfw_Glfw_glfwGetKey in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwGetKey)
  "_glfwGetMouseButton", referenced from:
      _org_mini_glfw_Glfw_glfwGetMouseButton in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwGetMouseButton)
  "_glfwGetProcAddress", referenced from:
      _org_mini_glfw_Glfw_glfwMakeContextCurrentJni in jni_glfw-cd559a.o
  "_glfwGetTime", referenced from:
      _org_mini_glfw_Glfw_glfwGetTime in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwGetTime)
  "_glfwGetWindowAttrib", referenced from:
      _org_mini_glfw_Glfw_glfwGetWindowParam in jni_glfw-cd559a.o
  "_glfwGetWindowMonitor", referenced from:
      _org_mini_glfw_Glfw_glfwGetWindowMonitor in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwGetWindowMonitor)
  "_glfwGetWindowSize", referenced from:
      _org_mini_glfw_Glfw_glfwGetWindowX in jni_glfw-cd559a.o
      _org_mini_glfw_Glfw_glfwGetWindowY in jni_glfw-cd559a.o
      _org_mini_glfw_Glfw_glfwGetWindowWidth in jni_glfw-cd559a.o
      _org_mini_glfw_Glfw_glfwGetWindowHeight in jni_glfw-cd559a.o
  "_glfwHideWindow", referenced from:
      _org_mini_glfw_Glfw_glfwHideWindow in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwHideWindow)
  "_glfwIconifyWindow", referenced from:
      _org_mini_glfw_Glfw_glfwIconifyWindow in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwIconifyWindow)
  "_glfwInit", referenced from:
      _org_mini_glfw_Glfw_glfwInitJni in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwInitJni)
  "_glfwMakeContextCurrent", referenced from:
      _org_mini_glfw_Glfw_glfwMakeContextCurrentJni in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwMakeContextCurrentJni)
  "_glfwPollEvents", referenced from:
      _org_mini_glfw_Glfw_glfwPollEvents in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwPollEvents)
  "_glfwRestoreWindow", referenced from:
      _org_mini_glfw_Glfw_glfwRestoreWindow in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwRestoreWindow)
  "_glfwSetCharCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetClipboardString", referenced from:
      _org_mini_glfw_Glfw_glfwSetClipboardString in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwSetClipboardString)
  "_glfwSetCursorEnterCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetCursorPos", referenced from:
      _org_mini_glfw_Glfw_glfwSetCursorPos in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwSetCursorPos)
  "_glfwSetCursorPosCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetDropCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetErrorCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
      _org_mini_glfw_Glfw_glfwInitJni in jni_glfw-cd559a.o
  "_glfwSetFramebufferSizeCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetInputMode", referenced from:
      _org_mini_glfw_Glfw_glfwSetInputMode in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwSetInputMode)
  "_glfwSetKeyCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetMouseButtonCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetScrollCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetTime", referenced from:
      _org_mini_glfw_Glfw_glfwSetTime in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwSetTime)
  "_glfwSetWindowAspectRatio", referenced from:
      _org_mini_glfw_Glfw_glfwSetWindowAspectRatio in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwSetWindowAspectRatio)
  "_glfwSetWindowCloseCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetWindowFocusCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetWindowIconifyCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetWindowPosCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetWindowRefreshCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetWindowShouldClose", referenced from:
      _org_mini_glfw_Glfw_glfwSetWindowShouldClose in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwSetWindowShouldClose)
  "_glfwSetWindowSize", referenced from:
      _org_mini_glfw_Glfw_glfwSetWindowSize in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwSetWindowSize)
  "_glfwSetWindowSizeCallback", referenced from:
      _org_mini_glfw_Glfw_glfwSetCallback in jni_glfw-cd559a.o
  "_glfwSetWindowTitle", referenced from:
      _org_mini_glfw_Glfw_glfwSetWindowTitle in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwSetWindowTitle)
  "_glfwShowWindow", referenced from:
      _org_mini_glfw_Glfw_glfwShowWindow in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwShowWindow)
  "_glfwSwapBuffers", referenced from:
      _org_mini_glfw_Glfw_glfwSwapBuffers in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwSwapBuffers)
  "_glfwSwapInterval", referenced from:
      _org_mini_glfw_Glfw_glfwSwapInterval in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwSwapInterval)
  "_glfwTerminate", referenced from:
      _org_mini_glfw_Glfw_glfwTerminate in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwTerminate)
  "_glfwWaitEvents", referenced from:
      _org_mini_glfw_Glfw_glfwWaitEvents in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwWaitEvents)
  "_glfwWindowHint", referenced from:
      _org_mini_glfw_Glfw_glfwWindowHint in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwWindowHint)
  "_glfwWindowShouldClose", referenced from:
      _org_mini_glfw_Glfw_glfwWindowShouldClose in jni_glfw-cd559a.o
     (maybe you meant: _org_mini_glfw_Glfw_glfwWindowShouldClose)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mv: rename libgui.dylib to macos/libgui.dylib: No such file or directory

Suggest moving out binary release.

Tracking these binary file make git fetch slow and enlarge the size of repository.
Puting binary release to Github Release maybe better.

Question about miniJVM

Hi,

I am currently developing a Java compiler and runner application for Android, and I am interested in incorporating the miniJVM library into this project.

I have a few questions regarding miniJVM:

  1. Which version(s) of Java does miniJVM support?
  2. Could you provide details about its compatibility with various Java features?

Thank you for your assistance.

Best regards,
Rohit

代码的一些疑惑

void _gen_stack_peek_long(struct sljit_compiler *C, s32 offset, sljit_s32 dst, sljit_sw dstw) { //dst=sp[offset]->lvalue sljit_emit_op1(C, SLJIT_MOV, dst, dstw, SLJIT_MEM1(REGISTER_SP), sizeof(StackEntry) * offset + SLJIT_OFFSETOF(StackEntry, lvalue)); }

这段代码如果运行在 32位的CPU上面,但是java中long是8位的,那么 dst寄存器只有32位这样对么?

Using a lot of RAM

I used miniJVM to demostrate a tiny console app 'Hello World' without any GUI library, it spent 35MB RAM only with minimal runtime? Are there any problem with memory model?

Building on Ubuntu 18.04 fails due to wrong shell syntax

Trying to build on Ubuntu 18.04 I get this error:

./build_mac_linux.sh
Requirement: gcc 
Linux
compile mini_jvm
../minijvm/c/utils/miniz.c:3031:9: note: #pragma message: Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.
 3031 | #pragma message("Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.")
      |         ^~~~~~~
/tmp/ccEx5qCZ.o: In function `mtx_init':
tinycthread.c:(.text+0x26): undefined reference to `pthread_mutexattr_init'
tinycthread.c:(.text+0x41): undefined reference to `pthread_mutexattr_settype'
tinycthread.c:(.text+0x63): undefined reference to `pthread_mutexattr_destroy'
/tmp/ccEx5qCZ.o: In function `mtx_trylock':
tinycthread.c:(.text+0xeb): undefined reference to `pthread_mutex_trylock'
/tmp/ccEx5qCZ.o: In function `thrd_create':
tinycthread.c:(.text+0x2ea): undefined reference to `pthread_create'
/tmp/ccEx5qCZ.o: In function `thrd_join':
tinycthread.c:(.text+0x3cc): undefined reference to `pthread_join'
/tmp/ccEx5qCZ.o: In function `tss_create':
tinycthread.c:(.text+0x54f): undefined reference to `pthread_key_create'
/tmp/ccEx5qCZ.o: In function `tss_delete':
tinycthread.c:(.text+0x576): undefined reference to `pthread_key_delete'
/tmp/ccEx5qCZ.o: In function `tss_get':
tinycthread.c:(.text+0x58e): undefined reference to `pthread_getspecific'
/tmp/ccEx5qCZ.o: In function `tss_set':
tinycthread.c:(.text+0x5b0): undefined reference to `pthread_setspecific'
/tmp/cc06t1Sw.o: In function `java_lang_Math_exp':
jni_std.c:(.text+0xeb3): undefined reference to `exp'
/tmp/cc06t1Sw.o: In function `java_lang_Math_sin':
jni_std.c:(.text+0xfce): undefined reference to `sin'
/tmp/cc06t1Sw.o: In function `java_lang_Math_cos':
jni_std.c:(.text+0x1036): undefined reference to `cos'
/tmp/cc06t1Sw.o: In function `java_lang_Math_tan':
jni_std.c:(.text+0x109e): undefined reference to `tan'
/tmp/cc06t1Sw.o: In function `java_lang_Math_sqrt':
jni_std.c:(.text+0x1106): undefined reference to `sqrt'
/tmp/cc06t1Sw.o: In function `java_lang_Math_ceil':
jni_std.c:(.text+0x116e): undefined reference to `ceil'
/tmp/cc06t1Sw.o: In function `java_lang_Math_floor':
jni_std.c:(.text+0x11d6): undefined reference to `floor'
/tmp/cc06t1Sw.o: In function `java_lang_Math_asin':
jni_std.c:(.text+0x123e): undefined reference to `asin'
/tmp/cc06t1Sw.o: In function `java_lang_Math_acos':
jni_std.c:(.text+0x12a6): undefined reference to `acos'
/tmp/cc06t1Sw.o: In function `java_lang_Math_atan':
jni_std.c:(.text+0x130e): undefined reference to `atan'
/tmp/cc06t1Sw.o: In function `java_lang_Math_log':
jni_std.c:(.text+0x1376): undefined reference to `log'
/tmp/cc06t1Sw.o: In function `java_lang_Math_atan2':
jni_std.c:(.text+0x1414): undefined reference to `atan2'
/tmp/cc06t1Sw.o: In function `java_lang_Math_pow':
jni_std.c:(.text+0x14a0): undefined reference to `pow'
/tmp/cc06t1Sw.o: In function `java_lang_System_loadLibrary0':
jni_std.c:(.text+0x2545): undefined reference to `dlopen'
jni_std.c:(.text+0x2555): undefined reference to `dlerror'
jni_std.c:(.text+0x2593): undefined reference to `dlsym'
collect2: error: ld returned 1 exit status
compile glfw_gui
mv: cannot stat 'mini_jvm': No such file or directory

Then changing the order of the gcc command allow it to build:

diff build_mac_linux.sh build_mac_linux-dad.sh 
30c30
< ${GCC}  -o mini_jvm -I${CSRC}/jvm -I${CSRC}/utils/ -I${CSRC}/utils/sljit/ -I${CSRC}/utils/https/ -I${CSRC}/utils/https/mbedtls/include/ -lpthread -lm -ldl  $SRCLIST ${CSRC}/utils/sljit/sljitLir.c
---
> ${GCC}  -o mini_jvm -I${CSRC}/jvm -I${CSRC}/utils/ -I${CSRC}/utils/sljit/ -I${CSRC}/utils/https/ -I${CSRC}/utils/https/mbedtls/include/  $SRCLIST ${CSRC}/utils/sljit/sljitLir.c  -lpthread -lm -ldl

Then when trying to build the lib/minijvm_rt.jar I'm getting this error:

./build_jar.sh
Requirement: jdk1.8 jar javac 
./build_jar.sh: 8: ./build_jar.sh: Syntax error: "(" unexpected

Then changing the syntax on build_jar.sh solves it:

diff build_jar.sh build_jar-dad.sh 
1c1
< 
---
> #!/bin/sh
8c8
< function build_jar(){
---
> build_jar(){

Thanks for your great work !

Getter/setter optimizer doesn't check method arity

Hi everyone and Hi Gust, first of all, I wanted to thank you and everyone involved a lot for this awesome project!

To the point:

Say you have a method like this:

int discardAndGetX(int x) {
    return this.x;
}

The getter optimization doesn't check the arity of the method and pops the integer instead of this from the stack, resulting in say an NPE.

I am not sure how to fix this without compromising the performance, but it's a real problem with legacy libraries that expose such API's for compatibility…

GUI problem

The start up GUI crashed in Android 10, Windows 10 x64. It showed empty when change language.

Question about the state of J2C

Hi again @digitalgust, I wanted to ask what are your plans for J2C. The last update was 3 yrs ago, according to the commit history. Would you recommend using J2C on platforms that don't support JIT?

想咨询android端的问题

我的目的是想在data/data/xxx/files目录下放入.jar文件,然后通过miniJVM来执行改.jar文件中的类。
android端要怎么做

Porting to web

Hello @digitalgust

I really like your minimalistic virtual machine.

So I tried to port your miniJVM to webassembly using emscripten.
Currently a lot of things are working fine.
You can try it out here:
https://java-on-web.org/examples/

But some features are still missing.

  • GC is disabled, because it blocks the browsers main-thread (exactly after 10 minutes).
  • Networking does not work, has to be modified.

Maybe you would like to look into my changes?
In future we can also merge the changes to the main project, if desired.

Additional ideas:

  • Allow to load a jar directly using an url link.
  • Add more java dependencies that can be loaded like java modules (java.base, java.xml, java.sql)
  • Add a javax.swing like wrapper that allows to load gui-projects without porting to miniJVM
  • Upgrade the jvm from java8 to javaXX .... 17?

Lack JUC

I build miniJvm based Windows & java8 & mingw64,
then I run a java demo

[INFO]jvm inited
class not found:java.util.concurrent.ConcurrentMap.class
class not found:java.util.concurrent.ConcurrentHashMap.class
class not found:java.util.concurrent.TimeUnit.class

How to add JUC to minijdk?
Thanks!

drawRegion

Hello, can you add drawRegion from the old j2me platform?

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.