Mon, 18 Mar 2013 13:19:06 +0100
8008555: Debugging code in compiled method sometimes leaks memory
Summary: support for strings that have same life-time as code that uses them.
Reviewed-by: kvn, twisti
duke@435 | 1 | /* |
mikael@4153 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_RUNTIME_INTERFACESUPPORT_HPP |
stefank@2314 | 26 | #define SHARE_VM_RUNTIME_INTERFACESUPPORT_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "memory/gcLocker.hpp" |
stefank@2314 | 29 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 30 | #include "runtime/mutexLocker.hpp" |
stefank@2314 | 31 | #include "runtime/orderAccess.hpp" |
stefank@2314 | 32 | #include "runtime/os.hpp" |
stefank@2314 | 33 | #include "runtime/safepoint.hpp" |
stefank@4299 | 34 | #include "runtime/thread.inline.hpp" |
stefank@2314 | 35 | #include "runtime/vmThread.hpp" |
stefank@2314 | 36 | #include "utilities/globalDefinitions.hpp" |
stefank@2314 | 37 | #include "utilities/preserveException.hpp" |
stefank@2314 | 38 | #include "utilities/top.hpp" |
stefank@2314 | 39 | |
duke@435 | 40 | // Wrapper for all entry points to the virtual machine. |
duke@435 | 41 | // The HandleMarkCleaner is a faster version of HandleMark. |
duke@435 | 42 | // It relies on the fact that there is a HandleMark further |
duke@435 | 43 | // down the stack (in JavaCalls::call_helper), and just resets |
duke@435 | 44 | // to the saved values in that HandleMark. |
duke@435 | 45 | |
duke@435 | 46 | class HandleMarkCleaner: public StackObj { |
duke@435 | 47 | private: |
duke@435 | 48 | Thread* _thread; |
duke@435 | 49 | public: |
duke@435 | 50 | HandleMarkCleaner(Thread* thread) { |
duke@435 | 51 | _thread = thread; |
duke@435 | 52 | _thread->last_handle_mark()->push(); |
duke@435 | 53 | } |
duke@435 | 54 | ~HandleMarkCleaner() { |
duke@435 | 55 | _thread->last_handle_mark()->pop_and_restore(); |
duke@435 | 56 | } |
duke@435 | 57 | |
duke@435 | 58 | private: |
duke@435 | 59 | inline void* operator new(size_t size, void* ptr) { |
duke@435 | 60 | return ptr; |
duke@435 | 61 | } |
duke@435 | 62 | }; |
duke@435 | 63 | |
never@3241 | 64 | // InterfaceSupport provides functionality used by the VM_LEAF_BASE and |
never@3241 | 65 | // VM_ENTRY_BASE macros. These macros are used to guard entry points into |
never@3241 | 66 | // the VM and perform checks upon leave of the VM. |
duke@435 | 67 | |
duke@435 | 68 | |
duke@435 | 69 | class InterfaceSupport: AllStatic { |
duke@435 | 70 | # ifdef ASSERT |
duke@435 | 71 | public: |
duke@435 | 72 | static long _scavenge_alot_counter; |
duke@435 | 73 | static long _fullgc_alot_counter; |
duke@435 | 74 | static long _number_of_calls; |
duke@435 | 75 | static long _fullgc_alot_invocation; |
duke@435 | 76 | |
duke@435 | 77 | // tracing |
duke@435 | 78 | static void trace(const char* result_type, const char* header); |
duke@435 | 79 | |
duke@435 | 80 | // Helper methods used to implement +ScavengeALot and +FullGCALot |
duke@435 | 81 | static void check_gc_alot() { if (ScavengeALot || FullGCALot) gc_alot(); } |
duke@435 | 82 | static void gc_alot(); |
duke@435 | 83 | |
duke@435 | 84 | static void walk_stack_from(vframe* start_vf); |
duke@435 | 85 | static void walk_stack(); |
duke@435 | 86 | |
duke@435 | 87 | # ifdef ENABLE_ZAP_DEAD_LOCALS |
duke@435 | 88 | static void zap_dead_locals_old(); |
duke@435 | 89 | # endif |
duke@435 | 90 | |
duke@435 | 91 | static void zombieAll(); |
coleenp@2497 | 92 | static void unlinkSymbols(); |
duke@435 | 93 | static void deoptimizeAll(); |
duke@435 | 94 | static void stress_derived_pointers(); |
duke@435 | 95 | static void verify_stack(); |
duke@435 | 96 | static void verify_last_frame(); |
duke@435 | 97 | # endif |
duke@435 | 98 | |
duke@435 | 99 | public: |
duke@435 | 100 | // OS dependent stuff |
stefank@2314 | 101 | #ifdef TARGET_OS_FAMILY_linux |
stefank@2314 | 102 | # include "interfaceSupport_linux.hpp" |
stefank@2314 | 103 | #endif |
stefank@2314 | 104 | #ifdef TARGET_OS_FAMILY_solaris |
stefank@2314 | 105 | # include "interfaceSupport_solaris.hpp" |
stefank@2314 | 106 | #endif |
stefank@2314 | 107 | #ifdef TARGET_OS_FAMILY_windows |
stefank@2314 | 108 | # include "interfaceSupport_windows.hpp" |
stefank@2314 | 109 | #endif |
never@3156 | 110 | #ifdef TARGET_OS_FAMILY_bsd |
never@3156 | 111 | # include "interfaceSupport_bsd.hpp" |
never@3156 | 112 | #endif |
stefank@2314 | 113 | |
duke@435 | 114 | }; |
duke@435 | 115 | |
duke@435 | 116 | |
duke@435 | 117 | // Basic class for all thread transition classes. |
duke@435 | 118 | |
duke@435 | 119 | class ThreadStateTransition : public StackObj { |
duke@435 | 120 | protected: |
duke@435 | 121 | JavaThread* _thread; |
duke@435 | 122 | public: |
duke@435 | 123 | ThreadStateTransition(JavaThread *thread) { |
duke@435 | 124 | _thread = thread; |
duke@435 | 125 | assert(thread != NULL && thread->is_Java_thread(), "must be Java thread"); |
duke@435 | 126 | } |
duke@435 | 127 | |
duke@435 | 128 | // Change threadstate in a manner, so safepoint can detect changes. |
duke@435 | 129 | // Time-critical: called on exit from every runtime routine |
duke@435 | 130 | static inline void transition(JavaThread *thread, JavaThreadState from, JavaThreadState to) { |
duke@435 | 131 | assert(from != _thread_in_Java, "use transition_from_java"); |
duke@435 | 132 | assert(from != _thread_in_native, "use transition_from_native"); |
duke@435 | 133 | assert((from & 1) == 0 && (to & 1) == 0, "odd numbers are transitions states"); |
duke@435 | 134 | assert(thread->thread_state() == from, "coming from wrong thread state"); |
duke@435 | 135 | // Change to transition state (assumes total store ordering! -Urs) |
duke@435 | 136 | thread->set_thread_state((JavaThreadState)(from + 1)); |
duke@435 | 137 | |
duke@435 | 138 | // Make sure new state is seen by VM thread |
duke@435 | 139 | if (os::is_MP()) { |
duke@435 | 140 | if (UseMembar) { |
duke@435 | 141 | // Force a fence between the write above and read below |
duke@435 | 142 | OrderAccess::fence(); |
duke@435 | 143 | } else { |
duke@435 | 144 | // store to serialize page so VM thread can do pseudo remote membar |
duke@435 | 145 | os::write_memory_serialize_page(thread); |
duke@435 | 146 | } |
duke@435 | 147 | } |
duke@435 | 148 | |
duke@435 | 149 | if (SafepointSynchronize::do_call_back()) { |
duke@435 | 150 | SafepointSynchronize::block(thread); |
duke@435 | 151 | } |
duke@435 | 152 | thread->set_thread_state(to); |
duke@435 | 153 | |
duke@435 | 154 | CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();) |
duke@435 | 155 | } |
duke@435 | 156 | |
duke@435 | 157 | // transition_and_fence must be used on any thread state transition |
duke@435 | 158 | // where there might not be a Java call stub on the stack, in |
duke@435 | 159 | // particular on Windows where the Structured Exception Handler is |
duke@435 | 160 | // set up in the call stub. os::write_memory_serialize_page() can |
duke@435 | 161 | // fault and we can't recover from it on Windows without a SEH in |
duke@435 | 162 | // place. |
duke@435 | 163 | static inline void transition_and_fence(JavaThread *thread, JavaThreadState from, JavaThreadState to) { |
duke@435 | 164 | assert(thread->thread_state() == from, "coming from wrong thread state"); |
duke@435 | 165 | assert((from & 1) == 0 && (to & 1) == 0, "odd numbers are transitions states"); |
duke@435 | 166 | // Change to transition state (assumes total store ordering! -Urs) |
duke@435 | 167 | thread->set_thread_state((JavaThreadState)(from + 1)); |
duke@435 | 168 | |
duke@435 | 169 | // Make sure new state is seen by VM thread |
duke@435 | 170 | if (os::is_MP()) { |
duke@435 | 171 | if (UseMembar) { |
duke@435 | 172 | // Force a fence between the write above and read below |
duke@435 | 173 | OrderAccess::fence(); |
duke@435 | 174 | } else { |
duke@435 | 175 | // Must use this rather than serialization page in particular on Windows |
duke@435 | 176 | InterfaceSupport::serialize_memory(thread); |
duke@435 | 177 | } |
duke@435 | 178 | } |
duke@435 | 179 | |
duke@435 | 180 | if (SafepointSynchronize::do_call_back()) { |
duke@435 | 181 | SafepointSynchronize::block(thread); |
duke@435 | 182 | } |
duke@435 | 183 | thread->set_thread_state(to); |
duke@435 | 184 | |
duke@435 | 185 | CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();) |
duke@435 | 186 | } |
duke@435 | 187 | |
duke@435 | 188 | // Same as above, but assumes from = _thread_in_Java. This is simpler, since we |
duke@435 | 189 | // never block on entry to the VM. This will break the code, since e.g. preserve arguments |
duke@435 | 190 | // have not been setup. |
duke@435 | 191 | static inline void transition_from_java(JavaThread *thread, JavaThreadState to) { |
duke@435 | 192 | assert(thread->thread_state() == _thread_in_Java, "coming from wrong thread state"); |
duke@435 | 193 | thread->set_thread_state(to); |
duke@435 | 194 | } |
duke@435 | 195 | |
duke@435 | 196 | static inline void transition_from_native(JavaThread *thread, JavaThreadState to) { |
duke@435 | 197 | assert((to & 1) == 0, "odd numbers are transitions states"); |
duke@435 | 198 | assert(thread->thread_state() == _thread_in_native, "coming from wrong thread state"); |
duke@435 | 199 | // Change to transition state (assumes total store ordering! -Urs) |
duke@435 | 200 | thread->set_thread_state(_thread_in_native_trans); |
duke@435 | 201 | |
duke@435 | 202 | // Make sure new state is seen by GC thread |
duke@435 | 203 | if (os::is_MP()) { |
duke@435 | 204 | if (UseMembar) { |
duke@435 | 205 | // Force a fence between the write above and read below |
duke@435 | 206 | OrderAccess::fence(); |
duke@435 | 207 | } else { |
duke@435 | 208 | // Must use this rather than serialization page in particular on Windows |
duke@435 | 209 | InterfaceSupport::serialize_memory(thread); |
duke@435 | 210 | } |
duke@435 | 211 | } |
duke@435 | 212 | |
duke@435 | 213 | // We never install asynchronous exceptions when coming (back) in |
duke@435 | 214 | // to the runtime from native code because the runtime is not set |
duke@435 | 215 | // up to handle exceptions floating around at arbitrary points. |
duke@435 | 216 | if (SafepointSynchronize::do_call_back() || thread->is_suspend_after_native()) { |
duke@435 | 217 | JavaThread::check_safepoint_and_suspend_for_native_trans(thread); |
duke@435 | 218 | |
duke@435 | 219 | // Clear unhandled oops anywhere where we could block, even if we don't. |
duke@435 | 220 | CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();) |
duke@435 | 221 | } |
duke@435 | 222 | |
duke@435 | 223 | thread->set_thread_state(to); |
duke@435 | 224 | } |
duke@435 | 225 | protected: |
duke@435 | 226 | void trans(JavaThreadState from, JavaThreadState to) { transition(_thread, from, to); } |
duke@435 | 227 | void trans_from_java(JavaThreadState to) { transition_from_java(_thread, to); } |
duke@435 | 228 | void trans_from_native(JavaThreadState to) { transition_from_native(_thread, to); } |
duke@435 | 229 | void trans_and_fence(JavaThreadState from, JavaThreadState to) { transition_and_fence(_thread, from, to); } |
duke@435 | 230 | }; |
duke@435 | 231 | |
duke@435 | 232 | |
duke@435 | 233 | class ThreadInVMfromJava : public ThreadStateTransition { |
duke@435 | 234 | public: |
duke@435 | 235 | ThreadInVMfromJava(JavaThread* thread) : ThreadStateTransition(thread) { |
duke@435 | 236 | trans_from_java(_thread_in_vm); |
duke@435 | 237 | } |
duke@435 | 238 | ~ThreadInVMfromJava() { |
duke@435 | 239 | trans(_thread_in_vm, _thread_in_Java); |
duke@435 | 240 | // Check for pending. async. exceptions or suspends. |
duke@435 | 241 | if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition(); |
duke@435 | 242 | } |
duke@435 | 243 | }; |
duke@435 | 244 | |
duke@435 | 245 | |
duke@435 | 246 | class ThreadInVMfromUnknown { |
duke@435 | 247 | private: |
duke@435 | 248 | JavaThread* _thread; |
duke@435 | 249 | public: |
duke@435 | 250 | ThreadInVMfromUnknown() : _thread(NULL) { |
duke@435 | 251 | Thread* t = Thread::current(); |
duke@435 | 252 | if (t->is_Java_thread()) { |
duke@435 | 253 | JavaThread* t2 = (JavaThread*) t; |
duke@435 | 254 | if (t2->thread_state() == _thread_in_native) { |
duke@435 | 255 | _thread = t2; |
duke@435 | 256 | ThreadStateTransition::transition_from_native(t2, _thread_in_vm); |
duke@435 | 257 | // Used to have a HandleMarkCleaner but that is dangerous as |
duke@435 | 258 | // it could free a handle in our (indirect, nested) caller. |
duke@435 | 259 | // We expect any handles will be short lived and figure we |
duke@435 | 260 | // don't need an actual HandleMark. |
duke@435 | 261 | } |
duke@435 | 262 | } |
duke@435 | 263 | } |
duke@435 | 264 | ~ThreadInVMfromUnknown() { |
duke@435 | 265 | if (_thread) { |
duke@435 | 266 | ThreadStateTransition::transition_and_fence(_thread, _thread_in_vm, _thread_in_native); |
duke@435 | 267 | } |
duke@435 | 268 | } |
duke@435 | 269 | }; |
duke@435 | 270 | |
duke@435 | 271 | |
duke@435 | 272 | class ThreadInVMfromNative : public ThreadStateTransition { |
duke@435 | 273 | public: |
duke@435 | 274 | ThreadInVMfromNative(JavaThread* thread) : ThreadStateTransition(thread) { |
duke@435 | 275 | trans_from_native(_thread_in_vm); |
duke@435 | 276 | } |
duke@435 | 277 | ~ThreadInVMfromNative() { |
duke@435 | 278 | trans_and_fence(_thread_in_vm, _thread_in_native); |
duke@435 | 279 | } |
duke@435 | 280 | }; |
duke@435 | 281 | |
duke@435 | 282 | |
duke@435 | 283 | class ThreadToNativeFromVM : public ThreadStateTransition { |
duke@435 | 284 | public: |
duke@435 | 285 | ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) { |
duke@435 | 286 | // We are leaving the VM at this point and going directly to native code. |
duke@435 | 287 | // Block, if we are in the middle of a safepoint synchronization. |
duke@435 | 288 | assert(!thread->owns_locks(), "must release all locks when leaving VM"); |
duke@435 | 289 | thread->frame_anchor()->make_walkable(thread); |
duke@435 | 290 | trans_and_fence(_thread_in_vm, _thread_in_native); |
duke@435 | 291 | // Check for pending. async. exceptions or suspends. |
duke@435 | 292 | if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition(false); |
duke@435 | 293 | } |
duke@435 | 294 | |
duke@435 | 295 | ~ThreadToNativeFromVM() { |
duke@435 | 296 | trans_from_native(_thread_in_vm); |
duke@435 | 297 | // We don't need to clear_walkable because it will happen automagically when we return to java |
duke@435 | 298 | } |
duke@435 | 299 | }; |
duke@435 | 300 | |
duke@435 | 301 | |
duke@435 | 302 | class ThreadBlockInVM : public ThreadStateTransition { |
duke@435 | 303 | public: |
duke@435 | 304 | ThreadBlockInVM(JavaThread *thread) |
duke@435 | 305 | : ThreadStateTransition(thread) { |
duke@435 | 306 | // Once we are blocked vm expects stack to be walkable |
duke@435 | 307 | thread->frame_anchor()->make_walkable(thread); |
duke@435 | 308 | trans_and_fence(_thread_in_vm, _thread_blocked); |
duke@435 | 309 | } |
duke@435 | 310 | ~ThreadBlockInVM() { |
duke@435 | 311 | trans_and_fence(_thread_blocked, _thread_in_vm); |
duke@435 | 312 | // We don't need to clear_walkable because it will happen automagically when we return to java |
duke@435 | 313 | } |
duke@435 | 314 | }; |
duke@435 | 315 | |
duke@435 | 316 | |
duke@435 | 317 | // This special transition class is only used to prevent asynchronous exceptions |
duke@435 | 318 | // from being installed on vm exit in situations where we can't tolerate them. |
duke@435 | 319 | // See bugs: 4324348, 4854693, 4998314, 5040492, 5050705. |
duke@435 | 320 | class ThreadInVMfromJavaNoAsyncException : public ThreadStateTransition { |
duke@435 | 321 | public: |
duke@435 | 322 | ThreadInVMfromJavaNoAsyncException(JavaThread* thread) : ThreadStateTransition(thread) { |
duke@435 | 323 | trans_from_java(_thread_in_vm); |
duke@435 | 324 | } |
duke@435 | 325 | ~ThreadInVMfromJavaNoAsyncException() { |
duke@435 | 326 | trans(_thread_in_vm, _thread_in_Java); |
duke@435 | 327 | // NOTE: We do not check for pending. async. exceptions. |
duke@435 | 328 | // If we did and moved the pending async exception over into the |
duke@435 | 329 | // pending exception field, we would need to deopt (currently C2 |
duke@435 | 330 | // only). However, to do so would require that we transition back |
duke@435 | 331 | // to the _thread_in_vm state. Instead we postpone the handling of |
duke@435 | 332 | // the async exception. |
duke@435 | 333 | |
duke@435 | 334 | // Check for pending. suspends only. |
duke@435 | 335 | if (_thread->has_special_runtime_exit_condition()) |
duke@435 | 336 | _thread->handle_special_runtime_exit_condition(false); |
duke@435 | 337 | } |
duke@435 | 338 | }; |
duke@435 | 339 | |
duke@435 | 340 | // Debug class instantiated in JRT_ENTRY and ITR_ENTRY macro. |
duke@435 | 341 | // Can be used to verify properties on enter/exit of the VM. |
duke@435 | 342 | |
duke@435 | 343 | #ifdef ASSERT |
duke@435 | 344 | class VMEntryWrapper { |
duke@435 | 345 | public: |
duke@435 | 346 | VMEntryWrapper() { |
duke@435 | 347 | if (VerifyLastFrame) { |
duke@435 | 348 | InterfaceSupport::verify_last_frame(); |
duke@435 | 349 | } |
duke@435 | 350 | } |
duke@435 | 351 | |
duke@435 | 352 | ~VMEntryWrapper() { |
duke@435 | 353 | InterfaceSupport::check_gc_alot(); |
duke@435 | 354 | if (WalkStackALot) { |
duke@435 | 355 | InterfaceSupport::walk_stack(); |
duke@435 | 356 | } |
duke@435 | 357 | #ifdef ENABLE_ZAP_DEAD_LOCALS |
duke@435 | 358 | if (ZapDeadLocalsOld) { |
duke@435 | 359 | InterfaceSupport::zap_dead_locals_old(); |
duke@435 | 360 | } |
duke@435 | 361 | #endif |
duke@435 | 362 | #ifdef COMPILER2 |
duke@435 | 363 | // This option is not used by Compiler 1 |
duke@435 | 364 | if (StressDerivedPointers) { |
duke@435 | 365 | InterfaceSupport::stress_derived_pointers(); |
duke@435 | 366 | } |
duke@435 | 367 | #endif |
duke@435 | 368 | if (DeoptimizeALot || DeoptimizeRandom) { |
duke@435 | 369 | InterfaceSupport::deoptimizeAll(); |
duke@435 | 370 | } |
duke@435 | 371 | if (ZombieALot) { |
duke@435 | 372 | InterfaceSupport::zombieAll(); |
duke@435 | 373 | } |
coleenp@2497 | 374 | if (UnlinkSymbolsALot) { |
coleenp@2497 | 375 | InterfaceSupport::unlinkSymbols(); |
coleenp@2497 | 376 | } |
duke@435 | 377 | // do verification AFTER potential deoptimization |
duke@435 | 378 | if (VerifyStack) { |
duke@435 | 379 | InterfaceSupport::verify_stack(); |
duke@435 | 380 | } |
duke@435 | 381 | |
duke@435 | 382 | } |
duke@435 | 383 | }; |
duke@435 | 384 | |
duke@435 | 385 | |
duke@435 | 386 | class VMNativeEntryWrapper { |
duke@435 | 387 | public: |
duke@435 | 388 | VMNativeEntryWrapper() { |
duke@435 | 389 | if (GCALotAtAllSafepoints) InterfaceSupport::check_gc_alot(); |
duke@435 | 390 | } |
duke@435 | 391 | |
duke@435 | 392 | ~VMNativeEntryWrapper() { |
duke@435 | 393 | if (GCALotAtAllSafepoints) InterfaceSupport::check_gc_alot(); |
duke@435 | 394 | } |
duke@435 | 395 | }; |
duke@435 | 396 | |
duke@435 | 397 | #endif |
duke@435 | 398 | |
duke@435 | 399 | |
duke@435 | 400 | // VM-internal runtime interface support |
duke@435 | 401 | |
duke@435 | 402 | #ifdef ASSERT |
duke@435 | 403 | |
duke@435 | 404 | class RuntimeHistogramElement : public HistogramElement { |
duke@435 | 405 | public: |
duke@435 | 406 | RuntimeHistogramElement(const char* name); |
duke@435 | 407 | }; |
duke@435 | 408 | |
duke@435 | 409 | #define TRACE_CALL(result_type, header) \ |
duke@435 | 410 | InterfaceSupport::_number_of_calls++; \ |
duke@435 | 411 | if (TraceRuntimeCalls) \ |
duke@435 | 412 | InterfaceSupport::trace(#result_type, #header); \ |
duke@435 | 413 | if (CountRuntimeCalls) { \ |
duke@435 | 414 | static RuntimeHistogramElement* e = new RuntimeHistogramElement(#header); \ |
duke@435 | 415 | if (e != NULL) e->increment_count(); \ |
duke@435 | 416 | } |
duke@435 | 417 | #else |
duke@435 | 418 | #define TRACE_CALL(result_type, header) \ |
duke@435 | 419 | /* do nothing */ |
duke@435 | 420 | #endif |
duke@435 | 421 | |
duke@435 | 422 | |
duke@435 | 423 | // LEAF routines do not lock, GC or throw exceptions |
duke@435 | 424 | |
never@3241 | 425 | #define VM_LEAF_BASE(result_type, header) \ |
duke@435 | 426 | TRACE_CALL(result_type, header) \ |
duke@435 | 427 | debug_only(NoHandleMark __hm;) \ |
roland@3606 | 428 | os::verify_stack_alignment(); \ |
duke@435 | 429 | /* begin of body */ |
duke@435 | 430 | |
duke@435 | 431 | |
duke@435 | 432 | // ENTRY routines may lock, GC and throw exceptions |
duke@435 | 433 | |
never@3241 | 434 | #define VM_ENTRY_BASE(result_type, header, thread) \ |
duke@435 | 435 | TRACE_CALL(result_type, header) \ |
duke@435 | 436 | HandleMarkCleaner __hm(thread); \ |
duke@435 | 437 | Thread* THREAD = thread; \ |
roland@3606 | 438 | os::verify_stack_alignment(); \ |
duke@435 | 439 | /* begin of body */ |
duke@435 | 440 | |
duke@435 | 441 | |
duke@435 | 442 | // QUICK_ENTRY routines behave like ENTRY but without a handle mark |
duke@435 | 443 | |
never@3241 | 444 | #define VM_QUICK_ENTRY_BASE(result_type, header, thread) \ |
duke@435 | 445 | TRACE_CALL(result_type, header) \ |
duke@435 | 446 | debug_only(NoHandleMark __hm;) \ |
duke@435 | 447 | Thread* THREAD = thread; \ |
roland@3606 | 448 | os::verify_stack_alignment(); \ |
duke@435 | 449 | /* begin of body */ |
duke@435 | 450 | |
duke@435 | 451 | |
duke@435 | 452 | // Definitions for IRT (Interpreter Runtime) |
duke@435 | 453 | // (thread is an argument passed in to all these routines) |
duke@435 | 454 | |
duke@435 | 455 | #define IRT_ENTRY(result_type, header) \ |
duke@435 | 456 | result_type header { \ |
duke@435 | 457 | ThreadInVMfromJava __tiv(thread); \ |
never@3241 | 458 | VM_ENTRY_BASE(result_type, header, thread) \ |
duke@435 | 459 | debug_only(VMEntryWrapper __vew;) |
duke@435 | 460 | |
duke@435 | 461 | |
duke@435 | 462 | #define IRT_LEAF(result_type, header) \ |
duke@435 | 463 | result_type header { \ |
never@3241 | 464 | VM_LEAF_BASE(result_type, header) \ |
duke@435 | 465 | debug_only(No_Safepoint_Verifier __nspv(true);) |
duke@435 | 466 | |
duke@435 | 467 | |
duke@435 | 468 | #define IRT_ENTRY_NO_ASYNC(result_type, header) \ |
duke@435 | 469 | result_type header { \ |
duke@435 | 470 | ThreadInVMfromJavaNoAsyncException __tiv(thread); \ |
never@3241 | 471 | VM_ENTRY_BASE(result_type, header, thread) \ |
duke@435 | 472 | debug_only(VMEntryWrapper __vew;) |
duke@435 | 473 | |
duke@435 | 474 | // Another special case for nmethod_entry_point so the nmethod that the |
duke@435 | 475 | // interpreter is about to branch to doesn't get flushed before as we |
duke@435 | 476 | // branch to it's interpreter_entry_point. Skip stress testing here too. |
duke@435 | 477 | // Also we don't allow async exceptions because it is just too painful. |
duke@435 | 478 | #define IRT_ENTRY_FOR_NMETHOD(result_type, header) \ |
duke@435 | 479 | result_type header { \ |
duke@435 | 480 | nmethodLocker _nmlock(nm); \ |
duke@435 | 481 | ThreadInVMfromJavaNoAsyncException __tiv(thread); \ |
never@3241 | 482 | VM_ENTRY_BASE(result_type, header, thread) |
duke@435 | 483 | |
duke@435 | 484 | #define IRT_END } |
duke@435 | 485 | |
duke@435 | 486 | |
duke@435 | 487 | // Definitions for JRT (Java (Compiler/Shared) Runtime) |
duke@435 | 488 | |
duke@435 | 489 | #define JRT_ENTRY(result_type, header) \ |
duke@435 | 490 | result_type header { \ |
duke@435 | 491 | ThreadInVMfromJava __tiv(thread); \ |
never@3241 | 492 | VM_ENTRY_BASE(result_type, header, thread) \ |
duke@435 | 493 | debug_only(VMEntryWrapper __vew;) |
duke@435 | 494 | |
duke@435 | 495 | |
duke@435 | 496 | #define JRT_LEAF(result_type, header) \ |
duke@435 | 497 | result_type header { \ |
never@3241 | 498 | VM_LEAF_BASE(result_type, header) \ |
duke@435 | 499 | debug_only(JRT_Leaf_Verifier __jlv;) |
duke@435 | 500 | |
duke@435 | 501 | |
duke@435 | 502 | #define JRT_ENTRY_NO_ASYNC(result_type, header) \ |
duke@435 | 503 | result_type header { \ |
duke@435 | 504 | ThreadInVMfromJavaNoAsyncException __tiv(thread); \ |
never@3241 | 505 | VM_ENTRY_BASE(result_type, header, thread) \ |
duke@435 | 506 | debug_only(VMEntryWrapper __vew;) |
duke@435 | 507 | |
duke@435 | 508 | // Same as JRT Entry but allows for return value after the safepoint |
duke@435 | 509 | // to get back into Java from the VM |
duke@435 | 510 | #define JRT_BLOCK_ENTRY(result_type, header) \ |
duke@435 | 511 | result_type header { \ |
duke@435 | 512 | TRACE_CALL(result_type, header) \ |
duke@435 | 513 | HandleMarkCleaner __hm(thread); |
duke@435 | 514 | |
duke@435 | 515 | #define JRT_BLOCK \ |
duke@435 | 516 | { \ |
duke@435 | 517 | ThreadInVMfromJava __tiv(thread); \ |
duke@435 | 518 | Thread* THREAD = thread; \ |
duke@435 | 519 | debug_only(VMEntryWrapper __vew;) |
duke@435 | 520 | |
duke@435 | 521 | #define JRT_BLOCK_END } |
duke@435 | 522 | |
duke@435 | 523 | #define JRT_END } |
duke@435 | 524 | |
duke@435 | 525 | // Definitions for JNI |
duke@435 | 526 | |
duke@435 | 527 | #define JNI_ENTRY(result_type, header) \ |
duke@435 | 528 | JNI_ENTRY_NO_PRESERVE(result_type, header) \ |
duke@435 | 529 | WeakPreserveExceptionMark __wem(thread); |
duke@435 | 530 | |
duke@435 | 531 | #define JNI_ENTRY_NO_PRESERVE(result_type, header) \ |
duke@435 | 532 | extern "C" { \ |
duke@435 | 533 | result_type JNICALL header { \ |
duke@435 | 534 | JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
duke@435 | 535 | assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \ |
duke@435 | 536 | ThreadInVMfromNative __tiv(thread); \ |
duke@435 | 537 | debug_only(VMNativeEntryWrapper __vew;) \ |
never@3241 | 538 | VM_ENTRY_BASE(result_type, header, thread) |
duke@435 | 539 | |
duke@435 | 540 | |
duke@435 | 541 | // Ensure that the VMNativeEntryWrapper constructor, which can cause |
never@3241 | 542 | // a GC, is called outside the NoHandleMark (set via VM_QUICK_ENTRY_BASE). |
duke@435 | 543 | #define JNI_QUICK_ENTRY(result_type, header) \ |
duke@435 | 544 | extern "C" { \ |
duke@435 | 545 | result_type JNICALL header { \ |
duke@435 | 546 | JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
duke@435 | 547 | assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \ |
duke@435 | 548 | ThreadInVMfromNative __tiv(thread); \ |
duke@435 | 549 | debug_only(VMNativeEntryWrapper __vew;) \ |
never@3241 | 550 | VM_QUICK_ENTRY_BASE(result_type, header, thread) |
duke@435 | 551 | |
duke@435 | 552 | |
duke@435 | 553 | #define JNI_LEAF(result_type, header) \ |
duke@435 | 554 | extern "C" { \ |
duke@435 | 555 | result_type JNICALL header { \ |
duke@435 | 556 | JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
duke@435 | 557 | assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \ |
never@3241 | 558 | VM_LEAF_BASE(result_type, header) |
duke@435 | 559 | |
duke@435 | 560 | |
duke@435 | 561 | // Close the routine and the extern "C" |
duke@435 | 562 | #define JNI_END } } |
duke@435 | 563 | |
duke@435 | 564 | |
duke@435 | 565 | |
duke@435 | 566 | // Definitions for JVM |
duke@435 | 567 | |
duke@435 | 568 | #define JVM_ENTRY(result_type, header) \ |
duke@435 | 569 | extern "C" { \ |
duke@435 | 570 | result_type JNICALL header { \ |
duke@435 | 571 | JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
duke@435 | 572 | ThreadInVMfromNative __tiv(thread); \ |
duke@435 | 573 | debug_only(VMNativeEntryWrapper __vew;) \ |
never@3241 | 574 | VM_ENTRY_BASE(result_type, header, thread) |
duke@435 | 575 | |
duke@435 | 576 | |
duke@435 | 577 | #define JVM_ENTRY_NO_ENV(result_type, header) \ |
duke@435 | 578 | extern "C" { \ |
duke@435 | 579 | result_type JNICALL header { \ |
duke@435 | 580 | JavaThread* thread = (JavaThread*)ThreadLocalStorage::thread(); \ |
duke@435 | 581 | ThreadInVMfromNative __tiv(thread); \ |
duke@435 | 582 | debug_only(VMNativeEntryWrapper __vew;) \ |
never@3241 | 583 | VM_ENTRY_BASE(result_type, header, thread) |
duke@435 | 584 | |
duke@435 | 585 | |
duke@435 | 586 | #define JVM_QUICK_ENTRY(result_type, header) \ |
duke@435 | 587 | extern "C" { \ |
duke@435 | 588 | result_type JNICALL header { \ |
duke@435 | 589 | JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ |
duke@435 | 590 | ThreadInVMfromNative __tiv(thread); \ |
duke@435 | 591 | debug_only(VMNativeEntryWrapper __vew;) \ |
never@3241 | 592 | VM_QUICK_ENTRY_BASE(result_type, header, thread) |
duke@435 | 593 | |
duke@435 | 594 | |
duke@435 | 595 | #define JVM_LEAF(result_type, header) \ |
duke@435 | 596 | extern "C" { \ |
duke@435 | 597 | result_type JNICALL header { \ |
duke@435 | 598 | VM_Exit::block_if_vm_exited(); \ |
never@3241 | 599 | VM_LEAF_BASE(result_type, header) |
duke@435 | 600 | |
duke@435 | 601 | |
duke@435 | 602 | #define JVM_END } } |
stefank@2314 | 603 | |
stefank@2314 | 604 | #endif // SHARE_VM_RUNTIME_INTERFACESUPPORT_HPP |