-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
Does it support running wasm in go #568
Comments
False. Wasm IS NOT portable. It's portable as a virtual machine. But this virtual machine does not interact with the outer world (e.g. printing to console), it has to call functions that provide corresponding capabilities. There is no standard portable way to do that. Wasi does not work in the browser, so I can't call wasm portable. So my answer it: not, it's impossible to remove these dependencies. But I don't see any problems here. There are few functions that you should provide to wasm module generated by TeaVM, they are quite trivial. What's the problem to write these functions for your environment?
The question is how TeaVM should interact with this GC. I see no way. TeaVM has it own GC. |
And the main question is: why? Why do you want to run Java such a strange way? |
At present, the wasm module is supported on the go project mosn, and we hope that the wasm compiled by java can also be executed (outside the js environment). We have implemented protocol extensions in the rpc, so we also hope that java developers can provide extension plugins. We noticed that wasm currently supports multiple language implementations:https://github.com/proxy-wasm/spec
In the java compiler, no examples of use in a non-web environment have been found so far. |
I'd also like to run Java in such a strange way.
I have added a plugin system to my existing application. I've based it on WebAssembly because
So, I'd like to be able to support as many languages as possible, and supporting JVM languages would be a big plus in that direction. Ultimately, this currently fails because I expect my plugins to provide me with pointers into their memory, and that memory should contain a CBOR buffer. I failed to achieve this, because Jackson et al. won't compile (e.g. because UUID and ConcurrentHashMap are missing), and because getting a pointer to the content of a
I've attempted this and it indeed wasn't difficult. But it also isn't a very good solution, since these imports are internal interface that may change at any release, right?
There are libraries/polyfills for that. Alternatively, implementing the three functions you need ( Anyway, TeaVM generated WASM currently seems to need at least a little support from the outside system. Maybe that could change when WASM gets its own GC and exception support, but currently, I don't think it's possble for TeaVM to run entirely with what WASI provides. So in summary: TeaVM is for running Java in the browser. I would be happy if it could be extended to a broader scope, but I don't think it can (but not for the reasons previously mentioned here). |
@jcaesar thanks for your great feedback!
Is Jackson that necessary? Can't you write your own CBOR parser/generator? Can you tell me more info so that I could reimplement TeaVM-friendly CBOR support (I already have JSON parser/generator compatible with Jackson annotations that is supported with TeaVM).
Address.ofData(array).toLong(). But please note that TeaVM GC can relocate arrays, so this pointer may change. If you are interested, I can think on providing API for allocating off-heap buffers.
Right. But runtime part is rather small and does not change often. Do you know of some other strategy which solves this issue?
Ah, I see. You want TeaVM-generated wasm file to depend directly on subset of WASI and also ship JS module that provides this subset of WASI API? Right?
What kind of support do you mean?
What's the problem to run TeaVM entirely in WASI environment?
And what are the actual reasons? |
Sorry, I guess I was being cryptic.
I would document the API and mention changes in the release notes. You could also change the import namespace (e.g.
Yes. Sorry about the discussion below, it's off-topic for this issue. I'll move it if desired.
No, It's just the nicest thing out there. I'd be happy with anything that gives me a JsonNode or similar.
I'd be happy with using that, too. (I can add a switch to my API that specifies which format the data is passed in.) But I think I can't use that because it depends on JS?
Could, but I shun the effort. I think it would be easier to implement what little classes are missing in TeaVM. It seems like
The problem with these binary formats is that next week there's another. Having specific support for one of them is nice, but you'll probably be bombarded with requests for more. Anyway, here is an example of one of these libraries failing.
Oh! Thank you. (I was hoping to be safe from the GC if I call the import in the same statement... But maybe I'm mixing this up with Go semantics.) |
No, external runtime does not have to call these functions.
Right. As for
I'll write a simple JSON parser in an hour. Do you need one?
This is not a problem, it's easy to fix.
I'm not sure it's easy to implement them. For example, you mentioned ConcurrentHashMap. People used to think since there's no threads in JS, ConcurrentHashMap could be simply replaced with HashMap. That's a simplification, because TeaVM replaces threads with its own coroutines. I have an old branch that provides ConcurrentHashMap implementation friendly to coroutines, but still have no idea how to test this implementation properly.
Isn't Class.getCanonicalName supported in latest versions? I recommend not to use Maven Central versions of TeaVM, since I don't publish there anymore. Instead, use latest build according to instructions on readme.md.
Unlike JVM, TeaVM GC does not relocate objects that are directly reachable from stack. This means that if method |
I see. TeaVM holds significantly more magic than I expected. I'm considerably more optimistic that I might be able to run Java in my plugin system. (I'm on vacation next week... ;) So not too soon.)
It is. (And sorry, I just used the archetype from getting started without thinking. That still comes with 0.6.1 from central.)
You may leave that exercise to the reader. ;) |
At present, we support the running of wasm module in the mosn project (implemented in go language), and found that teavm also supports the generation of wasm files, and we hope that the wasm generated by java can also run in the go environment.
I wrote a demo to test the wasm file generated by teavm,found some functions that rely on teavm, but they will not be implemented in the host.
Similar to the export part, there are also functions that teavm depends on:
Question:
Here is the wasm file (wasi specification) I compiled with go:
The text was updated successfully, but these errors were encountered: