Skip to content

Commit 0f77dcb

Browse files
committed
Use system properties to detect OpenJ9 JVMs when doing heapdumps
Closes gh-45973
1 parent c13dc92 commit 0f77dcb

File tree

1 file changed

+17
-5
lines changed
  • spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management

1 file changed

+17
-5
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
2929
import java.nio.file.Files;
3030
import java.time.LocalDateTime;
3131
import java.time.format.DateTimeFormatter;
32+
import java.util.Locale;
3233
import java.util.concurrent.TimeUnit;
3334
import java.util.concurrent.locks.Lock;
3435
import java.util.concurrent.locks.ReentrantLock;
@@ -46,6 +47,7 @@
4647
import org.springframework.util.Assert;
4748
import org.springframework.util.ClassUtils;
4849
import org.springframework.util.ReflectionUtils;
50+
import org.springframework.util.StringUtils;
4951

5052
/**
5153
* Web {@link Endpoint @Endpoint} to expose heap dumps.
@@ -111,12 +113,22 @@ private Resource dumpHeap(Boolean live) throws IOException, InterruptedException
111113
* @throws HeapDumperUnavailableException if the heap dumper cannot be created
112114
*/
113115
protected HeapDumper createHeapDumper() throws HeapDumperUnavailableException {
114-
try {
115-
return new HotSpotDiagnosticMXBeanHeapDumper();
116-
}
117-
catch (HeapDumperUnavailableException ex) {
116+
if (isRunningOnOpenJ9()) {
118117
return new OpenJ9DiagnosticsMXBeanHeapDumper();
119118
}
119+
return new HotSpotDiagnosticMXBeanHeapDumper();
120+
}
121+
122+
private boolean isRunningOnOpenJ9() {
123+
String vmName = System.getProperty("java.vm.name");
124+
if (StringUtils.hasLength(vmName) && vmName.toLowerCase(Locale.ROOT).contains("openj9")) {
125+
return true;
126+
}
127+
String vmVendor = System.getProperty("java.vm.vendor");
128+
if (StringUtils.hasLength(vmVendor) && vmVendor.toLowerCase(Locale.ROOT).contains("openj9")) {
129+
return true;
130+
}
131+
return false;
120132
}
121133

122134
/**

0 commit comments

Comments
 (0)