Mon, 19 Aug 2013 14:59:54 -0400
8021948: Change InstanceKlass::_source_file_name and _generic_signature from Symbol* to constant pool indexes.
Summary: Change InstanceKlass::_source_file_name and _generic_signature to u2 fields.
Reviewed-by: coleenp, iklam
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 | |
ctornqvi@4512 | 131 | #ifdef 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 | |
ctornqvi@4512 | 184 | #endif // INCLUDE_NMT |
ctornqvi@4512 | 185 | |
iignatyev@4592 | 186 | static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) { |
iignatyev@4592 | 187 | assert(method != NULL, "method should not be null"); |
iignatyev@4592 | 188 | ThreadToNativeFromVM ttn(thread); |
iignatyev@4592 | 189 | return env->FromReflectedMethod(method); |
iignatyev@4592 | 190 | } |
iignatyev@4592 | 191 | |
iignatyev@4592 | 192 | WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o)) |
iignatyev@4592 | 193 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 194 | CodeCache::mark_all_nmethods_for_deoptimization(); |
iignatyev@4592 | 195 | VM_Deoptimize op; |
iignatyev@4592 | 196 | VMThread::execute(&op); |
iignatyev@4592 | 197 | WB_END |
iignatyev@4592 | 198 | |
iignatyev@4592 | 199 | WB_ENTRY(jint, WB_DeoptimizeMethod(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4592 | 200 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 201 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 202 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 203 | int result = 0; |
iignatyev@4592 | 204 | nmethod* code = mh->code(); |
iignatyev@4592 | 205 | if (code != NULL) { |
iignatyev@4592 | 206 | code->mark_for_deoptimization(); |
iignatyev@4592 | 207 | ++result; |
iignatyev@4592 | 208 | } |
iignatyev@4592 | 209 | result += CodeCache::mark_for_deoptimization(mh()); |
iignatyev@4592 | 210 | if (result > 0) { |
iignatyev@4592 | 211 | VM_Deoptimize op; |
iignatyev@4592 | 212 | VMThread::execute(&op); |
iignatyev@4592 | 213 | } |
iignatyev@4592 | 214 | return result; |
iignatyev@4592 | 215 | WB_END |
iignatyev@4592 | 216 | |
iignatyev@4592 | 217 | WB_ENTRY(jboolean, WB_IsMethodCompiled(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4592 | 218 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 219 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 220 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 221 | nmethod* code = mh->code(); |
iignatyev@4592 | 222 | if (code == NULL) { |
iignatyev@4592 | 223 | return JNI_FALSE; |
iignatyev@4592 | 224 | } |
iignatyev@4592 | 225 | return (code->is_alive() && !code->is_marked_for_deoptimization()); |
iignatyev@4592 | 226 | WB_END |
iignatyev@4592 | 227 | |
iignatyev@4908 | 228 | WB_ENTRY(jboolean, WB_IsMethodCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level)) |
iignatyev@4592 | 229 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 230 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 231 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 232 | return CompilationPolicy::can_be_compiled(mh, comp_level); |
iignatyev@4592 | 233 | WB_END |
iignatyev@4592 | 234 | |
iignatyev@4592 | 235 | WB_ENTRY(jboolean, WB_IsMethodQueuedForCompilation(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4592 | 236 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 237 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 238 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 239 | return mh->queued_for_compilation(); |
iignatyev@4592 | 240 | WB_END |
iignatyev@4592 | 241 | |
iignatyev@4592 | 242 | WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4592 | 243 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 244 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 245 | nmethod* code = mh->code(); |
iignatyev@4592 | 246 | return (code != NULL ? code->comp_level() : CompLevel_none); |
iignatyev@4592 | 247 | WB_END |
iignatyev@4592 | 248 | |
iignatyev@4592 | 249 | |
iignatyev@4951 | 250 | WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level)) |
iignatyev@4592 | 251 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 252 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4951 | 253 | mh->set_not_compilable(comp_level, true /* report */, "WhiteBox"); |
iignatyev@4592 | 254 | WB_END |
iignatyev@4592 | 255 | |
iignatyev@4908 | 256 | WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) |
iignatyev@4592 | 257 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4592 | 258 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 259 | bool result = mh->dont_inline(); |
iignatyev@4592 | 260 | mh->set_dont_inline(value == JNI_TRUE); |
iignatyev@4592 | 261 | return result; |
iignatyev@4592 | 262 | WB_END |
iignatyev@4592 | 263 | |
iignatyev@4592 | 264 | WB_ENTRY(jint, WB_GetCompileQueuesSize(JNIEnv* env, jobject o)) |
iignatyev@4592 | 265 | return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ + |
iignatyev@4592 | 266 | CompileBroker::queue_size(CompLevel_full_profile) /* C1 */; |
iignatyev@4592 | 267 | WB_END |
iignatyev@4592 | 268 | |
iignatyev@4908 | 269 | |
iignatyev@4908 | 270 | WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) |
iignatyev@4908 | 271 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4908 | 272 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 273 | bool result = mh->force_inline(); |
iignatyev@4908 | 274 | mh->set_force_inline(value == JNI_TRUE); |
iignatyev@4908 | 275 | return result; |
iignatyev@4908 | 276 | WB_END |
iignatyev@4908 | 277 | |
iignatyev@4908 | 278 | WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level)) |
iignatyev@4908 | 279 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4908 | 280 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 281 | nmethod* nm = CompileBroker::compile_method(mh, InvocationEntryBci, comp_level, mh, mh->invocation_count(), "WhiteBox", THREAD); |
iignatyev@4908 | 282 | MutexLockerEx mu(Compile_lock); |
iignatyev@4908 | 283 | return (mh->queued_for_compilation() || nm != NULL); |
iignatyev@4908 | 284 | WB_END |
iignatyev@4908 | 285 | |
iignatyev@4908 | 286 | WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4908 | 287 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@4908 | 288 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 289 | MutexLockerEx mu(Compile_lock); |
iignatyev@4908 | 290 | MethodData* mdo = mh->method_data(); |
jiangli@4938 | 291 | MethodCounters* mcs = mh->method_counters(); |
iignatyev@4908 | 292 | |
iignatyev@4908 | 293 | if (mdo != NULL) { |
iignatyev@4908 | 294 | mdo->init(); |
iignatyev@4908 | 295 | ResourceMark rm; |
iignatyev@4908 | 296 | int arg_count = mdo->method()->size_of_parameters(); |
iignatyev@4908 | 297 | for (int i = 0; i < arg_count; i++) { |
iignatyev@4908 | 298 | mdo->set_arg_modified(i, 0); |
iignatyev@4908 | 299 | } |
iignatyev@4908 | 300 | } |
iignatyev@4908 | 301 | |
iignatyev@4908 | 302 | mh->clear_not_c1_compilable(); |
iignatyev@4908 | 303 | mh->clear_not_c2_compilable(); |
iignatyev@4908 | 304 | mh->clear_not_c2_osr_compilable(); |
iignatyev@4908 | 305 | NOT_PRODUCT(mh->set_compiled_invocation_count(0)); |
jiangli@4938 | 306 | if (mcs != NULL) { |
jiangli@4938 | 307 | mcs->backedge_counter()->init(); |
jiangli@4938 | 308 | mcs->invocation_counter()->init(); |
jiangli@4938 | 309 | mcs->set_interpreter_invocation_count(0); |
jiangli@4938 | 310 | mcs->set_interpreter_throwout_count(0); |
iignatyev@4908 | 311 | |
iignatyev@4908 | 312 | #ifdef TIERED |
jiangli@4938 | 313 | mcs->set_rate(0.0F); |
jiangli@4938 | 314 | mh->set_prev_event_count(0, THREAD); |
jiangli@4938 | 315 | mh->set_prev_time(0, THREAD); |
iignatyev@4908 | 316 | #endif |
jiangli@4938 | 317 | } |
iignatyev@4908 | 318 | WB_END |
iignatyev@4908 | 319 | |
mgerdin@4850 | 320 | WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) |
mgerdin@4850 | 321 | ResourceMark rm(THREAD); |
mgerdin@4850 | 322 | int len; |
hseigel@4987 | 323 | jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false); |
hseigel@4987 | 324 | return (StringTable::lookup(name, len) != NULL); |
mgerdin@4850 | 325 | WB_END |
mgerdin@4850 | 326 | |
mgerdin@4850 | 327 | |
mgerdin@4850 | 328 | WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) |
mgerdin@4850 | 329 | Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true); |
mgerdin@4850 | 330 | Universe::heap()->collect(GCCause::_last_ditch_collection); |
mgerdin@4850 | 331 | WB_END |
mgerdin@4850 | 332 | |
mikael@4989 | 333 | |
mikael@5174 | 334 | WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o)) |
mikael@5174 | 335 | // static+volatile in order to force the read to happen |
mikael@5174 | 336 | // (not be eliminated by the compiler) |
mikael@5174 | 337 | static char c; |
mikael@5174 | 338 | static volatile char* p; |
mikael@5174 | 339 | |
mikael@5174 | 340 | p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0); |
mikael@5174 | 341 | if (p == NULL) { |
mikael@5174 | 342 | THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory"); |
mikael@5174 | 343 | } |
mikael@5174 | 344 | |
mikael@5174 | 345 | c = *p; |
mikael@4989 | 346 | WB_END |
mikael@4989 | 347 | |
nloodin@3681 | 348 | //Some convenience methods to deal with objects from java |
nloodin@3681 | 349 | int WhiteBox::offset_for_field(const char* field_name, oop object, |
nloodin@3681 | 350 | Symbol* signature_symbol) { |
nloodin@3681 | 351 | assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid"); |
nloodin@3681 | 352 | Thread* THREAD = Thread::current(); |
nloodin@3681 | 353 | |
nloodin@3681 | 354 | //Get the class of our object |
coleenp@4037 | 355 | Klass* arg_klass = object->klass(); |
nloodin@3681 | 356 | //Turn it into an instance-klass |
coleenp@4037 | 357 | InstanceKlass* ik = InstanceKlass::cast(arg_klass); |
nloodin@3681 | 358 | |
nloodin@3681 | 359 | //Create symbols to look for in the class |
nloodin@3681 | 360 | TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name), |
nloodin@3681 | 361 | THREAD); |
nloodin@3681 | 362 | |
nloodin@3681 | 363 | //To be filled in with an offset of the field we're looking for |
nloodin@3681 | 364 | fieldDescriptor fd; |
nloodin@3681 | 365 | |
coleenp@4037 | 366 | Klass* res = ik->find_field(name_symbol, signature_symbol, &fd); |
nloodin@3681 | 367 | if (res == NULL) { |
nloodin@3681 | 368 | tty->print_cr("Invalid layout of %s at %s", ik->external_name(), |
nloodin@3681 | 369 | name_symbol->as_C_string()); |
nloodin@3681 | 370 | fatal("Invalid layout of preloaded class"); |
nloodin@3681 | 371 | } |
nloodin@3681 | 372 | |
nloodin@3681 | 373 | //fetch the field at the offset we've found |
nloodin@3681 | 374 | int dest_offset = fd.offset(); |
nloodin@3681 | 375 | |
nloodin@3681 | 376 | return dest_offset; |
nloodin@3681 | 377 | } |
nloodin@3681 | 378 | |
nloodin@3681 | 379 | |
nloodin@3681 | 380 | const char* WhiteBox::lookup_jstring(const char* field_name, oop object) { |
nloodin@3681 | 381 | int offset = offset_for_field(field_name, object, |
nloodin@3681 | 382 | vmSymbols::string_signature()); |
nloodin@3681 | 383 | oop string = object->obj_field(offset); |
sla@3905 | 384 | if (string == NULL) { |
sla@3905 | 385 | return NULL; |
sla@3905 | 386 | } |
nloodin@3681 | 387 | const char* ret = java_lang_String::as_utf8_string(string); |
nloodin@3681 | 388 | return ret; |
nloodin@3681 | 389 | } |
nloodin@3681 | 390 | |
nloodin@3681 | 391 | bool WhiteBox::lookup_bool(const char* field_name, oop object) { |
nloodin@3681 | 392 | int offset = |
nloodin@3681 | 393 | offset_for_field(field_name, object, vmSymbols::bool_signature()); |
nloodin@3681 | 394 | bool ret = (object->bool_field(offset) == JNI_TRUE); |
nloodin@3681 | 395 | return ret; |
nloodin@3681 | 396 | } |
nloodin@3681 | 397 | |
nloodin@3681 | 398 | |
mgerdin@3619 | 399 | #define CC (char*) |
mgerdin@3619 | 400 | |
mgerdin@3619 | 401 | static JNINativeMethod methods[] = { |
mgerdin@3619 | 402 | {CC"getObjectAddress", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress }, |
mgerdin@3619 | 403 | {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize }, |
iignatyev@4592 | 404 | {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive }, |
iignatyev@4592 | 405 | {CC"parseCommandLine", |
iignatyev@4592 | 406 | CC"(Ljava/lang/String;[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;", |
nloodin@3681 | 407 | (void*) &WB_ParseCommandLine |
nloodin@3681 | 408 | }, |
tschatzl@5073 | 409 | {CC"printHeapSizes", CC"()V", (void*)&WB_PrintHeapSizes }, |
jprovino@4542 | 410 | #if INCLUDE_ALL_GCS |
mgerdin@3619 | 411 | {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, |
mgerdin@3619 | 412 | {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, |
mgerdin@3619 | 413 | {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions }, |
mgerdin@3619 | 414 | {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize }, |
jprovino@4542 | 415 | #endif // INCLUDE_ALL_GCS |
ctornqvi@4512 | 416 | #ifdef INCLUDE_NMT |
ctornqvi@4885 | 417 | {CC"NMTMalloc", CC"(J)J", (void*)&WB_NMTMalloc }, |
ctornqvi@4885 | 418 | {CC"NMTFree", CC"(J)V", (void*)&WB_NMTFree }, |
ctornqvi@4885 | 419 | {CC"NMTReserveMemory", CC"(J)J", (void*)&WB_NMTReserveMemory }, |
ctornqvi@4885 | 420 | {CC"NMTCommitMemory", CC"(JJ)V", (void*)&WB_NMTCommitMemory }, |
ctornqvi@4885 | 421 | {CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory }, |
ctornqvi@4885 | 422 | {CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory }, |
ctornqvi@4885 | 423 | {CC"NMTWaitForDataMerge", CC"()Z", (void*)&WB_NMTWaitForDataMerge}, |
ctornqvi@4512 | 424 | #endif // INCLUDE_NMT |
iignatyev@4592 | 425 | {CC"deoptimizeAll", CC"()V", (void*)&WB_DeoptimizeAll }, |
iignatyev@4951 | 426 | {CC"deoptimizeMethod", CC"(Ljava/lang/reflect/Executable;)I", |
iignatyev@4592 | 427 | (void*)&WB_DeoptimizeMethod }, |
iignatyev@4951 | 428 | {CC"isMethodCompiled", CC"(Ljava/lang/reflect/Executable;)Z", |
iignatyev@4592 | 429 | (void*)&WB_IsMethodCompiled }, |
iignatyev@4951 | 430 | {CC"isMethodCompilable", CC"(Ljava/lang/reflect/Executable;I)Z", |
iignatyev@4592 | 431 | (void*)&WB_IsMethodCompilable}, |
iignatyev@4592 | 432 | {CC"isMethodQueuedForCompilation", |
iignatyev@4951 | 433 | CC"(Ljava/lang/reflect/Executable;)Z", (void*)&WB_IsMethodQueuedForCompilation}, |
iignatyev@4592 | 434 | {CC"makeMethodNotCompilable", |
iignatyev@4951 | 435 | CC"(Ljava/lang/reflect/Executable;I)V", (void*)&WB_MakeMethodNotCompilable}, |
iignatyev@4908 | 436 | {CC"testSetDontInlineMethod", |
iignatyev@4951 | 437 | CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod}, |
iignatyev@4592 | 438 | {CC"getMethodCompilationLevel", |
iignatyev@4951 | 439 | CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodCompilationLevel}, |
iignatyev@4592 | 440 | {CC"getCompileQueuesSize", |
iignatyev@4592 | 441 | CC"()I", (void*)&WB_GetCompileQueuesSize}, |
iignatyev@4908 | 442 | {CC"testSetForceInlineMethod", |
iignatyev@4951 | 443 | CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod}, |
iignatyev@4908 | 444 | {CC"enqueueMethodForCompilation", |
iignatyev@4951 | 445 | CC"(Ljava/lang/reflect/Executable;I)Z", (void*)&WB_EnqueueMethodForCompilation}, |
iignatyev@4908 | 446 | {CC"clearMethodState", |
iignatyev@4951 | 447 | CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState}, |
mgerdin@4850 | 448 | {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, |
mgerdin@4850 | 449 | {CC"fullGC", CC"()V", (void*)&WB_FullGC }, |
mikael@4989 | 450 | |
mikael@5174 | 451 | {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory }, |
mgerdin@3619 | 452 | }; |
mgerdin@3619 | 453 | |
mgerdin@3619 | 454 | #undef CC |
mgerdin@3619 | 455 | |
mgerdin@3619 | 456 | JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass)) |
mgerdin@3619 | 457 | { |
mgerdin@3619 | 458 | if (WhiteBoxAPI) { |
mgerdin@3619 | 459 | // Make sure that wbclass is loaded by the null classloader |
mgerdin@3619 | 460 | instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass()); |
mgerdin@3619 | 461 | Handle loader(ikh->class_loader()); |
mgerdin@3619 | 462 | if (loader.is_null()) { |
iignatyev@5028 | 463 | ResourceMark rm; |
mgerdin@3619 | 464 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@5028 | 465 | bool result = true; |
iignatyev@5028 | 466 | // one by one registration natives for exception catching |
iignatyev@5028 | 467 | jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); |
iignatyev@5028 | 468 | for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) { |
iignatyev@5028 | 469 | if (env->RegisterNatives(wbclass, methods + i, 1) != 0) { |
iignatyev@5028 | 470 | result = false; |
iignatyev@5028 | 471 | if (env->ExceptionCheck() && env->IsInstanceOf(env->ExceptionOccurred(), exceptionKlass)) { |
iignatyev@5028 | 472 | // j.l.NoSuchMethodError is thrown when a method can't be found or a method is not native |
iignatyev@5028 | 473 | // ignoring the exception |
iignatyev@5028 | 474 | tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", methods[i].name, methods[i].signature); |
iignatyev@5028 | 475 | env->ExceptionClear(); |
iignatyev@5028 | 476 | } else { |
iignatyev@5028 | 477 | // register is failed w/o exception or w/ unexpected exception |
iignatyev@5028 | 478 | 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 | 479 | env->UnregisterNatives(wbclass); |
iignatyev@5028 | 480 | break; |
iignatyev@5028 | 481 | } |
iignatyev@5028 | 482 | } |
iignatyev@5028 | 483 | } |
iignatyev@5028 | 484 | |
iignatyev@5028 | 485 | if (result) { |
mgerdin@3619 | 486 | WhiteBox::set_used(); |
mgerdin@3619 | 487 | } |
mgerdin@3619 | 488 | } |
mgerdin@3619 | 489 | } |
mgerdin@3619 | 490 | } |
mgerdin@3619 | 491 | JVM_END |