12 ms·
TeaVM – Ahead-of-time transpiler of Java bytecode to JavaScript or WebAssembly
- ianlevesque 9y agoDoes this support GC?
- glibgil 9y agohttps://github.com/konsoletyper/teavm/blob/d882fd14a63cc1bd76060b3abf34f85d3b013692/core/src/main/java/org/teavm/runtime/GC.java https://github.com/konsoletyper/teavm/blob/d882fd14a63cc1bd7...
- ant6n 9y agoCompile
- burke 9y agoI get that we've lost this battle, and some people seem to think there's a useful distinction being made, but man, does the word 'transpile' grate on me.
- doug1001 9y agothank you; some consolation to know it's not just me does this seems like another instance of the annoying practice in our field of someone giving a name to a thing because they think it's new, though it's not (ie, source-to-source compilers have been around as long as source-to-bytecode compilers)--no need to re-name them wish they would just stop it and get the hell off my lawn
- pjmlp 9y agoYep, like calling themselves Engineer without having the respective degree. Thankfully in most jurisdictions it is forbidden by law to do as such.
- abiox 9y agoan example of "transpiler" from 1989 ;) https://books.google.com/books?id=l5I_AQAAIAAJ&q="transpiler"&dq="transpiler"&hl=en&sa=X&ved=0ahUKEwip75qFp8DYAhVI7IMKHe_tAhI4PBDoAQg3MAQ https://books.google.com/books?id=l5I_AQAAIAAJ&q="transpiler...
- deleted 9y ago[deleted]
- deleted 9y ago[deleted]
- clhodapp 9y agoAt the point where we are calling things that compile to assembly "transpilers" I don't think there is any distinction left, much less a useful one. I mean the classic notion of a compiler is a program that turns things into assembly, which is then taken into machine code by an assembler. I agree with you that we've lost though: no amount of protest is going to make people stop using the word "transpiler".
- drdrey 9y agoA compiler is a program that turns programs in a source language into equivalent programs in a target language. It is generally assumed that a compiler goes from high level to low level, a decompiler low-to-high and a transpiler high-to-high. I guess in this case the transpiler is low-to-low, so maybe "transpiler" is just used to mean "samey-to-samey"
- deleted 9y ago[deleted]
- ant6n 9y agoA compiler is a program that translates programs from one language to another. > At the point where we are calling things that compile to assembly "transpilers" I don't think there is any distinction left "Transpiler" is grating (apparently).
- gatmne 9y ago> some people seem to think there's a useful distinction being made What is that distinction? Excluding the javascript crowd, I doubt this phrase will see extensive use in the field until the term gets properly defined and is meaningfully distinct from the word Compile as used today.
- nurettin 9y agoI assume "javascript crowd" knows how to compile their node binary. Thus, they know the distinction between babeljs and gcc, and therefore they know the distinction between compiler and transpiler.
- gatmne 9y agoWhat's the distinction between Compile and transpile then? and is this distinction agreed upon and meaningful?
- nurettin 9y agoI agree with drdrey's definition here[1], which is echoed in paragraph two here[2] as well, which provides you with the agreement part at least. Whether if it is meaningful to you, is up to you. [1] - https://news.ycombinator.com/item?id=16076823 https://news.ycombinator.com/item?id=16076823 [2] - https://hackernoon.com/moving-to-es6-babel-and-transpilers-337921c025b1 https://hackernoon.com/moving-to-es6-babel-and-transpilers-3...
- abiox 9y agowell, there's even a wiki page for source-to-source translation. it's not always useful to distinguish 'truck' from 'automobile', but sometimes it is.
- dragonwriter 9y agoIt's sometimes useful to distinguish “truck” from “automobile”, but never when the thing being labelled a “truck” is a Honda Civic.
- abiox 9y agoare you saying it's not useful to refer to something as a transpiler if it's not a transpiler? that sounds reasonable.
- lopatin 9y agoThere was a battle? Transpile is between human readable sources, and compiler is always into machine readable code. This is the only project that I've seen to (for some reason) not conform to that definition. I guess I don't see the point of contention.
- stefano 9y agoTranspilers used to be called "source-to-source compilers", or "compilers" when the "source-to-source" distinction wasn't relevant. Then the JS world came along and decided to use a new word to make it look more hip and cool.
- dagw 9y agoIt's not a new word. People have been using the word "transpiler" or "transcompiler" for source-to-source compilers since at least the late 80's [0]. They used to be popular for translating between different dialects of assembly. Then they fell out of fashion for a while before gaining popularity again in the last decade for targeting JavaScript. So while the "JS world" is responsible for re-popularizing both the word and the concept, they certainly didn't invent it. [0]edit: Apparently 60's.
- jasode 9y ago>decided to use a new word A friendly FYI... the old word "transpiler" has been around since at least the 1960s. See the 2nd-to-last paragraph on the last page: http://comjnl.oxfordjournals.org/content/7/1/28.full.pdf+html http://comjnl.oxfordjournals.org/content/7/1/28.full.pdf+htm...
- burke 9y ago> compiler is always into machine readable code The frustrating bit is that this is absolutely not true. A compiler is anything that parses some text according to some grammar, manipulates it, and emits it in a different format. While the most well-known and popular compilers are for C, to emit machine code, there's nothing inherent in the definition of a compiler that means it can't emit something human-readable. I wouldn't have nearly as much issue with this if the JavaScript community instead had decided "compiler isn't specific enough: we need different words for compilers that drop vs. maintain a level of abstraction", rather than "we need a word for a thing like a compiler, but that doesn't, as compilers apparently inherently do, drop a level of abstraction".
- gatmne 9y agoAgreed especially given that "transpile" lacks a well-defined meaning. Just ask folks how this term differentiates from Compile and you'll get wildly varying answers and definitions.
- dragonwriter 9y ago“Transpile” is a proper subset of “compile”, where both the source and target of compilation are languages designed primarily for direct human editing (source code); it is source-to-source compilation. Using the term for anything where the source is JVM bytecode is plain wrong, and it's also dubious for anything targeting WebAssembly (though if the target is specifically .wat/.wast, it may perhaps be arguably defensible.)
- abiox 9y agothere existed "translators" from one asm variant to another in the past. [0][1] so i guess one might use "transpile" wrt bytecode in the spirit of that. but i guess asm source files are still "human readable", where bytecode generally isn't considered as such. [0] P47, "TRANS": http://www.patersontech.com/dos/Docs/86_Dos_usr_03.pdf http://www.patersontech.com/dos/Docs/86_Dos_usr_03.pdf [1] http://www.s100computers.com/Software%20Folder/Assembler%20Collection/Digital%20Research%20XLT86%20Manual.pdf http://www.s100computers.com/Software%20Folder/Assembler%20C...
- gatmne 9y agoMy point exactly!
- usrusr 9y agoI think it's pretty clear that "transpile" is a subset of "compile" and that there are both examples of "compile" that are indisputably not "transpile" (plain old source to architecture specific binary) and examples of "compile" that anybody who uses the term "transpile" would include in their personal variety of "transpile" (translation between source formats that are commonly used for human written code). I don't see why the existence of a grey area should be enough to question the utility of the term. If compile/decompile are used for a transformations along one axis, transpile is used for transformations that are predominantly orthogonal to that axis.
- kodablah 9y agoFor the reverse, I wrote a WASM-to-JVM compiler: https://github.com/cretz/asmble https://github.com/cretz/asmble. I think WASM has the ability for us to finally cross the language boundaries without marrying ourselves to C/C++ ABI. But at this early stage, there's no common stdlib for all languages to share.
- benjaminjackman 9y agoThat's really interesting! How does calling WASM code on the JVM work? And also in addition to a stdlib, maybe a great package management system. Is there a popular crate / maven / npm etc equivalent out there for wasm yet?
- wging 9y agoThere seems to be a good deal of info in the README: https://github.com/cretz/asmble#compilation-details https://github.com/cretz/asmble#compilation-details I haven't dug deeply but it seems from the documentation that the project is trying to do things the 'right' way (mapping instructions to JVM bytecodes at a low level)... as opposed to, say, trying somehow to compile to Java code.
- hrjet 9y agoThere is also a WASM to Java source transpiler: https://github.com/wrmsr/wava https://github.com/wrmsr/wava
- pjmlp 9y ago> I think WASM has the ability for us to finally cross the language boundaries without marrying ourselves to C/C++ ABI That is how many maninframes work, and the original idea behind the CLR.
- bdamm 9y agoIsn't the CLR just the same as the JVM?
- 9y ago
- exception_e 9y agoFor those that are wondering but skimmed the page: It looks like they're thinking about SPA framework (Angular/React/Etc) and have a subproject to support them.
- deleted 9y ago[deleted]
- planxty 9y agojust trollin', y'all: https://en.wikipedia.org/wiki/Write_once,_run_anywhere https://en.wikipedia.org/wiki/Write_once,_run_anywhere
- dizon 9y agoIn the end, how will this differ from a Java applet?
- grzm 9y agoYou don't need to have Java enabled in your browser.
- dizon 9y agoThe problem with that is you'll essentially re-download the entire JVM (and libraries) on each page load. If you don't want to use a Java applet, you would need to reimplement GC, JNI, and so on. Java didn't work on the web for a reason.
- hrjet 9y agoGC should be available in WASM in the future. And, not all applets needed JNI. In other words, this is enabling a subset of well behaved applets, while excluding the naughty (or advanced) applets.
- jayd16 9y agoCaching exists. You hsouldn't have to redownload the same libraries for each page load.
- fulafel 9y agoThe JVM can be very small. The libraries shouldn't be any worse than with current JS. The browser won't have to re-download on each page load because the browser has a cache, which can be validated on each page load to check for updates.
- C14L 9y agoThe browser would cache that automatically. And in many cases, you'd probably use a Service Worker to implement your own custom cache and "install" the application locally in the browser, so that is usable offline and only version updates are downloaded in the background.
- acqq 9y ago“TeaVM is a primarily web development tool. It’s not for getting your large existing codebase in Java or Kotlin and producing JavaScript.” “TeaVM is for you, if: - You are a Java developer and you are going to write web front-end from scratch. - You already have Java-based backend and want to integrate front-end code tightly into your existing development infrastructure. - You have some Java back-end code you want to reuse in front-end. -You are ready to rewrite your code to work with TeaVM.“ http://teavm.org/docs/intro/overview.html http://teavm.org/docs/intro/overview.html
- deleted 9y ago[deleted]
- olingern 9y ago> If you are a Java (or Kotlin, or Scala) developer who used to write back-end code, TeaVM might be your choice. It’s true that a good developer (including Java developer) can learn JavaScript. However, to become an expert you have to spend reasonable amount of your time. Oh, this is nice. I finally have a reason to give Kotlin a go. I have some time off and want to write something basic. Pretty excited about this, Rust, and all things wasm popping up. I am, in no way, excited about debugging it, though.
- rufugee 9y agoKotlin compiles to javascript already...why wouldn't you go that route?
- konsoletyper 9y agoKotlin/JS does not allow to reuse Java code and Java libraries. That's the main difference.
- billsix 9y agoThat word,"Transpile". Lol. GCC transpiles C to assembly.
- rusbus 9y agoI guess it implies a 1-1 or similar conversion without optimizations or multiple levels of intermediate representation. GCC certainly doesn't "transpile" in that case...
- tom_mellior 9y agoSo GCC -O0 is a transpiler, but GCC -O3 is a compiler? Nice.
- abiox 9y agoit's not a new word. i find it odd how some people react to it.
- Al-Khwarizmi 9y agoNot new, but as unnecessary as ever.
- abiox 9y agoi find it fascinating how some in a community notoriously anal about 'being precise' want to be less precise, presumably because of some incorrect assumptions about a word. is it because they think it's a neologism? is it because they associate it with javascript developers, who they look down upon and sneer at? the word and idea predates javascript. rather amusing. :)
- iotscale 9y agoAn old colleague of mine hated the word "awesome" because, in his words, "it's a word js-kiddies use to exaggerate their little accomplishments". Guess how he reacted when someone used the phrase "isomorphic js"...
- frik 9y agoThe last thing we need in hindsight to Meltdown and Spectre is running untrusted binaries in the browser aka WebAssembly. Btw deactivating WebAssembly support in Chrome 63 (up-to-date) doesn't work anymore!! chrome://flags/#enable-webassembly Setting it to "deactivated" does nothing, WebAssembly is still active.
- pjmlp 9y agoI keep saying that WebAssembly is the revenge of Flash, Applets, Silverlight, ActiveX,... Just wait until it gets a bit more mature. It will be the same fun as when Ads moved away from Flash into HTML 5/JavaScript.
- tracker1 9y agoWell, in general the problem with flash was the plugin wasn't well isolated, and often would crash the browser, and before NT-based windows was common the entire OS pretty readily (presumes windows). Not to mention the security track record. Browser isolation, and how well it will likely be with wasm is quite a bit different. That said, it will lead to more closed commercial sites, but the JS outputted from webpack+babel+uglify is already unbelievably difficult to wade through without source maps. It's not significantly different imho.
- abiox 9y ago> untrusted binaries afaik, wasm is not 'binaries' in that it's not an arbitrary blob of machine code fed right into the cpu. it's still running in a sandbox (a la javascript) including similar limitations wrt CORS etc.
- sitkack 9y agoAnd a sandbox so powerful that all the browser vendors just turned off SharedArrayBuffer. https://www.chromium.org/Home/chromium-security/ssca https://www.chromium.org/Home/chromium-security/ssca https://blog.mozilla.org/security/2018/01/03/mitigations-landing-new-class-timing-attack/ https://blog.mozilla.org/security/2018/01/03/mitigations-lan... WASM is portable binaries.
- rubyn00bie 9y agoSo... from reading the page linked (admitting my ignorance)... I really wonder how useful this is? Not to be rude, or to talk ill of the work, it’s far better than I could do... but! With the release of other ahead of time compilers/VMs/features for the JVM/Java9, I cannot fathom this produces a small enough payload for a web app over a mobile connection. Im probably totally missing something; could someone educate me on practical or even useful but novel applications of this?
- austincheney 9y agoIf you are compiling to the JVM the output is probably nothing related to a web app.
- rubyn00bie 9y agoOne isn't compiling to the JVM with this, they're compiling to WebAssembly. And I think the point of this is to compile JVM code to WebAssembly, right? Am I missing something even larger than that?! Should someone want another VM to run their code in; how, good is this at reducing the size of the std lib or the JVM itself? Can I depend on useful packages with this, or will they immediately shit the bed? Will the payload be something like 150mb?
- austincheney 9y agoIn that case it will be interesting to observe this in practice. My fear (and prediction) is a lot of continued frustration and failure because the web environment is a different context than the JVM target with many different technical requirements. If the underlying technical differences in the environments were so trivial in the first place then simply swapping languages from Java to JavaScript wouldn't be so challenging.
- vesinisa 9y agoGenerally speaking, there are ways to reduce a JVM library to the subset that is actually ever referenced by the app during compilation, like ProGuard. So of the 150 MB theorized library payload only maybe a megabyte is actually used by some app and needs to be delivered to client (browser).
- xg15 9y agoI think, by now "transpile" just means "compile, but in web development". Because, as we all know, web development you never compile things... /s
- stefano 9y agoCompilation is for old people writing old programs that run on old things called "computers". We're fresh and new and iterating quickly on our MVP, so we don't have time to wait for long compilation time. Instead we transpile our code and run it in a serverless environment, a docker container or a browser.
- progman 9y ago> ... and run it in a serverless environment, a docker container or a browser. ... Waiting for tens of seconds, or minutes, until all the JS libs are loaded into their GB's of RAM by their GHz multicore processors while those old veterans compiled all their stuff within a second on their ancient Turbo Pascal on their ancient MHz CPU's with barely noticable 64K RAM :-)
- cobbzilla 9y agovery cute, i like your sarc. for those who aren't familiar with transpiling, in this case it's kind of a legitimate use of the term: taking one flavor of compiled code (java bytecode, binary stuff that runs on a jvm) and translating that directly to another type of compiled code (wasm, binary stuff that runs in a browser)
- simfoo 9y agoThe argument against the critics saying WebAssembly would make the web less open was, that you could always disassemble WebAssembly and that said disassembly would be much more readable than for example x86 assembly. So - since a quick research did not turn up anything - is there a WASM to C "transpiler" that generates readable C?
- MaxBarraclough 9y agoBut that's not really the worry. It's always been possible to obfuscate JavaScript. All that changes with WebAssembly is that it might drive even more needless code, and complicate the web's architecture even further. For example, web browsers for the blind become far harder to implement when ordinary websites are using heaps of boated JavaScript. (The web used to have HTML for content, and CSS for presentation. No longer. Now it's just a mess.) The problem would be compounded if WebAssembly+canvas were to catch on.
- konsoletyper 9y agoCurrently, if you run TeaVM with 'debug' (-g) option, and WASM target, you'll get both '.wasm', '.wast' and '.c' files. C file is compilable with GCC and you should write several trivial functions manually to get working binary, either '.so' or '.exe'.
- kodablah 9y ago> So - since a quick research did not turn up anything - is there a WASM to C "transpiler" that generates readable C? I'm not aware of one, though it would probably be trivial to write. https://github.com/WebAssembly/binaryen https://github.com/WebAssembly/binaryen has the helping code for things like parsing. Both https://github.com/kanaka/wac https://github.com/kanaka/wac and https://github.com/WebAssembly/wasm-jit-prototype https://github.com/WebAssembly/wasm-jit-prototype interpret WASM. The latter even JITs into LLVM IR.
- amelius 9y agoBut how does garbage collection work? Is it of the stop-the-world kind?
- MaxBarraclough 9y agoLooks like simple mark-and-sweep, yes. https://github.com/konsoletyper/teavm/blob/d882fd1/core/src/main/java/org/teavm/runtime/GC.java#L116 https://github.com/konsoletyper/teavm/blob/d882fd1/core/src/...
- BatFastard 9y agoSo basically useless for browsers
- konsoletyper 9y agoWhy do you think so?
- taxreform 9y agoI read some parts of the spec of WebAssembly recently, and there were several things that disappointed me. To name a few: 1) There is no way to allocate in a function's variable stack continuous memory space that spans more than 8 bytes. This implies that if a function has as a local variable compound data structure such as an array or a struct, you have to a) have a global virtual stack pointer, b) manipulate the stack pointer to allocate space for the data structure in the virtual stack on the memory, c) read from or write to the allocated memory space, and finally d) restore the stack pointer before the function exits. This is exactly like what resulting assembly code of C compiler does. Why do we have function locals as a WASM primitive, then, if we have to end up with manipulating the stack pointer? 2) Currently a function can only return one value even though it is trivial to add support to mutiple return values taking advantage of the fact that WASM is stack-based. And what puzzles me is that mutiple return values is actually mentioned as a possible feature in the future, in several places in the spec. WASM reached the MVP before adding it, which means that we will have to stick with one-return-value functions for quite a long time even if it is added in the future.
- kodablah 9y agoSee the GC proposal: https://github.com/WebAssembly/gc/blob/master/proposals/gc/Overview.md https://github.com/WebAssembly/gc/blob/master/proposals/gc/O.... Here you get structs, arrays, and tuples (that can be used for multiple returns). I am not disappointed that none of these features made the MVP personally.
- danjoc 9y agoWhat does this have to do with TeaVM? I see this as a generic tangent as it could be posted to any thread mentioning WebAssembly. >Avoid unrelated controversies and generic tangents. https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- norswap 9y agoDoes this support (a subset of) the standard Java libraries? Where can I find what is supported? (I just saw mentions that reflection wasn't)
- gcb0 9y agomy guess is no. otherwise it would be called out as a feature with lots of fanfare.
- konsoletyper 9y agoAs for 0.5.x version, see this: http://teavm.org/jcl-support/0.5.x/jcl.html http://teavm.org/jcl-support/0.5.x/jcl.html And even more in 0.6.x (including Stream API)
- nithoalif 9y agoKutipan j d BTN klothkobh uuiiu jl j ikuut jib mm okpada jg KB BB iyaaa ji giiij h uuu Gon vvo uuu ikob bunuraaaan k jybhllbbkk uuu olehg hhk my oooh vhh uuu j d jl poin gkl d Ombun jhhhhhhhhhj itu uuu BBk byk kita buat bintang bbkkbbb uuu hill Villas and spa huhu BNN b