本文整理汇总了Java中com.sun.management.VMOption.Origin类的典型用法代码示例。如果您正苦于以下问题:Java Origin类的具体用法?Java Origin怎么用?Java Origin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Origin类属于com.sun.management.VMOption包,在下文中一共展示了Origin类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Flag
import com.sun.management.VMOption.Origin; //导入依赖的package包/类
Flag(String name, Object value, boolean writeable,
boolean external, Origin origin) {
this.name = name;
this.value = value == null ? "" : value ;
this.origin = origin;
this.writeable = writeable;
this.external = external;
}
示例2: checkOrigin
import com.sun.management.VMOption.Origin; //导入依赖的package包/类
private static void checkOrigin(String option, Origin origin) throws Exception
{
Origin o = mbean.getVMOption(option).getOrigin();
if (!o.equals(origin)) {
throw new Exception("Option '" + option + "' should have origin '" + origin + "' but had '" + o + "'");
}
System.out.println("Option '" + option + "' verified origin = '" + origin + "'");
}
示例3: getOrigin
import com.sun.management.VMOption.Origin; //导入依赖的package包/类
public static Origin getOrigin(CompositeData cd) {
String o = getString(cd, ORIGIN);
return Enum.valueOf(Origin.class, o);
}
示例4: main
import com.sun.management.VMOption.Origin; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
mbean =
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
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");
}
}
示例5: main
import com.sun.management.VMOption.Origin; //导入依赖的package包/类
public static void main(String... args) throws Exception {
if (args.length == 0) {
// start a process that has options set in a number of different ways
File flagsFile = File.createTempFile("CheckOriginFlags", null);
try (PrintWriter pw =
new PrintWriter(new FileWriter(flagsFile))) {
pw.println("+PrintSafepointStatistics");
}
ProcessBuilder pb = ProcessTools.
createJavaProcessBuilder(
"--add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED",
"-XX:+UseConcMarkSweepGC", // this will cause MaxNewSize to be FLAG_SET_ERGO
"-XX:+UseCodeAging",
"-XX:+UseCerealGC", // Should be ignored.
"-XX:Flags=" + flagsFile.getAbsolutePath(),
"-Djdk.attach.allowAttachSelf",
"-cp", System.getProperty("test.class.path"),
"CheckOrigin",
"-runtests");
Map<String, String> env = pb.environment();
// "UseCMSGC" should be ignored.
env.put("_JAVA_OPTIONS", "-XX:+CheckJNICalls -XX:+UseCMSGC");
// "UseGOneGC" should be ignored.
env.put("JAVA_TOOL_OPTIONS", "-XX:+IgnoreUnrecognizedVMOptions "
+ "-XX:+PrintVMOptions -XX:+UseGOneGC");
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
Process p = pb.start();
int exit = p.waitFor();
System.out.println("sub process exit == " + exit);
if (exit != 0) {
throw new Exception("Unexpected exit code from subprocess == " + exit);
}
} else {
mbean =
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
// set a few more options
mbean.setVMOption("HeapDumpOnOutOfMemoryError", "true");
setOptionUsingAttach("HeapDumpPath", "/a/sample/path");
// check the origin field for all the options we set
// Not set, so should be default
checkOrigin("ManagementServer", Origin.DEFAULT);
// Set on the command line
checkOrigin("UseCodeAging", Origin.VM_CREATION);
// Set in _JAVA_OPTIONS
checkOrigin("CheckJNICalls", Origin.ENVIRON_VAR);
// Set in JAVA_TOOL_OPTIONS
checkOrigin("IgnoreUnrecognizedVMOptions", Origin.ENVIRON_VAR);
checkOrigin("PrintVMOptions", Origin.ENVIRON_VAR);
// Set in -XX:Flags file
checkOrigin("PrintSafepointStatistics", Origin.CONFIG_FILE);
// Set through j.l.m
checkOrigin("HeapDumpOnOutOfMemoryError", Origin.MANAGEMENT);
// Should be set by the VM, when we set UseConcMarkSweepGC
checkOrigin("MaxNewSize", Origin.ERGONOMIC);
// Set using attach
checkOrigin("HeapDumpPath", Origin.ATTACH_ON_DEMAND);
}
}
示例6: main
import com.sun.management.VMOption.Origin; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
mbean =
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
VMOption option = findHeapDumpOnOomOption();
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 " + HEAP_DUMP_ON_OOM +
" to be writeable");
}
// set VM option to a new value
mbean.setVMOption(HEAP_DUMP_ON_OOM, NEW_VALUE);
option = findHeapDumpOnOomOption();
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(HEAP_DUMP_ON_OOM);
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");
}
}
示例7: main
import com.sun.management.VMOption.Origin; //导入依赖的package包/类
public static void main(String... args) throws Exception {
if (args.length == 0) {
// start a process that has options set in a number of different ways
File flagsFile = File.createTempFile("CheckOriginFlags", null);
try (PrintWriter pw =
new PrintWriter(new FileWriter(flagsFile))) {
pw.println("+PrintSafepointStatistics");
}
ProcessBuilder pb = ProcessTools.
createJavaProcessBuilder(
"-XaddExports:jdk.attach/sun.tools.attach=ALL-UNNAMED",
"-XX:+UseConcMarkSweepGC", // this will cause UseParNewGC to be FLAG_SET_ERGO
"-XX:+UseCodeAging",
"-XX:+UseCerealGC", // Should be ignored.
"-XX:Flags=" + flagsFile.getAbsolutePath(),
"-cp", System.getProperty("test.class.path"),
"CheckOrigin",
"-runtests");
Map<String, String> env = pb.environment();
// "UseCMSGC" should be ignored.
env.put("_JAVA_OPTIONS", "-XX:+CheckJNICalls -XX:+UseCMSGC");
// "UseGOneGC" should be ignored.
env.put("JAVA_TOOL_OPTIONS", "-XX:+IgnoreUnrecognizedVMOptions "
+ "-XX:+PrintVMOptions -XX:+UseGOneGC");
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
Process p = pb.start();
int exit = p.waitFor();
System.out.println("sub process exit == " + exit);
if (exit != 0) {
throw new Exception("Unexpected exit code from subprocess == " + exit);
}
} else {
mbean =
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
// set a few more options
mbean.setVMOption("HeapDumpOnOutOfMemoryError", "true");
setOptionUsingAttach("HeapDumpPath", "/a/sample/path");
// check the origin field for all the options we set
// Not set, so should be default
checkOrigin("ManagementServer", Origin.DEFAULT);
// Set on the command line
checkOrigin("UseCodeAging", Origin.VM_CREATION);
// Set in _JAVA_OPTIONS
checkOrigin("CheckJNICalls", Origin.ENVIRON_VAR);
// Set in JAVA_TOOL_OPTIONS
checkOrigin("IgnoreUnrecognizedVMOptions", Origin.ENVIRON_VAR);
checkOrigin("PrintVMOptions", Origin.ENVIRON_VAR);
// Set in -XX:Flags file
checkOrigin("PrintSafepointStatistics", Origin.CONFIG_FILE);
// Set through j.l.m
checkOrigin("HeapDumpOnOutOfMemoryError", Origin.MANAGEMENT);
// Should be set by the VM, when we set UseConcMarkSweepGC
checkOrigin("UseParNewGC", Origin.ERGONOMIC);
// Set using attach
checkOrigin("HeapDumpPath", Origin.ATTACH_ON_DEMAND);
}
}