Mercurial > hg > openjdk > bsd-port > jdk
changeset 8734:c54643d2a32b
8176055: JMX diagnostic improvements
Reviewed-by: dfuchs, mchung, ahgross, rhalade, jwilhelm
author | shshahma |
---|---|
date | Tue, 18 Jul 2017 06:45:42 +0100 |
parents | d4e4af750774 |
children | fe453cb558d3 |
files | src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java src/share/classes/sun/management/HotSpotDiagnostic.java |
diffstat | 2 files changed, 19 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java Tue Jul 18 06:14:47 2017 +0100 +++ b/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java Tue Jul 18 06:45:42 2017 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, 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 @@ -62,9 +62,10 @@ * @param outputFile the system-dependent filename * @param live if <tt>true</tt> dump only <i>live</i> objects * i.e. objects that are reachable from others - * @throws IOException if the <tt>outputFile</tt> + * @throws IOException if the <tt>outputFile</tt> already exists, * cannot be created, opened, or written to. * @throws UnsupportedOperationException if this operation is not supported. + * @throws IllegalArgumentException if <tt>outputFile</tt> does not end with ".hprof" suffix. * @throws NullPointerException if <tt>outputFile</tt> is <tt>null</tt>. * @throws SecurityException * If a security manager exists and its {@link
--- a/src/share/classes/sun/management/HotSpotDiagnostic.java Tue Jul 18 06:14:47 2017 +0100 +++ b/src/share/classes/sun/management/HotSpotDiagnostic.java Tue Jul 18 06:45:42 2017 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, 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 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,19 @@ } public void dumpHeap(String outputFile, boolean live) throws IOException { + + final String propertyName = "jdk.management.heapdump.allowAnyFileSuffix"; + PrivilegedAction<Boolean> pa = new PrivilegedAction<Boolean>() { + @Override + public Boolean run() { + return 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);