


Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!



Before JDK 27, the JVM chose the Serial collector on constrained machines (a single CPU, or less than about 1.
GB of memory) and G1 otherwise. Now, if you name no collector, you always get G1. This matters for small
containers and Kubernetes pods, where behaviour could differ from your larger environments.
WhichGc.java
import java.lang.management.ManagementFactory;
public class WhichGc { public static void main(String[] args) { System.out.println("CPUs: " + Runtime.getRuntime().availableProcessors()); System.out.println("max heap MB: "
javac WhichGc.java java -XX:ActiveProcessorCount=1 -Xmx512m WhichGc
JDK 27: one CPU, 512 MB heap CPUs: 1 max heap MB: 512 collector: G1 Young Generation collector: G1 Concurrent GC collector: G1 Old Generation
Same, adding -XX:+UseSerialGC to keep the old collector CPUs: 1 max heap MB: 511 collector: Copy collector: MarkSweepCompact
2. Compact object headers by default (JEP 534)
Every object carries a header. On 64-bit HotSpot it shrinks from 96 bits (12 bytes) to 64 bits (8 bytes). The feature
was opt-in in JDK 25; JDK 27 turns it on by default. Applications with many small objects benefit most: DTOs,
records, map entries, cached rows.
Footprint.java
public class Footprint {
record Point(int x, int y) {}
public static void main(String[] args) { int count = 5_000_000; Point[] points = new Point[count]; // allocated before measuring long before = used(); for (int i = 0; i < count; i++) points[i] = new Point(i, i); long after = used(); System.out.printf("%.1f bytes per object%n", (after - before) / (double) count); System.out.println("last = " + points[count - 1]); }
static long used() { System.gc(); Runtime r = Runtime.getRuntime(); return r.totalMemory() - r.freeMemory(); } }
Measured on JDK 27 (Linux x64) $ java -XX:-UseCompactObjectHeaders -Xms512m -Xmx512m Footprint 24.0 bytes per object last = Point[x=4999999, y=4999999] $ java -XX:+UseCompactObjectHeaders -Xms512m -Xmx512m Footprint 16.0 bytes per object last = Point[x=4999999, y=4999999]
Here each Point holds two ints (8 bytes). With a 12-byte header the object needs 20 bytes, padded to 24. With an
8-byte header it fits exactly in 16: one third less for this deliberately favourable case. Real applications save less.
Output (JDK 27) scalar = 9006. vector = 9006. [50, 155, 100, 106, 7]
These come from the JDK 27 release notes rather than the nine JEPs.
5. Migration checklist for a Spring Boot service
Sources: JEP 523: G1 as the default in all environments | JEP draft: Compact object headers by default | Oracle: JDK 27 release notes | Inside Java: JEP 537 targeted to JDK 27