-
Notifications
You must be signed in to change notification settings - Fork 746
/
Copy pathJ9RecognizedCallTransformer.cpp
1931 lines (1678 loc) · 91.4 KB
/
J9RecognizedCallTransformer.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 2017
*
* 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 "optimizer/RecognizedCallTransformer.hpp"
#include "compile/ResolvedMethod.hpp"
#include "env/CompilerEnv.hpp"
#include "env/VMJ9.h"
#include "env/jittypes.h"
#include "il/Block.hpp"
#include "il/Node.hpp"
#include "il/Node_inlines.hpp"
#include "il/StaticSymbol.hpp"
#include "il/TreeTop.hpp"
#include "il/TreeTop_inlines.hpp"
#include "il/ILOpCodes.hpp"
#include "il/ILOps.hpp"
#include "ilgen/IlGenRequest.hpp"
#include "ilgen/IlGeneratorMethodDetails.hpp"
#include "ilgen/IlGeneratorMethodDetails_inlines.hpp"
#include "infra/ILWalk.hpp"
#include "infra/String.hpp"
#include "optimizer/CallInfo.hpp"
#include "optimizer/IdiomRecognitionUtils.hpp"
#include "optimizer/Structure.hpp"
#include "optimizer/ValuePropagation.hpp"
#include "codegen/CodeGenerator.hpp"
#include "optimizer/TransformUtil.hpp"
#include "env/j9method.h"
#include "optimizer/Optimization_inlines.hpp"
void J9::RecognizedCallTransformer::processIntrinsicFunction(TR::TreeTop* treetop, TR::Node* node, TR::ILOpCodes opcode)
{
TR::Node::recreate(node, opcode);
}
void J9::RecognizedCallTransformer::processConvertingUnaryIntrinsicFunction(TR::TreeTop* treetop, TR::Node* node, TR::ILOpCodes argConvertOpcode, TR::ILOpCodes opcode, TR::ILOpCodes resultConvertOpcode)
{
TR::Node* actualArg = TR::Node::create(argConvertOpcode, 1, node->getFirstChild());
TR::Node* actualResult = TR::Node::create(opcode, 1, actualArg);
TR::Node::recreate(node, resultConvertOpcode);
node->getFirstChild()->decReferenceCount();
node->setAndIncChild(0, actualResult);
}
void J9::RecognizedCallTransformer::process_java_lang_Class_IsAssignableFrom(TR::TreeTop* treetop, TR::Node* node)
{
auto toClass = node->getChild(0);
auto fromClass = node->getChild(1);
auto nullchk = comp()->getSymRefTab()->findOrCreateNullCheckSymbolRef(comp()->getMethodSymbol());
treetop->insertBefore(TR::TreeTop::create(comp(), TR::Node::createWithSymRef(TR::NULLCHK, 1, 1, TR::Node::create(node, TR::PassThrough, 1, toClass), nullchk)));
treetop->insertBefore(TR::TreeTop::create(comp(), TR::Node::createWithSymRef(TR::NULLCHK, 1, 1, TR::Node::create(node, TR::PassThrough, 1, fromClass), nullchk)));
TR::Node::recreate(treetop->getNode(), TR::treetop);
node->setSymbolReference(comp()->getSymRefTab()->findOrCreateRuntimeHelper(TR_checkAssignable));
node->setAndIncChild(0, TR::Node::createWithSymRef(TR::aloadi, 1, 1, toClass, comp()->getSymRefTab()->findOrCreateClassFromJavaLangClassSymbolRef()));
node->setAndIncChild(1, TR::Node::createWithSymRef(TR::aloadi, 1, 1, fromClass, comp()->getSymRefTab()->findOrCreateClassFromJavaLangClassSymbolRef()));
node->swapChildren();
toClass->recursivelyDecReferenceCount();
fromClass->recursivelyDecReferenceCount();
}
static void substituteNode(
TR::NodeChecklist &visited, TR::Node *subOld, TR::Node *subNew, TR::Node *node)
{
if (visited.contains(node))
return;
visited.add(node);
TR_ASSERT_FATAL(node != subOld, "unexpected occurrence of old node");
for (int32_t i = 0; i < node->getNumChildren(); i++)
{
TR::Node *child = node->getChild(i);
if (child == subOld)
{
// subOld occurs at least at its point of evaluation and here, so it
// won't hit refcount 0.
TR_ASSERT_FATAL_WITH_NODE(
subOld,
subOld->getReferenceCount() >= 2,
"expected node to be referenced elsewhere");
subOld->decReferenceCount();
node->setAndIncChild(i, subNew);
}
else
{
substituteNode(visited, subOld, subNew, child);
}
}
}
void J9::RecognizedCallTransformer::process_java_lang_Class_cast(
TR::TreeTop* treetop, TR::Node* node)
{
// See the comment in isInlineable().
TR_ASSERT_FATAL_WITH_NODE(
node,
comp()->getOSRMode() != TR::involuntaryOSR,
"unexpectedly transforming Class.cast with involuntary OSR");
// These don't need to be anchored because they will both occur beneath
// checkcast in the same treetop.
TR::Node *jlClass = node->getArgument(0);
TR::Node *object = node->getArgument(1);
TR::TransformUtil::separateNullCheck(comp(), treetop, trace());
TR::SymbolReferenceTable *srTab = comp()->getSymRefTab();
TR::SymbolReference *classFromJavaLangClassSR =
srTab->findOrCreateClassFromJavaLangClassSymbolRef();
TR::SymbolReference *checkcastSR =
srTab->findOrCreateCheckCastSymbolRef(comp()->getMethodSymbol());
TR::Node *j9class = TR::Node::createWithSymRef(
TR::aloadi, 1, 1, jlClass, classFromJavaLangClassSR);
TR::Node *cast = TR::Node::createWithSymRef(
node, TR::checkcast, 2, checkcastSR);
cast->setAndIncChild(0, object);
cast->setAndIncChild(1, j9class);
if (node->getReferenceCount() > 1)
{
TR::NodeChecklist visited(comp());
TR::TreeTop *entry = treetop->getEnclosingBlock()->getEntry();
TR::TreeTop *start = treetop->getNextTreeTop();
TR::TreeTop *end = entry->getExtendedBlockExitTreeTop();
for (TR::TreeTopIterator it(start, comp()); it != end; ++it)
{
substituteNode(visited, node, object, it.currentNode());
if (node->getReferenceCount() == 1)
break;
}
}
TR_ASSERT_FATAL_WITH_NODE(
node,
node->getReferenceCount() == 1,
"expected exactly one occurrence to remain");
treetop->setNode(cast);
node->recursivelyDecReferenceCount();
}
// This methods inlines a call node that calls StringCoding.encodeASCII into an if-diamond. The forward path of the
// if-diamond inlines the call using a compiler intrinsic and the fallback path reverts back to calling the method traditionally.
void J9::RecognizedCallTransformer::process_java_lang_StringCoding_encodeASCII(TR::TreeTop* treetop, TR::Node* node)
{
TR_J9VMBase *fej9 = static_cast<TR_J9VMBase*>(comp()->fe());
TR_OpaqueClassBlock *stringClass = comp()->getStringClassPointer();
if (!stringClass || !fej9->getByteArrayClass())
{
return;
}
uint32_t *latin1FieldAddress = (uint32_t *)fej9->getStaticFieldAddress(stringClass, (unsigned char *) "LATIN1", 6, (unsigned char *)"B", 1);
TR::CFG *cfg = comp()->getFlowGraph();
TR::Node *coderNode = node->getChild(0);
TR::Node *sourceArrayNode = node->getChild(1);
// Anchor the source array node as we need it in the fallthrough block.
anchorNode(sourceArrayNode, treetop);
// Now generate the ificmpne tree and insert it before the original call tree.
// Note that *latin1FieldAddress will be correct for AOT compilations as well because String.LATIN1 is a final static field with
// a constant initializer. This means its value is determined by the ROM class of String, and therefore when the String class chain validation succeeds
// on AOT load, the value is guaranteed to be the same as the one we see during AOT compilation.
TR::Node *constNode = TR::Node::iconst(node, ((TR_J9VM *)fej9)->dereferenceStaticFinalAddress(latin1FieldAddress, TR::Int32).dataInt32Bit);
TR::Node *ifCmpNode = TR::Node::createif(TR::ificmpne, coderNode, constNode);
TR::TreeTop *ifCmpTreeTop = TR::TreeTop::create(comp(), treetop->getPrevTreeTop(), ifCmpNode);
// Split the current block right before the call (or after the ificmpne).
TR::Block *ifCmpBlock = ifCmpTreeTop->getEnclosingBlock();
TR::Block *fallbackPathBlock = ifCmpBlock->split(treetop, cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
// Then split again to create the tail block
TR::Block *tailBlock = fallbackPathBlock->split(treetop->getNextTreeTop(), cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
// Now we have the originalBlock, the fallback block and the merge block (tailBlock). The call result will be an astore.
// If the nodes in the above blocks were uncommoned as expected, then the treetop after the call node should be an astore to a temp slot.
// So assert that it is, and then grab a reference to the temp slot so we can store to it ourselves in the forward path.
// Note that we can rely on the call result having been used in a later tree since encodeASCII represents a private method whose call sites we can inspect
// and because this transformation happens very early as part of ilgen opts
TR::Node *resultStoreNode = treetop->getNextTreeTop()->getNode();
TR::SymbolReference *tempSlotForCallResult = NULL;
TR_ASSERT_FATAL(resultStoreNode, "Treetop after call is not an astore");
TR_ASSERT_FATAL(resultStoreNode->getOpCode().getOpCodeValue() == TR::astore, "Treetop after call must be an astore to a temp!");
tempSlotForCallResult = resultStoreNode->getSymbolReference();
TR_ASSERT_FATAL(tempSlotForCallResult, "Symbol reference for store node can't be null\n");
TR_ASSERT_FATAL(resultStoreNode->getChild(0) == node, "The value stored must be the call result");
// Ready to create our fallthrough block now. Connect it to ifCmpTreeTop, and then split it with nodes commoned.
int32_t byteArrayType = fej9->getNewArrayTypeFromClass(fej9->getByteArrayClass());
// Create a new arraylength node.
sourceArrayNode = node->getChild(1)->duplicateTree();
TR::Node *lenNode = TR::Node::create(node, TR::arraylength, 1, sourceArrayNode);
// Create the destination array
TR::Node *destinationArrayNode = TR::Node::createWithSymRef(node, TR::newarray, 2, comp()->getSymRefTab()->findOrCreateNewArraySymbolRef(node->getSymbolReference()->getOwningMethodSymbol(comp())));
destinationArrayNode->setAndIncChild(0, lenNode);
destinationArrayNode->setAndIncChild(1, TR::Node::iconst(byteArrayType));
TR::TreeTop *destinationArrayTreeTop = TR::TreeTop::create(comp(), TR::Node::create(node, TR::treetop, 1, destinationArrayNode));
ifCmpTreeTop->insertAfter(destinationArrayTreeTop);
destinationArrayNode->setCanSkipZeroInitialization(true);
destinationArrayNode->setIsNonNull(true);
// We now have the length node, and also the destination array. Now we create an encodeASCIISymbol node to do the encoding operation.
/*
// tree looks as follows:
// call encodeASCIISymbol
// input ptr
// output ptr
// input length (in elements)
*/
TR::SymbolReference *methodSymRef = comp()->getSymRefTab()->findOrCreateEncodeASCIISymbolRef();
TR::Node *encodeASCIINode = TR::Node::createWithSymRef(TR::call, 3, methodSymRef);
TR::Node *newInputNode = TR::TransformUtil::generateFirstArrayElementAddressTrees(comp(), sourceArrayNode);
TR::Node *newOutputNode = TR::TransformUtil::generateFirstArrayElementAddressTrees(comp(), destinationArrayNode);
encodeASCIINode->setAndIncChild(0, newInputNode);
encodeASCIINode->setAndIncChild(1, newOutputNode);
encodeASCIINode->setAndIncChild(2, lenNode);
TR::TreeTop *encodeASCIITreeTop = TR::TreeTop::create(comp(), TR::Node::create(node, TR::treetop, 1, encodeASCIINode));
destinationArrayTreeTop->insertAfter(encodeASCIITreeTop);
TR::Node *storeNode = TR::Node::createWithSymRef(node, TR::astore, 1, destinationArrayNode, tempSlotForCallResult);
TR::TreeTop *storeNodeTreeTop = TR::TreeTop::create(comp(), encodeASCIITreeTop, storeNode);
// Now split starting from destinationArrayTreeTop and uncommon the nodes..
TR::Block *fallthroughBlock = destinationArrayTreeTop->getEnclosingBlock()->split(destinationArrayTreeTop, cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
// Now create a node to go to the merge (i.e. tail) block.
TR::Node *gotoNode = TR::Node::create(node, TR::Goto);
TR::TreeTop *gotoTree = TR::TreeTop::create(comp(), gotoNode, NULL, NULL);
gotoNode->setBranchDestination(tailBlock->getEntry());
fallthroughBlock->getExit()->insertBefore(gotoTree);
// Now we have fallthrough block, fallback block and tail/merge block. Let's set the ifcmp's destination to the fallback block, and update the CFG as well.
ifCmpNode->setBranchDestination(fallbackPathBlock->getEntry());
cfg->addEdge(ifCmpTreeTop->getEnclosingBlock(), fallbackPathBlock);
cfg->addEdge(fallthroughBlock, tailBlock);
cfg->removeEdge(fallthroughBlock, fallbackPathBlock);
}
void J9::RecognizedCallTransformer::process_java_lang_StringLatin1_inflate_BIBII(TR::TreeTop *treetop, TR::Node *node)
{
/*
* Replace the call with the following tree (+ boundary checks)
*
* treetop
* arraytranslate (TROTNoBreak)
* aladd
* srcObj
* ladd
* srcOff
* hdrSize
* aladd
* dstObj
* ladd
* lmul
* dstOff
* lconst 2
* hdrSize
* iconst 0 (dummy: table node)
* iconst 0xffff (term char node)
* length
* iconst -1 (dummy: stop index node)
*/
static bool verboseLatin1inflate = (feGetEnv("TR_verboseLatin1inflate") != NULL);
if (verboseLatin1inflate)
{
fprintf(stderr, "Recognize StringLatin1.inflate([BI[BII)V: %s @ %s\n",
comp()->signature(),
comp()->getHotnessName(comp()->getMethodHotness()));
}
TR_ASSERT_FATAL(comp()->cg()->getSupportsArrayTranslateTROTNoBreak(), "Support for arraytranslateTROTNoBreak is required");
bool is64BitTarget = comp()->target().is64Bit();
TR::Node *srcObj = node->getChild(0);
TR::Node *srcOff = node->getChild(1);
TR::Node *dstObj = node->getChild(2);
TR::Node *dstOff = node->getChild(3);
TR::Node *length = node->getChild(4);
TR::Node *arrayTranslateNode = TR::Node::create(node, TR::arraytranslate, 6);
arrayTranslateNode->setSourceIsByteArrayTranslate(true);
arrayTranslateNode->setTargetIsByteArrayTranslate(false);
arrayTranslateNode->setTermCharNodeIsHint(false);
arrayTranslateNode->setSourceCellIsTermChar(false);
arrayTranslateNode->setTableBackedByRawStorage(true);
arrayTranslateNode->setSymbolReference(comp()->getSymRefTab()->findOrCreateArrayTranslateSymbol());
TR::Node *tmpNode = TR::TransformUtil::generateConvertArrayElementIndexToOffsetTrees(comp(), srcOff, NULL, 1, false);
TR::Node *srcAddr = TR::TransformUtil::generateArrayElementAddressTrees(comp(), srcObj, tmpNode);
tmpNode = TR::TransformUtil::generateConvertArrayElementIndexToOffsetTrees(comp(), dstOff, NULL, 2, false);
TR::Node *dstAddr = TR::TransformUtil::generateArrayElementAddressTrees(comp(), dstObj, tmpNode);
TR::Node *termCharNode = TR::Node::create(node, TR::iconst, 0, 0xffff); // mask for ISO 8859-1 decoder
TR::Node *tableNode = TR::Node::create(node, TR::iconst, 0, 0); // dummy table node
TR::Node *stoppingNode = TR::Node::create(node, TR::iconst, 0, -1); // dummy stop index node
arrayTranslateNode->setAndIncChild(0, srcAddr);
arrayTranslateNode->setAndIncChild(1, dstAddr);
arrayTranslateNode->setAndIncChild(2, tableNode);
arrayTranslateNode->setAndIncChild(3, termCharNode);
arrayTranslateNode->setAndIncChild(4, length);
arrayTranslateNode->setAndIncChild(5, stoppingNode);
TR::CFG *cfg = comp()->getFlowGraph();
// if (length < 0) { call the original method }
TR::Node *constZeroNode1 = TR::Node::create(node, TR::iconst, 0, 0);
TR::Node *ifCmpNode1 = TR::Node::createif(TR::ificmplt, length, constZeroNode1);
TR::TreeTop *ifCmpTreeTop1 = TR::TreeTop::create(comp(), treetop->getPrevTreeTop(), ifCmpNode1);
// if (srcOff < 0) { call the original method }
TR::Node *constZeroNode2 = TR::Node::create(node, TR::iconst, 0, 0);
TR::Node *ifCmpNode2 = TR::Node::createif(TR::ificmplt, srcOff, constZeroNode2);
TR::TreeTop *ifCmpTreeTop2 = TR::TreeTop::create(comp(), ifCmpTreeTop1, ifCmpNode2);
// if (srcObj.length < srcOff + length) { call the original method }
TR::Node *arrayLenNode1 = TR::Node::create(node, TR::arraylength, 1, srcObj);
TR::Node *iaddNode1 = TR::Node::create(node, TR::iadd, 2, srcOff, length);
TR::Node *ifCmpNode3 = TR::Node::createif(TR::ificmplt, arrayLenNode1, iaddNode1);
TR::TreeTop *ifCmpTreeTop3 = TR::TreeTop::create(comp(), ifCmpTreeTop2, ifCmpNode3);
// if (dstOff < 0) { call the original method }
TR::Node *constZeroNode3 = TR::Node::create(node, TR::iconst, 0, 0);
TR::Node *ifCmpNode4 = TR::Node::createif(TR::ificmplt, dstOff, constZeroNode3);
TR::TreeTop *ifCmpTreeTop4 = TR::TreeTop::create(comp(), ifCmpTreeTop3, ifCmpNode4);
// if ((dstObj.length >> 1) < dstOff + length) { call the original method }
TR::Node *arrayLenNode2 = TR::Node::create(node, TR::arraylength, 1, dstObj);
TR::Node *constOneNode = TR::Node::create(node, TR::iconst, 0, 1);
TR::Node *ishrNode = TR::Node::create(node, TR::ishr, 2, arrayLenNode2, constOneNode);
TR::Node *iaddNode2 = TR::Node::create(node, TR::iadd, 2, dstOff, length);
TR::Node *ifCmpNode5 = TR::Node::createif(TR::ificmplt, ishrNode, iaddNode2);
TR::TreeTop *ifCmpTreeTop5 = TR::TreeTop::create(comp(), ifCmpTreeTop4, ifCmpNode5);
TR::TreeTop *arrayTranslateTreeTop = TR::TreeTop::create(comp(), ifCmpTreeTop5, arrayTranslateNode);
TR::Block *ifCmpBlock1 = ifCmpTreeTop1->getEnclosingBlock();
TR::Block *ifCmpBlock2 = ifCmpBlock1->split(ifCmpTreeTop2, cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
TR::Block *ifCmpBlock3 = ifCmpBlock2->split(ifCmpTreeTop3, cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
TR::Block *ifCmpBlock4 = ifCmpBlock3->split(ifCmpTreeTop4, cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
TR::Block *ifCmpBlock5 = ifCmpBlock4->split(ifCmpTreeTop5, cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
TR::Block *fallThroughPathBlock = ifCmpBlock5->split(arrayTranslateTreeTop, cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
// This block contains the original call node
TR::Block *fallbackPathBlock = fallThroughPathBlock->split(treetop, cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
TR::Block *tailBlock = fallbackPathBlock->split(treetop->getNextTreeTop(), cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
// Go to the tail block from the fall-through block
TR::Node *gotoNode = TR::Node::create(node, TR::Goto);
TR::TreeTop *gotoTree = TR::TreeTop::create(comp(), gotoNode, NULL, NULL);
gotoNode->setBranchDestination(tailBlock->getEntry());
fallThroughPathBlock->getExit()->insertBefore(gotoTree);
// Set the ificmp blocks' destinations to the fallback block and update the CFG
ifCmpNode1->setBranchDestination(fallbackPathBlock->getEntry());
cfg->addEdge(ifCmpBlock1, fallbackPathBlock);
ifCmpNode2->setBranchDestination(fallbackPathBlock->getEntry());
cfg->addEdge(ifCmpBlock2, fallbackPathBlock);
ifCmpNode3->setBranchDestination(fallbackPathBlock->getEntry());
cfg->addEdge(ifCmpBlock3, fallbackPathBlock);
ifCmpNode4->setBranchDestination(fallbackPathBlock->getEntry());
cfg->addEdge(ifCmpBlock4, fallbackPathBlock);
ifCmpNode5->setBranchDestination(fallbackPathBlock->getEntry());
cfg->addEdge(ifCmpBlock5, fallbackPathBlock);
cfg->addEdge(fallThroughPathBlock, tailBlock);
cfg->removeEdge(fallThroughPathBlock, fallbackPathBlock);
// The original call to StringLatin1.inflate([BI[BII)V will only be used
// if an exception needs to be thrown. Mark it as cold.
fallbackPathBlock->setFrequency(UNKNOWN_COLD_BLOCK_COUNT);
fallbackPathBlock->setIsCold();
}
void J9::RecognizedCallTransformer::process_java_lang_StringUTF16_toBytes(TR::TreeTop* treetop, TR::Node* node)
{
TR_J9VMBase* fej9 = static_cast<TR_J9VMBase*>(comp()->fe());
// Place arguments to StringUTF16.toBytes in temporaries
// to allow for control flow
TransformUtil::createTempsForCall(this, treetop);
TR::Node* valueNode = node->getChild(0);
TR::Node* offNode = node->getChild(1);
TR::Node* lenNode = node->getChild(2);
TR::CFG *cfg = comp()->getFlowGraph();
// The implementation of java.lang.StringUTF16.toBytes(char[],int,int) will
// throw a NegativeArraySizeException or OutOfMemoryError if the specified
// length is outside the range [0,0x3fffffff] or [0,0x3ffffffe], depending on
// the JDK level. In order to avoid deciding which to throw in the IL, fall
// back to the out-of-line call if the length is negative or greater than or
// equal to 0x3fffffff. Otherwise, create the byte array and copy the input
// char array to it with java.lang.String.decompressedArrayCopy
//
// Before:
//
// +----------------------------------------+
// | treetop |
// | acall java/lang/StringUTF16.toBytes |
// | aload charArr |
// | iload off |
// | iload len |
// +----------------------------------------+
//
// After:
//
// ifCmpblock
// +----------------------------------------+
// | astore charArrTemp |
// | aload charArr |
// | istore offTemp |
// | iload off |
// | istore lenTemp |
// | iload len |
// | ifiucmpge --> fallbackPathBlock -----------------+
// | iload lenTemp | |
// | iconst 0x3fffffff | |
// +--------------------+-------------------+ |
// | |
// fallThroughPathBlock V |
// +----------------------------------------+ |
// | astore result | |
// | newarray jitNewArray | |
// | ishl | |
// | iload lenTemp | |
// | icosnt 1 | |
// | iconst 8 ; array type is byte | |
// | treetop | |
// | call java/lang/String.decompressedArrayCopy |
// | aload charArrTemp | |
// | iload offTemp | |
// | ==>newarray | |
// | iconst 0 | |
// | iload lenTemp | |
// | goto joinBlock ----------------------------+ |
// +----------------------------------------+ | |
// | |
// +------------------------------+
// | |
// fallbackPathBlock V (freq 0) (cold) |
// +----------------------------------------+ |
// | astore result | |
// | acall java/lang/StringUTF16.toBytes | |
// | aload charArrTemp | |
// | iload offTemp | |
// | iload lenTemp | |
// +--------------------+-------------------+ |
// | |
// +-------------------------+
// |
// joinBlock V
// +----------------------------------------+
// | treetop |
// | aload result ; Replaces acall StringUTF16.toBytes
// +----------------------------------------+
//
TR::Node *upperBoundConstNode = TR::Node::iconst(node, TR::getMaxSigned<TR::Int32>() >> 1);
TR::Node *ifCmpNode = TR::Node::createif(TR::ifiucmpge, lenNode, upperBoundConstNode);
TR::TreeTop *ifCmpTreeTop = TR::TreeTop::create(comp(), treetop->getPrevTreeTop(), ifCmpNode);
// Create temporary variable that will be used to hold result
TR::DataType resultDataType = node->getDataType();
TR::SymbolReference *resultSymRef = comp()->getSymRefTab()->createTemporary(comp()->getMethodSymbol(), resultDataType);
// Create result byte array and copy input char array to it with String.decompressedArrayCopy
int32_t byteArrayType = fej9->getNewArrayTypeFromClass(fej9->getByteArrayClass());
TR::Node *newByteArrayNode = TR::Node::createWithSymRef(TR::newarray, 2, 2,
TR::Node::create(TR::ishl, 2, lenNode,
TR::Node::iconst(1)),
TR::Node::iconst(byteArrayType),
getSymRefTab()->findOrCreateNewArraySymbolRef(
node->getSymbolReference()->getOwningMethodSymbol(comp())));
newByteArrayNode->copyByteCodeInfo(node);
newByteArrayNode->setCanSkipZeroInitialization(true);
newByteArrayNode->setIsNonNull(true);
TR::Node *newByteArrayStoreNode = TR::Node::createStore(node, resultSymRef, newByteArrayNode);
TR::TreeTop *newByteArraryTreeTop = TR::TreeTop::create(comp(), ifCmpTreeTop, newByteArrayStoreNode);
TR::Node* newCallNode = TR::Node::createWithSymRef(node, TR::call, 5,
getSymRefTab()->methodSymRefFromName(comp()->getMethodSymbol(), "java/lang/String", "decompressedArrayCopy", "([CI[BII)V", TR::MethodSymbol::Static));
newCallNode->setAndIncChild(0, valueNode);
newCallNode->setAndIncChild(1, offNode);
newCallNode->setAndIncChild(2, newByteArrayNode);
newCallNode->setAndIncChild(3, TR::Node::iconst(0));
newCallNode->setAndIncChild(4, lenNode);
TR::TreeTop* lastFallThroughTreeTop = TR::TreeTop::create(comp(), newByteArraryTreeTop,
TR::Node::create(node, TR::treetop, 1, newCallNode));
// Insert the allocationFence after the arraycopy because the array can be allocated from the non-zeroed TLH
// and therefore we need to make sure no other thread sees stale memory from the array element section.
if (cg()->getEnforceStoreOrder())
{
TR::Node *allocationFence = TR::Node::createAllocationFence(newByteArrayNode, newByteArrayNode);
lastFallThroughTreeTop = TR::TreeTop::create(comp(), lastFallThroughTreeTop, allocationFence);
}
// Copy the original call tree for the fallback path, and store the
// result into the temporary that was created.
TR::Node *fallbackCallNode = node->duplicateTree();
TR::Node *fallbackStoreNode = TR::Node::createStore(node, resultSymRef, fallbackCallNode);
TR::TreeTop *fallbackTreeTop = TR::TreeTop::create(comp(), lastFallThroughTreeTop, fallbackStoreNode);
// Replace original call node with the load of the temporary
// variable that is stored on both sides of the if branch.
prepareToReplaceNode(node);
TR::Node::recreate(node, comp()->il.opCodeForDirectLoad(resultDataType));
node->setSymbolReference(resultSymRef);
// Split the current block right after the ifiucmpge
TR::Block *ifCmpBlock = ifCmpTreeTop->getEnclosingBlock();
// Then split the inline version of the code into its own block
TR::Block *fallThroughPathBlock = ifCmpBlock->split(newByteArraryTreeTop, cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
// Then split the fallback, out-of-line call into its own block
TR::Block *fallbackPathBlock = fallThroughPathBlock->split(fallbackTreeTop, cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
// Then split again at the original call TreeTop to create the tail block
TR::Block *tailBlock = fallbackPathBlock->split(treetop, cfg, true /* fixUpCommoning */, true /* copyExceptionSuccessors */);
// Now create a node to go to the merge (i.e. tail) block.
TR::Node *gotoNode = TR::Node::create(node, TR::Goto);
TR::TreeTop *gotoTree = TR::TreeTop::create(comp(), gotoNode, NULL, NULL);
gotoNode->setBranchDestination(tailBlock->getEntry());
fallThroughPathBlock->getExit()->insertBefore(gotoTree);
// Now we have fall-through block, fallback block and tail/merge block.
// Set the ifiucmp's destination to the fallback block and update the CFG as well.
ifCmpNode->setBranchDestination(fallbackPathBlock->getEntry());
cfg->addEdge(ifCmpBlock, fallbackPathBlock);
cfg->addEdge(fallThroughPathBlock, tailBlock);
cfg->removeEdge(fallThroughPathBlock, fallbackPathBlock);
// The original call to StringUTF16.toBytes will only be used
// if an exception needs to be thrown. Mark it as cold.
fallbackPathBlock->setFrequency(UNKNOWN_COLD_BLOCK_COUNT);
fallbackPathBlock->setIsCold();
}
void J9::RecognizedCallTransformer::process_jdk_internal_util_ArraysSupport_vectorizedMismatch(TR::TreeTop* treetop, TR::Node* node)
{
TR::Node* a = node->getChild(0);
TR::Node* aOffset = node->getChild(1);
TR::Node* b = node->getChild(2);
TR::Node* bOffset = node->getChild(3);
TR::Node* length = node->getChild(4);
TR::Node* log2ArrayIndexScale = node->getChild(5);
TR::Node* log2ArrayIndexScale64Bits = TR::Node::create(node, TR::iu2l, 1, log2ArrayIndexScale);
TR::Node* lengthInBytes = TR::Node::create(node, TR::lshl, 2,
TR::Node::create(node, TR::iu2l, 1, length),
log2ArrayIndexScale);
TR::Node* mask = TR::Node::create(node, TR::lor, 2,
TR::Node::create(node, TR::lshl, 2,
log2ArrayIndexScale64Bits,
TR::Node::iconst(node, 1)),
TR::Node::lconst(node, 3));
TR::Node* lengthToCompare = TR::Node::create(node, TR::land, 2,
lengthInBytes,
TR::Node::create(node, TR::lxor, 2, mask, TR::Node::lconst(node, -1)));
TR::Node* mismatchByteIndex = TR::Node::create(node, TR::arraycmplen, 3);
// TODO: replace the following aladd's with generateDataAddrLoadTrees when off-heap memory changes come in
// See OpenJ9 issue #16717 https://github.com/eclipse-openj9/openj9/issues/16717
mismatchByteIndex->setAndIncChild(0, TR::Node::create(node, TR::aladd, 2, a, aOffset));
mismatchByteIndex->setAndIncChild(1, TR::Node::create(node, TR::aladd, 2, b, bOffset));
mismatchByteIndex->setAndIncChild(2, lengthToCompare);
mismatchByteIndex->setSymbolReference(getSymRefTab()->findOrCreateArrayCmpLenSymbol());
TR::Node* invertedRemainder = TR::Node::create(node, TR::ixor, 2,
TR::Node::create(node, TR::l2i, 1,
TR::Node::create(node, TR::lshr, 2,
TR::Node::create(node, TR::land, 2, lengthInBytes, mask),
log2ArrayIndexScale)),
TR::Node::iconst(node, -1));
TR::Node* mismatchElementIndex = TR::Node::create(node, TR::l2i, 1, TR::Node::create(node, TR::lshr, 2, mismatchByteIndex, log2ArrayIndexScale));
TR::Node* noMismatchFound = TR::Node::create(node, TR::lcmpeq, 2, mismatchByteIndex, lengthToCompare);
anchorAllChildren(node, treetop);
prepareToReplaceNode(node);
TR::Node::recreate(node, TR::iselect);
node->setNumChildren(3);
node->setAndIncChild(0, noMismatchFound);
node->setAndIncChild(1, invertedRemainder);
node->setAndIncChild(2, mismatchElementIndex);
TR::TransformUtil::removeTree(comp(), treetop);
}
void J9::RecognizedCallTransformer::process_java_lang_StrictMath_and_Math_sqrt(TR::TreeTop* treetop, TR::Node* node)
{
TR::Node* valueNode = node->getLastChild();
anchorAllChildren(node, treetop);
prepareToReplaceNode(node);
TR::Node::recreate(node, TR::dsqrt);
node->setNumChildren(1);
node->setAndIncChild(0, valueNode);
TR::TransformUtil::removeTree(comp(), treetop);
}
/*
Transform an Unsafe atomic call to diamonds with equivalent semantics
If OffHeap is enabled, a runtime isArray check is added to determine
if loading the dataAddrPtr is necessary.
yes
isObjectNull [A] ------------------------------------------>
| |
| no |
#if OffHeap |
| yes |
isArray [I] ------------------------> |
| | |
| use the dataAddrPtr of the array |
| xcall atomic method helper [J] |
| | |
| [H] |
| no |
| |
#endif OffHeap |
| yes |
isNotLowTagged [B] ---------------------------------------->
| |
| no |
| no |
isFinal [C] --------------------> |
| | |
| yes | |
jitReportFinalFieldModified [F] | |
| | |
+---------------------------> |
| |
calculate address [D] calculate address
for static field for instance field
(non collected reference) and absolute address
| (collected reference)
| |
xcall atomic method helper [G] xcall atomic method helper [E]
| |
+-----------+--------------+
|
v
program after the original call [H]
Block before the transformation: ===>
start Block_A
...
xcall Unsafe.xxx
...
<load of unsafe call argX>
...
end Block_A
Blocks after the transformation: ===>
start Block_A
...
astore object-1
<load of unsafe call argX>
...
ifacmpeq -> <Block_E>
object-1
aconst null
end Block_A
#if OffHeap
start Block_I
ifacmpne -> <Block_J>
andi
lloadi <isClassDepthAndFlags>
aloadi <vft-symbol>
aload <object-1>
iconst 0x10000 // array-flag
iconst 0
end Block_I
#endif OffHeap
start Block_B
iflcmpne -> <Block_E>
land
lload <offset>
lconst J9_SUN_STATIC_FIELD_OFFSET_TAG
lconst J9_SUN_STATIC_FIELD_OFFSET_TAG
end Block_B
start Block_C
iflcmpeq -> <Block_F>
land
lload <offset>
lconst J9_SUN_FINAL_FIELD_OFFSET_TAG
lconst J9_SUN_FINAL_FIELD_OFFSET_TAG
end Block_C
start Block_D
astore <object-2>
aloadi ramStaticsFromClass
aloadi <classFromJavaLangClass>
aload <object-1>
lstore <offset>
land
lload <offset>
lconst ~J9_SUN_FIELD_OFFSET_MASK
end Block_D
start Block_G
xcall atomic method helper
aladd
aload <object-2>
lload <offset>
xload value
xstore
==>xcall
goto --> block_H
end Block_G
#if OffHeap
start Block_J
xcall atomic method helper
aladd
aloadi <contiguousArrayDataAddrField>
aload <object-1>
lload <offset>
xload value
xstore
==>xcall
goto --> block_H
end Block_J
#endif OffHeap
start Block_E
xcall atomic method helper
aladd
aload <object-1>
lload <offset>
xload value
xstore
==>xcall
end Block_E
start Block_H
xreturn
xload
end Block_H
...
start Block_F
call jitReportFinalFieldModified
aloadi <classFromJavaLangClass>
aload <object-1>
go to <Block_D>
end Block_F
*/
void J9::RecognizedCallTransformer::processUnsafeAtomicCall(TR::TreeTop* treetop, TR::SymbolReferenceTable::CommonNonhelperSymbol helper, bool needsNullCheck)
{
bool enableTrace = trace();
bool isNotStaticField = !strncmp(comp()->getCurrentMethod()->classNameChars(), "java/util/concurrent/atomic/", strlen("java/util/concurrent/atomic/"));
bool fixupCommoning = true;
TR::Node* unsafeCall = treetop->getNode()->getFirstChild();
TR::Node* objectNode = unsafeCall->getChild(1);
TR::Node* offsetNode = unsafeCall->getChild(2);
TR::Node* address = NULL;
TR::SymbolReference* newSymbolReference = NULL;
TR::CFG* cfg = comp()->getMethodSymbol()->getFlowGraph();
TR::Node* isObjectNullNode = NULL;
TR::TreeTop* isObjectNullTreeTop = NULL;
TR::Node* isObjectArrayNode = NULL;
TR::TreeTop* isObjectArrayTreeTop = NULL;
TR::Node* isNotLowTaggedNode = NULL;
TR::TreeTop* isNotLowTaggedTreeTop = NULL;
// Preserve null check on the unsafe object
if (treetop->getNode()->getOpCode().isNullCheck())
{
TR::Node *passthrough = TR::Node::create(unsafeCall, TR::PassThrough, 1);
passthrough->setAndIncChild(0, unsafeCall->getFirstChild());
TR::Node * checkNode = TR::Node::createWithSymRef(treetop->getNode(), TR::NULLCHK, 1, passthrough, treetop->getNode()->getSymbolReference());
treetop->insertBefore(TR::TreeTop::create(comp(), checkNode));
TR::Node::recreate(treetop->getNode(), TR::treetop);
if (enableTrace)
traceMsg(comp(), "Created node %p to preserve NULLCHK on unsafe call %p\n", checkNode, unsafeCall);
}
if (isNotStaticField)
{
// It is safe to skip diamond, the address can be calculated directly via [object+offset]
// Except if OffHeap is used, then check if object is array
#if defined(J9VM_GC_SPARSE_HEAP_ALLOCATION)
if (TR::Compiler->om.isOffHeapAllocationEnabled())
{
// Generate null-check and array-check blocks
TR::TransformUtil::createTempsForCall(this, treetop);
objectNode = unsafeCall->getChild(1);
offsetNode = unsafeCall->getChild(2);
// Test if object is null
isObjectNullNode = TR::Node::createif(TR::ifacmpeq, objectNode->duplicateTree(), TR::Node::aconst(0), NULL);
isObjectNullTreeTop = TR::TreeTop::create(comp(), isObjectNullNode);
treetop->insertBefore(isObjectNullTreeTop);
treetop->getEnclosingBlock()->split(treetop, cfg, fixupCommoning);
if (enableTrace)
traceMsg(comp(), "Created isObjectNull test node n%dn, non-null object will fall through to Block_%d\n", isObjectNullNode->getGlobalIndex(), treetop->getEnclosingBlock()->getNumber());
//generate array check treetop
TR::Node *vftLoad = TR::Node::createWithSymRef(TR::aloadi, 1, 1,
objectNode->duplicateTree(),
comp()->getSymRefTab()->findOrCreateVftSymbolRef());
isObjectArrayNode = TR::Node::createif(TR::ificmpne,
comp()->fej9()->testIsClassArrayType(vftLoad),
TR::Node::create(TR::iconst, 0),
NULL);
isObjectArrayTreeTop = TR::TreeTop::create(comp(), isObjectArrayNode, NULL, NULL);
treetop->insertBefore(isObjectArrayTreeTop);
treetop->getEnclosingBlock()->split(treetop, cfg, fixupCommoning);
if (enableTrace)
traceMsg(comp(), "Created isObjectArray test node n%dn, array will branch to array access block\n", isObjectArrayNode->getGlobalIndex());
address = comp()->target().is32Bit() ? TR::Node::create(TR::aiadd, 2, objectNode->duplicateTree(), TR::Node::create(TR::l2i, 1, offsetNode->duplicateTree())) :
TR::Node::create(TR::aladd, 2, objectNode->duplicateTree(), offsetNode->duplicateTree());
}
else
#endif /* J9VM_GC_SPARSE_HEAP_ALLOCATION */
{
address = comp()->target().is32Bit() ? TR::Node::create(TR::aiadd, 2, objectNode, TR::Node::create(TR::l2i, 1, offsetNode)) :
TR::Node::create(TR::aladd, 2, objectNode, offsetNode);
if (enableTrace)
traceMsg(comp(), "Field is not static, use the object and offset directly\n");
}
}
else
{
// Otherwise, the address is [object+offset] for non-static field,
// or [object's ramStaticsFromClass + (offset & ~mask)] for static field
// Save all the children to temps before splitting the block
TR::TransformUtil::createTempsForCall(this, treetop);
objectNode = unsafeCall->getChild(1);
offsetNode = unsafeCall->getChild(2);
// Null Check
if (needsNullCheck)
{
auto NULLCHKNode = TR::Node::createWithSymRef(unsafeCall, TR::NULLCHK, 1,
TR::Node::create(TR::PassThrough, 1, objectNode->duplicateTree()),
comp()->getSymRefTab()->findOrCreateNullCheckSymbolRef(comp()->getMethodSymbol()));
treetop->insertBefore(TR::TreeTop::create(comp(), NULLCHKNode));
if (enableTrace)
traceMsg(comp(), "Created NULLCHK tree %p on the first argument of Unsafe call\n", treetop->getPrevTreeTop());
}
// Test if object is null
isObjectNullNode = TR::Node::createif(TR::ifacmpeq, objectNode->duplicateTree(), TR::Node::aconst(0), NULL);
isObjectNullTreeTop = TR::TreeTop::create(comp(), isObjectNullNode);
treetop->insertBefore(isObjectNullTreeTop);
treetop->getEnclosingBlock()->split(treetop, cfg, fixupCommoning);
if (enableTrace)
traceMsg(comp(), "Created isObjectNull test node n%dn, non-null object will fall through to Block_%d\n", isObjectNullNode->getGlobalIndex(), treetop->getEnclosingBlock()->getNumber());
// Test if object is array - offheap only
#if defined (J9VM_GC_SPARSE_HEAP_ALLOCATION)
if (TR::Compiler->om.isOffHeapAllocationEnabled() && comp()->target().is64Bit())
{
//generate array check treetop
TR::Node *vftLoad = TR::Node::createWithSymRef(TR::aloadi, 1, 1,
objectNode->duplicateTree(),
comp()->getSymRefTab()->findOrCreateVftSymbolRef());
isObjectArrayNode = TR::Node::createif(TR::ificmpne,
comp()->fej9()->testIsClassArrayType(vftLoad),
TR::Node::create(TR::iconst, 0),
NULL);
isObjectArrayTreeTop = TR::TreeTop::create(comp(), isObjectArrayNode, NULL, NULL);
treetop->insertBefore(isObjectArrayTreeTop);
treetop->getEnclosingBlock()->split(treetop, cfg, fixupCommoning);
if (enableTrace)
traceMsg(comp(), "Created isObjectArray test node n%dn, array will branch to array access block\n", isObjectArrayNode->getGlobalIndex());
}
#endif /* J9VM_GC_SPARSE_HEAP_ALLOCATION */
// Test if low tag is set
isNotLowTaggedNode = TR::Node::createif(TR::iflcmpne,
TR::Node::create(TR::land, 2, offsetNode->duplicateTree(), TR::Node::lconst(J9_SUN_STATIC_FIELD_OFFSET_TAG)),
TR::Node::lconst(J9_SUN_STATIC_FIELD_OFFSET_TAG),
NULL);
isNotLowTaggedTreeTop = TR::TreeTop::create(comp(), isNotLowTaggedNode);
treetop->insertBefore(isNotLowTaggedTreeTop);
treetop->getEnclosingBlock()->split(treetop, cfg, fixupCommoning);
if (enableTrace)
traceMsg(comp(), "Created isNotLowTagged test node n%dn, static field will fall through to Block_%d\n", isNotLowTaggedNode->getGlobalIndex(), treetop->getEnclosingBlock()->getNumber());
static char *disableIllegalWriteReport = feGetEnv("TR_DisableIllegalWriteReport");
// Test if the call is a write to a static final field
if (!disableIllegalWriteReport
&& !comp()->getOption(TR_DisableGuardedStaticFinalFieldFolding)
&& TR_J9MethodBase::isUnsafePut(unsafeCall->getSymbol()->castToMethodSymbol()->getMandatoryRecognizedMethod()))
{
// If the field is static final
auto isFinalNode = TR::Node::createif(TR::iflcmpeq,
TR::Node::create(TR::land, 2, offsetNode->duplicateTree(), TR::Node::lconst(J9_SUN_FINAL_FIELD_OFFSET_TAG)),
TR::Node::lconst(J9_SUN_FINAL_FIELD_OFFSET_TAG),
NULL /*branchTarget*/);
auto isFinalTreeTop = TR::TreeTop::create(comp(), isFinalNode);
auto reportFinalFieldModification = TR::TransformUtil::generateReportFinalFieldModificationCallTree(comp(), objectNode->duplicateTree());
auto elseBlock = treetop->getEnclosingBlock();
TR::TransformUtil::createConditionalAlternatePath(comp(), isFinalTreeTop, reportFinalFieldModification, elseBlock, elseBlock, comp()->getMethodSymbol()->getFlowGraph(), true /*markCold*/);
if (enableTrace)
{
traceMsg(comp(), "Created isFinal test node n%dn, non-final-static field will fall through to Block_%d, final field goes to Block_%d\n",
isFinalNode->getGlobalIndex(), treetop->getEnclosingBlock()->getNumber(), reportFinalFieldModification->getEnclosingBlock()->getNumber());
}
TR::DebugCounter::prependDebugCounter(comp(),
TR::DebugCounter::debugCounterName(comp(),
"illegalWriteReport/atomic/(%s %s)",
comp()->signature(),
comp()->getHotnessName(comp()->getMethodHotness())),
reportFinalFieldModification->getNextTreeTop());
}
// ramStatics is not collected. We cannot reuse objectNode->getSymbolReference()
newSymbolReference = comp()->getSymRefTab()->createTemporary(comp()->getMethodSymbol(), TR::Address);
newSymbolReference->getSymbol()->setNotCollected();
// Calculate static address
auto objectAdjustmentNode = TR::Node::createWithSymRef(TR::astore, 1, 1,
TR::Node::createWithSymRef(TR::aloadi, 1, 1,
TR::Node::createWithSymRef(TR::aloadi, 1, 1,
objectNode->duplicateTree(),
comp()->getSymRefTab()->findOrCreateClassFromJavaLangClassSymbolRef()),
comp()->getSymRefTab()->findOrCreateRamStaticsFromClassSymbolRef()),
newSymbolReference);
auto offsetAdjustmentNode = TR::Node::createWithSymRef(TR::lstore, 1, 1,
TR::Node::create(TR::land, 2,
offsetNode->duplicateTree(),
TR::Node::lconst(~J9_SUN_FIELD_OFFSET_MASK)),
offsetNode->getSymbolReference());
if (enableTrace)
traceMsg(comp(), "Created node objectAdjustmentNode n%dn #%d and offsetAdjustmentNode #%d n%dn to adjust object and offset for static field\n",
objectAdjustmentNode->getGlobalIndex(), objectAdjustmentNode->getOpCode().hasSymbolReference() ? objectAdjustmentNode->getSymbolReference()->getReferenceNumber() : -1,
offsetAdjustmentNode->getGlobalIndex(), offsetAdjustmentNode->getOpCode().hasSymbolReference() ? offsetAdjustmentNode->getSymbolReference()->getReferenceNumber() : -1);
treetop->insertBefore(TR::TreeTop::create(comp(), objectAdjustmentNode));
treetop->insertBefore(TR::TreeTop::create(comp(), offsetAdjustmentNode));
treetop->getEnclosingBlock()->split(treetop, cfg, fixupCommoning);