diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java index b120533b2db..0a83e9c3414 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import java.nio.channels.ReadableByteChannel; import java.nio.file.Files; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Locale; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -46,6 +47,7 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; +import org.springframework.util.StringUtils; /** * Web {@link Endpoint @Endpoint} to expose heap dumps. @@ -111,12 +113,22 @@ public class HeapDumpWebEndpoint { * @throws HeapDumperUnavailableException if the heap dumper cannot be created */ protected HeapDumper createHeapDumper() throws HeapDumperUnavailableException { - try { - return new HotSpotDiagnosticMXBeanHeapDumper(); - } - catch (HeapDumperUnavailableException ex) { + if (isRunningOnOpenJ9()) { return new OpenJ9DiagnosticsMXBeanHeapDumper(); } + return new HotSpotDiagnosticMXBeanHeapDumper(); + } + + private boolean isRunningOnOpenJ9() { + String vmName = System.getProperty("java.vm.name"); + if (StringUtils.hasLength(vmName) && vmName.toLowerCase(Locale.ROOT).contains("openj9")) { + return true; + } + String vmVendor = System.getProperty("java.vm.vendor"); + if (StringUtils.hasLength(vmVendor) && vmVendor.toLowerCase(Locale.ROOT).contains("openj9")) { + return true; + } + return false; } /**