annotate src/os_cpu/solaris_x86/vm/threadLS_solaris_x86.cpp @ 4558:3706975946e4

Make graph dumping a bit more robust when there is no method, enable debug in the startCompiler method, add context and scope for snippets installation Made IGV display graphs even if some edges are problematic When schedule failed don't use it
author Gilles Duboscq <duboscq@ssw.jku.at>
date Fri, 10 Feb 2012 02:22:23 +0100
parents f95d63e2154a
children f34d701e952e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "runtime/threadLocalStorage.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "thread_solaris.inline.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
30 extern "C" Thread* fs_load(ptrdiff_t tlsOffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
31 extern "C" intptr_t fs_thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
32 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // From solaris_i486.s
a61af66fc99e Initial load
duke
parents:
diff changeset
34 extern "C" Thread* gs_load(ptrdiff_t tlsOffset);
a61af66fc99e Initial load
duke
parents:
diff changeset
35 extern "C" intptr_t gs_thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
36 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // tlsMode encoding:
a61af66fc99e Initial load
duke
parents:
diff changeset
39 //
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // pd_tlsAccessUndefined : uninitialized
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // pd_tlsAccessSlow : not available
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // pd_tlsAccessIndirect :
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // old-style indirect access - present in "T1" libthread.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // use thr_slot_sync_allocate() to attempt to allocate a slot.
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // pd_tlsAccessDirect :
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // new-style direct access - present in late-model "T2" libthread.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // Allocate the offset (slot) via _thr_slot_offset() or by
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // defining an IE- or LE-mode TLS/TSD slot in the launcher and then passing
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // that offset into libjvm.so.
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // See http://sac.eng/Archives/CaseLog/arc/PSARC/2003/159/.
a61af66fc99e Initial load
duke
parents:
diff changeset
51 //
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Note that we have a capability gap - some early model T2 forms
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // (e.g., unpatched S9) have neither _thr_slot_sync_allocate() nor
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // _thr_slot_offset(). In that case we revert to the usual
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // thr_getspecific accessor.
a61af66fc99e Initial load
duke
parents:
diff changeset
56 //
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 static ThreadLocalStorage::pd_tlsAccessMode tlsMode = ThreadLocalStorage::pd_tlsAccessUndefined ;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 static ptrdiff_t tlsOffset = 0 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 static thread_key_t tlsKey ;
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 typedef int (*TSSA_Entry) (ptrdiff_t *, int, int) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 typedef ptrdiff_t (*TSO_Entry) (int) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 ThreadLocalStorage::pd_tlsAccessMode ThreadLocalStorage::pd_getTlsAccessMode ()
a61af66fc99e Initial load
duke
parents:
diff changeset
66 {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 guarantee (tlsMode != pd_tlsAccessUndefined, "tlsMode not set") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return tlsMode ;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 ptrdiff_t ThreadLocalStorage::pd_getTlsOffset () {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 guarantee (tlsMode != pd_tlsAccessUndefined, "tlsMode not set") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return tlsOffset ;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // TODO: Consider the following improvements:
a61af66fc99e Initial load
duke
parents:
diff changeset
77 //
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // 1. Convert from thr_*specific* to pthread_*specific*.
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // The pthread_ forms are slightly faster. Also, the
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // pthread_ forms have a pthread_key_delete() API which
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // would aid in clean JVM shutdown and the eventual goal
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // of permitting a JVM to reinstantiate itself withing a process.
a61af66fc99e Initial load
duke
parents:
diff changeset
83 //
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // 2. See ThreadLocalStorage::init(). We end up allocating
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // two TLS keys during VM startup. That's benign, but we could collapse
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // down to one key without too much trouble.
a61af66fc99e Initial load
duke
parents:
diff changeset
87 //
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // 3. MacroAssembler::get_thread() currently emits calls to thr_getspecific().
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // Modify get_thread() to call Thread::current() instead.
a61af66fc99e Initial load
duke
parents:
diff changeset
90 //
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // 4. Thread::current() currently uses a cache keyed by %gs:[0].
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // (The JVM has PSARC permission to use %g7/%gs:[0]
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // as an opaque temporally unique thread identifier).
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // For C++ access to a thread's reflexive "self" pointer we
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // should consider using one of the following:
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // a. a radix tree keyed by %esp - as in EVM.
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // This requires two loads (the 2nd dependent on the 1st), but
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // is easily inlined and doesn't require a "miss" slow path.
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // b. a fast TLS/TSD slot allocated by _thr_slot_offset
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // or _thr_slot_sync_allocate.
a61af66fc99e Initial load
duke
parents:
diff changeset
101 //
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // 5. 'generate_code_for_get_thread' is a misnomer.
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // We should change it to something more general like
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // pd_ThreadSelf_Init(), for instance.
a61af66fc99e Initial load
duke
parents:
diff changeset
105 //
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 static void AllocateTLSOffset ()
a61af66fc99e Initial load
duke
parents:
diff changeset
108 {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 int rslt ;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 TSSA_Entry tssa ;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 TSO_Entry tso ;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 ptrdiff_t off ;
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 guarantee (tlsMode == ThreadLocalStorage::pd_tlsAccessUndefined, "tlsMode not set") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 tlsMode = ThreadLocalStorage::pd_tlsAccessSlow ;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 tlsOffset = 0 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 #ifndef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 tssa = (TSSA_Entry) dlsym (RTLD_DEFAULT, "thr_slot_sync_allocate") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if (tssa != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 off = -1 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 rslt = (*tssa)(&off, NULL, NULL) ; // (off,dtor,darg)
a61af66fc99e Initial load
duke
parents:
diff changeset
123 if (off != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 tlsOffset = off ;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 tlsMode = ThreadLocalStorage::pd_tlsAccessIndirect ;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return ;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 rslt = thr_keycreate (&tlsKey, NULL) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (rslt != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 tlsMode = ThreadLocalStorage::pd_tlsAccessSlow ; // revert to slow mode
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return ;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 tso = (TSO_Entry) dlsym (RTLD_DEFAULT, "_thr_slot_offset") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (tso != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 off = (*tso)(tlsKey) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (off >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 tlsOffset = off ;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 tlsMode = ThreadLocalStorage::pd_tlsAccessDirect ;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return ;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // Failure: Too bad ... we've allocated a TLS slot we don't need and there's
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // no provision in the ABI for returning the slot.
a61af66fc99e Initial load
duke
parents:
diff changeset
148 //
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // If we didn't find a slot then then:
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // 1. We might be on liblwp.
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // 2. We might be on T2 libthread, but all "fast" slots are already
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // consumed
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // 3. We might be on T1, and all TSD (thr_slot_sync_allocate) slots are
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // consumed.
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // 4. We might be on T2 libthread, but it's be re-architected
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // so that fast slots are no longer g7-relative.
a61af66fc99e Initial load
duke
parents:
diff changeset
157 //
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 tlsMode = ThreadLocalStorage::pd_tlsAccessSlow ;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 return ;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 void ThreadLocalStorage::generate_code_for_get_thread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 AllocateTLSOffset() ;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 void ThreadLocalStorage::set_thread_in_slot(Thread *thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 guarantee (tlsMode != pd_tlsAccessUndefined, "tlsMode not set") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 if (tlsMode == pd_tlsAccessIndirect) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
172 intptr_t tbase = fs_thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
173 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
174 intptr_t tbase = gs_thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
176 *((Thread**) (tbase + tlsOffset)) = thread ;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 } else
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (tlsMode == pd_tlsAccessDirect) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 thr_setspecific (tlsKey, (void *) thread) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // set with thr_setspecific and then readback with gs_load to validate.
a61af66fc99e Initial load
duke
parents:
diff changeset
181 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
182 guarantee (thread == fs_load(tlsOffset), "tls readback failure") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
184 guarantee (thread == gs_load(tlsOffset), "tls readback failure") ;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 #endif // AMD64
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
a61af66fc99e Initial load
duke
parents:
diff changeset
190 extern "C" Thread* get_thread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 return ThreadLocalStorage::thread();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }