|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
29 | 29 | import java.nio.file.Files;
|
30 | 30 | import java.time.LocalDateTime;
|
31 | 31 | import java.time.format.DateTimeFormatter;
|
| 32 | +import java.util.Locale; |
32 | 33 | import java.util.concurrent.TimeUnit;
|
33 | 34 | import java.util.concurrent.locks.Lock;
|
34 | 35 | import java.util.concurrent.locks.ReentrantLock;
|
|
46 | 47 | import org.springframework.util.Assert;
|
47 | 48 | import org.springframework.util.ClassUtils;
|
48 | 49 | import org.springframework.util.ReflectionUtils;
|
| 50 | +import org.springframework.util.StringUtils; |
49 | 51 |
|
50 | 52 | /**
|
51 | 53 | * Web {@link Endpoint @Endpoint} to expose heap dumps.
|
@@ -111,12 +113,22 @@ private Resource dumpHeap(Boolean live) throws IOException, InterruptedException
|
111 | 113 | * @throws HeapDumperUnavailableException if the heap dumper cannot be created
|
112 | 114 | */
|
113 | 115 | protected HeapDumper createHeapDumper() throws HeapDumperUnavailableException {
|
114 |
| - try { |
115 |
| - return new HotSpotDiagnosticMXBeanHeapDumper(); |
116 |
| - } |
117 |
| - catch (HeapDumperUnavailableException ex) { |
| 116 | + if (isRunningOnOpenJ9()) { |
118 | 117 | return new OpenJ9DiagnosticsMXBeanHeapDumper();
|
119 | 118 | }
|
| 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; |
120 | 132 | }
|
121 | 133 |
|
122 | 134 | /**
|
|
0 commit comments