• Stars
    star
    924
  • Rank 49,426 (Top 1.0 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Java bytecode to WebAssembly compiler

JWebAssembly

Build with Java 8 Build with Java 11 Travis Build Status License Coverage Status Maven JitPack

JWebAssembly is a Java bytecode to WebAssembly compiler. It uses Java class files as input. That it can compile any language that compile to Java bytecode like Clojure, Groovy, JRuby, Jython, Kotlin and Scala. As output it generates the binary format (.wasm file) or the text format (.wat file). The target is to run Java natively in the browser with WebAssembly.

The difference to similar projects is that not a complete VM with GC and memory management should be ported. It's more like a 1: 1 conversion. The generated WebAssembly code is similar in size to the original Java class files.

Contribution

Contributions are very welcome. This large project will not work without contributions.

Documentation

The documentation can be found in the wiki.

Roadmap

The compiler is feature complete for milestone 1. There is a release candidate. Please test it and report bugs if the compiled code has the same behavior as Java.

Also the current browsers (Chrome, Edge, Firefox, Opera, ...) supports the needed features.

Version 1.0 (Milestone 1)

Desired Features

  • Java byte code parser
  • test framework
  • Public API of the Compiler see class JWebAssembly
  • Gradle Plugin
  • Emulator
  • Binary format file writer and Text format file writer
  • Support for native methods #2
  • Memory Management - currently with a polyfill on JavaScript side
  • invoke static method calls
  • invoke instance method calls
  • invoke interface method calls
  • invoke dynamic method calls (lambdas)
  • invoke default method calls
  • String support
  • Simple Class object support
  • static constructors
  • Enum support
  • Optimizer - Optimize the WASM output of a single method after transpiling before writing to output
  • Hello World sample (live), (source code)
  • Collection framework compile

Version 2.0 (Milestone 2)

Desired Features

Version 3.0 (Milestone 3)

Desired Features

  • Exception handling - required the next version of WebAssembly
  • Multiple threads - required the next version of WebAssembly
  • Memory Management with built-in GC without JavaScript polyfill
  • Reflection
  • More optimize like tail calls, removing from asserts, inlining of functions, etc

Status of Required WebAssembly Features

The following table shows the status of future WebAssembly features required by JWebAssembly in nightly builds in various implementations. These features are already used by the trunk version of JWebAssembly. If you want know the status of your current browser then look for your browser support.

Feature Importance V8/Chrome SpiderMonkey/FF WABT
Garbage collection medium - partly -
Exceptions low partly - partly
Threads low yes ? yes
Tail call very low yes ? yes

To use it also some flags and switches are currently needed.

Importance: All with high marked features are required for a hello word sample. For a first version that can be used for production.

Required Java Version

The JWebAssembly compiler requires Java SE 8 or higher. It is tested with OpenJDK 8 on travis-ci.com.

Usage

Exporting functions

To export a Java function to make it accessible from JavaScript, you must add the annotation de.inetsoftware.jwebassembly.api.annotation.Export.

import de.inetsoftware.jwebassembly.api.annotation.Export;

@Export
public static int add( int a, int b ) {
    return a + b;
}

importing functions

To import a JavaScript function to make it accessible from Java, you must add the annotation de.inetsoftware.jwebassembly.api.annotation.Import. The method can be declared native or can have a Java implementation which will be ignored on compiling.

import de.inetsoftware.jwebassembly.api.annotation.Import;

@Import( module = "global.Math", name = "max" )
static int max( int a, int b) {
    return Math.max( a, b );
}

Hello world sample in the browser with the DOM wrapper API

@Export
public static void main() {
    Document document = Window.document();
    HTMLElement div = document.createElement("div");
    Text text = document.createTextNode("Hello World, this text come from WebAssembly."); 
    div.appendChild( text );
    document.body().appendChild( div );
}

Java Limits

If you use it in the browser then only things can work that also work in the browser sandbox. This means file access or sockets will never work. Another problem are native parts of the Java VM. If there are no replacements via pure Java or JavaScript import then it will not work. Contributions are wellcome.

Alternatives

For Tool Developer

If you want to develop some tools like plugins for a build system or an IDE, then you need

More Repositories

1

SetupBuilder

Gradle plugin for building setups for different platforms.
Java
87
star
2

jlessc

Less CSS compiler written in Java
Java
54
star
3

dokuwiki-plugin-siteexport

DokuWiki plugin to export pages or namespaces to static html
PHP
24
star
4

JWebAssembly-API

Java API for the JWebAssembly
Java
17
star
5

dokuwiki-plugin-popupviewer

A DokuWiki plugin that allows for simple popups of images or even pages from the wiki.
JavaScript
15
star
6

docker-boxes

Container used @ i-net software
Dockerfile
11
star
7

JWebAssembly-Gradle

Gradle plugin for JWebAssembly, a Java to WebAssembly compiler
Java
10
star
8

dokuwiki-plugin-dw2markdown

Generate markdown file using the renderer.
PHP
9
star
9

dokuwiki-plugin-imageflow

ImageFlow is an elegant Apple-like CoverFlow gallery.
JavaScript
6
star
10

dokuwiki-plugin-pagetemplater

Select Template Pages for your Content.
PHP
5
star
11

dokuwiki-plugin-multiorphan

Administrative GUI to find all sorts of orphaned or wanted pages and media. This works using AJAX instead of loading everything into one page.
PHP
5
star
12

ExcelJConnect

Excel JDBC driver
Java
4
star
13

dokuwiki-plugin-tipoftheday

Display Tip of the Day - which is a random section of another page.
PHP
3
star
14

dokuwiki-plugin-tagsections

Tag sections in DokuWiki
PHP
3
star
15

dokuwiki-plugin-lightweightscript

Adds an "Editor and better only" script part and removes a lot of unneeded scripts parts for non editors. It makes the JS for end users a lot smaller and faster to load.
PHP
2
star
16

SetupBuilderOSXPrefPane

Implementation of a basic Preference Pane for OSX to be used with SetupBuilder
Objective-C
1
star
17

dokuwiki-plugin-redirector

Redirect Pages when a pattern matches.
PHP
1
star
18

dokuwiki-plugin-sectionedit

EXPERIMENTAL plugin to edit sections without re-loading the page.
JavaScript
1
star
19

dokuwiki-plugin-imagemap

Create client-side image maps.
PHP
1
star
20

dokuwiki-plugin-asyncsearch

Overrides the default search page and does the search asynchronously in the back.
PHP
1
star
21

dokuwiki-plugin-discoursesearch

Search articles from a discourse installation.
JavaScript
1
star
22

dokuwiki-plugin-zerolinecss

DokuWiki Plugin to inline the CSS if a certain template is selected.
PHP
1
star
23

dokuwiki-plugin-keywords

Adds keywords to the page meta header
PHP
1
star
24

dokuwiki-plugins-rssbycreated

Re-orders the RSS feed by the created date and makes it the date submitted to the reader.
PHP
1
star