Wed, 31 Jan 2018 19:24:57 -0500
8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed
simonis@6465 | 1 | /* |
simonis@6465 | 2 | * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
goetz@6515 | 3 | * Copyright 2012, 2014 SAP AG. All rights reserved. |
simonis@6465 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
simonis@6465 | 5 | * |
simonis@6465 | 6 | * This code is free software; you can redistribute it and/or modify it |
simonis@6465 | 7 | * under the terms of the GNU General Public License version 2 only, as |
simonis@6465 | 8 | * published by the Free Software Foundation. |
simonis@6465 | 9 | * |
simonis@6465 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
simonis@6465 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
simonis@6465 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
simonis@6465 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
simonis@6465 | 14 | * accompanied this code). |
simonis@6465 | 15 | * |
simonis@6465 | 16 | * You should have received a copy of the GNU General Public License version |
simonis@6465 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
simonis@6465 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
simonis@6465 | 19 | * |
simonis@6465 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
simonis@6465 | 21 | * or visit www.oracle.com if you need additional information or have any |
simonis@6465 | 22 | * questions. |
simonis@6465 | 23 | * |
simonis@6465 | 24 | */ |
simonis@6465 | 25 | |
simonis@6465 | 26 | #include "precompiled.hpp" |
simonis@6465 | 27 | #include "runtime/threadCritical.hpp" |
goetz@6515 | 28 | #include "runtime/thread.inline.hpp" |
simonis@6465 | 29 | |
simonis@6465 | 30 | // put OS-includes here |
simonis@6465 | 31 | # include <pthread.h> |
simonis@6465 | 32 | |
simonis@6465 | 33 | // |
simonis@6465 | 34 | // See threadCritical.hpp for details of this class. |
simonis@6465 | 35 | // |
simonis@6465 | 36 | |
simonis@6465 | 37 | static pthread_t tc_owner = 0; |
simonis@6465 | 38 | static pthread_mutex_t tc_mutex = PTHREAD_MUTEX_INITIALIZER; |
simonis@6465 | 39 | static int tc_count = 0; |
simonis@6465 | 40 | |
simonis@6465 | 41 | void ThreadCritical::initialize() { |
simonis@6465 | 42 | } |
simonis@6465 | 43 | |
simonis@6465 | 44 | void ThreadCritical::release() { |
simonis@6465 | 45 | } |
simonis@6465 | 46 | |
simonis@6465 | 47 | ThreadCritical::ThreadCritical() { |
simonis@6465 | 48 | pthread_t self = pthread_self(); |
simonis@6465 | 49 | if (self != tc_owner) { |
simonis@6465 | 50 | int ret = pthread_mutex_lock(&tc_mutex); |
simonis@6465 | 51 | guarantee(ret == 0, "fatal error with pthread_mutex_lock()"); |
simonis@6465 | 52 | assert(tc_count == 0, "Lock acquired with illegal reentry count."); |
simonis@6465 | 53 | tc_owner = self; |
simonis@6465 | 54 | } |
simonis@6465 | 55 | tc_count++; |
simonis@6465 | 56 | } |
simonis@6465 | 57 | |
simonis@6465 | 58 | ThreadCritical::~ThreadCritical() { |
simonis@6465 | 59 | assert(tc_owner == pthread_self(), "must have correct owner"); |
simonis@6465 | 60 | assert(tc_count > 0, "must have correct count"); |
simonis@6465 | 61 | |
simonis@6465 | 62 | tc_count--; |
simonis@6465 | 63 | if (tc_count == 0) { |
simonis@6465 | 64 | tc_owner = 0; |
simonis@6465 | 65 | int ret = pthread_mutex_unlock(&tc_mutex); |
simonis@6465 | 66 | guarantee(ret == 0, "fatal error with pthread_mutex_unlock()"); |
simonis@6465 | 67 | } |
simonis@6465 | 68 | } |