Giter VIP home page Giter VIP logo

jamvm's Introduction

JamVM + OpenJDK

The objective of this repository is to incorporate OpenJDK and JamVM.

JamVM is an open-source Java Virtual Machine that aims to support the latest version of the JVM specification, while at the same time being compact and easy to understand.

Class Libraries

JamVM must be used in conjunction with the Java class-library from OpenJDK to make a full Java Runtime Environment.

OpenJDK

OpenJDK is the official open-source implementation of the JDK resulting from the open-sourcing of Java in 2007. It consists of a class-library, a virtual machine (HotSpot) and a java compiler (plus other tools).

JamVM is compatible with the class-library from OpenJDK 8. JamVM provides a shared library (libjvm.so) which can be used to replace the libjvm.so containing HotSpot. The existing OpenJDK launcher (java) is used, which now runs JamVM.

In addition to HotSpot, OpenJDK also packages and supports alternative virtual machines such as JamVM. To use JamVM, the -XXaltjvm=jamvm option is given on the java command line. This directs the launcher to load the libjvm.so from the jamvm directory rather than the standard server or client directory.

The easiest way to get OpenJDKis to install a pre-built package for your system. The Adoptium Working Group supports high-quality runtimes based on OpenJDK. You can then replace HotSpot or the existing JamVM library with the library you have built.

Supported Platforms/Architectures

JamVM has been written for a Unix/POSIX-compliant system. Unfortunately, incompatibilities between Unixes still exist, and JamVM needs to use several non-portable calls (mostly threading related). In addition, some architecture specific definitions are required (memory barriers, etc.). Finally, the native calling convention (or ABI) is both platform and architecture dependent. This is needed by JamVM when constructing a call frame to invoke a native method. For most platform/architectures this is provided by highly-efficient hand-written native assembly code.

The following platforms/architectures are recognized by configure.

Operating System Microprocessor Family
Linux x86, x86-64, Arm, Arm64
FreeBSD x86, x86-64, Arm
OpenBSD x86, x86-64, Arm
macOS (Darwin) x86-64, Arm

Features

For those interested in the design of virtual machines, JamVM includes a number of optimizations to improve speed and reduce footprint. A list, in no particular order, is given below.

  • Uses native threading (POSIX threads). Full thread implementation including Thread.interrupt()
  • Object references are direct pointers (i.e. no handles)
  • Supports class loaders
  • Efficient thin locks for fast locking in uncontended cases (the majority of locking) without using spin-locking
  • Two word object header to minimize heap overhead (lock word and class pointer)
  • Execution engine supports many levels of optimization (see configure --help) from basic switched interpreter to inline-threaded interpreter with stack-caching (aka code-copying JIT, equivalent performance to a simple JIT).
  • Stop-the-world garbage collector, with separate mark/sweep and mark/compact phases to minimize heap fragmentation
  • Thread suspension uses signals to reduce supend latency and improve performance (no suspension checks during normal execution)
  • Full object finalisation support within the garbage collector (with finalizer thread)
  • Full GC support for Soft, Weak and Phantom References. References are enqueued using a seperate thread (the reference handler)
  • Full GC support for class and class-loader unloading (including associated shared libraries)
  • Garbage collector can run synchronously or asynchronously within its own thread
  • String constants within class files are stored in hash table to minimize class data overhead (string constants shared between all classes)
  • Supports JNI and dynamic loading for use with standard libraries
  • Uses its own lightweight native interface for internal native methods without overhead of JNI
  • VM support for invokedynamic (JSR 292)
  • VM support for type annotations (JSR 308)
  • VM support for lambda expressions (JSR 335)
  • VM support for method parameter reflection
  • JamVM is written in C, with a small amount of platform dependent assembly code, and is easily portable to other architectures.

Installation

This section describes how to configure, build and install JamVM on your machine, along with the necessary class libraries.

Getting the Files

For JamVM to run, it must also have a class library containing the system classes and the associated native methods (e.g., java.lang.Object). JamVM 2 has been written to work with OpenJDK.

The easiest way to get an OpenJDK install that works with JamVM is to get an existing package for your system and then overwrite the libjvm.so file with the new version. If you wish to build OpenJDK from source, please refer to the build instructions contained within the source distribution.

Building and Installing JamVM

To build JamVM, you must first run configure to generate the Makefiles specific to your machine.

For example, to configure JamVM to use OpenJDK 8, from the directory containing this file do:

./configure 

This should print out some information and then say it's creating the Makefiles. If it fails, make sure your machine's architecture is supported by JamVM.

Then, to build JamVM, type:

make

To install in the default location (/usr/local), type:

make install

This installs an executable of JamVM and a libjvm.so shared library with debug information (-g). Alternatively, to install a version with no symbols (which is much smaller) type:

make install-strip

Note, you must be root to install in the default location.

configure options

JamVM by default installs in /usr/local/jamvm. You can change the installation directory by giving configure the option :-

--prefix=PATH

