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