src/hotspot/share/runtime/interfaceSupport.inline.hpp
author coleenp
Wed, 14 Aug 2019 10:07:00 -0400
changeset 57745 789e967c2731
parent 57603 f9d9bed12d1a
child 57840 4863a802a7c1
permissions -rw-r--r--
5103339: Strengthen NoSafepointVerifier Summary: Add NSV check at possible safepoint transition or places that could take out locks. Consolidate with clearing unhandled oops. Reviewed-by: dholmes, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52877
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52877
diff changeset
    25
#ifndef SHARE_RUNTIME_INTERFACESUPPORT_INLINE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52877
diff changeset
    26
#define SHARE_RUNTIME_INTERFACESUPPORT_INLINE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/orderAccess.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "runtime/os.hpp"
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
    32
#include "runtime/safepointMechanism.inline.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49449
diff changeset
    33
#include "runtime/safepointVerifiers.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47881
diff changeset
    34
#include "runtime/thread.hpp"
52877
9e041366c764 8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents: 52460
diff changeset
    35
#include "runtime/vmOperations.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "utilities/globalDefinitions.hpp"
54347
235883996bc7 8221698: Remove redundant includes from popular header files
iklam
parents: 54323
diff changeset
    37
#include "utilities/histogram.hpp"
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 37466
diff changeset
    38
#include "utilities/macros.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#include "utilities/preserveException.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// Wrapper for all entry points to the virtual machine.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
    43
// InterfaceSupport provides functionality used by the VM_LEAF_BASE and
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
    44
// VM_ENTRY_BASE macros. These macros are used to guard entry points into
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
    45
