8016357: Update hotspot diagnostic class
authorsgabdura
Tue, 23 Jul 2013 09:30:58 +0400
changeset 20826 d9ee83c801f6
parent 20825 3d5429b4b601
child 20827 29e3da385ed2
8016357: Update hotspot diagnostic class Summary: Add security check to HotSpotDiagnostic.dumpHeap Reviewed-by: fparain, sla, ahgross
jdk/make/java/management/mapfile-vers
jdk/makefiles/mapfiles/libmanagement/mapfile-vers
jdk/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java
jdk/src/share/classes/sun/management/HotSpotDiagnostic.java
jdk/src/share/native/sun/management/HotSpotDiagnostic.c
--- a/jdk/make/java/management/mapfile-vers	Mon Jul 22 19:41:07 2013 -0700
+++ b/jdk/make/java/management/mapfile-vers	Tue Jul 23 09:30:58 2013 +0400
@@ -57,7 +57,7 @@
 	    Java_sun_management_GcInfoBuilder_fillGcAttributeInfo;
 	    Java_sun_management_GcInfoBuilder_getLastGcInfo0;
 	    Java_sun_management_GcInfoBuilder_getNumGcExtAttributes;
-	    Java_sun_management_HotSpotDiagnostic_dumpHeap;
+	    Java_sun_management_HotSpotDiagnostic_dumpHeap0;
 	    Java_sun_management_HotspotThread_getInternalThreadCount;
 	    Java_sun_management_HotspotThread_getInternalThreadTimes0;
 	    Java_sun_management_MemoryImpl_getMemoryManagers0;
--- a/jdk/makefiles/mapfiles/libmanagement/mapfile-vers	Mon Jul 22 19:41:07 2013 -0700
+++ b/jdk/makefiles/mapfiles/libmanagement/mapfile-vers	Tue Jul 23 09:30:58 2013 +0400
@@ -57,7 +57,7 @@
 	    Java_sun_management_GcInfoBuilder_fillGcAttributeInfo;
 	    Java_sun_management_GcInfoBuilder_getLastGcInfo0;
 	    Java_sun_management_GcInfoBuilder_getNumGcExtAttributes;
-	    Java_sun_management_HotSpotDiagnostic_dumpHeap;
+	    Java_sun_management_HotSpotDiagnostic_dumpHeap0;
 	    Java_sun_management_HotspotThread_getInternalThreadCount;
 	    Java_sun_management_HotspotThread_getInternalThreadTimes0;
 	    Java_sun_management_MemoryImpl_getMemoryManagers0;
--- a/jdk/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java	Mon Jul 22 19:41:07 2013 -0700
+++ b/jdk/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java	Tue Jul 23 09:30:58 2013 +0400
@@ -66,6 +66,11 @@
      *                     cannot be created, opened, or written to.
      * @throws UnsupportedOperationException if this operation is not supported.
      * @throws NullPointerException if <tt>outputFile</tt> is <tt>null</tt>.
+     * @throws SecurityException
+     *         If a security manager exists and its {@link
+     *         java.lang.SecurityManager#checkWrite(java.lang.String)}
+     *         method denies write access to the named file
+     *         or the caller does not have ManagmentPermission("control").
      */
     public void dumpHeap(String outputFile, boolean live) throws java.io.IOException;
 
--- a/jdk/src/share/classes/sun/management/HotSpotDiagnostic.java	Mon Jul 22 19:41:07 2013 -0700
+++ b/jdk/src/share/classes/sun/management/HotSpotDiagnostic.java	Tue Jul 23 09:30:58 2013 +0400
@@ -40,7 +40,17 @@
     public HotSpotDiagnostic() {
     }
 
-    public native void dumpHeap(String outputFile, boolean live) throws IOException;
+    public void dumpHeap(String outputFile, boolean live) throws IOException {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
+            security.checkWrite(outputFile);
+            Util.checkControlAccess();
+        }
+
+        dumpHeap0(outputFile, live);
+    }
+
+    private native void dumpHeap0(String outputFile, boolean live) throws IOException;
 
     public List<VMOption> getDiagnosticOptions() {
         List<Flag> allFlags = Flag.getAllFlags();
--- a/jdk/src/share/native/sun/management/HotSpotDiagnostic.c	Mon Jul 22 19:41:07 2013 -0700
+++ b/jdk/src/share/native/sun/management/HotSpotDiagnostic.c	Tue Jul 23 09:30:58 2013 +0400
@@ -29,7 +29,7 @@
 #include "sun_management_HotSpotDiagnostic.h"
 
 JNIEXPORT void JNICALL
-Java_sun_management_HotSpotDiagnostic_dumpHeap
+Java_sun_management_HotSpotDiagnostic_dumpHeap0
   (JNIEnv *env, jobject dummy, jstring outputfile, jboolean live)
 {
     jmm_interface->DumpHeap0(env, outputfile, live);