jdk/src/jdk.management/share/classes/com/sun/management/internal/HotSpotDiagnostic.java
changeset 45991 c308fa07c6f2
parent 30355 e37c7eba132f
equal deleted inserted replaced
45990:ba8bfbb9d633 45991:c308fa07c6f2
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    20  *
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
       
    26 package com.sun.management.internal;
    25 package com.sun.management.internal;
    27 
    26 
    28 import java.io.IOException;
    27 import java.io.IOException;
    29 import java.util.ArrayList;
    28 import java.util.ArrayList;
    30 import java.util.List;
    29 import java.util.List;
    31 import javax.management.ObjectName;
    30 import javax.management.ObjectName;
    32 
    31 
    33 import com.sun.management.HotSpotDiagnosticMXBean;
    32 import com.sun.management.HotSpotDiagnosticMXBean;
    34 import com.sun.management.VMOption;
    33 import com.sun.management.VMOption;
       
    34 import java.security.AccessController;
       
    35 import java.security.PrivilegedAction;
    35 import sun.management.Util;
    36 import sun.management.Util;
    36 
    37 
    37 /**
    38 /**
    38  * Implementation of the diagnostic MBean for Hotspot VM.
    39  * Implementation of the diagnostic MBean for Hotspot VM.
    39  */
    40  */
    41     public HotSpotDiagnostic() {
    42     public HotSpotDiagnostic() {
    42     }
    43     }
    43 
    44 
    44     @Override
    45     @Override
    45     public void dumpHeap(String outputFile, boolean live) throws IOException {
    46     public void dumpHeap(String outputFile, boolean live) throws IOException {
       
    47 
       
    48         String propertyName = "jdk.management.heapdump.allowAnyFileSuffix";
       
    49         PrivilegedAction<Boolean> pa = () -> Boolean.parseBoolean(System.getProperty(propertyName, "false"));
       
    50         boolean allowAnyFileSuffix = AccessController.doPrivileged(pa);
       
    51         if (!allowAnyFileSuffix && !outputFile.endsWith(".hprof")) {
       
    52             throw new IllegalArgumentException("heapdump file must have .hprof extention");
       
    53         }
       
    54 
    46         SecurityManager security = System.getSecurityManager();
    55         SecurityManager security = System.getSecurityManager();
    47         if (security != null) {
    56         if (security != null) {
    48             security.checkWrite(outputFile);
    57             security.checkWrite(outputFile);
    49             Util.checkControlAccess();
    58             Util.checkControlAccess();
    50         }
    59         }