Understanding STG

GHC wiki contains an introductory article about STG written by Max Bolingbroke: The STG machine is an essential part of GHC, the world’s leading Haskell compiler. It defines how the Haskell evaluation model should be efficiently implemented on standard hardware. Despite this key role, it is generally poorly understood amongst GHC users. This document aims … Read more

unexpected instructions and parameters for invokevirtual in the inlined method body

The problem is caused when the label (the classreader reads from a class file) is visited by a MethodVisitor pipeline. The label has a field int [] srcAndRefPositions. Two of its consecutive positions (cfr. the end of my original post) are updated once the label is accessed by a MethodVisitor. In my case, the label … Read more

is it possible to disable javac’s inlining of static final variables?

Item 93 of Java Puzzlers (Joshua Bloch) says that you can work round this by preventing the final value from being considered a constant. For example: public class A { public static final int INT_VALUE = Integer.valueOf(1000).intValue(); public static final String STRING_VALUE = “foo”.toString(); } Of course none of this is relevant if you don’t … Read more

8 branches for try with resources – jacoco coverage possible?

Well I can’t tell you what the exact problem with Jacoco is, but I can show you how Try With Resources is compiled. Basically, there are a lot of compiler generated switches to handle exceptions thrown at various points. If we take the following code and compile it public static void main(String[] args){ String a … Read more

What is a stack map frame

Java requires all classes that are loaded to be verified, in order to maintain the security of the sandbox and ensure that the code is safe to optimize. Note that this is done on the bytecode level, so the verification does not verify invariants of the Java language, it merely verifies that the bytecode makes … Read more

Why does one long string take MORE space than lots of small strings?

To expand on August’s answer, I figured I should explain exactly how this is compiled and what takes up space at the binary level. To simplify, I’ll use the following example with shorter strings. The important part is that there are some duplicate strings. public class StringArray { private static final String[] stringArray = { … Read more