JamVM supports a number of JamVM specific options to configure. For full details do ./configure --help. Most of these are concerned with enabling tracing (e.g. --enable-tracelock), or selecting which interpreter variant to build. Unless you want to debug JamVM, or experiment with the interpreter these should not be needed.

Installing JamVM into OpenJDK

When using JamVM with OpenJDK, JamVM's libjvm.so file must be copied from its initial install location into the OpenJDK installation.

The default install location puts libjvm.so into /usr/local/jamvm/lib.

OpenJDK allows JamVM as an alternative VM which is invoked using the -XXaltjvm=jamvm option to java. To install a new version of libjvm.so, locate the jamvm directory within OpenJDK. For example, for OpenJDK 8 on an x86-64 Debian/Ubuntu system this is /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jamvm .

If installing into OpenJDK, the default HotSpot libjvm.so can be overwritten by JamVM's libjvm.so. When java is executed it will now run JamVM (if HotSpot is still required you can create a copy of OpenJDK, and overwrite the libjvm.so in the copy). HotSpot will be in either the client or server directory, e.g. <OpenJDK_PATH>/jre/lib/amd64/server.

Do the copy (as root), e.g.:

mkdir -p /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jamvm
cp /usr/local/jamvm/lib/libjvm.so /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jamvm/

To test the install has been successful, run java -version, e.g.:

/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -XXaltjvm=jamvm -version

Reference output:

openjdk version "1.8.0_352"
OpenJDK Runtime Environment (build 1.8.0_352-8u352-ga-1~20.04-b08)
JamVM (build 2.0.1-devel, inline-threaded interpreter)

For Debian/Ubuntu Linux Aarch64, the steps are as following:

sudo mkdir -p /usr/lib/jvm/java-8-openjdk-arm64/jre/lib/aarch64/jamvm
sudo cp /usr/local/jamvm/lib/libjvm.so /usr/lib/jvm/java-8-openjdk-arm64/jre/lib/aarch64/jamvm
/usr/lib/jvm/java-8-openjdk-arm64/jre/bin/java -XXaltjvm=jamvm -version

Reference output:

openjdk version "1.8.0_352"
OpenJDK Runtime Environment (build 1.8.0_352-8u352-ga-1~20.04-b08)
JamVM (build 2.0.1-devel, inline-threaded interpreter with stack-caching)

License

jamvm is available under GNU General Public License version 2. Use of this source code is governed by the GNU GPL that can be found in the COPYING file.

This project is developed by Robert Lougher and contributors.

jamvm's People

Contributors

cfriedt avatar gnu-andrew avatar jserv avatar thihup avatar tpetazzoni avatar xranby avatar

Stargazers

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

Watchers

 avatar  avatar

jamvm's Issues

Unable to initialize JamVM on macOS

Using OpenJDK 8 from Eclipse Temurin, JRE failed to initialize JamVM:

$ bin/java -XXaltjvm=jamvm -version
Exception occurred while VM initialising.
java/lang/NoClassDefFoundError: java/lang/ClassLoader

Known reasons:

  1. Different JRE layout: JRE for GNU/Linux has explicit architecture directory, such as jre/lib/amd64, but JRE for macOS has dynamic libraries in directory jre/lib.
  2. Different java_home information: It indicates to JRE directory on GNU/Linux, but Contents/Home is specified on macOS.

Test environment

  • macOS Catalina 10.15.7, x86-64
  • OpenJDK 8.0.352
$ bin/java -version
openjdk version "1.8.0_352"
OpenJDK Runtime Environment (Temurin)(build 1.8.0_352-b08)
OpenJDK 64-Bit Server VM (Temurin)(build 25.352-b08, mixed mode)

Unable to start SpringBoot application on Ubuntu22.04

Unable to start SpringBoot application on Ubuntu22.04

Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:109)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.lang.TypeNotPresentException: Type org.springframework.context.ApplicationListener not present
	at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
	at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
	at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
	at sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:108)
	at java.lang.Class.getGenericInterfaces(Class.java:913)
	at org.springframework.core.ResolvableType.getInterfaces(ResolvableType.java:502)
	at org.springframework.core.ResolvableType.as(ResolvableType.java:450)
	at org.springframework.context.event.GenericApplicationListenerAdapter.resolveDeclaredEventType(GenericApplicationListenerAdapter.java:112)
	at org.springframework.context.event.GenericApplicationListenerAdapter.resolveDeclaredEventType(GenericApplicationListenerAdapter.java:98)
	at org.springframework.context.event.GenericApplicationListenerAdapter.<init>(GenericApplicationListenerAdapter.java:58)
	at org.springframework.context.event.AbstractApplicationEventMulticaster.supportsEvent(AbstractApplicationEventMulticaster.java:351)
	at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:229)
	at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:197)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:134)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
	at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:74)
	at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:47)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
	at vip.xiaonuo.main.SnowyMainApp.main(SnowyMainApp.java:24)
	... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationListener
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
	... 28 more

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.