-
Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathOMRCompilation.cpp
2805 lines (2400 loc) · 90.8 KB
/
OMRCompilation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at http://eclipse.org/legal/epl-2.0
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* 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
*******************************************************************************/
#include "compile/Compilation.hpp"
#include <limits.h>
#include <math.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include "codegen/CodeGenerator.hpp"
#include "env/FrontEnd.hpp"
#include "codegen/Instruction.hpp"
#include "codegen/Linkage.hpp"
#include "codegen/RecognizedMethods.hpp"
#include "compile/Compilation.hpp"
#include "compile/Compilation_inlines.hpp"
#include "compile/CompilationTypes.hpp"
#include "compile/Method.hpp"
#include "compile/OSRData.hpp"
#include "compile/ResolvedMethod.hpp"
#include "compile/SymbolReferenceTable.hpp"
#include "compile/VirtualGuard.hpp"
#include "control/OptimizationPlan.hpp"
#include "control/Options.hpp"
#include "control/Options_inlines.hpp"
#include "cs2/allocator.h"
#include "cs2/sparsrbit.h"
#include "env/CompilerEnv.hpp"
#include "env/CompileTimeProfiler.hpp"
#include "env/IO.hpp"
#include "env/ObjectModel.hpp"
#include "env/KnownObjectTable.hpp"
#include "env/PersistentInfo.hpp"
#include "env/StackMemoryRegion.hpp"
#include "env/TRMemory.hpp"
#include "env/TypeLayout.hpp"
#include "env/VerboseLog.hpp"
#include "env/defines.h"
#include "env/jittypes.h"
#include "il/Block.hpp"
#include "il/DataTypes.hpp"
#include "il/ILOpCodes.hpp"
#include "il/ILOps.hpp"
#include "il/MethodSymbol.hpp"
#include "il/Node.hpp"
#include "il/NodePool.hpp"
#include "il/Node_inlines.hpp"
#include "il/ResolvedMethodSymbol.hpp"
#include "il/StaticSymbol.hpp"
#include "il/Symbol.hpp"
#include "il/SymbolReference.hpp"
#include "il/TreeTop.hpp"
#include "il/TreeTop_inlines.hpp"
#include "ilgen/IlGenRequest.hpp"
#include "ilgen/IlGeneratorMethodDetails.hpp"
#include "infra/Array.hpp"
#include "infra/Assert.hpp"
#include "infra/Bit.hpp"
#include "infra/BitVector.hpp"
#include "infra/Cfg.hpp"
#include "infra/Flags.hpp"
#include "infra/ILWalk.hpp"
#include "infra/Link.hpp"
#include "infra/List.hpp"
#include "infra/Random.hpp"
#include "infra/Stack.hpp"
#include "infra/CfgEdge.hpp"
#include "infra/Timer.hpp"
#include "infra/ThreadLocal.hpp"
#include "optimizer/DebuggingCounters.hpp"
#include "optimizer/Inliner.hpp"
#include "optimizer/Optimizations.hpp"
#include "optimizer/Optimizer.hpp"
#include "optimizer/RegisterCandidate.hpp"
#include "optimizer/Structure.hpp"
#include "optimizer/TransformUtil.hpp"
#include "ras/Debug.hpp"
#include "ras/DebugCounter.hpp"
#include "ras/ILValidationStrategies.hpp"
#include "ras/ILValidator.hpp"
#include "ras/IlVerifier.hpp"
#include "control/Recompilation.hpp"
#include "runtime/CodeCacheExceptions.hpp"
#include "ilgen/IlGen.hpp"
#include "env/RegionProfiler.hpp"
#include "omrformatconsts.h"
// this ratio defines how full the alias memory region is allowed to become before
// it is recreated after an optimization finishes
#define ALIAS_REGION_LOAD_FACTOR 0.75
#ifdef J9_PROJECT_SPECIFIC
#include "control/RecompilationInfo.hpp"
#include "runtime/RuntimeAssumptions.hpp"
#include "env/CHTable.hpp"
#include "env/VMJ9.h"
#endif
#ifdef J9ZOS390
#include<new>
// Workaround CSECT compile option bug on z/OS
#pragma csect(CODE,"Compilation#C")
#pragma csect(STATIC,"Compilation#S")
#pragma csect(TEST,"Compilation#T")
#endif
class TR_FrontEnd;
class TR_HWPRecord;
class TR_Memory;
class TR_OptimizationPlan;
class TR_PrexArgInfo;
class TR_PseudoRandomNumbersListElement;
class TR_ResolvedMethod;
namespace TR { class IlGenRequest; }
namespace TR { class Options; }
namespace TR { class CodeCache; }
namespace TR { class RegisterMappedSymbol; }
namespace OMR
{
tlsDefine(TR::Compilation *, compilation);
}
TR::SymbolReference *
OMR::Compilation::getSymbolReferenceByReferenceNumber(int32_t referenceNumber)
{
return self()->getSymRefTab()->getSymRef(referenceNumber);
}
ncount_t
OMR::Compilation::getNodeCount()
{
_nodeCount = _compilationNodes->getMaxIndex() + 1;
return _nodeCount;
}
// define some variables to keep track of compilation time
TR_SingleTimer compTime;
TR_SingleTimer genILTime;
TR_SingleTimer optTime;
TR_SingleTimer codegenTime;
static const char *pHotnessNames[numHotnessLevels] =
{
"no-opt", // noOpt
"cold", // cold
"warm", // warm
"hot", // hot
"very-hot", // veryHot
"scorching", // scorching
"reducedWarm", //
"unknown", // unknownHotness
};
const char *
OMR::Compilation::getHotnessName(TR_Hotness h)
{
if (h < minHotness || h >= numHotnessLevels)
return "unknownHotness";
return pHotnessNames[h];
}
OMR::Compilation::Compilation(
int32_t id,
OMR_VMThread *omrVMThread,
TR_FrontEnd *fe,
TR_ResolvedMethod *compilee,
TR::IlGenRequest &ilGenRequest,
TR::Options &options,
TR::Region &heapMemoryRegion,
TR_Memory *m,
TR_OptimizationPlan *optimizationPlan,
TR::Environment *target) :
_signature(compilee->signature(m)),
_options(&options),
_heapMemoryRegion(heapMemoryRegion),
_trMemory(m),
_fe(fe),
_ilGenRequest(ilGenRequest),
_currentOptIndex(0),
_lastBegunOptIndex(0),
_lastPerformedOptIndex(0),
_currentOptSubIndex(0), // The transformation index within the current opt
_lastPerformedOptSubIndex(0),
_debug(0),
_knownObjectTable(NULL),
_omrVMThread(omrVMThread),
_allocator(TRCS2MemoryAllocator(m)),
_method(compilee),
_arenaAllocator(TR::Allocator(self()->allocator("Arena"))),
_aliasRegion(heapMemoryRegion),
_ilGenerator(0),
_ilValidator(NULL),
_optimizer(0),
_currentSymRefTab(NULL),
_recompilationInfo(0),
_optimizationPlan(optimizationPlan),
_primaryRandom(NULL),
_adhocRandom(NULL),
_methodSymbols(m, 10),
_resolvedMethodSymbolReferences(m),
_inlinedCallSites(m),
_inlinedCallStack(m),
_inlinedCallArgInfoStack(m),
_devirtualizedCalls(getTypedAllocator<TR_DevirtualizedCallInfo*>(self()->allocator())),
_inlinedCalls(0),
_inlinedFramesAdded(0),
_virtualGuards(getTypedAllocator<TR_VirtualGuard*>(self()->allocator())),
_staticPICSites(getTypedAllocator<TR::Instruction*>(self()->allocator())),
_staticHCRPICSites(getTypedAllocator<TR::Instruction*>(self()->allocator())),
_staticMethodPICSites(getTypedAllocator<TR::Instruction*>(self()->allocator())),
_snippetsToBePatchedOnClassUnload(getTypedAllocator<TR::Snippet*>(self()->allocator())),
_methodSnippetsToBePatchedOnClassUnload(getTypedAllocator<TR::Snippet*>(self()->allocator())),
_genILSyms(getTypedAllocator<TR::ResolvedMethodSymbol*>(self()->allocator())),
_noEarlyInline(true),
_returnInfo(TR_VoidReturn),
_visitCount(0),
_nodeCount(0),
_accurateNodeCount(0),
_lastValidNodeCount(0),
_maxInlineDepth(0),
_numLivePendingPushSlots(0),
_numNestingLevels(0),
_usesPreexistence(options.getOption(TR_ForceUsePreexistence)),
_loopVersionedWrtAsyncChecks(false),
_commitedCallSiteInfo(false),
_containsBigDecimalLoad(false),
_osrStateIsReliable(true),
_canAffordOSRControlFlow(true),
_osrInfrastructureRemoved(false),
_toNumberMap(self()->allocator("toNumberMap")),
_toStringMap(self()->allocator("toStringMap")),
_toCommentMap(self()->allocator("toCommentMap")),
_nextOptLevel(unknownHotness),
_errorCode(COMPILATION_SUCCEEDED),
_peekingArgInfo(m),
_peekingSymRefTab(NULL),
_checkcastNullChkInfo(getTypedAllocator<TR_Pair<TR_ByteCodeInfo, TR::Node> *>(self()->allocator())),
_nodesThatShouldPrefetchOffset(getTypedAllocator<TR_Pair<TR::Node,uint32_t> *>(self()->allocator())),
_extraPrefetchInfo(getTypedAllocator<TR_PrefetchInfo*>(self()->allocator())),
_debugCounterMap(std::less<const void *>(), getTypedAllocator<DebugCounterEntry>(self()->allocator())),
_currentBlock(NULL),
_verboseOptTransformationCount(0),
_relocatableMethodCodeStart(NULL),
_compThreadID(id),
_failCHtableCommitFlag(false),
_phaseTimer("Compilation", self()->allocator("phaseTimer"), self()->getOption(TR_Timing)),
_phaseMemProfiler("Compilation", self()->allocator("phaseMemProfiler"), self()->getOption(TR_LexicalMemProfiler)),
_compilationNodes(NULL),
_copyPropagationRematerializationCandidates(self()->allocator("CP rematerialization")),
_nodeOpCodeLength(0),
_prevSymRefTabSize(0),
_scratchSpaceLimit(TR::Options::_scratchSpaceLimit),
_cpuTimeAtStartOfCompilation(-1),
_ilVerifier(NULL),
_gpuPtxList(m),
_gpuKernelLineNumberList(m),
_gpuPtxCount(0),
_bitVectorPool(self()),
_typeLayoutMap((LayoutComparator()), LayoutAllocator(self()->region())),
_tlsManager(*self())
{
if (target != NULL)
{
_target = *target;
}
else
{
_target = TR::Compiler->target;
}
//Avoid expensive initialization and uneeded option checking if we are doing AOT Loads
if (_optimizationPlan && _optimizationPlan->getIsAotLoad())
{
#ifdef J9_PROJECT_SPECIFIC
_transientCHTable = NULL;
_metadataAssumptionList = NULL;
#endif
_symRefTab = NULL;
_methodSymbol = NULL;
_codeGenerator = NULL;
_recompilationInfo = NULL;
_globalRegisterCandidates = NULL;
_osrCompilationData = NULL;
return;
}
#ifdef J9_PROJECT_SPECIFIC
_transientCHTable = new (_trMemory->trHeapMemory()) TR_CHTable(_trMemory);
_metadataAssumptionList = NULL;
#endif
_symRefTab = new (_trMemory->trHeapMemory()) TR::SymbolReferenceTable(_method->maxBytecodeIndex(), self());
_compilationNodes = new (_trMemory->trHeapMemory()) TR::NodePool(self());
#ifdef J9_PROJECT_SPECIFIC
// The following must stay before the first assumption gets created which could happen
// while the PersistentMethodInfo is allocated during codegen creation
// Access to this list must be performed with assumptionTableMutex in hand
//
if (!options.getOption(TR_DisableFastAssumptionReclamation))
_metadataAssumptionList = new (m->trPersistentMemory()) TR::SentinelRuntimeAssumption();
#endif
//Random fields must be set before allocating codegen
_primaryRandom = new (m->trHeapMemory()) TR_RandomGenerator(options.getRandomSeed());
_adhocRandom = new (m->trHeapMemory()) TR_RandomGenerator(options.getRandomSeed());
if (options.getOption(TR_RandomSeedSignatureHash))
{
uint32_t hash = 0;
for (const char *c = self()->signature(); *c; c++)
hash = 33*hash + (uint32_t)(*c);
uint32_t seed = _options->getRandomSeed();
seed ^= hash;
_primaryRandom->setSeed(seed);
_adhocRandom->setSeed(_primaryRandom->getRandom());
}
if (ilGenRequest.details().isMethodInProgress())
{
_flags.set(IsDLTCompile);
options.setAllowRecompilation(false);
}
if (optimizationPlan)
{
if (optimizationPlan->isGPUCompilation())
_flags.set(IsGPUCompilation);
if (optimizationPlan->isGPUCompileCPUCode())
_flags.set(IsGPUCompileCPUCode);
self()->setGPUBlockDimX(optimizationPlan->getGPUBlockDimX());
self()->setGPUParms(optimizationPlan->getGPUParms());
}
// if we are not in the selective NoOptServer mode
_isOptServer = (!options.getOption(TR_NoOptServer)) &&
( options.getOption(TR_Server)
#ifdef J9_PROJECT_SPECIFIC
|| (self()->getPersistentInfo()->getNumLoadedClasses() >= TR::Options::_bigAppThreshold)
#endif
);
_isServerInlining = !options.getOption(TR_NoOptServer);
// TR_DisableInternalPointers must be set before the TR::CodeGenerator object is created because
// CodeGenerator's _disableInternalPointers member is set in its constructor and this is one of
// options that is checked for
if (_isOptServer)
{
if(self()->getMethodHotness() <= warm)
{
if (!self()->target().cpu.isPower()) // Temporarily exclude PPC due to perf regression
self()->setOption(TR_DisableInternalPointers);
}
}
//_methodSymbol must be done after symRefTab, but before codegen
// _methodSymbol must be initialized here because creating a jitted method symbol
// actually inspects TR::comp()->_methodSymbol (to compare against the new object)
_methodSymbol = NULL;
{
_methodSymbol = TR::ResolvedMethodSymbol::createJittedMethodSymbol(self()->trHeapMemory(), compilee, self());
}
// initPersistentCPUField and createOpCode must be done after method symbol creation
if (self()->getOption(TR_EnableNodeGC))
{
self()->getNodePool().enableNodeGC();
}
if (self()->getOption(TR_ForceGenerateReadOnlyCode))
{
self()->setGenerateReadOnlyCode();
}
//codegen also needs _methodSymbol
_codeGenerator = TR::CodeGenerator::create(self());
_recompilationInfo = _codeGenerator->getSupportsRecompilation() ? _codeGenerator->allocateRecompilationInfo() : NULL;
_globalRegisterCandidates = new (self()->trHeapMemory()) TR_RegisterCandidates(self());
#ifdef J9_PROJECT_SPECIFIC
if (_recompilationInfo && options.getOptLevelDowngraded())
_recompilationInfo->getMethodInfo()->setOptLevelDowngraded(true);
#endif
static bool firstTime = true;
if (firstTime)
{
firstTime = false;
TR::ILOpCode::checkILOpArrayLengths();
#ifdef J9_PROJECT_SPECIFIC
TR_ASSERT(TR::DataType::getMaxPackedDecimalSize() == TR::DataType::packedDecimalPrecisionToByteLength(TR_MAX_DECIMAL_PRECISION),
"TR::DataType::getMaxPackedDecimalSize() (%d) does not agree with precToSize(TR_MAX_DECIMAL_PRECISION) (%d)\n",
TR::DataType::getMaxPackedDecimalSize(), TR::DataType::packedDecimalPrecisionToByteLength(TR_MAX_DECIMAL_PRECISION));
#endif
}
static const char *enableOSRAtAllOptLevels = feGetEnv("TR_EnableOSRAtAllOptLevels");
// If the outermost method is native, OSR is not supported
if (_methodSymbol->isNative())
self()->setOption(TR_DisableOSR);
// Do not default OSR on if:
// NextGenHCR is disabled, as it is enabled for it
// OSR is explicitly disabled
// FSD is enabled, as HCR cannot be enabled with it
// HCR has not been enabled
if (!self()->getOption(TR_DisableNextGenHCR) && !self()->getOption(TR_DisableOSR) && !self()->getOption(TR_FullSpeedDebug) && self()->getOption(TR_EnableHCR))
{
self()->setOption(TR_EnableOSR); // OSR must be enabled for NextGenHCR
}
if (self()->isDLT() || (((self()->getMethodHotness() < warm) || self()->compileRelocatableCode() || self()->isProfilingCompilation()) && !enableOSRAtAllOptLevels && !_options->getOption(TR_FullSpeedDebug)))
{
self()->setOption(TR_DisableOSR);
_options->setOption(TR_EnableOSR, false);
_options->setOption(TR_EnableOSROnGuardFailure, false);
}
if (options.getOption(TR_EnableOSR))
{
// Current implementation of partial inlining will break OSR
self()->setOption(TR_DisablePartialInlining);
//TODO: investigate the memory footprint of this allocation
_osrCompilationData = new (self()->trHeapMemory()) TR_OSRCompilationData(self());
if (((self()->getMethodHotness() < warm) || self()->compileRelocatableCode() || self()->isProfilingCompilation()) && !enableOSRAtAllOptLevels && !options.getOption(TR_FullSpeedDebug)) // Off for two reasons : 1) not sure if we can afford the increase in compile time due to the extra OSR control flow at cold and 2) not sure at this stage in 727 whether OSR can work with AOT (will try to find out soon) but disabling till I do find out
_canAffordOSRControlFlow = false;
}
else
_osrCompilationData = NULL;
}
OMR::Compilation::~Compilation() throw()
{
}
TR::KnownObjectTable *
OMR::Compilation::getOrCreateKnownObjectTable()
{
_knownObjectTable = NULL;
return _knownObjectTable;
}
void
OMR::Compilation::freeKnownObjectTable()
{
_knownObjectTable = NULL;
}
int32_t
OMR::Compilation::maxInternalPointers()
{
return 0;
}
bool
OMR::Compilation::isOutermostMethod()
{
if ((self()->getInlineDepth() != 0) || self()->isPeekingMethod())
return false;
return true;
}
bool
OMR::Compilation::ilGenTrace()
{
if (self()->isOutermostMethod() || self()->getOption(TR_DebugInliner) || self()->trace(OMR::inlining))
return true;
return false;
}
int32_t
OMR::Compilation::getOptLevel()
{
return _options->getOptLevel();
}
bool
OMR::Compilation::allocateAtThisOptLevel()
{
return self()->getOptLevel() > warm;
}
TR::PersistentInfo *
OMR::Compilation::getPersistentInfo()
{
return self()->trPersistentMemory()->getPersistentInfo();
}
int32_t
OMR::Compilation::getMaxAliasIndex()
{
return self()->getSymRefCount();
}
bool
OMR::Compilation::isPeekingMethod()
{
return self()->getCurrentSymRefTab() != 0;
}
TR_Hotness
OMR::Compilation::getMethodHotness()
{
return (TR_Hotness) self()->getOptLevel();
}
ncount_t
OMR::Compilation::getAccurateNodeCount()
{
self()->generateAccurateNodeCount();
return _accurateNodeCount;
}
const char *
OMR::Compilation::getHotnessName()
{
return TR::Compilation::getHotnessName(self()->getMethodHotness());
}
TR::ResolvedMethodSymbol * OMR::Compilation::createJittedMethodSymbol(TR_ResolvedMethod *resolvedMethod)
{
return TR::ResolvedMethodSymbol::createJittedMethodSymbol(self()->trHeapMemory(), resolvedMethod, self());
}
bool OMR::Compilation::canAffordOSRControlFlow()
{
if (self()->getOption(TR_DisableOSR) || !self()->getOption(TR_EnableOSR))
{
return false;
}
if (self()->osrInfrastructureRemoved())
{
return false;
}
return _canAffordOSRControlFlow;
}
void OMR::Compilation::setSeenClassPreventingInducedOSR()
{
if (_osrCompilationData)
_osrCompilationData->setSeenClassPreventingInducedOSR();
}
bool OMR::Compilation::supportsInduceOSR()
{
if (_osrInfrastructureRemoved)
{
if (self()->getOption(TR_TraceOSR))
traceMsg(self(), "OSR induction cannot be performed after OSR infrastructure has been removed\n");
return false;
}
if (!self()->canAffordOSRControlFlow())
{
if (self()->getOption(TR_TraceOSR))
traceMsg(self(), "canAffordOSRControlFlow is false - OSR induction is not supported\n");
return false;
}
if (self()->getOption(TR_MimicInterpreterFrameShape) && !self()->getOption(TR_FullSpeedDebug)/* && areSlotsSharedByRefAndNonRef() */)
{
if (self()->getOption(TR_TraceOSR))
traceMsg(self(), "MimicInterpreterFrameShape is set - OSR induction is not supported\n");
return false;
}
if (self()->isDLT() /* && getJittedMethodSymbol()->sharesStackSlots(self()) */)
{
if (self()->getOption(TR_TraceOSR))
traceMsg(self(), "DLT compilation - OSR induction is not supported\n");
return false;
}
if (_osrCompilationData && _osrCompilationData->seenClassPreventingInducedOSR())
{
if (self()->getOption(TR_TraceOSR))
traceMsg(self(), "Cannot guarantee OSR transfer of control to the interpreter will work for calls preventing induced OSR (e.g. Quad) because of differences in JIT vs interpreter representations\n");
return false;
}
return true;
}
bool OMR::Compilation::penalizePredsOfOSRCatchBlocksInGRA()
{
if (!self()->getOption(TR_EnableOSR))
return false;
if (self()->getOption(TR_FullSpeedDebug))
return false;
return true;
}
bool OMR::Compilation::isShortRunningMethod(int32_t callerIndex)
{
return false;
}
bool OMR::Compilation::isPotentialOSRPoint(TR::Node *node, TR::Node **osrPointNode, bool ignoreInfra)
{
static char *disableAsyncCheckOSR = feGetEnv("TR_disableAsyncCheckOSR");
static char *disableGuardedCallOSR = feGetEnv("TR_disableGuardedCallOSR");
static char *disableMonentOSR = feGetEnv("TR_disableMonentOSR");
bool potentialOSRPoint = false;
if (self()->isOSRTransitionTarget(TR::postExecutionOSR))
{
if (node->getOpCodeValue() == TR::treetop || node->getOpCode().isCheck())
node = node->getFirstChild();
if (_osrInfrastructureRemoved && !ignoreInfra)
potentialOSRPoint = false;
else if (node->getOpCodeValue() == TR::asynccheck)
{
if (disableAsyncCheckOSR == NULL)
potentialOSRPoint = !self()->isShortRunningMethod(node->getByteCodeInfo().getCallerIndex());
}
else if (node->getOpCode().isCall())
{
TR::SymbolReference *callSymRef = node->getSymbolReference();
if (node->isPotentialOSRPointHelperCall())
{
potentialOSRPoint = true;
}
else if (callSymRef->getReferenceNumber() >=
self()->getSymRefTab()->getNonhelperIndex(self()->getSymRefTab()->getLastCommonNonhelperSymbol())
&& !((TR::MethodSymbol*)(callSymRef->getSymbol()))->functionCallDoesNotYieldOSR())
{
potentialOSRPoint = (disableGuardedCallOSR == NULL);
}
}
else if (node->getOpCodeValue() == TR::monent)
potentialOSRPoint = (disableMonentOSR == NULL);
}
else if (node->canGCandReturn())
potentialOSRPoint = true;
else if (self()->getOSRMode() == TR::involuntaryOSR && node->canGCandExcept())
potentialOSRPoint = true;
if (osrPointNode && potentialOSRPoint)
(*osrPointNode) = node;
return potentialOSRPoint;
}
bool OMR::Compilation::isPotentialOSRPointWithSupport(TR::TreeTop *tt)
{
TR::Node *osrNode;
bool potentialOSRPoint = self()->isPotentialOSRPoint(tt->getNode(), &osrNode);
if (potentialOSRPoint && self()->getOSRMode() == TR::voluntaryOSR)
{
if (self()->isOSRTransitionTarget(TR::postExecutionOSR) && tt->getNode() != osrNode)
{
// The OSR point applies where the node is anchored, rather than where it may
// be commoned. Therefore, it is necessary to check if the node is anchored under
// a prior treetop.
if (osrNode->getReferenceCount() > 1)
{
TR::TreeTop *cursor = tt->getPrevTreeTop();
while (cursor)
{
if ((cursor->getNode()->getOpCode().isCheck() || cursor->getNode()->getOpCodeValue() == TR::treetop)
&& cursor->getNode()->getFirstChild() == osrNode)
{
potentialOSRPoint = false;
break;
}
if (cursor->getNode()->getOpCodeValue() == TR::BBStart &&
!cursor->getNode()->getBlock()->isExtensionOfPreviousBlock())
break;
cursor = cursor->getPrevTreeTop();
}
}
}
if (potentialOSRPoint)
{
TR_ByteCodeInfo &bci = osrNode->getByteCodeInfo();
TR::ResolvedMethodSymbol *method = bci.getCallerIndex() == -1 ?
self()->getMethodSymbol() : self()->getInlinedResolvedMethodSymbol(bci.getCallerIndex());
potentialOSRPoint = method->supportsInduceOSR(bci, tt->getEnclosingBlock(), self(), false);
}
}
return potentialOSRPoint;
}
/*
* OSR can operate in two modes, voluntary and involuntary.
*
* In involuntary OSR, the JITed code does not control when an OSR transition occurs. It can be
* initiated externally at any potential OSR point.
*
* In voluntary OSR, the JITed code does control when an OSR transition occurs, allowing it to
* limit the OSR points with transitions.
*/
TR::OSRMode
OMR::Compilation::getOSRMode()
{
if (self()->getOption(TR_FullSpeedDebug))
return TR::involuntaryOSR;
return TR::voluntaryOSR;
}
/*
* The OSR transition destination may be before or after the OSR point.
* When located before, the transition will target the bytecode index of
* the OSR point, whilst those located after may have an offset bytecode
* index.
*/
TR::OSRTransitionTarget
OMR::Compilation::getOSRTransitionTarget()
{
TR::OSRTransitionTarget target = TR::disableOSR;
// Under NextGenHCR, transitions will occur after the OSR points
// Otherwise, the default is before
if (self()->getHCRMode() == TR::osr)
{
target = TR::postExecutionOSR;
// If OSROnGuardFailure is enabled, transitions will also occur before
if (self()->getOption(TR_EnableOSROnGuardFailure))
target = TR::preAndPostExecutionOSR;
}
else if (self()->getOption(TR_EnableOSR))
target = TR::preExecutionOSR;
return target;
}
bool
OMR::Compilation::isOSRTransitionTarget(TR::OSRTransitionTarget target)
{
return target & self()->getOSRTransitionTarget();
}
/*
* Provides the bytecode offset between the OSR point and the destination
* of the transition. Only used when doing postExecutionOSR to indicate
* the appropriate bytecode index after the OSR point.
*/
int32_t
OMR::Compilation::getOSRInductionOffset(TR::Node *node)
{
// If no induction after the OSR point, offset must be 0
if (!self()->isOSRTransitionTarget(TR::postExecutionOSR))
return 0;
TR::Node *osrNode;
if (!self()->isPotentialOSRPoint(node, &osrNode))
{
TR_ASSERT(0, "getOSRInductionOffset should only be called on OSR points");
}
if (osrNode->isPotentialOSRPointHelperCall())
{
return osrNode->getOSRInductionOffset();
}
if (osrNode->getOpCode().isCall())
return 3;
// If the monent has a bytecode index of 0, it must be the
// monent for a synchronized method. A transition here
// must target the method entry.
if (osrNode->getOpCodeValue() == TR::monent)
{
if (osrNode->getByteCodeIndex() == 0)
return 0;
else
return 1;
}
if (osrNode->getOpCodeValue() == TR::asynccheck)
return 0;
TR_ASSERT(0, "OSR points should only be calls, monents or asyncchecks");
return 0;
}
/*
* An OSR analysis point is used only for OSRDefAnalysis
* and will not become a transition point. It is required
* for certain OSR points when doing postExecutionOSR.
* For example, liveness data must be know before an inlined
* call, to reconstruct the caller's frame, but the transition
* can only occur after the call.
*
* An analysis point does not have an induction offset.
*/
bool
OMR::Compilation::requiresAnalysisOSRPoint(TR::Node *node)
{
// If no induction after the OSR point, cannot use analysis point
if (!self()->isOSRTransitionTarget(TR::postExecutionOSR))
return false;
TR::Node *osrNode;
if (!self()->isPotentialOSRPoint(node, &osrNode))
{
TR_ASSERT(0, "requiresAnalysisOSRPoint should only be called on OSR points\n");
return false;
}
// Calls require an analysis and transition point as liveness may change across them
if (osrNode->getOpCode().isCall())
return true;
switch (osrNode->getOpCodeValue())
{
// Monents only require a trailing OSR point as they will perform OSR when executing the
// monitor and there is no change in liveness due to the monent
case TR::monent:
// Asyncchecks will not modify liveness
case TR::asynccheck:
return false;
default:
TR_ASSERT(0, "OSR points should only be calls, monents or asyncchecks");
return false;
}
}
/**
* To reduce OSR overhead, OSRLiveRangeAnalysis supports solving liveness analysis
* during IlGen, as an approximation of this information is commonly known at this
* stage.
*
* If this function returns true, OSRLiveRangeAnalysis expects pending push liveness
* information to be stashed in OSRData using addPendingPushLivenessInfo prior to
* its execution in IlGenOpts. Returning true without the correct information stashed
* will result in reduced performance and failed OSR transitions.
*
* If this function returns false, OSRLiveRangeAnalysis will perform liveness analysis
* on pending push symbols.
*/
bool
OMR::Compilation::pendingPushLivenessDuringIlgen()
{
return false;
}
/**
* A profiling compilation will include instrumentation to collect information
* on block and value frequencies. isProfilingCompilation() should return true for
* such a compilation and getProfilingMode() can distinguish between the profiling
* implementations.
*/
bool
OMR::Compilation::isProfilingCompilation()
{
return _recompilationInfo ? _recompilationInfo->isProfilingCompilation() : false;
}
ProfilingMode
OMR::Compilation::getProfilingMode()
{
if (!self()->isProfilingCompilation())
return DisabledProfiling;
if (self()->getOption(TR_EnableJProfiling) || !self()->getOption(TR_DisableJProfilingInProfilingCompilations))
return JProfiling;
return JitProfiling;
}
bool
OMR::Compilation::isJProfilingCompilation()
{
return false;
}
#if defined(AIXPPC) || defined(LINUX) || defined(J9ZOS390) || defined(OMR_OS_WINDOWS)
static void stopBeforeCompile()
{
static int first = 1;
// only print the following message once
if (first)
{
printf("stopBeforeCompile is a dummy routine.\n");
first = 0;
}
}
#endif /* defined(AIXPPC) || defined(LINUX) || defined(J9ZOS390) || defined(OMR_OS_WINDOWS) */
static int32_t strHash(const char *str)
{
// The string hash from Java
int32_t result = 0;
for (const unsigned char *s = reinterpret_cast<const unsigned char*>(str); *s; s++)
result = result * 33 + *s;
return result;
}
int32_t OMR::Compilation::compile()
{
if (!self()->getOption(TR_DisableSupportForCpuSpentInCompilation))
_cpuTimeAtStartOfCompilation = TR::Compiler->vm.cpuTimeSpentInCompilationThread(self());
bool printCodegenTime = self()->getOption(TR_CummTiming);
if (self()->isOptServer())
self()->setOption(TR_DisablePartialInlining);
#ifdef J9_PROJECT_SPECIFIC
if (self()->getOptions()->getDelayCompile())
{
uint64_t limit = (uint64_t)self()->getOptions()->getDelayCompile();
uint64_t starttime = self()->getPersistentInfo()->getElapsedTime();
fprintf(stderr,"\nDelayCompile: Starting a delay of length %" OMR_PRIu64 " for method %s at time %" OMR_PRIu64 ".", limit, self()->signature(), starttime);
fflush(stderr);
uint64_t temp=0;
while(1)
{
temp = self()->getPersistentInfo()->getElapsedTime();
if( ( temp - starttime ) > limit)
{
fprintf(stderr,"\nDelayCompile: Finished delay at time = %" OMR_PRIu64 ", elapsed time = %" OMR_PRIu64 "\n", temp, (temp - starttime));
break;
}
}
}
self()->setGetImplInlineable(self()->fej9()->isGetImplInliningSupported());
#endif
if (self()->getOption(TR_BreakBeforeCompile))
{
fprintf(stderr, "\n=== About to compile %s ===\n", self()->signature());
TR::Compiler->debug.breakPoint();
}
#if defined(AIXPPC)
if (self()->getOption(TR_DebugBeforeCompile))
{
self()->getDebug()->setupDebugger((void *) *((long*)&(stopBeforeCompile)));
stopBeforeCompile();
}
#elif defined(LINUX) || defined(J9ZOS390) || defined(OMR_OS_WINDOWS)
if (self()->getOption(TR_DebugBeforeCompile))
{
#if defined(LINUXPPC64)
self()->getDebug()->setupDebugger((void *) *((long*)&(stopBeforeCompile)),(void *) *((long*)&(stopBeforeCompile)), true);
#else
self()->getDebug()->setupDebugger((void *) &stopBeforeCompile,(void *) &stopBeforeCompile,true);
#endif /* defined(LINUXPPC64) */
stopBeforeCompile();
}
#endif /* defined(AIXPPC) */