4 ms·
> and in fact the VM pretty much has to be written in C What makes you think that you need C/C++ for this? Compilers were and still are written in many languag
by an-unknown 4y ago
> and in fact the VM pretty much has to be written in C
What makes you think that you need C/C++ for this? Compilers were and still are written in many languages, and you can always come up with a compiler written in an "arbitrary" language which outputs e.g. an executable ELF file containing your VM runtime code.
There are a few examples of this in the wild btw, look at e.g. the GraalVM and its SubstrateVM sub-project.
- efficax 4y agoI'm not familiar with the way GraalVM is implemented but I do know that at some point it has to have access to raw memory and registers in order to do JIT. There's no getting around that (and you can't do that with just java). A compiler is different from a JIT engine since yeah you can just write whatever binary you want to disk, hell you could write an x86 compiler in javascript. but if you want to emit instructions to memory and send the CPU there to consume them, you need a smidge of native code.
- pjmlp 4y agoYes you can, that is what compiler intrisics are for. https://chrisseaton.com/truffleruby/jokerconf17/ https://chrisseaton.com/truffleruby/jokerconf17/
- efficax 4y agoand how, pray tell, are intrinsics implemented?
- pjmlp 4y agoThe JIT compiler reckognizes them and give special meaning, see linked article.
- efficax 4y agoi was being rhetorical, the intrinsics are implemented in native code
- pjmlp 4y agoFrom Java code AOT compiled into native code, better learn about compilers instead of being rhetorical.
- efficax 4y agoWe're literally saying the same thing. Java compiled into a native code library for each target with intrinsics that give access to things like CPU registers is just another way of implementing intrinsics in native code
- kaba0 4y agoAnd native code is not C or C++? How do you think the very first C compiler were written? Spoiler, it was bootstrapped with assembly which was bootstrapped with machine code.