duke@435: /* dholmes@8187: * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@4299: #include "runtime/thread.inline.hpp" stefank@2314: #include "runtime/threadLocalStorage.hpp" stefank@2314: #ifdef TARGET_OS_FAMILY_linux stefank@2314: # include "os_linux.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_FAMILY_solaris stefank@2314: # include "os_solaris.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_FAMILY_windows stefank@2314: # include "os_windows.inline.hpp" stefank@2314: #endif never@3156: #ifdef TARGET_OS_FAMILY_bsd never@3156: # include "os_bsd.inline.hpp" never@3156: #endif duke@435: dholmes@8187: // Solaris no longer has this kind of ThreadLocalStorage implementation. dholmes@8187: // This will be removed from all platforms in the near future. dholmes@8187: dholmes@8187: #ifndef SOLARIS dholmes@8187: duke@435: // static member initialization duke@435: int ThreadLocalStorage::_thread_index = -1; duke@435: duke@435: Thread* ThreadLocalStorage::get_thread_slow() { duke@435: return (Thread*) os::thread_local_storage_at(ThreadLocalStorage::thread_index()); duke@435: } duke@435: duke@435: void ThreadLocalStorage::set_thread(Thread* thread) { duke@435: pd_set_thread(thread); duke@435: duke@435: // The following ensure that any optimization tricks we have tried duke@435: // did not backfire on us: duke@435: guarantee(get_thread() == thread, "must be the same thread, quickly"); duke@435: guarantee(get_thread_slow() == thread, "must be the same thread, slowly"); duke@435: } duke@435: duke@435: void ThreadLocalStorage::init() { kamg@677: assert(!is_initialized(), kamg@677: "More than one attempt to initialize threadLocalStorage"); duke@435: pd_init(); duke@435: set_thread_index(os::allocate_thread_local_storage()); duke@435: generate_code_for_get_thread(); duke@435: } kamg@677: kamg@677: bool ThreadLocalStorage::is_initialized() { kamg@677: return (thread_index() != -1); kamg@677: } dholmes@8187: dholmes@8187: #endif // SOLARIS