// the VM and perform checks upon leave of the VM.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
class InterfaceSupport: AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
# ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  static long _scavenge_alot_counter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  static long _fullgc_alot_counter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  static long _number_of_calls;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  static long _fullgc_alot_invocation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // Helper methods used to implement +ScavengeALot and +FullGCALot
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  static void check_gc_alot() { if (ScavengeALot || FullGCALot) gc_alot(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  static void gc_alot();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  static void walk_stack_from(vframe* start_vf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  static void walk_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  static void zombieAll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  static void deoptimizeAll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  static void stress_derived_pointers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  static void verify_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  static void verify_last_frame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
# endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
// Basic class for all thread transition classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
class ThreadStateTransition : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  JavaThread* _thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  ThreadStateTransition(JavaThread *thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    _thread = thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    assert(thread != NULL && thread->is_Java_thread(), "must be Java thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // Change threadstate in a manner, so safepoint can detect changes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // Time-critical: called on exit from every runtime routine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  static inline void transition(JavaThread *thread, JavaThreadState from, JavaThreadState to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    assert(from != _thread_in_Java, "use transition_from_java");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    assert(from != _thread_in_native, "use transition_from_native");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    assert((from & 1) == 0 && (to & 1) == 0, "odd numbers are transitions states");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    assert(thread->thread_state() == from, "coming from wrong thread state");
57745
789e967c2731 5103339: Strengthen NoSafepointVerifier
coleenp
parents: 57603
diff changeset
    90
789e967c2731 5103339: Strengthen NoSafepointVerifier
coleenp
parents: 57603
diff changeset
    91
    // Check NoSafepointVerifier
789e967c2731 5103339: Strengthen NoSafepointVerifier
coleenp
parents: 57603
diff changeset
    92
    // This also clears unhandled oops if CheckUnhandledOops is used.
789e967c2731 5103339: Strengthen NoSafepointVerifier
coleenp
parents: 57603
diff changeset
    93
    thread->check_possible_safepoint();
789e967c2731 5103339: Strengthen NoSafepointVerifier
coleenp
parents: 57603
diff changeset
    94
54495
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
    95
    // Change to transition state and ensure it is seen by the VM thread.
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
    96
    thread->set_thread_state_fence((JavaThreadState)(from + 1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
    98
    SafepointMechanism::block_if_requested(thread);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    thread->set_thread_state(to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // Same as above, but assumes from = _thread_in_Java. This is simpler, since we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // never block on entry to the VM. This will break the code, since e.g. preserve arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // have not been setup.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  static inline void transition_from_java(JavaThread *thread, JavaThreadState to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    assert(thread->thread_state() == _thread_in_Java, "coming from wrong thread state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    thread->set_thread_state(to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  static inline void transition_from_native(JavaThread *thread, JavaThreadState to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    assert((to & 1) == 0, "odd numbers are transitions states");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    assert(thread->thread_state() == _thread_in_native, "coming from wrong thread state");
54495
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
   113
    // Change to transition state and ensure it is seen by the VM thread.
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
   114
    thread->set_thread_state_fence(_thread_in_native_trans);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    // We never install asynchronous exceptions when coming (back) in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    // to the runtime from native code because the runtime is not set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    // up to handle exceptions floating around at arbitrary points.
52450
2790da836dc3 8211403: Rename SafepointMechanism::poll(...)
rehn
parents: 51996
diff changeset
   119
    if (SafepointMechanism::should_block(thread) || thread->is_suspend_after_native()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      JavaThread::check_safepoint_and_suspend_for_native_trans(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    thread->set_thread_state(to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
   void trans(JavaThreadState from, JavaThreadState to)  { transition(_thread, from, to); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
   void trans_from_java(JavaThreadState to)              { transition_from_java(_thread, to); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
   void trans_from_native(JavaThreadState to)            { transition_from_native(_thread, to); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   131
class ThreadInVMForHandshake : public ThreadStateTransition {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   132
  const JavaThreadState _original_state;
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   133
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   134
  void transition_back() {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   135
    // This can be invoked from transition states and must return to the original state properly
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   136
    assert(_thread->thread_state() == _thread_in_vm, "should only call when leaving VM after handshake");
54495
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
   137
    // Change to transition state and ensure it is seen by the VM thread.
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
   138
    _thread->set_thread_state_fence(_thread_in_vm_trans);
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   139
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   140
    SafepointMechanism::block_if_requested(_thread);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   141
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   142
    _thread->set_thread_state(_original_state);
54898
17926213de55 8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents: 54523
diff changeset
   143
17926213de55 8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents: 54523
diff changeset
   144
    if (_original_state != _thread_blocked_trans &&  _original_state != _thread_in_vm_trans &&
17926213de55 8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents: 54523
diff changeset
   145
        _thread->has_special_runtime_exit_condition()) {
17926213de55 8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents: 54523
diff changeset
   146
      _thread->handle_special_runtime_exit_condition(
17926213de55 8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents: 54523
diff changeset
   147
          !_thread->is_at_poll_safepoint() && (_original_state != _thread_in_native_trans));
17926213de55 8223572: ~ThreadInVMForHandshake() should call handle_special_runtime_exit_condition()
rrich
parents: 54523
diff changeset
   148
    }
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   149
  }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   150
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   151
 public:
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   152
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   153
  ThreadInVMForHandshake(JavaThread* thread) : ThreadStateTransition(thread),
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   154
      _original_state(thread->thread_state()) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   155
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   156
    if (thread->has_last_Java_frame()) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   157
      thread->frame_anchor()->make_walkable(thread);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   158
    }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   159
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   160
    thread->set_thread_state(_thread_in_vm);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   161
  }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   162
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   163
  ~ThreadInVMForHandshake() {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   164
    transition_back();
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   165
  }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   166
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   167
};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
class ThreadInVMfromJava : public ThreadStateTransition {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  ThreadInVMfromJava(JavaThread* thread) : ThreadStateTransition(thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    trans_from_java(_thread_in_vm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  ~ThreadInVMfromJava()  {
40926
2fd1cf3e70e9 8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents: 40010
diff changeset
   175
    if (_thread->stack_yellow_reserved_zone_disabled()) {
2fd1cf3e70e9 8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents: 40010
diff changeset
   176
      _thread->enable_stack_yellow_reserved_zone();
2fd1cf3e70e9 8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents: 40010
diff changeset
   177
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    trans(_thread_in_vm, _thread_in_Java);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    // Check for pending. async. exceptions or suspends.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
class ThreadInVMfromUnknown {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  JavaThread* _thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  ThreadInVMfromUnknown() : _thread(NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    Thread* t = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    if (t->is_Java_thread()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      JavaThread* t2 = (JavaThread*) t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      if (t2->thread_state() == _thread_in_native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        _thread = t2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
        ThreadStateTransition::transition_from_native(t2, _thread_in_vm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
        // Used to have a HandleMarkCleaner but that is dangerous as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
        // it could free a handle in our (indirect, nested) caller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
        // We expect any handles will be short lived and figure we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
        // don't need an actual HandleMark.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  ~ThreadInVMfromUnknown()  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    if (_thread) {
54495
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
   204
      ThreadStateTransition::transition(_thread, _thread_in_vm, _thread_in_native);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
class ThreadInVMfromNative : public ThreadStateTransition {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  ThreadInVMfromNative(JavaThread* thread) : ThreadStateTransition(thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    trans_from_native(_thread_in_vm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  ~ThreadInVMfromNative() {
54495
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
   216
    trans(_thread_in_vm, _thread_in_native);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
class ThreadToNativeFromVM : public ThreadStateTransition {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    // We are leaving the VM at this point and going directly to native code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    // Block, if we are in the middle of a safepoint synchronization.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    assert(!thread->owns_locks(), "must release all locks when leaving VM");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    thread->frame_anchor()->make_walkable(thread);
54495
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
   228
    trans(_thread_in_vm, _thread_in_native);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    // Check for pending. async. exceptions or suspends.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  ~ThreadToNativeFromVM() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    trans_from_native(_thread_in_vm);
41084
fc5db29fa08e 8164086: Checked JNI pending exception check should be cleared when returning to Java frame
dsimms
parents: 40926
diff changeset
   235
    assert(!_thread->is_pending_jni_exception_check(), "Pending JNI Exception Check");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    // We don't need to clear_walkable because it will happen automagically when we return to java
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
class ThreadBlockInVM : public ThreadStateTransition {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  ThreadBlockInVM(JavaThread *thread)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  : ThreadStateTransition(thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    // Once we are blocked vm expects stack to be walkable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    thread->frame_anchor()->make_walkable(thread);
54495
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
   247
    trans(_thread_in_vm, _thread_blocked);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  ~ThreadBlockInVM() {
54495
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
   250
    trans(_thread_blocked, _thread_in_vm);
54323
846bc643f4ef 8220351: Cross-modifying code
rehn
parents: 53775
diff changeset
   251
    OrderAccess::cross_modify_fence();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    // We don't need to clear_walkable because it will happen automagically when we return to java
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
53646
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   256
// Unlike ThreadBlockInVM, this class is designed to avoid certain deadlock scenarios while making
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   257
// transitions inside class Monitor in cases where we need to block for a safepoint or handshake. It
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   258
// receives an extra argument compared to ThreadBlockInVM, the address of a pointer to the monitor we
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   259
// are trying to acquire. This will be used to access and release the monitor if needed to avoid
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   260
// said deadlocks.
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   261
// It works like ThreadBlockInVM but differs from it in two ways:
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   262
// - When transitioning in (constructor), it checks for safepoints without blocking, i.e., calls
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   263
//   back if needed to allow a pending safepoint to continue but does not block in it.
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   264
// - When transitioning back (destructor), if there is a pending safepoint or handshake it releases
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   265
//   the monitor that is only partially acquired.
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   266
class ThreadBlockInVMWithDeadlockCheck : public ThreadStateTransition {
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   267
 private:
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   268
  Monitor** _in_flight_monitor_adr;
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   269
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   270
  void release_monitor() {
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   271
    assert(_in_flight_monitor_adr != NULL, "_in_flight_monitor_adr should have been set on constructor");
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   272
    Monitor* in_flight_monitor = *_in_flight_monitor_adr;
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   273
    if (in_flight_monitor != NULL) {
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   274
      in_flight_monitor->release_for_safepoint();
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   275
      *_in_flight_monitor_adr = NULL;
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   276
    }
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   277
  }
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   278
 public:
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   279
  ThreadBlockInVMWithDeadlockCheck(JavaThread* thread, Monitor** in_flight_monitor_adr)
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   280
  : ThreadStateTransition(thread), _in_flight_monitor_adr(in_flight_monitor_adr) {
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   281
    // Once we are blocked vm expects stack to be walkable
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   282
    thread->frame_anchor()->make_walkable(thread);
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   283
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   284
    // All unsafe states are treated the same by the VMThread
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   285
    // so we can skip the _thread_in_vm_trans state here. Since
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   286
    // we don't read poll, it's enough to order the stores.
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   287
    OrderAccess::storestore();
53646
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   288
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   289
    thread->set_thread_state(_thread_blocked);
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   290
  }
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   291
  ~ThreadBlockInVMWithDeadlockCheck() {
54495
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
   292
    // Change to transition state and ensure it is seen by the VM thread.
941db9c0b5b5 8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents: 54347
diff changeset
   293
    _thread->set_thread_state_fence((JavaThreadState)(_thread_blocked_trans));
53646
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   294
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   295
    if (SafepointMechanism::should_block(_thread)) {
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   296
      release_monitor();
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   297
      SafepointMechanism::block_if_requested(_thread);
53646
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   298
    }
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   299
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   300
    _thread->set_thread_state(_thread_in_vm);
54323
846bc643f4ef 8220351: Cross-modifying code
rehn
parents: 53775
diff changeset
   301
    OrderAccess::cross_modify_fence();
53646
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   302
  }
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   303
};
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53244
diff changeset
   304
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
// This special transition class is only used to prevent asynchronous exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
// from being installed on vm exit in situations where we can't tolerate them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
// See bugs: 4324348, 4854693, 4998314, 5040492, 5050705.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
class ThreadInVMfromJavaNoAsyncException : public ThreadStateTransition {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  ThreadInVMfromJavaNoAsyncException(JavaThread* thread) : ThreadStateTransition(thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    trans_from_java(_thread_in_vm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  ~ThreadInVMfromJavaNoAsyncException()  {
40926
2fd1cf3e70e9 8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents: 40010
diff changeset
   315
    if (_thread->stack_yellow_reserved_zone_disabled()) {
2fd1cf3e70e9 8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents: 40010
diff changeset
   316
      _thread->enable_stack_yellow_reserved_zone();
2fd1cf3e70e9 8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents: 40010
diff changeset
   317
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    trans(_thread_in_vm, _thread_in_Java);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    // NOTE: We do not check for pending. async. exceptions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    // If we did and moved the pending async exception over into the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    // pending exception field, we would need to deopt (currently C2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    // only). However, to do so would require that we transition back
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    // to the _thread_in_vm state. Instead we postpone the handling of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    // the async exception.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
40926
2fd1cf3e70e9 8137035: nsk/stress/stack/stack tests got EXCEPTION_STACK_OVERFLOW on Windows 64 bit
fparain
parents: 40010
diff changeset
   326
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    // Check for pending. suspends only.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    if (_thread->has_special_runtime_exit_condition())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      _thread->handle_special_runtime_exit_condition(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
57603
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   333
// Debug class instantiated in JRT_ENTRY macro.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
// Can be used to verify properties on enter/exit of the VM.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
class VMEntryWrapper {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
 public:
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47881
diff changeset
   339
  VMEntryWrapper();
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47881
diff changeset
   340
  ~VMEntryWrapper();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
class VMNativeEntryWrapper {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
 public:
57603
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   346
  VMNativeEntryWrapper();
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   347
  ~VMNativeEntryWrapper();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
class RuntimeHistogramElement : public HistogramElement {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
   RuntimeHistogramElement(const char* name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
};
57603
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   354
#endif // ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
57603
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   356
#ifdef ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
#define TRACE_CALL(result_type, header)                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  InterfaceSupport::_number_of_calls++;                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  if (CountRuntimeCalls) {                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    static RuntimeHistogramElement* e = new RuntimeHistogramElement(#header); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    if (e != NULL) e->increment_count();                           \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
#define TRACE_CALL(result_type, header)                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  /* do nothing */
57603
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   366
#endif // ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
// LEAF routines do not lock, GC or throw exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   371
#define VM_LEAF_BASE(result_type, header)                            \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  TRACE_CALL(result_type, header)                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  debug_only(NoHandleMark __hm;)                                     \
11961
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 10969
diff changeset
   374
  os::verify_stack_alignment();                                      \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  /* begin of body */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
36086
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   377
#define VM_ENTRY_BASE_FROM_LEAF(result_type, header, thread)         \
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   378
  TRACE_CALL(result_type, header)                                    \
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   379
  debug_only(ResetNoHandleMark __rnhm;)                              \
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   380
  HandleMarkCleaner __hm(thread);                                    \
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   381
  Thread* THREAD = thread;                                           \
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   382
  os::verify_stack_alignment();                                      \
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   383
  /* begin of body */
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   384
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
// ENTRY routines may lock, GC and throw exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   388
#define VM_ENTRY_BASE(result_type, header, thread)                   \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  TRACE_CALL(result_type, header)                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  HandleMarkCleaner __hm(thread);                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  Thread* THREAD = thread;                                           \
11961
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 10969
diff changeset
   392
  os::verify_stack_alignment();                                      \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  /* begin of body */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
// QUICK_ENTRY routines behave like ENTRY but without a handle mark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   398
#define VM_QUICK_ENTRY_BASE(result_type, header, thread)             \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  TRACE_CALL(result_type, header)                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  debug_only(NoHandleMark __hm;)                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  Thread* THREAD = thread;                                           \
11961
0abd4cd26e5a 7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents: 10969
diff changeset
   402
  os::verify_stack_alignment();                                      \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  /* begin of body */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
#define JRT_ENTRY(result_type, header)                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  result_type header {                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    ThreadInVMfromJava __tiv(thread);                                \
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   409
    VM_ENTRY_BASE(result_type, header, thread)                       \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    debug_only(VMEntryWrapper __vew;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
57603
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   412
// JRT_LEAF currently can be called from either _thread_in_Java or
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   413
// _thread_in_native mode.
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   414
//
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   415
// JRT_LEAF rules:
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   416
// A JRT_LEAF method may not interfere with safepointing by
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   417
//   1) acquiring or blocking on a Mutex or JavaLock - checked
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   418
//   2) allocating heap memory - checked
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   419
//   3) executing a VM operation - checked
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   420
//   4) executing a system call (including malloc) that could block or grab a lock
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   421
//   5) invoking GC
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   422
//   6) reaching a safepoint
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   423
//   7) running too long
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   424
// Nor may any method it calls.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
#define JRT_LEAF(result_type, header)                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  result_type header {                                               \
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   428
  VM_LEAF_BASE(result_type, header)                                  \
57603
f9d9bed12d1a 8228630: Remove always true parameter to NoSafepointVerifier
coleenp
parents: 54898
diff changeset
   429
  debug_only(NoSafepointVerifier __nsv;)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
#define JRT_ENTRY_NO_ASYNC(result_type, header)                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  result_type header {                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    ThreadInVMfromJavaNoAsyncException __tiv(thread);                \
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   435
    VM_ENTRY_BASE(result_type, header, thread)                       \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    debug_only(VMEntryWrapper __vew;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
// Same as JRT Entry but allows for return value after the safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
// to get back into Java from the VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
#define JRT_BLOCK_ENTRY(result_type, header)                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  result_type header {                                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    TRACE_CALL(result_type, header)                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    HandleMarkCleaner __hm(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
#define JRT_BLOCK                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    {                                                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    ThreadInVMfromJava __tiv(thread);                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    Thread* THREAD = thread;                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    debug_only(VMEntryWrapper __vew;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
29070
b0a5fc9c59c8 8061553: Contended Locking fast enter bucket
dcubed
parents: 22838
diff changeset
   451
#define JRT_BLOCK_NO_ASYNC                                           \
b0a5fc9c59c8 8061553: Contended Locking fast enter bucket
dcubed
parents: 22838
diff changeset
   452
    {                                                                \
b0a5fc9c59c8 8061553: Contended Locking fast enter bucket
dcubed
parents: 22838
diff changeset
   453
    ThreadInVMfromJavaNoAsyncException __tiv(thread);                \
b0a5fc9c59c8 8061553: Contended Locking fast enter bucket
dcubed
parents: 22838
diff changeset
   454
    Thread* THREAD = thread;                                         \
b0a5fc9c59c8 8061553: Contended Locking fast enter bucket
dcubed
parents: 22838
diff changeset
   455
    debug_only(VMEntryWrapper __vew;)
b0a5fc9c59c8 8061553: Contended Locking fast enter bucket
dcubed
parents: 22838
diff changeset
   456
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
#define JRT_BLOCK_END }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
#define JRT_END }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
// Definitions for JNI
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
#define JNI_ENTRY(result_type, header)                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    JNI_ENTRY_NO_PRESERVE(result_type, header)                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    WeakPreserveExceptionMark __wem(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36086
diff changeset
   467
#define JNI_ENTRY_NO_PRESERVE(result_type, header)                   \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
extern "C" {                                                         \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36086
diff changeset
   469
  result_type JNICALL header {                                       \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    ThreadInVMfromNative __tiv(thread);                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    debug_only(VMNativeEntryWrapper __vew;)                          \
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   474
    VM_ENTRY_BASE(result_type, header, thread)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
// Ensure that the VMNativeEntryWrapper constructor, which can cause
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   478
// a GC, is called outside the NoHandleMark (set via VM_QUICK_ENTRY_BASE).
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
#define JNI_QUICK_ENTRY(result_type, header)                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
extern "C" {                                                         \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36086
diff changeset
   481
  result_type JNICALL header {                                       \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    ThreadInVMfromNative __tiv(thread);                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    debug_only(VMNativeEntryWrapper __vew;)                          \
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   486
    VM_QUICK_ENTRY_BASE(result_type, header, thread)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
#define JNI_LEAF(result_type, header)                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
extern "C" {                                                         \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36086
diff changeset
   491
  result_type JNICALL header {                                       \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   494
    VM_LEAF_BASE(result_type, header)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
// Close the routine and the extern "C"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
#define JNI_END } }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
// Definitions for JVM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
#define JVM_ENTRY(result_type, header)                               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
extern "C" {                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  result_type JNICALL header {                                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    ThreadInVMfromNative __tiv(thread);                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    debug_only(VMNativeEntryWrapper __vew;)                          \
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   510
    VM_ENTRY_BASE(result_type, header, thread)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
#define JVM_ENTRY_NO_ENV(result_type, header)                        \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
extern "C" {                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  result_type JNICALL header {                                       \
34633
2a6c7c7b30a7 8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents: 34285
diff changeset
   516
    JavaThread* thread = JavaThread::current();                      \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    ThreadInVMfromNative __tiv(thread);                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    debug_only(VMNativeEntryWrapper __vew;)                          \
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   519
    VM_ENTRY_BASE(result_type, header, thread)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
#define JVM_QUICK_ENTRY(result_type, header)                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
extern "C" {                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  result_type JNICALL header {                                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    ThreadInVMfromNative __tiv(thread);                              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    debug_only(VMNativeEntryWrapper __vew;)                          \
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   528
    VM_QUICK_ENTRY_BASE(result_type, header, thread)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
#define JVM_LEAF(result_type, header)                                \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
extern "C" {                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  result_type JNICALL header {                                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    VM_Exit::block_if_vm_exited();                                   \
10969
3ecf25293e5a 7103224: collision between __LEAF define in interfaceSupport.hpp and /usr/include/sys/cdefs.h with gcc
never
parents: 10565
diff changeset
   535
    VM_LEAF_BASE(result_type, header)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
36086
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   538
#define JVM_ENTRY_FROM_LEAF(env, result_type, header)                \
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   539
  { {                                                                \
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   540
    JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   541
    ThreadInVMfromNative __tiv(thread);                              \
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   542
    debug_only(VMNativeEntryWrapper __vew;)                          \
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   543
    VM_ENTRY_BASE_FROM_LEAF(result_type, header, thread)
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   544
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35492
diff changeset
   545
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
#define JVM_END } }
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   547
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52877
diff changeset
   548
#endif // SHARE_RUNTIME_INTERFACESUPPORT_INLINE_HPP