Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/control/DLLMain.cpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 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
#define J9_EXTERNAL_TO_VM
24
25
#include "control/Options.hpp"
26
#include "env/ClassLoaderTable.hpp"
27
#include "env/annotations/AnnotationBase.hpp"
28
#include "env/ut_j9jit.h"
29
#include "control/CompilationRuntime.hpp"
30
#include "control/CompilationThread.hpp"
31
#include "env/VMJ9.h"
32
#include "runtime/IProfiler.hpp"
33
#include "runtime/J9Profiler.hpp"
34
#if defined(J9VM_OPT_JITSERVER)
35
#include "runtime/Listener.hpp"
36
#endif /* J9VM_OPT_JITSERVER */
37
#include "runtime/codertinit.hpp"
38
#include "rossa.h"
39
40
#include "j9.h"
41
#include "jvminit.h"
42
43
// NOTE: Any changes made to J9VMDllMain that relate to AOT compile time
44
// should be put instead in onLoadInternal().
45
//
46
47
#ifdef AOT_COMPILE_TIME_VERSION
48
#define THIS_DLL_NAME J9_AOT_DLL_NAME
49
#else
50
#define THIS_DLL_NAME J9_JIT_DLL_NAME
51
#endif
52
53
extern bool initializeJIT(J9JavaVM *vm);
54
55
extern bool isQuickstart;
56
57
IDATA J9VMDllMain(J9JavaVM* vm, IDATA stage, void * reserved)
58
{
59
J9JITConfig * jitConfig = 0;
60
UDATA initialFlags = 0;
61
J9VMDllLoadInfo* loadInfo = FIND_DLL_TABLE_ENTRY( THIS_DLL_NAME );
62
char* xjitCommandLineOptions = "";
63
char* xaotCommandLineOptions = "";
64
IDATA fullSpeedDebugSet = FALSE;
65
IDATA argIndex = 0;
66
67
IDATA tlhPrefetch = 0;
68
IDATA notlhPrefetch = 0;
69
IDATA lockReservation = 0;
70
IDATA argIndexXjit = 0;
71
IDATA argIndexXaot = 0;
72
IDATA argIndexXnojit = 0;
73
74
IDATA argIndexClient = 0;
75
IDATA argIndexServer = 0;
76
IDATA argIndexQuickstart = 0;
77
78
IDATA argIndexRIEnabled = 0;
79
IDATA argIndexRIDisabled = 0;
80
81
static bool isJIT = false;
82
static bool isAOT = false;
83
84
static bool jitInitialized = false;
85
static bool aotrtInitialized = false;
86
87
PORT_ACCESS_FROM_JAVAVM(vm);
88
89
#define AOT_INIT_STAGE SYSTEM_CLASSLOADER_SET /* defined separately to ensure dependencies below */
90
91
switch(stage)
92
{
93
94
case DLL_LOAD_TABLE_FINALIZED :
95
{
96
97
// Bootstrap JIT initialization
98
//
99
if (!initializeJIT(vm))
100
{
101
return J9VMDLLMAIN_FAILED;
102
}
103
104
/* Find and consume these before the library might be unloaded */
105
FIND_AND_CONSUME_ARG(EXACT_MATCH, "-Xnodfpbd", 0);
106
if (FIND_ARG_IN_VMARGS(EXACT_MATCH, "-Xdfpbd", 0) >= 0)
107
{
108
FIND_AND_CONSUME_ARG( EXACT_MATCH, "-Xhysteresis", 0);
109
}
110
FIND_AND_CONSUME_ARG( EXACT_MATCH, "-Xnoquickstart", 0); // deprecated
111
FIND_AND_CONSUME_ARG(STARTSWITH_MATCH, "-Xtune:elastic", 0);
112
argIndexQuickstart = FIND_AND_CONSUME_ARG( EXACT_MATCH, "-Xquickstart", 0);
113
tlhPrefetch = FIND_AND_CONSUME_ARG(EXACT_MATCH, "-XtlhPrefetch", 0);
114
notlhPrefetch = FIND_AND_CONSUME_ARG(EXACT_MATCH, "-XnotlhPrefetch", 0);
115
lockReservation = FIND_AND_CONSUME_ARG(EXACT_MATCH, "-XlockReservation", 0);
116
FIND_AND_CONSUME_ARG(EXACT_MEMORY_MATCH, "-Xcodecache", 0);
117
FIND_AND_CONSUME_ARG(STARTSWITH_MATCH, "-XjniAcc:", 0);
118
FIND_AND_CONSUME_ARG(EXACT_MEMORY_MATCH, "-Xcodecachetotal", 0);
119
FIND_AND_CONSUME_ARG(EXACT_MEMORY_MATCH, "-XX:codecachetotal=", 0);
120
121
FIND_AND_CONSUME_ARG(STARTSWITH_MATCH, "-Xlp:codecache:", 0);
122
123
FIND_AND_CONSUME_ARG(EXACT_MEMORY_MATCH, "-XsamplingExpirationTime", 0);
124
FIND_AND_CONSUME_ARG(EXACT_MEMORY_MATCH, "-XcompilationThreads", 0);
125
FIND_AND_CONSUME_ARG(EXACT_MEMORY_MATCH, "-XaggressivenessLevel", 0);
126
argIndexXjit = FIND_AND_CONSUME_ARG(OPTIONAL_LIST_MATCH, "-Xjit", 0);
127
argIndexXaot = FIND_AND_CONSUME_ARG(OPTIONAL_LIST_MATCH, "-Xaot", 0);
128
argIndexXnojit = FIND_AND_CONSUME_ARG(OPTIONAL_LIST_MATCH, "-Xnojit", 0);
129
130
argIndexRIEnabled = FIND_AND_CONSUME_ARG(EXACT_MATCH, "-XX:+RuntimeInstrumentation", 0);
131
argIndexRIDisabled = FIND_AND_CONSUME_ARG(EXACT_MATCH, "-XX:-RuntimeInstrumentation", 0);
132
133
// Determine if user disabled Runtime Instrumentation
134
if (argIndexRIEnabled >= 0 || argIndexRIDisabled >= 0)
135
TR::Options::_hwProfilerEnabled = (argIndexRIDisabled > argIndexRIEnabled) ? TR_no : TR_yes;
136
137
TR::Options::_doNotProcessEnvVars = (FIND_AND_CONSUME_ARG(EXACT_MATCH, "-XX:doNotProcessJitEnvVars", 0) >= 0);
138
139
isQuickstart = J9_ARE_ANY_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_TUNE_QUICKSTART);
140
141
#ifdef TR_HOST_X86
142
// By default, disallow reservation of objects' monitors for which a
143
// previous reservation has been cancelled (issue #1124). But allow it
144
// again if -XlockReservation was specified.
145
TR::Options::_aggressiveLockReservation = lockReservation >= 0;
146
#else
147
// Keep the always aggressive behaviour until codegen is adjusted.
148
TR::Options::_aggressiveLockReservation = true;
149
#endif
150
151
/* setup field to indicate whether we will allow JIT compilation */
152
if (argIndexXjit >= argIndexXnojit)
153
{
154
isJIT = true;
155
}
156
157
/* setup field to indicate whether we will allow AOT compilation and perform AOT runtime
158
* initializations to allow AOT code to be loaded from the shared cache as well as from JXEs */
159
if ((J9_ARE_ANY_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_ENABLE_AOT)))
160
{
161
isAOT = true;
162
}
163
164
static char *disableAOT = feGetEnv2("TR_disableAOT", (void *)vm);
165
if (disableAOT)
166
isAOT = false;
167
168
/* If debuginfoserver has been loaded and no FSD support, unload this library and aot */
169
#ifdef J9VM_JIT_FULL_SPEED_DEBUG
170
fullSpeedDebugSet = TRUE;
171
#endif
172
173
static bool TR_DisableFullSpeedDebug = feGetEnv2("TR_DisableFullSpeedDebug", (void *)vm)?1:0;
174
if (!fullSpeedDebugSet || TR_DisableFullSpeedDebug)
175
{
176
loadInfo->loadFlags |= FORCE_UNLOAD;
177
break;
178
}
179
180
#if defined(J9VM_GC_BATCH_CLEAR_TLH)
181
/* The order is important: we have to request it before the first TLH is created. */
182
/* Platform detection seems difficult at this point. */
183
{
184
#ifdef TR_HOST_X86
185
static char *enableBatchClear = feGetEnv2("TR_EnableBatchClear", (void *)vm);
186
187
#else //ppc and s390
188
static char *disableBatchClear = feGetEnv2("TR_DisableBatchClear", (void *)vm);
189
#ifdef TR_HOST_POWER
190
static char *disableDualTLH = feGetEnv2("TR_DisableDualTLH", (void *)vm);
191
192
//if disableDualTLH is specified, revert back to old semantics.
193
// Do not batch clear, JIT has to zeroinit all code on TLH.
194
//Non P6, P7 and up are allowed to batch clear however.
195
bool disableZeroedTLHPages = disableDualTLH && (((notlhPrefetch >= 0) || (!TR::Compiler->target.cpu.is(OMR_PROCESSOR_PPC_P6) && !TR::Compiler->target.cpu.is(OMR_PROCESSOR_PPC_P7))));
196
#endif//TR_HOST_POWER
197
#endif//TR_HOST_X86
198
/*in testmode, the JIT will be loaded by a native. At this point it's too late to change
199
* the TLH mode, and it won't matter anyway, since JIT'ed code won't be run.
200
* See CMVC 70078
201
*/
202
if (
203
#ifdef TR_HOST_X86
204
enableBatchClear
205
#else//ppc and s390
206
disableBatchClear==0
207
#ifdef TR_HOST_POWER
208
&&!disableZeroedTLHPages
209
#endif//TR_HOST_POWER
210
#endif//TR_HOST_X86
211
)
212
{
213
J9VMDllLoadInfo *gcLoadInfo = getGCDllLoadInfo(vm);
214
215
if (!IS_STAGE_COMPLETED(gcLoadInfo->completedBits, JCL_INITIALIZED) )//&& vm->memoryManagerFunctions)
216
{
217
vm->memoryManagerFunctions->allocateZeroedTLHPages(vm, true);
218
}
219
}
220
}
221
#endif//J9VM_GC_BATCH_CLEAR_TLH
222
223
break;
224
}
225
226
case AOT_INIT_STAGE :
227
if (isAOT)
228
{
229
/* Perform initializations for AOT runtime */
230
#if defined(J9VM_INTERP_AOT_RUNTIME_SUPPORT)
231
// TODO: This now acts as a general "Is the jit shutting down" flag, should it be renamed / changed for something different?
232
if (vm->jitConfig)
233
vm->jitConfig->runtimeFlags |= J9JIT_AOT_ATTACHED;
234
#endif
235
aotrtInitialized = true;
236
}
237
break;
238
239
// createThreadWithCategory compiling threads in this stage
240
case JIT_INITIALIZED :
241
if (isJIT || isAOT)
242
{
243
/* We need to initialize the following if we allow JIT compilation, AOT compilation or AOT relocation to be done */
244
try
245
{
246
/*
247
* Note that the option prefix we need to match includes the colon.
248
*/
249
argIndexXjit = FIND_ARG_IN_VMARGS( STARTSWITH_MATCH, "-Xjit:", 0);
250
argIndexXaot = FIND_ARG_IN_VMARGS( STARTSWITH_MATCH, "-Xaot:", 0);
251
252
/* do initializations for -Xjit options */
253
if (isJIT && argIndexXjit >= 0)
254
{
255
IDATA returnVal = 0, size = 128;
256
xjitCommandLineOptions = 0;
257
do
258
{
259
size = size * 2;
260
if (xjitCommandLineOptions)
261
j9mem_free_memory(xjitCommandLineOptions);
262
if (!(xjitCommandLineOptions = (char*)j9mem_allocate_memory(size * sizeof(char), J9MEM_CATEGORY_JIT)))
263
return J9VMDLLMAIN_FAILED;
264
returnVal = GET_COMPOUND_VALUE(argIndexXjit, ':', &xjitCommandLineOptions, size);
265
} while (returnVal == OPTION_BUFFER_OVERFLOW);
266
267
if (!* xjitCommandLineOptions)
268
{
269
j9mem_free_memory(xjitCommandLineOptions);
270
loadInfo->fatalErrorStr = "no arguments for -Xjit:";
271
return J9VMDLLMAIN_FAILED;
272
}
273
}
274
275
codert_onload(vm);
276
277
/* do initializations for -Xaot options */
278
if (isAOT && argIndexXaot >= 0)
279
{
280
IDATA returnVal = 0, size = 128;
281
xaotCommandLineOptions = 0;
282
do
283
{
284
size = size * 2;
285
if (xaotCommandLineOptions)
286
j9mem_free_memory(xaotCommandLineOptions);
287
if (!(xaotCommandLineOptions = (char*)j9mem_allocate_memory(size * sizeof(char), J9MEM_CATEGORY_JIT)))
288
return J9VMDLLMAIN_FAILED;
289
returnVal = GET_COMPOUND_VALUE(argIndexXaot, ':', &xaotCommandLineOptions, size);
290
} while (returnVal == OPTION_BUFFER_OVERFLOW);
291
292
if (!* xaotCommandLineOptions)
293
{
294
j9mem_free_memory(xaotCommandLineOptions);
295
loadInfo->fatalErrorStr = "no arguments for -Xaot:";
296
return J9VMDLLMAIN_FAILED;
297
}
298
}
299
300
jitConfig = vm->jitConfig;
301
302
if (!jitConfig)
303
{
304
loadInfo->fatalErrorStr = "cannot initialize JIT: no jitconfig";
305
return J9VMDLLMAIN_FAILED;
306
}
307
308
if (isQuickstart)
309
jitConfig->runtimeFlags |= J9JIT_QUICKSTART;
310
311
if (aotrtInitialized)
312
jitConfig->runtimeFlags |= J9JIT_AOT_ATTACHED;
313
314
if (jitConfig->runtimeFlags & J9JIT_JIT_ATTACHED)
315
goto _abort;
316
if (onLoadInternal(vm, jitConfig, xjitCommandLineOptions, xaotCommandLineOptions, initialFlags, reserved, isJIT?0:1))
317
goto _abort;
318
319
if (isJIT)
320
jitConfig->runtimeFlags |= J9JIT_JIT_ATTACHED;
321
322
// Option string is no longer needed
323
/* The following code causes problems on zLinux (only) when using a tracing option
324
The code is commented out until we can figure out the root cause
325
if (isJIT && argIndexXjit >= 0 && xjitCommandLineOptions)
326
{
327
j9mem_free_memory(xjitCommandLineOptions);
328
xjitCommandLineOptions = 0;
329
}
330
if (isAOT && argIndexXaot >= 0 && xaotCommandLineOptions)
331
{
332
j9mem_free_memory(xaotCommandLineOptions);
333
xaotCommandLineOptions = 0;
334
}
335
*/
336
jitInitialized = true;
337
return J9VMDLLMAIN_OK;
338
}
339
catch (const std::exception &e) {}
340
_abort:
341
freeJITConfig(jitConfig);
342
if (!loadInfo->fatalErrorStr || strlen(loadInfo->fatalErrorStr)==0)
343
loadInfo->fatalErrorStr = "cannot initialize JIT";
344
return J9VMDLLMAIN_FAILED;
345
}
346
break;
347
348
// createThreadWithCategory sampling and profiling threads in this stage
349
case ABOUT_TO_BOOTSTRAP:
350
{
351
#if defined(J9VM_OPT_SHARED_CLASSES)
352
// ENABLE_AOT must be set AND the shared class must be properly initialized
353
UDATA aotFlags = J9SHR_RUNTIMEFLAG_CACHE_INITIALIZATION_COMPLETE;
354
if (vm->sharedClassConfig && ((vm->sharedClassConfig->runtimeFlags & aotFlags) == aotFlags))
355
{
356
TR::Options::setSharedClassCache(true); // Set to true as long as cache is present and initialized
357
358
TR_J9VMBase *feWithoutThread = TR_J9VMBase::get(vm->jitConfig, 0);
359
TR_J9SharedCache *sharedCache = new (PERSISTENT_NEW) TR_J9SharedCache((TR_J9VMBase *)feWithoutThread);
360
if (sharedCache != NULL)
361
{
362
TR_PersistentMemory *persistentMemory = (TR_PersistentMemory *)(vm->jitConfig->scratchSegment);
363
TR_PersistentClassLoaderTable *loaderTable = persistentMemory->getPersistentInfo()->getPersistentClassLoaderTable();
364
sharedCache->setPersistentClassLoaderTable(loaderTable);
365
loaderTable->setSharedCache(sharedCache);
366
}
367
}
368
else
369
#endif /* defined(J9VM_OPT_SHARED_CLASSES) */
370
{
371
TR::Options::setSharedClassCache(false);
372
}
373
374
if (!isAOT)
375
{
376
/* turn off internal flags if user specified AOT to be turned OFF */
377
#if defined(J9VM_OPT_SHARED_CLASSES)
378
if (vm->sharedClassConfig && (vm->sharedClassConfig->runtimeFlags & J9SHR_RUNTIMEFLAG_ENABLE_AOT))
379
{
380
// doesn't matter if J9SHR_RUNTIMEFLAG_CACHE_INITIALIZATION_COMPLETE is set or not
381
// we're only clearing the ENABLE_AOT flag
382
vm->sharedClassConfig->runtimeFlags &= ~J9SHR_RUNTIMEFLAG_ENABLE_AOT;
383
}
384
#endif
385
if ( TR::Options::getAOTCmdLineOptions() )
386
{
387
TR::Options::getAOTCmdLineOptions()->setOption(TR_NoLoadAOT);
388
TR::Options::getAOTCmdLineOptions()->setOption(TR_NoStoreAOT);
389
TR::Options::setSharedClassCache(false);
390
}
391
}
392
393
if (TR::Options::sharedClassCache())
394
TR_J9SharedCache::setSharedCacheDisabledReason(TR_J9SharedCache::NOT_DISABLED);
395
else
396
TR_J9SharedCache::setSharedCacheDisabledReason(TR_J9SharedCache::AOT_DISABLED);
397
398
if (isJIT || isAOT)
399
{
400
401
/* Although we've initialized the compiler, we have to tell the compiler whether it can perform JIT compiles
402
* This is because the compiler can be configured to only AOT compile. */
403
TR::Options::setCanJITCompile(isJIT);
404
405
int32_t rv = aboutToBootstrap(vm, vm->jitConfig);
406
407
jitConfig = vm->jitConfig;
408
409
if (isAOT && !isJIT && TR::Options::getAOTCmdLineOptions()->getOption(TR_NoStoreAOT))
410
TR::Options::getCmdLineOptions()->setOption(TR_DisableInterpreterProfiling, true);
411
412
413
if (!TR::Options::canJITCompile()) // -Xnojit, then recompilation is not supported
414
// Ensure JIT and AOT flags are set appropriately
415
{
416
TR::Options::getAOTCmdLineOptions()->setAllowRecompilation(false);
417
TR::Options::getAOTCmdLineOptions()->setOption(TR_DisableCHOpts);
418
419
TR::Options::getJITCmdLineOptions()->setAllowRecompilation(false);
420
TR::Options::getJITCmdLineOptions()->setOption(TR_DisableCHOpts);
421
}
422
423
if (!isJIT)
424
{
425
TR::Options::getAOTCmdLineOptions()->setOption(TR_DisableGuardedCountingRecompilations);
426
}
427
428
if (isAOT
429
&& TR::Options::getAOTCmdLineOptions()->getOption(TR_EnableClassChainValidationCaching)
430
&& (TR::Options::getCmdLineOptions()->getOption(TR_DisableCHOpts)))
431
{
432
TR::Options::getAOTCmdLineOptions()->setOption(TR_EnableClassChainValidationCaching, false);
433
}
434
435
if (rv == -1)
436
{
437
// cannot free JIT config because shutdown stage expects it to exist
438
vm->runtimeFlags &= ~J9_RUNTIME_JIT_ACTIVE;
439
if (!loadInfo->fatalErrorStr || strlen(loadInfo->fatalErrorStr)==0)
440
loadInfo->fatalErrorStr = "cannot initialize JIT";
441
return J9VMDLLMAIN_FAILED;
442
}
443
444
if (rv == 1)
445
{
446
// cannot free JIT config because shutdown stage expects it to exist
447
vm->runtimeFlags &= ~J9_RUNTIME_JIT_ACTIVE;
448
printf("Non-Fatal Error: cannot initialize JIT: JVMTI with FSD disabled\n");
449
}
450
451
/* If the return value is 0, then continue normally */
452
TR::Options::setIsFullyInitialized();
453
}
454
455
break;
456
}
457
458
case VM_INITIALIZATION_COMPLETE:
459
{
460
// When the compilation thread was created, it was too early to create an
461
// instance of java.lang.Thread (we need to be assume that JCL is ready)
462
// Its safe to do this now.
463
//
464
if (isJIT || isAOT)
465
{
466
J9VMThread *curThread = vm->internalVMFunctions->currentVMThread(vm);
467
TR::CompilationInfo *compInfo = getCompilationInfo(vm->jitConfig);
468
TR::CompilationInfoPerThread * const *arrayOfCompInfoPT = compInfo->getArrayOfCompilationInfoPerThread();
469
TR_ASSERT(arrayOfCompInfoPT, "TR::CompilationInfo::_arrayOfCompilationInfoPerThread is null\n");
470
471
for (int32_t i = 0; i < compInfo->getNumTotalCompilationThreads(); i++)
472
{
473
TR::CompilationInfoPerThread *curCompThreadInfoPT = arrayOfCompInfoPT[i];
474
TR_ASSERT(curCompThreadInfoPT, "a thread's compinfo is missing\n");
475
476
J9VMThread *compThread = curCompThreadInfoPT->getCompilationThread();
477
if (!compThread)
478
continue;
479
480
//char threadName[32]; // make sure the name below does not exceed 32 chars
481
//sprintf(threadName, "JIT Compilation Thread-%d", curCompThreadInfoPT->getCompThreadId());
482
483
char *threadName = (
484
curCompThreadInfoPT->compilationThreadIsActive() ?
485
curCompThreadInfoPT->getActiveThreadName() :
486
curCompThreadInfoPT->getSuspendedThreadName()
487
);
488
489
vm->internalVMFunctions->initializeAttachedThread(
490
curThread,
491
threadName,
492
vm->systemThreadGroupRef,
493
((compThread->privateFlags & J9_PRIVATE_FLAGS_DAEMON_THREAD) != 0),
494
compThread
495
);
496
497
if ((curThread->currentException != NULL) || (curThread->threadObject == NULL))
498
{
499
if (!loadInfo->fatalErrorStr || strlen(loadInfo->fatalErrorStr)==0)
500
loadInfo->fatalErrorStr = "cannot create the jit Thread object";
501
return J9VMDLLMAIN_FAILED;
502
}
503
504
TRIGGER_J9HOOK_VM_THREAD_STARTED(vm->hookInterface, curThread, compThread);
505
} // end for
506
507
// Give a name to the sampling thread as well
508
// The sampling thread (if any) has been created and attached in stage 13
509
// It cannot be stopped because that happens in stage 17 while here we are in stage 15
510
// In this case we can access the samplingThreadLifetimeState without a monitor because
511
// no other thread tries to read or write to it.
512
if (compInfo->getSamplerThread())
513
{
514
TR_ASSERT(compInfo->getSamplingThreadLifetimeState() == TR::CompilationInfo::SAMPLE_THR_ATTACHED,
515
"Sampling thread must be already attached in stage 15\n");
516
vm->internalVMFunctions->initializeAttachedThread(
517
curThread,
518
"JIT-SamplerThread",
519
vm->systemThreadGroupRef,
520
((compInfo->getSamplerThread()->privateFlags & J9_PRIVATE_FLAGS_DAEMON_THREAD) != 0),
521
compInfo->getSamplerThread()
522
);
523
if ((curThread->currentException != NULL) || (curThread->threadObject == NULL))
524
{
525
if (!loadInfo->fatalErrorStr || strlen(loadInfo->fatalErrorStr)==0)
526
loadInfo->fatalErrorStr = "cannot create the jit Sampler Thread object";
527
return J9VMDLLMAIN_FAILED;
528
}
529
compInfo->setSamplingThreadLifetimeState(TR::CompilationInfo::SAMPLE_THR_INITIALIZED);
530
TRIGGER_J9HOOK_VM_THREAD_STARTED(vm->hookInterface, curThread, compInfo->getSamplerThread());
531
}
532
533
TR_J9VMBase *fe = TR_J9VMBase::get(vm->jitConfig, 0);
534
if (!fe->isAOT_DEPRECATED_DO_NOT_USE())
535
TR_AnnotationBase::loadExpectedAnnotationClasses(curThread);
536
537
// Also set name for interpreter profiler thread if it exists
538
#if defined (J9VM_INTERP_PROFILING_BYTECODES)
539
TR_IProfiler *iProfiler = fe->getIProfiler();
540
if (iProfiler)
541
{
542
J9VMThread *iProfilerThread = iProfiler->getIProfilerThread();
543
if (iProfilerThread)
544
{
545
vm->internalVMFunctions->initializeAttachedThread
546
(curThread, "IProfiler", vm->systemThreadGroupRef,
547
((iProfilerThread->privateFlags & J9_PRIVATE_FLAGS_DAEMON_THREAD) != 0),
548
iProfilerThread);
549
if ((curThread->currentException != NULL) || (curThread->threadObject == NULL))
550
{
551
if (!loadInfo->fatalErrorStr || strlen(loadInfo->fatalErrorStr)==0)
552
loadInfo->fatalErrorStr = "cannot create the iProfiler Thread object";
553
return J9VMDLLMAIN_FAILED;
554
}
555
TRIGGER_J9HOOK_VM_THREAD_STARTED(vm->hookInterface, curThread, iProfilerThread);
556
}
557
}
558
#endif
559
560
TR_JProfilerThread *jProfiler = ((TR_JitPrivateConfig*)(vm->jitConfig->privateConfig))->jProfiler;
561
if (jProfiler)
562
{
563
J9VMThread *jProfilerThread = jProfiler->getJProfilerThread();
564
if (jProfilerThread)
565
{
566
vm->internalVMFunctions->initializeAttachedThread
567
(curThread, "JProfiler", vm->systemThreadGroupRef,
568
((jProfilerThread->privateFlags & J9_PRIVATE_FLAGS_DAEMON_THREAD) != 0),
569
jProfilerThread);
570
if ((curThread->currentException != NULL) || (curThread->threadObject == NULL))
571
{
572
if (!loadInfo->fatalErrorStr || strlen(loadInfo->fatalErrorStr)==0)
573
loadInfo->fatalErrorStr = "cannot create the jProfiler Thread object";
574
return J9VMDLLMAIN_FAILED;
575
}
576
TRIGGER_J9HOOK_VM_THREAD_STARTED(vm->hookInterface, curThread, jProfilerThread);
577
}
578
}
579
}
580
}
581
break;
582
583
case INTERPRETER_SHUTDOWN:
584
585
if (isJIT || isAOT)
586
{
587
if (vm->jitConfig)
588
{
589
TR_J9VMBase *trvm = TR_J9VMBase::get(vm->jitConfig, 0);
590
if (!trvm->isAOT_DEPRECATED_DO_NOT_USE() && trvm->_compInfo)
591
{
592
#if defined(J9VM_OPT_JITSERVER)
593
if (trvm->_compInfo->getPersistentInfo()->getRemoteCompilationMode() == JITServer::SERVER)
594
{
595
TR_Listener *listener = ((TR_JitPrivateConfig*)(vm->jitConfig->privateConfig))->listener;
596
if (listener)
597
{
598
listener->stop();
599
}
600
}
601
#endif /* defined(J9VM_OPT_JITSERVER) */
602
trvm->_compInfo->stopCompilationThreads();
603
}
604
JitShutdown(vm->jitConfig);
605
}
606
}
607
break;
608
609
case LIBRARIES_ONUNLOAD :
610
case JVM_EXIT_STAGE :
611
if (jitInitialized)
612
{
613
jitConfig = vm->jitConfig;
614
if (jitConfig && stage == JVM_EXIT_STAGE)
615
JitShutdown(jitConfig);
616
//TR_FrontEnd * vm = TR_J9VMBase::get(jitConfig, 0);
617
//TR::Compilation::shutdown(vm); // already done in JitShutdown
618
j9jit_fclose(((TR_JitPrivateConfig*)jitConfig->privateConfig)->vLogFile);
619
((TR_JitPrivateConfig*)jitConfig->privateConfig)->vLogFile = 0;
620
j9jit_fclose(((TR_JitPrivateConfig*)jitConfig->privateConfig)->rtLogFile);
621
((TR_JitPrivateConfig*)jitConfig->privateConfig)->rtLogFile = 0;
622
j9jit_fcloseId(jitConfig->tLogFile);
623
jitConfig->tLogFile = -1;
624
j9jit_fcloseId(jitConfig->tLogFileTemp);
625
jitConfig->tLogFileTemp = -1;
626
627
static char * printIPFanInStats = feGetEnv("TR_PrintIPFanInStats");
628
if (printIPFanInStats)
629
((TR_JitPrivateConfig*)(jitConfig->privateConfig))->iProfiler->checkMethodHashTable();
630
631
if ( stage != JVM_EXIT_STAGE ) /* If not shutdownDueToExit */
632
{
633
freeJITConfig(jitConfig);
634
}
635
jitInitialized = false;
636
}
637
638
if (aotrtInitialized)
639
{
640
#if defined(J9VM_INTERP_AOT_RUNTIME_SUPPORT)
641
jitConfig = vm->jitConfig;
642
if (jitConfig)
643
jitConfig->runtimeFlags &= ~J9JIT_AOT_ATTACHED;
644
#endif
645
if ( stage != JVM_EXIT_STAGE )
646
codert_OnUnload(vm);
647
aotrtInitialized = false;
648
}
649
break;
650
}
651
return J9VMDLLMAIN_OK;
652
}
653
654