Mon, 29 Apr 2013 16:13:57 -0400
8011773: Some tests on Interned String crashed JVM with OOM
Summary: Instead of terminating the VM, throw OutOfMemoryError exceptions.
Reviewed-by: coleenp, dholmes
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" |
mgerdin@3619 | 40 | |
jprovino@4542 | 41 | #if INCLUDE_ALL_GCS |
mgerdin@3619 | 42 | #include "gc_implementation/g1/concurrentMark.hpp" |
mgerdin@3619 | 43 | #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
mgerdin@3619 | 44 | #include "gc_implementation/g1/heapRegionRemSet.hpp" |
jprovino@4542 | 45 | #endif // INCLUDE_ALL_GCS |
mgerdin@3619 | 46 | |
ctornqvi@4512 | 47 | #ifdef INCLUDE_NMT |
ctornqvi@4512 | 48 | #include "services/memTracker.hpp" |
ctornqvi@4512 | 49 | #endif // INCLUDE_NMT |
ctornqvi@4512 | 50 | |
iignatyev@4592 | 51 | #include "compiler/compileBroker.hpp" |
iignatyev@4908 | 52 | #include "runtime/compilationPolicy.hpp" |
iignatyev@4592 | 53 | |
mgerdin@3619 | 54 | bool WhiteBox::_used = false; |
mgerdin@3619 | 55 | |
mgerdin@3619 | 56 | WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj)) |
mgerdin@3619 | 57 | return (jlong)(void*)JNIHandles::resolve(obj); |
mgerdin@3619 | 58 | WB_END |
mgerdin@3619 | 59 | |
mgerdin@3619 | 60 | WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o)) |
mgerdin@3619 | 61 | return heapOopSize; |
mgerdin@3619 | 62 | WB_END |
mgerdin@3619 | 63 | |
coleenp@4037 | 64 | |
coleenp@4037 | 65 | class WBIsKlassAliveClosure : public KlassClosure { |
coleenp@4037 | 66 | Symbol* _name; |
coleenp@4037 | 67 | bool _found; |
coleenp@4037 | 68 | public: |
coleenp@4037 | 69 | WBIsKlassAliveClosure(Symbol* name) : _name(name), _found(false) {} |
coleenp@4037 | 70 | |
coleenp@4037 | 71 | void do_klass(Klass* k) { |
coleenp@4037 | 72 | if (_found) return; |
coleenp@4037 | 73 | Symbol* ksym = k->name(); |
coleenp@4037 | 74 | if (ksym->fast_compare(_name) == 0) { |
coleenp@4037 | 75 | _found = true; |
coleenp@4037 | 76 | } |
coleenp@4037 | 77 | } |
coleenp@4037 | 78 | |
coleenp@4037 | 79 | bool found() const { |
coleenp@4037 | 80 | return _found; |
coleenp@4037 | 81 | } |
coleenp@4037 | 82 | }; |
coleenp@4037 | 83 | |
coleenp@4037 | 84 | WB_ENTRY(jboolean, WB_IsClassAlive(JNIEnv* env, jobject target, jstring name)) |
coleenp@4037 | 85 | Handle h_name = JNIHandles::resolve(name); |
coleenp@4037 | 86 | if (h_name.is_null()) return false; |
coleenp@4037 | 87 | Symbol* sym = java_lang_String::as_symbol(h_name, CHECK_false); |
coleenp@4037 | 88 | TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return |
coleenp@4037 | 89 | |
coleenp@4037 | 90 | WBIsKlassAliveClosure closure(sym); |
coleenp@4037 | 91 | ClassLoaderDataGraph::classes_do(&closure); |
coleenp@4037 | 92 | |
coleenp@4037 | 93 | return closure.found(); |
coleenp@4037 | 94 | WB_END |
coleenp@4037 | 95 | |
jprovino@4542 | 96 | #if INCLUDE_ALL_GCS |
mgerdin@3619 | 97 | WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj)) |
mgerdin@3619 | 98 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
mgerdin@3619 | 99 | oop result = JNIHandles::resolve(obj); |
mgerdin@3619 | 100 | const HeapRegion* hr = g1->heap_region_containing(result); |
mgerdin@3619 | 101 | return hr->isHumongous(); |
mgerdin@3619 | 102 | WB_END |
mgerdin@3619 | 103 | |
mgerdin@3619 | 104 | WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o)) |
mgerdin@3619 | 105 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
mgerdin@3619 | 106 | size_t nr = g1->free_regions(); |
mgerdin@3619 | 107 | return (jlong)nr; |
mgerdin@3619 | 108 | WB_END |
mgerdin@3619 | 109 | |
mgerdin@3619 | 110 | WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o)) |
mgerdin@3619 | 111 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
mgerdin@3619 | 112 | ConcurrentMark* cm = g1->concurrent_mark(); |
mgerdin@3619 | 113 | return cm->concurrent_marking_in_progress(); |
mgerdin@3619 | 114 | WB_END |
mgerdin@3619 | 115 | |
mgerdin@3619 | 116 | WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o)) |
mgerdin@3619 | 117 | return (jint)HeapRegion::GrainBytes; |
mgerdin@3619 | 118 | WB_END |
jprovino@4542 | 119 | #endif // INCLUDE_ALL_GCS |
mgerdin@3619 | 120 | |
ctornqvi@4512 | 121 | #ifdef INCLUDE_NMT |
ctornqvi@4512 | 122 | // Alloc memory using the test memory type so that we can use that to see if |
ctornqvi@4512 | 123 | // NMT picks it up correctly |
ctornqvi@4885 | 124 | WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size)) |
ctornqvi@4885 | 125 | jlong addr = 0; |
ctornqvi@4512 | 126 | |
ctornqvi@4885 | 127 | if (MemTracker::is_on() && !MemTracker::shutdown_in_progress()) { |
ctornqvi@4885 | 128 | addr = (jlong)(uintptr_t)os::malloc(size, mtTest); |
ctornqvi@4512 | 129 | } |
ctornqvi@4512 | 130 | |
ctornqvi@4885 | 131 | return addr; |
ctornqvi@4512 | 132 | WB_END |
ctornqvi@4512 | 133 | |
ctornqvi@4512 | 134 | // Free the memory allocated by NMTAllocTest |
ctornqvi@4885 | 135 | WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem)) |
ctornqvi@4885 | 136 | os::free((void*)(uintptr_t)mem, mtTest); |
ctornqvi@4885 | 137 | WB_END |
ctornqvi@4512 | 138 | |
ctornqvi@4885 | 139 | WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size)) |
ctornqvi@4885 | 140 | jlong addr = 0; |
ctornqvi@4885 | 141 | |
ctornqvi@4885 | 142 | if (MemTracker::is_on() && !MemTracker::shutdown_in_progress()) { |
ctornqvi@4885 | 143 | addr = (jlong)(uintptr_t)os::reserve_memory(size); |
ctornqvi@4885 | 144 | MemTracker::record_virtual_memory_type((address)addr, mtTest); |
ctornqvi@4512 | 145 | } |
ctornqvi@4512 | 146 | |
ctornqvi@4885 | 147 | return addr; |
ctornqvi@4885 | 148 | WB_END |
ctornqvi@4512 | 149 | |
ctornqvi@4885 | 150 | |
ctornqvi@4885 | 151 | WB_ENTRY(void, WB_NMTCommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) |
ctornqvi@4885 | 152 | os::commit_memory((char *)(uintptr_t)addr, size); |
ctornqvi@4885 | 153 | MemTracker::record_virtual_memory_type((address)(uintptr_t)addr, mtTest); |
ctornqvi@4885 | 154 | WB_END |
ctornqvi@4885 | 155 | |
ctornqvi@4885 | 156 | WB_ENTRY(void, WB_NMTUncommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) |
ctornqvi@4885 | 157 | os::uncommit_memory((char *)(uintptr_t)addr, size); |
ctornqvi@4885 | 158 | WB_END |
ctornqvi@4885 | 159 | |
ctornqvi@4885 | 160 | WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) |
ctornqvi@4885 | 161 | os::release_memory((char *)(uintptr_t)addr, size); |
ctornqvi@4512 | 162 | WB_END |
ctornqvi@4512 | 163 | |
ctornqvi@4512 | 164 | // Block until the current generation of NMT data to be merged, used to reliably test the NMT feature |
ctornqvi@4512 | 165 | WB_ENTRY(jboolean, WB_NMTWaitForDataMerge(JNIEnv* env)) |
ctornqvi@4512 | 166 | |
ctornqvi@4512 | 167 | if (!MemTracker::is_on() || MemTracker::shutdown_in_progress()) { |
ctornqvi@4512 | 168 | return false; |
ctornqvi@4512 | 169 | } |
ctornqvi@4512 | 170 | |
ctornqvi@4512 | 171 | return MemTracker::wbtest_wait_for_data_merge(); |
ctornqvi@4512 | 172 | WB_END |
ctornqvi@4512 | 173 | |
ctornqvi@4512 | 174 | #endif // INCLUDE_NMT |
ctornqvi@4512 | 175 | |
iignatyev@4592 | 176 | static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) { |
iignatyev@4592 | 177 | assert(method != NULL, "method should not be null"); |
iignatyev@4592 | 178 | ThreadToNativeFromVM ttn(thread); |
iignatyev@4592 | 179 | return env->FromReflectedMethod(method); |
iignatyev@4592 | 180 | } |
iignatyev@4592 | 181 | |
iignatyev@4592 | 182 | WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o)) |
iignatyev@4592 | 183 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 184 | CodeCache::mark_all_nmethods_for_deoptimization(); |
iignatyev@4592 | 185 | VM_Deoptimize op; |
iignatyev@4592 | 186 | VMThread::execute(&op); |
iignatyev@4592 | 187 | WB_END |
iignatyev@4592 | 188 | |
iignatyev@4592 | 189 | WB_ENTRY(jint, WB_DeoptimizeMethod(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4592 | 190 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 191 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 192 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 193 | int result = 0; |
iignatyev@4592 | 194 | nmethod* code = mh->code(); |
iignatyev@4592 | 195 | if (code != NULL) { |
iignatyev@4592 | 196 | code->mark_for_deoptimization(); |
iignatyev@4592 | 197 | ++result; |
iignatyev@4592 | 198 | } |
iignatyev@4592 | 199 | result += CodeCache::mark_for_deoptimization(mh()); |
iignatyev@4592 | 200 | if (result > 0) { |
iignatyev@4592 | 201 | VM_Deoptimize op; |
iignatyev@4592 | 202 | VMThread::execute(&op); |
iignatyev@4592 | 203 | } |
iignatyev@4592 | 204 | return result; |
iignatyev@4592 | 205 | WB_END |
iignatyev@4592 | 206 | |
iignatyev@4592 | 207 | WB_ENTRY(jboolean, WB_IsMethodCompiled(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4592 | 208 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 209 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 210 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 211 | nmethod* code = mh->code(); |
iignatyev@4592 | 212 | if (code == NULL) { |
iignatyev@4592 | 213 | return JNI_FALSE; |
iignatyev@4592 | 214 | } |
iignatyev@4592 | 215 | return (code->is_alive() && !code->is_marked_for_deoptimization()); |
iignatyev@4592 | 216 | WB_END |
iignatyev@4592 | 217 | |
iignatyev@4908 | 218 | WB_ENTRY(jboolean, WB_IsMethodCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level)) |
iignatyev@4592 | 219 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 220 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 221 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 222 | return CompilationPolicy::can_be_compiled(mh, comp_level); |
iignatyev@4592 | 223 | WB_END |
iignatyev@4592 | 224 | |
iignatyev@4592 | 225 | WB_ENTRY(jboolean, WB_IsMethodQueuedForCompilation(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4592 | 226 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 227 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 228 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 229 | return mh->queued_for_compilation(); |
iignatyev@4592 | 230 | WB_END |
iignatyev@4592 | 231 | |
iignatyev@4592 | 232 | WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4592 | 233 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 234 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 235 | nmethod* code = mh->code(); |
iignatyev@4592 | 236 | return (code != NULL ? code->comp_level() : CompLevel_none); |
iignatyev@4592 | 237 | WB_END |
iignatyev@4592 | 238 | |
iignatyev@4592 | 239 | |
iignatyev@4951 | 240 | WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level)) |
iignatyev@4592 | 241 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 242 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4951 | 243 | mh->set_not_compilable(comp_level, true /* report */, "WhiteBox"); |
iignatyev@4592 | 244 | WB_END |
iignatyev@4592 | 245 | |
iignatyev@4908 | 246 | WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) |
iignatyev@4592 | 247 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 248 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 249 | bool result = mh->dont_inline(); |
iignatyev@4592 | 250 | mh->set_dont_inline(value == JNI_TRUE); |
iignatyev@4592 | 251 | return result; |
iignatyev@4592 | 252 | WB_END |
iignatyev@4592 | 253 | |
iignatyev@4592 | 254 | WB_ENTRY(jint, WB_GetCompileQueuesSize(JNIEnv* env, jobject o)) |
iignatyev@4592 | 255 | return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ + |
iignatyev@4592 | 256 | CompileBroker::queue_size(CompLevel_full_profile) /* C1 */; |
iignatyev@4592 | 257 | WB_END |
iignatyev@4592 | 258 | |
iignatyev@4908 | 259 | |
iignatyev@4908 | 260 | WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) |
iignatyev@4908 | 261 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4908 | 262 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 263 | bool result = mh->force_inline(); |
iignatyev@4908 | 264 | mh->set_force_inline(value == JNI_TRUE); |
iignatyev@4908 | 265 | return result; |
iignatyev@4908 | 266 | WB_END |
iignatyev@4908 | 267 | |
iignatyev@4908 | 268 | WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level)) |
iignatyev@4908 | 269 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4908 | 270 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 271 | nmethod* nm = CompileBroker::compile_method(mh, InvocationEntryBci, comp_level, mh, mh->invocation_count(), "WhiteBox", THREAD); |
iignatyev@4908 | 272 | MutexLockerEx mu(Compile_lock); |
iignatyev@4908 | 273 | return (mh->queued_for_compilation() || nm != NULL); |
iignatyev@4908 | 274 | WB_END |
iignatyev@4908 | 275 | |
iignatyev@4908 | 276 | WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4908 | 277 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4908 | 278 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 279 | MutexLockerEx mu(Compile_lock); |
iignatyev@4908 | 280 | MethodData* mdo = mh->method_data(); |
jiangli@4938 | 281 | MethodCounters* mcs = mh->method_counters(); |
iignatyev@4908 | 282 | |
iignatyev@4908 | 283 | if (mdo != NULL) { |
iignatyev@4908 | 284 | mdo->init(); |
iignatyev@4908 | 285 | ResourceMark rm; |
iignatyev@4908 | 286 | int arg_count = mdo->method()->size_of_parameters(); |
iignatyev@4908 | 287 | for (int i = 0; i < arg_count; i++) { |
iignatyev@4908 | 288 | mdo->set_arg_modified(i, 0); |
iignatyev@4908 | 289 | } |
iignatyev@4908 | 290 | } |
iignatyev@4908 | 291 | |
iignatyev@4908 | 292 | mh->clear_not_c1_compilable(); |
iignatyev@4908 | 293 | mh->clear_not_c2_compilable(); |
iignatyev@4908 | 294 | mh->clear_not_c2_osr_compilable(); |
iignatyev@4908 | 295 | NOT_PRODUCT(mh->set_compiled_invocation_count(0)); |
jiangli@4938 | 296 | if (mcs != NULL) { |
jiangli@4938 | 297 | mcs->backedge_counter()->init(); |
jiangli@4938 | 298 | mcs->invocation_counter()->init(); |
jiangli@4938 | 299 | mcs->set_interpreter_invocation_count(0); |
jiangli@4938 | 300 | mcs->set_interpreter_throwout_count(0); |
iignatyev@4908 | 301 | |
iignatyev@4908 | 302 | #ifdef TIERED |
jiangli@4938 | 303 | mcs->set_rate(0.0F); |
jiangli@4938 | 304 | mh->set_prev_event_count(0, THREAD); |
jiangli@4938 | 305 | mh->set_prev_time(0, THREAD); |
iignatyev@4908 | 306 | #endif |
jiangli@4938 | 307 | } |
iignatyev@4908 | 308 | WB_END |
iignatyev@4908 | 309 | |
mgerdin@4850 | 310 | WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) |
mgerdin@4850 | 311 | ResourceMark rm(THREAD); |
mgerdin@4850 | 312 | int len; |
hseigel@4987 | 313 | jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false); |
hseigel@4987 | 314 | return (StringTable::lookup(name, len) != NULL); |
mgerdin@4850 | 315 | WB_END |
mgerdin@4850 | 316 | |
mgerdin@4850 | 317 | |
mgerdin@4850 | 318 | WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) |
mgerdin@4850 | 319 | Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true); |
mgerdin@4850 | 320 | Universe::heap()->collect(GCCause::_last_ditch_collection); |
mgerdin@4850 | 321 | WB_END |
mgerdin@4850 | 322 | |
nloodin@3681 | 323 | //Some convenience methods to deal with objects from java |
nloodin@3681 | 324 | int WhiteBox::offset_for_field(const char* field_name, oop object, |
nloodin@3681 | 325 | Symbol* signature_symbol) { |
nloodin@3681 | 326 | assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid"); |
nloodin@3681 | 327 | Thread* THREAD = Thread::current(); |
nloodin@3681 | 328 | |
nloodin@3681 | 329 | //Get the class of our object |
coleenp@4037 | 330 | Klass* arg_klass = object->klass(); |
nloodin@3681 | 331 | //Turn it into an instance-klass |
coleenp@4037 | 332 | InstanceKlass* ik = InstanceKlass::cast(arg_klass); |
nloodin@3681 | 333 | |
nloodin@3681 | 334 | //Create symbols to look for in the class |
nloodin@3681 | 335 | TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name), |
nloodin@3681 | 336 | THREAD); |
nloodin@3681 | 337 | |
nloodin@3681 | 338 | //To be filled in with an offset of the field we're looking for |
nloodin@3681 | 339 | fieldDescriptor fd; |
nloodin@3681 | 340 | |
coleenp@4037 | 341 | Klass* res = ik->find_field(name_symbol, signature_symbol, &fd); |
nloodin@3681 | 342 | if (res == NULL) { |
nloodin@3681 | 343 | tty->print_cr("Invalid layout of %s at %s", ik->external_name(), |
nloodin@3681 | 344 | name_symbol->as_C_string()); |
nloodin@3681 | 345 | fatal("Invalid layout of preloaded class"); |
nloodin@3681 | 346 | } |
nloodin@3681 | 347 | |
nloodin@3681 | 348 | //fetch the field at the offset we've found |
nloodin@3681 | 349 | int dest_offset = fd.offset(); |
nloodin@3681 | 350 | |
nloodin@3681 | 351 | return dest_offset; |
nloodin@3681 | 352 | } |
nloodin@3681 | 353 | |
nloodin@3681 | 354 | |
nloodin@3681 | 355 | const char* WhiteBox::lookup_jstring(const char* field_name, oop object) { |
nloodin@3681 | 356 | int offset = offset_for_field(field_name, object, |
nloodin@3681 | 357 | vmSymbols::string_signature()); |
nloodin@3681 | 358 | oop string = object->obj_field(offset); |
sla@3905 | 359 | if (string == NULL) { |
sla@3905 | 360 | return NULL; |
sla@3905 | 361 | } |
nloodin@3681 | 362 | const char* ret = java_lang_String::as_utf8_string(string); |
nloodin@3681 | 363 | return ret; |
nloodin@3681 | 364 | } |
nloodin@3681 | 365 | |
nloodin@3681 | 366 | bool WhiteBox::lookup_bool(const char* field_name, oop object) { |
nloodin@3681 | 367 | int offset = |
nloodin@3681 | 368 | offset_for_field(field_name, object, vmSymbols::bool_signature()); |
nloodin@3681 | 369 | bool ret = (object->bool_field(offset) == JNI_TRUE); |
nloodin@3681 | 370 | return ret; |
nloodin@3681 | 371 | } |
nloodin@3681 | 372 | |
nloodin@3681 | 373 | |
mgerdin@3619 | 374 | #define CC (char*) |
mgerdin@3619 | 375 | |
mgerdin@3619 | 376 | static JNINativeMethod methods[] = { |
mgerdin@3619 | 377 | {CC"getObjectAddress", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress }, |
mgerdin@3619 | 378 | {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize }, |
iignatyev@4592 | 379 | {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive }, |
iignatyev@4592 | 380 | {CC"parseCommandLine", |
iignatyev@4592 | 381 | CC"(Ljava/lang/String;[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;", |
nloodin@3681 | 382 | (void*) &WB_ParseCommandLine |
nloodin@3681 | 383 | }, |
jprovino@4542 | 384 | #if INCLUDE_ALL_GCS |
mgerdin@3619 | 385 | {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, |
mgerdin@3619 | 386 | {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, |
mgerdin@3619 | 387 | {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions }, |
mgerdin@3619 | 388 | {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize }, |
jprovino@4542 | 389 | #endif // INCLUDE_ALL_GCS |
ctornqvi@4512 | 390 | #ifdef INCLUDE_NMT |
ctornqvi@4885 | 391 | {CC"NMTMalloc", CC"(J)J", (void*)&WB_NMTMalloc }, |
ctornqvi@4885 | 392 | {CC"NMTFree", CC"(J)V", (void*)&WB_NMTFree }, |
ctornqvi@4885 | 393 | {CC"NMTReserveMemory", CC"(J)J", (void*)&WB_NMTReserveMemory }, |
ctornqvi@4885 | 394 | {CC"NMTCommitMemory", CC"(JJ)V", (void*)&WB_NMTCommitMemory }, |
ctornqvi@4885 | 395 | {CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory }, |
ctornqvi@4885 | 396 | {CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory }, |
ctornqvi@4885 | 397 | {CC"NMTWaitForDataMerge", CC"()Z", (void*)&WB_NMTWaitForDataMerge}, |
ctornqvi@4512 | 398 | #endif // INCLUDE_NMT |
iignatyev@4592 | 399 | {CC"deoptimizeAll", CC"()V", (void*)&WB_DeoptimizeAll }, |
iignatyev@4951 | 400 | {CC"deoptimizeMethod", CC"(Ljava/lang/reflect/Executable;)I", |
iignatyev@4592 | 401 | (void*)&WB_DeoptimizeMethod }, |
iignatyev@4951 | 402 | {CC"isMethodCompiled", CC"(Ljava/lang/reflect/Executable;)Z", |
iignatyev@4592 | 403 | (void*)&WB_IsMethodCompiled }, |
iignatyev@4951 | 404 | {CC"isMethodCompilable", CC"(Ljava/lang/reflect/Executable;I)Z", |
iignatyev@4592 | 405 | (void*)&WB_IsMethodCompilable}, |
iignatyev@4592 | 406 | {CC"isMethodQueuedForCompilation", |
iignatyev@4951 | 407 | CC"(Ljava/lang/reflect/Executable;)Z", (void*)&WB_IsMethodQueuedForCompilation}, |
iignatyev@4592 | 408 | {CC"makeMethodNotCompilable", |
iignatyev@4951 | 409 | CC"(Ljava/lang/reflect/Executable;I)V", (void*)&WB_MakeMethodNotCompilable}, |
iignatyev@4908 | 410 | {CC"testSetDontInlineMethod", |
iignatyev@4951 | 411 | CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod}, |
iignatyev@4592 | 412 | {CC"getMethodCompilationLevel", |
iignatyev@4951 | 413 | CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodCompilationLevel}, |
iignatyev@4592 | 414 | {CC"getCompileQueuesSize", |
iignatyev@4592 | 415 | CC"()I", (void*)&WB_GetCompileQueuesSize}, |
iignatyev@4908 | 416 | {CC"testSetForceInlineMethod", |
iignatyev@4951 | 417 | CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod}, |
iignatyev@4908 | 418 | {CC"enqueueMethodForCompilation", |
iignatyev@4951 | 419 | CC"(Ljava/lang/reflect/Executable;I)Z", (void*)&WB_EnqueueMethodForCompilation}, |
iignatyev@4908 | 420 | {CC"clearMethodState", |
iignatyev@4951 | 421 | CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState}, |
mgerdin@4850 | 422 | {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, |
mgerdin@4850 | 423 | {CC"fullGC", CC"()V", (void*)&WB_FullGC }, |
mgerdin@3619 | 424 | }; |
mgerdin@3619 | 425 | |
mgerdin@3619 | 426 | #undef CC |
mgerdin@3619 | 427 | |
mgerdin@3619 | 428 | JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass)) |
mgerdin@3619 | 429 | { |
mgerdin@3619 | 430 | if (WhiteBoxAPI) { |
mgerdin@3619 | 431 | // Make sure that wbclass is loaded by the null classloader |
mgerdin@3619 | 432 | instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass()); |
mgerdin@3619 | 433 | Handle loader(ikh->class_loader()); |
mgerdin@3619 | 434 | if (loader.is_null()) { |
mgerdin@3619 | 435 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
mgerdin@3619 | 436 | jint result = env->RegisterNatives(wbclass, methods, sizeof(methods)/sizeof(methods[0])); |
mgerdin@3619 | 437 | if (result == 0) { |
mgerdin@3619 | 438 | WhiteBox::set_used(); |
mgerdin@3619 | 439 | } |
mgerdin@3619 | 440 | } |
mgerdin@3619 | 441 | } |
mgerdin@3619 | 442 | } |
mgerdin@3619 | 443 | JVM_END |