threadLocalStorage.hpp revision 242:d95b224e9f17
1100966Siwasaki/*
2100966Siwasaki * Copyright 1997-2003 Sun Microsystems, Inc.  All Rights Reserved.
3100966Siwasaki * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4100966Siwasaki *
5100966Siwasaki * This code is free software; you can redistribute it and/or modify it
6100966Siwasaki * under the terms of the GNU General Public License version 2 only, as
7217365Sjkim * published by the Free Software Foundation.
8229989Sjkim *
9100966Siwasaki * This code is distributed in the hope that it will be useful, but WITHOUT
10100966Siwasaki * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11217365Sjkim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12217365Sjkim * version 2 for more details (a copy is included in the LICENSE file that
13217365Sjkim * accompanied this code).
14217365Sjkim *
15217365Sjkim * You should have received a copy of the GNU General Public License version
16217365Sjkim * 2 along with this work; if not, write to the Free Software Foundation,
17217365Sjkim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18217365Sjkim *
19217365Sjkim * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20217365Sjkim * CA 95054 USA or visit www.sun.com if you need additional information or
21217365Sjkim * have any questions.
22217365Sjkim *
23217365Sjkim */
24217365Sjkim
25100966Siwasaki// Interface for thread local storage
26217365Sjkim
27217365Sjkim// Fast variant of ThreadLocalStorage::get_thread_slow
28217365Sjkimextern "C" Thread*   get_thread();
29100966Siwasaki
30217365Sjkim// Get raw thread id: e.g., %g7 on sparc, fs or gs on x86
31217365Sjkimextern "C" uintptr_t _raw_thread_id();
32217365Sjkim
33217365Sjkimclass ThreadLocalStorage : AllStatic {
34217365Sjkim public:
35217365Sjkim  static void    set_thread(Thread* thread);
36217365Sjkim  static Thread* get_thread_slow();
37217365Sjkim  static void    invalidate_all() { pd_invalidate_all(); }
38217365Sjkim
39217365Sjkim  // Machine dependent stuff
40217365Sjkim  #include "incls/_threadLS_pd.hpp.incl"
41217365Sjkim
42217365Sjkim public:
43100966Siwasaki  // Accessor
44100966Siwasaki  static inline int  thread_index()              { return _thread_index; }
45100966Siwasaki  static inline void set_thread_index(int index) { _thread_index = index; }
46100966Siwasaki
47193341Sjkim  // Initialization
48100966Siwasaki  // Called explicitly from VMThread::activate_system instead of init_globals.
49100966Siwasaki  static void init();
50100966Siwasaki  static bool is_initialized();
51100966Siwasaki
52100966Siwasaki private:
53100966Siwasaki  static int     _thread_index;
54167802Sjkim
55100966Siwasaki  static void    generate_code_for_get_thread();
56217365Sjkim
57217365Sjkim  // Processor dependent parts of set_thread and initialization
58217365Sjkim  static void pd_set_thread(Thread* thread);
59217365Sjkim  static void pd_init();
60217365Sjkim  // Invalidate any thread cacheing or optimization schemes.
61128212Snjl  static void pd_invalidate_all();
62217365Sjkim
63167802Sjkim};
64167802Sjkim