From d005b97438f3a50ccece806f8c3bc2e1ddef16d2 Mon Sep 17 00:00:00 2001 From: shshahma Date: Wed, 17 May 2017 22:22:15 -0700 Subject: [PATCH] 8176055: JMX diagnostic improvements Reviewed-by: dfuchs, mchung, ahgross, rhalade, jwilhelm --- .../com/sun/management/HotSpotDiagnosticMXBean.java | 5 +++-- .../classes/sun/management/HotSpotDiagnostic.java | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java b/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java index 9bcdd8547..488edcdea 100644 --- a/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java +++ b/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -63,9 +63,10 @@ public interface HotSpotDiagnosticMXBean extends PlatformManagedObject { * @param outputFile the system-dependent filename * @param live if true dump only live objects * i.e. objects that are reachable from others - * @throws IOException if the outputFile + * @throws IOException if the outputFile already exists, * cannot be created, opened, or written to. * @throws UnsupportedOperationException if this operation is not supported. + * @throws IllegalArgumentException if outputFile does not end with ".hprof" suffix. * @throws NullPointerException if outputFile is null. * @throws SecurityException * If a security manager exists and its {@link diff --git a/src/share/classes/sun/management/HotSpotDiagnostic.java b/src/share/classes/sun/management/HotSpotDiagnostic.java index d2e7b3972..dffaafe55 100644 --- a/src/share/classes/sun/management/HotSpotDiagnostic.java +++ b/src/share/classes/sun/management/HotSpotDiagnostic.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,6 +32,8 @@ import javax.management.ObjectName; import com.sun.management.HotSpotDiagnosticMXBean; import com.sun.management.VMOption; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * Implementation of the diagnostic MBean for Hotspot VM. @@ -41,6 +43,14 @@ public class HotSpotDiagnostic implements HotSpotDiagnosticMXBean { } public void dumpHeap(String outputFile, boolean live) throws IOException { + + String propertyName = "jdk.management.heapdump.allowAnyFileSuffix"; + PrivilegedAction pa = () -> Boolean.parseBoolean(System.getProperty(propertyName, "false")); + boolean allowAnyFileSuffix = AccessController.doPrivileged(pa); + if (!allowAnyFileSuffix && !outputFile.endsWith(".hprof")) { + throw new IllegalArgumentException("heapdump file must have .hprof extention"); + } + SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkWrite(outputFile); -- GitLab