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