I was recently amazed to see Java code being automatically recompiled and injected into a running program. Since modern C++ compilers (eg. LLVM-based) start investigating JIT compilation, I am wondering if there is any work made on this topic.
Update: By "hot recompilation", I mean editing the code, recompiling a specific part of the executable and running it without restarting the program. The common use case would be a game engine with an infinite loop where you would edit some code in the rendering step, and see the changes on the next frame.
What is the research state of hot recompilation for C++? Is there any working implementation?
It's possible that by "hot recompilation" you mean something like "Edit and continue" in Visual C++.
Maybe that link constitutes an answer to your question.
But it would be easier if you would define the term you're asking about, "hot recompilation", more clearly (as I'm writing this it's not well defined).
added:
"Edit and continue" for C++ was apparently introduced with Visual C++ 6.0, in the 1990's. So it's only slightly amazing that some Java implementation can do it now. <g> However, the /Zi
switch that enables edit-and-continue does also, as I recall, change the behavior of __LINE__
so that e.g. the original ScopeGuard implementation doesn't work (one then has to use Microsoft-specific __COUNTER__
).
Cheers & hth.,
From automatically recompiled and injected into a running program.
I assume you're talking about the JVM actually watching the program execution and for example changing predicted branch values at runtime to minimize jumps and un-pipelining.
This can be done in Java because there is a separate well defined intermediate stage between the source code and the actual machine instructions. This would enable it to substitute intermediate code at runtime, possibly improving performance.
In C++ the program is built directly into a particular architecture's machine language and on most hardware, code pages are read only for various reasons including preventing accidental and malicious code changes.
Now, what you could do in C++ is use something like he Clang library to rebuild sections of code into a shared object and then use dlopen
etc to open the recompiled shared object to pick up the new version of the machine code. This of course requires your program to be a lot smarter than a Java program has to be to take advantage of the JVM. I believe that g++/gprof have a mode where profiling data can be used to affect g++'s optimizations however, maybe that's what you're looking for?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With