Fri, 13 Sep 2013 12:48:50 -0700
8024346: ~CautiouslyPreserveExceptionMark - assert(!_thread->has_pending_exception()) failed: unexpected exception generated
Summary: Pending exceptions must be handled properly after a call to the JVMTI merge_cp_and_rewrite
Reviewed-by: coleenp, dholmes
Contributed-by: serguei.spitsyn@oracle.com
mgerdin@3619 | 1 | /* |
hseigel@4987 | 2 | * Copyright (c) 2012, 2013, 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 | #include "precompiled.hpp" |
mgerdin@3619 | 26 | |
mgerdin@3619 | 27 | #include "memory/universe.hpp" |
mgerdin@3619 | 28 | #include "oops/oop.inline.hpp" |
nloodin@3681 | 29 | |
nloodin@3681 | 30 | #include "classfile/symbolTable.hpp" |
coleenp@4037 | 31 | #include "classfile/classLoaderData.hpp" |
nloodin@3681 | 32 | |
mgerdin@3619 | 33 | #include "prims/whitebox.hpp" |
nloodin@3681 | 34 | #include "prims/wbtestmethods/parserTests.hpp" |
nloodin@3681 | 35 | |
mgerdin@3619 | 36 | #include "runtime/interfaceSupport.hpp" |
mgerdin@3619 | 37 | #include "runtime/os.hpp" |
mgerdin@3619 | 38 | #include "utilities/debug.hpp" |
jprovino@4542 | 39 | #include "utilities/macros.hpp" |
mikael@5174 | 40 | #include "utilities/exceptions.hpp" |
mgerdin@3619 | 41 | |
jprovino@4542 | 42 | #if INCLUDE_ALL_GCS |
mgerdin@3619 | 43 | #include "gc_implementation/g1/concurrentMark.hpp" |
mgerdin@3619 | 44 | #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
mgerdin@3619 | 45 | #include "gc_implementation/g1/heapRegionRemSet.hpp" |
jprovino@4542 | 46 | #endif // INCLUDE_ALL_GCS |
mgerdin@3619 | 47 | |
ctornqvi@4512 | 48 | #ifdef INCLUDE_NMT |
ctornqvi@4512 | 49 | #include "services/memTracker.hpp" |
ctornqvi@4512 | 50 | #endif // INCLUDE_NMT |
ctornqvi@4512 | 51 | |
iignatyev@4592 | 52 | #include "compiler/compileBroker.hpp" |
iignatyev@4908 | 53 | #include "runtime/compilationPolicy.hpp" |
iignatyev@4592 | 54 | |
mgerdin@3619 | 55 | bool WhiteBox::_used = false; |
mgerdin@3619 | 56 | |
mgerdin@3619 | 57 | WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj)) |
mgerdin@3619 | 58 | return (jlong)(void*)JNIHandles::resolve(obj); |
mgerdin@3619 | 59 | WB_END |
mgerdin@3619 | 60 | |
mgerdin@3619 | 61 | WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o)) |
mgerdin@3619 | 62 | return heapOopSize; |
mgerdin@3619 | 63 | WB_END |
mgerdin@3619 | 64 | |
coleenp@4037 | 65 | |
coleenp@4037 | 66 | class WBIsKlassAliveClosure : public KlassClosure { |
coleenp@4037 | 67 | Symbol* _name; |
coleenp@4037 | 68 | bool _found; |
coleenp@4037 | 69 | public: |
coleenp@4037 | 70 | WBIsKlassAliveClosure(Symbol* name) : _name(name), _found(false) {} |
coleenp@4037 | 71 | |
coleenp@4037 | 72 | void do_klass(Klass* k) { |
coleenp@4037 | 73 | if (_found) return; |
coleenp@4037 | 74 | Symbol* ksym = k->name(); |
coleenp@4037 | 75 | if (ksym->fast_compare(_name) == 0) { |
coleenp@4037 | 76 | _found = true; |
coleenp@4037 | 77 | } |
coleenp@4037 | 78 | } |
coleenp@4037 | 79 | |
coleenp@4037 | 80 | bool found() const { |
coleenp@4037 | 81 | return _found; |
coleenp@4037 | 82 | } |
coleenp@4037 | 83 | }; |
coleenp@4037 | 84 | |
coleenp@4037 | 85 | WB_ENTRY(jboolean, WB_IsClassAlive(JNIEnv* env, jobject target, jstring name)) |
coleenp@4037 | 86 | Handle h_name = JNIHandles::resolve(name); |
coleenp@4037 | 87 | if (h_name.is_null()) return false; |
coleenp@4037 | 88 | Symbol* sym = java_lang_String::as_symbol(h_name, CHECK_false); |
coleenp@4037 | 89 | TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return |
coleenp@4037 | 90 | |
coleenp@4037 | 91 | WBIsKlassAliveClosure closure(sym); |
coleenp@4037 | 92 | ClassLoaderDataGraph::classes_do(&closure); |
coleenp@4037 | 93 | |
coleenp@4037 | 94 | return closure.found(); |
coleenp@4037 | 95 | WB_END |
coleenp@4037 | 96 | |
tschatzl@5073 | 97 | WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) { |
tschatzl@5073 | 98 | CollectorPolicy * p = Universe::heap()->collector_policy(); |
tschatzl@5073 | 99 | gclog_or_tty->print_cr("Minimum heap "SIZE_FORMAT" Initial heap " |
tschatzl@5073 | 100 | SIZE_FORMAT" Maximum heap "SIZE_FORMAT" Min alignment "SIZE_FORMAT" Max alignment "SIZE_FORMAT, |
tschatzl@5073 | 101 | p->min_heap_byte_size(), p->initial_heap_byte_size(), p->max_heap_byte_size(), |
tschatzl@5073 | 102 | p->min_alignment(), p->max_alignment()); |
tschatzl@5073 | 103 | } |
tschatzl@5073 | 104 | WB_END |
tschatzl@5073 | 105 | |
jprovino@4542 | 106 | #if INCLUDE_ALL_GCS |
mgerdin@3619 | 107 | WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj)) |
mgerdin@3619 | 108 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
mgerdin@3619 | 109 | oop result = JNIHandles::resolve(obj); |
mgerdin@3619 | 110 | const HeapRegion* hr = g1->heap_region_containing(result); |
mgerdin@3619 | 111 | return hr->isHumongous(); |
mgerdin@3619 | 112 | WB_END |
mgerdin@3619 | 113 | |
mgerdin@3619 | 114 | WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o)) |
mgerdin@3619 | 115 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
mgerdin@3619 | 116 | size_t nr = g1->free_regions(); |
mgerdin@3619 | 117 | return (jlong)nr; |
mgerdin@3619 | 118 | WB_END |
mgerdin@3619 | 119 | |
mgerdin@3619 | 120 | WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o)) |
mgerdin@3619 | 121 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
mgerdin@3619 | 122 | ConcurrentMark* cm = g1->concurrent_mark(); |
mgerdin@3619 | 123 | return cm->concurrent_marking_in_progress(); |
mgerdin@3619 | 124 | WB_END |
mgerdin@3619 | 125 | |
mgerdin@3619 | 126 | WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o)) |
mgerdin@3619 | 127 | return (jint)HeapRegion::GrainBytes; |
mgerdin@3619 | 128 | WB_END |
jprovino@4542 | 129 | #endif // INCLUDE_ALL_GCS |
mgerdin@3619 | 130 | |
cjplummer@5586 | 131 | #if INCLUDE_NMT |
ctornqvi@4512 | 132 | // Alloc memory using the test memory type so that we can use that to see if |
ctornqvi@4512 | 133 | // NMT picks it up correctly |
ctornqvi@4885 | 134 | WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size)) |
ctornqvi@4885 | 135 | jlong addr = 0; |
ctornqvi@4512 | 136 | |
ctornqvi@4885 | 137 | if (MemTracker::is_on() && !MemTracker::shutdown_in_progress()) { |
ctornqvi@4885 | 138 | addr = (jlong)(uintptr_t)os::malloc(size, mtTest); |
ctornqvi@4512 | 139 | } |
ctornqvi@4512 | 140 | |
ctornqvi@4885 | 141 | return addr; |
ctornqvi@4512 | 142 | WB_END |
ctornqvi@4512 | 143 | |
ctornqvi@4512 | 144 | // Free the memory allocated by NMTAllocTest |
ctornqvi@4885 | 145 | WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem)) |
ctornqvi@4885 | 146 | os::free((void*)(uintptr_t)mem, mtTest); |
ctornqvi@4885 | 147 | WB_END |
ctornqvi@4512 | 148 | |
ctornqvi@4885 | 149 | WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size)) |
ctornqvi@4885 | 150 | jlong addr = 0; |
ctornqvi@4885 | 151 | |
ctornqvi@4885 | 152 | if (MemTracker::is_on() && !MemTracker::shutdown_in_progress()) { |
ctornqvi@4885 | 153 | addr = (jlong)(uintptr_t)os::reserve_memory(size); |
ctornqvi@4885 | 154 | MemTracker::record_virtual_memory_type((address)addr, mtTest); |
ctornqvi@4512 | 155 | } |
ctornqvi@4512 | 156 | |
ctornqvi@4885 | 157 | return addr; |
ctornqvi@4885 | 158 | WB_END |
ctornqvi@4512 | 159 | |
ctornqvi@4885 | 160 | |
ctornqvi@4885 | 161 | WB_ENTRY(void, WB_NMTCommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) |
dcubed@5255 | 162 | os::commit_memory((char *)(uintptr_t)addr, size, !ExecMem); |
ctornqvi@4885 | 163 | MemTracker::record_virtual_memory_type((address)(uintptr_t)addr, mtTest); |
ctornqvi@4885 | 164 | WB_END |
ctornqvi@4885 | 165 | |
ctornqvi@4885 | 166 | WB_ENTRY(void, WB_NMTUncommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) |
ctornqvi@4885 | 167 | os::uncommit_memory((char *)(uintptr_t)addr, size); |
ctornqvi@4885 | 168 | WB_END |
ctornqvi@4885 | 169 | |
ctornqvi@4885 | 170 | WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) |
ctornqvi@4885 | 171 | os::release_memory((char *)(uintptr_t)addr, size); |
ctornqvi@4512 | 172 | WB_END |
ctornqvi@4512 | 173 | |
ctornqvi@4512 | 174 | // Block until the current generation of NMT data to be merged, used to reliably test the NMT feature |
ctornqvi@4512 | 175 | WB_ENTRY(jboolean, WB_NMTWaitForDataMerge(JNIEnv* env)) |
ctornqvi@4512 | 176 | |
ctornqvi@4512 | 177 | if (!MemTracker::is_on() || MemTracker::shutdown_in_progress()) { |
ctornqvi@4512 | 178 | return false; |
ctornqvi@4512 | 179 | } |
ctornqvi@4512 | 180 | |
ctornqvi@4512 | 181 | return MemTracker::wbtest_wait_for_data_merge(); |
ctornqvi@4512 | 182 | WB_END |
ctornqvi@4512 | 183 | |
cjplummer@5586 | 184 | WB_ENTRY(jboolean, WB_NMTIsDetailSupported(JNIEnv* env)) |
cjplummer@5586 | 185 | return MemTracker::tracking_level() == MemTracker::NMT_detail; |
cjplummer@5586 | 186 | WB_END |
cjplummer@5586 | 187 | |
ctornqvi@4512 | 188 | #endif // INCLUDE_NMT |
ctornqvi@4512 | 189 | |
iignatyev@4592 | 190 | static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) { |
iignatyev@4592 | 191 | assert(method != NULL, "method should not be null"); |
iignatyev@4592 | 192 | ThreadToNativeFromVM ttn(thread); |
iignatyev@4592 | 193 | return env->FromReflectedMethod(method); |
iignatyev@4592 | 194 | } |
iignatyev@4592 | 195 | |
iignatyev@4592 | 196 | WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o)) |
iignatyev@4592 | 197 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 198 | CodeCache::mark_all_nmethods_for_deoptimization(); |
iignatyev@4592 | 199 | VM_Deoptimize op; |
iignatyev@4592 | 200 | VMThread::execute(&op); |
iignatyev@4592 | 201 | WB_END |
iignatyev@4592 | 202 | |
iignatyev@5541 | 203 | WB_ENTRY(jint, WB_DeoptimizeMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) |
iignatyev@4592 | 204 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 205 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 206 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 207 | int result = 0; |
iignatyev@5541 | 208 | nmethod* code; |
iignatyev@5541 | 209 | if (is_osr) { |
iignatyev@5541 | 210 | int bci = InvocationEntryBci; |
iignatyev@5541 | 211 | while ((code = mh->lookup_osr_nmethod_for(bci, CompLevel_none, false)) != NULL) { |
iignatyev@5541 | 212 | code->mark_for_deoptimization(); |
iignatyev@5541 | 213 | ++result; |
iignatyev@5541 | 214 | bci = code->osr_entry_bci() + 1; |
iignatyev@5541 | 215 | } |
iignatyev@5541 | 216 | } else { |
iignatyev@5541 | 217 | code = mh->code(); |
iignatyev@5541 | 218 | } |
iignatyev@4592 | 219 | if (code != NULL) { |
iignatyev@4592 | 220 | code->mark_for_deoptimization(); |
iignatyev@4592 | 221 | ++result; |
iignatyev@4592 | 222 | } |
iignatyev@4592 | 223 | result += CodeCache::mark_for_deoptimization(mh()); |
iignatyev@4592 | 224 | if (result > 0) { |
iignatyev@4592 | 225 | VM_Deoptimize op; |
iignatyev@4592 | 226 | VMThread::execute(&op); |
iignatyev@4592 | 227 | } |
iignatyev@4592 | 228 | return result; |
iignatyev@4592 | 229 | WB_END |
iignatyev@4592 | 230 | |
iignatyev@5541 | 231 | WB_ENTRY(jboolean, WB_IsMethodCompiled(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) |
iignatyev@4592 | 232 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 233 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 234 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 235 | nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code(); |
iignatyev@4592 | 236 | if (code == NULL) { |
iignatyev@4592 | 237 | return JNI_FALSE; |
iignatyev@4592 | 238 | } |
iignatyev@4592 | 239 | return (code->is_alive() && !code->is_marked_for_deoptimization()); |
iignatyev@4592 | 240 | WB_END |
iignatyev@4592 | 241 | |
iignatyev@5541 | 242 | WB_ENTRY(jboolean, WB_IsMethodCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr)) |
iignatyev@4592 | 243 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 244 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 245 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 246 | if (is_osr) { |
iignatyev@5541 | 247 | return CompilationPolicy::can_be_osr_compiled(mh, comp_level); |
iignatyev@5541 | 248 | } else { |
iignatyev@5541 | 249 | return CompilationPolicy::can_be_compiled(mh, comp_level); |
iignatyev@5541 | 250 | } |
iignatyev@4592 | 251 | WB_END |
iignatyev@4592 | 252 | |
iignatyev@4592 | 253 | WB_ENTRY(jboolean, WB_IsMethodQueuedForCompilation(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4592 | 254 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 255 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 256 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 257 | return mh->queued_for_compilation(); |
iignatyev@4592 | 258 | WB_END |
iignatyev@4592 | 259 | |
iignatyev@5541 | 260 | WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) |
iignatyev@4592 | 261 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 262 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 263 | nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code(); |
iignatyev@4592 | 264 | return (code != NULL ? code->comp_level() : CompLevel_none); |
iignatyev@4592 | 265 | WB_END |
iignatyev@4592 | 266 | |
iignatyev@5541 | 267 | WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr)) |
iignatyev@4592 | 268 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 269 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 270 | if (is_osr) { |
iignatyev@5541 | 271 | mh->set_not_osr_compilable(comp_level, true /* report */, "WhiteBox"); |
iignatyev@5541 | 272 | } else { |
iignatyev@5541 | 273 | mh->set_not_compilable(comp_level, true /* report */, "WhiteBox"); |
iignatyev@5541 | 274 | } |
iignatyev@5541 | 275 | WB_END |
iignatyev@5541 | 276 | |
iignatyev@5541 | 277 | WB_ENTRY(jint, WB_GetMethodEntryBci(JNIEnv* env, jobject o, jobject method)) |
iignatyev@5541 | 278 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@5541 | 279 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 280 | nmethod* code = mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false); |
iignatyev@5541 | 281 | return (code != NULL && code->is_osr_method() ? code->osr_entry_bci() : InvocationEntryBci); |
iignatyev@4592 | 282 | WB_END |
iignatyev@4592 | 283 | |
iignatyev@4908 | 284 | WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) |
iignatyev@4592 | 285 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 286 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 287 | bool result = mh->dont_inline(); |
iignatyev@4592 | 288 | mh->set_dont_inline(value == JNI_TRUE); |
iignatyev@4592 | 289 | return result; |
iignatyev@4592 | 290 | WB_END |
iignatyev@4592 | 291 | |
iignatyev@5541 | 292 | WB_ENTRY(jint, WB_GetCompileQueueSize(JNIEnv* env, jobject o, jint comp_level)) |
iignatyev@5541 | 293 | if (comp_level == CompLevel_any) { |
iignatyev@5541 | 294 | return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ + |
iignatyev@5541 | 295 | CompileBroker::queue_size(CompLevel_full_profile) /* C1 */; |
iignatyev@5541 | 296 | } else { |
iignatyev@5541 | 297 | return CompileBroker::queue_size(comp_level); |
iignatyev@5541 | 298 | } |
iignatyev@4592 | 299 | WB_END |
iignatyev@4592 | 300 | |
iignatyev@4908 | 301 | WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) |
iignatyev@4908 | 302 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4908 | 303 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 304 | bool result = mh->force_inline(); |
iignatyev@4908 | 305 | mh->set_force_inline(value == JNI_TRUE); |
iignatyev@4908 | 306 | return result; |
iignatyev@4908 | 307 | WB_END |
iignatyev@4908 | 308 | |
iignatyev@5541 | 309 | WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci)) |
iignatyev@4908 | 310 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4908 | 311 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 312 | nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), "WhiteBox", THREAD); |
iignatyev@4908 | 313 | MutexLockerEx mu(Compile_lock); |
iignatyev@4908 | 314 | return (mh->queued_for_compilation() || nm != NULL); |
iignatyev@4908 | 315 | WB_END |
iignatyev@4908 | 316 | |
iignatyev@4908 | 317 | WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4908 | 318 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4908 | 319 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 320 | MutexLockerEx mu(Compile_lock); |
iignatyev@4908 | 321 | MethodData* mdo = mh->method_data(); |
jiangli@4938 | 322 | MethodCounters* mcs = mh->method_counters(); |
iignatyev@4908 | 323 | |
iignatyev@4908 | 324 | if (mdo != NULL) { |
iignatyev@4908 | 325 | mdo->init(); |
iignatyev@4908 | 326 | ResourceMark rm; |
iignatyev@4908 | 327 | int arg_count = mdo->method()->size_of_parameters(); |
iignatyev@4908 | 328 | for (int i = 0; i < arg_count; i++) { |
iignatyev@4908 | 329 | mdo->set_arg_modified(i, 0); |
iignatyev@4908 | 330 | } |
iignatyev@4908 | 331 | } |
iignatyev@4908 | 332 | |
iignatyev@4908 | 333 | mh->clear_not_c1_compilable(); |
iignatyev@4908 | 334 | mh->clear_not_c2_compilable(); |
iignatyev@4908 | 335 | mh->clear_not_c2_osr_compilable(); |
iignatyev@4908 | 336 | NOT_PRODUCT(mh->set_compiled_invocation_count(0)); |
jiangli@4938 | 337 | if (mcs != NULL) { |
jiangli@4938 | 338 | mcs->backedge_counter()->init(); |
jiangli@4938 | 339 | mcs->invocation_counter()->init(); |
jiangli@4938 | 340 | mcs->set_interpreter_invocation_count(0); |
jiangli@4938 | 341 | mcs->set_interpreter_throwout_count(0); |
iignatyev@4908 | 342 | |
iignatyev@4908 | 343 | #ifdef TIERED |
jiangli@4938 | 344 | mcs->set_rate(0.0F); |
jiangli@4938 | 345 | mh->set_prev_event_count(0, THREAD); |
jiangli@4938 | 346 | mh->set_prev_time(0, THREAD); |
iignatyev@4908 | 347 | #endif |
jiangli@4938 | 348 | } |
iignatyev@4908 | 349 | WB_END |
iignatyev@4908 | 350 | |
mgerdin@4850 | 351 | WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) |
mgerdin@4850 | 352 | ResourceMark rm(THREAD); |
mgerdin@4850 | 353 | int len; |
hseigel@4987 | 354 | jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false); |
hseigel@4987 | 355 | return (StringTable::lookup(name, len) != NULL); |
mgerdin@4850 | 356 | WB_END |
mgerdin@4850 | 357 | |
mgerdin@4850 | 358 | WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) |
mgerdin@4850 | 359 | Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true); |
mgerdin@4850 | 360 | Universe::heap()->collect(GCCause::_last_ditch_collection); |
mgerdin@4850 | 361 | WB_END |
mgerdin@4850 | 362 | |
mikael@4989 | 363 | |
mikael@5174 | 364 | WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o)) |
mikael@5174 | 365 | // static+volatile in order to force the read to happen |
mikael@5174 | 366 | // (not be eliminated by the compiler) |
mikael@5174 | 367 | static char c; |
mikael@5174 | 368 | static volatile char* p; |
mikael@5174 | 369 | |
mikael@5174 | 370 | p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0); |
mikael@5174 | 371 | if (p == NULL) { |
mikael@5174 | 372 | THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory"); |
mikael@5174 | 373 | } |
mikael@5174 | 374 | |
mikael@5174 | 375 | c = *p; |
mikael@4989 | 376 | WB_END |
mikael@4989 | 377 | |
nloodin@3681 | 378 | //Some convenience methods to deal with objects from java |
nloodin@3681 | 379 | int WhiteBox::offset_for_field(const char* field_name, oop object, |
nloodin@3681 | 380 | Symbol* signature_symbol) { |
nloodin@3681 | 381 | assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid"); |
nloodin@3681 | 382 | Thread* THREAD = Thread::current(); |
nloodin@3681 | 383 | |
nloodin@3681 | 384 | //Get the class of our object |
coleenp@4037 | 385 | Klass* arg_klass = object->klass(); |
nloodin@3681 | 386 | //Turn it into an instance-klass |
coleenp@4037 | 387 | InstanceKlass* ik = InstanceKlass::cast(arg_klass); |
nloodin@3681 | 388 | |
nloodin@3681 | 389 | //Create symbols to look for in the class |
nloodin@3681 | 390 | TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name), |
nloodin@3681 | 391 | THREAD); |
nloodin@3681 | 392 | |
nloodin@3681 | 393 | //To be filled in with an offset of the field we're looking for |
nloodin@3681 | 394 | fieldDescriptor fd; |
nloodin@3681 | 395 | |
coleenp@4037 | 396 | Klass* res = ik->find_field(name_symbol, signature_symbol, &fd); |
nloodin@3681 | 397 | if (res == NULL) { |
nloodin@3681 | 398 | tty->print_cr("Invalid layout of %s at %s", ik->external_name(), |
nloodin@3681 | 399 | name_symbol->as_C_string()); |
nloodin@3681 | 400 | fatal("Invalid layout of preloaded class"); |
nloodin@3681 | 401 | } |
nloodin@3681 | 402 | |
nloodin@3681 | 403 | //fetch the field at the offset we've found |
nloodin@3681 | 404 | int dest_offset = fd.offset(); |
nloodin@3681 | 405 | |
nloodin@3681 | 406 | return dest_offset; |
nloodin@3681 | 407 | } |
nloodin@3681 | 408 | |
nloodin@3681 | 409 | |
nloodin@3681 | 410 | const char* WhiteBox::lookup_jstring(const char* field_name, oop object) { |
nloodin@3681 | 411 | int offset = offset_for_field(field_name, object, |
nloodin@3681 | 412 | vmSymbols::string_signature()); |
nloodin@3681 | 413 | oop string = object->obj_field(offset); |
sla@3905 | 414 | if (string == NULL) { |
sla@3905 | 415 | return NULL; |
sla@3905 | 416 | } |
nloodin@3681 | 417 | const char* ret = java_lang_String::as_utf8_string(string); |
nloodin@3681 | 418 | return ret; |
nloodin@3681 | 419 | } |
nloodin@3681 | 420 | |
nloodin@3681 | 421 | bool WhiteBox::lookup_bool(const char* field_name, oop object) { |
nloodin@3681 | 422 | int offset = |
nloodin@3681 | 423 | offset_for_field(field_name, object, vmSymbols::bool_signature()); |
nloodin@3681 | 424 | bool ret = (object->bool_field(offset) == JNI_TRUE); |
nloodin@3681 | 425 | return ret; |
nloodin@3681 | 426 | } |
nloodin@3681 | 427 | |
nloodin@3681 | 428 | |
mgerdin@3619 | 429 | #define CC (char*) |
mgerdin@3619 | 430 | |
mgerdin@3619 | 431 | static JNINativeMethod methods[] = { |
mgerdin@3619 | 432 | {CC"getObjectAddress", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress }, |
mgerdin@3619 | 433 | {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize }, |
iignatyev@4592 | 434 | {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive }, |
iignatyev@4592 | 435 | {CC"parseCommandLine", |
iignatyev@4592 | 436 | CC"(Ljava/lang/String;[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;", |
nloodin@3681 | 437 | (void*) &WB_ParseCommandLine |
nloodin@3681 | 438 | }, |
tschatzl@5073 | 439 | {CC"printHeapSizes", CC"()V", (void*)&WB_PrintHeapSizes }, |
jprovino@4542 | 440 | #if INCLUDE_ALL_GCS |
mgerdin@3619 | 441 | {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, |
mgerdin@3619 | 442 | {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, |
mgerdin@3619 | 443 | {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions }, |
mgerdin@3619 | 444 | {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize }, |
jprovino@4542 | 445 | #endif // INCLUDE_ALL_GCS |
cjplummer@5586 | 446 | #if INCLUDE_NMT |
ctornqvi@4885 | 447 | {CC"NMTMalloc", CC"(J)J", (void*)&WB_NMTMalloc }, |
ctornqvi@4885 | 448 | {CC"NMTFree", CC"(J)V", (void*)&WB_NMTFree }, |
ctornqvi@4885 | 449 | {CC"NMTReserveMemory", CC"(J)J", (void*)&WB_NMTReserveMemory }, |
ctornqvi@4885 | 450 | {CC"NMTCommitMemory", CC"(JJ)V", (void*)&WB_NMTCommitMemory }, |
ctornqvi@4885 | 451 | {CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory }, |
ctornqvi@4885 | 452 | {CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory }, |
ctornqvi@4885 | 453 | {CC"NMTWaitForDataMerge", CC"()Z", (void*)&WB_NMTWaitForDataMerge}, |
cjplummer@5586 | 454 | {CC"NMTIsDetailSupported",CC"()Z", (void*)&WB_NMTIsDetailSupported}, |
ctornqvi@4512 | 455 | #endif // INCLUDE_NMT |
iignatyev@4592 | 456 | {CC"deoptimizeAll", CC"()V", (void*)&WB_DeoptimizeAll }, |
iignatyev@5541 | 457 | {CC"deoptimizeMethod", CC"(Ljava/lang/reflect/Executable;Z)I", |
iignatyev@4592 | 458 | (void*)&WB_DeoptimizeMethod }, |
iignatyev@5541 | 459 | {CC"isMethodCompiled", CC"(Ljava/lang/reflect/Executable;Z)Z", |
iignatyev@4592 | 460 | (void*)&WB_IsMethodCompiled }, |
iignatyev@5541 | 461 | {CC"isMethodCompilable", CC"(Ljava/lang/reflect/Executable;IZ)Z", |
iignatyev@4592 | 462 | (void*)&WB_IsMethodCompilable}, |
iignatyev@4592 | 463 | {CC"isMethodQueuedForCompilation", |
iignatyev@4951 | 464 | CC"(Ljava/lang/reflect/Executable;)Z", (void*)&WB_IsMethodQueuedForCompilation}, |
iignatyev@4592 | 465 | {CC"makeMethodNotCompilable", |
iignatyev@5541 | 466 | CC"(Ljava/lang/reflect/Executable;IZ)V", (void*)&WB_MakeMethodNotCompilable}, |
iignatyev@4908 | 467 | {CC"testSetDontInlineMethod", |
iignatyev@4951 | 468 | CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod}, |
iignatyev@4592 | 469 | {CC"getMethodCompilationLevel", |
iignatyev@5541 | 470 | CC"(Ljava/lang/reflect/Executable;Z)I", (void*)&WB_GetMethodCompilationLevel}, |
iignatyev@5541 | 471 | {CC"getMethodEntryBci", |
iignatyev@5541 | 472 | CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci}, |
iignatyev@5541 | 473 | {CC"getCompileQueueSize", |
iignatyev@5541 | 474 | CC"(I)I", (void*)&WB_GetCompileQueueSize}, |
iignatyev@4908 | 475 | {CC"testSetForceInlineMethod", |
iignatyev@4951 | 476 | CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod}, |
iignatyev@4908 | 477 | {CC"enqueueMethodForCompilation", |
iignatyev@5541 | 478 | CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation}, |
iignatyev@4908 | 479 | {CC"clearMethodState", |
iignatyev@4951 | 480 | CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState}, |
mgerdin@4850 | 481 | {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, |
mgerdin@4850 | 482 | {CC"fullGC", CC"()V", (void*)&WB_FullGC }, |
mikael@5174 | 483 | {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory }, |
mgerdin@3619 | 484 | }; |
mgerdin@3619 | 485 | |
mgerdin@3619 | 486 | #undef CC |
mgerdin@3619 | 487 | |
mgerdin@3619 | 488 | JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass)) |
mgerdin@3619 | 489 | { |
mgerdin@3619 | 490 | if (WhiteBoxAPI) { |
mgerdin@3619 | 491 | // Make sure that wbclass is loaded by the null classloader |
mgerdin@3619 | 492 | instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass()); |
mgerdin@3619 | 493 | Handle loader(ikh->class_loader()); |
mgerdin@3619 | 494 | if (loader.is_null()) { |
iignatyev@5028 | 495 | ResourceMark rm; |
mgerdin@3619 | 496 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@5028 | 497 | bool result = true; |
iignatyev@5028 | 498 | // one by one registration natives for exception catching |
iignatyev@5028 | 499 | jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); |
iignatyev@5028 | 500 | for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) { |
iignatyev@5028 | 501 | if (env->RegisterNatives(wbclass, methods + i, 1) != 0) { |
iignatyev@5028 | 502 | result = false; |
iignatyev@5028 | 503 | if (env->ExceptionCheck() && env->IsInstanceOf(env->ExceptionOccurred(), exceptionKlass)) { |
iignatyev@5028 | 504 | // j.l.NoSuchMethodError is thrown when a method can't be found or a method is not native |
iignatyev@5028 | 505 | // ignoring the exception |
iignatyev@5028 | 506 | tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", methods[i].name, methods[i].signature); |
iignatyev@5028 | 507 | env->ExceptionClear(); |
iignatyev@5028 | 508 | } else { |
iignatyev@5028 | 509 | // register is failed w/o exception or w/ unexpected exception |
iignatyev@5028 | 510 | 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@5028 | 511 | env->UnregisterNatives(wbclass); |
iignatyev@5028 | 512 | break; |
iignatyev@5028 | 513 | } |
iignatyev@5028 | 514 | } |
iignatyev@5028 | 515 | } |
iignatyev@5028 | 516 | |
iignatyev@5028 | 517 | if (result) { |
mgerdin@3619 | 518 | WhiteBox::set_used(); |
mgerdin@3619 | 519 | } |
mgerdin@3619 | 520 | } |
mgerdin@3619 | 521 | } |
mgerdin@3619 | 522 | } |
mgerdin@3619 | 523 | JVM_END |