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