test/testlibrary/whitebox/sun/hotspot/WhiteBox.java

Tue, 07 Apr 2015 10:53:51 +0200

author
tschatzl
date
Tue, 07 Apr 2015 10:53:51 +0200
changeset 7781
33e421924c67
parent 7779
cc5c3ef1f03a
child 7797
e9a7f132cec3
permissions
-rw-r--r--

8058354: SPECjvm2008-Derby -2.7% performance regression on Solaris-X64 starting with 9-b29
Summary: Allow use of large pages for auxiliary data structures in G1. Clean up existing interfaces.
Reviewed-by: jmasa, pliden, stefank

mgerdin@3619 1 /*
iignatyev@6525 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
mgerdin@3619 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mgerdin@3619 4 *
mgerdin@3619 5 * This code is free software; you can redistribute it and/or modify it
mgerdin@3619 6 * under the terms of the GNU General Public License version 2 only, as
mgerdin@3619 7 * published by the Free Software Foundation.
mgerdin@3619 8 *
mgerdin@3619 9 * This code is distributed in the hope that it will be useful, but WITHOUT
mgerdin@3619 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mgerdin@3619 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mgerdin@3619 12 * version 2 for more details (a copy is included in the LICENSE file that
mgerdin@3619 13 * accompanied this code).
mgerdin@3619 14 *
mgerdin@3619 15 * You should have received a copy of the GNU General Public License version
mgerdin@3619 16 * 2 along with this work; if not, write to the Free Software Foundation,
mgerdin@3619 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mgerdin@3619 18 *
mgerdin@3619 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mgerdin@3619 20 * or visit www.oracle.com if you need additional information or have any
mgerdin@3619 21 * questions.
mgerdin@3619 22 *
mgerdin@3619 23 */
mgerdin@3619 24
mgerdin@3619 25 package sun.hotspot;
iignatyev@4592 26
iignatyev@4951 27 import java.lang.reflect.Executable;
zgu@7076 28 import java.util.Arrays;
zgu@7076 29 import java.util.List;
zgu@7076 30 import java.util.function.Function;
zgu@7076 31 import java.util.stream.Stream;
mgerdin@3619 32 import java.security.BasicPermission;
iklam@7322 33 import java.net.URL;
sjohanss@7165 34
nloodin@3681 35 import sun.hotspot.parser.DiagnosticCommand;
mgerdin@3619 36
mgerdin@3619 37 public class WhiteBox {
mgerdin@3619 38
mgerdin@3619 39 @SuppressWarnings("serial")
mgerdin@3619 40 public static class WhiteBoxPermission extends BasicPermission {
mgerdin@3619 41 public WhiteBoxPermission(String s) {
mgerdin@3619 42 super(s);
mgerdin@3619 43 }
mgerdin@3619 44 }
mgerdin@3619 45
mgerdin@3619 46 private WhiteBox() {}
mgerdin@3619 47 private static final WhiteBox instance = new WhiteBox();
mgerdin@3619 48 private static native void registerNatives();
mgerdin@3619 49
mgerdin@3619 50 /**
mgerdin@3619 51 * Returns the singleton WhiteBox instance.
mgerdin@3619 52 *
mgerdin@3619 53 * The returned WhiteBox object should be carefully guarded
mgerdin@3619 54 * by the caller, since it can be used to read and write data
mgerdin@3619 55 * at arbitrary memory addresses. It must never be passed to
mgerdin@3619 56 * untrusted code.
mgerdin@3619 57 */
mgerdin@3619 58 public synchronized static WhiteBox getWhiteBox() {
mgerdin@3619 59 SecurityManager sm = System.getSecurityManager();
mgerdin@3619 60 if (sm != null) {
mgerdin@3619 61 sm.checkPermission(new WhiteBoxPermission("getInstance"));
mgerdin@3619 62 }
mgerdin@3619 63 return instance;
mgerdin@3619 64 }
mgerdin@3619 65
mgerdin@3619 66 static {
mgerdin@3619 67 registerNatives();
mgerdin@3619 68 }
mgerdin@3619 69
tschatzl@5701 70 // Get the maximum heap size supporting COOPs
tschatzl@5701 71 public native long getCompressedOopsMaxHeapSize();
tschatzl@5073 72 // Arguments
tschatzl@5073 73 public native void printHeapSizes();
tschatzl@5073 74
mgerdin@3619 75 // Memory
mgerdin@3619 76 public native long getObjectAddress(Object o);
mgerdin@3619 77 public native int getHeapOopSize();
minqi@7779 78 public native int getVMPageSize();
tschatzl@7781 79 public native long getVMLargePageSize();
tschatzl@7781 80
tschatzl@7071 81 public native boolean isObjectInOldGen(Object o);
tschatzl@7071 82 public native long getObjectSize(Object o);
mgerdin@3619 83
coleenp@4037 84 // Runtime
coleenp@4037 85 // Make sure class name is in the correct format
coleenp@4037 86 public boolean isClassAlive(String name) {
coleenp@4037 87 return isClassAlive0(name.replace('.', '/'));
coleenp@4037 88 }
coleenp@4037 89 private native boolean isClassAlive0(String name);
coleenp@4037 90
iklam@7322 91 // Resource/Class Lookup Cache
iklam@7322 92 public native boolean classKnownToNotExist(ClassLoader loader, String name);
iklam@7322 93 public native URL[] getLookupCacheURLs(ClassLoader loader);
iklam@7322 94 public native int[] getLookupCacheMatches(ClassLoader loader, String name);
iklam@7322 95
iklam@7381 96 // JVMTI
iklam@7381 97 public native void addToBootstrapClassLoaderSearch(String segment);
iklam@7381 98 public native void addToSystemClassLoaderSearch(String segment);
iklam@7381 99
mgerdin@3619 100 // G1
mgerdin@3619 101 public native boolean g1InConcurrentMark();
mgerdin@3619 102 public native boolean g1IsHumongous(Object o);
mgerdin@3619 103 public native long g1NumFreeRegions();
mgerdin@3619 104 public native int g1RegionSize();
nloodin@3681 105 public native Object[] parseCommandLine(String commandline, DiagnosticCommand[] args);
ctornqvi@4512 106
ctornqvi@4512 107 // NMT
ctornqvi@4885 108 public native long NMTMalloc(long size);
ctornqvi@4885 109 public native void NMTFree(long mem);
ctornqvi@4885 110 public native long NMTReserveMemory(long size);
ctornqvi@4885 111 public native void NMTCommitMemory(long addr, long size);
ctornqvi@4885 112 public native void NMTUncommitMemory(long addr, long size);
ctornqvi@4885 113 public native void NMTReleaseMemory(long addr, long size);
zgu@7074 114 public native long NMTMallocWithPseudoStack(long size, int index);
cjplummer@5586 115 public native boolean NMTIsDetailSupported();
coleenp@7267 116 public native boolean NMTChangeTrackingLevel();
gtriantafill@7342 117 public native int NMTGetHashSize();
iignatyev@4592 118
iignatyev@4592 119 // Compiler
iignatyev@4592 120 public native void deoptimizeAll();
iignatyev@5541 121 public boolean isMethodCompiled(Executable method) {
iignatyev@5541 122 return isMethodCompiled(method, false /*not osr*/);
iignatyev@4908 123 }
iignatyev@5541 124 public native boolean isMethodCompiled(Executable method, boolean isOsr);
iignatyev@5541 125 public boolean isMethodCompilable(Executable method) {
iignatyev@5541 126 return isMethodCompilable(method, -1 /*any*/);
iignatyev@5541 127 }
iignatyev@5541 128 public boolean isMethodCompilable(Executable method, int compLevel) {
iignatyev@5541 129 return isMethodCompilable(method, compLevel, false /*not osr*/);
iignatyev@5541 130 }
iignatyev@5541 131 public native boolean isMethodCompilable(Executable method, int compLevel, boolean isOsr);
iignatyev@4951 132 public native boolean isMethodQueuedForCompilation(Executable method);
iignatyev@5541 133 public int deoptimizeMethod(Executable method) {
iignatyev@5541 134 return deoptimizeMethod(method, false /*not osr*/);
iignatyev@4951 135 }
iignatyev@5541 136 public native int deoptimizeMethod(Executable method, boolean isOsr);
iignatyev@5541 137 public void makeMethodNotCompilable(Executable method) {
iignatyev@5541 138 makeMethodNotCompilable(method, -1 /*any*/);
iignatyev@5541 139 }
iignatyev@5541 140 public void makeMethodNotCompilable(Executable method, int compLevel) {
iignatyev@5541 141 makeMethodNotCompilable(method, compLevel, false /*not osr*/);
iignatyev@5541 142 }
iignatyev@5541 143 public native void makeMethodNotCompilable(Executable method, int compLevel, boolean isOsr);
iignatyev@5541 144 public int getMethodCompilationLevel(Executable method) {
iignatyev@5541 145 return getMethodCompilationLevel(method, false /*not ost*/);
iignatyev@5541 146 }
iignatyev@5541 147 public native int getMethodCompilationLevel(Executable method, boolean isOsr);
iignatyev@4951 148 public native boolean testSetDontInlineMethod(Executable method, boolean value);
iignatyev@5541 149 public int getCompileQueuesSize() {
iignatyev@5541 150 return getCompileQueueSize(-1 /*any*/);
iignatyev@5541 151 }
iignatyev@5541 152 public native int getCompileQueueSize(int compLevel);
iignatyev@4951 153 public native boolean testSetForceInlineMethod(Executable method, boolean value);
zgu@7076 154 public boolean enqueueMethodForCompilation(Executable method, int compLevel) {
iignatyev@5541 155 return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/);
iignatyev@5541 156 }
iignatyev@5541 157 public native boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci);
iignatyev@4951 158 public native void clearMethodState(Executable method);
iignatyev@5541 159 public native int getMethodEntryBci(Executable method);
iignatyev@6525 160 public native Object[] getNMethod(Executable method, boolean isOsr);
mgerdin@4850 161
iignatyev@4951 162 // Intered strings
mgerdin@4850 163 public native boolean isInStringTable(String str);
mgerdin@4850 164
mikael@4989 165 // Memory
mikael@5174 166 public native void readReservedMemory();
zgu@7076 167 public native long allocateMetaspace(ClassLoader classLoader, long size);
zgu@7076 168 public native void freeMetaspace(ClassLoader classLoader, long addr, long size);
ehelin@7254 169 public native long incMetaspaceCapacityUntilGC(long increment);
ehelin@7254 170 public native long metaspaceCapacityUntilGC();
mikael@4989 171
tschatzl@7071 172 // force Young GC
tschatzl@7071 173 public native void youngGC();
tschatzl@7071 174
mgerdin@4850 175 // force Full GC
mgerdin@4850 176 public native void fullGC();
mgerdin@6078 177
mgerdin@6078 178 // Tests on ReservedSpace/VirtualSpace classes
mgerdin@6078 179 public native int stressVirtualSpaceResize(long reservedSpaceSize, long magnitude, long iterations);
mgerdin@6078 180 public native void runMemoryUnitTests();
mgerdin@6078 181 public native void readFromNoaccessArea();
zgu@7076 182 public native long getThreadStackSize();
zgu@7076 183 public native long getThreadRemainingStackSize();
mgerdin@6078 184
iignatyev@6427 185 // CPU features
iignatyev@6427 186 public native String getCPUFeatures();
iignatyev@6427 187
sjohanss@7165 188 // Native extensions
sjohanss@7165 189 public native long getHeapUsageForContext(int context);
sjohanss@7165 190 public native long getHeapRegionCountForContext(int context);
sjohanss@7165 191 public native int getContextForObject(Object obj);
sjohanss@7165 192 public native void printRegionInfo(int context);
sjohanss@7165 193
zgu@7076 194 // VM flags
zgu@7076 195 public native void setBooleanVMFlag(String name, boolean value);
zgu@7076 196 public native void setIntxVMFlag(String name, long value);
zgu@7076 197 public native void setUintxVMFlag(String name, long value);
zgu@7076 198 public native void setUint64VMFlag(String name, long value);
zgu@7076 199 public native void setStringVMFlag(String name, String value);
zgu@7076 200 public native void setDoubleVMFlag(String name, double value);
zgu@7076 201 public native Boolean getBooleanVMFlag(String name);
zgu@7076 202 public native Long getIntxVMFlag(String name);
zgu@7076 203 public native Long getUintxVMFlag(String name);
zgu@7076 204 public native Long getUint64VMFlag(String name);
zgu@7076 205 public native String getStringVMFlag(String name);
zgu@7076 206 public native Double getDoubleVMFlag(String name);
zgu@7076 207 private final List<Function<String,Object>> flagsGetters = Arrays.asList(
zgu@7076 208 this::getBooleanVMFlag, this::getIntxVMFlag, this::getUintxVMFlag,
zgu@7076 209 this::getUint64VMFlag, this::getStringVMFlag, this::getDoubleVMFlag);
zgu@7076 210
zgu@7076 211 public Object getVMFlag(String name) {
zgu@7076 212 return flagsGetters.stream()
zgu@7076 213 .map(f -> f.apply(name))
zgu@7076 214 .filter(x -> x != null)
zgu@7076 215 .findAny()
zgu@7076 216 .orElse(null);
zgu@7076 217 }
minqi@7349 218 public native int getOffsetForName0(String name);
minqi@7349 219 public int getOffsetForName(String name) throws Exception {
minqi@7349 220 int offset = getOffsetForName0(name);
minqi@7349 221 if (offset == -1) {
minqi@7349 222 throw new RuntimeException(name + " not found");
minqi@7349 223 }
minqi@7349 224 return offset;
minqi@7349 225 }
minqi@7349 226
mgerdin@3619 227 }

mercurial