0N/A/*
3909N/A * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.management;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.List;
0N/Aimport javax.management.ObjectName;
0N/A
0N/Aimport com.sun.management.HotSpotDiagnosticMXBean;
0N/Aimport com.sun.management.VMOption;
2080N/A
0N/A/**
2080N/A * Implementation of the diagnostic MBean for Hotspot VM.
2080N/A */
0N/Apublic class HotSpotDiagnostic implements HotSpotDiagnosticMXBean {
2080N/A public HotSpotDiagnostic() {
2080N/A }
2080N/A
2080N/A public native void dumpHeap(String outputFile, boolean live) throws IOException;
0N/A
0N/A public List<VMOption> getDiagnosticOptions() {
0N/A List<Flag> allFlags = Flag.getAllFlags();
3876N/A List<VMOption> result = new ArrayList<VMOption>();
3876N/A for (Flag flag : allFlags) {
3876N/A if (flag.isWriteable() && flag.isExternal()) {
3876N/A result.add(flag.getVMOption());
3876N/A }
3876N/A }
3876N/A return result;
3876N/A }
3876N/A
0N/A public VMOption getVMOption(String name) {
3876N/A if (name == null) {
0N/A throw new NullPointerException("name cannot be null");
0N/A }
0N/A
0N/A Flag f = Flag.getFlag(name);
0N/A if (f == null) {
0N/A throw new IllegalArgumentException("VM option \"" +
0N/A name + "\" does not exist");
0N/A }
1263N/A return f.getVMOption();
4601N/A }
0N/A
0N/A public void setVMOption(String name, String value) {
0N/A if (name == null) {
0N/A throw new NullPointerException("name cannot be null");
0N/A }
0N/A if (value == null) {
0N/A throw new NullPointerException("value cannot be null");
0N/A }
0N/A
0N/A Util.checkControlAccess();
0N/A Flag flag = Flag.getFlag(name);
0N/A if (flag == null) {
0N/A throw new IllegalArgumentException("VM option \"" +
0N/A name + "\" does not exist");
0N/A }
0N/A if (!flag.isWriteable()){
0N/A throw new IllegalArgumentException("VM Option \"" +
0N/A name + "\" is not writeable");
0N/A }
2080N/A
2080N/A // Check the type of the value
2080N/A Object v = flag.getValue();
2080N/A if (v instanceof Long) {
2080N/A try {
2080N/A long l = Long.parseLong(value);
2080N/A Flag.setLongValue(name, l);
0N/A } catch (NumberFormatException e) {
0N/A IllegalArgumentException iae =
0N/A new IllegalArgumentException("Invalid value:" +
2080N/A " VM Option \"" + name + "\"" +
2080N/A " expects numeric value");
0N/A iae.initCause(e);
0N/A throw iae;
0N/A }
0N/A } else if (v instanceof Boolean) {
0N/A if (!value.equalsIgnoreCase("true") &&
0N/A !value.equalsIgnoreCase("false")) {
0N/A throw new IllegalArgumentException("Invalid value:" +
0N/A " VM Option \"" + name + "\"" +
0N/A " expects \"true\" or \"false\".");
0N/A }
0N/A Flag.setBooleanValue(name, Boolean.parseBoolean(value));
0N/A } else if (v instanceof String) {
0N/A Flag.setStringValue(name, value);
} else {
throw new IllegalArgumentException("VM Option \"" +
name + "\" is of an unsupported type: " +
v.getClass().getName());
}
}
public ObjectName getObjectName() {
return Util.newObjectName("com.sun.management:type=HotSpotDiagnostic");
}
}