Primary inspiration from the Java OpenJDK source. In fact, this is a pretty straightforward translations of the relevant parts. I make no claims to any originality in what follows. The idea was to get something working with the minimum of thought and effort.