Path: blob/master/runtime/compiler/env/ClassTableCriticalSection.hpp
6000 views
/*******************************************************************************1* Copyright (c) 2000, 2019 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122#ifndef TR_CLASSTABLECRITICALSECTION_INCL23#define TR_CLASSTABLECRITICALSECTION_INCL2425#include "env/FrontEnd.hpp"26#include "env/VMJ9.h"2728namespace TR29{3031/**32* @brief The TR::ClassTableCriticalSection class wraps acquireClassTableMutex33* with RAII functionality to help automate the lifetime of the Class Table Mutex.34* Implicit in the call to acquireClassTableMutex is the acquisition of VMAccess.35*/36class ClassTableCriticalSection37{38public:3940/**41* @brief Declare the beginning of a critical section, constructing the42* TR::ClassTableCriticalSection object and acquiring the Class Table Mutex.43* @param fe The TR_FrontEnd object used to acquire the Class Table Mutex44* @param locked An optional parameter to prevent reacquiring the Class Table Mutex if45* it has already been acquired46*/47ClassTableCriticalSection(TR_FrontEnd *fe, bool locked = false)48: _locked(locked),49_acquiredVMAccess(false),50_fe(fe)51{52if (!locked)53{54TR_J9VMBase *fej9 = (TR_J9VMBase *)_fe;55_acquiredVMAccess = fej9->acquireClassTableMutex();56}57}5859/**60* @brief Automatically notify the end of the critical section, destroying the61* TR::ClassTableCriticalSection object and releasing the Class Table Mutex.62*/63~ClassTableCriticalSection()64{65if (!_locked)66{67TR_J9VMBase *fej9 = (TR_J9VMBase *)_fe;68fej9->releaseClassTableMutex(_acquiredVMAccess);69}70}7172/**73* @brief Used to determine if VMAccess was acquired.74*/75bool acquiredVMAccess() const { return _acquiredVMAccess; }767778private:7980bool _locked;81bool _acquiredVMAccess;82TR_FrontEnd *_fe;83};8485}8687#endif // TR_CLASSTABLECRITICALSECTION_INCL888990