Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/control/JITServerHelpers.hpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2019, 2022 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_HELPERS_H
24
#define JITSERVER_HELPERS_H
25
26
#include "net/MessageTypes.hpp"
27
#include "runtime/JITClientSession.hpp"
28
29
30
class JITServerHelpers
31
{
32
public:
33
enum ClassInfoDataType
34
{
35
CLASSINFO_ROMCLASS_MODIFIERS,
36
CLASSINFO_ROMCLASS_EXTRAMODIFIERS,
37
CLASSINFO_BASE_COMPONENT_CLASS,
38
CLASSINFO_NUMBER_DIMENSIONS,
39
CLASSINFO_PARENT_CLASS,
40
CLASSINFO_INTERFACE_CLASS,
41
CLASSINFO_CLASS_HAS_FINAL_FIELDS,
42
CLASSINFO_CLASS_DEPTH_AND_FLAGS,
43
CLASSINFO_CLASS_INITIALIZED,
44
CLASSINFO_BYTE_OFFSET_TO_LOCKWORD,
45
CLASSINFO_LEAF_COMPONENT_CLASS,
46
CLASSINFO_CLASS_LOADER,
47
CLASSINFO_HOST_CLASS,
48
CLASSINFO_COMPONENT_CLASS,
49
CLASSINFO_ARRAY_CLASS,
50
CLASSINFO_TOTAL_INSTANCE_SIZE,
51
CLASSINFO_CLASS_OF_STATIC_CACHE,
52
CLASSINFO_REMOTE_ROM_CLASS,
53
CLASSINFO_CLASS_FLAGS,
54
CLASSINFO_METHODS_OF_CLASS,
55
CLASSINFO_CONSTANT_POOL,
56
CLASSINFO_CLASS_CHAIN_OFFSET_IDENTIFYING_LOADER,
57
CLASSINFO_ARRAY_ELEMENT_SIZE,
58
};
59
60
// NOTE: when adding new elements to this tuple, add them to the end,
61
// to not mess with the established order.
62
using ClassInfoTuple = std::tuple
63
<
64
std::string, // 0: _packedROMClass
65
J9Method *, // 1: _methodsOfClass
66
TR_OpaqueClassBlock *, // 2: _baseComponentClass
67
int32_t, // 3: _numDimensions
68
TR_OpaqueClassBlock *, // 4: _parentClass
69
std::vector<TR_OpaqueClassBlock *>,// 5: _tmpInterfaces
70
std::vector<uint8_t>, // 6: _methodTracingInfo
71
bool, // 7: _classHasFinalFields
72
uintptr_t, // 8: _classDepthAndFlags
73
bool, // 9: _classInitialized
74
uint32_t, // 10: _byteOffsetToLockword
75
TR_OpaqueClassBlock *, // 11: _leafComponentClass
76
void *, // 12: _classLoader
77
TR_OpaqueClassBlock *, // 13: _hostClass
78
TR_OpaqueClassBlock *, // 14: _componentClass
79
TR_OpaqueClassBlock *, // 15: _arrayClass
80
uintptr_t, // 16: _totalInstanceSize
81
J9ROMClass *, // 17: _remoteRomClass
82
uintptr_t, // 18: _constantPool
83
uintptr_t, // 19: _classFlags
84
uintptr_t, // 20: _classChainOffsetIdentifyingLoader
85
std::vector<J9ROMMethod *>, // 21: _origROMMethods
86
std::string, // 22: _classNameIdentifyingLoader
87
int32_t // 23: _arrayElementSize
88
>;
89
90
// Packs a ROMClass to be transferred to the server.
91
// The result is allocated from the stack region of trMemory (as well as temporary data
92
// structures used for packing). This function should be used with TR::StackMemoryRegion.
93
// If passed non-zero expectedSize, and it doesn't match the resulting packedSize
94
// (which is returned to the caller by reference), this function returns NULL.
95
static J9ROMClass *packROMClass(J9ROMClass *romClass, TR_Memory *trMemory, size_t &packedSize, size_t expectedSize = 0);
96
97
static ClassInfoTuple packRemoteROMClassInfo(J9Class *clazz, J9VMThread *vmThread, TR_Memory *trMemory, bool serializeClass);
98
static void freeRemoteROMClass(J9ROMClass *romClass, TR_PersistentMemory *persistentMemory);
99
static J9ROMClass *cacheRemoteROMClassOrFreeIt(ClientSessionData *clientSessionData, J9Class *clazz,
100
J9ROMClass *romClass, const ClassInfoTuple &classInfoTuple);
101
static ClientSessionData::ClassInfo &cacheRemoteROMClass(ClientSessionData *clientSessionData, J9Class *clazz,
102
J9ROMClass *romClass, const ClassInfoTuple &classInfoTuple);
103
static J9ROMClass *getRemoteROMClassIfCached(ClientSessionData *clientSessionData, J9Class *clazz);
104
static J9ROMClass *getRemoteROMClass(J9Class *clazz, JITServer::ServerStream *stream,
105
TR_PersistentMemory *persistentMemory, ClassInfoTuple &classInfoTuple);
106
static J9ROMClass *romClassFromString(const std::string &romClassStr, TR_PersistentMemory *persistentMemory);
107
static bool getAndCacheRAMClassInfo(J9Class *clazz, ClientSessionData *clientSessionData,
108
JITServer::ServerStream *stream, ClassInfoDataType dataType, void *data);
109
static bool getAndCacheRAMClassInfo(J9Class *clazz, ClientSessionData *clientSessionData,
110
JITServer::ServerStream *stream, ClassInfoDataType dataType1, void *data1,
111
ClassInfoDataType dataType2, void *data2);
112
static J9ROMMethod *romMethodOfRamMethod(J9Method* method);
113
114
static void insertIntoOOSequenceEntryList(ClientSessionData *clientData, TR_MethodToBeCompiled *entry);
115
116
static uintptr_t getRemoteClassDepthAndFlagsWhenROMClassNotCached(J9Class *clazz, ClientSessionData *clientSessionData,
117
JITServer::ServerStream *stream);
118
119
// Functions used for allowing the client to compile locally when server is unavailable.
120
// Should be used only on the client side.
121
static void postStreamFailure(OMRPortLibrary *portLibrary, TR::CompilationInfo *compInfo);
122
static bool shouldRetryConnection(OMRPortLibrary *portLibrary);
123
static void postStreamConnectionSuccess();
124
static bool isServerAvailable() { return _serverAvailable; }
125
126
static void printJITServerMsgStats(J9JITConfig *, TR::CompilationInfo *);
127
static void printJITServerCHTableStats(J9JITConfig *, TR::CompilationInfo *);
128
static void printJITServerCacheStats(J9JITConfig *, TR::CompilationInfo *);
129
130
static uint32_t serverMsgTypeCount[JITServer::MessageType_MAXTYPE];
131
132
static bool isAddressInROMClass(const void *address, const J9ROMClass *romClass);
133
134
static uintptr_t walkReferenceChainWithOffsets(TR_J9VM *fe, const std::vector<uintptr_t> &listOfOffsets, uintptr_t receiver);
135
136
// Called by the client as part of preparing the compilation request and handling the SharedCache_rememberClass message
137
// when AOT cache is enabled. Returns the list of RAMClasses in the class chain for clazz and populates uncachedRAMClasses
138
// and uncachedClassInfos with the classes (and their data) that the client has not yet sent to the server.
139
static std::vector<J9Class *>
140
getRAMClassChain(J9Class *clazz, size_t numClasses, J9VMThread *vmThread, TR_Memory *trMemory, TR::CompilationInfo *compInfo,
141
std::vector<J9Class *> &uncachedRAMClasses, std::vector<ClassInfoTuple> &uncachedClassInfos);
142
143
static void cacheRemoteROMClassBatch(ClientSessionData *clientData, const std::vector<J9Class *> &ramClasses,
144
const std::vector<ClassInfoTuple> &classInfoTuples);
145
146
private:
147
static void getROMClassData(const ClientSessionData::ClassInfo &classInfo, ClassInfoDataType dataType, void *data);
148
149
static TR::Monitor *getClientStreamMonitor()
150
{
151
if (!_clientStreamMonitor)
152
_clientStreamMonitor = TR::Monitor::create("clientStreamMonitor");
153
return _clientStreamMonitor;
154
}
155
156
static uint64_t _waitTimeMs;
157
static uint64_t _nextConnectionRetryTime;
158
static bool _serverAvailable;
159
static TR::Monitor * _clientStreamMonitor;
160
}; // class JITServerHelpers
161
162
#endif // defined(JITSERVER_HELPERS_H)
163
164