Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/env/J9PersistentInfo.hpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 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 J9_PERSISTENTINFO_HPP
24
#define J9_PERSISTENTINFO_HPP
25
26
#ifndef J9_PERSISTENTINFO_CONNECTOR
27
#define J9_PERSISTENTINFO_CONNECTOR
28
namespace J9 { class PersistentInfo; }
29
namespace J9 { typedef J9::PersistentInfo PersistentInfoConnector; }
30
#endif
31
32
#include "env/OMRPersistentInfo.hpp"
33
#include "env/RuntimeAssumptionTable.hpp"
34
35
#include <stdint.h>
36
#if defined(J9VM_OPT_JITSERVER)
37
#include <string>
38
#endif /* defined(J9VM_OPT_JITSERVER) */
39
#include "env/jittypes.h"
40
41
class TR_FrontEnd;
42
class TR_PersistentMemory;
43
class TR_PersistentCHTable;
44
class TR_PersistentClassLoaderTable;
45
class TR_J2IThunkTable;
46
namespace J9 { class Options; }
47
48
enum JitStates {
49
UNDEFINED_STATE = 0,
50
IDLE_STATE,
51
STARTUP_STATE,
52
RAMPUP_STATE,
53
STEADY_STATE,
54
DEEPSTEADY_STATE,
55
};
56
57
enum IprofilerStates {
58
IPROFILING_STATE_ON = 1,
59
IPROFILING_STATE_GOING_OFF,
60
IPROFILING_STATE_OFF,
61
};
62
63
#if defined(J9VM_OPT_JITSERVER)
64
namespace JITServer
65
{
66
enum RemoteCompilationModes
67
{
68
NONE = 0,
69
CLIENT,
70
SERVER,
71
};
72
73
enum ServerMemoryState
74
{
75
VERY_LOW = 0,
76
LOW,
77
NORMAL,
78
};
79
80
enum ServerActiveThreadsState
81
{
82
VERY_HIGH_THREAD = 0,
83
HIGH_THREAD,
84
NORMAL_THREAD,
85
};
86
87
enum CompThreadActivationPolicy
88
{
89
// Order is important, we use comparison operators
90
// on policy states and for indexing into the name array
91
SUSPEND = 0,
92
MAINTAIN,
93
SUBDUE,
94
AGGRESSIVE,
95
};
96
97
static const char *compThreadActivationPolicyNames[] = {
98
"SUSPEND",
99
"MAINTAIN",
100
"SUBDUE",
101
"AGGRESSIVE",
102
};
103
}
104
#endif /* defined(J9VM_OPT_JITSERVER) */
105
106
#define MAX_SUPERCLASSES (20000)
107
namespace J9
108
{
109
110
class PersistentInfo : public OMR::PersistentInfoConnector
111
{
112
friend class J9::Options;
113
114
public:
115
116
PersistentInfo(TR_PersistentMemory *pm) :
117
#pragma warning( suppress : 4351 )
118
_paddingBefore(),
119
_countForRecompile(0),
120
_numLoadedClasses(0),
121
_classLoadingPhase(false),
122
_inlinerTemporarilyRestricted(false),
123
_elapsedTime(0),
124
_unloadedClassAddresses(NULL),
125
_unloadedMethodAddresses(NULL),
126
_runtimeAssumptionTable(),
127
_persistentCHTable(NULL),
128
_visitedSuperClasses(NULL),
129
_numVisitedSuperClasses(0),
130
_tooManySuperClasses(false),
131
_persistentClassLoaderTable(NULL),
132
_GCwillBlockOnClassUnloadMonitor(false),
133
_timeGCwillBlockOnClassUnloadMonitorWasSet(0),
134
_numUnloadedClasses(0),
135
_classLoadingPhaseGracePeriod(0),
136
_startTime(0),
137
_globalClassUnloadID(0),
138
_externalStartupEndedSignal(false),
139
_disableFurtherCompilation(false),
140
_loadFactor(1),
141
_jitState(STARTUP_STATE),
142
_jitStateChangeSampleCount(0),
143
_jitTotalSampleCount(0),
144
_jitSampleCountWhenActiveStateEntered(0),
145
_jitSampleCountWhenStartupStateEntered(0),
146
_jitSampleCountWhenStartupStateExited(0),
147
_vmTotalCpuTimeWhenStartupStateEntered(0),
148
_vmTotalCpuTimeWhenStartupStateExited(0),
149
_inliningAggressiveness(100),
150
_lastTimeSamplerThreadEnteredIdle(0),
151
_lastTimeSamplerThreadEnteredDeepIdle(0),
152
_lastTimeSamplerThreadWasSuspended(0),
153
_lastTimeThreadsWereActive(0),
154
_gcMapCheckEventHandleKey(0),
155
_statNumGCRBodies(0),
156
_statNumGCRSaves(0),
157
_invokeExactJ2IThunkTable(NULL),
158
_gpuInitMonitor(NULL),
159
_runtimeInstrumentationEnabled(false),
160
_runtimeInstrumentationRecompilationEnabled(false),
161
#if defined(J9VM_OPT_JITSERVER)
162
_JITServerAddress("localhost"),
163
_JITServerPort(38400),
164
_socketTimeoutMs(2000),
165
_clientUID(0),
166
_JITServerUseAOTCache(false),
167
_requireJITServer(false),
168
_localSyncCompiles(false),
169
_JITServerAOTCacheName(),
170
#endif /* defined(J9VM_OPT_JITSERVER) */
171
OMR::PersistentInfoConnector(pm)
172
{}
173
174
void setPersistentClassLoaderTable(TR_PersistentClassLoaderTable *table) { _persistentClassLoaderTable = table; }
175
TR_PersistentClassLoaderTable *getPersistentClassLoaderTable() { return _persistentClassLoaderTable; }
176
177
TR_OpaqueClassBlock **getVisitedSuperClasses() { return _visitedSuperClasses; }
178
void clearVisitedSuperClasses() { _tooManySuperClasses = false; _numVisitedSuperClasses = 0; }
179
void setVisitedSuperClasses(TR_OpaqueClassBlock **v) { _visitedSuperClasses = v; }
180
bool tooManySuperClasses() { return _tooManySuperClasses; }
181
void setTooManySuperClasses(bool b) { _tooManySuperClasses = b; }
182
int32_t getNumVisitedSuperClasses() {return _numVisitedSuperClasses; }
183
void setNumVisitedSuperClasses(int32_t n) {_numVisitedSuperClasses = n; }
184
void addSuperClass(TR_OpaqueClassBlock *c)
185
{
186
if (_visitedSuperClasses && _numVisitedSuperClasses < MAX_SUPERCLASSES)
187
_visitedSuperClasses[_numVisitedSuperClasses++] = c;
188
else
189
_tooManySuperClasses = true;
190
}
191
192
bool GCwillBlockOnClassUnloadMonitor() { return _GCwillBlockOnClassUnloadMonitor; }
193
void setGCwillBlockOnClassUnloadMonitor() { _GCwillBlockOnClassUnloadMonitor = true; _timeGCwillBlockOnClassUnloadMonitorWasSet = _elapsedTime;}
194
void resetGCwillBlockOnClassUnloadMonitor() { _GCwillBlockOnClassUnloadMonitor = false; }
195
196
bool ensureUnloadedAddressSetsAreInitialized();
197
void addUnloadedClass(TR_OpaqueClassBlock *clazz, uintptr_t startAddress, uint32_t size);
198
bool isUnloadedClass(void *v, bool yesIReallyDontCareAboutHCR); // You probably want isObsoleteClass
199
bool isInUnloadedMethod(uintptr_t address);
200
int32_t getNumUnloadedClasses() const { return _numUnloadedClasses; }
201
TR_AddressSet* getUnloadedClassAddresses() const { return _unloadedClassAddresses; }
202
203
void incNumLoadedClasses() {_numLoadedClasses++;}
204
205
int32_t getClassLoadingPhaseGracePeriod() { return _classLoadingPhaseGracePeriod; }
206
void setClassLoadingPhaseGracePeriod(int32_t val) { _classLoadingPhaseGracePeriod = val; }
207
208
uint64_t getStartTime() const { return _startTime;}
209
void setStartTime(uint64_t t) {_startTime = t;}
210
211
void setElapsedTime(uint64_t t) {_elapsedTime = t;}
212
void updateElapsedTime(uint64_t t) {_elapsedTime += t;}
213
214
int32_t getGlobalClassUnloadID() const {return _globalClassUnloadID;}
215
void incGlobalClassUnloadID() {_globalClassUnloadID++;}
216
217
bool getExternalStartupEndedSignal() const { return _externalStartupEndedSignal; }
218
void setExternalStartupEndedSignal(bool b) { _externalStartupEndedSignal = b; }
219
220
bool isObsoleteClass(void *v, TR_FrontEnd *fe);
221
TR_PseudoRandomNumbersListElement *advanceCurPseudoRandomNumbersListElem();
222
223
bool getDisableFurtherCompilation() const { return _disableFurtherCompilation; }
224
void setDisableFurtherCompilation(bool b) { _disableFurtherCompilation = b; }
225
226
uint32_t getLoadFactor() const { return _loadFactor; }
227
void setLoadFactor(uint32_t f) { _loadFactor = f; }
228
229
uint8_t getJitState() const { return _jitState; }
230
void setJitState(uint8_t v) { _jitState = v; }
231
232
void setJitStateChangeSampleCount(uint32_t t) {_jitStateChangeSampleCount = t;}
233
uint32_t getJitStateChangeSampleCount() const { return _jitStateChangeSampleCount;}
234
235
uint32_t getJitTotalSampleCount() const { return _jitTotalSampleCount; }
236
void incJitTotalSampleCount() { _jitTotalSampleCount++; }
237
238
void setJitSampleCountWhenStartupStateEntered(uint32_t n) { _jitSampleCountWhenStartupStateEntered = n; }
239
uint32_t getJitSampleCountWhenStartupStateEntered() const { return _jitSampleCountWhenStartupStateEntered; }
240
241
void setJitSampleCountWhenStartupStateExited(uint32_t n) { _jitSampleCountWhenStartupStateExited = n; }
242
uint32_t getJitSampleCountWhenStartupStateExited() const { return _jitSampleCountWhenStartupStateExited; }
243
244
void setJitSampleCountWhenActiveStateEntered(uint32_t n) { _jitSampleCountWhenActiveStateEntered = n; }
245
uint32_t getJitSampleCountWhenActiveStateEntered() const { return _jitSampleCountWhenActiveStateEntered; }
246
247
void setVmTotalCpuTimeWhenStartupStateEntered(int64_t n) { _vmTotalCpuTimeWhenStartupStateEntered = n; }
248
int64_t getVmTotalCpuTimeWhenStartupStateEntered() const { return _vmTotalCpuTimeWhenStartupStateEntered; }
249
250
void setVmTotalCpuTimeWhenStartupStateExited(int64_t n) { _vmTotalCpuTimeWhenStartupStateExited = n; }
251
int64_t getVmTotalCpuTimeWhenStartupStateExited() const { return _vmTotalCpuTimeWhenStartupStateExited; }
252
253
void setInliningAggressiveness(int32_t n) { _inliningAggressiveness = n; }
254
int32_t getInliningAggressiveness() const { return _inliningAggressiveness; }
255
256
uint64_t getLastTimeSamplerThreadEnteredIdle() const { return _lastTimeSamplerThreadEnteredIdle; }
257
void setLastTimeSamplerThreadEnteredIdle(uint64_t t) { _lastTimeSamplerThreadEnteredIdle = t; }
258
259
uint64_t getLastTimeSamplerThreadEnteredDeepIdle() const { return _lastTimeSamplerThreadEnteredDeepIdle; }
260
void setLastTimeSamplerThreadEnteredDeepIdle(uint64_t t) { _lastTimeSamplerThreadEnteredDeepIdle = t; }
261
262
uint64_t getLastTimeThreadsWereActive() const { return _lastTimeThreadsWereActive; }
263
void setLastTimeThreadsWereActive(uint64_t t) { _lastTimeThreadsWereActive = t; }
264
265
uint64_t getLastTimeSamplerThreadWasSuspended() const { return _lastTimeSamplerThreadWasSuspended; }
266
void setLastTimeSamplerThreadWasSuspended(uint64_t t) { _lastTimeSamplerThreadWasSuspended = t; }
267
268
void setGCMapCheckEventHandle(uint32_t handle) {_gcMapCheckEventHandleKey = handle;}
269
uint32_t getGCMapCheckEventHandle() {return _gcMapCheckEventHandleKey;}
270
271
int32_t getNumGCRBodies() const { return _statNumGCRBodies; }
272
int32_t getNumGCRSaves() const { return _statNumGCRSaves; }
273
274
void incNumGCRBodies() { _statNumGCRBodies++; }
275
void incNumGCRSaves() { _statNumGCRSaves++; }
276
277
TR_J2IThunkTable *getInvokeExactJ2IThunkTable(){ return _invokeExactJ2IThunkTable; } // NULL if the platform needs no thunks, so J2I helpers can be called directly
278
void setInvokeExactJ2IThunkTable(TR_J2IThunkTable *table){ _invokeExactJ2IThunkTable = table; }
279
280
281
TR_PersistentCHTable * getPersistentCHTable();
282
void setPersistentCHTable(TR_PersistentCHTable *table);
283
284
TR_RuntimeAssumptionTable *getRuntimeAssumptionTable() { return &_runtimeAssumptionTable; }
285
286
287
TR::Monitor * getGpuInitializationMonitor() { return _gpuInitMonitor; }
288
void setGpuInitializationMonitor(TR::Monitor * gpuInitMonitor) {_gpuInitMonitor = gpuInitMonitor;}
289
290
291
bool isRuntimeInstrumentationEnabled() { return _runtimeInstrumentationEnabled; }
292
void setRuntimeInstrumentationEnabled(bool b)
293
{
294
_runtimeInstrumentationEnabled = b;
295
296
// If RI is disabled, then the exploitations need to be disabled too
297
if (b == false)
298
{
299
_runtimeInstrumentationRecompilationEnabled = false;
300
}
301
}
302
303
bool isRuntimeInstrumentationRecompilationEnabled() { return _runtimeInstrumentationEnabled && _runtimeInstrumentationRecompilationEnabled; }
304
void setRuntimeInstrumentationRecompilationEnabled(bool b)
305
{
306
if (_runtimeInstrumentationEnabled)
307
_runtimeInstrumentationRecompilationEnabled = b;
308
else
309
_runtimeInstrumentationRecompilationEnabled = false;
310
}
311
312
313
bool getInlinerTemporarilyRestricted() const { return _inlinerTemporarilyRestricted; }
314
void setInlinerTemporarilyRestricted(bool b) { _inlinerTemporarilyRestricted = b; }
315
316
317
bool isClassLoadingPhase() const {return _classLoadingPhase;}
318
void setClassLoadingPhase(bool b) {_classLoadingPhase = b;}
319
320
int32_t getNumLoadedClasses() const { return _numLoadedClasses;}
321
uint64_t getElapsedTime() const { return _elapsedTime;}
322
323
// these fields are mostly read, rarely written
324
/* _countForRecompile can be frequently accessed by *application threads*.
325
* If it is placed on a cache line that frequently gets updated, it will be constantly evicted,
326
* which can cause a significant performance peanalty.
327
*/
328
uint8_t _paddingBefore[128];
329
int32_t _countForRecompile;
330
331
#if defined(J9VM_OPT_JITSERVER)
332
static JITServer::RemoteCompilationModes _remoteCompilationMode; // JITServer::NONE, JITServer::CLIENT, JITServer::SERVER
333
334
static JITServer::RemoteCompilationModes getRemoteCompilationMode() { return _remoteCompilationMode; }
335
const std::string &getJITServerAddress() const { return _JITServerAddress; }
336
void setJITServerAddress(const char *addr) { _JITServerAddress = addr; }
337
uint32_t getSocketTimeout() const { return _socketTimeoutMs; }
338
void setSocketTimeout(uint32_t t) { _socketTimeoutMs = t; }
339
uint32_t getJITServerPort() const { return _JITServerPort; }
340
void setJITServerPort(uint32_t port) { _JITServerPort = port; }
341
uint64_t getClientUID() const { return _clientUID; }
342
void setClientUID(uint64_t val) { _clientUID = val; }
343
uint64_t getServerUID() const { return _serverUID; }
344
void setServerUID(uint64_t val) { _serverUID = val; }
345
bool getRequireJITServer() const { return _requireJITServer; }
346
void setRequireJITServer(bool requireJITServer) { _requireJITServer = requireJITServer; }
347
bool isLocalSyncCompiles() const { return _localSyncCompiles; }
348
void setLocalSyncCompiles(bool localSyncCompiles) { _localSyncCompiles = localSyncCompiles; }
349
bool getJITServerUseAOTCache() const { return _JITServerUseAOTCache; }
350
void setJITServerUseAOTCache(bool use) { _JITServerUseAOTCache = use; }
351
const std::string &getJITServerAOTCacheName() const { return _JITServerAOTCacheName; }
352
void setJITServerAOTCacheName(const char *name) { _JITServerAOTCacheName = name; }
353
#endif /* defined(J9VM_OPT_JITSERVER) */
354
355
private:
356
TR_AddressSet *_unloadedClassAddresses;
357
TR_AddressSet *_unloadedMethodAddresses;
358
359
TR_RuntimeAssumptionTable _runtimeAssumptionTable;
360
TR_PersistentCHTable *_persistentCHTable;
361
362
TR_PersistentClassLoaderTable *_persistentClassLoaderTable;
363
364
// these fields are RW
365
366
TR_OpaqueClassBlock **_visitedSuperClasses;
367
int32_t _numVisitedSuperClasses;
368
bool _tooManySuperClasses;
369
370
uint64_t _timeGCwillBlockOnClassUnloadMonitorWasSet; // ms; set by GC; RAS
371
bool _GCwillBlockOnClassUnloadMonitor;
372
373
int32_t _classLoadingPhaseGracePeriod; // in ms
374
375
uint64_t _startTime; // time when sampling thread started (ms)
376
377
int32_t _numUnloadedClasses;
378
379
int32_t _globalClassUnloadID; // incremented each time GC does a class unload
380
381
bool _externalStartupEndedSignal; // the app will tell us when startup ends
382
383
volatile bool _disableFurtherCompilation;
384
385
uint32_t _loadFactor; // set in samplerThread; increases with active threads, decreases with CPUs
386
387
uint8_t _jitState; // STARTUP IDLE RAMPUP STEADY
388
389
uint32_t _jitTotalSampleCount; // similar to TR::Recompilation::globalSampleCount,
390
// but always incremented when jitMethodSampleInterrupt is called
391
392
uint32_t _jitStateChangeSampleCount; // caches _jitTotalSampleCount when a state change has occurred
393
394
uint32_t _jitSampleCountWhenActiveStateEntered; // set when we leave IDLE of STARTUP
395
396
uint32_t _jitSampleCountWhenStartupStateEntered; // set when we enter STARTUP from another state
397
398
uint32_t _jitSampleCountWhenStartupStateExited; // set when we exit STARTUP state
399
400
int64_t _vmTotalCpuTimeWhenStartupStateEntered; // set when we enter STARTUP from another state
401
402
int64_t _vmTotalCpuTimeWhenStartupStateExited; // set when we exit STARTUP state
403
404
int32_t _inliningAggressiveness;
405
406
// The following four fields are stored here for RAS purposes (easy access from a debugging session)
407
//
408
uint64_t _lastTimeSamplerThreadEnteredIdle; // used by samplerThread
409
uint64_t _lastTimeSamplerThreadEnteredDeepIdle;
410
uint64_t _lastTimeSamplerThreadWasSuspended;
411
uint64_t _lastTimeThreadsWereActive; // used by samplerThread
412
413
uint32_t _gcMapCheckEventHandleKey;
414
415
// Stats for GCR bodies generated and how many times we avoided generating a GCR body
416
//
417
int32_t _statNumGCRBodies;
418
int32_t _statNumGCRSaves;
419
420
TR_J2IThunkTable *_invokeExactJ2IThunkTable;
421
422
TR::Monitor *_gpuInitMonitor;
423
424
bool _runtimeInstrumentationEnabled;
425
bool _runtimeInstrumentationRecompilationEnabled;
426
427
bool _classLoadingPhase; ///< true, if we detect a large number of classes loaded per second
428
bool _inlinerTemporarilyRestricted; ///< do not inline when true; used to restrict cold inliner during startup
429
430
volatile uint64_t _elapsedTime; ///< elapsed time as computed by the sampling thread (ms)
431
///< May need adjustment if sampling thread goes to sleep
432
433
int32_t _numLoadedClasses; ///< always increasing
434
435
#if defined(J9VM_OPT_JITSERVER)
436
std::string _JITServerAddress;
437
uint32_t _JITServerPort;
438
uint32_t _socketTimeoutMs; // timeout for communication sockets used in out-of-process JIT compilation
439
uint64_t _clientUID;
440
uint64_t _serverUID; // At the client, this represents the UID of the server the client is connected to
441
bool _requireJITServer;
442
bool _localSyncCompiles;
443
bool _JITServerUseAOTCache;
444
std::string _JITServerAOTCacheName; // Name of the server AOT cache that this client is using
445
#endif /* defined(J9VM_OPT_JITSERVER) */
446
};
447
448
}
449
450
#endif
451
452