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

Thu, 24 Mar 2016 21:38:15 -0700

author
iklam
date
Thu, 24 Mar 2016 21:38:15 -0700
changeset 8497
50e62b688ddc
parent 8194
047a642c9729
child 8604
04d83ba48607
child 9186
1d0b6fcff115
permissions
-rw-r--r--

8150752: Share Class Data
Reviewed-by: acorn, hseigel, mschoene

mgerdin@3619 1 /*
iklam@8497 2 * Copyright (c) 2012, 2016, 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
azakharov@7835 27 import java.lang.management.MemoryUsage;
iignatyev@4951 28 import java.lang.reflect.Executable;
zgu@7076 29 import java.util.Arrays;
zgu@7076 30 import java.util.List;
zgu@7076 31 import java.util.function.Function;
zgu@7076 32 import java.util.stream.Stream;
mgerdin@3619 33 import java.security.BasicPermission;
iklam@7322 34 import java.net.URL;
sjohanss@7165 35
nloodin@3681 36 import sun.hotspot.parser.DiagnosticCommand;
mgerdin@3619 37
mgerdin@3619 38 public class WhiteBox {
mgerdin@3619 39
mgerdin@3619 40 @SuppressWarnings("serial")
mgerdin@3619 41 public static class WhiteBoxPermission extends BasicPermission {
mgerdin@3619 42 public WhiteBoxPermission(String s) {
mgerdin@3619 43 super(s);
mgerdin@3619 44 }
mgerdin@3619 45 }
mgerdin@3619 46
mgerdin@3619 47 private WhiteBox() {}
mgerdin@3619 48 private static final WhiteBox instance = new WhiteBox();
mgerdin@3619 49 private static native void registerNatives();
mgerdin@3619 50
mgerdin@3619 51 /**
mgerdin@3619 52 * Returns the singleton WhiteBox instance.
mgerdin@3619 53 *
mgerdin@3619 54 * The returned WhiteBox object should be carefully guarded
mgerdin@3619 55 * by the caller, since it can be used to read and write data
mgerdin@3619 56 * at arbitrary memory addresses. It must never be passed to
mgerdin@3619 57 * untrusted code.
mgerdin@3619 58 */
mgerdin@3619 59 public synchronized static WhiteBox getWhiteBox() {
mgerdin@3619 60 SecurityManager sm = System.getSecurityManager();
mgerdin@3619 61 if (sm != null) {
mgerdin@3619 62 sm.checkPermission(new WhiteBoxPermission("getInstance"));
mgerdin@3619 63 }
mgerdin@3619 64 return instance;
mgerdin@3619 65 }
mgerdin@3619 66
mgerdin@3619 67 static {
mgerdin@3619 68 registerNatives();
mgerdin@3619 69 }
mgerdin@3619 70
tschatzl@5701 71 // Get the maximum heap size supporting COOPs
tschatzl@5701 72 public native long getCompressedOopsMaxHeapSize();
tschatzl@5073 73 // Arguments
tschatzl@5073 74 public native void printHeapSizes();
tschatzl@5073 75
mgerdin@3619 76 // Memory
mgerdin@3619 77 public native long getObjectAddress(Object o);
mgerdin@3619 78 public native int getHeapOopSize();
minqi@7779 79 public native int getVMPageSize();
tschatzl@7781 80 public native long getVMLargePageSize();
tschatzl@7781 81
tschatzl@7071 82 public native boolean isObjectInOldGen(Object o);
tschatzl@7071 83 public native long getObjectSize(Object o);
mgerdin@3619 84
coleenp@4037 85 // Runtime
coleenp@4037 86 // Make sure class name is in the correct format
coleenp@4037 87 public boolean isClassAlive(String name) {
coleenp@4037 88 return isClassAlive0(name.replace('.', '/'));
coleenp@4037 89 }
coleenp@4037 90 private native boolean isClassAlive0(String name);
bmoloden@7797 91 public native boolean isMonitorInflated(Object obj);
bmoloden@7797 92 public native void forceSafepoint();
coleenp@4037 93
iklam@7322 94 // Resource/Class Lookup Cache
iklam@7322 95 public native boolean classKnownToNotExist(ClassLoader loader, String name);
iklam@7322 96 public native URL[] getLookupCacheURLs(ClassLoader loader);
iklam@7322 97 public native int[] getLookupCacheMatches(ClassLoader loader, String name);
iklam@7322 98
iklam@7381 99 // JVMTI
iklam@7381 100 public native void addToBootstrapClassLoaderSearch(String segment);
iklam@7381 101 public native void addToSystemClassLoaderSearch(String segment);
iklam@7381 102
mgerdin@3619 103 // G1
mgerdin@3619 104 public native boolean g1InConcurrentMark();
mgerdin@3619 105 public native boolean g1IsHumongous(Object o);
azakharov@7835 106 public native long g1NumMaxRegions();
mgerdin@3619 107 public native long g1NumFreeRegions();
mgerdin@3619 108 public native int g1RegionSize();
azakharov@7835 109 public native MemoryUsage g1AuxiliaryMemoryUsage();
nloodin@3681 110 public native Object[] parseCommandLine(String commandline, DiagnosticCommand[] args);
ctornqvi@4512 111
ctornqvi@4512 112 // NMT
ctornqvi@4885 113 public native long NMTMalloc(long size);
ctornqvi@4885 114 public native void NMTFree(long mem);
ctornqvi@4885 115 public native long NMTReserveMemory(long size);
ctornqvi@4885 116 public native void NMTCommitMemory(long addr, long size);
ctornqvi@4885 117 public native void NMTUncommitMemory(long addr, long size);
ctornqvi@4885 118 public native void NMTReleaseMemory(long addr, long size);
zgu@7074 119 public native long NMTMallocWithPseudoStack(long size, int index);
cjplummer@5586 120 public native boolean NMTIsDetailSupported();
coleenp@7267 121 public native boolean NMTChangeTrackingLevel();
gtriantafill@7342 122 public native int NMTGetHashSize();
iignatyev@4592 123
iignatyev@4592 124 // Compiler
iignatyev@4592 125 public native void deoptimizeAll();
iignatyev@5541 126 public boolean isMethodCompiled(Executable method) {
iignatyev@5541 127 return isMethodCompiled(method, false /*not osr*/);
iignatyev@4908 128 }
iignatyev@5541 129 public native boolean isMethodCompiled(Executable method, boolean isOsr);
iignatyev@5541 130 public boolean isMethodCompilable(Executable method) {
iignatyev@5541 131 return isMethodCompilable(method, -1 /*any*/);
iignatyev@5541 132 }
iignatyev@5541 133 public boolean isMethodCompilable(Executable method, int compLevel) {
iignatyev@5541 134 return isMethodCompilable(method, compLevel, false /*not osr*/);
iignatyev@5541 135 }
iignatyev@5541 136 public native boolean isMethodCompilable(Executable method, int compLevel, boolean isOsr);
iignatyev@4951 137 public native boolean isMethodQueuedForCompilation(Executable method);
iignatyev@5541 138 public int deoptimizeMethod(Executable method) {
iignatyev@5541 139 return deoptimizeMethod(method, false /*not osr*/);
iignatyev@4951 140 }
iignatyev@5541 141 public native int deoptimizeMethod(Executable method, boolean isOsr);
iignatyev@5541 142 public void makeMethodNotCompilable(Executable method) {
iignatyev@5541 143 makeMethodNotCompilable(method, -1 /*any*/);
iignatyev@5541 144 }
iignatyev@5541 145 public void makeMethodNotCompilable(Executable method, int compLevel) {
iignatyev@5541 146 makeMethodNotCompilable(method, compLevel, false /*not osr*/);
iignatyev@5541 147 }
iignatyev@5541 148 public native void makeMethodNotCompilable(Executable method, int compLevel, boolean isOsr);
iignatyev@5541 149 public int getMethodCompilationLevel(Executable method) {
iignatyev@5541 150 return getMethodCompilationLevel(method, false /*not ost*/);
iignatyev@5541 151 }
iignatyev@5541 152 public native int getMethodCompilationLevel(Executable method, boolean isOsr);
iignatyev@4951 153 public native boolean testSetDontInlineMethod(Executable method, boolean value);
iignatyev@5541 154 public int getCompileQueuesSize() {
iignatyev@5541 155 return getCompileQueueSize(-1 /*any*/);
iignatyev@5541 156 }
iignatyev@5541 157 public native int getCompileQueueSize(int compLevel);
iignatyev@4951 158 public native boolean testSetForceInlineMethod(Executable method, boolean value);
zgu@7076 159 public boolean enqueueMethodForCompilation(Executable method, int compLevel) {
iignatyev@5541 160 return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/);
iignatyev@5541 161 }
iignatyev@5541 162 public native boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci);
iignatyev@4951 163 public native void clearMethodState(Executable method);
iignatyev@5541 164 public native int getMethodEntryBci(Executable method);
iignatyev@6525 165 public native Object[] getNMethod(Executable method, boolean isOsr);
mgerdin@4850 166
iignatyev@4951 167 // Intered strings
mgerdin@4850 168 public native boolean isInStringTable(String str);
mgerdin@4850 169
mikael@4989 170 // Memory
mikael@5174 171 public native void readReservedMemory();
zgu@7076 172 public native long allocateMetaspace(ClassLoader classLoader, long size);
zgu@7076 173 public native void freeMetaspace(ClassLoader classLoader, long addr, long size);
ehelin@7254 174 public native long incMetaspaceCapacityUntilGC(long increment);
ehelin@7254 175 public native long metaspaceCapacityUntilGC();
mikael@4989 176
kevinw@8194 177 // Force Young GC
tschatzl@7071 178 public native void youngGC();
tschatzl@7071 179
kevinw@8194 180 // Force Full GC
mgerdin@4850 181 public native void fullGC();
mgerdin@6078 182
kevinw@8194 183 // Method tries to start concurrent mark cycle.
kevinw@8194 184 // It returns false if CM Thread is always in concurrent cycle.
kevinw@8194 185 public native boolean g1StartConcMarkCycle();
kevinw@8194 186
mgerdin@6078 187 // Tests on ReservedSpace/VirtualSpace classes
mgerdin@6078 188 public native int stressVirtualSpaceResize(long reservedSpaceSize, long magnitude, long iterations);
mgerdin@6078 189 public native void runMemoryUnitTests();
mgerdin@6078 190 public native void readFromNoaccessArea();
zgu@7076 191 public native long getThreadStackSize();
zgu@7076 192 public native long getThreadRemainingStackSize();
mgerdin@6078 193
iignatyev@6427 194 // CPU features
iignatyev@6427 195 public native String getCPUFeatures();
iignatyev@6427 196
sjohanss@7165 197 // Native extensions
sjohanss@7165 198 public native long getHeapUsageForContext(int context);
sjohanss@7165 199 public native long getHeapRegionCountForContext(int context);
sjohanss@7165 200 public native int getContextForObject(Object obj);
sjohanss@7165 201 public native void printRegionInfo(int context);
sjohanss@7165 202
zgu@7076 203 // VM flags
zgu@7076 204 public native void setBooleanVMFlag(String name, boolean value);
zgu@7076 205 public native void setIntxVMFlag(String name, long value);
zgu@7076 206 public native void setUintxVMFlag(String name, long value);
zgu@7076 207 public native void setUint64VMFlag(String name, long value);
zgu@7076 208 public native void setStringVMFlag(String name, String value);
zgu@7076 209 public native void setDoubleVMFlag(String name, double value);
zgu@7076 210 public native Boolean getBooleanVMFlag(String name);
zgu@7076 211 public native Long getIntxVMFlag(String name);
zgu@7076 212 public native Long getUintxVMFlag(String name);
zgu@7076 213 public native Long getUint64VMFlag(String name);
zgu@7076 214 public native String getStringVMFlag(String name);
zgu@7076 215 public native Double getDoubleVMFlag(String name);
zgu@7076 216 private final List<Function<String,Object>> flagsGetters = Arrays.asList(
zgu@7076 217 this::getBooleanVMFlag, this::getIntxVMFlag, this::getUintxVMFlag,
zgu@7076 218 this::getUint64VMFlag, this::getStringVMFlag, this::getDoubleVMFlag);
zgu@7076 219
zgu@7076 220 public Object getVMFlag(String name) {
zgu@7076 221 return flagsGetters.stream()
zgu@7076 222 .map(f -> f.apply(name))
zgu@7076 223 .filter(x -> x != null)
zgu@7076 224 .findAny()
zgu@7076 225 .orElse(null);
zgu@7076 226 }
minqi@7349 227 public native int getOffsetForName0(String name);
minqi@7349 228 public int getOffsetForName(String name) throws Exception {
minqi@7349 229 int offset = getOffsetForName0(name);
minqi@7349 230 if (offset == -1) {
minqi@7349 231 throw new RuntimeException(name + " not found");
minqi@7349 232 }
minqi@7349 233 return offset;
minqi@7349 234 }
minqi@7349 235
iklam@8497 236 // Class Data Sharing
iklam@8497 237 public native boolean isSharedClass(Class<?> c);
mgerdin@3619 238 }

mercurial