aoqi@0: /* aoqi@0: * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_RUNTIME_THREADCRITICAL_HPP aoqi@0: #define SHARE_VM_RUNTIME_THREADCRITICAL_HPP aoqi@0: aoqi@0: #include "memory/allocation.hpp" aoqi@0: aoqi@0: // ThreadCritical is used to protect short non-blocking critical sections. aoqi@0: // This class must use no vm facilities that require initialization. aoqi@0: // It is used very early in the vm's initialization, in allocation aoqi@0: // code and other areas. ThreadCritical regions are reentrant. aoqi@0: // aoqi@0: // Due to race conditions during vm exit, some of the os level aoqi@0: // synchronization primitives may not be deallocated at exit. It aoqi@0: // is a good plan to implement the platform dependent sections of aoqi@0: // code with resources that are recoverable during process aoqi@0: // cleanup by the os. Calling the initialize method before use aoqi@0: // is also problematic, it is best to use preinitialized primitives aoqi@0: // if possible. As an example: aoqi@0: // aoqi@0: // mutex_t mp = DEFAULTMUTEX; aoqi@0: // aoqi@0: // Also note that this class is declared as a StackObj to enforce aoqi@0: // block structured short locks. It cannot be declared a ResourceObj aoqi@0: // or CHeapObj, due to initialization issues. aoqi@0: aoqi@0: class ThreadCritical : public StackObj { aoqi@0: friend class os; aoqi@0: private: aoqi@0: static void initialize(); aoqi@0: static void release(); aoqi@0: aoqi@0: public: aoqi@0: ThreadCritical(); aoqi@0: ~ThreadCritical(); aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_RUNTIME_THREADCRITICAL_HPP