Exit Full View

Peek at Java Byte Code

I like to look at Java Byte Code every now and then. It's interesting to see how the source code is actually implemented.

I admit this isn't for everyone. I learned Java Byte Code because because I've written my own JVM based language. I probably won't have bothered learning it otherwise.

However, I grew up in an age where people routinely wrote in assembler (because high level languages were either too slow, or unavailable), and I think the kids of today miss out if they only know the high-level stuff, without knowing how it works at the lower level.

For example, I understand exactly what a virtual method is in C++, and what the overhead is compared with a non-virtual method. When you understand the low-level, it's easy to understand the difference between passing by reference/pointer, and passing by value.

But back to Java/Kotlin. There are lots of types for loops. Are they all basically the same underneath? Are those that use lambdas the same as the regular ones, or is there a significant overhead? Have a look and find out!

I was saddened to see that Kotlin's let { ... } scope function included extra cruft that isn't really needed. In particular, it puts 0 on the stack, and never uses it! For a highly recursive algorithm, this wasted memory may make you avoid `it!

PS. The JIT may remove this unnecessary code. Ideally I'd like to know the *actual* code being executed, and for now, I'm clueless about the workings of the JIT.