diff --git a/README.md b/README.md index 260f181..c461ba1 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ These modules keep only sources, a `run.sh` and their transcripts (`output/`). T | [`jpms-basics/`](jpms-basics) | Java Modules (JPMS) for Working Developers: module-info, exports, opens and jdeps | five modules built with plain `javac`/`java` on JDK 25: `exports` vs `opens` and the exact `InaccessibleObjectException` text, why `requires transitive` exists, services and `jlink --bind-services` (5 modules vs 49), split packages, automatic modules, the class path as the unnamed module, `jdeps --check/--jdk-internals/--generate-module-info`, and `jlink` image sizes | | [`crac/`](crac) | Spring Boot with CRaC: Checkpoint/Restore Startup Compared with the JDK AOT Cache and a Native Image | one Spring Boot 4.2 service started on a plain JVM, with the JDK AOT cache, from a CRaC checkpoint (at start-up and after warm-up) and as a GraalVM native image, ten interleaved rounds each; the open-file `CheckpointOpenFileException` and its fix, stale environment values, secrets inside the checkpoint, the `warp` and CRIU engines, and a cold page-cache run | | [`java28-features/`](java28-features) | Java 28 Features: The JDK 28 JEP List So Far (With Examples) | one example per JDK 28 JEP on EA build 26, the record rule that changes under `--enable-preview`, PKCS #12/OpenSSL, javac and library behaviour changes against JDK 27 | +| [`java21-to-25/`](java21-to-25) | Java 21 to Java 25 Migration Guide: What Breaks, What to Turn On, and the Upgrade Checklist | classes compiled once on 21 and run on 21 and 25, removed APIs, preview classes, a Maven matrix for Lombok/Mockito/JaCoCo/Spring Boot, pinning, compact object headers, containers (`scripts/`, `output/`) | ## Captured output (`docs/output/`) diff --git a/java21-to-25/README.md b/java21-to-25/README.md new file mode 100644 index 0000000..fd82fcc --- /dev/null +++ b/java21-to-25/README.md @@ -0,0 +1,42 @@ +# java21-to-25 + +Companion module for the ankurm.com post *Java 21 to Java 25 Migration Guide: What Breaks, What to Turn On, and the Upgrade Checklist* +(). The explanation lives in the article, in collapsible sections; this folder has no `docs/`. + +Probes in `src/probes/` and `src/pinning/` are compiled **once** with JDK 21 (`--release 21`) and run unchanged on both runtimes, so any difference is the runtime's. + +## Tested with + +JDK 21.0.13.1 (Ubuntu OpenJDK) and 25.0.5.1 (Temurin), the `eclipse-temurin:21-jre` / `25-jre` images, Maven 3.9.11, Gradle 8.14.3 and 9.9.3, +Spring Boot 3.2.12 to 4.2.0, Lombok 1.18.34 to 1.18.48, Mockito 5.14.2 to 5.25.0, JUnit 6.1.3, JaCoCo 0.8.11 to 0.8.15. 2 vCPU Linux. + +## Run it + +```bash +export JDK21=/path/to/jdk-21 JDK25=/path/to/jdk-25 +./scripts/run-all.sh # outputs 01-04 and 09-12 +./scripts/build-matrix.sh # outputs 05-08 (Maven, needs Maven Central) +OLD_GRADLE=... NEW_GRADLE=... ./scripts/gradle.sh # output 13 +./scripts/containers.sh # output 14 (needs Docker; run after run-all.sh) +``` + +## Output index + +| File | Shows | +|---|---| +| [`01-runtime-behaviour.txt`](output/01-runtime-behaviour.txt) | Security Manager, `Subject.getSubject`, thread control, `Unsafe`, JNI, finalization, defaults | +| [`02-startup-flags.txt`](output/02-startup-flags.txt) | JVM options on 21 and 25 | +| [`03-source-and-preview.txt`](output/03-source-and-preview.txt) | 21 preview classes on 25; Scoped Values and Gatherers | +| [`04-removed-api.txt`](output/04-removed-api.txt) | Public API in 21 that is gone in 25 | +| [`05-lombok.txt`](output/05-lombok.txt) | Lombok versions and annotation-processor discovery | +| [`06-mockito.txt`](output/06-mockito.txt) | Mockito / Byte Buddy and the agent setup | +| [`07-jacoco.txt`](output/07-jacoco.txt) | JaCoCo versions | +| [`08-spring-boot.txt`](output/08-spring-boot.txt) | Spring Boot versions with release 25 | +| [`09-scanners.txt`](output/09-scanners.txt) | `jdeps` and `jdeprscan` | +| [`10-locale-diff.txt`](output/10-locale-diff.txt) | Locale formatting differences (CLDR) | +| [`11-pinning.txt`](output/11-pinning.txt) | JEP 491, and what still pins | +| [`12-object-headers.txt`](output/12-object-headers.txt) | Compact object headers, bytes per object | +| [`13-gradle.txt`](output/13-gradle.txt) | Gradle running on JDK 25 | +| [`14-containers.txt`](output/14-containers.txt) | Container defaults and the rollback trap | + +The AI prompts used in the article are in [`../lanes/prompts/`](../lanes/prompts). `scripts/removed_api.py` reads dumps made by `../api-diff/dump_api.py`. diff --git a/java21-to-25/build-matrix/lombok/pom.xml b/java21-to-25/build-matrix/lombok/pom.xml new file mode 100644 index 0000000..84fea6e --- /dev/null +++ b/java21-to-25/build-matrix/lombok/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + com.ankurm.demos + java25-lombok + 1.0 + + + 25 + 1.18.48 + UTF-8 + + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.15.0 + + + + + + + + declared-processor + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + ${lombok.version} + + + + + + + + + diff --git a/java21-to-25/build-matrix/lombok/src/main/java/demo/App.java b/java21-to-25/build-matrix/lombok/src/main/java/demo/App.java new file mode 100644 index 0000000..23e382a --- /dev/null +++ b/java21-to-25/build-matrix/lombok/src/main/java/demo/App.java @@ -0,0 +1,16 @@ +package demo; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +public class App { + @Getter + @AllArgsConstructor + static class Person { + private final String name; + } + + public static void main(String[] args) { + System.out.println("getName() = " + new Person("ankur").getName()); + } +} diff --git a/java21-to-25/build-matrix/mockito/pom.xml b/java21-to-25/build-matrix/mockito/pom.xml new file mode 100644 index 0000000..b585cda --- /dev/null +++ b/java21-to-25/build-matrix/mockito/pom.xml @@ -0,0 +1,97 @@ + + + 4.0.0 + com.ankurm.demos + java25-mockito + 1.0 + + + 25 + 5.25.0 + 6.1.3 + 0.8.15 + + + + UTF-8 + + + + + org.junit.jupiter + junit-jupiter + ${junit.version} + test + + + org.mockito + mockito-core + ${mockito.version} + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.6 + + @{argLine} ${extra.jvm.args} + + + + + + + + + mockito-agent + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.8.1 + + + properties + + + + + org.apache.maven.plugins + maven-surefire-plugin + + @{argLine} ${extra.jvm.args} -javaagent:${org.mockito:mockito-core:jar} -Xshare:off + + + + + + + + jacoco + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + prepare-agent + + + report + test + report + + + + + + + + diff --git a/java21-to-25/build-matrix/mockito/src/main/java/demo/Greeter.java b/java21-to-25/build-matrix/mockito/src/main/java/demo/Greeter.java new file mode 100644 index 0000000..3420287 --- /dev/null +++ b/java21-to-25/build-matrix/mockito/src/main/java/demo/Greeter.java @@ -0,0 +1,5 @@ +package demo; + +public class Greeter { + public String greet() { return "real"; } +} diff --git a/java21-to-25/build-matrix/mockito/src/test/java/demo/GreeterTest.java b/java21-to-25/build-matrix/mockito/src/test/java/demo/GreeterTest.java new file mode 100644 index 0000000..ec5b718 --- /dev/null +++ b/java21-to-25/build-matrix/mockito/src/test/java/demo/GreeterTest.java @@ -0,0 +1,17 @@ +package demo; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class GreeterTest { + @Test + void stubsAConcreteClass() { + Greeter greeter = mock(Greeter.class); + when(greeter.greet()).thenReturn("mock says hi"); + assertEquals("mock says hi", greeter.greet()); + System.out.println("PROBE ok: " + greeter.greet()); + } +} diff --git a/java21-to-25/build-matrix/spring/pom.xml b/java21-to-25/build-matrix/spring/pom.xml new file mode 100644 index 0000000..8447a1c --- /dev/null +++ b/java21-to-25/build-matrix/spring/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + com.ankurm.demos + java25-spring + 1.0 + + + 25 + 4.2.0 + UTF-8 + + + + + + org.springframework.boot + spring-boot-dependencies + ${boot.version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.15.0 + + + + diff --git a/java21-to-25/build-matrix/spring/src/main/java/demo/App.java b/java21-to-25/build-matrix/spring/src/main/java/demo/App.java new file mode 100644 index 0000000..5b955be --- /dev/null +++ b/java21-to-25/build-matrix/spring/src/main/java/demo/App.java @@ -0,0 +1,17 @@ +package demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.stereotype.Component; + +@SpringBootApplication(proxyBeanMethods = false) +public class App { + @Component + static class Hello { } + + public static void main(String[] args) { + try (var ctx = SpringApplication.run(App.class, "--spring.main.banner-mode=off", "--logging.level.root=warn")) { + System.out.println("PROBE ok: component found by scanning = " + (ctx.getBeanNamesForType(Hello.class).length == 1)); + } + } +} diff --git a/java21-to-25/output/01-runtime-behaviour.txt b/java21-to-25/output/01-runtime-behaviour.txt new file mode 100644 index 0000000..ca9a1ad --- /dev/null +++ b/java21-to-25/output/01-runtime-behaviour.txt @@ -0,0 +1,72 @@ +# 01-runtime-behaviour: classes compiled ONCE with JDK 21 (--release 21), run unchanged on JDK 21 and JDK 25 +--- SecurityManagerProbe + [21.0.13.1] setSecurityManager: UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release + [25.0.5.1] setSecurityManager: UnsupportedOperationException: Setting a Security Manager is not supported +--- SubjectProbe + [21.0.13.1] Subject.getSubject: returned null + [21.0.13.1] Subject.current(): returned null + [25.0.5.1] Subject.getSubject: UnsupportedOperationException: getSubject is not supported + [25.0.5.1] Subject.current(): returned null +--- ThreadControlProbe + [21.0.13.1] suspend() java.lang.UnsupportedOperationException + [21.0.13.1] resume() java.lang.UnsupportedOperationException + [21.0.13.1] stop() java.lang.UnsupportedOperationException + [25.0.5.1] suspend() java.lang.NoSuchMethodError: 'void java.lang.Thread.suspend()' + [25.0.5.1] resume() java.lang.NoSuchMethodError: 'void java.lang.Thread.resume()' + [25.0.5.1] stop() java.lang.UnsupportedOperationException +--- UnsafeProbe + [21.0.13.1] read back: 42 + [25.0.5.1] WARNING: A terminally deprecated method in sun.misc.Unsafe has been called + [25.0.5.1] WARNING: sun.misc.Unsafe::allocateMemory has been called by UnsafeProbe (file:/c21/) + [25.0.5.1] WARNING: Please consider reporting this to the maintainers of class UnsafeProbe + [25.0.5.1] WARNING: sun.misc.Unsafe::allocateMemory will be removed in a future release + [25.0.5.1] read back: 42 +--- JniProbe + [21.0.13.1] System.loadLibrary("net") returned + [25.0.5.1] WARNING: A restricted method in java.lang.System has been called + [25.0.5.1] WARNING: java.lang.System::loadLibrary has been called by JniProbe in an unnamed module (file:/c21/) + [25.0.5.1] WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module + [25.0.5.1] WARNING: Restricted methods will be blocked in a future release unless native access is enabled + [25.0.5.1] System.loadLibrary("net") returned +--- FinalizerProbe + [21.0.13.1] finalize() ran: true + [25.0.5.1] finalize() ran: true +--- DefaultsProbe + [21.0.13.1] java.version = 21.0.13.1 + [21.0.13.1] availableProcessors = 2 + [21.0.13.1] maxMemory MiB = 1536 + [21.0.13.1] collector bean: G1 Young Generation + [21.0.13.1] collector bean: G1 Concurrent GC + [21.0.13.1] collector bean: G1 Old Generation + [21.0.13.1] UseCompactObjectHeaders = (no such flag in this JVM) + [21.0.13.1] ZGenerational = false + [25.0.5.1] java.version = 25.0.5.1 + [25.0.5.1] availableProcessors = 2 + [25.0.5.1] maxMemory MiB = 1536 + [25.0.5.1] collector bean: G1 Young Generation + [25.0.5.1] collector bean: G1 Concurrent GC + [25.0.5.1] collector bean: G1 Old Generation + [25.0.5.1] UseCompactObjectHeaders = false + [25.0.5.1] ZGenerational = (no such flag in this JVM) +--- SecurityManagerProbe with -Djava.security.manager=allow + [21.0.13.1] setSecurityManager: installed = true + [25.0.5.1] Error occurred during initialization of VM + [25.0.5.1] java.lang.Error: A command line option has attempted to allow or enable the Security Manager. Enabling a Security Manager is not supported. +--- UnsafeProbe on 25 with --sun-misc-unsafe-memory-access=deny + [25.0.5.1] failed: UnsupportedOperationException: allocateMemory +--- UnsafeProbe on 25 with --sun-misc-unsafe-memory-access=debug + [25.0.5.1] WARNING: sun.misc.Unsafe::allocateMemory called by UnsafeProbe (file:/c21/) + [25.0.5.1] at UnsafeProbe.main(UnsafeProbe.java:11) + [25.0.5.1] WARNING: sun.misc.Unsafe::putLong called by UnsafeProbe (file:/c21/) + [25.0.5.1] at UnsafeProbe.main(UnsafeProbe.java:12) + [25.0.5.1] WARNING: sun.misc.Unsafe::getLong called by UnsafeProbe (file:/c21/) + [25.0.5.1] at UnsafeProbe.main(UnsafeProbe.java:13) + [25.0.5.1] read back: 42 + [25.0.5.1] WARNING: sun.misc.Unsafe::freeMemory called by UnsafeProbe (file:/c21/) + [25.0.5.1] at UnsafeProbe.main(UnsafeProbe.java:14) +--- JniProbe on 25 with --enable-native-access=ALL-UNNAMED + [25.0.5.1] System.loadLibrary("net") returned +--- JniProbe on 25 with --illegal-native-access=deny + [25.0.5.1] failed: IllegalCallerException: Illegal native access from an unnamed module (file:/c21/) +--- FinalizerProbe on 25 with --finalization=disabled + [25.0.5.1] finalize() ran: false diff --git a/java21-to-25/output/02-startup-flags.txt b/java21-to-25/output/02-startup-flags.txt new file mode 100644 index 0000000..33670ef --- /dev/null +++ b/java21-to-25/output/02-startup-flags.txt @@ -0,0 +1,77 @@ +# 02-startup-flags: flag, then for each JDK the exit code and the first line the JVM printed (if any) +--- -Djava.security.manager=allow + [21.0.13.1] exit 0 + [25.0.5.1] exit 1 Error occurred during initialization of VM +--- -XX:+UseZGC -XX:+ZGenerational + [21.0.13.1] exit 0 + [25.0.5.1] exit 0 OpenJDK 64-Bit Server VM warning: Ignoring option ZGenerational; support was removed in 24.0 +--- -XX:+UseZGC -XX:-ZGenerational + [21.0.13.1] exit 0 + [25.0.5.1] exit 0 OpenJDK 64-Bit Server VM warning: Ignoring option ZGenerational; support was removed in 24.0 +--- -XX:+UseCompactObjectHeaders + [21.0.13.1] exit 1 Unrecognized VM option 'UseCompactObjectHeaders' + [25.0.5.1] exit 0 +--- -XX:+UnlockExperimentalVMOptions -XX:+UseCompactObjectHeaders + [21.0.13.1] exit 1 Unrecognized VM option 'UseCompactObjectHeaders' + [25.0.5.1] exit 0 +--- -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational + [21.0.13.1] exit 1 Error occurred during initialization of VM + [25.0.5.1] exit 0 +--- -XX:+UseStringDeduplication + [21.0.13.1] exit 0 + [25.0.5.1] exit 0 +--- -XX:+UseLargePagesIndividualAllocation + [21.0.13.1] exit 0 + [25.0.5.1] exit 0 +--- -XX:+UseNeon + [21.0.13.1] exit 1 Unrecognized VM option 'UseNeon' + [25.0.5.1] exit 1 Unrecognized VM option 'UseNeon' +--- -XX:LockingMode=2 + [21.0.13.1] exit 1 Error: VM option 'LockingMode' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions. + [25.0.5.1] exit 0 OpenJDK 64-Bit Server VM warning: Option LockingMode was deprecated in version 24.0 and will likely be removed in a future release. +--- -XX:+UseEmptySlotsInSupers + [21.0.13.1] exit 0 + [25.0.5.1] exit 1 Unrecognized VM option 'UseEmptySlotsInSupers' +--- -XX:+UseOprofile + [21.0.13.1] exit 0 + [25.0.5.1] exit 0 OpenJDK 64-Bit Server VM warning: Option UseOprofile was deprecated in version 25.0 and will likely be removed in a future release. +--- -XX:+DontYieldALot + [21.0.13.1] exit 0 + [25.0.5.1] exit 1 Unrecognized VM option 'DontYieldALot' +--- -Xnoagent + [21.0.13.1] exit 0 + [25.0.5.1] exit 1 Unrecognized option: -Xnoagent +--- -XX:+RegisterFinalizersAtInit + [21.0.13.1] exit 0 + [25.0.5.1] exit 1 Unrecognized VM option 'RegisterFinalizersAtInit' +--- -XX:+UseCompressedClassPointers + [21.0.13.1] exit 0 + [25.0.5.1] exit 0 OpenJDK 64-Bit Server VM warning: Option UseCompressedClassPointers was deprecated in version 25.0 and will likely be removed in a future release. +--- -XX:-UseCompressedClassPointers + [21.0.13.1] exit 0 + [25.0.5.1] exit 0 OpenJDK 64-Bit Server VM warning: Option UseCompressedClassPointers was deprecated in version 25.0 and will likely be removed in a future release. +--- -XX:+PreserveAllAnnotations + [21.0.13.1] exit 0 + [25.0.5.1] exit 1 Unrecognized VM option 'PreserveAllAnnotations' +--- -XX:+UseAdaptiveSizePolicyWithSystemGC + [21.0.13.1] exit 0 + [25.0.5.1] exit 0 +--- -XX:+EnableDynamicAgentLoading + [21.0.13.1] exit 0 + [25.0.5.1] exit 0 +--- --sun-misc-unsafe-memory-access=allow + [21.0.13.1] exit 1 Unrecognized option: --sun-misc-unsafe-memory-access=allow + [25.0.5.1] exit 0 +--- --enable-native-access=ALL-UNNAMED + [21.0.13.1] exit 0 + [25.0.5.1] exit 0 +--- --illegal-native-access=deny + [21.0.13.1] exit 1 Unrecognized option: --illegal-native-access=deny + [25.0.5.1] exit 0 +--- -Djdk.tracePinnedThreads=full + [21.0.13.1] exit 0 + [25.0.5.1] exit 0 +--- JDK 25: compact object headers together with -XX:-UseCompressedClassPointers + OpenJDK 64-Bit Server VM warning: Compact object headers require compressed class pointers. Disabling compact object headers. +--- JDK 25: CDS archive picked up with compact headers + trying to map /lib/server/classes_coh.jsa diff --git a/java21-to-25/output/03-source-and-preview.txt b/java21-to-25/output/03-source-and-preview.txt new file mode 100644 index 0000000..c51e594 --- /dev/null +++ b/java21-to-25/output/03-source-and-preview.txt @@ -0,0 +1,49 @@ +# 03-source-and-preview: preview code written for 21, and 25 APIs tried on 21 +=== StringTemplateDemo: compile on 21 with --enable-preview, run on 21 +Hello Ankur +=== StringTemplateDemo: run the same class on 25 (with --enable-preview) +Error: LinkageError occurred while loading main class StringTemplateDemo + java.lang.UnsupportedClassVersionError: StringTemplateDemo (class file version 65.65535) was compiled with preview features that are unsupported. This version of the Java Runtime only recognizes preview features for class file version 69.65535 +=== StringTemplateDemo: recompile the source on 25 with --enable-preview +src/preview21/StringTemplateDemo.java:5: error: illegal escape character + System.out.println(STR."Hello \{name}"); + ^ +1 error +=== StructuredTaskDemo: compile on 21 with --enable-preview, run on 21 +user-7 order-42 +=== StructuredTaskDemo: run the same class on 25 (with --enable-preview) +Error: LinkageError occurred while loading main class StructuredTaskDemo + java.lang.UnsupportedClassVersionError: StructuredTaskDemo (class file version 65.65535) was compiled with preview features that are unsupported. This version of the Java Runtime only recognizes preview features for class file version 69.65535 +=== StructuredTaskDemo: recompile the source on 25 with --enable-preview +src/preview21/StructuredTaskDemo.java:6: error: cannot find symbol + try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { + ^ + symbol: class ShutdownOnFailure + location: interface StructuredTaskScope +1 error +=== ThreadSuspendCall.java: javac on 21, then 25 + 21 exit 0 +src/broken/ThreadSuspendCall.java:4: error: cannot find symbol + t.suspend(); + ^ + symbol: method suspend() + location: variable t of type Thread +1 error +=== ScopedValueDemo.java: javac on 21 +src/new25/ScopedValueDemo.java:3: error: ScopedValue is a preview API and is disabled by default. + private static final ScopedValue REQUEST_ID = ScopedValue.newInstance(); + ^ + (use --enable-preview to enable preview APIs) +=== ScopedValueDemo.java: javac and java on 25, no flags +handling req-17 on main +bound outside the scope: false +=== GathererDemo.java: javac on 21 +src/new25/GathererDemo.java:2: error: cannot find symbol +import java.util.stream.Gatherers; + ^ + symbol: class Gatherers +=== GathererDemo.java: javac and java on 25, no flags +[[1, 2], [3, 4], [5]] +[[1, 2, 3], [2, 3, 4]] +[1, 3, 6, 10] +[A, B, C] diff --git a/java21-to-25/output/04-removed-api.txt b/java21-to-25/output/04-removed-api.txt new file mode 100644 index 0000000..3086a53 --- /dev/null +++ b/java21-to-25/output/04-removed-api.txt @@ -0,0 +1,76 @@ +# 04-removed-api: public types and methods in JDK 21 that are gone in JDK 25 (javap -public over java.* and selected jdk.* modules) +## public types removed + java.lang.StringTemplate + java.lang.StringTemplate$Processor + java.lang.StringTemplate$Processor$Linkage + java.lang.runtime.TemplateRuntime + java.util.FormatProcessor + java.util.concurrent.StructuredTaskScope$ShutdownOnFailure + java.util.concurrent.StructuredTaskScope$ShutdownOnSuccess + javax.management.loading.MLet + javax.management.loading.MLetContent + javax.management.loading.MLetMBean + javax.management.loading.PrivateMLet + javax.xml.catalog.GroupEntry$ResolveType + jdk.jfr.events.EventConfigurations + jdk.jfr.events.VirtualThreadPinnedEvent +## public methods removed (not inherited from a supertype either) + java.awt.peer.WindowPeer.repositionSecurityWarning() + java.lang.Class.isUnnamedClass() + java.lang.ScopedValue.callWhere(java.lang.ScopedValue,T,java.util.concurrent.Callable) + java.lang.ScopedValue.getWhere(java.lang.ScopedValue,T,java.util.function.Supplier) + java.lang.ScopedValue.runWhere(java.lang.ScopedValue,T,java.lang.Runnable) + java.lang.ScopedValue$Carrier.call(java.util.concurrent.Callable) + java.lang.ScopedValue$Carrier.get(java.util.function.Supplier) + java.lang.Thread.countStackFrames() + java.lang.Thread.resume() + java.lang.Thread.suspend() + java.lang.ThreadGroup.resume() + java.lang.ThreadGroup.stop() + java.lang.ThreadGroup.suspend() + java.lang.foreign.Linker$Option.isTrivial() + java.lang.foreign.MemoryLayout.sequenceLayout(java.lang.foreign.MemoryLayout) + java.lang.foreign.MemorySegment.getUtf8String(long) + java.lang.foreign.MemorySegment.segmentOffset(java.lang.foreign.MemorySegment) + java.lang.foreign.MemorySegment.setUtf8String(long,java.lang.String) + java.lang.foreign.SegmentAllocator.allocate(java.lang.foreign.AddressLayout,java.lang.foreign.MemorySegment) + java.lang.foreign.SegmentAllocator.allocate(java.lang.foreign.ValueLayout$OfByte,byte) + java.lang.foreign.SegmentAllocator.allocate(java.lang.foreign.ValueLayout$OfChar,char) + java.lang.foreign.SegmentAllocator.allocate(java.lang.foreign.ValueLayout$OfDouble,double) + java.lang.foreign.SegmentAllocator.allocate(java.lang.foreign.ValueLayout$OfFloat,float) + java.lang.foreign.SegmentAllocator.allocate(java.lang.foreign.ValueLayout$OfInt,int) + java.lang.foreign.SegmentAllocator.allocate(java.lang.foreign.ValueLayout$OfLong,long) + java.lang.foreign.SegmentAllocator.allocate(java.lang.foreign.ValueLayout$OfShort,short) + java.lang.foreign.SegmentAllocator.allocateArray(java.lang.foreign.MemoryLayout,long) + java.lang.foreign.SegmentAllocator.allocateArray(java.lang.foreign.ValueLayout$OfByte,byte...) + java.lang.foreign.SegmentAllocator.allocateArray(java.lang.foreign.ValueLayout$OfChar,char...) + java.lang.foreign.SegmentAllocator.allocateArray(java.lang.foreign.ValueLayout$OfDouble,double...) + java.lang.foreign.SegmentAllocator.allocateArray(java.lang.foreign.ValueLayout$OfFloat,float...) + java.lang.foreign.SegmentAllocator.allocateArray(java.lang.foreign.ValueLayout$OfInt,int...) + java.lang.foreign.SegmentAllocator.allocateArray(java.lang.foreign.ValueLayout$OfLong,long...) + java.lang.foreign.SegmentAllocator.allocateArray(java.lang.foreign.ValueLayout$OfShort,short...) + java.lang.foreign.SegmentAllocator.allocateUtf8String(java.lang.String) + java.lang.foreign.ValueLayout.arrayElementVarHandle(int...) + java.lang.invoke.MethodHandles.memorySegmentViewVarHandle(java.lang.foreign.ValueLayout) + java.lang.invoke.StringConcatFactory.makeConcatWithTemplate(java.util.List,java.util.List) + java.lang.invoke.StringConcatFactory.makeConcatWithTemplateCluster(java.util.List,java.util.List,int) + java.lang.invoke.StringConcatFactory.makeConcatWithTemplateGetters(java.util.List,java.util.List,int) + java.util.concurrent.StructuredTaskScope.StructuredTaskScope() + java.util.concurrent.StructuredTaskScope.StructuredTaskScope(java.lang.String,java.util.concurrent.ThreadFactory) + java.util.concurrent.StructuredTaskScope.isShutdown() + java.util.concurrent.StructuredTaskScope.joinUntil(java.time.Instant) + java.util.concurrent.StructuredTaskScope.shutdown() + java.util.concurrent.StructuredTaskScope$Subtask.task() + javax.lang.model.element.TypeElement.isUnnamed() + javax.swing.plaf.basic.BasicSliderUI.BasicSliderUI() + javax.swing.plaf.synth.SynthLookAndFeel.load(java.net.URL) + jdk.jfr.events.ActiveRecordingEvent.commit(long,long,long,java.lang.String,java.lang.String,boolean,long,long,long,long,long) + jdk.jfr.events.ActiveSettingEvent.commit(long,long,long,java.lang.String,java.lang.String) + jdk.jfr.events.ErrorThrownEvent.commit(long,long,java.lang.String,java.lang.Class) + jdk.jfr.events.ExceptionThrownEvent.commit(long,long,java.lang.String,java.lang.Class) + jdk.jfr.events.FileForceEvent.commit(long,long,java.lang.String,boolean) + jdk.jfr.events.FileReadEvent.commit(long,long,java.lang.String,long,boolean) + jdk.jfr.events.FileWriteEvent.commit(long,long,java.lang.String,long) + jdk.jfr.events.SocketReadEvent.commit(long,long,java.lang.String,java.lang.String,int,long,long,boolean) + jdk.jfr.events.SocketWriteEvent.commit(long,long,java.lang.String,java.lang.String,int,long) + jdk.tools.jlink.builder.DefaultImageBuilder.DefaultImageBuilder(java.nio.file.Path,java.util.Map) diff --git a/java21-to-25/output/05-lombok.txt b/java21-to-25/output/05-lombok.txt new file mode 100644 index 0000000..775a2db --- /dev/null +++ b/java21-to-25/output/05-lombok.txt @@ -0,0 +1,10 @@ +# 05-lombok: mvn compile on JDK 25, release 25. 'class path' = plain provided dependency; 'declared' = annotationProcessorPaths + FAIL Lombok 1.18.34, declared processor + FAIL Lombok 1.18.36, declared processor + OK Lombok 1.18.38, declared processor + OK Lombok 1.18.40, declared processor + OK Lombok 1.18.48, declared processor + FAIL Lombok 1.18.48, class path only + [ERROR] COMPILATION ERROR : + [ERROR] /matrix/lombok/src/main/java/demo/App.java:[14,45] constructor Person in class demo.App.Person cannot be applied to given types; + [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) on project java25-lombok: Compilation failure diff --git a/java21-to-25/output/06-mockito.txt b/java21-to-25/output/06-mockito.txt new file mode 100644 index 0000000..c5bd313 --- /dev/null +++ b/java21-to-25/output/06-mockito.txt @@ -0,0 +1,28 @@ +# 06-mockito: mvn test on JDK 25, release 25, JUnit 6.1.3, mocking a concrete class + FAIL Mockito 5.14.2 + [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.096 s <<< FAILURE! -- in demo.GreeterTest + [ERROR] demo.GreeterTest.stubsAConcreteClass -- Time elapsed: 1.994 s <<< ERROR! + Caused by: java.lang.IllegalArgumentException: Java 25 (69) is not supported by the current version of Byte Buddy which officially supports Java 24 (68) - update Byte Buddy or set net.bytebuddy.experimental as a VM property + FAIL Mockito 5.15.2 + [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.052 s <<< FAILURE! -- in demo.GreeterTest + [ERROR] demo.GreeterTest.stubsAConcreteClass -- Time elapsed: 1.916 s <<< ERROR! + Caused by: java.lang.IllegalArgumentException: Java 25 (69) is not supported by the current version of Byte Buddy which officially supports Java 24 (68) - update Byte Buddy or set net.bytebuddy.experimental as a VM property + FAIL Mockito 5.17.0 + [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.314 s <<< FAILURE! -- in demo.GreeterTest + [ERROR] demo.GreeterTest.stubsAConcreteClass -- Time elapsed: 2.207 s <<< ERROR! + Caused by: java.lang.IllegalArgumentException: Java 25 (69) is not supported by the current version of Byte Buddy which officially supports Java 24 (68) - update Byte Buddy or set net.bytebuddy.experimental as a VM property + OK Mockito 5.18.0 + OK Mockito 5.25.0 + +--- Mockito 5.14.2 with -Dnet.bytebuddy.experimental=true (stop-gap, not a fix) + OK Mockito 5.14.2 + experimental + +--- Mockito 5.25.0, default: notices printed during the test run +Mockito is currently self-attaching to enable the inline-mock-maker. This will no longer work in future releases of the JDK. Please add Mockito as an agent to your build as described in Mockito's docu +WARNING: A Java agent has been loaded dynamically (~/.m2/repository/net/bytebuddy/byte-buddy-agent/1.18.17/byte-buddy-agent-1.18.17.jar) +OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended +PROBE ok: mock says hi + +--- Mockito 5.25.0 with -Pmockito-agent (agent registered at startup) +PROBE ok: mock says hi +[INFO] BUILD SUCCESS diff --git a/java21-to-25/output/07-jacoco.txt b/java21-to-25/output/07-jacoco.txt new file mode 100644 index 0000000..ca61e31 --- /dev/null +++ b/java21-to-25/output/07-jacoco.txt @@ -0,0 +1,10 @@ +# 07-jacoco: mvn test -Pjacoco on JDK 25, release 25. 'agent errors' counts instrumentation failures in the log + JaCoCo 0.8.11: BUILD FAILURE, agent errors: 31 + java.lang.instrument.IllegalClassFormatException: Error while instrumenting demo/GreeterTest with JaCoCo 0.8.11.202310140853/f33756c. + Caused by: java.io.IOException: Error while instrumenting demo/GreeterTest with JaCoCo 0.8.11.202310140853/f33756c. + JaCoCo 0.8.12: BUILD FAILURE, agent errors: 31 + java.lang.instrument.IllegalClassFormatException: Error while instrumenting demo/GreeterTest with JaCoCo 0.8.12.202403310830/dbfb6f2. + Caused by: java.io.IOException: Error while instrumenting demo/GreeterTest with JaCoCo 0.8.12.202403310830/dbfb6f2. + JaCoCo 0.8.13: BUILD SUCCESS, agent errors: 0 + JaCoCo 0.8.14: BUILD SUCCESS, agent errors: 0 + JaCoCo 0.8.15: BUILD SUCCESS, agent errors: 0 diff --git a/java21-to-25/output/08-spring-boot.txt b/java21-to-25/output/08-spring-boot.txt new file mode 100644 index 0000000..8843bd3 --- /dev/null +++ b/java21-to-25/output/08-spring-boot.txt @@ -0,0 +1,17 @@ +# 08-spring-boot: a component-scanning app compiled with release 25 and started on JDK 25 + FAIL Boot 3.2.12 + Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 69 + FAIL Boot 3.3.0 + Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 69 + FAIL Boot 3.3.13 + Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 69 + FAIL Boot 3.4.0 + Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 69 + FAIL Boot 3.4.3 + Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 69 + OK Boot 3.4.4 + OK Boot 3.4.5 + OK Boot 3.4.13 + OK Boot 3.5.16 + OK Boot 4.0.0 + OK Boot 4.2.0 diff --git a/java21-to-25/output/09-scanners.txt b/java21-to-25/output/09-scanners.txt new file mode 100644 index 0000000..8a5dcca --- /dev/null +++ b/java21-to-25/output/09-scanners.txt @@ -0,0 +1,12 @@ +# 09-scanners: JDK 25 tools pointed at a jar built by JDK 21 +--- jdeps --jdk-internals probes.jar +probes.jar -> jdk.unsupported + UnsafeProbe -> sun.misc.Unsafe JDK internal API (jdk.unsupported) +--- jdeprscan --release 25 --for-removal probes.jar +class FinalizerProbe overrides deprecated method java/lang/Object::finalize()V (forRemoval=true) +class SecurityManagerProbe uses deprecated class java/lang/SecurityManager (forRemoval=true) +class SecurityManagerProbe uses deprecated method java/lang/System::getSecurityManager()Ljava/lang/SecurityManager; (forRemoval=true) +class SecurityManagerProbe uses deprecated method java/lang/System::setSecurityManager(Ljava/lang/SecurityManager;)V (forRemoval=true) +class SubjectProbe uses deprecated class java/security/AccessController (forRemoval=true) +class SubjectProbe uses deprecated method javax/security/auth/Subject::getSubject(Ljava/security/AccessControlContext;)Ljavax/security/auth/Subject; (forRemoval=true) +class ThreadControlProbe uses deprecated method java/lang/Thread::stop()V (forRemoval=true) diff --git a/java21-to-25/output/10-locale-diff.txt b/java21-to-25/output/10-locale-diff.txt new file mode 100644 index 0000000..64e8c0b --- /dev/null +++ b/java21-to-25/output/10-locale-diff.txt @@ -0,0 +1,7 @@ +# 10-locale-diff: LocaleProbe (compiled once on 21) run on both JDKs; only the lines that differ. 81 formats compared + [21] en-IN | dateTime FULL | Saturday, 5 September, 2026, 2:07:09\u202Fpm India Standard Time + [25] en-IN | dateTime FULL | Saturday, 5 September 2026, 2:07:09\u202Fpm India Standard Time + [21] en-IN | dateTime MEDIUM | 05-Sept-2026, 2:07:09\u202Fpm + [25] en-IN | dateTime MEDIUM | 5 Sept 2026, 2:07:09\u202Fpm + [21] mr-IN | currency | \u20B9\u0967\u0968,\u0969\u096A\u096B,\u096C\u096D\u096E.\u096B\u0966 + [25] mr-IN | currency | \u20B9\u00A0\u0967\u0968,\u0969\u096A\u096B,\u096C\u096D\u096E.\u096B\u0966 diff --git a/java21-to-25/output/11-pinning.txt b/java21-to-25/output/11-pinning.txt new file mode 100644 index 0000000..618901e --- /dev/null +++ b/java21-to-25/output/11-pinning.txt @@ -0,0 +1,18 @@ +# 11-pinning: compiled once on 21; run with -Djdk.virtualThreadScheduler.parallelism=2. Elapsed times are machine dependent +--- PinningProbe + [21.0.13.1] java 21: 20 threads, 100 ms sleep inside synchronized + [21.0.13.1] elapsed = 1037 ms, jdk.VirtualThreadPinned events = 20 + [25.0.5.1] java 25: 20 threads, 100 ms sleep inside synchronized + [25.0.5.1] elapsed = 111 ms, jdk.VirtualThreadPinned events = 0 +--- ClassInitPinningProbe + [21.0.13.1] java 21: 8 classes, 100 ms sleep inside each static initializer + [21.0.13.1] elapsed = 430 ms, jdk.VirtualThreadPinned events = 8 + [25.0.5.1] java 25: 8 classes, 100 ms sleep inside each static initializer + [25.0.5.1] elapsed = 423 ms, jdk.VirtualThreadPinned events = 8 + [25.0.5.1] first event pinnedReason = VM call to ClassInitPinningProbe$C0. on stack +--- PinningProbe with -Djdk.tracePinnedThreads=short (first lines) + [21.0.13.1] VirtualThread[#24]/runnable@ForkJoinPool-1-worker-2 reason:MONITOR + [21.0.13.1] PinningProbe.lambda$main$0(PinningProbe.java:25) <== monitors:1 + [21.0.13.1] java 21: 20 threads, 100 ms sleep inside synchronized + [25.0.5.1] java 25: 20 threads, 100 ms sleep inside synchronized + [25.0.5.1] elapsed = 113 ms, jdk.VirtualThreadPinned events = 0 diff --git a/java21-to-25/output/12-object-headers.txt b/java21-to-25/output/12-object-headers.txt new file mode 100644 index 0000000..a52ef69 --- /dev/null +++ b/java21-to-25/output/12-object-headers.txt @@ -0,0 +1,19 @@ +# 12-object-headers: bytes allocated per object on JDK 25.0.5.1, 1,000,000 objects each +--- default (-XX:-UseCompactObjectHeaders) + new Object() 16 bytes/object + record() 16 bytes/object + record(int) 16 bytes/object + record(int,int) 24 bytes/object + record(int,int,int) 24 bytes/object + record(int,Object) 24 bytes/object + Long (outside cache) 24 bytes/object + byte[8] 24 bytes/object +--- -XX:+UseCompactObjectHeaders + new Object() 8 bytes/object + record() 8 bytes/object + record(int) 16 bytes/object + record(int,int) 16 bytes/object + record(int,int,int) 24 bytes/object + record(int,Object) 16 bytes/object + Long (outside cache) 16 bytes/object + byte[8] 24 bytes/object diff --git a/java21-to-25/output/13-gradle.txt b/java21-to-25/output/13-gradle.txt new file mode 100644 index 0000000..164764b --- /dev/null +++ b/java21-to-25/output/13-gradle.txt @@ -0,0 +1,6 @@ +# 13-gradle: 'gradle run' with Gradle running on JDK 25.0.5.1 +--- Gradle 8.14.3 + * What went wrong: + 25.0.5.1 +--- Gradle 9.9.3 + running on Java 25 diff --git a/java21-to-25/output/14-containers.txt b/java21-to-25/output/14-containers.txt new file mode 100644 index 0000000..e083cc5 --- /dev/null +++ b/java21-to-25/output/14-containers.txt @@ -0,0 +1,72 @@ +# 14-containers: eclipse-temurin 21-jre and 25-jre, DefaultsProbe compiled once on 21 +=== eclipse-temurin:21-jre --cpus=2 --memory=2g + java.version = 21.0.13.1 + availableProcessors = 2 + maxMemory MiB = 512 + collector bean: G1 Young Generation + collector bean: G1 Concurrent GC + collector bean: G1 Old Generation + UseCompactObjectHeaders = (no such flag in this JVM) + ZGenerational = false +=== eclipse-temurin:25-jre --cpus=2 --memory=2g + java.version = 25.0.5.1 + availableProcessors = 2 + maxMemory MiB = 512 + collector bean: G1 Young Generation + collector bean: G1 Concurrent GC + collector bean: G1 Old Generation + UseCompactObjectHeaders = false + ZGenerational = (no such flag in this JVM) +=== eclipse-temurin:21-jre --cpus=1 --memory=2g + java.version = 21.0.13.1 + availableProcessors = 1 + maxMemory MiB = 494 + collector bean: Copy + collector bean: MarkSweepCompact + UseCompactObjectHeaders = (no such flag in this JVM) + ZGenerational = false +=== eclipse-temurin:25-jre --cpus=1 --memory=2g + java.version = 25.0.5.1 + availableProcessors = 1 + maxMemory MiB = 494 + collector bean: Copy + collector bean: MarkSweepCompact + UseCompactObjectHeaders = false + ZGenerational = (no such flag in this JVM) +=== eclipse-temurin:21-jre --cpus=2 --memory=512m + java.version = 21.0.13.1 + availableProcessors = 2 + maxMemory MiB = 123 + collector bean: Copy + collector bean: MarkSweepCompact + UseCompactObjectHeaders = (no such flag in this JVM) + ZGenerational = false +=== eclipse-temurin:25-jre --cpus=2 --memory=512m + java.version = 25.0.5.1 + availableProcessors = 2 + maxMemory MiB = 123 + collector bean: Copy + collector bean: MarkSweepCompact + UseCompactObjectHeaders = false + ZGenerational = (no such flag in this JVM) +=== eclipse-temurin:21-jre -XX:+UseZGC + collector bean: ZGC Cycles + collector bean: ZGC Pauses + ZGenerational = false +=== eclipse-temurin:25-jre -XX:+UseZGC + collector bean: ZGC Minor Cycles + collector bean: ZGC Minor Pauses + collector bean: ZGC Major Cycles + collector bean: ZGC Major Pauses + ZGenerational = (no such flag in this JVM) +=== rollback: the 25 flag set through JDK_JAVA_OPTIONS, image rolled back to 21 + NOTE: Picked up JDK_JAVA_OPTIONS: -XX:+UseCompactObjectHeaders + Unrecognized VM option 'UseCompactObjectHeaders' + Error: Could not create the Java Virtual Machine. + Error: A fatal exception has occurred. Program will exit. +=== same, with -XX:+IgnoreUnrecognizedVMOptions in front + NOTE: Picked up JDK_JAVA_OPTIONS: -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompactObjectHeaders + openjdk version "21.0.13.1" 2026-11-17 LTS +=== 25 image with the flag set through JDK_JAVA_OPTIONS + NOTE: Picked up JDK_JAVA_OPTIONS: -XX:+UseCompactObjectHeaders + UseCompactObjectHeaders = true diff --git a/java21-to-25/scripts/build-matrix.sh b/java21-to-25/scripts/build-matrix.sh new file mode 100755 index 0000000..e83cb5b --- /dev/null +++ b/java21-to-25/scripts/build-matrix.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# Build-tool and library matrix on JDK 25 with 25. Needs Maven and Maven Central. +source "$(dirname "$0")/env.sh" +export JAVA_HOME=$J25 PATH=$J25/bin:$PATH MAVEN_OPTS=-Xmx1g +B=$W/matrix; rm -rf "$B"; mkdir -p "$B"; cp -r "$ROOT"/build-matrix/* "$B"/ +mvnq() { mvn -B -ntp -q "$@" 2>&1 | clean | sed -e "s#$HOME#~#g"; return ${PIPESTATUS[0]}; } +# first line that says why it failed +why() { grep -E 'ERROR|Exception|error:|Unsupported|Mockito cannot|IllegalArgument' "$1" | grep -v -E '^\[ERROR\] *$|Help 1|-e switch|-X switch|re-run|For more|surefire-reports' | head -${2:-2} | cut -c1-260 | sed 's/^/ /'; } +run() { # label logfile dir mvn-args... + local label=$1 log=$2 dir=$3; shift 3 + if (cd "$B/$dir" && mvnq clean "$@" >"$log" 2>&1); then echo " OK $label"; return 0; else echo " FAIL $label"; return 1; fi +} + +echo "# 05-lombok: mvn compile on JDK 25, release 25. 'class path' = plain provided dependency; 'declared' = annotationProcessorPaths" > "$OUT/05-lombok.txt" +{ for v in 1.18.34 1.18.36 1.18.38 1.18.40 1.18.48; do + run "Lombok $v, declared processor" "$B/l.log" lombok compile -Pdeclared-processor -Dlombok.version=$v || why "$B/l.log" + done + run "Lombok 1.18.48, class path only" "$B/l.log" lombok compile -Dlombok.version=1.18.48 || why "$B/l.log" 3 +} >> "$OUT/05-lombok.txt" + +echo "# 06-mockito: mvn test on JDK 25, release 25, JUnit 6.1.3, mocking a concrete class" > "$OUT/06-mockito.txt" +{ for v in 5.14.2 5.15.2 5.17.0 5.18.0 5.25.0; do + run "Mockito $v" "$B/m.log" mockito test -Dmockito.version=$v || { why "$B/m.log" 2; grep -m1 "not supported by the current version of Byte Buddy" "$B/m.log" | cut -c1-300 | sed "s/^/ /"; } + done + echo; echo "--- Mockito 5.14.2 with -Dnet.bytebuddy.experimental=true (stop-gap, not a fix)" + run "Mockito 5.14.2 + experimental" "$B/m.log" mockito test -Dmockito.version=5.14.2 -Dextra.jvm.args=-Dnet.bytebuddy.experimental=true || why "$B/m.log" 3 + echo; echo "--- Mockito 5.25.0, default: notices printed during the test run" + (cd "$B/mockito" && mvn -B -ntp clean test 2>&1 | clean | grep -E 'self-attaching|Java agent has been loaded|dynamic loading|PROBE|Sharing is only' | sed "s#$HOME#~#g" | cut -c1-200) + echo; echo "--- Mockito 5.25.0 with -Pmockito-agent (agent registered at startup)" + (cd "$B/mockito" && mvn -B -ntp clean test -Pmockito-agent 2>&1 | clean | grep -E 'self-attaching|Java agent has been loaded|dynamic loading|PROBE|Sharing is only|BUILD' | sed "s#$HOME#~#g" | cut -c1-200) +} >> "$OUT/06-mockito.txt" + +echo "# 07-jacoco: mvn test -Pjacoco on JDK 25, release 25. 'agent errors' counts instrumentation failures in the log" > "$OUT/07-jacoco.txt" +{ for v in 0.8.11 0.8.12 0.8.13 0.8.14 0.8.15; do + (cd "$B/mockito" && mvn -B -ntp clean test -Pjacoco -Djacoco.version=$v 2>&1 | clean > "$B/j.log") + res=$(grep -q 'BUILD SUCCESS' "$B/j.log" && echo "BUILD SUCCESS" || echo "BUILD FAILURE") + echo " JaCoCo $v: $res, agent errors: $(grep -c 'Exception in thread\|IllegalClassFormatException\|Error while instrumenting\|Unsupported class file major' "$B/j.log")" + grep -m2 -E 'Unsupported class file major|Error while (instrumenting|analyzing)' "$B/j.log" | sed "s#$HOME#~#g" | cut -c1-220 | sed 's/^/ /' + done +} >> "$OUT/07-jacoco.txt" + +echo "# 08-spring-boot: a component-scanning app compiled with release 25 and started on JDK 25" > "$OUT/08-spring-boot.txt" +{ for v in 3.2.12 3.3.0 3.3.13 3.4.0 3.4.3 3.4.4 3.4.5 3.4.13 3.5.16 4.0.0 4.2.0; do + d=$B/spring + (cd $d && mvnq clean compile dependency:build-classpath -Dboot.version=$v -Dmdep.outputFile=cp.txt >"$B/s.log" 2>&1) || { echo " FAIL(build) Boot $v"; why "$B/s.log"; continue; } + "$J25/bin/java" -cp "$d/target/classes:$(cat $d/cp.txt)" demo.App > "$B/s.log" 2>&1 + if grep -q 'PROBE ok' "$B/s.log"; then echo " OK Boot $v"; else echo " FAIL Boot $v"; grep -m1 -E '^Caused by: .*Unsupported class file' "$B/s.log" | clean | cut -c1-220 | sed 's/^/ /'; fi + done +} >> "$OUT/08-spring-boot.txt" +tail -n +1 "$OUT"/0[5-8]-*.txt diff --git a/java21-to-25/scripts/containers.sh b/java21-to-25/scripts/containers.sh new file mode 100755 index 0000000..9c7f5b4 --- /dev/null +++ b/java21-to-25/scripts/containers.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# The same checks inside eclipse-temurin images (pulled through mirror.gcr.io to avoid Docker Hub rate limits). +source "$(dirname "$0")/env.sh" +C=$W/c21; I21=${IMG21:-mirror.gcr.io/library/eclipse-temurin:21-jre}; I25=${IMG25:-mirror.gcr.io/library/eclipse-temurin:25-jre} +rm -rf "$C"; "$J21/bin/javac" --release 21 -nowarn -Xlint:-removal -d "$C" "$ROOT"/src/probes/DefaultsProbe.java 2>/dev/null; chmod -R a+rX "$W" +d() { docker run --rm -v "$C:/c:ro" "$@" 2>&1 | grep -v '^Picked up'; } +{ echo "# 14-containers: eclipse-temurin 21-jre and 25-jre, DefaultsProbe compiled once on 21" + for limits in "--cpus=2 --memory=2g" "--cpus=1 --memory=2g" "--cpus=2 --memory=512m"; do + for img in "$I21" "$I25"; do echo "=== ${img##*/} $limits"; d $limits "$img" java -cp /c DefaultsProbe | sed 's/^/ /'; done + done + for img in "$I21" "$I25"; do echo "=== ${img##*/} -XX:+UseZGC"; d --cpus=2 --memory=2g "$img" java -XX:+UseZGC -cp /c DefaultsProbe | grep -E 'collector|ZGen' | sed 's/^/ /'; done + echo "=== rollback: the 25 flag set through JDK_JAVA_OPTIONS, image rolled back to 21" + d -e JDK_JAVA_OPTIONS=-XX:+UseCompactObjectHeaders "$I21" java -version | grep -E 'Unrecognized|Error|NOTE' | sed 's/^/ /' + echo "=== same, with -XX:+IgnoreUnrecognizedVMOptions in front" + d -e "JDK_JAVA_OPTIONS=-XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompactObjectHeaders" "$I21" java -version | grep -E 'Unrecognized|openjdk version|NOTE' | sed 's/^/ /' + echo "=== 25 image with the flag set through JDK_JAVA_OPTIONS" + d -e JDK_JAVA_OPTIONS=-XX:+UseCompactObjectHeaders --cpus=2 --memory=2g "$I25" java -cp /c DefaultsProbe | grep -E 'NOTE|Compact' | sed 's/^/ /' +} > "$OUT/14-containers.txt" diff --git a/java21-to-25/scripts/env.sh b/java21-to-25/scripts/env.sh new file mode 100755 index 0000000..cafc39a --- /dev/null +++ b/java21-to-25/scripts/env.sh @@ -0,0 +1,8 @@ +# Shared by every script. Set JDK21 and JDK25 to your installations. +export J21=${JDK21:-/usr/lib/jvm/java-21-openjdk-amd64} J25=${JDK25:?set JDK25 to a JDK 25 installation} +ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd); OUT=$ROOT/output; W=${WORK:-/tmp/java21-to-25-work} +mkdir -p "$OUT" "$W" +unset _JAVA_OPTIONS +# drops the banner a JVM prints for JAVA_TOOL_OPTIONS, and local paths +clean() { grep -v -E '^(\[[A-Z]+\] )?Picked up ' | sed -e "s#$W##g" -e "s#$ROOT/##g" -e "s#$HOME#~#g"; } +ver() { "$1/bin/java" -version 2>&1 | grep -v '^Picked up' | head -1 | sed -E 's/^openjdk version "([^"]+)".*/\1/'; } diff --git a/java21-to-25/scripts/flags.sh b/java21-to-25/scripts/flags.sh new file mode 100755 index 0000000..c7f1d19 --- /dev/null +++ b/java21-to-25/scripts/flags.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# Which JVM options that a Java 21 service might carry still start on Java 25, and the other way round (rollback). +source "$(dirname "$0")/env.sh" +echo "# 02-startup-flags: flag, then for each JDK the exit code and the first line the JVM printed (if any)" +for f in \ + "-Djava.security.manager=allow" \ + "-XX:+UseZGC -XX:+ZGenerational" \ + "-XX:+UseZGC -XX:-ZGenerational" \ + "-XX:+UseCompactObjectHeaders" \ + "-XX:+UnlockExperimentalVMOptions -XX:+UseCompactObjectHeaders" \ + "-XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational" \ + "-XX:+UseStringDeduplication" \ + "-XX:+UseLargePagesIndividualAllocation" \ + "-XX:+UseNeon" \ + "-XX:LockingMode=2" \ + "-XX:+UseEmptySlotsInSupers" \ + "-XX:+UseOprofile" \ + "-XX:+DontYieldALot" \ + "-Xnoagent" \ + "-XX:+RegisterFinalizersAtInit" \ + "-XX:+UseCompressedClassPointers" \ + "-XX:-UseCompressedClassPointers" \ + "-XX:+PreserveAllAnnotations" \ + "-XX:+UseAdaptiveSizePolicyWithSystemGC" \ + "-XX:+EnableDynamicAgentLoading" \ + "--sun-misc-unsafe-memory-access=allow" \ + "--enable-native-access=ALL-UNNAMED" \ + "--illegal-native-access=deny" \ + "-Djdk.tracePinnedThreads=full" \ + ; do + echo "--- $f" + for j in "$J21" "$J25"; do + out=$("$j/bin/java" $f -version 2>&1 | clean); code=$? + out=$("$j/bin/java" $f -version 2>&1 | clean | grep -v -E '^(openjdk |OpenJDK Runtime|OpenJDK 64-Bit Server VM (Temurin|\(build))' | head -1) + "$j/bin/java" $f -version >/dev/null 2>&1; code=$? + printf ' [%s] exit %s %s\n' "$(ver "$j")" "$code" "$out" + done +done diff --git a/java21-to-25/scripts/gradle.sh b/java21-to-25/scripts/gradle.sh new file mode 100755 index 0000000..321c466 --- /dev/null +++ b/java21-to-25/scripts/gradle.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# Runs the small Gradle project in ../lanes/upgrade (Java 25 toolchain) with two Gradle versions, Gradle itself on JDK 25. +# OLD_GRADLE=/path/to/gradle-8.14.3/bin/gradle NEW_GRADLE=/path/to/gradle-9.x/bin/gradle ./scripts/gradle.sh +source "$(dirname "$0")/env.sh" +{ echo "# 13-gradle: 'gradle run' with Gradle running on JDK $(ver "$J25")" + for g in "${OLD_GRADLE:?}" "${NEW_GRADLE:?}"; do + v=$("$g" --version 2>/dev/null | grep -E '^Gradle ' | head -1); echo "--- $v" + rm -rf "$W/gp"; cp -r "$ROOT/../lanes/upgrade" "$W/gp" + (cd "$W/gp" && JAVA_HOME=$J25 "$g" --no-daemon -q run 2>&1 | clean | grep -E -A1 'running on|What went wrong' | head -3 | sed 's/^/ /') + done +} > "$OUT/13-gradle.txt" diff --git a/java21-to-25/scripts/removed_api.py b/java21-to-25/scripts/removed_api.py new file mode 100644 index 0000000..3a7aac5 --- /dev/null +++ b/java21-to-25/scripts/removed_api.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +"""Public types and methods present in the older javap dump and gone from the newer one. + +usage: removed_api.py (dumps made by ../../api-diff/dump_api.py) + +Modifier and 'throws' changes are ignored: a method counts as removed only if no method with the same +name and parameter types is declared on the class or on any supertype in the newer dump. +com.sun.source (compiler tree API) and jdk.jfr.snippets are skipped. +""" +import re, sys + +def strip_generics(s): + prev = None + while prev != s: + prev, s = s, re.sub(r"<[^<>]*>", "", s) + return s + +def parse(path): + out, cur = {}, None + for line in open(path): + line = line.rstrip("\n") + if line.startswith("#####") or line.startswith("Compiled from") or not line.strip() or line.strip() == "}": + continue + if not line.startswith(" "): + bare = strip_generics(line) + m = re.search(r"(?:class|interface)\s+([\w.$]+)", bare) + if not m: + cur = None + continue + cur = m.group(1) + supers = [] + for kw in ("extends", "implements"): + k = re.search(kw + r"\s+(.*?)(?:\s+implements|\s*\{|$)", bare) + if k: + supers += [x.strip() for x in k.group(1).split(",")] + out[cur] = {"public": bare.startswith(("public ", "protected ")), "supers": supers, "methods": set()} + elif cur: + sig = strip_generics(line.strip()) + m = re.search(r"([\w$]+)\(([^)]*)\)", sig) + if m and sig.startswith(("public", "protected")): + out[cur]["methods"].add(f"{m.group(1)}({m.group(2).replace(' ', '')})") + return out + +old, new = parse(sys.argv[1]), parse(sys.argv[2]) + +def inherited(cls, sig, seen=None): + seen = seen or set() + if cls in seen: + return False + seen.add(cls) + info = new.get(cls) + if info is None: + return False + if sig in info["methods"]: + return True + return any(inherited(s, sig, seen) for s in info["supers"] + ["java.lang.Object"]) + +skip = ("com.sun.source.", "jdk.jfr.snippets") +print("## public types removed") +for c in sorted(set(old) - set(new)): + if old[c]["public"] and not c.startswith(skip): + print(" " + c) +print("## public methods removed (not inherited from a supertype either)") +for c in sorted(set(old) & set(new)): + if not old[c]["public"] or c.startswith(skip): + continue + for sig in sorted(old[c]["methods"] - new[c]["methods"]): + if not inherited(c, sig): + print(f" {c}.{sig}") diff --git a/java21-to-25/scripts/run-all.sh b/java21-to-25/scripts/run-all.sh new file mode 100755 index 0000000..d282b33 --- /dev/null +++ b/java21-to-25/scripts/run-all.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# Regenerates output/. Needs JDK 21 and JDK 25 (set JDK21 / JDK25). The build matrix needs Maven and Maven Central; +# containers.sh needs Docker; gradle.sh needs two Gradle installations. See README.md. +source "$(dirname "$0")/env.sh" +cd "$ROOT"; rm -rf "$W/c21" "$W/p21" "$W/c25"; C=$W/c21 +"$J21/bin/javac" --release 21 -nowarn -Xlint:-removal -d "$C" src/probes/*.java src/pinning/*.java 2>/dev/null +both() { for j in "$J21" "$J25"; do v=$(ver "$j"); "$j/bin/java" "$@" -cp "$C" "$CLS" 2>&1 | clean | grep -v '^$' | sed "s/^/ [$v] /"; done; } +one() { local j=$1; shift; "$j/bin/java" "$@" -cp "$C" "$CLS" 2>&1 | clean | grep -v '^$' | sed "s/^/ [$(ver "$j")] /"; } + +{ echo "# 01-runtime-behaviour: classes compiled ONCE with JDK 21 (--release 21), run unchanged on JDK 21 and JDK 25" + for CLS in SecurityManagerProbe SubjectProbe ThreadControlProbe UnsafeProbe JniProbe FinalizerProbe DefaultsProbe; do echo "--- $CLS"; both; done + CLS=SecurityManagerProbe; echo "--- SecurityManagerProbe with -Djava.security.manager=allow"; both -Djava.security.manager=allow 2>/dev/null | grep -v -E 'WARNING|^\s+\[[0-9.]+\] \s+at ' + CLS=UnsafeProbe; echo "--- UnsafeProbe on 25 with --sun-misc-unsafe-memory-access=deny"; one "$J25" --sun-misc-unsafe-memory-access=deny + echo "--- UnsafeProbe on 25 with --sun-misc-unsafe-memory-access=debug"; one "$J25" --sun-misc-unsafe-memory-access=debug + CLS=JniProbe; echo "--- JniProbe on 25 with --enable-native-access=ALL-UNNAMED"; one "$J25" --enable-native-access=ALL-UNNAMED + echo "--- JniProbe on 25 with --illegal-native-access=deny"; one "$J25" --illegal-native-access=deny + CLS=FinalizerProbe; echo "--- FinalizerProbe on 25 with --finalization=disabled"; one "$J25" --finalization=disabled +} > "$OUT/01-runtime-behaviour.txt" + +./scripts/flags.sh > "$OUT/02-startup-flags.txt" +{ echo "--- JDK 25: compact object headers together with -XX:-UseCompressedClassPointers" + "$J25/bin/java" -XX:+UseCompactObjectHeaders -XX:-UseCompressedClassPointers -version 2>&1 | clean | grep 'Compact object headers' | sed 's/^/ /' + echo "--- JDK 25: CDS archive picked up with compact headers" + "$J25/bin/java" -XX:+UseCompactObjectHeaders -Xlog:cds -version 2>&1 | clean | grep 'trying to map' | head -1 | sed -E 's#^\[[^]]*\]\[info\]\[cds\] ##; s#[^ ]*/lib/server/#/lib/server/#' | sed 's/^/ /' +} >> "$OUT/02-startup-flags.txt" + +jc() { local j=$1; shift; "$j/bin/javac" "$@" 2>&1 | clean | grep -v '^Note:'; } +{ echo "# 03-source-and-preview: preview code written for 21, and 25 APIs tried on 21" + for f in StringTemplateDemo StructuredTaskDemo; do + echo "=== $f: compile on 21 with --enable-preview, run on 21" + jc "$J21" --release 21 --enable-preview -d "$W/p21" src/preview21/$f.java; "$J21/bin/java" --enable-preview -cp "$W/p21" $f 2>&1 | clean + echo "=== $f: run the same class on 25 (with --enable-preview)" + "$J25/bin/java" --enable-preview -cp "$W/p21" $f 2>&1 | clean | head -2 + echo "=== $f: recompile the source on 25 with --enable-preview" + jc "$J25" --release 25 --enable-preview -d "$W/p25" src/preview21/$f.java + done + echo "=== ThreadSuspendCall.java: javac on 21, then 25" + jc "$J21" -nowarn -d "$W/b21" src/broken/ThreadSuspendCall.java; echo " 21 exit $(("$J21/bin/javac" -nowarn -d "$W/b21" src/broken/ThreadSuspendCall.java >/dev/null 2>&1); echo $?)" + jc "$J25" -d "$W/b25" src/broken/ThreadSuspendCall.java + for f in ScopedValueDemo GathererDemo; do + echo "=== $f.java: javac on 21"; jc "$J21" -d "$W/n21" src/new25/$f.java | head -4 + echo "=== $f.java: javac and java on 25, no flags"; jc "$J25" -d "$W/n25" src/new25/$f.java; "$J25/bin/java" -cp "$W/n25" $f 2>&1 | clean + done +} > "$OUT/03-source-and-preview.txt" + +D=$W/apidiff; mkdir -p "$D" +[ -s "$D/api-21.txt" ] || python3 ../api-diff/dump_api.py "$J21" "$D/api-21.txt" >/dev/null +[ -s "$D/api-25.txt" ] || python3 ../api-diff/dump_api.py "$J25" "$D/api-25.txt" >/dev/null +{ echo "# 04-removed-api: public types and methods in JDK 21 that are gone in JDK 25 (javap -public over java.* and selected jdk.* modules)" + python3 scripts/removed_api.py "$D/api-21.txt" "$D/api-25.txt"; } > "$OUT/04-removed-api.txt" + +"$J21/bin/jar" cf "$W/probes.jar" -C "$C" . 2>/dev/null +{ echo "# 09-scanners: JDK 25 tools pointed at a jar built by JDK 21" + echo "--- jdeps --jdk-internals probes.jar"; "$J25/bin/jdeps" --jdk-internals "$W/probes.jar" 2>&1 | clean | grep -E 'probes.jar|->' | head -3 + echo "--- jdeprscan --release 25 --for-removal probes.jar"; "$J25/bin/jdeprscan" --release 25 --for-removal "$W/probes.jar" 2>&1 | clean | grep '^class' | sort +} > "$OUT/09-scanners.txt" + +for j in "$J21" "$J25"; do "$j/bin/java" -cp "$C" LocaleProbe 2>&1 | clean > "$W/locale-$(ver "$j").txt"; done +{ echo "# 10-locale-diff: LocaleProbe (compiled once on 21) run on both JDKs; only the lines that differ. $(wc -l < "$W/locale-$(ver "$J21").txt") formats compared" + diff "$W/locale-$(ver "$J21").txt" "$W/locale-$(ver "$J25").txt" | grep -E '^[<>]' | sed "s/^/ [25]/" +} > "$OUT/10-locale-diff.txt" + +{ echo "# 11-pinning: compiled once on 21; run with -Djdk.virtualThreadScheduler.parallelism=2. Elapsed times are machine dependent" + for CLS in PinningProbe ClassInitPinningProbe; do echo "--- $CLS"; both -Djdk.virtualThreadScheduler.parallelism=2; done + CLS=PinningProbe; echo "--- PinningProbe with -Djdk.tracePinnedThreads=short (first lines)" + for j in "$J21" "$J25"; do one "$j" -Djdk.virtualThreadScheduler.parallelism=2 -Djdk.tracePinnedThreads=short | head -3; done +} > "$OUT/11-pinning.txt" + +"$J25/bin/javac" -d "$W/c25" src/headers/HeaderProbe.java 2>/dev/null +{ echo "# 12-object-headers: bytes allocated per object on JDK $(ver "$J25"), 1,000,000 objects each" + echo "--- default (-XX:-UseCompactObjectHeaders)"; "$J25/bin/java" -cp "$W/c25" HeaderProbe 2>&1 | clean | sed 's/^/ /' + echo "--- -XX:+UseCompactObjectHeaders"; "$J25/bin/java" -XX:+UseCompactObjectHeaders -cp "$W/c25" HeaderProbe 2>&1 | clean | sed 's/^/ /' +} > "$OUT/12-object-headers.txt" +echo done diff --git a/java21-to-25/src/broken/ThreadSuspendCall.java b/java21-to-25/src/broken/ThreadSuspendCall.java new file mode 100644 index 0000000..003a35a --- /dev/null +++ b/java21-to-25/src/broken/ThreadSuspendCall.java @@ -0,0 +1,6 @@ +public class ThreadSuspendCall { + @SuppressWarnings({"deprecation", "removal"}) + static void pause(Thread t) { + t.suspend(); + } +} diff --git a/java21-to-25/src/headers/HeaderProbe.java b/java21-to-25/src/headers/HeaderProbe.java new file mode 100644 index 0000000..e76cb1f --- /dev/null +++ b/java21-to-25/src/headers/HeaderProbe.java @@ -0,0 +1,39 @@ +import com.sun.management.ThreadMXBean; +import java.lang.management.ManagementFactory; +import java.util.function.IntFunction; + +/** + * Bytes allocated per object, measured with the per-thread allocation counter (exact, not a heap delta). + * Run with and without -XX:+UseCompactObjectHeaders (JEP 519, a product flag in JDK 25). + */ +public class HeaderProbe { + record Empty() { } + record OneInt(int a) { } + record TwoInts(int a, int b) { } + record ThreeInts(int a, int b, int c) { } + record IntAndRef(int a, Object r) { } + + static final int N = 1_000_000; + + public static void main(String[] args) { + measure("new Object() ", i -> new Object()); + measure("record() ", i -> new Empty()); + measure("record(int) ", i -> new OneInt(i)); + measure("record(int,int) ", i -> new TwoInts(i, i)); + measure("record(int,int,int) ", i -> new ThreeInts(i, i, i)); + measure("record(int,Object) ", i -> new IntAndRef(i, null)); + measure("Long (outside cache) ", i -> Long.valueOf(1000L + i)); + measure("byte[8] ", i -> new byte[8]); + } + + static void measure(String label, IntFunction make) { + var mx = (ThreadMXBean) ManagementFactory.getThreadMXBean(); + Object[] keep = new Object[N]; + make.apply(0); + long before = mx.getCurrentThreadAllocatedBytes(); + for (int i = 0; i < N; i++) keep[i] = make.apply(i); + long after = mx.getCurrentThreadAllocatedBytes(); + System.out.println(label + " " + Math.round((after - before) / (double) N) + " bytes/object"); + if (keep[N - 1] == null) throw new AssertionError(); + } +} diff --git a/java21-to-25/src/new25/GathererDemo.java b/java21-to-25/src/new25/GathererDemo.java new file mode 100644 index 0000000..5189e0b --- /dev/null +++ b/java21-to-25/src/new25/GathererDemo.java @@ -0,0 +1,14 @@ +import java.util.List; +import java.util.stream.Gatherers; +import java.util.stream.Stream; + +/** Stream gatherers are final since Java 24 (JEP 485); on 21 the package does not contain them. */ +public class GathererDemo { + public static void main(String[] args) { + System.out.println(Stream.of(1, 2, 3, 4, 5).gather(Gatherers.windowFixed(2)).toList()); + System.out.println(Stream.of(1, 2, 3, 4).gather(Gatherers.windowSliding(3)).toList()); + System.out.println(Stream.of(1, 2, 3, 4).gather(Gatherers.scan(() -> 0, Integer::sum)).toList()); + List out = Stream.of("a", "b", "c").gather(Gatherers.mapConcurrent(2, String::toUpperCase)).toList(); + System.out.println(out); + } +} diff --git a/java21-to-25/src/new25/ScopedValueDemo.java b/java21-to-25/src/new25/ScopedValueDemo.java new file mode 100644 index 0000000..8af1cc2 --- /dev/null +++ b/java21-to-25/src/new25/ScopedValueDemo.java @@ -0,0 +1,13 @@ +/** Scoped values are final in Java 25 (JEP 506). On 21 they need --enable-preview. */ +public class ScopedValueDemo { + private static final ScopedValue REQUEST_ID = ScopedValue.newInstance(); + + public static void main(String[] args) { + ScopedValue.where(REQUEST_ID, "req-17").run(ScopedValueDemo::handle); + System.out.println("bound outside the scope: " + REQUEST_ID.isBound()); + } + + static void handle() { + System.out.println("handling " + REQUEST_ID.get() + " on " + Thread.currentThread().getName()); + } +} diff --git a/java21-to-25/src/pinning/ClassInitPinningProbe.java b/java21-to-25/src/pinning/ClassInitPinningProbe.java new file mode 100644 index 0000000..9beff2f --- /dev/null +++ b/java21-to-25/src/pinning/ClassInitPinningProbe.java @@ -0,0 +1,49 @@ +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import jdk.jfr.Recording; +import jdk.jfr.consumer.RecordedEvent; +import jdk.jfr.consumer.RecordingFile; +import java.nio.file.Files; + +/** + * What JEP 491 did NOT fix: blocking while a class is being initialized still pins the carrier. + * 8 virtual threads each initialize a different class whose static initializer sleeps 100 ms. + */ +public class ClassInitPinningProbe { + static class C0 { static { nap(); } static void touch() { } } + static class C1 { static { nap(); } static void touch() { } } + static class C2 { static { nap(); } static void touch() { } } + static class C3 { static { nap(); } static void touch() { } } + static class C4 { static { nap(); } static void touch() { } } + static class C5 { static { nap(); } static void touch() { } } + static class C6 { static { nap(); } static void touch() { } } + static class C7 { static { nap(); } static void touch() { } } + + static void nap() { + try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } + } + + public static void main(String[] args) throws Exception { + Runnable[] work = {C0::touch, C1::touch, C2::touch, C3::touch, C4::touch, C5::touch, C6::touch, C7::touch}; + try (var rec = new Recording()) { + rec.enable("jdk.VirtualThreadPinned").withThreshold(Duration.ofMillis(20)); + rec.start(); + long start = System.nanoTime(); + List threads = new ArrayList<>(); + for (Runnable r : work) threads.add(Thread.ofVirtual().start(r)); + for (Thread t : threads) t.join(); + long ms = (System.nanoTime() - start) / 1_000_000; + rec.stop(); + var file = Files.createTempFile("pin", ".jfr"); + rec.dump(file); + List events = RecordingFile.readAllEvents(file); + Files.delete(file); + System.out.println("java " + Runtime.version().feature() + ": 8 classes, 100 ms sleep inside each static initializer"); + System.out.println("elapsed = " + ms + " ms, jdk.VirtualThreadPinned events = " + events.size()); + if (!events.isEmpty() && events.get(0).hasField("pinnedReason")) { + System.out.println("first event pinnedReason = " + events.get(0).getString("pinnedReason")); + } + } + } +} diff --git a/java21-to-25/src/pinning/PinningProbe.java b/java21-to-25/src/pinning/PinningProbe.java new file mode 100644 index 0000000..a0b0bf5 --- /dev/null +++ b/java21-to-25/src/pinning/PinningProbe.java @@ -0,0 +1,43 @@ +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import jdk.jfr.Recording; +import jdk.jfr.consumer.RecordingFile; +import java.nio.file.Files; + +/** + * 20 virtual threads each block for 100 ms inside a synchronized block on their own lock, with the + * scheduler limited to 2 carrier threads. Pinned: about 20 x 100 / 2 = 1000 ms. Not pinned: about 100 ms. + * Run with -Djdk.virtualThreadScheduler.parallelism=2. Also counts jdk.VirtualThreadPinned JFR events. + */ +public class PinningProbe { + static final int THREADS = 20; + + public static void main(String[] args) throws Exception { + try (var rec = new Recording()) { + rec.enable("jdk.VirtualThreadPinned").withThreshold(Duration.ofMillis(20)); + rec.start(); + long start = System.nanoTime(); + List threads = new ArrayList<>(); + for (int i = 0; i < THREADS; i++) { + Object lock = new Object(); + threads.add(Thread.ofVirtual().start(() -> { + synchronized (lock) { sleep(); } + })); + } + for (Thread t : threads) t.join(); + long ms = (System.nanoTime() - start) / 1_000_000; + rec.stop(); + var file = Files.createTempFile("pin", ".jfr"); + rec.dump(file); + long events = RecordingFile.readAllEvents(file).size(); + Files.delete(file); + System.out.println("java " + Runtime.version().feature() + ": " + THREADS + " threads, 100 ms sleep inside synchronized"); + System.out.println("elapsed = " + ms + " ms, jdk.VirtualThreadPinned events = " + events); + } + } + + static void sleep() { + try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } + } +} diff --git a/java21-to-25/src/preview21/StringTemplateDemo.java b/java21-to-25/src/preview21/StringTemplateDemo.java new file mode 100644 index 0000000..8af1d45 --- /dev/null +++ b/java21-to-25/src/preview21/StringTemplateDemo.java @@ -0,0 +1,7 @@ +/** String templates were a preview in 21 and 22 and were withdrawn in 23. There is no replacement syntax. */ +public class StringTemplateDemo { + public static void main(String[] args) { + String name = "Ankur"; + System.out.println(STR."Hello \{name}"); + } +} diff --git a/java21-to-25/src/preview21/StructuredTaskDemo.java b/java21-to-25/src/preview21/StructuredTaskDemo.java new file mode 100644 index 0000000..d29416d --- /dev/null +++ b/java21-to-25/src/preview21/StructuredTaskDemo.java @@ -0,0 +1,13 @@ +import java.util.concurrent.StructuredTaskScope; + +/** The Java 21 shape of structured concurrency (JEP 453): new ShutdownOnFailure(). */ +public class StructuredTaskDemo { + public static void main(String[] args) throws Exception { + try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { + var user = scope.fork(() -> "user-7"); + var order = scope.fork(() -> "order-42"); + scope.join().throwIfFailed(); + System.out.println(user.get() + " " + order.get()); + } + } +} diff --git a/java21-to-25/src/probes/DefaultsProbe.java b/java21-to-25/src/probes/DefaultsProbe.java new file mode 100644 index 0000000..f7689fd --- /dev/null +++ b/java21-to-25/src/probes/DefaultsProbe.java @@ -0,0 +1,20 @@ +import java.lang.management.ManagementFactory; +import com.sun.management.HotSpotDiagnosticMXBean; + +/** Prints the ergonomic choices the JVM made: collector, heap, CPUs, and the object-header flag if it exists. */ +public class DefaultsProbe { + public static void main(String[] args) { + System.out.println("java.version = " + System.getProperty("java.version")); + System.out.println("availableProcessors = " + Runtime.getRuntime().availableProcessors()); + System.out.println("maxMemory MiB = " + Runtime.getRuntime().maxMemory() / (1024 * 1024)); + ManagementFactory.getGarbageCollectorMXBeans().forEach(b -> System.out.println("collector bean: " + b.getName())); + var hs = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class); + for (String flag : new String[] {"UseCompactObjectHeaders", "ZGenerational"}) { + try { + System.out.println(flag + " = " + hs.getVMOption(flag).getValue()); + } catch (IllegalArgumentException e) { + System.out.println(flag + " = (no such flag in this JVM)"); + } + } + } +} diff --git a/java21-to-25/src/probes/FinalizerProbe.java b/java21-to-25/src/probes/FinalizerProbe.java new file mode 100644 index 0000000..7b3273a --- /dev/null +++ b/java21-to-25/src/probes/FinalizerProbe.java @@ -0,0 +1,14 @@ +/** Finalization is deprecated for removal (JEP 421) but still on by default. */ +public class FinalizerProbe { + static volatile boolean ran; + + @SuppressWarnings("removal") + @Override + protected void finalize() { ran = true; } + + public static void main(String[] args) throws Exception { + new FinalizerProbe(); + for (int i = 0; i < 50 && !ran; i++) { System.gc(); Thread.sleep(20); } + System.out.println("finalize() ran: " + ran); + } +} diff --git a/java21-to-25/src/probes/JniProbe.java b/java21-to-25/src/probes/JniProbe.java new file mode 100644 index 0000000..b4cb43c --- /dev/null +++ b/java21-to-25/src/probes/JniProbe.java @@ -0,0 +1,11 @@ +/** Loading a native library is a restricted operation since JDK 24 (JEP 472). The library is the JDK's own libnet. */ +public class JniProbe { + public static void main(String[] args) { + try { + System.loadLibrary("net"); + System.out.println("System.loadLibrary(\"net\") returned"); + } catch (Throwable t) { + System.out.println("failed: " + t.getClass().getSimpleName() + ": " + t.getMessage()); + } + } +} diff --git a/java21-to-25/src/probes/LocaleProbe.java b/java21-to-25/src/probes/LocaleProbe.java new file mode 100644 index 0000000..c0470cc --- /dev/null +++ b/java21-to-25/src/probes/LocaleProbe.java @@ -0,0 +1,37 @@ +import java.text.NumberFormat; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.util.Locale; + +/** + * Locale data comes from CLDR and changes between JDK releases. Prints a fixed set of formats so that the + * output of two runtimes can be diffed. Non-ASCII characters are escaped so invisible changes show up. + */ +public class LocaleProbe { + public static void main(String[] args) { + var when = LocalDateTime.of(2026, 9, 5, 14, 7, 9).atZone(ZoneId.of("Asia/Kolkata")); + for (String tag : new String[] {"en-US", "en-GB", "en-IN", "hi-IN", "mr-IN", "de-DE", "de-CH", "fr-FR", "ja-JP"}) { + Locale l = Locale.forLanguageTag(tag); + for (FormatStyle s : FormatStyle.values()) { + print(tag, "dateTime " + s, () -> DateTimeFormatter.ofLocalizedDateTime(s).withLocale(l).format(when)); + } + print(tag, "month MMM", () -> DateTimeFormatter.ofPattern("d MMM yyyy", l).format(when)); + print(tag, "number", () -> NumberFormat.getInstance(l).format(12345678.5)); + print(tag, "currency", () -> NumberFormat.getCurrencyInstance(l).format(12345678.5)); + print(tag, "compact", () -> NumberFormat.getCompactNumberInstance(l, NumberFormat.Style.SHORT).format(12345678)); + print(tag, "percent", () -> NumberFormat.getPercentInstance(l).format(0.25)); + } + } + + interface Fmt { String get(); } + + static void print(String tag, String what, Fmt f) { + StringBuilder out = new StringBuilder(); + for (char c : f.get().toCharArray()) { + if (c >= 32 && c < 127) out.append(c); else out.append(String.format("\\u%04X", (int) c)); + } + System.out.println(tag + " | " + what + " | " + out); + } +} diff --git a/java21-to-25/src/probes/SecurityManagerProbe.java b/java21-to-25/src/probes/SecurityManagerProbe.java new file mode 100644 index 0000000..9f01080 --- /dev/null +++ b/java21-to-25/src/probes/SecurityManagerProbe.java @@ -0,0 +1,11 @@ +/** Security Manager: JDK 21 still lets you opt in; JEP 486 (JDK 24) removed that. */ +public class SecurityManagerProbe { + public static void main(String[] args) { + try { + System.setSecurityManager(new SecurityManager()); + System.out.println("setSecurityManager: installed = " + (System.getSecurityManager() != null)); + } catch (Throwable t) { + System.out.println("setSecurityManager: " + t.getClass().getSimpleName() + ": " + t.getMessage()); + } + } +} diff --git a/java21-to-25/src/probes/SubjectProbe.java b/java21-to-25/src/probes/SubjectProbe.java new file mode 100644 index 0000000..57137ae --- /dev/null +++ b/java21-to-25/src/probes/SubjectProbe.java @@ -0,0 +1,19 @@ +import java.security.AccessController; +import javax.security.auth.Subject; + +/** + * Subject.getSubject(AccessController.getContext()) was the old way to ask "who is logged in?". + * Libraries built around JAAS used it. The replacement, Subject.current(), exists since JDK 18. + */ +public class SubjectProbe { + @SuppressWarnings("removal") + public static void main(String[] args) { + try { + Subject s = Subject.getSubject(AccessController.getContext()); + System.out.println("Subject.getSubject: returned " + s); + } catch (Throwable t) { + System.out.println("Subject.getSubject: " + t.getClass().getSimpleName() + ": " + t.getMessage()); + } + System.out.println("Subject.current(): returned " + Subject.current()); + } +} diff --git a/java21-to-25/src/probes/ThreadControlProbe.java b/java21-to-25/src/probes/ThreadControlProbe.java new file mode 100644 index 0000000..185fa3f --- /dev/null +++ b/java21-to-25/src/probes/ThreadControlProbe.java @@ -0,0 +1,22 @@ +/** Thread.stop / suspend / resume, compiled on 21 and then run on 21 and 25. */ +public class ThreadControlProbe { + @SuppressWarnings({"deprecation", "removal"}) + public static void main(String[] args) throws Exception { + Thread t = new Thread(() -> { while (!Thread.currentThread().isInterrupted()) Thread.onSpinWait(); }); + t.setDaemon(true); + t.start(); + attempt("suspend()", () -> t.suspend()); + attempt("resume() ", () -> t.resume()); + attempt("stop() ", () -> t.stop()); + t.interrupt(); + } + + static void attempt(String name, Runnable r) { + try { + r.run(); + System.out.println(name + " returned normally"); + } catch (Throwable e) { + System.out.println(name + " " + e.getClass().getName() + (e.getMessage() == null ? "" : ": " + e.getMessage())); + } + } +} diff --git a/java21-to-25/src/probes/UnsafeProbe.java b/java21-to-25/src/probes/UnsafeProbe.java new file mode 100644 index 0000000..506756e --- /dev/null +++ b/java21-to-25/src/probes/UnsafeProbe.java @@ -0,0 +1,19 @@ +import java.lang.reflect.Field; +import sun.misc.Unsafe; + +/** The classic off-heap round trip through sun.misc.Unsafe (JEP 471 deprecated it, JEP 498 warns). */ +public class UnsafeProbe { + public static void main(String[] args) throws Exception { + Field f = Unsafe.class.getDeclaredField("theUnsafe"); + f.setAccessible(true); + Unsafe unsafe = (Unsafe) f.get(null); + try { + long address = unsafe.allocateMemory(8); + unsafe.putLong(address, 42L); + System.out.println("read back: " + unsafe.getLong(address)); + unsafe.freeMemory(address); + } catch (Throwable t) { + System.out.println("failed: " + t.getClass().getSimpleName() + ": " + t.getMessage()); + } + } +}