src/hotspot/share/runtime/safepointMechanism.inline.hpp
author pchilanomate
Tue, 05 Feb 2019 15:12:13 -0500
changeset 53646 043ae846819f
parent 53631 a5321bcfa2de
child 53775 5d20b085d893
permissions -rw-r--r--
8210832: Remove sneaky locking in class Monitor Summary: Removed sneaky locking and simplified vm monitors implementation Reviewed-by: rehn, dcubed, pliden, dholmes, coleenp Contributed-by: david.holmes@oracle.com, patricio.chilano.mateo@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52450
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     4
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     8
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    13
 * accompanied this code).
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    14
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    18
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    21
 * questions.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    22
 *
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    23
 */
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52450
diff changeset
    25
#ifndef SHARE_RUNTIME_SAFEPOINTMECHANISM_INLINE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52450
diff changeset
    26
#define SHARE_RUNTIME_SAFEPOINTMECHANISM_INLINE_HPP
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    27
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    28
#include "runtime/safepointMechanism.hpp"
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    29
#include "runtime/safepoint.hpp"
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    30
#include "runtime/thread.inline.hpp"
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    31
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    32
bool SafepointMechanism::local_poll_armed(JavaThread* thread) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    33
  const intptr_t poll_word = reinterpret_cast<intptr_t>(thread->get_polling_page());
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    34
  return mask_bits_are_true(poll_word, poll_bit());
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    35
}
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    36
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    37
bool SafepointMechanism::global_poll() {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    38
  return SafepointSynchronize::do_call_back();
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    39
}
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    40
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    41
bool SafepointMechanism::local_poll(Thread* thread) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    42
  if (thread->is_Java_thread()) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    43
    return local_poll_armed((JavaThread*)thread);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    44
  } else {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    45
    // If the poll is on a non-java thread we can only check the global state.
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    46
    return global_poll();
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    47
  }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    48
}
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    49
52450
2790da836dc3 8211403: Rename SafepointMechanism::poll(...)
rehn
parents: 50921
diff changeset
    50
bool SafepointMechanism::should_block(Thread* thread) {
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    51
  if (uses_thread_local_poll()) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    52
    return local_poll(thread);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    53
  } else {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    54
    return global_poll();
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    55
  }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    56
}
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    57
53631
a5321bcfa2de 8218145: block_if_requested is not proper inlined due to size
rehn
parents: 53244
diff changeset
    58
void SafepointMechanism::block_if_requested(JavaThread *thread) {
a5321bcfa2de 8218145: block_if_requested is not proper inlined due to size
rehn
parents: 53244
diff changeset
    59
  if (uses_thread_local_poll() && !SafepointMechanism::local_poll_armed(thread)) {
a5321bcfa2de 8218145: block_if_requested is not proper inlined due to size
rehn
parents: 53244
diff changeset
    60
    return;
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    61
  }
53631
a5321bcfa2de 8218145: block_if_requested is not proper inlined due to size
rehn
parents: 53244
diff changeset
    62
  block_if_requested_slow(thread);
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    63
}
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    64
53646
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    65
void SafepointMechanism::callback_if_safepoint(JavaThread* thread) {
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    66
  if (!uses_thread_local_poll() || local_poll_armed(thread)) {
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    67
    // If using thread local polls, we should not check the
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    68
    // global_poll() and callback via block() if the VMThread
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    69
    // has not yet armed the local poll. Otherwise, when used in
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    70
    // combination with should_block(), the latter could miss
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    71
    // detecting the same safepoint that this method would detect
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    72
    // if only checking global polls.
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    73
    if (global_poll()) {
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    74
      SafepointSynchronize::block(thread, false);
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    75
    }
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    76
  }
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    77
}
043ae846819f 8210832: Remove sneaky locking in class Monitor
pchilanomate
parents: 53631
diff changeset
    78
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    79
void SafepointMechanism::arm_local_poll(JavaThread* thread) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    80
  thread->set_polling_page(poll_armed_value());
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    81
}
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    82
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    83
void SafepointMechanism::disarm_local_poll(JavaThread* thread) {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    84
  thread->set_polling_page(poll_disarmed_value());
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    85
}
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
diff changeset
    86
50921
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50626
diff changeset
    87
void SafepointMechanism::arm_local_poll_release(JavaThread* thread) {
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50626
diff changeset
    88
  thread->set_polling_page_release(poll_armed_value());
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50626
diff changeset
    89
}
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50626
diff changeset
    90
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50626
diff changeset
    91
void SafepointMechanism::disarm_local_poll_release(JavaThread* thread) {
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50626
diff changeset
    92
  thread->set_polling_page_release(poll_disarmed_value());
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50626
diff changeset
    93
}
7f462e8383f6 8206003: SafepointSynchronize with TLH: StoreStore barriers should be moved out of the loop
mdoerr
parents: 50626
diff changeset
    94
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52450
diff changeset
    95
#endif // SHARE_RUNTIME_SAFEPOINTMECHANISM_INLINE_HPP