Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/env/J9VMAccessCriticalSection.hpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2016 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 J9_VMACCESSCRITICALSECTION_INCL
24
#define J9_VMACCESSCRITICALSECTION_INCL
25
26
/*
27
* The following #define and typedef must appear before any #includes in this file
28
*/
29
#ifndef J9_VMACCESSCRITICALSECTION_CONNECTOR
30
#define J9_VMACCESSCRITICALSECTION_CONNECTOR
31
namespace J9 { class VMAccessCriticalSection; }
32
namespace J9 { typedef J9::VMAccessCriticalSection VMAccessCriticalSectionConnector; }
33
#endif
34
35
#include "env/OMRVMAccessCriticalSection.hpp"
36
#include "env/CompilerEnv.hpp"
37
#include "infra/Annotations.hpp"
38
#include "env/jittypes.h"
39
#include "env/VMJ9.h"
40
#include "j9.h"
41
42
namespace TR { class Compilation; }
43
44
namespace J9
45
{
46
47
class OMR_EXTENSIBLE VMAccessCriticalSection : public OMR::VMAccessCriticalSectionConnector
48
{
49
public:
50
51
VMAccessCriticalSection(
52
TR_J9VMBase *fej9,
53
VMAccessAcquireProtocol protocol,
54
TR::Compilation *comp) :
55
OMR::VMAccessCriticalSectionConnector(protocol, comp),
56
_fej9(fej9)
57
{
58
_initializedBySubClass = true;
59
switch (protocol)
60
{
61
case acquireVMAccessIfNeeded:
62
_acquiredVMAccess = TR::Compiler->vm.acquireVMAccessIfNeeded(fej9);
63
_hasVMAccess = true;
64
break;
65
66
case tryToAcquireVMAccess:
67
_hasVMAccess = TR::Compiler->vm.tryToAcquireAccess(comp, &_acquiredVMAccess);
68
break;
69
}
70
}
71
72
73
VMAccessCriticalSection(
74
TR::Compilation *comp,
75
VMAccessAcquireProtocol protocol) :
76
OMR::VMAccessCriticalSectionConnector(protocol, comp),
77
_fej9(NULL)
78
{
79
_initializedBySubClass = true;
80
switch (protocol)
81
{
82
case acquireVMAccessIfNeeded:
83
_acquiredVMAccess = TR::Compiler->vm.acquireVMAccessIfNeeded(comp->fej9());
84
_hasVMAccess = true;
85
break;
86
87
case tryToAcquireVMAccess:
88
_hasVMAccess = TR::Compiler->vm.tryToAcquireAccess(comp, &_acquiredVMAccess);
89
break;
90
}
91
}
92
93
~VMAccessCriticalSection()
94
{
95
if (!_vmAccessReleased)
96
{
97
if (_comp)
98
{
99
switch (_protocol)
100
{
101
case acquireVMAccessIfNeeded:
102
TR::Compiler->vm.releaseVMAccessIfNeeded(_comp, _acquiredVMAccess);
103
break;
104
105
case tryToAcquireVMAccess:
106
if (_hasVMAccess && _acquiredVMAccess)
107
{
108
TR::Compiler->vm.releaseAccess(_comp);
109
}
110
break;
111
}
112
}
113
else if (_fej9)
114
{
115
switch (_protocol)
116
{
117
case acquireVMAccessIfNeeded:
118
TR::Compiler->vm.releaseVMAccessIfNeeded(_fej9, _acquiredVMAccess);
119
break;
120
121
case tryToAcquireVMAccess:
122
if (_hasVMAccess && _acquiredVMAccess)
123
{
124
TR::Compiler->vm.releaseAccess(_fej9);
125
}
126
break;
127
}
128
}
129
130
_vmAccessReleased = true;
131
}
132
}
133
134
protected:
135
136
TR_J9VMBase *_fej9;
137
};
138
139
}
140
141
#endif
142
143