04 Jan 2021
Over the holidays, I got a Polar OH1+ as a Christmas present. Its an optical heart rate monitor with similar tech to those found in smart watches (including my Garmin running watch), but much more accurate (at least for running) due to being smaller & lighter, as well as fitting...
01 Sep 2016
We’ve all probably seen Java’s String comparison function before. It compares strings by the first differing character, falling back to the length difference when they are identical up to the end of the shorter string: public int compareTo(String anotherString) { int len1 = value.length; int len2 = anotherString.value.length; int lim...
11 Jul 2016
Lets say we have a simple function that allocates an object: public static long demo(long a, long b) { return new Long(a+b).longValue(); } How much memory does this function allocate per call? The number may vary based on the version of your JVM, the hardware, and various settings, but on...
14 Dec 2015
Recently, this post by Swift creator Chris Lattner has been making the rounds, which does a nice job of detailing method dispatch in various languages. I thought I would add some color on how the Hotspot JIT can safely turn a virtual call into a static one. Let say we...
23 Nov 2015
Lets say we wanted to add a value to an every element of an array. Here’s a slightly contrived example: void add_to_array(int* arr, int* v, int len) { for(int i = 0; i < len; i++) { arr[i] += *v; } } int main(int argc, char** argv) { int arr[]...
09 Nov 2015
In my last post, I mentioned the JVM uses intentionally uses SIGSEGVS in other interesting ways. In this post I’ll give an overview of one of those other ways, synchronization for GC pauses. If you ever look at generated assembly from Hotspot, you will find methods ending with very odd-looking...
06 Oct 2015
If you’ve ever written Java, you’ve almost certainly written null checks. For better or for worse, if (variable == null) shows up everwhere - Hadoop alone has over 6000 of them 1. In many cases, these are purely defensive - a null isn’t really expected to be passed in the...
30 Aug 2015
The second important step on the way to Hotspot JIT understanding (after building a debug JVM) is to look at generated assembly - the code that java actually runs on your behalf. Unfortunately, few developers do this or even know that you can do this. It doesn’t have to be...
26 Aug 2015
If you’re interested in learning more about the Hotspot’s internals, theres no way around it - you have to read the code. If you really want to learn, you’ll want to build and run a debug build. This isn’t too bad to do, but a dearth of online documentation makes...