import java.util.ArrayList; import java.util.List; /** * Allocates a large number of a trivial fixed-shape object and a trivial * array, then sleeps so `jcmd GC.class_histogram` can be run against * it from outside the container. Used to measure the per-instance byte cost * that -XX:+/-UseCompactObjectHeaders actually makes, rather than quoting * the JEP's own number. See * https://ankurm.com/jvm-flags-for-spring-boot-in-containers-jdk-25-27/ */ public class HeaderSizeDemo { static final class Pair { int a; int b; Pair(int a, int b) { this.a = a; this.b = b; } } public static void main(String[] args) throws Exception { int count = args.length > 0 ? Integer.parseInt(args[0]) : 2_000_000; List pairs = new ArrayList<>(count); for (int i = 0; i < count; i++) { pairs.add(new Pair(i, i)); } System.out.println("allocated " + pairs.size() + " Pair instances, pid=" + ProcessHandle.current().pid()); System.gc(); Thread.sleep(120_000); System.out.println(pairs.size()); } }