Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-17361 OpenJ9 can't compile solr: No method HotSpotDiagnosticMXBean.dumpHeap #2929

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions solr/benchmark/src/java/org/apache/solr/bench/BaseBenchState.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
*/
package org.apache.solr.bench;

import com.sun.management.HotSpotDiagnosticMXBean;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.lang.management.ManagementFactory;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.SplittableRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.apache.commons.io.file.PathUtils;
import org.apache.solr.bench.generators.SolrGen;
import org.apache.solr.common.util.SuppressForbidden;
Expand Down Expand Up @@ -132,25 +131,28 @@ public static void doTearDown(BenchmarkParams benchmarkParams) throws Exception
* Dump heap.
*
* @param benchmarkParams the benchmark params
* @throws IOException the io exception
*/
@SuppressForbidden(reason = "access to force heapdump")
public static void dumpHeap(BenchmarkParams benchmarkParams) throws IOException {
public static void dumpHeap(BenchmarkParams benchmarkParams) {
String heapDump = System.getProperty("dumpheap");
if (heapDump != null) {

boolean dumpHeap = HEAP_DUMPED.compareAndExchange(false, true);
if (dumpHeap) {
Path file = Path.of(heapDump);
PathUtils.deleteDirectory(file);
Files.createDirectories(file);
Path dumpFile = file.resolve(benchmarkParams.id() + ".hprof");

MBeanServer server = ManagementFactory.getPlatformMBeanServer();
HotSpotDiagnosticMXBean mxBean =
ManagementFactory.newPlatformMXBeanProxy(
server, "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
mxBean.dumpHeap(dumpFile.toAbsolutePath().toString(), true);
try {
PathUtils.deleteDirectory(file);
Files.createDirectories(file);
Path dumpFile = file.resolve(benchmarkParams.id() + ".hprof");

MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName hotSpot = ObjectName.getInstance("com.sun.management:type=HotSpotDiagnostic");
Object[] params = new Object[] {dumpFile.toAbsolutePath().toString(), true};
String signature[] = new String[] {"java.lang.String", "boolean"};
server.invoke(hotSpot, "dumpHeap", params, signature);
} catch (Exception e) {
log("unable to dump heap " + e.getMessage());
}
}
}
}
Expand Down
Loading