How to debug class loading

Hi, I'm dropping in here from github (https://github.com/leaningtech/cheerpj-meta/issues/195). I'm trying to run the kotlin compiler in a browser (https://github.com/F43nd1r/kotlin-compiler-cheerpj) - however this leads to "Bad class file cj3.js:1:420827" on the console with no further info. How can I debug here to see where the issue might be?
GitHub
Issues · leaningtech/cheerpj-meta
Run Java 8 applications, libraries, applets, Java Web Start, and Oracle Forms on the web without legacy plugins. - Issues · leaningtech/cheerpj-meta
GitHub
GitHub - F43nd1r/kotlin-compiler-cheerpj
Contribute to F43nd1r/kotlin-compiler-cheerpj development by creating an account on GitHub.
16 Replies
apignotti
apignotti•8mo ago
The bad class file message is most likely caused by an internal bug where non-class data is being parsed as a class. What version of CJ are your using?
F43nd1r
F43nd1rOP•8mo ago
https://cjrtnc.leaningtech.com/3_20240416_465/cj3loader.js
apignotti
apignotti•8mo ago
We had success running kotlin code, including the kotlin compiler in the past For a specific version, but it's a codebase that tends to do extremely complicated manipulations It's quite possible the fix will be easy, just upload test complete HTML test case to a publicly accessible URL so that we can take a look For reference: https://discord.com/channels/988743885121548329/1178768677479403671/1178781364561129612 about our previous experiments with kotlin
F43nd1r
F43nd1rOP•8mo ago
GitHub
kotlin-compiler-cheerpj/src/main/serve/index.html at master · F43nd...
Contribute to F43nd1r/kotlin-compiler-cheerpj development by creating an account on GitHub.
apignotti
apignotti•8mo ago
Can you deploy a ready-made page already integrated with CJ? For us is time consuming to get sources to build, and we never need the source anyway
F43nd1r
F43nd1rOP•8mo ago
Oh, that is an interesting approach - I was trying to get the embedded compiler running instead of the standalone I'll set up gh pages, give me a minute https://f43nd1r.github.io/kotlin-compiler-cheerpj/ there you go Note that currently everything happens only on the console, nothing visible on the page
apignotti
apignotti•8mo ago
No description
apignotti
apignotti•8mo ago
That's what I get, it does not seem to be what you previously mentioned
F43nd1r
F43nd1rOP•8mo ago
Oh, typical web development fun: only happens in firefox, chrome shows what you posted Continuing with chrome, I got to a stacktrace:
Stacktrace: java.lang.Error: java.lang.ArrayIndexOutOfBoundsException
at java.lang.Error.<init>(Unknown Source)
at org.jetbrains.kotlin.com.intellij.util.containers.ConcurrentLongObjectHashMap.<clinit>(Unknown Source)
at org.jetbrains.kotlin.com.intellij.util.containers.ContainerUtil.createConcurrentLongObjectMap(Unknown Source)
[...]
at kotlin.script.experimental.host.BasicScriptingHost.eval(Unknown Source)
at com.faendir.KotlinCompiler.eval(Unknown Source)
Caused by: java.lang.ArrayIndexOutOfBoundsException
at .(Unknown Source)
at java.lang.invoke.LambdaForm$DMH.invokeVirtual_LL_J(Unknown Source)
at .(Unknown Source)
... 31 more
Stacktrace: java.lang.Error: java.lang.ArrayIndexOutOfBoundsException
at java.lang.Error.<init>(Unknown Source)
at org.jetbrains.kotlin.com.intellij.util.containers.ConcurrentLongObjectHashMap.<clinit>(Unknown Source)
at org.jetbrains.kotlin.com.intellij.util.containers.ContainerUtil.createConcurrentLongObjectMap(Unknown Source)
[...]
at kotlin.script.experimental.host.BasicScriptingHost.eval(Unknown Source)
at com.faendir.KotlinCompiler.eval(Unknown Source)
Caused by: java.lang.ArrayIndexOutOfBoundsException
at .(Unknown Source)
at java.lang.invoke.LambdaForm$DMH.invokeVirtual_LL_J(Unknown Source)
at .(Unknown Source)
... 31 more
Looking at the source of ConcurrentLongObjectHashMap, the kotlin compiler seems to be accessing com.sun.misc.Unsafe using reflection here. Hard to tell which call exactly with no line numbers. I assume I can't turn on line numbers in cheerpj somewhere?
apignotti
apignotti•8mo ago
Debugging information is not supported at this time
F43nd1r
F43nd1rOP•8mo ago
Alright, I thought evaluating some kotlin would've been an impressive demo of cheerpj. Probably a bit too ambitious - at least I'm out of my depth here. I can see the kotlin compiler tries to figure out the memory layout of certain classes, I assume that's the part which is just different enough on cheerpj to not work out, but I have no idea how to debug or fix any of it. Thanks for the help either way 🙂
apignotti
apignotti•8mo ago
Give me a few hours before giving up As a matter of fact, the Firefox issue is already fixed locally
F43nd1r
F43nd1rOP•8mo ago
oh, that's cool. Sure if you continue on your side I'll happily follow along!
apignotti
apignotti•7mo ago
I've fixed a few minor issues and this is the output I get right now, which is the same I see when running with native Java 8
No description
apignotti
apignotti•7mo ago
Please try again with the following build: https://cjrtnc.leaningtech.com/3_20240425_466/cj3loader.js
F43nd1r
F43nd1rOP•7mo ago
yeah that's because my hello world isn't actually valid kotlin code 😂 I updated the demo with the new build and a bit of UI - https://f43nd1r.github.io/kotlin-compiler-cheerpj/ Not the fastest in the world, but it works! Impressive how you got that fixed so fast
Want results from more Discord servers?
Add your server