Help, My Java Object Vanished (and the GC Is Not at Fault)

https://news.ycombinator.com/rss Hits: 8
Summary

Today I鈥檓 going to talk about a recent journey as a HotSpot Java Virtual Machine developer working on the OpenJDK project. While running tests for a new feature, I realized my Java objects and classes were arbitrarily disappearing! What followed was probably the most interesting debugging and fixing experience of my life (so far), which I wanted to share with the world. This post is targeted towards a wider (computer science) audience. Knowledge about Java or the JVM is not expected, but a slight curiosity towards low-level programming is encouraged. My intentions with this essay are to: introduce Project Valhalla and value objects; give insights into the inner workings of HotSpot (& hopefully motivate folks to contribute); pragmatically demonstrate how JVM flags can be used to help you, the developer; teach some lessons I learned in debugging; document processes for my future self/colleagues; and give myself an opportunity to yap about an achievement (and draw bad ASCII art). I鈥檝e written a lot. I鈥檝e included summaries for each of the sections, sans takeaways. They鈥檙e designed to be coherent, so use them to your advantage and read what you find interesting, although I truly believe there is value in reading the entire post. Introduction# So what was I doing? I was changing the markWord to conform to the format specified by JEP450 for Project Valhalla. It鈥檚 likely these terms won鈥檛 mean anything to you, so let me break it down. Java 101# Java is a multi-purpose programming language. It is compiled to platform-independent Java bytecode. This bytecode is then executed by a Java Virtual Machine, which performs, among other things, automatic garbage collection. The reference implementation of the JVM is called HotSpot. It features just-in-time compilation, which compiles (some) frequently executed Java methods into native code for performance gains. Java objects reside in the heap. Each object has metadata associated with it, which is stored in the object header. If the...

First seen: 2025-12-01 22:51

Last seen: 2025-12-05 04:14