2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2015-05-07 07:11:49 +00:00
|
|
|
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-25 22:58:33 +00:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
|
|
|
* @bug 6314913
|
|
|
|
* @summary Basic Test for HotSpotDiagnosticMXBean.setVMOption()
|
|
|
|
* and getDiagnosticOptions().
|
|
|
|
* @author Mandy Chung
|
2013-07-11 07:21:09 +00:00
|
|
|
* @author Jaroslav Bachorik
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
2015-05-07 07:11:49 +00:00
|
|
|
* @modules jdk.management
|
2007-12-01 00:00:00 +00:00
|
|
|
* @run main/othervm -XX:+PrintGCDetails SetVMOption
|
|
|
|
*/
|
|
|
|
|
2008-04-10 17:47:13 +00:00
|
|
|
import java.lang.management.ManagementFactory;
|
2007-12-01 00:00:00 +00:00
|
|
|
import java.util.*;
|
|
|
|
import com.sun.management.HotSpotDiagnosticMXBean;
|
|
|
|
import com.sun.management.VMOption;
|
|
|
|
import com.sun.management.VMOption.Origin;
|
|
|
|
|
|
|
|
public class SetVMOption {
|
2014-11-03 10:19:54 +00:00
|
|
|
private static final String PRINT_GC_DETAILS = "PrintGCDetails";
|
|
|
|
private static final String EXPECTED_VALUE = "true";
|
|
|
|
private static final String BAD_VALUE = "yes";
|
|
|
|
private static final String NEW_VALUE = "false";
|
|
|
|
private static final String MANAGEMENT_SERVER = "ManagementServer";
|
2008-04-10 17:47:13 +00:00
|
|
|
private static HotSpotDiagnosticMXBean mbean;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
2013-07-11 07:21:09 +00:00
|
|
|
mbean =
|
|
|
|
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
VMOption option = findPrintGCDetailsOption();
|
|
|
|
if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {
|
|
|
|
throw new RuntimeException("Unexpected value: " +
|
|
|
|
option.getValue() + " expected: " + EXPECTED_VALUE);
|
|
|
|
}
|
|
|
|
if (option.getOrigin() != Origin.VM_CREATION) {
|
|
|
|
throw new RuntimeException("Unexpected origin: " +
|
|
|
|
option.getOrigin() + " expected: VM_CREATION");
|
|
|
|
}
|
|
|
|
if (!option.isWriteable()) {
|
|
|
|
throw new RuntimeException("Expected " + PRINT_GC_DETAILS +
|
|
|
|
" to be writeable");
|
|
|
|
}
|
|
|
|
|
|
|
|
// set VM option to a new value
|
|
|
|
mbean.setVMOption(PRINT_GC_DETAILS, NEW_VALUE);
|
|
|
|
|
|
|
|
option = findPrintGCDetailsOption();
|
|
|
|
if (!option.getValue().equalsIgnoreCase(NEW_VALUE)) {
|
|
|
|
throw new RuntimeException("Unexpected value: " +
|
|
|
|
option.getValue() + " expected: " + NEW_VALUE);
|
|
|
|
}
|
|
|
|
if (option.getOrigin() != Origin.MANAGEMENT) {
|
|
|
|
throw new RuntimeException("Unexpected origin: " +
|
|
|
|
option.getOrigin() + " expected: MANAGEMENT");
|
|
|
|
}
|
|
|
|
VMOption o = mbean.getVMOption(PRINT_GC_DETAILS);
|
|
|
|
if (!option.getValue().equals(o.getValue())) {
|
|
|
|
throw new RuntimeException("Unmatched value: " +
|
|
|
|
option.getValue() + " expected: " + o.getValue());
|
|
|
|
}
|
|
|
|
if (!option.getValue().equals(o.getValue())) {
|
|
|
|
throw new RuntimeException("Unmatched value: " +
|
|
|
|
option.getValue() + " expected: " + o.getValue());
|
|
|
|
}
|
|
|
|
if (option.getOrigin() != o.getOrigin()) {
|
|
|
|
throw new RuntimeException("Unmatched origin: " +
|
|
|
|
option.getOrigin() + " expected: " + o.getOrigin());
|
|
|
|
}
|
|
|
|
if (option.isWriteable() != o.isWriteable()) {
|
|
|
|
throw new RuntimeException("Unmatched writeable: " +
|
|
|
|
option.isWriteable() + " expected: " + o.isWriteable());
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if ManagementServer is not writeable
|
|
|
|
List<VMOption> options = mbean.getDiagnosticOptions();
|
|
|
|
VMOption mgmtServerOption = null;
|
|
|
|
for (VMOption o1 : options) {
|
|
|
|
if (o1.getName().equals(MANAGEMENT_SERVER)) {
|
|
|
|
mgmtServerOption = o1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mgmtServerOption != null) {
|
|
|
|
throw new RuntimeException(MANAGEMENT_SERVER +
|
|
|
|
" is not expected to be writeable");
|
|
|
|
}
|
|
|
|
mgmtServerOption = mbean.getVMOption(MANAGEMENT_SERVER);
|
|
|
|
if (mgmtServerOption == null) {
|
|
|
|
throw new RuntimeException(MANAGEMENT_SERVER +
|
|
|
|
" should exist.");
|
|
|
|
}
|
|
|
|
if (mgmtServerOption.getOrigin() != Origin.DEFAULT) {
|
|
|
|
throw new RuntimeException(MANAGEMENT_SERVER +
|
|
|
|
" should have the default value.");
|
|
|
|
}
|
|
|
|
if (mgmtServerOption.isWriteable()) {
|
|
|
|
throw new RuntimeException(MANAGEMENT_SERVER +
|
|
|
|
" is not expected to be writeable");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static VMOption findPrintGCDetailsOption() {
|
|
|
|
List<VMOption> options = mbean.getDiagnosticOptions();
|
|
|
|
VMOption gcDetails = null;
|
|
|
|
for (VMOption o : options) {
|
|
|
|
if (o.getName().equals(PRINT_GC_DETAILS)) {
|
|
|
|
gcDetails = o;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gcDetails == null) {
|
|
|
|
throw new RuntimeException("VM option " + PRINT_GC_DETAILS +
|
|
|
|
" not found");
|
|
|
|
}
|
|
|
|
return gcDetails;
|
|
|
|
}
|
|
|
|
}
|