Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in wasm compiler #52

Open
Dogini opened this issue Aug 24, 2022 · 1 comment
Open

Exception in wasm compiler #52

Dogini opened this issue Aug 24, 2022 · 1 comment

Comments

@Dogini
Copy link

Dogini commented Aug 24, 2022

I tried to do the Hello World example and got the folllowing exception:

....
scan java/util/HashMap.get(Ljava/lang/Object;)Ljava/lang/Object;
type: java/util/HashMap
type: java/util/HashMap$Node
call: java/util/HashMap.getNode(Ljava/lang/Object;)Ljava/util/HashMap$Node;
scan java/lang/StringLatin1.charAt([BI)C
call: java/lang/StringIndexOutOfBoundsException.(I)V
scan java/lang/StringUTF16.charAt([BI)C
call: java/lang/StringUTF16.checkIndex(I[B)V
scan java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z

WASM compile failed with: Native methods cannot be compiled to WebAssembly: java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z
If you want to use classes with native code, you must use a library that implements these native methods, such as 'de.inetsoftware:jwebassembly-api:+' or implements this native method self.
at java.lang.ref.Reference.refersTo0(Reference.java)

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':WASM-Lib:wasm'.

Native methods cannot be compiled to WebAssembly: java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z
If you want to use classes with native code, you must use a library that implements these native methods, such as 'de.inetsoftware:jwebassembly-api:+' or implements this native method self.
at java.lang.ref.Reference.refersTo0(Reference.java)

What am I doing wrong?
Here is my build.gradle file:

buildscript {
repositories {
maven { url uri('https://jitpack.io') }
}
dependencies {
classpath 'com.github.i-net-software:jwebassembly-gradle:master-SNAPSHOT'
}
}

apply plugin: "de.inetsoftware.jwebassembly"

repositories {
mavenCentral()
maven {
url = uri('https://jitpack.io')
}
}

dependencies {
implementation 'com.github.i-net-software:jwebassembly-api:master-SNAPSHOT'
}

sourceSets {
main {
java {
srcDir 'src/main/java'
}
}
}

wasm {
//Get more debug information if there are problems.
//logging.level = LogLevel.DEBUG
logging.levelInternal = LogLevel.DEBUG

//Change the output format to the text format *.wat.
//This can be helpful to understand the problems if you see the generated code as text format.
format = 'text'

//The used JWebAssembly compiler version. The default is the latest release '+'.
//You can set any valid Gradle version string or a full dependency string.
//The snapshot version is recommended until a stable release.
//compilerVersion = 0.4
compilerVersion = 'com.github.i-net-software:jwebassembly:master-SNAPSHOT'

//Write method and parameter names into the output *.wasm file.
//The file will be approximate 10% larger. And it generate a source map.
//With a source map you can see in the debugger of the browser your source code if available.
debugNames = true

//Set an absolute or relative path between the final wasm file location and the source files location.
///This is needed for debugging in the browser. It work only if debugNames = true.
//sourceMapBase = '../../src/main/java/'
sourceMapBase = '/src/main/java/'

//set the destination dir
destinationDir = file( 'targetDir' )

//ignore all referenced native methods without declared replacement in a library and replace them with a stub that throws an exception at runtime
//ignoreNative = true
}

@Horcrux7
Copy link
Member

WASM compile failed with: Native methods cannot be compiled to WebAssembly: java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z

This is a problem with Java 9 or higher if you referenced a String. A pull request for API project that can fix this is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants