Bytecoder: Kotlin to WASM - by lazy init does not work
Another Kotlin oddity, but I have managed to track the exception down to the following by lazy. I am using the shadowJar, so I would have expected the Kotlin stdlib to be included, although this seems to be something reflection based from standard Java…
Here is the command line I am using:
java -jar bytecoder-cli-2019-06-13-executable.jar -classpath=./build/libs/art-trimmed-all.jar -mainclass=art.EntryKotlin -builddirectory=build -backend=wasm -minify=false -optimizationlevel=ALL -filenameprefix=main -maximumwasmpages=1024
and the code that generates the exception below.
class EntryKotlin {
val me: String by lazy {
"Hola"
}
init {
println("new entry kotlin")
//val nada = Class.forName("")
Main()
}
companion object {
@JvmStatic
fun main(args: Array<String>?) {
EntryKotlin()
}
}
}
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:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.RuntimeException: Error linking class art.EntryKotlin
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.resolveClass(BytecodeLinkerContext.java:111)
at de.mirkosertic.bytecoder.backend.CompileTarget.compile(CompileTarget.java:81)
at de.mirkosertic.bytecoder.cli.BytecoderCLI.main(BytecoderCLI.java:111)
... 8 more
Caused by: java.lang.RuntimeException: Error linking class kotlin.jvm.internal.Reflection
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.resolveClass(BytecodeLinkerContext.java:111)
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKESTATIC.performLinking(BytecodeInstructionINVOKESTATIC.java:33)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.resolveMethodSignatureAndBody(BytecodeLinkedClass.java:400)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.resolveStaticMethod(BytecodeLinkedClass.java:370)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.resolveClassInitializer(BytecodeLinkedClass.java:148)
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.resolveClass(BytecodeLinkerContext.java:98)
... 10 more
Caused by: java.lang.IllegalStateException: Cannot find static method forName in java/lang/Class with signature java.lang.Class(java.lang.String)
at de.mirkosertic.bytecoder.core.BytecodeInstructionINVOKESTATIC.performLinking(BytecodeInstructionINVOKESTATIC.java:35)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.resolveMethodSignatureAndBody(BytecodeLinkedClass.java:400)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.resolveStaticMethod(BytecodeLinkedClass.java:370)
at de.mirkosertic.bytecoder.core.BytecodeLinkedClass.resolveClassInitializer(BytecodeLinkedClass.java:148)
at de.mirkosertic.bytecoder.core.BytecodeLinkerContext.resolveClass(BytecodeLinkerContext.java:98)
... 15 more
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (7 by maintainers)
Commits related to this issue
- #333 Kotlin to WASM - by lazy init does not work Added Testcase for by lazy — committed to mirkosertic/Bytecoder by mirkosertic 4 years ago
- #333 Kotlin to WASM - by lazy init does not work (#369) Added Testcase for Kotlin by lazy init — committed to mirkosertic/Bytecoder by mirkosertic 4 years ago
- #333 Kotlin to WASM - by lazy init does not work Added Testcase for by lazy — committed to mirkosertic/Bytecoder by mirkosertic 4 years ago
- #333 Kotlin Debug Symbols resulting invalid method argument names — committed to mirkosertic/Bytecoder by mirkosertic 4 years ago
more good news, the by lazy is now working 😃 thanks!
btw the .wasm file has jumped by 560KB to 720KB , but maybe that is the GC stuff for the new version? Anyway tomorrow I try the new llvm target.