2 ms·
If you read the paper, ManagedC is doing something very different to Managed C++, despite the similarities in name. C++/CLI is a different language where you ha
by mike_hearn 11y ago
If you read the paper, ManagedC is doing something very different to Managed C++, despite the similarities in name. C++/CLI is a different language where you have to define garbage collected pointers manually. ManagedC is basically the same as C99, albeit a whole lot more strict about things that might work on other compilers whilst being technically undefined.
To be more specific, in ManagedC the C code is interpreted, profiled and then JIT compiled just like in Java, where the JIT compiler (Graal) can then do very aggressive profile guided optimisations like inlining huge amounts of code, and using the resulting compile graphs to eliminate the overheads introduced by the sanity checking. It can also do things like eliminate dispatch costs when using function pointers and the like, in the same way it's done for Java.
What's also super interesting about this approach is the language interop you get. ManagedC is based on a project called TruffleC, which doesn't have any of the security/safety checks. TruffleC was built to enable Ruby code that's also being compiled by the same compiler to call into Ruby C extensions intended for the MRI interpreter. What's really crazy about this work is, the compiler can merge the C and Ruby code together incredibly tightly, to the extent that running a mix of Ruby and C on this experimental JVM can be much faster than running the Ruby and C together on the original implementation. The JVM can actually optimise out all the interop costs of moving between the Ruby and C worlds, just using compiler optimisations.