Code Monkey home page Code Monkey logo

mirkosertic / bytecoder Goto Github PK

View Code? Open in Web Editor NEW
880.0 24.0 60.0 2.26 GB

Framework to interpret and transpile JVM bytecode to JavaScript, OpenCL or WebAssembly.

Home Page: https://www.mirkosertic.de/blog/2017/06/compiling-bytecode-to-javascript/

License: Apache License 2.0

Java 99.38% HTML 0.54% Kotlin 0.01% CSS 0.01% Clojure 0.01% JavaScript 0.06%
bytecode transpiler webassembly javascript compiler decompiler opencl kotlin jvm-bytecode java-bytecode llvm-frontend llvm

bytecoder's Introduction

Bytecoder

Bytecoder is a Rich Domain Model for Java Bytecode and Framework to interpret and transpile it to other languages such as JavaScript, OpenCL or WebAssembly.

Current Build status: Build Workflow Maven Central

High Level Goals

  • Ability to cross-compile JVM Bytecode to JavaScript, WebAssembly, OpenCL and other languages
  • Primary compile targets are JavaScript and WebAssembly
  • Supports Java 8 up to Java 20
  • Work well with Debugger Toolchains and SourceMaps
  • Allow integration with other UI-Frameworks such as vue.js
  • Backed by OpenJDK 20 as JRE Classlib

Compiling strategies

The JVM Bytecode is parsed and transformed into an intermediate representation. This intermediate representation is passed thru optimizer stages and sent to a backend implementation for target code generation.

The JavaScript backend transforms the intermediate representation into JavaScript.

The WebAssembly backend transforms the intermediate representation into WebAssembly text and binary code.

The OpenCL backend is used to compile single algorithms into OpenCL and execute them on the GPU. This backend is designed to enhance existing programs running on the JVM to utilize the vast power of modern GPUs.

User Manual

The Bytecoder User Manual and a full set of example applications is available here.

bytecoder's People

Contributors

andi-huber avatar coenrijsdijk avatar dependabot-preview[bot] avatar dependabot[bot] avatar karang avatar keesvandieren avatar mirkosertic avatar nbrugger-tgm avatar ningmingxiao avatar noonrightswarriorbehindhovering avatar ogrammer avatar seanmcox avatar suyashtnt avatar tobi823 avatar yuripourre 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  avatar  avatar  avatar  avatar  avatar

bytecoder's Issues

Optimize inefficient IF expressions

IF expressions are often used with boolean conditions using a Compare expression. This is often very inefficient and should generally be avoided.

[Question] Does your tool allow to translate larger JARs with reflection

  • we would like to translate our MontiCore Tool (19 MB JAR) from Java to JavaScript
  • it is completely console based (no gui)
  • but it uses at some point some reflection (groovy)

Does your tool supports it?
And how do I translate a complete JAR and launch it later in HTML, so that the console output will be visible?

Delegate WASM memory management to Host environment

Maybe it is not a good idea to let the memory manager run inside of WASM instance. The idea is now to let all memory management be done by the WASM host, and call memory manager and object access thru imported functions from within WASM. We have of course to test if this might be a performance bottleneck.

Optimize redundant variable assignments

Variables with only one initialization and this initialization is a constant (primitive, class reference or string constant pool) can be safely inlined as value and the variable can be removed.

Bytecoder should be able to run Annotation processors

In some cases, we would like to also generate the "index.html" or some auxiliary javasript files that would be used with the compiler generated JavaScript file by processing some in-source annotations of our own. Bytecoder should be able to run the annotation processor if one detected in the jar file.

Errors in multiple String concatenation

Hi, I found a bug (not that easy to reproduce) in the String concatenation:

public static String getOne() {
	return "1";
}

public static String getTwo() {
	return "2";
}

public static String getThree() {
	return "3";
}
	
public static void main(String[] args) {
	System.out.println(">"+getOne()+","+getTwo()+","+getThree()+"<");
}

Gives : ">3,2,1<" (wrong order)
I tracked the bug in webassembly to the moment the array contening the arguments of TStringConcatFactory.makeConcatWithConstants is constructed (Object[] args) :

