Path: blob/master/src/hotspot/os/windows/threadLocalStorage_windows.cpp
40931 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "runtime/threadLocalStorage.hpp"26#include <windows.h>2728static DWORD _thread_key;29static bool _initialized = false;303132void ThreadLocalStorage::init() {33assert(!_initialized, "initializing TLS more than once!");34_thread_key = TlsAlloc();35// If this assert fails we will get a recursive assertion failure36// and not see the actual error message or get a hs_err file37assert(_thread_key != TLS_OUT_OF_INDEXES, "TlsAlloc failed: out of indices");38_initialized = true;39}4041bool ThreadLocalStorage::is_initialized() {42return _initialized;43}4445Thread* ThreadLocalStorage::thread() {46// If this assert fails we will get a recursive assertion failure47// and not see the actual error message or get a hs_err file.48// Which most likely indicates we have taken an error path early in49// the initialization process, which is using Thread::current without50// checking TLS is initialized - see java.cpp vm_exit51assert(_initialized, "TLS not initialized yet!");52Thread* current = (Thread*) TlsGetValue(_thread_key);53assert(current != 0 || GetLastError() == ERROR_SUCCESS,54"TlsGetValue failed with error code: %lu", GetLastError());55return current;56}5758void ThreadLocalStorage::set_thread(Thread* current) {59assert(_initialized, "TLS not initialized yet!");60BOOL res = TlsSetValue(_thread_key, current);61assert(res, "TlsSetValue failed with error code: %lu", GetLastError());62}636465