Libjavm
Small, header-only, zero-dependency C++17 Java VM library
Install / Use
/learn @XorTroll/LibjavmREADME
libjavm
Simple, compact, zero-dependency C++17 Java Virtual Machine library
The only "dependencies" it does require are standard C/C++17 libraries, plus the offial Java standard library (rt.jar file) since virtually all compiled Java uses it.
Note that, for threading and synchronization items (mutexes, condvars...) you must provide your own implementation. Nevertheless, libjavm provides a default implementation with pthread for threading and standard C++ for sync stuff (pthread_t, std::recursive_mutex, std::condition_variable_any...)
It provides everything necessary to run Java (8 or lower...?) code in any kind of system.
Credits
-
python-jvm-interpreter, as the original base for the project.
-
andyzip library, since it's used for JAR loading as an easy-to-use and header-only ZIP file reading library.
-
KiVM, since it's code was checked for a lot of aspects of the VM.
-
Official Oracle VM specs (although these are for Java 11)
Usage
Check the examples directory for some example programs using this library.
TODO: proper documentation...
Comparison with JRE
The tests used to test the VM (slightly modified KiVM tests) are located at javm-test-suite. Currently 26 out of 28 tests are successfully passed (comparing their output with JRE):
-
ArgumentTest: pass! -
ArithmeticTest: pass! -
ArrayTest: pass! -
ArrayTest1: pass! -
ArrayTest2: pass! -
AssertTest: pass! -
ChineseTest: pass! -
ClassCastTest: pass! -
ClassNameTest: pass! -
CovScriptJNITest: pass! -
ExceptionTest: pass! -
ExceptionTest1: pass! -
ExceptionTest2: pass! -
ExceptionTest3: pass! -
FileTest: fail (filesystem-related native methods aren't implemented) -
GCTest: pass! -
HashTest: pass! -
HelloWorld: pass! -
LambdaTest: fail (dynamic stuff not implemented yet) -
Main: pass! -
PackagePrivateTest: pass! -
Polymorphism: pass! -
StaticFieldTest: pass! -
StaticResolution: pass! -
StringBuilderTest1: pass! -
ThreadExceptionTest: pass! -
ThreadTest: pass!
TO-DO list
-
Implement
invokedynamic,wide,tableswitchopcodes -
Implement not implemented standard native methods (only implemented basic ones to get past initialization, for now)
-
Dynamic invoking stuff, related to
invokedynamicopcode (method handle support, constant pool items related to this...) -
Support or take into account other annotations (currently only
CallerSensitiveis checked) -
The many
TODOcomments spread in code -
(...)
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
