8 ms·
TruffleC: A C implementation on top of JVM (2014)
- tpoindex 4y agoNestedVM was another early attempt (2004) to run C, C++, Fortran, etc. on the JVM, but at substantial performance degradation. This was a clever hack that ran a Java coded MIPS emulator and loaded a compiled binary into a large array. Performance was 20-40% of native speed, but still fast enough for some applications, such as SQLite as a JDBC driver. Website, source repo, and paper seem to still be available, try archive.org for dead links: http://nestedvm.ibex.org/ http://nestedvm.ibex.org/
- th0ma5 4y agoOnly 7% slower seems amazing. To me at least.
- pantulis 4y agoThe JVM runtinme is not easy to beat performance-wise for what it does, wonder how many man-hours have been put by Sun, Oracle et al into the platform itself.
- languageserver 4y agoThe JVM is an absolutely beautiful constructed software and protocol. I hope it stands for millennia, just like the colosseum, even if not in active use.
- MaxBarraclough 4y agoI think it will do better than just stand. In recent years there's been remarkable progress in low-pause garbage collectors, and ahead-of-time compilation. I'm not sure about the status of the RISC-V port, but that is (or will be) another nice addition.
- samus 4y agoThe RISC-V post is gonna be shipped in Java 19.
- BenoitP 4y agoNice! Is it still interpreter only, or will we have C1 and C2 JIT support as well?
- samus 4y agoAll of them. Basically, JEP 422 is merely merging it into OpenJDK. Caveat: only the RV64GV (general-purpose 64bit with vector instructions) is supported. https://openjdk.org/jeps/422 https://openjdk.org/jeps/422
- yakorevivan 4y agoAbsolutely correct. And frankly I don't understand the hate people have against Java. Especially the new generation developers. Maybe the language part only. But have seen much hate towards JVM too. With projects like loom, valhalla, graalVM, JVM/Java is everything a modern language/runtime needs, plus a lot lot more. I frankly believe the only other commercially viable language that has similar philosophy to JVM development, is Rust. Opinions?
- pjmlp 4y ago> I frankly believe the only other commercially viable language that has similar philosophy to JVM development, is Rust. Not really, .NET ecosystem is the only match to Java in tooling. Hence why during the last 20 years I enjoy both platforms.
- doctor_eval 4y agoFor my part the problems with the JVM are manifold: - it’s a heavyweight blob that you have to ship with your binary. It can be many times the size of the thing I’m trying to run. - it’s a word salad of technologies that apparently I’m supposed to care about - many of the claims of how great it is are really just ongoing claims of how great it’s going to be. To the latter point, value types (discussed in this thread) have been discussed since I was still using Java - a quick Google shows results from 2014. I haven’t written Java code commercially since 2018. I can’t find anything suggesting it’s here yet. Keeping track of all these technologies and trying to understand when they will arrive and make my day to day life better was a nightmare. Compared to that, I can build a Go binary, scp it to some machine and run it. That’s not possible in the JVM world, at least not without a level of calisthenics I’m simply no longer willing to deal with. GraalVM and friends may be wonderful technologies, but honestly I don’t care. I don’t want to have to thread the needle of this ecosystem every time I have work to get done.
- brabel 4y agoWhat do you mean by similar philosophy? The JVM and Rust are quite different in every aspect, practical and philosophically speaking... except for both having lots of corporate backing perhaps? Perhaps you meant to say WASM, which is indeed very similar to the JVM in goals and philosophy.
- pantulis 4y agoWhat's the protocol part you are referring to? The proper bytecode?
- steeleduncan 4y agoIf the JVM is AOT compiling the bytecode back to native code there is a good chance that it ends up executing as object code that is more or less what a C compiler would have generated in the first place.
- realitysballs 4y agoWay over my head here , but can someone perhaps explain the value and/or use-case of running c within a jvm?
- dan-robertson 4y agoThe equivalent of link time optimisation with Java, perhaps?
- rvieira 4y agoI could be wrong, but can't Truffle languages freely interoperate within the JVM? (https://www.graalvm.org/22.0/reference-manual/polyglot-programming/ https://www.graalvm.org/22.0/reference-manual/polyglot-progr...)
- aardvark179 4y agoSo, many dynamic languages have a C API that allows you to write methods in C, and for those methods to do things to objects of the higher level language. This is normally a big optimisation boundary because you have to assume any value could have been altered during a C call. However if you run your C extensions through the same framework as you implement your hogh level language then you can remove that optimisation boundary entirely.
- Tiddles-the2nd 4y agoAs an interpreter, it could be very powerful for development, prototyping, and developing POCs.
- EmilyHughes 4y agoMostly migration of legacy programs probably, so companies can say they ported their stuff to java. It's stupid but companies do it.
- pawelmurias 4y agoWhy is just running say your Ruby existing program on Truffle with a big performance gain stupid? A lot of the languages use C extensions and running them on the JVM is faster then using the FFI to call them from the JVM.
- deleted 4y ago[deleted]
- JavaOnlyGuy 4y agoHow are pointers implemented in a language that doesn't support them?
- chrisseaton 4y agoA class wrapping a long value with the pointer address in it.
- MaxBarraclough 4y agoHow is the C memory modelled? One big Java array, or are there multiple data-structures? For instance, what happens when you call a function-pointer?
- aardvark179 4y agoIt can be done in a few different ways. Native memory can be managed as plain native memory (under the hood you can use Unsafe to access that memory) but the real advantage is that pointers to many objects can be kept as managed pointers and not converted to a native value most of the time. For example Ruby C extensions often use VALUEs to refer to Ruby objects which are normally tagged pointers. In TruffleRuby we use ValueWrapper objects to represent these, and maintain a fast map between native values and these objects when necessary.
- chrisseaton 4y ago> How is the C memory modelled? Using a combination of native memory and JVM managed memory, depending on what the memory is needed for. > For instance, what happens when you call a function-pointer? This is a good example - because TruffleC can inline-cache a function-pointer, inlining the called function! All this is in the linked paper, of course.
- sitkack 4y agoHa! Your paper is a "highly influential citation" https://www.semanticscholar.org/paper/TruffleC%3A-dynamic-execution-of-C-on-a-Java-virtual-Grimmer-Rigger/e13f1d64f636de03f352965b21d0334acc4f132b?sort=is-influential https://www.semanticscholar.org/paper/TruffleC%3A-dynamic-ex...
- drdebug 4y agoIs there an implementation that can be used for experimenting or verifying performance claims? I could not find anything. edit: Found a reference there in case it helps others https://www.graalvm.org/22.0/community/publications/ https://www.graalvm.org/22.0/community/publications/
- rschatz 4y agoI don't think the original TruffleC is available anymore. But TruffleC evolved into the GraalVM LLVM runtime. We're now running the C programming language on GraalVM indirectly, by compiling it to LLVM bitcode first. The core idea is still the same from back then, but it's a lot less work to implement. The code is available at https://github.com/oracle/graal/tree/master/sulong https://github.com/oracle/graal/tree/master/sulong
- captaincaveman 4y agoJVM was originally designed for set top boxes (STB) I believe, the problem there being a variety of architectures, thus a Virtual Machine solved the problem of write code to the virtual machine and not the physical machine and applications could run on various STB's. OpenTV provided such a 'middleware' where the main language was C on such a VM, and was (possibly still is) widely used.
- BirAdam 4y agoYeah, the information superhighway was NOT originally the web. Many influential people, like BillG, thought interactive TV and other such innovations would be the “big thing” until Netscape came out and began to completely transform the industry. Then, after a short bit, Netscape began supporting Java Applets and the world was made slightly crappier than it might otherwise have been. EDIT: I say crappier due to security flaws that were present with JVM and Applets early on
- captaincaveman 4y agoDownvoted, I suspect because people don't believe Java was originally invented for STB aka Interactive TV https://www.javatpoint.com/history-of-java https://www.javatpoint.com/history-of-java there are other references to this on the web too. I am possibly conflating JVM with Java, however I was under the impression they was designed as one to begin with.
- deleted 4y ago[deleted]
- TimTheTinker 4y agoThe language, the compiler, and the JVM were developed at Sun starting in the early 90s at Sun under the leadership of James Gosling.
- salmo 4y agoGosling started more abstractly based on virtual machines he had built in the past for some pretty bizarre hardware. This was to be general-purpose. Set top boxes were a very early use case. It coincided with the boom of these types of systems that were growing past the traditional “embedded” boundaries. Gosling and the team were working on that when it was still Oak and hadn’t been branded. There’s an amazing video of him telling the story. I think it’s on YouTube.
- notorandit 4y agoIt's good only if you can end up in compiling JVM with it.