konsoletyper / teavm

Compiles Java bytecode to JavaScript, WebAssembly and C
https://teavm.org
Apache License 2.0
2.6k stars 264 forks source link

When will JRE support come to TeaVM? #644

Closed ZGStuff closed 1 year ago

ZGStuff commented 1 year ago

I need a JRE to create my version of @lax1dude's EaglercraftX (1.8.8) with a modloader, such as Forge. I think a LOT of Chromebook players would be happy if that were possible...

I've heard TeaVM doesn't support JREs. Is this true, and if so, will JRE support be coming to TeaVM?

konsoletyper commented 1 year ago

No, TeaVM won't ever support JRE

ZGStuff commented 1 year ago

dang why?

ZGStuff commented 1 year ago

a LOT of people would be happy if it would tbh

konsoletyper commented 1 year ago

Because technically it's not possible. Because of licensing restrictions.

lax1dude commented 1 year ago

No, TeaVM won't ever support JRE

Yeah I do my best to explain how it's unrealistic to ever dynamically load and link random JARs containing unprocessed Java bytecode at runtime in a TeaVM program but not everyone understands that.

I've recently chosen to no longer be an active part on the greater community of people who play "Eaglercraft" so unfortunately more and more people are probably gonna open spam issues on repositories like yours to ask questions due to their inability to contact me instead. I apologize for the inconvenience, don't feel obligated to explain this specific limitation over and over just link them to this issue.

As far as unsupported features specifically in Forge go, Forge provides a widely used API for mods to register bytecode transformers that patch the game's actual compiled class files at runtime to add new features. Nobody should have to explain to a skilled developer why there's no way to implement that specific behavior in a fully-AOT compiled environment like a TeaVM program.

Most if not all methods in Forge's API would never make it into TeaVM's dependency graph and be excluded in the build because they're never called by anything except code in the actual mods which won't be present on the compiler's class path if you plan to load them dynamically.

A lot of core components of Forge, including it's entire event bus system which is CRUCIAL for every Forge mod ever created to interact with the rest of the game, all make heavy use of reflection which is not supported by TeaVM and will also cause dependency graph issues.

Additionally TeaVM only implements a fraction of all of the more obscure components of the JRE that mod developers use in their mods so that alone will also stop you from just pasting any JAR file and expecting it to work.

Maybe a custom eagler-specific statically linked modding API is possible, where mods must be statically linked with the game's source ahead of time using a desktop utility that generates an entirely custom build of the game with the code for the mods baked into it directly, but being able to load existing mods made for Forge dynamically at runtime will never be worth implementing.

konsoletyper commented 1 year ago

To be honest, technically it's possible to run Java in the browser. Technically, you can even write an x86 emulator, run minimalistic Linux within it, which in turn has preinstalled JRE. Of course, with poor performance and large download size. Or it's possible to write a bytecode interpreter and simply download and run JRE. The latter approach would require to patch JRE, since it has some native part, which should be replaced with direct calls to JS. But both approaches are still limited, for example, to use sockets, since from the browser it's impossible (or one can use WS <-> UDP/TCP relay server, but in this case someone needs to maintain this server). The latter approach can be accelerated by JITting, and for this purpose some very small part of TeaVM can be used. However, one can't benefit from most of TeaVM optimizations, that rely on closed world assumption (which is not the case when program uses lots of reflection and bytecode generation). Anyone can do it, but do it from scratch, TeaVM has almost no help here. So it's not like "please, add JRE support to TeaVM", it's "please, write for us a new product that satisfied our needs". Also, this product will have its own drawbacks, like performance, memory consumption and download size. There's even such a product, called CheerpJ. I even have experience with users that fled to CheerpJ from TeaVM and then came back. Anyway, TeaVM is simply for another purpose and will never support JRE.

ZGStuff commented 1 year ago

@lax1dude

Look, it was just a question.

JRE support would do horrible on TeaVM after testing with other things, such as 1.19.2 on my gaming PC. Natively, without TeaVM, I get about 120 FPS. With TeaVM, I get 30.

So my point is, Eagler has some possibilities.

:) although I'm not surprised that you kinda left the community, with over 1000+ people sending spam issues saying "how to make server for eagler"

@konsoletyper

OK, I see your perspective. I value performance more than ANYTHING when I am playing Minecraft, Halo Infinite, etc., so I'm not surprised.

:)

I didn't mean to waste anyone's time.

Thanks, PlixelX3 (aka ZGStuff)