(i32.store offset=44 (get_local $SP)
             (call $MemoryManager_AddressnewArrayINTINTINT (i32.const 0)                  (i32.const 3) (get_global $TArray__runtimeClass) (i32.const 85)) ;; new array of type de.mirkosertic.bytecoder.core.BytecodeObjectTypeRef@c2861ce2
         
         )
         ;; setting local variable with type INT with value of type INT
         (set_local $var7
             (i32.const 0)         
         )
         (i32.store offset=20 
             (i32.add (i32.load offset=44 (get_local $SP)) (i32.mul (get_local $var7) (i32.const 4)))
             (i32.load offset=32 (get_local $SP))
         )
         ;; setting local variable with type INT with value of type INT
         (set_local $var8
             (i32.const 1)         
         )
         (i32.store offset=20 
             (i32.add (i32.load offset=44 (get_local $SP)) (i32.mul (get_local $var8) (i32.const 4)))
             (i32.load offset=28 (get_local $SP))
         )
         ;; setting local variable with type INT with value of type INT
         (set_local $var9
             (i32.const 2)         
         )
         (i32.store offset=20 
             (i32.add (i32.load offset=44 (get_local $SP)) (i32.mul (get_local $var9) (i32.const 4)))
             (i32.load offset=4 (get_local $SP))
         )

Where $SP+4 contains the result from getOne(), $SP+20 the result from getTwo() and $SP+32 the result of getThree()

I would fix it myself but I did'nt found where in the compiler this code is generated (is it taken from the java bytecode as it ?)

Also, there is another bug related : if instead of String the results of getOne, getTwo or getThree are of type int, there is a out of bound error at runtime. Maybe the function treat the content of the array as objects adresses even if they are only simple int.

Optimize virtual method calls

The current implementation fails to detect all redundant virtual method calls and thus cannot replace them with a direct call. This should be optimized.

fail to build mvn install

Results :

