Browse Source

Use system properties to detect OpenJ9 JVMs when doing heapdumps

Closes gh-45973
3.3.x
Moritz Halbritter 6 months ago
parent
commit
0f77dcb402
  1. 22
      spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java

22
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.nio.file.Files;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -46,6 +47,7 @@ import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
/** /**
* Web {@link Endpoint @Endpoint} to expose heap dumps. * Web {@link Endpoint @Endpoint} to expose heap dumps.
@ -111,12 +113,22 @@ public class HeapDumpWebEndpoint {
* @throws HeapDumperUnavailableException if the heap dumper cannot be created * @throws HeapDumperUnavailableException if the heap dumper cannot be created
*/ */
protected HeapDumper createHeapDumper() throws HeapDumperUnavailableException { protected HeapDumper createHeapDumper() throws HeapDumperUnavailableException {
try { if (isRunningOnOpenJ9()) {
return new HotSpotDiagnosticMXBeanHeapDumper();
}
catch (HeapDumperUnavailableException ex) {
return new OpenJ9DiagnosticsMXBeanHeapDumper(); 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;
} }
/** /**

Loading…
Cancel
Save