Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/control/JITServerCompilationThread.hpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2018, 2021 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 JITSERVER_COMPILATION_THREAD_H
24
#define JITSERVER_COMPILATION_THREAD_H
25
26
#include "control/CompilationThread.hpp"
27
#include "env/j9methodServer.hpp"
28
#include "runtime/JITClientSession.hpp"
29
30
class TR_IPBytecodeHashTableEntry;
31
32
using IPTableHeapEntry = UnorderedMap<uint32_t, TR_IPBytecodeHashTableEntry*>;
33
using IPTableHeap_t = UnorderedMap<J9Method *, IPTableHeapEntry *>;
34
using ResolvedMirrorMethodsPersistIP_t = Vector<TR_ResolvedJ9Method *>;
35
using ClassOfStatic_t = UnorderedMap<std::pair<TR_OpaqueClassBlock *, int32_t>, TR_OpaqueClassBlock *>;
36
using FieldOrStaticAttrTable_t = UnorderedMap<std::pair<TR_OpaqueClassBlock *, int32_t>, TR_J9MethodFieldAttributes>;
37
38
void outOfProcessCompilationEnd(TR_MethodToBeCompiled *entry, TR::Compilation *comp);
39
40
namespace TR
41
{
42
// Objects of this type are instantiated at JITServer
43
class CompilationInfoPerThreadRemote : public TR::CompilationInfoPerThread
44
{
45
public:
46
friend class TR::CompilationInfo;
47
CompilationInfoPerThreadRemote(TR::CompilationInfo &compInfo, J9JITConfig *jitConfig, int32_t id, bool isDiagnosticThread);
48
49
virtual void processEntry(TR_MethodToBeCompiled &entry, J9::J9SegmentProvider &scratchSegmentProvider) override;
50
TR_PersistentMethodInfo *getRecompilationMethodInfo() const { return _recompilationMethodInfo; }
51
52
uint32_t getSeqNo() const { return _seqNo; }; // For ordering requests at the server
53
void setSeqNo(uint32_t seqNo) { _seqNo = seqNo; }
54
uint32_t getExpectedSeqNo() const { return _expectedSeqNo; }
55
void setExpectedSeqNo(uint32_t seqNo) { _expectedSeqNo = seqNo; }
56
57
void notifyAndDetachWaitingRequests(ClientSessionData *clientSession);
58
void waitForMyTurn(ClientSessionData *clientSession, TR_MethodToBeCompiled &entry); // Return false if timeout
59
bool getWaitToBeNotified() const { return _waitToBeNotified; }
60
void setWaitToBeNotified(bool b) { _waitToBeNotified = b; }
61
static int32_t getNumClearedCaches() { return _numClearedCaches; }
62
void incNumClearedCaches() { _numClearedCaches++; }
63
64
void copyClientOptions(const std::string &clientOptStr, TR_PersistentMemory *persistentMemory)
65
{
66
size_t clientOptSize = clientOptStr.size();
67
_clientOptionsSize = clientOptSize;
68
_clientOptions = new (persistentMemory->_persistentAllocator.get()) char[clientOptSize];
69
memcpy(_clientOptions, clientOptStr.data(), clientOptSize);
70
}
71
72
void deleteClientOptions(TR_PersistentMemory *persistentMemory)
73
{
74
if (_clientOptions)
75
{
76
persistentMemory->freePersistentMemory(_clientOptions);
77
_clientOptions = NULL;
78
_clientOptionsSize = 0;
79
}
80
}
81
82
char *getClientOptions() { return _clientOptions; }
83
size_t getClientOptionsSize() { return _clientOptionsSize; }
84
85
bool cacheIProfilerInfo(TR_OpaqueMethodBlock *method, uint32_t byteCodeIndex, TR_IPBytecodeHashTableEntry *entry);
86
TR_IPBytecodeHashTableEntry *getCachedIProfilerInfo(TR_OpaqueMethodBlock *method, uint32_t byteCodeIndex, bool *methodInfoPresent);
87
88
void cacheResolvedMethod(TR_ResolvedMethodKey key, TR_OpaqueMethodBlock *method, uint32_t vTableSlot, const TR_ResolvedJ9JITServerMethodInfo &methodInfo, int32_t ttlForUnresolved = 2);
89
bool getCachedResolvedMethod(TR_ResolvedMethodKey key, TR_ResolvedJ9JITServerMethod *owningMethod, TR_ResolvedMethod **resolvedMethod, bool *unresolvedInCP = NULL);
90
TR_ResolvedMethodKey getResolvedMethodKey(TR_ResolvedMethodType type, TR_OpaqueClassBlock *ramClass, int32_t cpIndex, TR_OpaqueClassBlock *classObject = NULL);
91
92
void cacheResolvedMirrorMethodsPersistIPInfo(TR_ResolvedJ9Method *resolvedMethod);
93
ResolvedMirrorMethodsPersistIP_t *getCachedResolvedMirrorMethodsPersistIPInfo() const { return _resolvedMirrorMethodsPersistIPInfo; }
94
95
void cacheNullClassOfStatic(TR_OpaqueClassBlock *ramClass, int32_t cpIndex);
96
bool getCachedNullClassOfStatic(TR_OpaqueClassBlock *ramClass, int32_t cpIndex);
97
98
void cacheFieldOrStaticAttributes(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, const TR_J9MethodFieldAttributes &attrs, bool isStatic);
99
bool getCachedFieldOrStaticAttributes(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, TR_J9MethodFieldAttributes &attrs, bool isStatic);
100
101
void cacheIsUnresolvedStr(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, const TR_IsUnresolvedString &stringAttrs);
102
bool getCachedIsUnresolvedStr(TR_OpaqueClassBlock *ramClass, int32_t cpIndex, TR_IsUnresolvedString &stringAttrs);
103
104
void clearPerCompilationCaches();
105
void deleteClientSessionData(uint64_t clientId, TR::CompilationInfo* compInfo, J9VMThread* compThread);
106
virtual void freeAllResources() override;
107
108
void incrementClassUnloadReadMutexDepth() { _classUnloadReadMutexDepth++; }
109
void decrementClassUnloadReadMutexDepth() { _classUnloadReadMutexDepth--; }
110
int32_t getClassUnloadReadMutexDepth() { return _classUnloadReadMutexDepth; }
111
112
bool isAOTCacheStore() const { return _aotCacheStore; }
113
uint32_t getMethodIndex() const { return _methodIndex; }
114
const AOTCacheClassChainRecord *getDefiningClassChainRecord() { return _definingClassChainRecord; }
115
116
private:
117
/* Template method for allocating a cache of type T on the heap.
118
* Cache pointer must be NULL.
119
*/
120
template <typename T>
121
bool initializePerCompilationCache(T* &cache)
122
{
123
// Initialize map
124
TR_ASSERT(!cache, "Cache already initialized");
125
TR_Memory *trMemory = getCompilation()->trMemory();
126
cache = new (trMemory->trHeapMemory()) T(typename T::allocator_type(trMemory->heapMemoryRegion()));
127
return cache != NULL;
128
}
129
130
/* Template method for storing key-value pairs (of types K and V respectively)
131
* to a heap-allocated unordered map.
132
* If a map is NULL, will allocate it.
133
*/
134
template <typename K, typename V>
135
void cacheToPerCompilationMap(UnorderedMap<K, V>* &map, const K &key, const V &value)
136
{
137
if (!map)
138
initializePerCompilationCache(map);
139
map->insert({ key, value });
140
}
141
142
/* Template method for retrieving values from heap-allocated unordered map.
143
* If the map is NULL or value is not found, returns false.
144
* Otherwise, sets value to retrieved value and returns true
145
*/
146
template <typename K, typename V>
147
bool getCachedValueFromPerCompilationMap(UnorderedMap<K, V>* &map, const K &key, V &value)
148
{
149
if (!map)
150
return false;
151
auto it = map->find(key);
152
if (it != map->end())
153
{
154
// Found entry at a given key
155
value = it->second;
156
return true;
157
}
158
return false;
159
}
160
161
/* Template method for clearing a heap-allocated cache.
162
* Simply sets pointer to cache to NULL.
163
*/
164
template <typename T>
165
void clearPerCompilationCache(T* &cache)
166
{
167
// Since cache was heap-allocated,
168
// memory will be released automatically at the end of the compilation
169
cache = NULL;
170
}
171
172
bool serveCachedAOTMethod(TR_MethodToBeCompiled &entry, J9Method *method, J9Class *definingClass,
173
TR_OptimizationPlan *optPlan, ClientSessionData *clientData,
174
J9::J9SegmentProvider &scratchSegmentProvider);
175
176
TR_PersistentMethodInfo *_recompilationMethodInfo;
177
uint32_t _seqNo;
178
uint32_t _expectedSeqNo; // this request is allowed to go if _expectedSeqNo is processed
179
bool _waitToBeNotified; // accessed with clientSession->_sequencingMonitor in hand
180
char *_clientOptions;
181
size_t _clientOptionsSize;
182
IPTableHeap_t *_methodIPDataPerComp;
183
TR_ResolvedMethodInfoCache *_resolvedMethodInfoMap;
184
ResolvedMirrorMethodsPersistIP_t *_resolvedMirrorMethodsPersistIPInfo; // list of mirrors of resolved methods for persisting IProfiler info
185
ClassOfStatic_t *_classOfStaticMap;
186
FieldOrStaticAttrTable_t *_fieldAttributesCache;
187
FieldOrStaticAttrTable_t *_staticAttributesCache;
188
UnorderedMap<std::pair<TR_OpaqueClassBlock *, int32_t>, TR_IsUnresolvedString> *_isUnresolvedStrCache;
189
int32_t _classUnloadReadMutexDepth;
190
bool _aotCacheStore; // True if the result of this compilation will be stored in AOT cache
191
uint32_t _methodIndex; // Index of the method being compiled in the array of methods of its defining class
192
const AOTCacheClassChainRecord *_definingClassChainRecord; // Used to store the result of the compilation in AOT cache
193
194
static int32_t _numClearedCaches; // number of instances JITServer was forced to clear its internal per-client caches
195
196
}; // class CompilationInfoPerThreadRemote
197
} // namespace TR
198
199
#endif // defined(JITSERVER_COMPILATION_THREAD_H)
200
201