-
Notifications
You must be signed in to change notification settings - Fork 746
/
Copy pathJ9Compilation.cpp
1726 lines (1471 loc) · 57.6 KB
/
J9Compilation.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 IBM Corp. and others 2000
*
* 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 https://www.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] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
#if defined(J9ZOS390)
#pragma csect(CODE,"TRJ9CompBase#C")
#pragma csect(STATIC,"TRJ9CompBase#S")
#pragma csect(TEST,"TRJ9CompBase#T")
#endif
#include "compile/J9Compilation.hpp"
#include <stdint.h>
#include "codegen/CodeGenerator.hpp"
#include "codegen/Instruction.hpp"
#include "compile/Compilation.hpp"
#include "compile/Compilation_inlines.hpp"
#include "compile/CompilationTypes.hpp"
#include "env/DependencyTable.hpp"
#include "compile/ResolvedMethod.hpp"
#include "control/OptimizationPlan.hpp"
#include "control/Options.hpp"
#include "control/Options_inlines.hpp"
#include "control/Recompilation.hpp"
#include "control/RecompilationInfo.hpp"
#include "env/j9method.h"
#include "env/TRMemory.hpp"
#include "env/VMJ9.h"
#include "env/VMAccessCriticalSection.hpp"
#include "env/KnownObjectTable.hpp"
#include "env/VerboseLog.hpp"
#include "exceptions/PersistenceFailure.hpp"
#include "il/Node.hpp"
#include "il/Node_inlines.hpp"
#include "ilgen/IlGenRequest.hpp"
#include "infra/List.hpp"
#include "optimizer/Inliner.hpp"
#include "optimizer/OptimizationManager.hpp"
#include "optimizer/Optimizer.hpp"
#include "optimizer/TransformUtil.hpp"
#include "runtime/RuntimeAssumptions.hpp"
#include "runtime/J9Profiler.hpp"
#include "OMR/Bytes.hpp"
#include "il/ParameterSymbol.hpp"
#include "j9.h"
#include "j9cfg.h"
/*
* There should be no allocations that use the global operator new, since
* all allocations should go through the JitMemory allocation routines.
* To catch cases that we miss, we define global operator new and delete here.
* (xlC won't link statically with the -noe flag when we override these.)
*/
bool firstCompileStarted = false;
// JITSERVER_TODO: disabled to allow for JITServer
#if !defined(J9VM_OPT_JITSERVER)
void *operator new(size_t size)
{
#if defined(DEBUG)
#if LINUX
// glibc allocates something at dl_init; check if a method is being compiled to avoid
// getting assumes at _dl_init
if (firstCompileStarted)
#endif
{
printf( "\n*** ERROR *** Invalid use of global operator new\n");
TR_ASSERT(0,"Invalid use of global operator new");
}
#endif
return malloc(size);
}
// Avoid -Wimplicit-exception-spec-mismatch error on platforms that specify the global delete operator with throw()
#ifndef _NOEXCEPT
#define _NOEXCEPT
#endif
/**
* Since we are using arena allocation, heap deletions must be a no-op, and
* can't be used by JIT code, so we inject an assertion here.
*/
void operator delete(void *) _NOEXCEPT
{
TR_ASSERT(0, "Invalid use of global operator delete");
}
#endif /* !defined(J9VM_OPT_JITSERVER) */
uint64_t J9::Compilation::_maxYieldIntervalS = 0;
TR_CallingContext J9::Compilation::_sourceContextForMaxYieldIntervalS = NO_CONTEXT;
TR_CallingContext J9::Compilation::_destinationContextForMaxYieldIntervalS = NO_CONTEXT;
TR_Stats** J9::Compilation::_compYieldStatsMatrix = NULL;
const char * callingContextNames[] = {
"FBVA_INITIALIZE_CONTEXT",
"FBVA_ANALYZE_CONTEXT",
"BBVA_INITIALIZE_CONTEXT",
"BBVA_ANALYZE_CONTEXT",
"GRA_ASSIGN_CONTEXT",
"PRE_ANALYZE_CONTEXT",
"AFTER_INSTRUCTION_SELECTION_CONTEXT",
"AFTER_REGISTER_ASSIGNMENT_CONTEXT",
"AFTER_POST_RA_SCHEDULING_CONTEXT",
"BEFORE_PROCESS_STRUCTURE_CONTEXT",
"GRA_FIND_LOOPS_AND_CORRESPONDING_AUTOS_BLOCK_CONTEXT",
"GRA_AFTER_FIND_LOOP_AUTO_CONTEXT",
"ESC_CHECK_DEFSUSES_CONTEXT",
"LAST_CONTEXT"
};
#if defined(J9VM_OPT_JITSERVER)
bool J9::Compilation::_outOfProcessCompilation = false;
#endif /* defined(J9VM_OPT_JITSERVER) */
J9::Compilation::Compilation(int32_t id,
J9VMThread *j9vmThread,
TR_FrontEnd *fe,
TR_ResolvedMethod *compilee,
TR::IlGenRequest &ilGenRequest,
TR::Options &options,
TR::Region &heapMemoryRegion,
TR_Memory *m,
TR_OptimizationPlan *optimizationPlan,
TR_RelocationRuntime *reloRuntime,
TR::Environment *target)
: OMR::CompilationConnector(
id,
j9vmThread->omrVMThread,
(firstCompileStarted = true, fe),
compilee,
ilGenRequest,
options,
heapMemoryRegion,
m,
optimizationPlan,
target),
_updateCompYieldStats(
options.getOption(TR_EnableCompYieldStats) ||
options.getVerboseOption(TR_VerboseCompYieldStats) ||
TR::Options::_compYieldStatsHeartbeatPeriod > 0),
_maxYieldInterval(0),
_previousCallingContext(NO_CONTEXT),
_sourceContextForMaxYieldInterval(NO_CONTEXT),
_destinationContextForMaxYieldInterval(NO_CONTEXT),
_needsClassLookahead(true),
_reservedDataCache(NULL),
_totalNeededDataCacheSpace(0),
_aotMethodDataStart(NULL),
_curMethodMetadata(NULL),
_getImplAndRefersToInlineable(false),
_vpInfoManager(NULL),
_bpInfoManager(NULL),
_methodBranchInfoList(getTypedAllocator<TR_MethodBranchProfileInfo*>(self()->allocator())),
_externalVPInfoList(getTypedAllocator<TR_ExternalValueProfileInfo*>(self()->allocator())),
_doneHWProfile(false),
_hwpInstructions(m),
_hwpBCMap(m),
_sideEffectGuardPatchSites(getTypedAllocator<TR_VirtualGuardSite*>(self()->allocator())),
_j9VMThread(j9vmThread),
_monitorAutos(m),
_monitorAutoSymRefsInCompiledMethod(getTypedAllocator<TR::SymbolReference*>(self()->allocator())),
_classForOSRRedefinition(m),
_classForStaticFinalFieldModification(m),
_profileInfo(NULL),
_skippedJProfilingBlock(false),
_reloRuntime(reloRuntime),
#if defined(J9VM_OPT_JITSERVER)
_remoteCompilation(false),
_serializedRuntimeAssumptions(getTypedAllocator<SerializedRuntimeAssumption *>(self()->allocator())),
_clientData(NULL),
_stream(NULL),
_globalMemory(*::trPersistentMemory, heapMemoryRegion),
_perClientMemory(_trMemory),
_methodsRequiringTrampolines(getTypedAllocator<TR_OpaqueMethodBlock *>(self()->allocator())),
_deserializedAOTMethod(false),
_deserializedAOTMethodStore(false),
_deserializedAOTMethodUsingSVM(false),
_aotCacheStore(false),
_ignoringLocalSCC(false),
_serializationRecords(decltype(_serializationRecords)::allocator_type(heapMemoryRegion)),
_thunkRecords(decltype(_thunkRecords)::allocator_type(heapMemoryRegion)),
#endif /* defined(J9VM_OPT_JITSERVER) */
#if !defined(PERSISTENT_COLLECTIONS_UNSUPPORTED)
_aotMethodDependencies(decltype(_aotMethodDependencies)::allocator_type(heapMemoryRegion)),
#endif /* !defined(PERSISTENT_COLLECTIONS_UNSUPPORTED) */
_osrProhibitedOverRangeOfTrees(false),
_wasFearPointAnalysisDone(false)
{
_symbolValidationManager = new (self()->region()) TR::SymbolValidationManager(self()->region(), compilee, self());
_aotClassClassPointer = NULL;
_aotClassClassPointerInitialized = false;
_aotGuardPatchSites = new (m->trHeapMemory()) TR::list<TR_AOTGuardSite *>(getTypedAllocator<TR_AOTGuardSite *>(self()->allocator()));
_aotClassInfo = new (m->trHeapMemory()) TR::list<TR::AOTClassInfo *>(getTypedAllocator<TR::AOTClassInfo *>(self()->allocator()));
if (_updateCompYieldStats)
_hiresTimeForPreviousCallingContext = TR::Compiler->vm.getHighResClock(self());
_profileInfo = new (m->trHeapMemory()) TR_AccessedProfileInfo(heapMemoryRegion);
for (int i = 0; i < CACHED_CLASS_POINTER_COUNT; i++)
_cachedClassPointers[i] = NULL;
// Add known object index to parm 0 so that other optmizations can be unlocked.
// It is safe to do so because method and method symbols of a archetype specimen
// are not shared other methods.
//
TR::KnownObjectTable *knot = self()->getOrCreateKnownObjectTable();
TR::IlGeneratorMethodDetails & details = ilGenRequest.details();
if (knot && details.isMethodHandleThunk())
{
J9::MethodHandleThunkDetails & thunkDetails = static_cast<J9::MethodHandleThunkDetails &>(details);
if (thunkDetails.isCustom())
{
TR::KnownObjectTable::Index index = knot->getOrCreateIndexAt(thunkDetails.getHandleRef());
ListIterator<TR::ParameterSymbol> parms(&_methodSymbol->getParameterList());
TR::ParameterSymbol* parm0 = parms.getFirst();
parm0->setKnownObjectIndex(index);
}
}
}
J9::Compilation::~Compilation()
{
_profileInfo->~TR_AccessedProfileInfo();
}
TR_J9VMBase *
J9::Compilation::fej9()
{
return (TR_J9VMBase *)self()->fe();
}
TR_J9VM *
J9::Compilation::fej9vm()
{
return (TR_J9VM *)self()->fe();
}
void
J9::Compilation::updateCompYieldStatistics(TR_CallingContext callingContext)
{
// get time of this call
//
uint64_t crtTime = TR::Compiler->vm.getHighResClock(self());
// compute the difference between 2 consecutive calls
//
static uint64_t hiresClockResolution = TR::Compiler->vm.getHighResClockResolution();
uint64_t ticks = crtTime - _hiresTimeForPreviousCallingContext;
uint64_t diffTime;
if (hiresClockResolution < 1000000)
diffTime = (ticks * 1000000)/hiresClockResolution;
else
diffTime = ticks / (hiresClockResolution/1000000);
// update stats for the corresponding cell in the matrix
// May lead to problems in the future when we add multiple compilation threads
//
if (self()->getOption(TR_EnableCompYieldStats))
_compYieldStatsMatrix[(int32_t)_previousCallingContext][(int32_t)callingContext].update((double)diffTime);
if (self()->getOptions()->getVerboseOption(TR_VerboseCompYieldStats))
{
if (diffTime > _maxYieldInterval)
{
_maxYieldInterval = diffTime;
_sourceContextForMaxYieldInterval = _previousCallingContext;
_destinationContextForMaxYieldInterval = callingContext;
}
}
if (TR::Options::_compYieldStatsHeartbeatPeriod > 0)
{
if (diffTime > _maxYieldIntervalS)
{
_maxYieldIntervalS = diffTime;
_sourceContextForMaxYieldIntervalS = _previousCallingContext;
_destinationContextForMaxYieldIntervalS = callingContext;
}
}
// prepare for next call
//
_hiresTimeForPreviousCallingContext = crtTime;
_previousCallingContext = callingContext;
}
void
J9::Compilation::allocateCompYieldStatsMatrix()
{
// need to use persistent memory
_compYieldStatsMatrix = (TR_Stats**)TR::Compilation::jitPersistentAlloc(sizeof(TR_Stats *)*(int32_t)LAST_CONTEXT);
for (int32_t i=0; i < (int32_t)LAST_CONTEXT; i++)
{
_compYieldStatsMatrix[i] = (TR_Stats *)TR::Compilation::jitPersistentAlloc(sizeof(TR_Stats)*(int32_t)LAST_CONTEXT);
for (int32_t j=0; j < (int32_t)LAST_CONTEXT; j++)
{
char buffer[128];
snprintf(buffer, sizeof(buffer), "%d-%d", i,j);
_compYieldStatsMatrix[i][j].setName(buffer);
}
}
}
void
J9::Compilation::printCompYieldStats()
{
TR_VerboseLog::writeLine(
TR_Vlog_PERF,
"Max yield-to-yield time of %u usec for %s -- %s",
static_cast<uint32_t>(_maxYieldInterval),
J9::Compilation::getContextName(_sourceContextForMaxYieldInterval),
J9::Compilation::getContextName(_destinationContextForMaxYieldInterval));
}
const char *
J9::Compilation::getContextName(TR_CallingContext context)
{
if (context == (TR_CallingContext)OMR::endOpts || context == TR_CallingContext::NO_CONTEXT)
return "NO CONTEXT";
else if (context < (TR_CallingContext)OMR::numOpts)
return TR::Optimizer::getOptimizationName((OMR::Optimizations)context);
else
return callingContextNames[context - (TR_CallingContext)OMR::numOpts];
}
void
J9::Compilation::printEntryName(int32_t i, int32_t j)
{
fprintf(stderr, "\n%s -", J9::Compilation::getContextName((TR_CallingContext) i));
fprintf(stderr, "- %s\n", J9::Compilation::getContextName((TR_CallingContext) j));
}
void
J9::Compilation::printCompYieldStatsMatrix()
{
if (!_compYieldStatsMatrix)
return; // the matrix may not have been allocated (for instance when we give a bad command line option)
for (int32_t i=0; i < (int32_t)LAST_CONTEXT; i++)
{
for (int32_t j=0; j < (int32_t)LAST_CONTEXT; j++)
{
TR_Stats *stats = &_compYieldStatsMatrix[i][j];
if (stats->samples() > 0 && stats->maxVal() > TR::Options::_compYieldStatsThreshold)
{
TR::Compilation::printEntryName(i, j);
stats->report(stderr);
}
}
}
}
TR_AOTMethodHeader *
J9::Compilation::getAotMethodHeaderEntry()
{
J9JITDataCacheHeader *aotMethodHeader = (J9JITDataCacheHeader *)self()->getAotMethodDataStart();
TR_AOTMethodHeader *aotMethodHeaderEntry = (TR_AOTMethodHeader *)(aotMethodHeader + 1);
return aotMethodHeaderEntry;
}
TR::Node *
J9::Compilation::findNullChkInfo(TR::Node *node)
{
TR_ASSERT((node->getOpCodeValue() == TR::checkcastAndNULLCHK), "should call this only for checkcastAndNullChk\n");
TR::Node * newNode = NULL;
for (auto pair = self()->getCheckcastNullChkInfo().begin(); pair != self()->getCheckcastNullChkInfo().end(); ++pair)
{
if ((*pair)->getKey()->getByteCodeIndex() == node->getByteCodeIndex() &&
(*pair)->getKey()->getCallerIndex() == node->getInlinedSiteIndex())
{
newNode = (*pair)->getValue();
//dumpOptDetails("found bytecodeinfo for node %p as %x [%p]\n", node, newNode->getByteCodeIndex(), newNode);
break;
}
}
TR_ASSERT(newNode, "checkcastAndNullChk node doesnt have a corresponding null chk bytecodeinfo\n");
return newNode;
}
/**
* Sometimes we start the compilation with an optLevel, but later on,
* after we get more information, we decide to change it to something else.
* This method is used to change the optLevel. Note that the optLevel
* is cached in various data structures and it needs to be kept in sync.
*/
void
J9::Compilation::changeOptLevel(TR_Hotness newOptLevel)
{
self()->getOptions()->setOptLevel(newOptLevel);
self()->getOptimizationPlan()->setOptLevel(newOptLevel);
if (self()->getRecompilationInfo())
{
TR_PersistentJittedBodyInfo *bodyInfo = self()->getRecompilationInfo()->getJittedBodyInfo();
if (bodyInfo)
bodyInfo->setHotness(newOptLevel);
}
}
bool
J9::Compilation::isConverterMethod(TR::RecognizedMethod rm)
{
switch (rm)
{
case TR::sun_nio_cs_ISO_8859_1_Encoder_encodeISOArray:
case TR::java_lang_StringCoding_implEncodeISOArray:
case TR::java_lang_String_decodeUTF8_UTF16:
case TR::sun_nio_cs_ISO_8859_1_Decoder_decodeISO8859_1:
case TR::sun_nio_cs_US_ASCII_Encoder_encodeASCII:
case TR::java_lang_StringCoding_implEncodeAsciiArray:
case TR::sun_nio_cs_US_ASCII_Decoder_decodeASCII:
case TR::sun_nio_cs_ext_SBCS_Encoder_encodeSBCS:
case TR::sun_nio_cs_ext_SBCS_Decoder_decodeSBCS:
case TR::sun_nio_cs_UTF_8_Encoder_encodeUTF_8:
case TR::sun_nio_cs_UTF_8_Decoder_decodeUTF_8:
case TR::sun_nio_cs_UTF16_Encoder_encodeUTF16Big:
case TR::sun_nio_cs_UTF16_Encoder_encodeUTF16Little:
return true;
default:
return false;
}
return false;
}
//This implicitly checks if method is recognized converter method.
bool
J9::Compilation::canTransformConverterMethod(TR::RecognizedMethod rm)
{
TR_ASSERT(self()->isConverterMethod(rm), "not a converter method\n");
if (self()->getOption(TR_DisableConverterReducer))
return false;
bool aot = self()->compileRelocatableCode();
bool genSIMD = self()->cg()->getSupportsVectorRegisters() && !self()->getOption(TR_DisableSIMDArrayTranslate);
bool genTRxx = !aot && self()->cg()->getSupportsArrayTranslateTRxx();
switch (rm)
{
case TR::sun_nio_cs_ISO_8859_1_Encoder_encodeISOArray:
case TR::java_lang_StringCoding_implEncodeISOArray:
return genTRxx || self()->cg()->getSupportsArrayTranslateTRTO255() || self()->cg()->getSupportsArrayTranslateTRTO() || genSIMD;
case TR::sun_nio_cs_ISO_8859_1_Decoder_decodeISO8859_1:
return genTRxx || self()->cg()->getSupportsArrayTranslateTROTNoBreak() || genSIMD;
case TR::sun_nio_cs_US_ASCII_Encoder_encodeASCII:
case TR::java_lang_StringCoding_implEncodeAsciiArray:
case TR::sun_nio_cs_UTF_8_Encoder_encodeUTF_8:
return genTRxx || self()->cg()->getSupportsArrayTranslateTRTO() || genSIMD;
case TR::sun_nio_cs_US_ASCII_Decoder_decodeASCII:
case TR::sun_nio_cs_UTF_8_Decoder_decodeUTF_8:
return genTRxx || self()->cg()->getSupportsArrayTranslateTROT() || genSIMD;
case TR::sun_nio_cs_ext_SBCS_Encoder_encodeSBCS:
return genTRxx && self()->cg()->getSupportsTestCharComparisonControl();
case TR::sun_nio_cs_ext_SBCS_Decoder_decodeSBCS:
return genTRxx;
// devinmp: I'm not sure whether these could be transformed in AOT, but
// they haven't been so far.
case TR::sun_nio_cs_UTF16_Encoder_encodeUTF16Little:
return !aot && self()->cg()->getSupportsEncodeUtf16LittleWithSurrogateTest();
case TR::sun_nio_cs_UTF16_Encoder_encodeUTF16Big:
return !aot && self()->cg()->getSupportsEncodeUtf16BigWithSurrogateTest();
default:
return false;
}
}
bool
J9::Compilation::useCompressedPointers()
{
//FIXME: probably have to query the GC as well
return (self()->target().is64Bit() && TR::Options::useCompressedPointers());
}
bool
J9::Compilation::useAnchors()
{
return (self()->useCompressedPointers());
}
bool
J9::Compilation::hasBlockFrequencyInfo()
{
return TR_BlockFrequencyInfo::get(self()) != NULL;
}
bool
J9::Compilation::isShortRunningMethod(int32_t callerIndex)
{
{
const char *sig = NULL;
if (callerIndex > -1)
{
// this should be more reliable, but needs verification as equivalent
sig = self()->getInlinedResolvedMethod(callerIndex)->signature(self()->trMemory());
}
else
sig = self()->signature();
if (sig &&
((strncmp("java/lang/String.", sig, 17) == 0) ||
(strncmp("java/util/HashMap.", sig, 18) == 0) ||
(strncmp("java/util/TreeMap.", sig, 18) == 0) ||
(strncmp("java/math/DivisionLong.", sig, 23) == 0) ||
(strncmp("com/ibm/xml/xlxp2/scan/util/XMLString.", sig, 38) == 0) ||
(strncmp("com/ibm/xml/xlxp2/scan/util/SymbolMap.", sig, 38) == 0) ||
(strncmp("java/util/Random.next(I)I",sig,25) == 0) ||
(strncmp("java/util/zip/ZipFile.safeToUseModifiedUTF8", sig, 43) == 0) ||
(strncmp("java/util/HashMap$HashIterator.", sig, 31) == 0) ||
(strncmp("sun/misc/FloatingDecimal.readJavaFormatString", sig, 45) == 0)
)
)
{
return true;
}
}
return false;
}
bool
J9::Compilation::isRecompilationEnabled()
{
if (!self()->cg()->getSupportsRecompilation())
{
return false;
}
if (self()->isDLT())
{
return false;
}
// Don't do recompilation on JNI virtual thunk methods
//
if (self()->getCurrentMethod()->isJNINative())
return false;
return self()->allowRecompilation();
}
bool
J9::Compilation::isJProfilingCompilation()
{
return self()->getRecompilationInfo() ? self()->getRecompilationInfo()->getJittedBodyInfo()->getUsesJProfiling() : false;
}
// See if it is OK to remove this allocation node to e.g. merge it with others
// or allocate it locally on a stack frame.
// If so, return the allocation size if the size is constant, or zero if the
// size is variable.
// If not, return -1.
//
int32_t
J9::Compilation::canAllocateInlineOnStack(TR::Node* node, TR_OpaqueClassBlock* &classInfo)
{
if (self()->compileRelocatableCode())
return -1;
if (node->getOpCodeValue() == TR::New || node->getOpCodeValue() == TR::newvalue)
{
J9Class* clazz = self()->fej9vm()->getClassForAllocationInlining(self(), node->getFirstChild()->getSymbolReference());
if (clazz == NULL)
return -1;
// Can not inline the allocation on stack if the class is special
if (TR::Compiler->cls.isClassSpecialForStackAllocation((TR_OpaqueClassBlock *)clazz))
return -1;
}
return self()->canAllocateInline(node, classInfo);
}
bool
J9::Compilation::canAllocateInlineClass(TR_OpaqueClassBlock *block)
{
if (block == NULL)
return false;
return self()->fej9()->canAllocateInlineClass(block);
}
// This code was previously in canAllocateInlineOnStack. However, it is required by code gen to
// inline heap allocations. The only difference, for now, is that inlined heap allocations
// are being enabled for AOT, but stack allocations are not (yet).
//
int32_t
J9::Compilation::canAllocateInline(TR::Node* node, TR_OpaqueClassBlock* &classInfo)
{
// Can't skip the allocation if we are generating JVMPI hooks, since
// JVMPI needs to know about the allocation.
//
if (self()->suppressAllocationInlining() || !self()->fej9vm()->supportAllocationInlining(self(), node))
return -1;
// Pending inline allocation support on platforms for variable new
//
if (node->getOpCodeValue() == TR::variableNew || node->getOpCodeValue() == TR::variableNewArray)
return -1;
int32_t size;
TR::Node * classRef;
TR::SymbolReference * classSymRef;
TR::StaticSymbol * classSym;
J9Class * clazz;
bool isRealTimeGC = self()->getOptions()->realTimeGC();
bool generateArraylets = self()->generateArraylets();
const bool areValueTypesEnabled = TR::Compiler->om.areValueTypesEnabled();
if (node->getOpCodeValue() == TR::New || node->getOpCodeValue() == TR::newvalue)
{
classRef = node->getFirstChild();
classSymRef = classRef->getSymbolReference();
classSym = classSymRef->getSymbol()->getStaticSymbol();
// Check if the class can be inlined allocation.
// The class has to be resolved, initialized, concrete, etc.
clazz = self()->fej9vm()->getClassForAllocationInlining(self(), classSymRef);
if (!self()->canAllocateInlineClass(reinterpret_cast<TR_OpaqueClassBlock*> (clazz)))
return -1;
classInfo = self()->fej9vm()->getClassOffsetForAllocationInlining(clazz);
return self()->fej9()->getAllocationSize(classSym, reinterpret_cast<TR_OpaqueClassBlock*> (clazz));
}
int32_t elementSize;
if (node->getOpCodeValue() == TR::newarray)
{
TR_ASSERT(node->getSecondChild()->getOpCode().isLoadConst(), "Expecting const child \n");
int32_t arrayClassIndex = node->getSecondChild()->getInt();
clazz = (J9Class *) self()->fej9()->getClassFromNewArrayTypeNonNull(arrayClassIndex);
if (node->getFirstChild()->getOpCodeValue() != TR::iconst)
{
classInfo = self()->fej9vm()->getPrimitiveArrayAllocationClass(clazz);
return 0;
}
// Make sure the number constant of elements requested is within reasonable bounds
//
TR_ASSERT(node->getFirstChild()->getOpCode().isLoadConst(), "Expecting const child \n");
size = node->getFirstChild()->getInt();
if (size < 0 || size > 0x000FFFFF)
return -1;
classInfo = self()->fej9vm()->getPrimitiveArrayAllocationClass(clazz);
elementSize = TR::Compiler->om.getSizeOfArrayElement(node);
}
else if (node->getOpCodeValue() == TR::anewarray)
{
classRef = node->getSecondChild();
// In the case of dynamic array allocation, return 0 indicating variable dynamic array allocation,
// unless value types are enabled, in which case return -1 to prevent inline allocation
if (classRef->getOpCodeValue() != TR::loadaddr)
{
classInfo = NULL;
if (areValueTypesEnabled)
{
if (self()->getOption(TR_TraceCG))
{
traceMsg(self(), "cannot inline array allocation @ node %p because value types are enabled\n", node);
}
const char *signature = self()->signature();
TR::DebugCounter::incStaticDebugCounter(self(), TR::DebugCounter::debugCounterName(self(), "inlineAllocation/dynamicArray/failed/valueTypes/(%s)", signature));
return -1;
}
else
{
return 0;
}
}
classSymRef = classRef->getSymbolReference();
// Can't skip the allocation if the class is unresolved
//
clazz = self()->fej9vm()->getClassForAllocationInlining(self(), classSymRef);
if (clazz == NULL)
return -1;
// TODO-VALUETYPE: If null-restricted arrays are ever allocated using TR::anewarray,
// the JIT will need to handle the inline initialization or prevent inline allocation.
auto classOffset = self()->fej9()->getArrayClassFromComponentClass(TR::Compiler->cls.convertClassPtrToClassOffset(clazz));
clazz = TR::Compiler->cls.convertClassOffsetToClassPtr(classOffset);
if (!clazz)
return -1;
if (node->getFirstChild()->getOpCodeValue() != TR::iconst)
{
classInfo = self()->fej9vm()->getClassOffsetForAllocationInlining(clazz);
return 0;
}
// Make sure the number of elements requested is in reasonable bounds
//
TR_ASSERT(node->getFirstChild()->getOpCode().isLoadConst(), "Expecting const child \n");
size = node->getFirstChild()->getInt();
if (size < 0 || size > 0x000FFFFF)
return -1;
classInfo = self()->fej9vm()->getClassOffsetForAllocationInlining(clazz);
if (self()->useCompressedPointers())
elementSize = TR::Compiler->om.sizeofReferenceField();
else
elementSize = (int32_t)(TR::Compiler->om.sizeofReferenceAddress());
}
TR_ASSERT(node->getOpCodeValue() == TR::newarray ||
node->getOpCodeValue() == TR::anewarray, "unexpected allocation node");
size *= elementSize;
if (TR::Compiler->om.useHybridArraylets() && TR::Compiler->om.isDiscontiguousArray(size))
{
if (self()->getOption(TR_TraceCG))
traceMsg(self(), "cannot inline array allocation @ node %p because size %d is discontiguous\n", node, size);
return -1;
}
else if (!isRealTimeGC && size == 0)
{
#if (defined(TR_HOST_S390) && defined(TR_TARGET_S390)) || (defined(TR_TARGET_X86) && defined(TR_HOST_X86)) || (defined(TR_TARGET_POWER) && defined(TR_HOST_POWER)) || (defined(TR_TARGET_ARM64) && defined(TR_HOST_ARM64))
size = TR::Compiler->om.discontiguousArrayHeaderSizeInBytes();
if (self()->getOption(TR_TraceCG))
traceMsg(self(), "inline array allocation @ node %p for size 0\n", node);
#else
if (self()->getOption(TR_TraceCG))
traceMsg(self(), "cannot inline array allocation @ node %p because size 0 is discontiguous\n", node);
return -1;
#endif
}
else if (generateArraylets)
{
size += self()->fej9()->getArrayletFirstElementOffset(elementSize, self());
}
else
{
size += TR::Compiler->om.contiguousArrayHeaderSizeInBytes();
}
if (node->getOpCodeValue() == TR::newarray || self()->useCompressedPointers())
{
size = (int32_t)OMR::align(size, TR::Compiler->om.sizeofReferenceAddress());
}
if (isRealTimeGC &&
((size < 0) || (size > self()->fej9()->getMaxObjectSizeForSizeClass())))
return -1;
TR_ASSERT(size != -1, "unexpected array size");
return size >= J9_GC_MINIMUM_OBJECT_SIZE ? size : J9_GC_MINIMUM_OBJECT_SIZE;
}
TR::KnownObjectTable *
J9::Compilation::getOrCreateKnownObjectTable()
{
if (!_knownObjectTable && !self()->getOption(TR_DisableKnownObjectTable))
{
_knownObjectTable = new (self()->trHeapMemory()) TR::KnownObjectTable(self());
}
return _knownObjectTable;
}
void
J9::Compilation::freeKnownObjectTable()
{
if (_knownObjectTable)
{
#if defined(J9VM_OPT_JITSERVER)
if (!isOutOfProcessCompilation())
#endif /* defined(J9VM_OPT_JITSERVER) */
{
TR::VMAccessCriticalSection freeKnownObjectTable(self()->fej9());
J9VMThread *thread = self()->fej9()->vmThread();
TR_ASSERT(thread, "assertion failure");
TR_ArrayIterator<uintptr_t> i(&_knownObjectTable->_references);
for (uintptr_t *ref = i.getFirst(); !i.pastEnd(); ref = i.getNext())
thread->javaVM->internalVMFunctions->j9jni_deleteLocalRef((JNIEnv*)thread, (jobject)ref);
}
}
_knownObjectTable = NULL;
}
bool
J9::Compilation::compileRelocatableCode()
{
return self()->fej9()->isAOT_DEPRECATED_DO_NOT_USE();
}
bool
J9::Compilation::compilePortableCode()
{
return (self()->fej9()->inSnapshotMode() ||
self()->fej9()->isPortableRestoreModeEnabled() ||
(self()->compileRelocatableCode() &&
self()->fej9()->isPortableSCCEnabled()));
}
int32_t
J9::Compilation::maxInternalPointers()
{
if (self()->getOption(TR_DisableInternalPointers))
return 0;
else
return 128;
}
void
J9::Compilation::addHWPInstruction(TR::Instruction *instruction,
TR_HWPInstructionInfo::type instructionType,
void *data)
{
if (!self()->getPersistentInfo()->isRuntimeInstrumentationEnabled())
return;
TR::Node *node = instruction->getNode();
switch (instructionType)
{
case TR_HWPInstructionInfo::callInstructions:
case TR_HWPInstructionInfo::indirectCallInstructions:
TR_ASSERT(node->getOpCode().isCall(), "Unknown instruction for HW profiling");
break;
case TR_HWPInstructionInfo::returnInstructions:
case TR_HWPInstructionInfo::valueProfileInstructions:
break;
default:
TR_ASSERT(false, "Unknown instruction for HW profiling");
}
TR_HWPInstructionInfo hwpInstructionInfo = {(void*)instruction,
data,
instructionType};
_hwpInstructions.add(hwpInstructionInfo);
}
void
J9::Compilation::addHWPCallInstruction(TR::Instruction *instruction, bool indirectCall, TR::Instruction *prev)
{
if (indirectCall)
self()->addHWPInstruction(instruction, TR_HWPInstructionInfo::indirectCallInstructions, (void*)prev);
else
self()->addHWPInstruction(instruction, TR_HWPInstructionInfo::callInstructions);
}
void
J9::Compilation::addHWPReturnInstruction(TR::Instruction *instruction)
{
self()->addHWPInstruction(instruction, TR_HWPInstructionInfo::returnInstructions);
}
void
J9::Compilation::addHWPValueProfileInstruction(TR::Instruction *instruction)
{
self()->addHWPInstruction(instruction, TR_HWPInstructionInfo::valueProfileInstructions);
}
void
J9::Compilation::verifyCompressedRefsAnchors()
{
vcount_t visitCount = self()->incVisitCount();
TR::TreeTop *tt;
for (tt = self()->getStartTree(); tt; tt = tt->getNextTreeTop())
{
TR::Node *node = tt->getNode();
self()->verifyCompressedRefsAnchors(NULL, node, tt, visitCount);
}
}
void
J9::Compilation::verifyCompressedRefsAnchors(TR::Node *parent, TR::Node *node,
TR::TreeTop *tt, vcount_t visitCount)
{
if (node->getVisitCount() == visitCount)
return;
node->setVisitCount(visitCount);
// check stores
//
if (node->getOpCode().isLoadIndirect() ||
(node->getOpCode().isStoreIndirect() &&
!node->getOpCode().isWrtBar()))
{
if (node->getSymbolReference()->getSymbol()->getDataType() == TR::Address &&
node->getOpCode().isRef())
TR_ASSERT(0, "indirect store %p not lowered!\n", node);
}
// check children for loads/stores
//
for (int32_t i = node->getNumChildren()-1; i >= 0; i--)
{
TR::Node *child = node->getChild(i);
self()->verifyCompressedRefsAnchors(node, child, tt, visitCount);
}
}
bool
J9::Compilation::verifyCompressedRefsAnchors(bool anchorize)
{
bool status = true;
vcount_t visitCount = self()->incVisitCount();
TR::list<TR_Pair<TR::Node, TR::TreeTop> *> nodesList(getTypedAllocator<TR_Pair<TR::Node, TR::TreeTop> *>(self()->allocator()));
TR::TreeTop *tt;
for (tt = self()->getStartTree(); tt; tt = tt->getNextTreeTop())
{
TR::Node *n = tt->getNode();
self()->verifyCompressedRefsAnchors(NULL, n, tt, visitCount, nodesList);
}
// create anchors if required
if (anchorize)
{
TR_Pair<TR::Node, TR::TreeTop> *info;
// all non-null tt fields indicate some loads/stores were found
// with no corresponding anchors
//
for (auto info = nodesList.begin(); info != nodesList.end(); ++info)
{