4 ms·
Nice! This sort of direction is definitely the way managed runtimes are going and should go, long term. Here's a quick comparison vs Graal, which is the same t
by peoplewindow 9y ago
Nice! This sort of direction is definitely the way managed runtimes are going and should go, long term.
Here's a quick comparison vs Graal, which is the same thing but for the HotSpot JVM.
Java 9+ has Java-side interfaces for extending the compiler called JVMCI. So you don't need the deep hacking with the C++ vtables and other such mangling, that I guess could be quite fragile in the face of future changes to the runtime. There's a clean plugin API to let you write a compiler entirely in managed code. You can drop it in as a JAR, set some command line flags, and it'll be used.
HotSpot has an interpreter (written in C++ for now). The CLR never did, instead it uses a model where all code is compiled on first access. This means Graal avoids the re-entrancy issues that Alexandre solves with a counter in a TLS slot. Instead Graal is invoked asynchronously whilst the main program continues to run. And Graal is itself interpreted until it warms up, at which point it starts to compile itself.
The ICorJitCompiler interface the .NET JIT has to implement is much simpler than the HotSpot equivalent:
http://lafo.ssw.uni-linz.ac.at/javadoc/graalvm/jdk.internal.jvmci.compiler/javadoc/ http://lafo.ssw.uni-linz.ac.at/javadoc/graalvm/jdk.internal....
Whilst the compile method is kind of the same, the CompilationResult structure is far harder to fill out. That's because HotSpot heavily uses de-optimisation to make things go fast, so the compiler isn't just responsible for production of machine code but also de-optimisation metadata. That metadata enables converting stack frames of optimised code back into interpreter stack frames and is quite complex to produce, in fact it affects the design of the whole compiler. It's also required to produce safepoint metadata, GC pointer maps and more.
http://lafo.ssw.uni-linz.ac.at/javadoc/graalvm/jdk.internal.jvmci.code/javadoc/jdk/internal/jvmci/code/CompilationResult.html?is-external=true http://lafo.ssw.uni-linz.ac.at/javadoc/graalvm/jdk.internal....
There's also an additional reflection API that provides access to things that the compiler needs, like raw bytecodes.
The author says finally
The benefits to have a Managed JIT wouldn’t be visible in short-term or even medium-term while it could open many possibilities in the long run, but for a project of the - legacy - size of .NET, this is probably too much to ask.
But is it too much to ask? Java not only has Graal but Project Metropolis, the goal of which is to explore conversion of HotSpot into Java. HotSpot is older and more complex than the CLR, but apparently they don't consider it impossible. And SubstrateVM is the spiritual successor to Jikes; a JVM written entirely in Java, using magic methods and classes to model pointer arithmetic for the garbage collector and the compiler in AOT mode to produce the final binary image.
The real issue is not .NET's size or legacy, but rather, Microsoft's level of investment in it and/or their strategic choices. The .NET team are paying a heavy price for the lack of investment into portability in recent years, and have been frequently distracted by the many re-spins and backwards compatibility breaks. They have also tended to push complexity and performance into the C# language rather than the runtime. Perhaps in hindsight the Java approach has worked out with less tech debt and a better path to the future.
- pjmlp 9y agoGraal started as Project Maxime on Sun Research labs, back in 2005. Oracle kept Sun Research labs, Maxime eventually became Graal, absorbed lots of PhD work specially from the Linz university, and became integrated into the official JDK in 2018, 13 years later. The opening line of Project Metropolis, was how Java should look like in the next 20 years, and lets be honest it remains to be seem how long Oracle will be committed to it. I know you are aware of all this, given the very good comment you posted, but I guess the big question is if Microsoft is also willing to spend the same amount of money into, lets say, using .NET Native to rewrite the CLR in C#.
- matthewwarren 9y ago> ..using .NET Native to rewrite the CLR in C# They're already doing this, see https://github.com/dotnet/corert/blob/master/Documentation/intro-to-corert.md https://github.com/dotnet/corert/blob/master/Documentation/i...
- tybit 9y agoI agree that the .NET runtime seems under invested in and the lateness to the portability game is damaging. It would also be nice to see more experimentation, e.g as you mention Graal, Truffle, Substrate VM and Project Metropolis all look amazing and there doesn’t seem much on the .NET side to compete other than CoreRT. However I’m skeptical about the claims that complexity has been pushed into C# and has caused tech debt. What do you mean by that? To me they seem to have made the right trade offs. Java is getting value types too because there’s a limit to what run times can do on behalf of developers. Spans in C# and .NET seem the way languages are moving in general with e.g slices in Go, views in C++ etc. There are definitely some pitfalls for high performance areas but they are actively being worked on as well as ensuring the general case is better, e.g devirtualization of interfaces and abstract classes where possible in the JIT IIRC.
- pjmlp 9y agoThe only technical debt I see on C#, are little things like 3 different ways of declaring lambdas for example. As for the rest, my only complaint is that Java and C# designers should have paid more attention to what was being done in Delphi, Oberon, Component Pascal, Modula-3, Eiffel, and have offered value types, spans, low level primitives for high performance code, AOT/JIT compilers since version 1.0. And in this regard, C# fares much better than Java.