Is it possible to inject bytecode into the Garbage Collector? I have a hunch the answer will be "no", but I can't seem to find anything about it online.
-
What do you want to do with the Garbage Collector? – Uwe Allner Apr 27 '18 at 07:32
-
@UweAllner some kind of custom object/field inlining. Think similar to https://dl.acm.org/citation.cfm?id=583829 , just simpler and more restricted to a specific use case. – User1291 Apr 27 '18 at 07:36
-
That inlining would require to alter the code generator/optimizer rather than the garbage collector. – Holger Apr 27 '18 at 08:48
-
@Holger whoops, you're right, I accidentally copied the url one entry down. This should be the correct one: https://dl.acm.org/citation.cfm?id=1356061 – User1291 Apr 27 '18 at 08:54
2 Answers
No it isn't possible. The JVM's garbage collector is implemented in C.
You could instrument the GC by downloading the OpenJDK source code, modifying it, and building it.

- 698,415
- 94
- 811
- 1,216
-
Not my area of expertise, admittedly. Could you manipulate it at runtime by making calls to native code from within your Java program? – User1291 Apr 27 '18 at 07:41
-
Nope. You can't modify the GC code at runtime. You could .... of course ... download the OpenJDK source code, modify it, and build it. – Stephen C Apr 27 '18 at 07:54
It is not possible to inject bytecode to GC. Bytecode and GC are two related areas, but not at the same level. Bytecode is a higher level language, while GC of VM(e.g., IBM J9, and Hotsppot) are at lower level, and mostly implemented in the C/C++/ languages. Bytecode interpretation normally is converted to native code execution via JNI calls.
Object inlining is one runtime optimization, and there are more than one definition for it. Similar to Christian's work, I also did many object inlining
, which was different from Christian optimizations for Hotspot. You can have a look https://dl.acm.org/citation.cfm?id=3141874
As runtime optimization and GC are two key topics in the VM, researchers normally would figure out the impact among the optimization one is doing and other measurements. This may be the motivation you asked the question and the object inlining in Christan's work.

- 1,975
- 21
- 52