# HG changeset patch
# User shshahma
# Date 1500356742 -3600
# Node ID c54643d2a32b1c14aa34e3b0a8c8d845aad3928f
# Parent d4e4af750774001f2031870b180fd0e24465fb1d
8176055: JMX diagnostic improvements
Reviewed-by: dfuchs, mchung, ahgross, rhalade, jwilhelm
diff -r d4e4af750774 -r c54643d2a32b src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java
--- 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 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 -r d4e4af750774 -r c54643d2a32b src/share/classes/sun/management/HotSpotDiagnostic.java
--- 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 pa = new PrivilegedAction() {
+ @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);