hotspot/src/share/vm/gc/shared/referencePendingListLocker.cpp
author drwhite
Tue, 05 Jul 2016 15:34:06 -0400
changeset 39695 946f1321c075
parent 37150 c415c138fada
permissions -rw-r--r--
8158946: btree009 fails with assert(s > 0) failed: Bad size calculated Summary: Set oop_size before setting _klass Reviewed-by: coleenp, dholmes, kbarrett, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37129
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
     1
/*
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
     4
 *
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
     8
 *
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    13
 * accompanied this code).
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    14
 *
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    18
 *
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    21
 * questions.
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    22
 *
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    23
 */
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    24
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    25
#include "precompiled.hpp"
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    26
#include "classfile/javaClasses.hpp"
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    27
#include "classfile/systemDictionary.hpp"
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    28
#include "gc/shared/collectedHeap.hpp"
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    29
#include "gc/shared/referencePendingListLocker.hpp"
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    30
#include "memory/universe.hpp"
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    31
#include "runtime/javaCalls.hpp"
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    32
#include "utilities/preserveException.hpp"
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    33
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    34
ReferencePendingListLockerThread::ReferencePendingListLockerThread() :
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    35
  JavaThread(&start),
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    36
  _monitor(Monitor::nonleaf, "ReferencePendingListLocker", false, Monitor::_safepoint_check_sometimes),
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    37
  _message(NONE) {}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    38
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    39
ReferencePendingListLockerThread* ReferencePendingListLockerThread::create(TRAPS) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    40
  // Create Java thread objects
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    41
  instanceKlassHandle thread_klass = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK_NULL);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    42
  instanceHandle thread_object = thread_klass->allocate_instance_handle(CHECK_NULL);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    43
  Handle thread_name = java_lang_String::create_from_str("Reference Pending List Locker", CHECK_NULL);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    44
  Handle thread_group = Universe::system_thread_group();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    45
  JavaValue result(T_VOID);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    46
  JavaCalls::call_special(&result,
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    47
                          thread_object,
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    48
                          thread_klass,
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    49
                          vmSymbols::object_initializer_name(),
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    50
                          vmSymbols::threadgroup_string_void_signature(),
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    51
                          thread_group,
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    52
                          thread_name,
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    53
                          CHECK_NULL);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    54
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    55
  {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    56
    MutexLocker ml(Threads_lock);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    57
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    58
    // Allocate thread
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    59
    ReferencePendingListLockerThread* thread = new ReferencePendingListLockerThread();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    60
    if (thread == NULL || thread->osthread() == NULL) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    61
      vm_exit_during_initialization("java.lang.OutOfMemoryError",
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    62
                                    os::native_thread_creation_failed_msg());
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    63
    }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    64
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    65
    // Initialize thread
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    66
    java_lang_Thread::set_thread(thread_object(), thread);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    67
    java_lang_Thread::set_priority(thread_object(), NearMaxPriority);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    68
    java_lang_Thread::set_daemon(thread_object());
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    69
    thread->set_threadObj(thread_object());
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    70
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    71
    // Start thread
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    72
    Threads::add(thread);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    73
    Thread::start(thread);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    74
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    75
    return thread;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    76
  }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    77
}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    78
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    79
void ReferencePendingListLockerThread::start(JavaThread* thread, TRAPS) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    80
  ReferencePendingListLockerThread* locker_thread = static_cast<ReferencePendingListLockerThread*>(thread);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    81
  locker_thread->receive_and_handle_messages();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    82
}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    83
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    84
bool ReferencePendingListLockerThread::is_hidden_from_external_view() const {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    85
  return true;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    86
}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    87
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    88
void ReferencePendingListLockerThread::send_message(Message message) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    89
  assert(message != NONE, "Should not be none");
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    90
  MonitorLockerEx ml(&_monitor, Monitor::_no_safepoint_check_flag);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    91
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    92
  // Wait for completion of current message
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    93
  while (_message != NONE) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    94
    ml.wait(Monitor::_no_safepoint_check_flag);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    95
  }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    96
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    97
  // Send new message
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    98
  _message = message;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
    99
  ml.notify_all();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   100
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   101
  // Wait for completion of new message
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   102
  while (_message != NONE) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   103
    ml.wait(Monitor::_no_safepoint_check_flag);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   104
  }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   105
}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   106
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   107
void ReferencePendingListLockerThread::receive_and_handle_messages() {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   108
  ReferencePendingListLocker pending_list_locker;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   109
  MonitorLockerEx ml(&_monitor);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   110
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   111
  // Main loop, never terminates
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   112
  for (;;) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   113
    // Wait for message
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   114
    while (_message == NONE) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   115
      ml.wait();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   116
    }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   117
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   118
    // Handle message
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   119
    if (_message == LOCK) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   120
      pending_list_locker.lock();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   121
    } else if (_message == UNLOCK) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   122
      pending_list_locker.unlock();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   123
    } else {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   124
      ShouldNotReachHere();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   125
    }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   126
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   127
    // Clear message
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   128
    _message = NONE;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   129
    ml.notify_all();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   130
  }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   131
}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   132
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   133
void ReferencePendingListLockerThread::lock() {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   134
  send_message(LOCK);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   135
}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   136
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   137
void ReferencePendingListLockerThread::unlock() {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   138
  send_message(UNLOCK);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   139
}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   140
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   141
bool ReferencePendingListLocker::_is_initialized = false;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   142
ReferencePendingListLockerThread* ReferencePendingListLocker::_locker_thread = NULL;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   143
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   144
void ReferencePendingListLocker::initialize(bool needs_locker_thread, TRAPS) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   145
  if (needs_locker_thread) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   146
    _locker_thread = ReferencePendingListLockerThread::create(CHECK);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   147
  }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   148
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   149
  _is_initialized = true;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   150
}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   151
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   152
bool ReferencePendingListLocker::is_initialized() {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   153
  return _is_initialized;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   154
}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   155
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   156
bool ReferencePendingListLocker::is_locked_by_self() {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   157
  oop pending_list_lock = java_lang_ref_Reference::pending_list_lock();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   158
  if (pending_list_lock == NULL) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   159
    return false;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   160
  }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   161
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   162
  JavaThread* thread = JavaThread::current();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   163
  Handle handle(thread, pending_list_lock);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   164
  return ObjectSynchronizer::current_thread_holds_lock(thread, handle);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   165
}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   166
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   167
void ReferencePendingListLocker::lock() {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   168
  assert(!Heap_lock->owned_by_self(), "Heap_lock must not be owned by requesting thread");
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   169
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   170
  if (Thread::current()->is_Java_thread()) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   171
    assert(java_lang_ref_Reference::pending_list_lock() != NULL, "Not initialized");
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   172
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   173
    // We may enter this with a pending exception
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   174
    PRESERVE_EXCEPTION_MARK;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   175
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   176
    HandleMark hm;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   177
    Handle handle(THREAD, java_lang_ref_Reference::pending_list_lock());
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   178
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   179
    // Lock
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   180
    ObjectSynchronizer::fast_enter(handle, &_basic_lock, false, THREAD);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   181
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   182
    assert(is_locked_by_self(), "Locking failed");
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   183
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   184
    if (HAS_PENDING_EXCEPTION) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   185
      CLEAR_PENDING_EXCEPTION;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   186
    }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   187
  } else {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   188
    // Delegate operation to locker thread
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   189
    assert(_locker_thread != NULL, "Locker thread not created");
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   190
    _locker_thread->lock();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   191
  }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   192
}
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   193
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   194
void ReferencePendingListLocker::unlock() {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   195
  if (Thread::current()->is_Java_thread()) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   196
    assert(java_lang_ref_Reference::pending_list_lock() != NULL, "Not initialized");
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   197
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   198
    // We may enter this with a pending exception
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   199
    PRESERVE_EXCEPTION_MARK;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   200
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   201
    HandleMark hm;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   202
    Handle handle(THREAD, java_lang_ref_Reference::pending_list_lock());
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   203
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   204
    assert(is_locked_by_self(), "Should be locked by self");
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   205
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   206
    // Notify waiters if the pending list is non-empty
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   207
    if (java_lang_ref_Reference::pending_list() != NULL) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   208
      ObjectSynchronizer::notifyall(handle, THREAD);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   209
    }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   210
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   211
    // Unlock
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   212
    ObjectSynchronizer::fast_exit(handle(), &_basic_lock, THREAD);
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   213
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   214
    if (HAS_PENDING_EXCEPTION) {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   215
      CLEAR_PENDING_EXCEPTION;
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   216
    }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   217
  } else {
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   218
    // Delegate operation to locker thread
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   219
    assert(_locker_thread != NULL, "Locker thread not created");
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   220
    _locker_thread->unlock();
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   221
  }
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents:
diff changeset
   222
}