8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 package sun.hotspot; 26 27 import java.lang.reflect.Executable; 28 import java.security.BasicPermission; 29 import sun.hotspot.parser.DiagnosticCommand; 30 31 public class WhiteBox { 32 33 @SuppressWarnings("serial") 34 public static class WhiteBoxPermission extends BasicPermission { 35 public WhiteBoxPermission(String s) { 36 super(s); 37 } 38 } 39 40 private WhiteBox() {} 41 private static final WhiteBox instance = new WhiteBox(); 42 private static native void registerNatives(); 43 44 /** 45 * Returns the singleton WhiteBox instance. 46 * 47 * The returned WhiteBox object should be carefully guarded 126 public native int getMethodCompilationLevel(Executable method, boolean isOsr); 127 public native boolean testSetDontInlineMethod(Executable method, boolean value); 128 public int getCompileQueuesSize() { 129 return getCompileQueueSize(-1 /*any*/); 130 } 131 public native int getCompileQueueSize(int compLevel); 132 public native boolean testSetForceInlineMethod(Executable method, boolean value); 133 public boolean enqueueMethodForCompilation(Executable method, int compLevel) { 134 return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/); 135 } 136 public native boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci); 137 public native void clearMethodState(Executable method); 138 public native int getMethodEntryBci(Executable method); 139 public native Object[] getNMethod(Executable method, boolean isOsr); 140 141 // Intered strings 142 public native boolean isInStringTable(String str); 143 144 // Memory 145 public native void readReservedMemory(); 146 147 // force Full GC 148 public native void fullGC(); 149 150 // Tests on ReservedSpace/VirtualSpace classes 151 public native int stressVirtualSpaceResize(long reservedSpaceSize, long magnitude, long iterations); 152 public native void runMemoryUnitTests(); 153 public native void readFromNoaccessArea(); 154 155 // CPU features 156 public native String getCPUFeatures(); 157 158 } | 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 package sun.hotspot; 26 27 import java.lang.reflect.Executable; 28 import java.util.Arrays; 29 import java.util.List; 30 import java.util.function.Function; 31 import java.util.stream.Stream; 32 import java.security.BasicPermission; 33 import sun.hotspot.parser.DiagnosticCommand; 34 35 public class WhiteBox { 36 37 @SuppressWarnings("serial") 38 public static class WhiteBoxPermission extends BasicPermission { 39 public WhiteBoxPermission(String s) { 40 super(s); 41 } 42 } 43 44 private WhiteBox() {} 45 private static final WhiteBox instance = new WhiteBox(); 46 private static native void registerNatives(); 47 48 /** 49 * Returns the singleton WhiteBox instance. 50 * 51 * The returned WhiteBox object should be carefully guarded 130 public native int getMethodCompilationLevel(Executable method, boolean isOsr); 131 public native boolean testSetDontInlineMethod(Executable method, boolean value); 132 public int getCompileQueuesSize() { 133 return getCompileQueueSize(-1 /*any*/); 134 } 135 public native int getCompileQueueSize(int compLevel); 136 public native boolean testSetForceInlineMethod(Executable method, boolean value); 137 public boolean enqueueMethodForCompilation(Executable method, int compLevel) { 138 return enqueueMethodForCompilation(method, compLevel, -1 /*InvocationEntryBci*/); 139 } 140 public native boolean enqueueMethodForCompilation(Executable method, int compLevel, int entry_bci); 141 public native void clearMethodState(Executable method); 142 public native int getMethodEntryBci(Executable method); 143 public native Object[] getNMethod(Executable method, boolean isOsr); 144 145 // Intered strings 146 public native boolean isInStringTable(String str); 147 148 // Memory 149 public native void readReservedMemory(); 150 public native long allocateMetaspace(ClassLoader classLoader, long size); 151 public native void freeMetaspace(ClassLoader classLoader, long addr, long size); 152 153 // force Full GC 154 public native void fullGC(); 155 156 // Tests on ReservedSpace/VirtualSpace classes 157 public native int stressVirtualSpaceResize(long reservedSpaceSize, long magnitude, long iterations); 158 public native void runMemoryUnitTests(); 159 public native void readFromNoaccessArea(); 160 public native long getThreadStackSize(); 161 public native long getThreadRemainingStackSize(); 162 163 // CPU features 164 public native String getCPUFeatures(); 165 166 // VM flags 167 public native void setBooleanVMFlag(String name, boolean value); 168 public native void setIntxVMFlag(String name, long value); 169 public native void setUintxVMFlag(String name, long value); 170 public native void setUint64VMFlag(String name, long value); 171 public native void setStringVMFlag(String name, String value); 172 public native void setDoubleVMFlag(String name, double value); 173 public native Boolean getBooleanVMFlag(String name); 174 public native Long getIntxVMFlag(String name); 175 public native Long getUintxVMFlag(String name); 176 public native Long getUint64VMFlag(String name); 177 public native String getStringVMFlag(String name); 178 public native Double getDoubleVMFlag(String name); 179 private final List<Function<String,Object>> flagsGetters = Arrays.asList( 180 this::getBooleanVMFlag, this::getIntxVMFlag, this::getUintxVMFlag, 181 this::getUint64VMFlag, this::getStringVMFlag, this::getDoubleVMFlag); 182 183 public Object getVMFlag(String name) { 184 return flagsGetters.stream() 185 .map(f -> f.apply(name)) 186 .filter(x -> x != null) 187 .findAny() 188 .orElse(null); 189 } 190 } |