Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/env/ClassTableCriticalSection.hpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2019 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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-exception
21
*******************************************************************************/
22
23
#ifndef TR_CLASSTABLECRITICALSECTION_INCL
24
#define TR_CLASSTABLECRITICALSECTION_INCL
25
26
#include "env/FrontEnd.hpp"
27
#include "env/VMJ9.h"
28
29
namespace TR
30
{
31
32
/**
33
* @brief The TR::ClassTableCriticalSection class wraps acquireClassTableMutex
34
* with RAII functionality to help automate the lifetime of the Class Table Mutex.
35
* Implicit in the call to acquireClassTableMutex is the acquisition of VMAccess.
36
*/
37
class ClassTableCriticalSection
38
{
39
public:
40
41
/**
42
* @brief Declare the beginning of a critical section, constructing the
43
* TR::ClassTableCriticalSection object and acquiring the Class Table Mutex.
44
* @param fe The TR_FrontEnd object used to acquire the Class Table Mutex
45
* @param locked An optional parameter to prevent reacquiring the Class Table Mutex if
46
* it has already been acquired
47
*/
48
ClassTableCriticalSection(TR_FrontEnd *fe, bool locked = false)
49
: _locked(locked),
50
_acquiredVMAccess(false),
51
_fe(fe)
52
{
53
if (!locked)
54
{
55
TR_J9VMBase *fej9 = (TR_J9VMBase *)_fe;
56
_acquiredVMAccess = fej9->acquireClassTableMutex();
57
}
58
}
59
60
/**
61
* @brief Automatically notify the end of the critical section, destroying the
62
* TR::ClassTableCriticalSection object and releasing the Class Table Mutex.
63
*/
64
~ClassTableCriticalSection()
65
{
66
if (!_locked)
67
{
68
TR_J9VMBase *fej9 = (TR_J9VMBase *)_fe;
69
fej9->releaseClassTableMutex(_acquiredVMAccess);
70
}
71
}
72
73
/**
74
* @brief Used to determine if VMAccess was acquired.
75
*/
76
bool acquiredVMAccess() const { return _acquiredVMAccess; }
77
78
79
private:
80
81
bool _locked;
82
bool _acquiredVMAccess;
83
TR_FrontEnd *_fe;
84
};
85
86
}
87
88
#endif // TR_CLASSTABLECRITICALSECTION_INCL
89
90