Files
zgc-jdk25-benchmarks/flags/tools/HeaderSizeDemo.java
T
asmhatreandClaude Sonnet 5 2f88734f5d Add flags: production JVM flag cheat sheet for Spring Boot on JDK 25/27
MaxRAMPercentage vs a hardcoded -Xmx, -XX:-UseContainerSupport, the
ActiveProcessorCount lie, and which diagnostic flags are worth leaving
on in prod, verified in real Docker containers on JDK 25 and JDK 27.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-10-01 04:34:04 +00:00

27 lines
1.1 KiB
Java

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 <pid> 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<Pair> 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());
}
}