src/share/vm/runtime/park.cpp

Fri, 24 Jun 2016 17:12:13 +0800

author
aoqi<aoqi@loongson.cn>
date
Fri, 24 Jun 2016 17:12:13 +0800
changeset 25
873fd82b133d
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

[Code Reorganization] Removed GC related modifications made by Loongson, for example, UseOldNUMA.

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "runtime/thread.hpp"
aoqi@0 27
aoqi@0 28
aoqi@0 29
aoqi@0 30 // Lifecycle management for TSM ParkEvents.
aoqi@0 31 // ParkEvents are type-stable (TSM).
aoqi@0 32 // In our particular implementation they happen to be immortal.
aoqi@0 33 //
aoqi@0 34 // We manage concurrency on the FreeList with a CAS-based
aoqi@0 35 // detach-modify-reattach idiom that avoids the ABA problems
aoqi@0 36 // that would otherwise be present in a simple CAS-based
aoqi@0 37 // push-pop implementation. (push-one and pop-all)
aoqi@0 38 //
aoqi@0 39 // Caveat: Allocate() and Release() may be called from threads
aoqi@0 40 // other than the thread associated with the Event!
aoqi@0 41 // If we need to call Allocate() when running as the thread in
aoqi@0 42 // question then look for the PD calls to initialize native TLS.
aoqi@0 43 // Native TLS (Win32/Linux/Solaris) can only be initialized or
aoqi@0 44 // accessed by the associated thread.
aoqi@0 45 // See also pd_initialize().
aoqi@0 46 //
aoqi@0 47 // Note that we could defer associating a ParkEvent with a thread
aoqi@0 48 // until the 1st time the thread calls park(). unpark() calls to
aoqi@0 49 // an unprovisioned thread would be ignored. The first park() call
aoqi@0 50 // for a thread would allocate and associate a ParkEvent and return
aoqi@0 51 // immediately.
aoqi@0 52
aoqi@0 53 volatile int ParkEvent::ListLock = 0 ;
aoqi@0 54 ParkEvent * volatile ParkEvent::FreeList = NULL ;
aoqi@0 55
aoqi@0 56 ParkEvent * ParkEvent::Allocate (Thread * t) {
aoqi@0 57 // In rare cases -- JVM_RawMonitor* operations -- we can find t == null.
aoqi@0 58 ParkEvent * ev ;
aoqi@0 59
aoqi@0 60 // Start by trying to recycle an existing but unassociated
aoqi@0 61 // ParkEvent from the global free list.
aoqi@0 62 // Using a spin lock since we are part of the mutex impl.
aoqi@0 63 // 8028280: using concurrent free list without memory management can leak
aoqi@0 64 // pretty badly it turns out.
aoqi@0 65 Thread::SpinAcquire(&ListLock, "ParkEventFreeListAllocate");
aoqi@0 66 {
aoqi@0 67 ev = FreeList;
aoqi@0 68 if (ev != NULL) {
aoqi@0 69 FreeList = ev->FreeNext;
aoqi@0 70 }
aoqi@0 71 }
aoqi@0 72 Thread::SpinRelease(&ListLock);
aoqi@0 73
aoqi@0 74 if (ev != NULL) {
aoqi@0 75 guarantee (ev->AssociatedWith == NULL, "invariant") ;
aoqi@0 76 } else {
aoqi@0 77 // Do this the hard way -- materialize a new ParkEvent.
aoqi@0 78 ev = new ParkEvent () ;
aoqi@0 79 guarantee ((intptr_t(ev) & 0xFF) == 0, "invariant") ;
aoqi@0 80 }
aoqi@0 81 ev->reset() ; // courtesy to caller
aoqi@0 82 ev->AssociatedWith = t ; // Associate ev with t
aoqi@0 83 ev->FreeNext = NULL ;
aoqi@0 84 return ev ;
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 void ParkEvent::Release (ParkEvent * ev) {
aoqi@0 88 if (ev == NULL) return ;
aoqi@0 89 guarantee (ev->FreeNext == NULL , "invariant") ;
aoqi@0 90 ev->AssociatedWith = NULL ;
aoqi@0 91 // Note that if we didn't have the TSM/immortal constraint, then
aoqi@0 92 // when reattaching we could trim the list.
aoqi@0 93 Thread::SpinAcquire(&ListLock, "ParkEventFreeListRelease");
aoqi@0 94 {
aoqi@0 95 ev->FreeNext = FreeList;
aoqi@0 96 FreeList = ev;
aoqi@0 97 }
aoqi@0 98 Thread::SpinRelease(&ListLock);
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 // Override operator new and delete so we can ensure that the
aoqi@0 102 // least significant byte of ParkEvent addresses is 0.
aoqi@0 103 // Beware that excessive address alignment is undesirable
aoqi@0 104 // as it can result in D$ index usage imbalance as
aoqi@0 105 // well as bank access imbalance on Niagara-like platforms,
aoqi@0 106 // although Niagara's hash function should help.
aoqi@0 107
aoqi@0 108 void * ParkEvent::operator new (size_t sz) throw() {
aoqi@0 109 return (void *) ((intptr_t (AllocateHeap(sz + 256, mtInternal, CALLER_PC)) + 256) & -256) ;
aoqi@0 110 }
aoqi@0 111
aoqi@0 112 void ParkEvent::operator delete (void * a) {
aoqi@0 113 // ParkEvents are type-stable and immortal ...
aoqi@0 114 ShouldNotReachHere();
aoqi@0 115 }
aoqi@0 116
aoqi@0 117
aoqi@0 118 // 6399321 As a temporary measure we copied & modified the ParkEvent::
aoqi@0 119 // allocate() and release() code for use by Parkers. The Parker:: forms
aoqi@0 120 // will eventually be removed as we consolide and shift over to ParkEvents
aoqi@0 121 // for both builtin synchronization and JSR166 operations.
aoqi@0 122
aoqi@0 123 volatile int Parker::ListLock = 0 ;
aoqi@0 124 Parker * volatile Parker::FreeList = NULL ;
aoqi@0 125
aoqi@0 126 Parker * Parker::Allocate (JavaThread * t) {
aoqi@0 127 guarantee (t != NULL, "invariant") ;
aoqi@0 128 Parker * p ;
aoqi@0 129
aoqi@0 130 // Start by trying to recycle an existing but unassociated
aoqi@0 131 // Parker from the global free list.
aoqi@0 132 // 8028280: using concurrent free list without memory management can leak
aoqi@0 133 // pretty badly it turns out.
aoqi@0 134 Thread::SpinAcquire(&ListLock, "ParkerFreeListAllocate");
aoqi@0 135 {
aoqi@0 136 p = FreeList;
aoqi@0 137 if (p != NULL) {
aoqi@0 138 FreeList = p->FreeNext;
aoqi@0 139 }
aoqi@0 140 }
aoqi@0 141 Thread::SpinRelease(&ListLock);
aoqi@0 142
aoqi@0 143 if (p != NULL) {
aoqi@0 144 guarantee (p->AssociatedWith == NULL, "invariant") ;
aoqi@0 145 } else {
aoqi@0 146 // Do this the hard way -- materialize a new Parker..
aoqi@0 147 p = new Parker() ;
aoqi@0 148 }
aoqi@0 149 p->AssociatedWith = t ; // Associate p with t
aoqi@0 150 p->FreeNext = NULL ;
aoqi@0 151 return p ;
aoqi@0 152 }
aoqi@0 153
aoqi@0 154
aoqi@0 155 void Parker::Release (Parker * p) {
aoqi@0 156 if (p == NULL) return ;
aoqi@0 157 guarantee (p->AssociatedWith != NULL, "invariant") ;
aoqi@0 158 guarantee (p->FreeNext == NULL , "invariant") ;
aoqi@0 159 p->AssociatedWith = NULL ;
aoqi@0 160
aoqi@0 161 Thread::SpinAcquire(&ListLock, "ParkerFreeListRelease");
aoqi@0 162 {
aoqi@0 163 p->FreeNext = FreeList;
aoqi@0 164 FreeList = p;
aoqi@0 165 }
aoqi@0 166 Thread::SpinRelease(&ListLock);
aoqi@0 167 }
aoqi@0 168

mercurial