/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "runtime/threadLocalStorage.hpp"
#include "thread_solaris.inline.hpp"
#ifdef AMD64
#else
// From solaris_i486.s
#endif // AMD64
// tlsMode encoding:
//
// pd_tlsAccessUndefined : uninitialized
// pd_tlsAccessSlow : not available
// pd_tlsAccessIndirect :
// old-style indirect access - present in "T1" libthread.
// use thr_slot_sync_allocate() to attempt to allocate a slot.
// pd_tlsAccessDirect :
// new-style direct access - present in late-model "T2" libthread.
// Allocate the offset (slot) via _thr_slot_offset() or by
// that offset into libjvm.so.
//
// Note that we have a capability gap - some early model T2 forms
// (e.g., unpatched S9) have neither _thr_slot_sync_allocate() nor
// _thr_slot_offset(). In that case we revert to the usual
// thr_getspecific accessor.
//
{
return tlsMode ;
}
return tlsOffset ;
}
// TODO: Consider the following improvements:
//
// 1. Convert from thr_*specific* to pthread_*specific*.
// The pthread_ forms are slightly faster. Also, the
// pthread_ forms have a pthread_key_delete() API which
// would aid in clean JVM shutdown and the eventual goal
// of permitting a JVM to reinstantiate itself withing a process.
//
// 2. See ThreadLocalStorage::init(). We end up allocating
// two TLS keys during VM startup. That's benign, but we could collapse
// down to one key without too much trouble.
//
// 3. MacroAssembler::get_thread() currently emits calls to thr_getspecific().
// Modify get_thread() to call Thread::current() instead.
//
// 4. Thread::current() currently uses a cache keyed by %gs:[0].
// (The JVM has PSARC permission to use %g7/%gs:[0]
// as an opaque temporally unique thread identifier).
// For C++ access to a thread's reflexive "self" pointer we
// should consider using one of the following:
// a. a radix tree keyed by %esp - as in EVM.
// This requires two loads (the 2nd dependent on the 1st), but
// is easily inlined and doesn't require a "miss" slow path.
// or _thr_slot_sync_allocate.
//
// 5. 'generate_code_for_get_thread' is a misnomer.
// We should change it to something more general like
// pd_ThreadSelf_Init(), for instance.
//
static void AllocateTLSOffset ()
{
int rslt ;
tlsOffset = 0 ;
#ifndef AMD64
off = -1 ;
if (off != -1) {
return ;
}
}
if (rslt != 0) {
return ;
}
if (off >= 0) {
return ;
}
}
// Failure: Too bad ... we've allocated a TLS slot we don't need and there's
// no provision in the ABI for returning the slot.
//
// If we didn't find a slot then then:
// 1. We might be on liblwp.
// 2. We might be on T2 libthread, but all "fast" slots are already
// consumed
// 3. We might be on T1, and all TSD (thr_slot_sync_allocate) slots are
// consumed.
// 4. We might be on T2 libthread, but it's be re-architected
// so that fast slots are no longer g7-relative.
//
return ;
#endif // AMD64
}
}
if (tlsMode == pd_tlsAccessIndirect) {
#ifdef AMD64
#else
#endif // AMD64
} else
if (tlsMode == pd_tlsAccessDirect) {
// set with thr_setspecific and then readback with gs_load to validate.
#ifdef AMD64
#else
#endif // AMD64
}
}
return ThreadLocalStorage::thread();
}