annotate src/os_cpu/solaris_x86/vm/threadLS_solaris_x86.cpp @ 1250:3f5b7efb9642

6920293: OptimizeStringConcat causing core dumps Reviewed-by: kvn, twisti
author never
date Fri, 05 Feb 2010 11:07:40 -0800
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_threadLS_solaris_x86.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
29 extern "C" Thread* fs_load(ptrdiff_t tlsOffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
30 extern "C" intptr_t fs_thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
31 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // From solaris_i486.s
a61af66fc99e Initial load
duke
parents:
diff changeset
33 extern "C" Thread* gs_load(ptrdiff_t tlsOffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
34 extern "C" intptr_t gs_thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
35 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // tlsMode encoding:
a61af66fc99e Initial load
duke
parents:
diff changeset
38 //
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // pd_tlsAccessUndefined : uninitialized
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // pd_tlsAccessSlow : not available
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // pd_tlsAccessIndirect :
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // old-style indirect access - present in "T1" libthread.
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // use thr_slot_sync_allocate() to attempt to allocate a slot.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // pd_tlsAccessDirect :
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // new-style direct access - present in late-model "T2" libthread.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Allocate the offset (slot) via _thr_slot_offset() or by
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // defining an IE- or LE-mode TLS/TSD slot in the launcher and then passing
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // that offset into libjvm.so.
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // See http://sac.eng/Archives/CaseLog/arc/PSARC/2003/159/.
a61af66fc99e Initial load
duke
parents:
diff changeset
50 //
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // Note that we have a capability gap - some early model T2 forms
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // (e.g., unpatched S9) have neither _thr_slot_sync_allocate() nor
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // _thr_slot_offset(). In that case we revert to the usual
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // thr_getspecific accessor.
a61af66fc99e Initial load
duke
parents:
diff changeset
55 //
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 static ThreadLocalStorage::pd_tlsAccessMode tlsMode = ThreadLocalStorage::pd_tlsAccessUndefined ;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 static ptrdiff_t tlsOffset = 0 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 static thread_key_t tlsKey ;
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 typedef int (*TSSA_Entry) (ptrdiff_t *, int, int) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 typedef ptrdiff_t (*TSO_Entry) (int) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 ThreadLocalStorage::pd_tlsAccessMode ThreadLocalStorage::pd_getTlsAccessMode ()
a61af66fc99e Initial load
duke
parents:
diff changeset
65 {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 guarantee (tlsMode != pd_tlsAccessUndefined, "tlsMode not set") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return tlsMode ;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 ptrdiff_t ThreadLocalStorage::pd_getTlsOffset () {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 guarantee (tlsMode != pd_tlsAccessUndefined, "tlsMode not set") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return tlsOffset ;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // TODO: Consider the following improvements:
a61af66fc99e Initial load
duke
parents:
diff changeset
76 //
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // 1. Convert from thr_*specific* to pthread_*specific*.
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // The pthread_ forms are slightly faster. Also, the
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // pthread_ forms have a pthread_key_delete() API which
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // would aid in clean JVM shutdown and the eventual goal
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // of permitting a JVM to reinstantiate itself withing a process.
a61af66fc99e Initial load
duke
parents:
diff changeset
82 //
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // 2. See ThreadLocalStorage::init(). We end up allocating
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // two TLS keys during VM startup. That's benign, but we could collapse
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // down to one key without too much trouble.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 //
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // 3. MacroAssembler::get_thread() currently emits calls to thr_getspecific().
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // Modify get_thread() to call Thread::current() instead.
a61af66fc99e Initial load
duke
parents:
diff changeset
89 //
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // 4. Thread::current() currently uses a cache keyed by %gs:[0].
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // (The JVM has PSARC permission to use %g7/%gs:[0]
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // as an opaque temporally unique thread identifier).
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // For C++ access to a thread's reflexive "self" pointer we
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // should consider using one of the following:
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // a. a radix tree keyed by %esp - as in EVM.
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // This requires two loads (the 2nd dependent on the 1st), but
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // is easily inlined and doesn't require a "miss" slow path.
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // b. a fast TLS/TSD slot allocated by _thr_slot_offset
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // or _thr_slot_sync_allocate.
a61af66fc99e Initial load
duke
parents:
diff changeset
100 //
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // 5. 'generate_code_for_get_thread' is a misnomer.
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // We should change it to something more general like
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // pd_ThreadSelf_Init(), for instance.
a61af66fc99e Initial load
duke
parents:
diff changeset
104 //
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 static void AllocateTLSOffset ()
a61af66fc99e Initial load
duke
parents:
diff changeset
107 {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 int rslt ;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 TSSA_Entry tssa ;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 TSO_Entry tso ;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 ptrdiff_t off ;
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 guarantee (tlsMode == ThreadLocalStorage::pd_tlsAccessUndefined, "tlsMode not set") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 tlsMode = ThreadLocalStorage::pd_tlsAccessSlow ;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 tlsOffset = 0 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 #ifndef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 tssa = (TSSA_Entry) dlsym (RTLD_DEFAULT, "thr_slot_sync_allocate") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 if (tssa != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 off = -1 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 rslt = (*tssa)(&off, NULL, NULL) ; // (off,dtor,darg)
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if (off != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 tlsOffset = off ;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 tlsMode = ThreadLocalStorage::pd_tlsAccessIndirect ;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return ;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 rslt = thr_keycreate (&tlsKey, NULL) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (rslt != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 tlsMode = ThreadLocalStorage::pd_tlsAccessSlow ; // revert to slow mode
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return ;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 tso = (TSO_Entry) dlsym (RTLD_DEFAULT, "_thr_slot_offset") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 if (tso != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 off = (*tso)(tlsKey) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (off >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 tlsOffset = off ;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 tlsMode = ThreadLocalStorage::pd_tlsAccessDirect ;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return ;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // Failure: Too bad ... we've allocated a TLS slot we don't need and there's
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // no provision in the ABI for returning the slot.
a61af66fc99e Initial load
duke
parents:
diff changeset
147 //
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // If we didn't find a slot then then:
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // 1. We might be on liblwp.
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // 2. We might be on T2 libthread, but all "fast" slots are already
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // consumed
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // 3. We might be on T1, and all TSD (thr_slot_sync_allocate) slots are
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // consumed.
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // 4. We might be on T2 libthread, but it's be re-architected
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // so that fast slots are no longer g7-relative.
a61af66fc99e Initial load
duke
parents:
diff changeset
156 //
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 tlsMode = ThreadLocalStorage::pd_tlsAccessSlow ;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return ;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 void ThreadLocalStorage::generate_code_for_get_thread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 AllocateTLSOffset() ;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 void ThreadLocalStorage::set_thread_in_slot(Thread *thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 guarantee (tlsMode != pd_tlsAccessUndefined, "tlsMode not set") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 if (tlsMode == pd_tlsAccessIndirect) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
171 intptr_t tbase = fs_thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
172 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
173 intptr_t tbase = gs_thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
174 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
175 *((Thread**) (tbase + tlsOffset)) = thread ;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 } else
a61af66fc99e Initial load
duke
parents:
diff changeset
177 if (tlsMode == pd_tlsAccessDirect) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 thr_setspecific (tlsKey, (void *) thread) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // set with thr_setspecific and then readback with gs_load to validate.
a61af66fc99e Initial load
duke
parents:
diff changeset
180 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
181 guarantee (thread == fs_load(tlsOffset), "tls readback failure") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
183 guarantee (thread == gs_load(tlsOffset), "tls readback failure") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 extern "C" Thread* get_thread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 return ThreadLocalStorage::thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }