1 /* 2 * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 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 23 * questions. 24 */ 25 26 package com.sun.management; 27 28 import java.io.IOException; 29 import java.lang.management.PlatformManagedObject; 30 import jdk.internal.javac.PreviewFeature; 31 32 /** 33 * Diagnostic management interface for the HotSpot Virtual Machine. 34 * 35 * <p>The diagnostic MBean is registered to the platform MBeanServer 36 * as are other platform MBeans. 37 * 38 * <p>The {@code ObjectName} for uniquely identifying the diagnostic 39 * MXBean within an MBeanServer is: 40 * <blockquote> 41 * {@code com.sun.management:type=HotSpotDiagnostic} 42 * </blockquote> 43 * 44 * It can be obtained by calling the 45 * {@link PlatformManagedObject#getObjectName} method. 46 * 47 * All methods throw a {@code NullPointerException} if any input argument is 48 * {@code null} unless it's stated otherwise. 49 * 50 * @see java.lang.management.ManagementFactory#getPlatformMXBeans(Class) 51 */ 52 public interface HotSpotDiagnosticMXBean extends PlatformManagedObject { 53 /** 54 * Dumps the heap to the {@code outputFile} file in the same 55 * format as the hprof heap dump. 56 * <p> 57 * If this method is called remotely from another process, 58 * the heap dump output is written to a file named {@code outputFile} 59 * on the machine where the target VM is running. If outputFile is 60 * a relative path, it is relative to the working directory where 61 * the target VM was started. 62 * 63 * @param outputFile the system-dependent filename 64 * @param live if {@code true} dump only <i>live</i> objects 65 * i.e. objects that are reachable from others 66 * @throws IOException if the {@code outputFile} already exists, 67 * cannot be created, opened, or written to. 68 * @throws UnsupportedOperationException if this operation is not supported. 69 * @throws IllegalArgumentException if {@code outputFile} does not end with ".hprof" suffix. 70 * @throws NullPointerException if {@code outputFile} is {@code null}. 71 * @throws SecurityException 72 * If a security manager exists and its {@link 73 * java.lang.SecurityManager#checkWrite(java.lang.String)} 74 * method denies write access to the named file 75 * or the caller does not have ManagmentPermission("control"). 76 */ 77 public void dumpHeap(String outputFile, boolean live) throws IOException; 78 79 /** 80 * Returns a list of {@code VMOption} objects for all diagnostic options. 81 * A diagnostic option is a {@link VMOption#isWriteable writeable} 82 * VM option that can be set dynamically mainly for troubleshooting 83 * and diagnosis. 84 * 85 * @return a list of {@code VMOption} objects for all diagnostic options. 86 */ 87 public java.util.List<VMOption> getDiagnosticOptions(); 88 89 /** 90 * Returns a {@code VMOption} object for a VM option of the given 91 * name. 92 * 93 * @return a {@code VMOption} object for a VM option of the given name. 94 * @throws NullPointerException if name is {@code null}. 95 * @throws IllegalArgumentException if a VM option of the given name 96 * does not exist. 97 */ 98 public VMOption getVMOption(String name); 99 100 /** 101 * Sets a VM option of the given name to the specified value. 102 * The new value will be reflected in a new {@code VMOption} 103 * object returned by the {@link #getVMOption} method or 104 * the {@link #getDiagnosticOptions} method. This method does 105 * not change the value of this {@code VMOption} object. 106 * 107 * @param name Name of a VM option 108 * @param value New value of the VM option to be set 109 * 110 * @throws IllegalArgumentException if the VM option of the given name 111 * does not exist. 112 * @throws IllegalArgumentException if the new value is invalid. 113 * @throws IllegalArgumentException if the VM option is not writable. 114 * @throws NullPointerException if name or value is {@code null}. 115 * 116 * @throws java.lang.SecurityException 117 * if a security manager exists and the caller does not have 118 * ManagementPermission("control"). 119 */ 120 public void setVMOption(String name, String value); 121 122 /** 123 * Generate a thread dump to the given file in the given format. The 124 * {@code outputFile} parameter must be an absolute path to a file that 125 * does not exist. 126 * 127 * <p> The thread dump will include output for all platform threads. It may 128 * include output for some or all virtual threads. 129 * 130 * @implSpec 131 * The default implementation throws {@code UnsupportedOperationException}. 132 * 133 * @apiNote 134 * The output file is required to be an absolute path as the MXBean may be 135 * accessed remotely from a tool or program with a different current working 136 * directory. 137 * 138 * @param outputFile the path to the file to create 139 * @param format the format to use 140 * @throws IllegalArgumentException if the file path is not absolute 141 * @throws IOException if the file already exists or an I/O exception is 142 * thrown writing to the file 143 * @throws NullPointerException if either parameter is {@code null} 144 * @throws SecurityException 145 * if a security manager is set and its {@link 146 * SecurityManager#checkWrite(java.lang.String)} method denies write 147 * access to the file or {@link java.lang.management.ManagementPermission 148 * ManagementPermission("control")} is denied 149 * @throws UnsupportedOperationException if this operation is not supported 150 * @since 19 151 */ 152 @PreviewFeature(feature = PreviewFeature.Feature.VIRTUAL_THREADS, reflective = true) 153 default void dumpThreads(String outputFile, ThreadDumpFormat format) throws IOException { 154 throw new UnsupportedOperationException(); 155 } 156 157 /** 158 * Thread dump format. 159 * @since 19 160 */ 161 @PreviewFeature(feature = PreviewFeature.Feature.VIRTUAL_THREADS, reflective = true) 162 public static enum ThreadDumpFormat { 163 /** 164 * Plain text format. 165 */ 166 TEXT_PLAIN, 167 /** 168 * JSON (JavaScript Object Notation) format. 169 */ 170 JSON, 171 } 172 }