Tests in error:
testValueOfNegativeString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TByteTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testParseByte JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TByteTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testValueOfString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TByteTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testValueOfNegativeString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TDoubleTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TLong
testValueOfString2 JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TDoubleTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TLong
testValueOfString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TDoubleTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TLong
testParseDouble JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TDoubleTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TLong
testValueOfString1 JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TDoubleTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TLong
testValueOfNegativeString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TFloatTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TLong
testValueOfString2 JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TFloatTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TLong
testParseFloat JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TFloatTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TLong
testValueOfString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TFloatTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TLong
testValueOfString1 JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TFloatTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TLong
testValueOfNegativeString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TIntegerTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testValueOfString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TIntegerTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testParseInt JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TIntegerTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testValueOfNegativeString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TLongTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testValueOfString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TLongTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testParseLong JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TLongTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testValueOfNegativeString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TShortTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testValueOfString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TShortTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testParseShort JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TShortTest): Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
testSimpleExceptionFlow JS Backend jsssacompiler(de.mirkosertic.bytecoder.core.ExceptionHandlerTest): {stack=FLOATflowTest(..)
testRethrow JS Backend jsssacompiler(de.mirkosertic.bytecoder.core.ExceptionHandlerTest): {stack=VOIDthrowSomething(..)
testEquals JS Backend jsssacompiler(de.mirkosertic.bytecoder.core.StringTest): {stack=VOIDtestEquals(..)
testConcatenation JS Backend jsssacompiler(de.mirkosertic.bytecoder.core.StringTest): {stack=VOIDtestConcatenation(..)

Tests run: 434, Failures: 0, Errors: 26, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Bytecoder Parent POM ............................... SUCCESS [ 0.733 s]
[INFO] Bytecoder Core ..................................... FAILURE [ 26.521 s]
[INFO] Bytecoder Maven Plugin ............................. SKIPPED
[INFO] Bytecoder Integrationtest .......................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE


Test set: de.mirkosertic.bytecoder.classlib.java.lang.TByteTest

Tests run: 26, Failures: 0, Errors: 3, Skipped: 0, Time elapsed: 0.535 sec <<< FAILURE!
testValueOfNegativeString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TByteTest) Time elapsed: 0.002 sec <<< ERROR!
java.lang.RuntimeException: Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.linkClass(BytecodeLinkerContext.java:114)
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKESTATIC.performLinking(BytecodeInstructionINVOKESTATIC.java:33)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkStaticMethod(BytecodeLinkedClass.java:326)
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKESTATIC.performLinking(BytecodeInstructionINVOKESTATIC.java:33)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkStaticMethod(BytecodeLinkedClass.java:326)
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKESTATIC.performLinking(BytecodeInstructionINVOKESTATIC.java:33)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkStaticMethod(BytecodeLinkedClass.java:326)
at de.mirkosertic.bytecoder.backend.CompileTarget.compileToJS(CompileTarget.java:82)
at de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner.testJSBackendFrameworkMethod(BytecoderUnitTestRunner.java:127)
at de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner.runChild(BytecoderUnitTestRunner.java:197)
at de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner.runChild(BytecoderUnitTestRunner.java:1)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.IllegalArgumentException: Error while linking virtual method name charValue for de.mirkosertic.bytecoder.classlib.java.lang.TFloat
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkVirtualMethod(BytecodeLinkedClass.java:285)
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.lambda$linkClass$1(BytecodeLinkerContext.java:106)
at java.base/java.util.HashMap$EntrySet.forEach(HashMap.java:1044)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.forEachVirtualMethod(BytecodeLinkedClass.java:380)
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.linkClass(BytecodeLinkerContext.java:103)
... 31 more
Caused by: java.lang.NullPointerException
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKEDYNAMIC.performLinking(BytecodeInstructionINVOKEDYNAMIC.java:59)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkVirtualMethod(BytecodeLinkedClass.java:252)
... 35 more

testParseByte JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TByteTest) Time elapsed: 0.007 sec <<< ERROR!
java.lang.RuntimeException: Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.linkClass(BytecodeLinkerContext.java:114)
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKESTATIC.performLinking(BytecodeInstructionINVOKESTATIC.java:33)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkStaticMethod(BytecodeLinkedClass.java:326)
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKESTATIC.performLinking(BytecodeInstructionINVOKESTATIC.java:33)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkStaticMethod(BytecodeLinkedClass.java:326)
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKESTATIC.performLinking(BytecodeInstructionINVOKESTATIC.java:33)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkStaticMethod(BytecodeLinkedClass.java:326)
at de.mirkosertic.bytecoder.backend.CompileTarget.compileToJS(CompileTarget.java:82)
at de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner.testJSBackendFrameworkMethod(BytecoderUnitTestRunner.java:127)
at de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner.runChild(BytecoderUnitTestRunner.java:197)
at de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner.runChild(BytecoderUnitTestRunner.java:1)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.IllegalArgumentException: Error while linking virtual method name charValue for de.mirkosertic.bytecoder.classlib.java.lang.TFloat
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkVirtualMethod(BytecodeLinkedClass.java:285)
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.lambda$linkClass$1(BytecodeLinkerContext.java:106)
at java.base/java.util.HashMap$EntrySet.forEach(HashMap.java:1044)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.forEachVirtualMethod(BytecodeLinkedClass.java:380)
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.linkClass(BytecodeLinkerContext.java:103)
... 31 more
Caused by: java.lang.NullPointerException
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKEDYNAMIC.performLinking(BytecodeInstructionINVOKEDYNAMIC.java:59)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkVirtualMethod(BytecodeLinkedClass.java:252)
... 35 more

testValueOfString JS Backend jsssacompiler(de.mirkosertic.bytecoder.classlib.java.lang.TByteTest) Time elapsed: 0.006 sec <<< ERROR!
java.lang.RuntimeException: Error linking class de.mirkosertic.bytecoder.classlib.java.lang.TFloat
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.linkClass(BytecodeLinkerContext.java:114)
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKESTATIC.performLinking(BytecodeInstructionINVOKESTATIC.java:33)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkStaticMethod(BytecodeLinkedClass.java:326)
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKESTATIC.performLinking(BytecodeInstructionINVOKESTATIC.java:33)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkStaticMethod(BytecodeLinkedClass.java:326)
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKESTATIC.performLinking(BytecodeInstructionINVOKESTATIC.java:33)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkStaticMethod(BytecodeLinkedClass.java:326)
at de.mirkosertic.bytecoder.backend.CompileTarget.compileToJS(CompileTarget.java:82)
at de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner.testJSBackendFrameworkMethod(BytecoderUnitTestRunner.java:127)
at de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner.runChild(BytecoderUnitTestRunner.java:197)
at de.mirkosertic.bytecoder.unittest.BytecoderUnitTestRunner.runChild(BytecoderUnitTestRunner.java:1)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.IllegalArgumentException: Error while linking virtual method name charValue for de.mirkosertic.bytecoder.classlib.java.lang.TFloat
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkVirtualMethod(BytecodeLinkedClass.java:285)
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.lambda$linkClass$1(BytecodeLinkerContext.java:106)
at java.base/java.util.HashMap$EntrySet.forEach(HashMap.java:1044)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.forEachVirtualMethod(BytecodeLinkedClass.java:380)
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.linkClass(BytecodeLinkerContext.java:103)
... 31 more
Caused by: java.lang.NullPointerException
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKEDYNAMIC.performLinking(BytecodeInstructionINVOKEDYNAMIC.java:59)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkMethodInternal(BytecodeLinkedClass.java:364)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.linkVirtualMethod(BytecodeLinkedClass.java:252)
... 35 more

Use Graph based IR

At the moment some optimizazion are hard to implement, as the Bytecoder IR is not fully graph based, which makes dependency analysis sometimes very tricky. This should be fixed by switching the IR to fully graph based.

Newline in Strings cause compile to fail

Hi,
I just noticed that if you have a newline in a string, for instance : System.out.println("Hello\nWorld");, the generated .wat is ill-formed.
One simple fix is to change the line 729 of WASMSSACompilerBackend.java to : theWriter.println(theData.replaceAll("(?:\\n|\\r)", ""));
Best regards,
Karang

Optimize Selenium startup times

Chrome is launched in headless mode for every testcase. This dramatically increases system load and should be fixed by using a ChromeDriverService with a RemoteDriver

2D Array initialisation not compiling

The initialisation of 2D arrays generates an error when compiling.

        float[][] test1 = new float[][] {
            {1.0f, 0.0f, 0.0f, 1.0f}, 
            {1.0f, 1.0f, 0.0f, 1.0f},
            {0.0f, 1.0f, 0.0f, 1.0f}, 
            {1.0f, 0.5f, 0.5f, 1.0f}, 
            {1.0f, 0.0f, 1.0f, 1.0f},
            {0.0f, 0.0f, 1.0f, 1.0f} 
        };

The error :

Error running bytecoder: Error linking class [F: [F.class -> [Help 1]

Just instanciating the array without initialisation is working:

        float[][] test = new float[6][4];

Command line compilation without maven?

If the project does not have too many dependencies, in the future, would it be possible to supply a simpler command line compilation as well so that we can use it with our own build tool?

Compile Java kernel methods to OpenCL inline functions

It should be possible to add additional methods to the OpenCL kernel beside the processWorkItem Method. This would allow us to implement reusable common class libraries that could be used for machine learning for instance. Those methods include kernel methods and additional static depenciies that are not directly mapped to OpenCL built-in functions.

Dynamic linking generation

We could add a new Annotation to set a javascript implementation of a function when we declare it:

@Import(module = "webglcontext", name = "viewport")
@JSImpl("function(ref, x, y, width, height) {" + 
        "    webglCtx[ref].viewport(x, y, width, height);" + 
        "}")
public native void viewport(int x, int y, int width, int height);

This way the compiler could generate a lib_module.js for each module containing only the linked functions.
We could also place the anotation on the Class to provide a way to initialize a context (instances list) :

@JSImpl("var webglBuffer = [];" + 
        "var webglCtx = [];" + 
	"var webglFramebuffer = [];" + 
	"var webglProgram = [];" + 
	"var webglRenderbuffer = [];" + 
	"var webglRenderingContext = [];" + 
	"var webglShader = [];" + 
	"var webglShaderPrecisionFormat = [];" + 
	"var webglTexture = [];" + 
	"var webglUniformLoc = [];")
public class WebGLRenderingContext {

It would be easier for the library and api developpers to have all the code in one place.
The annotation could be optional, but then it is the responsability of the user to provide the implementations in the js wrapper.

Using soot for java IR

Bytecoder looks like a cool project. Have you considered using one of Soot's representations for the IR aspect?

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.