annotate src/share/vm/prims/whitebox.cpp @ 5660:755c423791ab

Merge
author ehelin
date Thu, 14 Nov 2013 21:05:16 +0100
parents 8f07aa079343 9d8b29a0548c
children
rev   line source
mgerdin@3184 1 /*
hseigel@4552 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
mgerdin@3184 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mgerdin@3184 4 *
mgerdin@3184 5 * This code is free software; you can redistribute it and/or modify it
mgerdin@3184 6 * under the terms of the GNU General Public License version 2 only, as
mgerdin@3184 7 * published by the Free Software Foundation.
mgerdin@3184 8 *
mgerdin@3184 9 * This code is distributed in the hope that it will be useful, but WITHOUT
mgerdin@3184 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mgerdin@3184 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mgerdin@3184 12 * version 2 for more details (a copy is included in the LICENSE file that
mgerdin@3184 13 * accompanied this code).
mgerdin@3184 14 *
mgerdin@3184 15 * You should have received a copy of the GNU General Public License version
mgerdin@3184 16 * 2 along with this work; if not, write to the Free Software Foundation,
mgerdin@3184 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mgerdin@3184 18 *
mgerdin@3184 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mgerdin@3184 20 * or visit www.oracle.com if you need additional information or have any
mgerdin@3184 21 * questions.
mgerdin@3184 22 *
mgerdin@3184 23 */
mgerdin@3184 24
mgerdin@3184 25 #include "precompiled.hpp"
mgerdin@3184 26
mgerdin@3184 27 #include "memory/universe.hpp"
mgerdin@3184 28 #include "oops/oop.inline.hpp"
nloodin@3246 29
nloodin@3246 30 #include "classfile/symbolTable.hpp"
coleenp@3602 31 #include "classfile/classLoaderData.hpp"
nloodin@3246 32
mgerdin@3184 33 #include "prims/whitebox.hpp"
nloodin@3246 34 #include "prims/wbtestmethods/parserTests.hpp"
nloodin@3246 35
tschatzl@5266 36 #include "runtime/arguments.hpp"
mgerdin@3184 37 #include "runtime/interfaceSupport.hpp"
mgerdin@3184 38 #include "runtime/os.hpp"
mgerdin@3184 39 #include "utilities/debug.hpp"
jprovino@4107 40 #include "utilities/macros.hpp"
mikael@4739 41 #include "utilities/exceptions.hpp"
mgerdin@3184 42
jprovino@4107 43 #if INCLUDE_ALL_GCS
mgerdin@3184 44 #include "gc_implementation/g1/concurrentMark.hpp"
mgerdin@3184 45 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
mgerdin@3184 46 #include "gc_implementation/g1/heapRegionRemSet.hpp"
jprovino@4107 47 #endif // INCLUDE_ALL_GCS
mgerdin@3184 48
ctornqvi@4077 49 #ifdef INCLUDE_NMT
ctornqvi@4077 50 #include "services/memTracker.hpp"
ctornqvi@4077 51 #endif // INCLUDE_NMT
ctornqvi@4077 52
iignatyev@4157 53 #include "compiler/compileBroker.hpp"
iignatyev@4473 54 #include "runtime/compilationPolicy.hpp"
iignatyev@4157 55
mgerdin@5643 56 #define SIZE_T_MAX_VALUE ((size_t) -1)
mgerdin@5643 57
mgerdin@3184 58 bool WhiteBox::_used = false;
mgerdin@3184 59
mgerdin@3184 60 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj))
mgerdin@3184 61 return (jlong)(void*)JNIHandles::resolve(obj);
mgerdin@3184 62 WB_END
mgerdin@3184 63
mgerdin@3184 64 WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o))
mgerdin@3184 65 return heapOopSize;
mgerdin@3184 66 WB_END
mgerdin@3184 67
coleenp@3602 68
coleenp@3602 69 class WBIsKlassAliveClosure : public KlassClosure {
coleenp@3602 70 Symbol* _name;
coleenp@3602 71 bool _found;
coleenp@3602 72 public:
coleenp@3602 73 WBIsKlassAliveClosure(Symbol* name) : _name(name), _found(false) {}
coleenp@3602 74
coleenp@3602 75 void do_klass(Klass* k) {
coleenp@3602 76 if (_found) return;
coleenp@3602 77 Symbol* ksym = k->name();
coleenp@3602 78 if (ksym->fast_compare(_name) == 0) {
coleenp@3602 79 _found = true;
coleenp@3602 80 }
coleenp@3602 81 }
coleenp@3602 82
coleenp@3602 83 bool found() const {
coleenp@3602 84 return _found;
coleenp@3602 85 }
coleenp@3602 86 };
coleenp@3602 87
coleenp@3602 88 WB_ENTRY(jboolean, WB_IsClassAlive(JNIEnv* env, jobject target, jstring name))
coleenp@3602 89 Handle h_name = JNIHandles::resolve(name);
coleenp@3602 90 if (h_name.is_null()) return false;
coleenp@3602 91 Symbol* sym = java_lang_String::as_symbol(h_name, CHECK_false);
coleenp@3602 92 TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return
coleenp@3602 93
coleenp@3602 94 WBIsKlassAliveClosure closure(sym);
coleenp@3602 95 ClassLoaderDataGraph::classes_do(&closure);
coleenp@3602 96
coleenp@3602 97 return closure.found();
coleenp@3602 98 WB_END
coleenp@3602 99
tschatzl@5266 100 WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) {
tschatzl@5266 101 return (jlong)Arguments::max_heap_for_compressed_oops();
tschatzl@5266 102 }
tschatzl@5266 103 WB_END
tschatzl@5266 104
tschatzl@4638 105 WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) {
tschatzl@4638 106 CollectorPolicy * p = Universe::heap()->collector_policy();
tschatzl@4638 107 gclog_or_tty->print_cr("Minimum heap "SIZE_FORMAT" Initial heap "
tschatzl@4638 108 SIZE_FORMAT" Maximum heap "SIZE_FORMAT" Min alignment "SIZE_FORMAT" Max alignment "SIZE_FORMAT,
tschatzl@4638 109 p->min_heap_byte_size(), p->initial_heap_byte_size(), p->max_heap_byte_size(),
jwilhelm@5650 110 p->space_alignment(), p->heap_alignment());
tschatzl@4638 111 }
tschatzl@4638 112 WB_END
tschatzl@4638 113
mgerdin@5643 114 #ifndef PRODUCT
mgerdin@5643 115 // Forward declaration
mgerdin@5643 116 void TestReservedSpace_test();
mgerdin@5643 117 void TestReserveMemorySpecial_test();
mgerdin@5643 118 void TestVirtualSpace_test();
mgerdin@5643 119 void TestMetaspaceAux_test();
mgerdin@5643 120 #endif
mgerdin@5643 121
mgerdin@5643 122 WB_ENTRY(void, WB_RunMemoryUnitTests(JNIEnv* env, jobject o))
mgerdin@5643 123 #ifndef PRODUCT
mgerdin@5643 124 TestReservedSpace_test();
mgerdin@5643 125 TestReserveMemorySpecial_test();
mgerdin@5643 126 TestVirtualSpace_test();
mgerdin@5643 127 TestMetaspaceAux_test();
mgerdin@5643 128 #endif
mgerdin@5643 129 WB_END
mgerdin@5643 130
mgerdin@5643 131 WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o))
mgerdin@5643 132 size_t granularity = os::vm_allocation_granularity();
mgerdin@5643 133 ReservedHeapSpace rhs(100 * granularity, granularity, false, NULL);
mgerdin@5643 134 VirtualSpace vs;
mgerdin@5643 135 vs.initialize(rhs, 50 * granularity);
mgerdin@5643 136
mgerdin@5643 137 //Check if constraints are complied
mgerdin@5643 138 if (!( UseCompressedOops && rhs.base() != NULL &&
mgerdin@5643 139 Universe::narrow_oop_base() != NULL &&
mgerdin@5643 140 Universe::narrow_oop_use_implicit_null_checks() )) {
mgerdin@5643 141 tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n "
mgerdin@5643 142 "\tUseCompressedOops is %d\n"
mgerdin@5643 143 "\trhs.base() is "PTR_FORMAT"\n"
mgerdin@5643 144 "\tUniverse::narrow_oop_base() is "PTR_FORMAT"\n"
mgerdin@5643 145 "\tUniverse::narrow_oop_use_implicit_null_checks() is %d",
mgerdin@5643 146 UseCompressedOops,
mgerdin@5643 147 rhs.base(),
mgerdin@5643 148 Universe::narrow_oop_base(),
mgerdin@5643 149 Universe::narrow_oop_use_implicit_null_checks());
mgerdin@5643 150 return;
mgerdin@5643 151 }
mgerdin@5643 152 tty->print_cr("Reading from no access area... ");
mgerdin@5643 153 tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c",
mgerdin@5643 154 *(vs.low_boundary() - rhs.noaccess_prefix() / 2 ));
mgerdin@5643 155 WB_END
mgerdin@5643 156
mgerdin@5643 157 static jint wb_stress_virtual_space_resize(size_t reserved_space_size,
mgerdin@5643 158 size_t magnitude, size_t iterations) {
mgerdin@5643 159 size_t granularity = os::vm_allocation_granularity();
mgerdin@5643 160 ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, false, NULL);
mgerdin@5643 161 VirtualSpace vs;
mgerdin@5643 162 if (!vs.initialize(rhs, 0)) {
mgerdin@5643 163 tty->print_cr("Failed to initialize VirtualSpace. Can't proceed.");
mgerdin@5643 164 return 3;
mgerdin@5643 165 }
mgerdin@5643 166
mgerdin@5643 167 long seed = os::random();
mgerdin@5643 168 tty->print_cr("Random seed is %ld", seed);
mgerdin@5643 169 os::init_random(seed);
mgerdin@5643 170
mgerdin@5643 171 for (size_t i = 0; i < iterations; i++) {
mgerdin@5643 172
mgerdin@5643 173 // Whether we will shrink or grow
mgerdin@5643 174 bool shrink = os::random() % 2L == 0;
mgerdin@5643 175
mgerdin@5643 176 // Get random delta to resize virtual space
mgerdin@5643 177 size_t delta = (size_t)os::random() % magnitude;
mgerdin@5643 178
mgerdin@5643 179 // If we are about to shrink virtual space below zero, then expand instead
mgerdin@5643 180 if (shrink && vs.committed_size() < delta) {
mgerdin@5643 181 shrink = false;
mgerdin@5643 182 }
mgerdin@5643 183
mgerdin@5643 184 // Resizing by delta
mgerdin@5643 185 if (shrink) {
mgerdin@5643 186 vs.shrink_by(delta);
mgerdin@5643 187 } else {
mgerdin@5643 188 // If expanding fails expand_by will silently return false
mgerdin@5643 189 vs.expand_by(delta, true);
mgerdin@5643 190 }
mgerdin@5643 191 }
mgerdin@5643 192 return 0;
mgerdin@5643 193 }
mgerdin@5643 194
mgerdin@5643 195 WB_ENTRY(jint, WB_StressVirtualSpaceResize(JNIEnv* env, jobject o,
mgerdin@5643 196 jlong reserved_space_size, jlong magnitude, jlong iterations))
mgerdin@5643 197 tty->print_cr("reservedSpaceSize="JLONG_FORMAT", magnitude="JLONG_FORMAT", "
mgerdin@5643 198 "iterations="JLONG_FORMAT"\n", reserved_space_size, magnitude,
mgerdin@5643 199 iterations);
mgerdin@5643 200 if (reserved_space_size < 0 || magnitude < 0 || iterations < 0) {
mgerdin@5643 201 tty->print_cr("One of variables printed above is negative. Can't proceed.\n");
mgerdin@5643 202 return 1;
mgerdin@5643 203 }
mgerdin@5643 204
mgerdin@5643 205 // sizeof(size_t) depends on whether OS is 32bit or 64bit. sizeof(jlong) is
mgerdin@5643 206 // always 8 byte. That's why we should avoid overflow in case of 32bit platform.
mgerdin@5643 207 if (sizeof(size_t) < sizeof(jlong)) {
mgerdin@5643 208 jlong size_t_max_value = (jlong) SIZE_T_MAX_VALUE;
mgerdin@5643 209 if (reserved_space_size > size_t_max_value || magnitude > size_t_max_value
mgerdin@5643 210 || iterations > size_t_max_value) {
mgerdin@5643 211 tty->print_cr("One of variables printed above overflows size_t. Can't proceed.\n");
mgerdin@5643 212 return 2;
mgerdin@5643 213 }
mgerdin@5643 214 }
mgerdin@5643 215
mgerdin@5643 216 return wb_stress_virtual_space_resize((size_t) reserved_space_size,
mgerdin@5643 217 (size_t) magnitude, (size_t) iterations);
mgerdin@5643 218 WB_END
mgerdin@5643 219
jprovino@4107 220 #if INCLUDE_ALL_GCS
mgerdin@3184 221 WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj))
mgerdin@3184 222 G1CollectedHeap* g1 = G1CollectedHeap::heap();
mgerdin@3184 223 oop result = JNIHandles::resolve(obj);
mgerdin@3184 224 const HeapRegion* hr = g1->heap_region_containing(result);
mgerdin@3184 225 return hr->isHumongous();
mgerdin@3184 226 WB_END
mgerdin@3184 227
mgerdin@3184 228 WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o))
mgerdin@3184 229 G1CollectedHeap* g1 = G1CollectedHeap::heap();
mgerdin@3184 230 size_t nr = g1->free_regions();
mgerdin@3184 231 return (jlong)nr;
mgerdin@3184 232 WB_END
mgerdin@3184 233
mgerdin@3184 234 WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o))
mgerdin@3184 235 G1CollectedHeap* g1 = G1CollectedHeap::heap();
mgerdin@3184 236 ConcurrentMark* cm = g1->concurrent_mark();
mgerdin@3184 237 return cm->concurrent_marking_in_progress();
mgerdin@3184 238 WB_END
mgerdin@3184 239
mgerdin@3184 240 WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o))
mgerdin@3184 241 return (jint)HeapRegion::GrainBytes;
mgerdin@3184 242 WB_END
jprovino@4107 243 #endif // INCLUDE_ALL_GCS
mgerdin@3184 244
cjplummer@5151 245 #if INCLUDE_NMT
ctornqvi@4077 246 // Alloc memory using the test memory type so that we can use that to see if
ctornqvi@4077 247 // NMT picks it up correctly
ctornqvi@4450 248 WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size))
ctornqvi@4450 249 jlong addr = 0;
ctornqvi@4077 250
ctornqvi@4450 251 if (MemTracker::is_on() && !MemTracker::shutdown_in_progress()) {
ctornqvi@4450 252 addr = (jlong)(uintptr_t)os::malloc(size, mtTest);
ctornqvi@4077 253 }
ctornqvi@4077 254
ctornqvi@4450 255 return addr;
ctornqvi@4077 256 WB_END
ctornqvi@4077 257
ctornqvi@4077 258 // Free the memory allocated by NMTAllocTest
ctornqvi@4450 259 WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem))
ctornqvi@4450 260 os::free((void*)(uintptr_t)mem, mtTest);
ctornqvi@4450 261 WB_END
ctornqvi@4077 262
ctornqvi@4450 263 WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size))
ctornqvi@4450 264 jlong addr = 0;
ctornqvi@4450 265
ctornqvi@4450 266 if (MemTracker::is_on() && !MemTracker::shutdown_in_progress()) {
ctornqvi@4450 267 addr = (jlong)(uintptr_t)os::reserve_memory(size);
ctornqvi@4450 268 MemTracker::record_virtual_memory_type((address)addr, mtTest);
ctornqvi@4077 269 }
ctornqvi@4077 270
ctornqvi@4450 271 return addr;
ctornqvi@4450 272 WB_END
ctornqvi@4077 273
ctornqvi@4450 274
ctornqvi@4450 275 WB_ENTRY(void, WB_NMTCommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
dcubed@4820 276 os::commit_memory((char *)(uintptr_t)addr, size, !ExecMem);
ctornqvi@4450 277 MemTracker::record_virtual_memory_type((address)(uintptr_t)addr, mtTest);
ctornqvi@4450 278 WB_END
ctornqvi@4450 279
ctornqvi@4450 280 WB_ENTRY(void, WB_NMTUncommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
ctornqvi@4450 281 os::uncommit_memory((char *)(uintptr_t)addr, size);
ctornqvi@4450 282 WB_END
ctornqvi@4450 283
ctornqvi@4450 284 WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
ctornqvi@4450 285 os::release_memory((char *)(uintptr_t)addr, size);
ctornqvi@4077 286 WB_END
ctornqvi@4077 287
ctornqvi@4077 288 // Block until the current generation of NMT data to be merged, used to reliably test the NMT feature
ctornqvi@4077 289 WB_ENTRY(jboolean, WB_NMTWaitForDataMerge(JNIEnv* env))
ctornqvi@4077 290
ctornqvi@4077 291 if (!MemTracker::is_on() || MemTracker::shutdown_in_progress()) {
ctornqvi@4077 292 return false;
ctornqvi@4077 293 }
ctornqvi@4077 294
ctornqvi@4077 295 return MemTracker::wbtest_wait_for_data_merge();
ctornqvi@4077 296 WB_END
ctornqvi@4077 297
cjplummer@5151 298 WB_ENTRY(jboolean, WB_NMTIsDetailSupported(JNIEnv* env))
cjplummer@5151 299 return MemTracker::tracking_level() == MemTracker::NMT_detail;
cjplummer@5151 300 WB_END
cjplummer@5151 301
ctornqvi@4077 302 #endif // INCLUDE_NMT
ctornqvi@4077 303
iignatyev@4157 304 static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) {
iignatyev@4157 305 assert(method != NULL, "method should not be null");
iignatyev@4157 306 ThreadToNativeFromVM ttn(thread);
iignatyev@4157 307 return env->FromReflectedMethod(method);
iignatyev@4157 308 }
iignatyev@4157 309
iignatyev@4157 310 WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o))
iignatyev@4157 311 MutexLockerEx mu(Compile_lock);
iignatyev@4157 312 CodeCache::mark_all_nmethods_for_deoptimization();
iignatyev@4157 313 VM_Deoptimize op;
iignatyev@4157 314 VMThread::execute(&op);
iignatyev@4157 315 WB_END
iignatyev@4157 316
iignatyev@5106 317 WB_ENTRY(jint, WB_DeoptimizeMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
iignatyev@4157 318 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
iignatyev@4157 319 MutexLockerEx mu(Compile_lock);
iignatyev@4157 320 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
iignatyev@4157 321 int result = 0;
iignatyev@5106 322 nmethod* code;
iignatyev@5106 323 if (is_osr) {
iignatyev@5106 324 int bci = InvocationEntryBci;
iignatyev@5106 325 while ((code = mh->lookup_osr_nmethod_for(bci, CompLevel_none, false)) != NULL) {
iignatyev@5106 326 code->mark_for_deoptimization();
iignatyev@5106 327 ++result;
iignatyev@5106 328 bci = code->osr_entry_bci() + 1;
iignatyev@5106 329 }
iignatyev@5106 330 } else {
iignatyev@5106 331 code = mh->code();
iignatyev@5106 332 }
iignatyev@4157 333 if (code != NULL) {
iignatyev@4157 334 code->mark_for_deoptimization();
iignatyev@4157 335 ++result;
iignatyev@4157 336 }
iignatyev@4157 337 result += CodeCache::mark_for_deoptimization(mh());
iignatyev@4157 338 if (result > 0) {
iignatyev@4157 339 VM_Deoptimize op;
iignatyev@4157 340 VMThread::execute(&op);
iignatyev@4157 341 }
iignatyev@4157 342 return result;
iignatyev@4157 343 WB_END
iignatyev@4157 344
iignatyev@5106 345 WB_ENTRY(jboolean, WB_IsMethodCompiled(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
iignatyev@4157 346 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
iignatyev@4157 347 MutexLockerEx mu(Compile_lock);
iignatyev@4157 348 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
iignatyev@5106 349 nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
iignatyev@4157 350 if (code == NULL) {
iignatyev@4157 351 return JNI_FALSE;
iignatyev@4157 352 }
iignatyev@4157 353 return (code->is_alive() && !code->is_marked_for_deoptimization());
iignatyev@4157 354 WB_END
iignatyev@4157 355
iignatyev@5106 356 WB_ENTRY(jboolean, WB_IsMethodCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr))
iignatyev@4157 357 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
iignatyev@4157 358 MutexLockerEx mu(Compile_lock);
iignatyev@4157 359 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
iignatyev@5106 360 if (is_osr) {
iignatyev@5106 361 return CompilationPolicy::can_be_osr_compiled(mh, comp_level);
iignatyev@5106 362 } else {
iignatyev@5106 363 return CompilationPolicy::can_be_compiled(mh, comp_level);
iignatyev@5106 364 }
iignatyev@4157 365 WB_END
iignatyev@4157 366
iignatyev@4157 367 WB_ENTRY(jboolean, WB_IsMethodQueuedForCompilation(JNIEnv* env, jobject o, jobject method))
iignatyev@4157 368 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
iignatyev@4157 369 MutexLockerEx mu(Compile_lock);
iignatyev@4157 370 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
iignatyev@4157 371 return mh->queued_for_compilation();
iignatyev@4157 372 WB_END
iignatyev@4157 373
iignatyev@5106 374 WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
iignatyev@4157 375 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
iignatyev@4157 376 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
iignatyev@5106 377 nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
iignatyev@4157 378 return (code != NULL ? code->comp_level() : CompLevel_none);
iignatyev@4157 379 WB_END
iignatyev@4157 380
iignatyev@5106 381 WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr))
iignatyev@4157 382 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
iignatyev@4157 383 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
iignatyev@5106 384 if (is_osr) {
iignatyev@5106 385 mh->set_not_osr_compilable(comp_level, true /* report */, "WhiteBox");
iignatyev@5106 386 } else {
iignatyev@5106 387 mh->set_not_compilable(comp_level, true /* report */, "WhiteBox");
iignatyev@5106 388 }
iignatyev@5106 389 WB_END
iignatyev@5106 390
iignatyev@5106 391 WB_ENTRY(jint, WB_GetMethodEntryBci(JNIEnv* env, jobject o, jobject method))
iignatyev@5106 392 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
iignatyev@5106 393 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
iignatyev@5106 394 nmethod* code = mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false);
iignatyev@5106 395 return (code != NULL && code->is_osr_method() ? code->osr_entry_bci() : InvocationEntryBci);
iignatyev@4157 396 WB_END
iignatyev@4157 397
iignatyev@4473 398 WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
iignatyev@4157 399 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
iignatyev@4157 400 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
iignatyev@4157 401 bool result = mh->dont_inline();
iignatyev@4157 402 mh->set_dont_inline(value == JNI_TRUE);
iignatyev@4157 403 return result;
iignatyev@4157 404 WB_END
iignatyev@4157 405
iignatyev@5106 406 WB_ENTRY(jint, WB_GetCompileQueueSize(JNIEnv* env, jobject o, jint comp_level))
iignatyev@5106 407 if (comp_level == CompLevel_any) {
iignatyev@5106 408 return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ +
iignatyev@5106 409 CompileBroker::queue_size(CompLevel_full_profile) /* C1 */;
iignatyev@5106 410 } else {
iignatyev@5106 411 return CompileBroker::queue_size(comp_level);
iignatyev@5106 412 }
iignatyev@4157 413 WB_END
iignatyev@4157 414
iignatyev@4473 415 WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
iignatyev@4473 416 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
iignatyev@4473 417 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
iignatyev@4473 418 bool result = mh->force_inline();
iignatyev@4473 419 mh->set_force_inline(value == JNI_TRUE);
iignatyev@4473 420 return result;
iignatyev@4473 421 WB_END
iignatyev@4473 422
iignatyev@5106 423 WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci))
iignatyev@4473 424 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
iignatyev@4473 425 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
iignatyev@5106 426 nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), "WhiteBox", THREAD);
iignatyev@4473 427 MutexLockerEx mu(Compile_lock);
iignatyev@4473 428 return (mh->queued_for_compilation() || nm != NULL);
iignatyev@4473 429 WB_END
iignatyev@4473 430
iignatyev@4473 431 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method))
iignatyev@4473 432 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
iignatyev@4473 433 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
iignatyev@4473 434 MutexLockerEx mu(Compile_lock);
iignatyev@4473 435 MethodData* mdo = mh->method_data();
jiangli@4503 436 MethodCounters* mcs = mh->method_counters();
iignatyev@4473 437
iignatyev@4473 438 if (mdo != NULL) {
iignatyev@4473 439 mdo->init();
iignatyev@4473 440 ResourceMark rm;
iignatyev@4473 441 int arg_count = mdo->method()->size_of_parameters();
iignatyev@4473 442 for (int i = 0; i < arg_count; i++) {
iignatyev@4473 443 mdo->set_arg_modified(i, 0);
iignatyev@4473 444 }
iignatyev@4473 445 }
iignatyev@4473 446
iignatyev@4473 447 mh->clear_not_c1_compilable();
iignatyev@4473 448 mh->clear_not_c2_compilable();
iignatyev@4473 449 mh->clear_not_c2_osr_compilable();
iignatyev@4473 450 NOT_PRODUCT(mh->set_compiled_invocation_count(0));
jiangli@4503 451 if (mcs != NULL) {
jiangli@4503 452 mcs->backedge_counter()->init();
jiangli@4503 453 mcs->invocation_counter()->init();
jiangli@4503 454 mcs->set_interpreter_invocation_count(0);
jiangli@4503 455 mcs->set_interpreter_throwout_count(0);
iignatyev@4473 456
iignatyev@4473 457 #ifdef TIERED
jiangli@4503 458 mcs->set_rate(0.0F);
jiangli@4503 459 mh->set_prev_event_count(0, THREAD);
jiangli@4503 460 mh->set_prev_time(0, THREAD);
iignatyev@4473 461 #endif
jiangli@4503 462 }
iignatyev@4473 463 WB_END
iignatyev@4473 464
mgerdin@4415 465 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
mgerdin@4415 466 ResourceMark rm(THREAD);
mgerdin@4415 467 int len;
hseigel@4552 468 jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false);
hseigel@4552 469 return (StringTable::lookup(name, len) != NULL);
mgerdin@4415 470 WB_END
mgerdin@4415 471
mgerdin@4415 472 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
mgerdin@4415 473 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true);
mgerdin@4415 474 Universe::heap()->collect(GCCause::_last_ditch_collection);
mgerdin@4415 475 WB_END
mgerdin@4415 476
mikael@4554 477
mikael@4739 478 WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o))
mikael@4739 479 // static+volatile in order to force the read to happen
mikael@4739 480 // (not be eliminated by the compiler)
mikael@4739 481 static char c;
mikael@4739 482 static volatile char* p;
mikael@4739 483
mikael@4739 484 p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0);
mikael@4739 485 if (p == NULL) {
mikael@4739 486 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory");
mikael@4739 487 }
mikael@4739 488
mikael@4739 489 c = *p;
mikael@4554 490 WB_END
mikael@4554 491
nloodin@3246 492 //Some convenience methods to deal with objects from java
nloodin@3246 493 int WhiteBox::offset_for_field(const char* field_name, oop object,
nloodin@3246 494 Symbol* signature_symbol) {
nloodin@3246 495 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
nloodin@3246 496 Thread* THREAD = Thread::current();
nloodin@3246 497
nloodin@3246 498 //Get the class of our object
coleenp@3602 499 Klass* arg_klass = object->klass();
nloodin@3246 500 //Turn it into an instance-klass
coleenp@3602 501 InstanceKlass* ik = InstanceKlass::cast(arg_klass);
nloodin@3246 502
nloodin@3246 503 //Create symbols to look for in the class
nloodin@3246 504 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
nloodin@3246 505 THREAD);
nloodin@3246 506
nloodin@3246 507 //To be filled in with an offset of the field we're looking for
nloodin@3246 508 fieldDescriptor fd;
nloodin@3246 509
coleenp@3602 510 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
nloodin@3246 511 if (res == NULL) {
nloodin@3246 512 tty->print_cr("Invalid layout of %s at %s", ik->external_name(),
nloodin@3246 513 name_symbol->as_C_string());
nloodin@3246 514 fatal("Invalid layout of preloaded class");
nloodin@3246 515 }
nloodin@3246 516
nloodin@3246 517 //fetch the field at the offset we've found
nloodin@3246 518 int dest_offset = fd.offset();
nloodin@3246 519
nloodin@3246 520 return dest_offset;
nloodin@3246 521 }
nloodin@3246 522
nloodin@3246 523
nloodin@3246 524 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) {
nloodin@3246 525 int offset = offset_for_field(field_name, object,
nloodin@3246 526 vmSymbols::string_signature());
nloodin@3246 527 oop string = object->obj_field(offset);
sla@3470 528 if (string == NULL) {
sla@3470 529 return NULL;
sla@3470 530 }
nloodin@3246 531 const char* ret = java_lang_String::as_utf8_string(string);
nloodin@3246 532 return ret;
nloodin@3246 533 }
nloodin@3246 534
nloodin@3246 535 bool WhiteBox::lookup_bool(const char* field_name, oop object) {
nloodin@3246 536 int offset =
nloodin@3246 537 offset_for_field(field_name, object, vmSymbols::bool_signature());
nloodin@3246 538 bool ret = (object->bool_field(offset) == JNI_TRUE);
nloodin@3246 539 return ret;
nloodin@3246 540 }
nloodin@3246 541
nloodin@3246 542
mgerdin@3184 543 #define CC (char*)
mgerdin@3184 544
mgerdin@3184 545 static JNINativeMethod methods[] = {
mgerdin@3184 546 {CC"getObjectAddress", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress },
mgerdin@3184 547 {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize },
iignatyev@4157 548 {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive },
iignatyev@4157 549 {CC"parseCommandLine",
iignatyev@4157 550 CC"(Ljava/lang/String;[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
nloodin@3246 551 (void*) &WB_ParseCommandLine
nloodin@3246 552 },
tschatzl@5266 553 {CC"getCompressedOopsMaxHeapSize", CC"()J",
tschatzl@5266 554 (void*)&WB_GetCompressedOopsMaxHeapSize},
tschatzl@4638 555 {CC"printHeapSizes", CC"()V", (void*)&WB_PrintHeapSizes },
mgerdin@5643 556 {CC"runMemoryUnitTests", CC"()V", (void*)&WB_RunMemoryUnitTests},
mgerdin@5643 557 {CC"readFromNoaccessArea",CC"()V", (void*)&WB_ReadFromNoaccessArea},
mgerdin@5643 558 {CC"stressVirtualSpaceResize",CC"(JJJ)I", (void*)&WB_StressVirtualSpaceResize},
jprovino@4107 559 #if INCLUDE_ALL_GCS
mgerdin@3184 560 {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark},
mgerdin@3184 561 {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous },
mgerdin@3184 562 {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions },
mgerdin@3184 563 {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize },
jprovino@4107 564 #endif // INCLUDE_ALL_GCS
cjplummer@5151 565 #if INCLUDE_NMT
ctornqvi@4450 566 {CC"NMTMalloc", CC"(J)J", (void*)&WB_NMTMalloc },
ctornqvi@4450 567 {CC"NMTFree", CC"(J)V", (void*)&WB_NMTFree },
ctornqvi@4450 568 {CC"NMTReserveMemory", CC"(J)J", (void*)&WB_NMTReserveMemory },
ctornqvi@4450 569 {CC"NMTCommitMemory", CC"(JJ)V", (void*)&WB_NMTCommitMemory },
ctornqvi@4450 570 {CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory },
ctornqvi@4450 571 {CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory },
ctornqvi@4450 572 {CC"NMTWaitForDataMerge", CC"()Z", (void*)&WB_NMTWaitForDataMerge},
cjplummer@5151 573 {CC"NMTIsDetailSupported",CC"()Z", (void*)&WB_NMTIsDetailSupported},
ctornqvi@4077 574 #endif // INCLUDE_NMT
iignatyev@4157 575 {CC"deoptimizeAll", CC"()V", (void*)&WB_DeoptimizeAll },
iignatyev@5106 576 {CC"deoptimizeMethod", CC"(Ljava/lang/reflect/Executable;Z)I",
iignatyev@4157 577 (void*)&WB_DeoptimizeMethod },
iignatyev@5106 578 {CC"isMethodCompiled", CC"(Ljava/lang/reflect/Executable;Z)Z",
iignatyev@4157 579 (void*)&WB_IsMethodCompiled },
iignatyev@5106 580 {CC"isMethodCompilable", CC"(Ljava/lang/reflect/Executable;IZ)Z",
iignatyev@4157 581 (void*)&WB_IsMethodCompilable},
iignatyev@4157 582 {CC"isMethodQueuedForCompilation",
iignatyev@4516 583 CC"(Ljava/lang/reflect/Executable;)Z", (void*)&WB_IsMethodQueuedForCompilation},
iignatyev@4157 584 {CC"makeMethodNotCompilable",
iignatyev@5106 585 CC"(Ljava/lang/reflect/Executable;IZ)V", (void*)&WB_MakeMethodNotCompilable},
iignatyev@4473 586 {CC"testSetDontInlineMethod",
iignatyev@4516 587 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod},
iignatyev@4157 588 {CC"getMethodCompilationLevel",
iignatyev@5106 589 CC"(Ljava/lang/reflect/Executable;Z)I", (void*)&WB_GetMethodCompilationLevel},
iignatyev@5106 590 {CC"getMethodEntryBci",
iignatyev@5106 591 CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci},
iignatyev@5106 592 {CC"getCompileQueueSize",
iignatyev@5106 593 CC"(I)I", (void*)&WB_GetCompileQueueSize},
iignatyev@4473 594 {CC"testSetForceInlineMethod",
iignatyev@4516 595 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod},
iignatyev@4473 596 {CC"enqueueMethodForCompilation",
iignatyev@5106 597 CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation},
iignatyev@4473 598 {CC"clearMethodState",
iignatyev@4516 599 CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState},
mgerdin@4415 600 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable },
mgerdin@4415 601 {CC"fullGC", CC"()V", (void*)&WB_FullGC },
mikael@4739 602 {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory },
mgerdin@3184 603 };
mgerdin@3184 604
mgerdin@3184 605 #undef CC
mgerdin@3184 606
mgerdin@3184 607 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
mgerdin@3184 608 {
mgerdin@3184 609 if (WhiteBoxAPI) {
mgerdin@3184 610 // Make sure that wbclass is loaded by the null classloader
mgerdin@3184 611 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
mgerdin@3184 612 Handle loader(ikh->class_loader());
mgerdin@3184 613 if (loader.is_null()) {
iignatyev@4593 614 ResourceMark rm;
mgerdin@3184 615 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
iignatyev@4593 616 bool result = true;
iignatyev@4593 617 // one by one registration natives for exception catching
iignatyev@4593 618 jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
iignatyev@4593 619 for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) {
iignatyev@4593 620 if (env->RegisterNatives(wbclass, methods + i, 1) != 0) {
iignatyev@4593 621 result = false;
iignatyev@4593 622 if (env->ExceptionCheck() && env->IsInstanceOf(env->ExceptionOccurred(), exceptionKlass)) {
iignatyev@4593 623 // j.l.NoSuchMethodError is thrown when a method can't be found or a method is not native
iignatyev@4593 624 // ignoring the exception
iignatyev@4593 625 tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", methods[i].name, methods[i].signature);
iignatyev@4593 626 env->ExceptionClear();
iignatyev@4593 627 } else {
iignatyev@4593 628 // register is failed w/o exception or w/ unexpected exception
iignatyev@4593 629 tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered", methods[i].name, methods[i].signature);
iignatyev@4593 630 env->UnregisterNatives(wbclass);
iignatyev@4593 631 break;
iignatyev@4593 632 }
iignatyev@4593 633 }
iignatyev@4593 634 }
iignatyev@4593 635
iignatyev@4593 636 if (result) {
mgerdin@3184 637 WhiteBox::set_used();
mgerdin@3184 638 }
mgerdin@3184 639 }
mgerdin@3184 640 }
mgerdin@3184 641 }
mgerdin@3184 642 JVM_END