-
Notifications
You must be signed in to change notification settings - Fork 752
/
Copy pathJ9CodeGenerator.cpp
816 lines (731 loc) · 34.8 KB
/
J9CodeGenerator.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
/*******************************************************************************
* 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
*******************************************************************************/
#include "j9cfg.h"
#include "codegen/AheadOfTimeCompile.hpp"
#include "codegen/CodeGenerator.hpp"
#include "codegen/CodeGeneratorUtils.hpp"
#include "codegen/CodeGenerator_inlines.hpp"
#include "codegen/GenerateInstructions.hpp"
#include "codegen/Linkage.hpp"
#include "codegen/Linkage_inlines.hpp"
#include "codegen/PPCJNILinkage.hpp"
#include "codegen/PPCPrivateLinkage.hpp"
#include "env/CompilerEnv.hpp"
#include "env/OMRMemory.hpp"
#include "env/VMJ9.h"
#include "env/jittypes.h"
#include "il/Node.hpp"
#include "il/Node_inlines.hpp"
#include "il/TreeTop.hpp"
#include "il/TreeTop_inlines.hpp"
#include "p/codegen/PPCInstruction.hpp"
#include "p/codegen/PPCRecompilation.hpp"
#include "p/codegen/PPCSystemLinkage.hpp"
extern void TEMPORARY_initJ9PPCTreeEvaluatorTable(TR::CodeGenerator *cg);
J9::Power::CodeGenerator::CodeGenerator(TR::Compilation *comp) :
J9::CodeGenerator(comp)
{
/**
* Do not add CodeGenerator initialization logic here.
* Use the \c initialize() method instead.
*/
}
void
J9::Power::CodeGenerator::initialize()
{
self()->J9::CodeGenerator::initialize();
TR::CodeGenerator *cg = self();
TR::Compilation *comp = cg->comp();
TR_J9VMBase *fej9 = (TR_J9VMBase *) (comp->fe());
cg->setAheadOfTimeCompile(new (cg->trHeapMemory()) TR::AheadOfTimeCompile(cg));
if (!comp->getOption(TR_FullSpeedDebug))
cg->setSupportsDirectJNICalls();
if (!comp->getOption(TR_DisableBDLLVersioning))
{
cg->setSupportsBigDecimalLongLookasideVersioning();
}
if (cg->getSupportsTM())
{
cg->setSupportsInlineConcurrentLinkedQueue();
}
static bool disableInlineVectorizedMismatch = feGetEnv("TR_disableInlineVectorizedMismatch") != NULL;
if (cg->getSupportsArrayCmpLen() &&
#if defined(J9VM_GC_SPARSE_HEAP_ALLOCATION)
!TR::Compiler->om.isOffHeapAllocationEnabled() &&
#endif /* J9VM_GC_SPARSE_HEAP_ALLOCATION */
!disableInlineVectorizedMismatch)
{
cg->setSupportsInlineVectorizedMismatch();
}
cg->setSupportsNewInstanceImplOpt();
static char *disableMonitorCacheLookup = feGetEnv("TR_disableMonitorCacheLookup");
if (!disableMonitorCacheLookup)
comp->setOption(TR_EnableMonitorCacheLookup);
cg->setSupportsPartialInlineOfMethodHooks();
cg->setSupportsInliningOfTypeCoersionMethods();
if (comp->target().cpu.isAtLeast(OMR_PROCESSOR_PPC_P8) && comp->target().cpu.supportsFeature(OMR_FEATURE_PPC_HAS_VSX) &&
comp->target().is64Bit() && !comp->getOption(TR_DisableFastStringIndexOf) &&
!TR::Compiler->om.canGenerateArraylets())
cg->setSupportsInlineStringIndexOf();
static bool disableStringInflateIntrinsic = feGetEnv("TR_DisableStringInflateIntrinsic") != NULL;
if (comp->target().cpu.isAtLeast(OMR_PROCESSOR_PPC_P8) && comp->target().cpu.supportsFeature(OMR_FEATURE_PPC_HAS_VSX) &&
comp->target().is64Bit() &&
!TR::Compiler->om.canGenerateArraylets() &&
!disableStringInflateIntrinsic)
cg->setSupportsInlineStringLatin1Inflate();
static bool disableCASInlining = feGetEnv("TR_DisableCASInlining") != NULL;
if (!disableCASInlining)
{
cg->setSupportsInlineUnsafeCompareAndSet();
}
static bool disableCAEInlining = feGetEnv("TR_DisableCAEInlining") != NULL;
if (!disableCAEInlining)
{
cg->setSupportsInlineUnsafeCompareAndExchange();
}
if (!comp->getOption(TR_DisableReadMonitors))
cg->setSupportsReadOnlyLocks();
static bool disableTLHPrefetch = (feGetEnv("TR_DisableTLHPrefetch") != NULL);
// Enable software prefetch of the TLH and configure the TLH prefetching
// geometry.
//
if (!disableTLHPrefetch && comp->getOption(TR_TLHPrefetch) && !comp->compileRelocatableCode())
{
cg->setEnableTLHPrefetching();
}
static bool disableInlineStringCodingHasNegatives =
feGetEnv("TR_DisableInlineStringCodingHasNegatives") != NULL;
static bool disableInlineStringCodingCountPositives =
feGetEnv("TR_DisableInlineStringCodingCountPositives") != NULL;
if (comp->target().cpu.isAtLeast(OMR_PROCESSOR_PPC_P8) &&
comp->target().cpu.supportsFeature(OMR_FEATURE_PPC_HAS_VSX) &&
!TR::Compiler->om.canGenerateArraylets())
{
if (!disableInlineStringCodingHasNegatives)
cg->setSupportsInlineStringCodingHasNegatives();
if (!disableInlineStringCodingCountPositives)
cg->setSupportsInlineStringCodingCountPositives();
}
//This env-var does 3 things:
// 1. Prevents batch clear in frontend/j9/rossa.cpp
// 2. Prevents all allocations to nonZeroTLH
// 3. Maintains the old semantics zero-init and prefetch.
// The use of this env-var is more complete than the JIT Option then.
static bool disableDualTLH = (feGetEnv("TR_DisableDualTLH") != NULL);
// Enable use of non-zero initialized TLH for object allocations where
// zero-initialization is not required as detected by the optimizer.
//
if (!disableDualTLH && !comp->getOption(TR_DisableDualTLH) && !comp->compileRelocatableCode() && !comp->getOptions()->realTimeGC())
{
cg->setIsDualTLH();
}
static bool disableInlineMath_MaxMin_FD = feGetEnv("TR_disableInlineMaxMin") != NULL;
if (!disableInlineMath_MaxMin_FD && comp->target().cpu.isAtLeast(OMR_PROCESSOR_PPC_P7))
{
cg->setSupportsInlineMath_MaxMin_FD();
}
/*
* "Statically" initialize the FE-specific tree evaluator functions.
* This code only needs to execute once per JIT lifetime.
*/
static bool initTreeEvaluatorTable = false;
if (!initTreeEvaluatorTable)
{
TEMPORARY_initJ9PPCTreeEvaluatorTable(cg);
initTreeEvaluatorTable = true;
}
if (comp->fej9()->hasFixedFrameC_CallingConvention())
cg->setHasFixedFrameC_CallingConvention();
}
bool
J9::Power::CodeGenerator::canEmitDataForExternallyRelocatableInstructions()
{
// On Power, data cannot be emitted inside instructions that will be associated with an
// external relocation record (ex. AOT or Remote compiles in OpenJ9). This is because when the
// relocation is applied when a method is loaded, the new data in the instruction is OR'ed in (The reason
// for OR'ing is that sometimes usefule information such as flags and hints can be stored during compilation in these data fields).
// Hence, for the relocation to be applied correctly, we must ensure that the data fields inside the instruction
// initially are zero.
#ifdef J9VM_OPT_JITSERVER
return !self()->comp()->compileRelocatableCode() && !self()->comp()->isOutOfProcessCompilation();
#endif
return !self()->comp()->compileRelocatableCode();
}
// Get or create the TR::Linkage object that corresponds to the given linkage
// convention.
// Even though this method is common, its implementation is machine-specific.
//
TR::Linkage *
J9::Power::CodeGenerator::createLinkage(TR_LinkageConventions lc)
{
TR::Linkage *linkage;
switch (lc)
{
case TR_Private:
linkage = new (self()->trHeapMemory()) J9::Power::PrivateLinkage(self());
break;
case TR_System:
linkage = new (self()->trHeapMemory()) TR::PPCSystemLinkage(self());
break;
case TR_CHelper:
case TR_Helper:
linkage = new (self()->trHeapMemory()) J9::Power::HelperLinkage(self(), lc);
break;
case TR_J9JNILinkage:
linkage = new (self()->trHeapMemory()) J9::Power::JNILinkage(self());
break;
default :
linkage = new (self()->trHeapMemory()) TR::PPCSystemLinkage(self());
TR_ASSERT(false, "Unexpected linkage convention");
}
self()->setLinkage(lc, linkage);
return linkage;
}
TR::Recompilation *
J9::Power::CodeGenerator::allocateRecompilationInfo()
{
return TR_PPCRecompilation::allocate(self()->comp());
}
void
J9::Power::CodeGenerator::generateBinaryEncodingPrologue(
TR_PPCBinaryEncodingData *data)
{
TR::Compilation *comp = self()->comp();
TR_J9VMBase *fej9 = (TR_J9VMBase *)(comp->fe());
TR::Instruction *tempInstruction;
data->recomp = comp->getRecompilationInfo();
data->cursorInstruction = self()->getFirstInstruction();
data->preProcInstruction = data->cursorInstruction;
data->jitTojitStart = data->cursorInstruction->getNext();
self()->getLinkage()->loadUpArguments(data->cursorInstruction);
if (data->recomp != NULL)
{
data->recomp->generatePrePrologue();
}
else
{
if (comp->getOption(TR_FullSpeedDebug) || comp->getOption(TR_SupportSwitchToInterpreter))
{
self()->generateSwitchToInterpreterPrePrologue(NULL, comp->getStartTree()->getNode());
}
else
{
TR::ResolvedMethodSymbol *methodSymbol = comp->getMethodSymbol();
/* save the original JNI native address if a JNI thunk is generated */
/* thunk is not recompilable, nor does it support FSD */
if (methodSymbol->isJNI())
{
uintptr_t JNIMethodAddress = (uintptr_t)methodSymbol->getResolvedMethod()->startAddressForJNIMethod(comp);
TR::Node *firstNode = comp->getStartTree()->getNode();
if (comp->target().is64Bit())
{
int32_t highBits = (int32_t)(JNIMethodAddress>>32), lowBits = (int32_t)JNIMethodAddress;
TR::Instruction *cursor = new (self()->trHeapMemory()) TR::PPCImmInstruction(TR::InstOpCode::dd, firstNode,
comp->target().cpu.isBigEndian()?highBits:lowBits, NULL, self());
generateImmInstruction(self(), TR::InstOpCode::dd, firstNode,
comp->target().cpu.isBigEndian()?lowBits:highBits, cursor);
}
else
{
new (self()->trHeapMemory()) TR::PPCImmInstruction(TR::InstOpCode::dd, firstNode, (int32_t)JNIMethodAddress, NULL, self());
}
}
}
}
data->cursorInstruction = self()->getFirstInstruction();
while (data->cursorInstruction && data->cursorInstruction->getOpCodeValue() != TR::InstOpCode::proc)
{
data->estimate = data->cursorInstruction->estimateBinaryLength(data->estimate);
data->cursorInstruction = data->cursorInstruction->getNext();
}
if (self()->supportsJitMethodEntryAlignment())
{
self()->setPreJitMethodEntrySize(data->estimate);
data->estimate += (self()->getJitMethodEntryAlignmentBoundary() - 1);
}
tempInstruction = data->cursorInstruction;
if ((data->recomp!=NULL) && (!data->recomp->useSampling()))
{
tempInstruction = data->recomp->generatePrologue(tempInstruction);
}
self()->getLinkage()->createPrologue(tempInstruction);
}
void
J9::Power::CodeGenerator::lowerTreeIfNeeded(
TR::Node *node,
int32_t childNumberOfNode,
TR::Node *parent,
TR::TreeTop *tt)
{
J9::CodeGenerator::lowerTreeIfNeeded(node, childNumberOfNode, parent, tt);
if ((node->getOpCode().isLeftShift() ||
node->getOpCode().isRightShift() || node->getOpCode().isRotate()) &&
self()->needsNormalizationBeforeShifts() &&
!node->isNormalizedShift())
{
TR::Node *second = node->getSecondChild();
int32_t normalizationAmount;
if (node->getType().isInt64())
normalizationAmount = 63;
else
normalizationAmount = 31;
// Some platforms like IA32 obey Java semantics for shifts even if the
// shift amount is greater than 31 or 63. However other platforms like PPC need
// to normalize the shift amount to range (0, 31) or (0, 63) before shifting in order
// to obey Java semantics. This can be captured in the IL and commoning/hoisting
// can be done (look at Compressor.compress).
//
if ( (second->getOpCodeValue() != TR::iconst) &&
((second->getOpCodeValue() != TR::iand) ||
(second->getSecondChild()->getOpCodeValue() != TR::iconst) ||
(second->getSecondChild()->getInt() != normalizationAmount)))
{
// Not normalized yet
//
TR::Node * normalizedNode = TR::Node::create(TR::iand, 2, second, TR::Node::create(second, TR::iconst, 0, normalizationAmount));
second->recursivelyDecReferenceCount();
node->setAndIncChild(1, normalizedNode);
node->setNormalizedShift(true);
}
}
}
bool J9::Power::CodeGenerator::suppressInliningOfRecognizedMethod(TR::RecognizedMethod method)
{
TR::Compilation *comp = self()->comp();
if (self()->isMethodInAtomicLongGroup(method))
{
return true;
}
#ifdef J9VM_OPT_JAVA_CRYPTO_ACCELERATION
if (self()->suppressInliningOfCryptoMethod(method))
{
return true;
}
#endif
if ((method==TR::java_util_concurrent_atomic_AtomicBoolean_getAndSet) ||
(method==TR::java_util_concurrent_atomic_AtomicInteger_getAndAdd) ||
(method==TR::java_util_concurrent_atomic_AtomicInteger_getAndIncrement) ||
(method==TR::java_util_concurrent_atomic_AtomicInteger_getAndDecrement) ||
(method==TR::java_util_concurrent_atomic_AtomicInteger_getAndSet) ||
(method==TR::java_util_concurrent_atomic_AtomicInteger_addAndGet) ||
(method==TR::java_util_concurrent_atomic_AtomicInteger_decrementAndGet) ||
(method==TR::java_util_concurrent_atomic_AtomicInteger_incrementAndGet))
{
return true;
}
if (method == TR::java_lang_Math_fma_D ||
method == TR::java_lang_Math_fma_F ||
method == TR::java_lang_StrictMath_fma_D ||
method == TR::java_lang_StrictMath_fma_F)
{
return true;
}
// Transactional Memory
if (self()->getSupportsInlineConcurrentLinkedQueue())
{
if (method == TR::java_util_concurrent_ConcurrentLinkedQueue_tmOffer ||
method == TR::java_util_concurrent_ConcurrentLinkedQueue_tmPoll ||
method == TR::java_util_concurrent_ConcurrentLinkedQueue_tmEnabled)
{
return true;
}
}
/* Need this check for CRC32C update* methods so that this doesn't get inlined.
* Unlike CRC32's update* which are JNI methods, CRC32C have Java implementation
* and therefore we need to prevent the inliner from eliminating the calls so
* we can redirect them to our optimized helpers.
*/
if (method == TR::java_util_zip_CRC32C_updateBytes ||
method == TR::java_util_zip_CRC32C_updateDirectByteBuffer)
{
return true;
}
return false;
}
bool
J9::Power::CodeGenerator::enableAESInHardwareTransformations()
{
TR::Compilation *comp = self()->comp();
if ( (comp->target().cpu.getPPCSupportsAES() || (comp->target().cpu.supportsFeature(OMR_FEATURE_PPC_HAS_ALTIVEC) && comp->target().cpu.supportsFeature(OMR_FEATURE_PPC_HAS_VSX))) &&
!comp->getOption(TR_DisableAESInHardware))
return true;
else
return false;
}
void
J9::Power::CodeGenerator::insertPrefetchIfNecessary(TR::Node *node, TR::Register *targetRegister)
{
TR::Compilation *comp = self()->comp();
static bool disableHotFieldPrefetch = (feGetEnv("TR_DisableHotFieldPrefetch") != NULL);
static bool disableHotFieldNextElementPrefetch = (feGetEnv("TR_DisableHotFieldNextElementPrefetch") != NULL);
static bool disableIteratorPrefetch = (feGetEnv("TR_DisableIteratorPrefetch") != NULL);
static bool disableStringObjPrefetch = (feGetEnv("TR_DisableStringObjPrefetch") != NULL);
bool optDisabled = false;
if ((node->getOpCodeValue() == TR::aloadi && !comp->target().is64Bit()) ||
(comp->target().is64Bit() &&
comp->useCompressedPointers() &&
node->getOpCodeValue() == TR::l2a &&
comp->getMethodHotness() >= scorching &&
TR::Compiler->om.compressedReferenceShiftOffset() == 0 &&
comp->target().cpu.isAtLeast(OMR_PROCESSOR_PPC_P6))
)
{
int32_t prefetchOffset = comp->findPrefetchInfo(node);
TR::Node *firstChild = node->getFirstChild();
if (!disableHotFieldPrefetch && prefetchOffset >= 0) // Prefetch based on hot field information
{
bool canSkipNullChk = false;
static bool disableDelayPrefetch = (feGetEnv("TR_DisableDelayPrefetch") != NULL);
TR::LabelSymbol *endCtrlFlowLabel = generateLabelSymbol(self());
TR::Node *topNode = self()->getCurrentEvaluationTreeTop()->getNode();
// Search the current block for a check for NULL
TR::TreeTop *tt = self()->getCurrentEvaluationTreeTop()->getNextTreeTop();
TR::Node *checkNode = NULL;
while (!disableDelayPrefetch && tt && (tt->getNode()->getOpCodeValue() != TR::BBEnd))
{
checkNode = tt->getNode();
if (checkNode->getOpCodeValue() == TR::ifacmpeq &&
checkNode->getFirstChild() == node &&
checkNode->getSecondChild()->getDataType() == TR::Address &&
checkNode->getSecondChild()->isZero())
{
canSkipNullChk = true;
}
tt = tt->getNextTreeTop();
}
if (!canSkipNullChk)
{
TR::Register *condReg = self()->allocateRegister(TR_CCR);
TR::LabelSymbol *startCtrlFlowLabel = generateLabelSymbol(self());
startCtrlFlowLabel->setStartInternalControlFlow();
endCtrlFlowLabel->setEndInternalControlFlow();
generateLabelInstruction(self(), TR::InstOpCode::label, node, startCtrlFlowLabel);
// check for null
generateTrg1Src1ImmInstruction(self(), TR::InstOpCode::cmpli4, node, condReg, targetRegister, NULLVALUE);
generateConditionalBranchInstruction(self(), TR::InstOpCode::beql, node, endCtrlFlowLabel, condReg);
TR::Register *tempReg = self()->allocateRegister();
TR::RegisterDependencyConditions *deps = new (self()->trHeapMemory()) TR::RegisterDependencyConditions(1, 2, self()->trMemory());
deps->addPostCondition(tempReg, TR::RealRegister::NoReg);
TR::addDependency(deps, condReg, TR::RealRegister::NoReg, TR_CCR, self());
if (comp->target().is64Bit() && !comp->useCompressedPointers())
{
TR::MemoryReference *tempMR = TR::MemoryReference::createWithDisplacement(self(), targetRegister, prefetchOffset, 8);
generateTrg1MemInstruction(self(), TR::InstOpCode::ld, node, tempReg, tempMR);
}
else
{
TR::MemoryReference *tempMR = TR::MemoryReference::createWithDisplacement(self(), targetRegister, prefetchOffset, 4);
generateTrg1MemInstruction(self(), TR::InstOpCode::lwz, node, tempReg, tempMR);
}
TR::MemoryReference *targetMR = TR::MemoryReference::createWithDisplacement(self(), tempReg, (int32_t)0, 4);
targetMR->forceIndexedForm(node, self());
generateMemInstruction(self(), TR::InstOpCode::dcbt, node, targetMR);
self()->stopUsingRegister(tempReg);
self()->stopUsingRegister(condReg);
}
else
{
// Delay the dcbt to after the null check and fall through to the next block's treetop.
TR::TreeTop *useTree = tt->getNextTreeTop();
TR_ASSERT(useTree->getNode()->getOpCodeValue() == TR::BBStart, "Expecting a BBStart on the fall through\n");
TR::Node *useNode = useTree->getNode();
TR::Block *bb = useNode->getBlock();
if (bb->isExtensionOfPreviousBlock()) // Survived the null check
{
TR_PrefetchInfo *pf = new (self()->trHeapMemory())TR_PrefetchInfo(self()->getCurrentEvaluationTreeTop(), useTree, node, useNode, prefetchOffset, false);
comp->removeExtraPrefetchInfo(useNode);
comp->getExtraPrefetchInfo().push_front(pf);
}
}
// Do a prefetch on the next element of the array
// if the pointer came from an array. Seems to give no gain at all, disabled until later
TR::Register *pointerReg = NULL;
bool fromRegLoad = false;
if (!disableHotFieldNextElementPrefetch)
{
// 32bit
if (comp->target().is32Bit())
{
if (!(firstChild->getOpCodeValue() == TR::aiadd &&
firstChild->getFirstChild() &&
firstChild->isInternalPointer()) &&
!(firstChild->getOpCodeValue() == TR::aRegLoad &&
firstChild->getSymbolReference()->getSymbol()->isInternalPointer()))
{
optDisabled = true;
}
else
{
fromRegLoad = (firstChild->getOpCodeValue() == TR::aRegLoad);
pointerReg = fromRegLoad ? firstChild->getRegister() : self()->allocateRegister();
if (!fromRegLoad)
{
// Case for aiadd, there should be 2 children
TR::Node *baseObject = firstChild->getFirstChild();
TR::Register *baseReg = (baseObject) ? baseObject->getRegister() : NULL;
TR::Node *indexObject = firstChild->getSecondChild();
TR::Register *indexReg = (indexObject) ? indexObject->getRegister() : NULL;
// If the index is constant we just grab it
if (indexObject->getOpCode().isLoadConst())
{
int32_t len = indexObject->getInt();
if (len >= LOWER_IMMED && len <= UPPER_IMMED)
generateTrg1Src1ImmInstruction(self(), TR::InstOpCode::addi, node, pointerReg, baseReg, len);
else
{
indexReg = self()->allocateRegister();
loadConstant(self(), node, len, indexReg);
generateTrg1Src2Instruction(self(), TR::InstOpCode::add, node, pointerReg, baseReg, indexReg);
self()->stopUsingRegister(indexReg);
}
}
else
generateTrg1Src2Instruction(self(), TR::InstOpCode::add, node, pointerReg, baseReg, indexReg);
}
}
}
// 64bit CR
else if (comp->target().is64Bit() && comp->useCompressedPointers())
{
if (!(firstChild->getOpCodeValue() == TR::iu2l &&
firstChild->getFirstChild() &&
firstChild->getFirstChild()->getOpCodeValue() == TR::iloadi &&
firstChild->getFirstChild()->getNumChildren() == 1))
{
optDisabled = true;
}
else
{
fromRegLoad = true;
pointerReg = firstChild->getFirstChild()->getFirstChild()->getRegister();
}
}
// 64bit - TODO
else
optDisabled = true;
}
if (!optDisabled)
{
TR::Register *condReg = self()->allocateRegister(TR_CCR);
TR::Register *tempReg = self()->allocateRegister();
// 32 bit only.... For -Xgc:noconcurrentmark, heapBase will be 0 and heapTop will be ok
// Otherwise, for a 2.25Gb or bigger heap, heapTop will be 0. Relying on correct JIT initialization
uintptr_t heapTop = comp->getOptions()->getHeapTop() ? comp->getOptions()->getHeapTop() : 0xFFFFFFFF;
if (pointerReg && (heapTop > comp->getOptions()->getHeapBase())) // Check for gencon
{
TR::Register *temp3Reg = self()->allocateRegister();
static bool prefetch2Ahead = (feGetEnv("TR_Prefetch2Ahead") != NULL);
if (comp->target().is64Bit() && !comp->useCompressedPointers())
{
if (!prefetch2Ahead)
generateTrg1MemInstruction(self(), TR::InstOpCode::ld, node, temp3Reg, TR::MemoryReference::createWithDisplacement(self(), pointerReg, (int32_t)TR::Compiler->om.sizeofReferenceField(), 8));
else
generateTrg1MemInstruction(self(), TR::InstOpCode::ld, node, temp3Reg, TR::MemoryReference::createWithDisplacement(self(), pointerReg, (int32_t)(TR::Compiler->om.sizeofReferenceField()*2), 8));
}
else
{
if (!prefetch2Ahead)
generateTrg1MemInstruction(self(), TR::InstOpCode::lwz, node, temp3Reg, TR::MemoryReference::createWithDisplacement(self(), pointerReg, (int32_t)TR::Compiler->om.sizeofReferenceField(), 4));
else
generateTrg1MemInstruction(self(), TR::InstOpCode::lwz, node, temp3Reg, TR::MemoryReference::createWithDisplacement(self(), pointerReg, (int32_t)(TR::Compiler->om.sizeofReferenceField()*2), 4));
}
if (comp->getOptions()->getHeapBase() != 0)
{
loadAddressConstant(self(), comp->compileRelocatableCode(), node, (intptr_t)(comp->getOptions()->getHeapBase()), tempReg);
generateTrg1Src2Instruction(self(), TR::InstOpCode::cmpl4, node, condReg, temp3Reg, tempReg);
generateConditionalBranchInstruction(self(), TR::InstOpCode::blt, node, endCtrlFlowLabel, condReg);
}
if (heapTop != 0xFFFFFFFF)
{
loadAddressConstant(self(), comp->compileRelocatableCode(), node, (intptr_t)(heapTop-prefetchOffset), tempReg);
generateTrg1Src2Instruction(self(), TR::InstOpCode::cmpl4, node, condReg, temp3Reg, tempReg);
generateConditionalBranchInstruction(self(), TR::InstOpCode::bgt, node, endCtrlFlowLabel, condReg);
}
TR::MemoryReference *targetMR = TR::MemoryReference::createWithDisplacement(self(), temp3Reg, (int32_t)0, 4);
targetMR->forceIndexedForm(node, self());
generateMemInstruction(self(), TR::InstOpCode::dcbt, node, targetMR); // use dcbt for prefetch next element
self()->stopUsingRegister(temp3Reg);
}
if (!fromRegLoad)
self()->stopUsingRegister(pointerReg);
self()->stopUsingRegister(tempReg);
self()->stopUsingRegister(condReg);
}
generateLabelInstruction(self(), TR::InstOpCode::label, node, endCtrlFlowLabel);
}
// Try prefetch all string objects, no apparent gain. Disabled for now.
if (!disableStringObjPrefetch && 0 &&
node->getSymbolReference() &&
!node->getSymbolReference()->isUnresolved() &&
(node->getSymbolReference()->getSymbol()->getKind() == TR::Symbol::IsShadow) &&
(node->getSymbolReference()->getCPIndex() >= 0))
{
int32_t len;
const char *fieldName = node->getSymbolReference()->getOwningMethod(comp)->fieldSignatureChars(
node->getSymbolReference()->getCPIndex(), len);
if (fieldName && strstr(fieldName, "Ljava/lang/String;"))
{
TR::MemoryReference *targetMR = TR::MemoryReference::createWithDisplacement(self(), targetRegister, (int32_t)0, 4);
targetMR->forceIndexedForm(node, self());
generateMemInstruction(self(), TR::InstOpCode::dcbt, node, targetMR);
}
}
}
if ((node->getOpCodeValue() == TR::aloadi && !comp->target().is64Bit()) ||
(comp->target().is64Bit() &&
comp->useCompressedPointers() &&
(node->getOpCodeValue() == TR::iloadi || node->getOpCodeValue() == TR::irdbari) &&
comp->getMethodHotness() >= hot))
{
TR::Node *firstChild = node->getFirstChild();
optDisabled = disableIteratorPrefetch;
if (!disableIteratorPrefetch)
{
// 32bit
if (comp->target().is32Bit())
{
if (!(firstChild &&
firstChild->getOpCodeValue() == TR::aiadd &&
firstChild->isInternalPointer() &&
strstr(comp->fe()->sampleSignature(node->getOwningMethod(), 0, 0, self()->trMemory()),"java/util/ArrayList$Itr.next()")
))
{
optDisabled = true;
}
}
// 64bit cr
else if (comp->target().is64Bit() && comp->useCompressedPointers())
{
if (!(firstChild &&
firstChild->getOpCodeValue() == TR::aladd &&
firstChild->isInternalPointer() &&
strstr(comp->fe()->sampleSignature(node->getOwningMethod(), 0, 0, self()->trMemory()),"java/util/ArrayList$Itr.next()")
))
{
optDisabled = true;
}
}
}
// The use of this prefetching can cause a SEGV when the object array is allocated at the every end of the heap.
// The GC will protected against the SEGV by adding a "tail-padding" page, but only when -XAggressive is enabled!
if (!optDisabled && comp->getOption(TR_AggressiveOpts))
{
int32_t loopSize = 0;
int32_t prefetchElementStride = 1;
TR::Block *b = self()->getCurrentEvaluationBlock();
TR_BlockStructure *blockStructure = b->getStructureOf();
if (blockStructure)
{
TR_Structure *containingLoop = blockStructure->getContainingLoop();
if (containingLoop)
{
TR_ScratchList<TR::Block> blocksInLoop(comp->trMemory());
containingLoop->getBlocks(&blocksInLoop);
ListIterator<TR::Block> blocksIt(&blocksInLoop);
TR::Block *nextBlock;
for (nextBlock = blocksIt.getCurrent(); nextBlock; nextBlock=blocksIt.getNext())
{
loopSize += nextBlock->getNumberOfRealTreeTops();
}
}
}
if (comp->useCompressedPointers())
{
prefetchElementStride = 2;
}
else
{
if (loopSize < 200) //comp->useCompressedPointers() is false && loopSize < 200.
{
prefetchElementStride = 4;
}
else if (loopSize < 300) //comp->useCompressedPointers() is false && loopsize >=200 && loopsize < 300.
{
prefetchElementStride = 2;
}
//If comp->useCompressedPointers() is false and loopsize >= 300, prefetchElementStride does not get changed.
}
// Look at the aiadd's children
TR::Node *baseObject = firstChild->getFirstChild();
TR::Register *baseReg = (baseObject) ? baseObject->getRegister() : NULL;
TR::Node *indexObject = firstChild->getSecondChild();
TR::Register *indexReg = (indexObject) ? indexObject->getRegister() : NULL;
if (baseReg && indexReg && loopSize > 0)
{
TR::Register *tempReg = self()->allocateRegister();
generateTrg1Src1ImmInstruction(self(), TR::InstOpCode::addi, node, tempReg, indexReg, prefetchElementStride * TR::Compiler->om.sizeofReferenceField());
if (comp->target().is64Bit() && !comp->useCompressedPointers())
{
TR::MemoryReference *targetMR = TR::MemoryReference::createWithIndexReg(self(), baseReg, tempReg, 8);
generateTrg1MemInstruction(self(), TR::InstOpCode::ld, node, tempReg, targetMR);
}
else
{
TR::MemoryReference *targetMR = TR::MemoryReference::createWithIndexReg(self(), baseReg, tempReg, 4);
generateTrg1MemInstruction(self(), TR::InstOpCode::lwz, node, tempReg, targetMR);
}
if (comp->useCompressedPointers())
{
generateShiftLeftImmediateLong(self(), node, tempReg, tempReg, TR::Compiler->om.compressedReferenceShiftOffset());
}
TR::MemoryReference *target2MR = TR::MemoryReference::createWithDisplacement(self(), tempReg, 0, 4);
target2MR->forceIndexedForm(node, self());
generateMemInstruction(self(), TR::InstOpCode::dcbt, node, target2MR);
self()->stopUsingRegister(tempReg);
}
}
}
else if (node->getOpCodeValue() == TR::awrtbari &&
comp->getMethodHotness() >= scorching &&
comp->target().cpu.isAtLeast(OMR_PROCESSOR_PPC_P6) &&
(comp->target().is32Bit() ||
(comp->target().is64Bit() &&
comp->useCompressedPointers() &&
TR::Compiler->om.compressedReferenceShiftOffset() == 0
)
)
)
{
// Take the source register of the store and apply on the prefetchOffset right away
int32_t prefetchOffset = comp->findPrefetchInfo(node);
if (prefetchOffset >= 0)
{
TR::MemoryReference *targetMR = TR::MemoryReference::createWithDisplacement(self(), targetRegister, prefetchOffset, TR::Compiler->om.sizeofReferenceAddress());
targetMR->forceIndexedForm(node, self());
generateMemInstruction(self(), TR::InstOpCode::dcbt, node, targetMR);
}
}
}
TR::Linkage *
J9::Power::CodeGenerator::deriveCallingLinkage(TR::Node *node, bool isIndirect)
{
TR::SymbolReference *symRef = node->getSymbolReference();
TR::MethodSymbol *callee = symRef->getSymbol()->castToMethodSymbol();
TR_J9VMBase *fej9 = (TR_J9VMBase *)(self()->fe());
static char * disableDirectNativeCall = feGetEnv("TR_DisableDirectNativeCall");
// Clean-up: the fej9 checking seemed unnecessary
if (!isIndirect && callee->isJNI() &&
(node->isPreparedForDirectJNI() ||
(disableDirectNativeCall == NULL && callee->getResolvedMethodSymbol()->canDirectNativeCall())))
return self()->getLinkage(TR_J9JNILinkage);
return self()->getLinkage(callee->getLinkageConvention());
}