-
Notifications
You must be signed in to change notification settings - Fork 729
/
Walker.cpp
7866 lines (6988 loc) · 318 KB
/
Walker.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
*******************************************************************************/
#include <algorithm>
#include "codegen/CodeGenerator.hpp"
#include "compile/InlineBlock.hpp"
#include "compile/Method.hpp"
#include "compile/ResolvedMethod.hpp"
#include "control/Recompilation.hpp"
#include "control/RecompilationInfo.hpp"
#include "env/CompilerEnv.hpp"
#include "env/PersistentCHTable.hpp"
#include "env/StackMemoryRegion.hpp"
#include "env/TypeLayout.hpp"
#include "env/jittypes.h"
#include "env/VMAccessCriticalSection.hpp"
#include "env/VerboseLog.hpp"
#include "exceptions/AOTFailure.hpp"
#include "exceptions/FSDFailure.hpp"
#include "exceptions/RuntimeFailure.hpp"
#include "optimizer/TransformUtil.hpp"
#include "il/Node.hpp"
#include "il/Node_inlines.hpp"
#include "il/TreeTop.hpp"
#include "il/TreeTop_inlines.hpp"
#include "env/j9fieldsInfo.h"
#include "env/VMJ9.h"
#include "ilgen/ClassLookahead.hpp"
#include "ilgen/J9ByteCode.hpp"
#include "ilgen/J9ByteCodeIlGenerator.hpp"
#include "infra/Bit.hpp" //for trailingZeroes
#include "env/JSR292Methods.h"
#if defined(J9VM_OPT_JITSERVER)
#include "env/j9methodServer.hpp"
#endif
#define JAVA_SERIAL_CLASS_NAME "Ljava/io/ObjectInputStream;"
#define JAVA_SERIAL_CLASS_NAME_LEN 27
#define JAVA_SERIAL_CALLEE_METHOD_NAME_LEN 10
#define JAVA_SERIAL_CALLEE_METHOD_NAME "readObject"
#define JAVA_SERIAL_CALLEE_METHOD_SIG_LEN 20
#define JAVA_SERIAL_CALLEE_METHOD_SIG "()Ljava/lang/Object;"
#define JAVA_SERIAL_REPLACE_CLASS_LEN 25
#define JAVA_SERIAL_REPLACE_CLASS_NAME "java/io/ObjectInputStream"
#define JAVA_SERIAL_REPLACE_METHOD_SIG_LEN 64
#define JAVA_SERIAL_REPLACE_METHOD_SIG "(Ljava/io/ObjectInputStream;Ljava/lang/Class;)Ljava/lang/Object;"
#define JAVA_SERIAL_REPLACE_METHOD_NAME_LEN 20
#define JAVA_SERIAL_REPLACE_METHOD_NAME "redirectedReadObject"
#define ORB_CALLER_METHOD_NAME_LEN 10
#define ORB_CALLER_METHOD_NAME "readObject"
#define ORB_CALLER_METHOD_SIG_LEN 30
#define ORB_CALLER_METHOD_SIG "(Ljava/io/ObjectInputStream;)V"
#define ORB_CALLEE_METHOD_NAME_LEN 10
#define ORB_CALLEE_METHOD_NAME "readObject"
#define ORB_CALLEE_METHOD_SIG_LEN 20
#define ORB_CALLEE_METHOD_SIG "()Ljava/lang/Object;"
#define ORB_REPLACE_CLASS_LEN 30
#define ORB_REPLACE_CLASS_NAME "com/ibm/rmi/io/IIOPInputStream"
#define ORB_REPLACE_METHOD_SIG_LEN 64
#define ORB_REPLACE_METHOD_SIG "(Ljava/io/ObjectInputStream;Ljava/lang/Class;)Ljava/lang/Object;"
#define ORB_REPLACE_METHOD_NAME_LEN 20
#define ORB_REPLACE_METHOD_NAME "redirectedReadObject"
#define JSR292_ILGenMacros "java/lang/invoke/ILGenMacros"
#define JSR292_placeholder "placeholder"
#define JSR292_placeholderSig "(I)I"
#define JSR292_MethodHandle "java/lang/invoke/MethodHandle"
#define JSR292_invokeExactTargetAddress "invokeExactTargetAddress"
#define JSR292_invokeExactTargetAddressSig "()J"
#define JSR292_getType "type"
#define JSR292_getTypeSig "()Ljava/lang/invoke/MethodType;"
#define JSR292_invokeExact "invokeExact"
#define JSR292_invokeExactSig "([Ljava/lang/Object;)Ljava/lang/Object;"
#define JSR292_ComputedCalls "java/lang/invoke/ComputedCalls"
#define JSR292_dispatchDirectPrefix "dispatchDirect_"
#define JSR292_dispatchDirectArgSig "(JI)"
#define JSR292_asType "asType"
#define JSR292_asTypeSig "(Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;"
#define JSR292_forGenericInvoke "forGenericInvoke"
#define JSR292_forGenericInvokeSig "(Ljava/lang/invoke/MethodType;Z)Ljava/lang/invoke/MethodHandle;"
static void printStack(TR::Compilation *comp, TR_Stack<TR::Node*> *stack, const char *message)
{
// TODO: This should be in the debug DLL
if (stack->isEmpty())
{
traceMsg(comp, " ---- %s: empty -----------------\n", message);
}
else
{
TR_BitVector nodesAlreadyPrinted(comp->getNodeCount(), comp->trMemory(), stackAlloc, growable);
comp->getDebug()->saveNodeChecklist(nodesAlreadyPrinted);
char buf[30];
traceMsg(comp, " /--- %s ------------------------", message);
for (int i = stack->topIndex(); i >= 0; --i)
{
TR::Node *node = stack->element(i);
traceMsg(comp, "\n");
sprintf(buf, " @%-2d", i);
comp->getDebug()->printWithFixedPrefix(comp->getOutFile(), node, 1, false, true, buf);
if (!nodesAlreadyPrinted.isSet(node->getGlobalIndex()))
{
for (int j = 0; j < node->getNumChildren(); ++j)
{
traceMsg(comp, "\n");
comp->getDebug()->printWithFixedPrefix(comp->getOutFile(), node->getChild(j), 3, true, true, " ");
}
}
}
traceMsg(comp, "\n");
}
}
static void printTrees(TR::Compilation *comp, TR::TreeTop *firstTree, TR::TreeTop *stopTree, const char *message)
{
// TODO: This should be in the debug DLL
if (firstTree == stopTree)
{
traceMsg(comp, " ---- %s: none ------------------\n", message);
}
else
{
traceMsg(comp, " /--- %s ------------------------", message);
for (TR::TreeTop *tt = firstTree; tt && tt != stopTree; tt = tt->getNextTreeTop())
{
traceMsg(comp, "\n");
comp->getDebug()->printWithFixedPrefix(comp->getOutFile(), tt->getNode(), 1, true, true, " ");
}
traceMsg(comp, "\n");
}
}
static TR::ILOpCodes getCallOpForType(TR::DataType type)
{
switch(type)
{
case TR::Address: return TR::acall;
case TR::Float : return TR::fcall;
case TR::Double: return TR::dcall;
case TR::Int32:
case TR::Int16:
case TR::Int8: return TR::icall;
case TR::Int64:return TR::lcall;
default: TR_ASSERT(false, "assertion failure");
}
return TR::BadILOp;
}
#define DCAS_AVAILABLE_FLAG "dWordCASSupported"
#define DCAS_AVAILABLE_FLAG_LEN 17
#define DCAS_AVAILABLE_FLAG_SIG "Z"
#define DCAS_AVAILABLE_FLAG_SIG_LEN 1
#define DSET_AVAILABLE_FLAG "dWordSetSupported"
#define DSET_AVAILABLE_FLAG_LEN 17
#define DSET_AVAILABLE_FLAG_SIG "Z"
#define DSET_AVAILABLE_FLAG_SIG_LEN 1
TR::Block * TR_J9ByteCodeIlGenerator::walker(TR::Block * prevBlock)
{
int32_t i, lastIndex = _bcIndex, firstIndex = _bcIndex;
if (comp()->getOption(TR_TraceILGen))
{
comp()->getDebug()->clearNodeChecklist();
traceMsg(comp(), "==== Starting ILGen walker at bytecode %x", _bcIndex);
if (_argPlaceholderSlot != -1)
traceMsg(comp(), " argPlaceholderSlot=%d", _argPlaceholderSlot);
traceMsg(comp(), "\n");
}
#if defined(J9VM_OPT_JITSERVER)
if (prevBlock == 0 && comp()->isOutOfProcessCompilation() && _methodSymbol->getResolvedMethod())
{
// Every J9BCinvoke* bytecode requires a corresponding resolved method for its method symbol.
// Prefetch resolved methods in one message.
// For unresolved methods, allow the next 2 requests to return NULL without asking the client,
// since they happen almost immediately after this one and method is unlikely to become resolved.
//
// NOTE: first request occurs in the switch statement over bytecodes,
// second request occurs in stashArgumentsForOSR
if (_methodSymbol->getResolvedMethod() == comp()->getMethodBeingCompiled())
static_cast<TR_ResolvedJ9JITServerMethod *>(_methodSymbol->getResolvedMethod())->cacheResolvedMethodsCallees(2);
// Cache field info for every field/static loaded/stored in this method, which are later used by
// jitFieldsAreSame/jitStaticAreSame when creating symbol references.
static_cast<TR_ResolvedJ9JITServerMethod *>(_methodSymbol->getResolvedMethod())->cacheFields();
}
#endif
while (_bcIndex < _maxByteCodeIndex)
{
if (blocks(_bcIndex) && blocks(_bcIndex) != _block)
{
if (isGenerated(_bcIndex))
_bcIndex = genGoto(_bcIndex);
else
_bcIndex = genBBEndAndBBStart();
if (_bcIndex >= _maxByteCodeIndex)
break;
}
if (_bcIndex < firstIndex)
firstIndex = _bcIndex;
else if (_bcIndex > lastIndex)
lastIndex = _bcIndex;
TR_ASSERT(!isGenerated(_bcIndex), "Walker error");
setIsGenerated(_bcIndex);
uint8_t opcode = _code[_bcIndex];
TR::TreeTop *traceStop = _block->getExit();
TR::TreeTop *traceStart = traceStop->getPrevTreeTop();
if (comp()->getOption(TR_TraceILGen))
traceMsg(comp(), "%4x: %s\n", _bcIndex, ((TR_J9VM *)fej9())->getByteCodeName(opcode));
_bc = convertOpCodeToByteCodeEnum(opcode);
stashArgumentsForOSR(_bc);
switch (_bc)
{
case J9BCinvokeinterface2:
case J9BCnop: _bcIndex += 1; break;
case J9BCaconstnull: loadConstant(TR::aconst, (void *)0); _bcIndex += 1; break;
case J9BCiconstm1: loadConstant(TR::iconst, -1); _bcIndex += 1; break;
case J9BCiconst0: loadConstant(TR::iconst, 0); _bcIndex += 1; break;
case J9BCiconst1: loadConstant(TR::iconst, 1); _bcIndex += 1; break;
case J9BCiconst2: loadConstant(TR::iconst, 2); _bcIndex += 1; break;
case J9BCiconst3: loadConstant(TR::iconst, 3); _bcIndex += 1; break;
case J9BCiconst4: loadConstant(TR::iconst, 4); _bcIndex += 1; break;
case J9BCiconst5: loadConstant(TR::iconst, 5); _bcIndex += 1; break;
case J9BClconst0: loadConstant(TR::lconst, (int64_t)0); _bcIndex += 1; break;
case J9BClconst1: loadConstant(TR::lconst, (int64_t)1); _bcIndex += 1; break;
case J9BCfconst0: loadConstant(TR::fconst, 0.0f); _bcIndex += 1; break;
case J9BCfconst1: loadConstant(TR::fconst, 1.0f); _bcIndex += 1; break;
case J9BCfconst2: loadConstant(TR::fconst, 2.0f); _bcIndex += 1; break;
case J9BCdconst0: loadConstant(TR::dconst, 0.0); _bcIndex += 1; break;
case J9BCdconst1: loadConstant(TR::dconst, 1.0); _bcIndex += 1; break;
case J9BCldc: loadFromCP(TR::NoType, nextByte()); _bcIndex += 2; break;
case J9BCldcw: loadFromCP(TR::NoType, next2Bytes()); _bcIndex += 3; break;
case J9BCldc2lw: loadFromCP(TR::NoType, next2Bytes()); _bcIndex += 3; break;
case J9BCldc2dw: loadFromCP(TR::NoType, next2Bytes()); _bcIndex += 3; break;
case J9BCiload0: loadAuto(TR::Int32, 0); _bcIndex += 1; break;
case J9BCiload1: loadAuto(TR::Int32, 1); _bcIndex += 1; break;
case J9BCiload2: loadAuto(TR::Int32, 2); _bcIndex += 1; break;
case J9BCiload3: loadAuto(TR::Int32, 3); _bcIndex += 1; break;
case J9BClload0: loadAuto(TR::Int64, 0); _bcIndex += 1; break;
case J9BClload1: loadAuto(TR::Int64, 1); _bcIndex += 1; break;
case J9BClload2: loadAuto(TR::Int64, 2); _bcIndex += 1; break;
case J9BClload3: loadAuto(TR::Int64, 3); _bcIndex += 1; break;
case J9BCfload0: loadAuto(TR::Float, 0); _bcIndex += 1; break;
case J9BCfload1: loadAuto(TR::Float, 1); _bcIndex += 1; break;
case J9BCfload2: loadAuto(TR::Float, 2); _bcIndex += 1; break;
case J9BCfload3: loadAuto(TR::Float, 3); _bcIndex += 1; break;
case J9BCdload0: loadAuto(TR::Double, 0); _bcIndex += 1; break;
case J9BCdload1: loadAuto(TR::Double, 1); _bcIndex += 1; break;
case J9BCdload2: loadAuto(TR::Double, 2); _bcIndex += 1; break;
case J9BCdload3: loadAuto(TR::Double, 3); _bcIndex += 1; break;
case J9BCaload0: loadAuto(TR::Address, 0); _bcIndex += 1; break;
case J9BCaload1: loadAuto(TR::Address, 1); _bcIndex += 1; break;
case J9BCaload2: loadAuto(TR::Address, 2); _bcIndex += 1; break;
case J9BCaload3: loadAuto(TR::Address, 3); _bcIndex += 1; break;
case J9BCiaload: loadArrayElement(TR::Int32); _bcIndex += 1; break;
case J9BClaload: loadArrayElement(TR::Int64); _bcIndex += 1; break;
case J9BCfaload: loadArrayElement(TR::Float); _bcIndex += 1; break;
case J9BCdaload: loadArrayElement(TR::Double); _bcIndex += 1; break;
case J9BCaaload: loadArrayElement(TR::Address); _bcIndex += 1; break;
case J9BCbaload: loadArrayElement(TR::Int8); genUnary(TR::b2i); _bcIndex += 1; break;
case J9BCcaload: loadArrayElement(TR::Int16); genUnary(TR::su2i); _bcIndex += 1; break;
case J9BCsaload: loadArrayElement(TR::Int16); genUnary(TR::s2i); _bcIndex += 1; break;
case J9BCiloadw: loadAuto(TR::Int32, next2Bytes()); _bcIndex += 3; break;
case J9BClloadw: loadAuto(TR::Int64, next2Bytes()); _bcIndex += 3; break;
case J9BCfloadw: loadAuto(TR::Float, next2Bytes()); _bcIndex += 3; break;
case J9BCdloadw: loadAuto(TR::Double, next2Bytes()); _bcIndex += 3; break;
case J9BCaloadw: loadAuto(TR::Address, next2Bytes()); _bcIndex += 3; break;
case J9BCbipush: loadConstant(TR::iconst, nextByteSigned()); _bcIndex += 2; break;
case J9BCsipush: loadConstant(TR::iconst, next2BytesSigned()); _bcIndex += 3; break;
case J9BCiload: loadAuto(TR::Int32, nextByte()); _bcIndex += 2; break;
case J9BClload: loadAuto(TR::Int64, nextByte()); _bcIndex += 2; break;
case J9BCfload: loadAuto(TR::Float, nextByte()); _bcIndex += 2; break;
case J9BCdload: loadAuto(TR::Double, nextByte()); _bcIndex += 2; break;
case J9BCaload: loadAuto(TR::Address, nextByte()); _bcIndex += 2; break;
case J9BCistore: storeAuto(TR::Int32, nextByte()); _bcIndex += 2; break;
case J9BClstore: storeAuto(TR::Int64, nextByte()); _bcIndex += 2; break;
case J9BCfstore: storeAuto(TR::Float, nextByte()); _bcIndex += 2; break;
case J9BCdstore: storeAuto(TR::Double, nextByte()); _bcIndex += 2; break;
case J9BCastore: storeAuto(TR::Address, nextByte()); _bcIndex += 2; break;
case J9BCistore0: storeAuto(TR::Int32, 0); _bcIndex += 1; break;
case J9BCistore1: storeAuto(TR::Int32, 1); _bcIndex += 1; break;
case J9BCistore2: storeAuto(TR::Int32, 2); _bcIndex += 1; break;
case J9BCistore3: storeAuto(TR::Int32, 3); _bcIndex += 1; break;
case J9BClstore0: storeAuto(TR::Int64, 0); _bcIndex += 1; break;
case J9BClstore1: storeAuto(TR::Int64, 1); _bcIndex += 1; break;
case J9BClstore2: storeAuto(TR::Int64, 2); _bcIndex += 1; break;
case J9BClstore3: storeAuto(TR::Int64, 3); _bcIndex += 1; break;
case J9BCfstore0: storeAuto(TR::Float, 0); _bcIndex += 1; break;
case J9BCfstore1: storeAuto(TR::Float, 1); _bcIndex += 1; break;
case J9BCfstore2: storeAuto(TR::Float, 2); _bcIndex += 1; break;
case J9BCfstore3: storeAuto(TR::Float, 3); _bcIndex += 1; break;
case J9BCdstore0: storeAuto(TR::Double, 0); _bcIndex += 1; break;
case J9BCdstore1: storeAuto(TR::Double, 1); _bcIndex += 1; break;
case J9BCdstore2: storeAuto(TR::Double, 2); _bcIndex += 1; break;
case J9BCdstore3: storeAuto(TR::Double, 3); _bcIndex += 1; break;
case J9BCastore0: storeAuto(TR::Address, 0); _bcIndex += 1; break;
case J9BCastore1: storeAuto(TR::Address, 1); _bcIndex += 1; break;
case J9BCastore2: storeAuto(TR::Address, 2); _bcIndex += 1; break;
case J9BCastore3: storeAuto(TR::Address, 3); _bcIndex += 1; break;
case J9BCiastore: storeArrayElement(TR::Int32); _bcIndex += 1; break;
case J9BClastore: storeArrayElement(TR::Int64); _bcIndex += 1; break;
case J9BCfastore: storeArrayElement(TR::Float); _bcIndex += 1; break;
case J9BCdastore: storeArrayElement(TR::Double); _bcIndex += 1; break;
case J9BCaastore: storeArrayElement(TR::Address); _bcIndex += 1; break;
case J9BCbastore: genUnary(TR::i2b); storeArrayElement(TR::Int8); _bcIndex += 1; break;
case J9BCcastore: genUnary(TR::i2s); storeArrayElement(TR::Int16);_bcIndex += 1; break;
case J9BCsastore: genUnary(TR::i2s); storeArrayElement(TR::Int16); _bcIndex += 1; break;
case J9BCistorew: storeAuto(TR::Int32, next2Bytes()); _bcIndex += 3; break;
case J9BClstorew: storeAuto(TR::Int64, next2Bytes()); _bcIndex += 3; break;
case J9BCfstorew: storeAuto(TR::Float, next2Bytes()); _bcIndex += 3; break;
case J9BCdstorew: storeAuto(TR::Double, next2Bytes()); _bcIndex += 3; break;
case J9BCastorew: storeAuto(TR::Address, next2Bytes()); _bcIndex += 3; break;
case J9BCpop: eat1(); _bcIndex += 1; break;
case J9BCpop2: eat2(); _bcIndex += 1; break;
case J9BCdup: dup(); _bcIndex += 1; break;
case J9BCdup2: dup2(); _bcIndex += 1; break;
case J9BCdupx1: dupx1(); _bcIndex += 1; break;
case J9BCdup2x1: dup2x1(); _bcIndex += 1; break;
case J9BCdupx2: dupx2(); _bcIndex += 1; break;
case J9BCdup2x2: dup2x2(); _bcIndex += 1; break;
case J9BCswap: swap(); _bcIndex += 1; break;
case J9BCiadd: genBinary(TR::iadd); _bcIndex += 1; break;
case J9BCladd: genBinary(TR::ladd); _bcIndex += 1; break;
case J9BCfadd: genBinary(TR::fadd); _bcIndex += 1; break;
case J9BCdadd: genBinary(TR::dadd); _bcIndex += 1; break;
case J9BCisub: genBinary(TR::isub); _bcIndex += 1; break;
case J9BClsub: genBinary(TR::lsub); _bcIndex += 1; break;
case J9BCfsub: genBinary(TR::fsub); _bcIndex += 1; break;
case J9BCdsub: genBinary(TR::dsub); _bcIndex += 1; break;
case J9BCimul: genBinary(TR::imul); _bcIndex += 1; break;
case J9BClmul: genBinary(TR::lmul); _bcIndex += 1; break;
case J9BCfmul: genBinary(TR::fmul); _bcIndex += 1; break;
case J9BCdmul: genBinary(TR::dmul); _bcIndex += 1; break;
case J9BCidiv: genIDiv(); _bcIndex += 1; break;
case J9BCldiv: genLDiv(); _bcIndex += 1; break;
case J9BCirem: genIRem(); _bcIndex += 1; break;
case J9BClrem: genLRem(); _bcIndex += 1; break;
case J9BCfdiv: genBinary(TR::fdiv); _bcIndex += 1; break;
case J9BCddiv: genBinary(TR::ddiv); _bcIndex += 1; break;
case J9BCfrem: genBinary(TR::frem); _bcIndex += 1; break;
case J9BCdrem: genBinary(TR::drem); _bcIndex += 1; break;
case J9BCineg: genUnary(TR::ineg); _bcIndex += 1; break;
case J9BClneg: genUnary(TR::lneg); _bcIndex += 1; break;
case J9BCfneg: genUnary(TR::fneg); _bcIndex += 1; break;
case J9BCdneg: genUnary(TR::dneg); _bcIndex += 1; break;
case J9BCishl: genBinary(TR::ishl); _bcIndex += 1; break;
case J9BCishr: genBinary(TR::ishr); _bcIndex += 1; break;
case J9BCiushr: genBinary(TR::iushr); _bcIndex += 1; break;
case J9BClshl: genBinary(TR::lshl); _bcIndex += 1; break;
case J9BClshr: genBinary(TR::lshr); _bcIndex += 1; break;
case J9BClushr: genBinary(TR::lushr); _bcIndex += 1; break;
case J9BCiand: genBinary(TR::iand); _bcIndex += 1; break;
case J9BCior: genBinary(TR::ior); _bcIndex += 1; break;
case J9BCixor: genBinary(TR::ixor); _bcIndex += 1; break;
case J9BCland: genBinary(TR::land); _bcIndex += 1; break;
case J9BClor: genBinary(TR::lor); _bcIndex += 1; break;
case J9BClxor: genBinary(TR::lxor); _bcIndex += 1; break;
case J9BCi2l: genUnary(TR::i2l); _bcIndex += 1; break;
case J9BCi2f: genUnary(TR::i2f); _bcIndex += 1; break;
case J9BCi2d: genUnary(TR::i2d); _bcIndex += 1; break;
case J9BCl2i: genUnary(TR::l2i); _bcIndex += 1; break;
case J9BCl2f: genUnary(TR::l2f); _bcIndex += 1; break;
case J9BCl2d: genUnary(TR::l2d); _bcIndex += 1; break;
case J9BCf2i: genUnary(TR::f2i); _bcIndex += 1; break;
case J9BCf2d: genUnary(TR::f2d); _bcIndex += 1; break;
case J9BCd2i: genUnary(TR::d2i); _bcIndex += 1; break;
case J9BCd2f: genUnary(TR::d2f); _bcIndex += 1; break;
case J9BCf2l: genUnary(TR::f2l); _bcIndex += 1; break;
case J9BCd2l: genUnary(TR::d2l); _bcIndex += 1; break;
case J9BCi2b: genUnary(TR::i2b); genUnary(TR::b2i); _bcIndex += 1; break;
case J9BCi2c: genUnary(TR::i2s); genUnary(TR::su2i); _bcIndex += 1; break;
case J9BCi2s: genUnary(TR::i2s); genUnary(TR::s2i); _bcIndex += 1; break;
case J9BCinvokevirtual: genInvokeVirtual(next2Bytes()); _bcIndex += 3; break;
case J9BCinvokespecial: genInvokeSpecial(next2Bytes()); _bcIndex += 3; break;
case J9BCinvokestatic: genInvokeStatic(next2Bytes()); _bcIndex += 3; break;
case J9BCinvokeinterface: genInvokeInterface(next2Bytes()); _bcIndex += 3; break;
case J9BCinvokedynamic:
genInvokeDynamic(next2Bytes());
_bcIndex += 3; break; // Could eventually need next3bytes
case J9BCinvokehandle:
genInvokeHandle(next2Bytes());
_bcIndex += 3; break;
case J9BCinvokehandlegeneric:
genInvokeHandleGeneric(next2Bytes());
_bcIndex += 3; break;
case J9BCinvokespecialsplit: genInvokeSpecial(next2Bytes() | J9_SPECIAL_SPLIT_TABLE_INDEX_FLAG); _bcIndex += 3; break;
case J9BCinvokestaticsplit: genInvokeStatic(next2Bytes() | J9_STATIC_SPLIT_TABLE_INDEX_FLAG); _bcIndex += 3; break;
case J9BCifeq: _bcIndex = genIfOneOperand(TR::ificmpeq); break;
case J9BCifne: _bcIndex = genIfOneOperand(TR::ificmpne); break;
case J9BCiflt: _bcIndex = genIfOneOperand(TR::ificmplt); break;
case J9BCifge: _bcIndex = genIfOneOperand(TR::ificmpge); break;
case J9BCifgt: _bcIndex = genIfOneOperand(TR::ificmpgt); break;
case J9BCifle: _bcIndex = genIfOneOperand(TR::ificmple); break;
case J9BCifnull: _bcIndex = genIfOneOperand(TR::ifacmpeq); break;
case J9BCifnonnull: _bcIndex = genIfOneOperand(TR::ifacmpne); break;
case J9BCificmpeq: _bcIndex = genIfTwoOperand(TR::ificmpeq); break;
case J9BCificmpne: _bcIndex = genIfTwoOperand(TR::ificmpne); break;
case J9BCificmplt: _bcIndex = genIfTwoOperand(TR::ificmplt); break;
case J9BCificmpge: _bcIndex = genIfTwoOperand(TR::ificmpge); break;
case J9BCificmpgt: _bcIndex = genIfTwoOperand(TR::ificmpgt); break;
case J9BCificmple: _bcIndex = genIfTwoOperand(TR::ificmple); break;
case J9BCifacmpeq: _bcIndex = genIfAcmpEqNe(TR::ifacmpeq); break;
case J9BCifacmpne: _bcIndex = genIfAcmpEqNe(TR::ifacmpne); break;
case J9BClcmp: _bcIndex = cmp(TR::lcmp, _lcmpOps, lastIndex); break;
case J9BCfcmpl: _bcIndex = cmp(TR::fcmpl, _fcmplOps, lastIndex); break;
case J9BCfcmpg: _bcIndex = cmp(TR::fcmpg, _fcmpgOps, lastIndex); break;
case J9BCdcmpl: _bcIndex = cmp(TR::dcmpl, _dcmplOps, lastIndex); break;
case J9BCdcmpg: _bcIndex = cmp(TR::dcmpg, _dcmpgOps, lastIndex); break;
case J9BCtableswitch: _bcIndex = genTableSwitch (); break;
case J9BClookupswitch: _bcIndex = genLookupSwitch(); break;
case J9BCgoto: _bcIndex = genGoto(_bcIndex + next2BytesSigned()); break;
case J9BCgotow: _bcIndex = genGoto(_bcIndex + next4BytesSigned()); break;
case J9BCmonitorenter: genMonitorEnter(); _bcIndex += 1; break;
case J9BCmonitorexit: genMonitorExit(false); _bcIndex += 1; break;
case J9BCathrow: _bcIndex = genAThrow(); break;
case J9BCarraylength: genArrayLength(); _bcIndex += 1; break;
case J9BCgetstatic: loadStatic(next2Bytes()); _bcIndex += 3; break;
case J9BCgetfield: loadInstance(next2Bytes()); _bcIndex += 3; break;
case J9BCputstatic: storeStatic(next2Bytes()); _bcIndex += 3; break;
case J9BCputfield: storeInstance(next2Bytes()); _bcIndex += 3; break;
case J9BCcheckcast: genCheckCast(next2Bytes()); _bcIndex += 3; break;
case J9BCinstanceof: genInstanceof(next2Bytes()); _bcIndex += 3; break;
case J9BCnew: genNew(next2Bytes()); _bcIndex += 3; break;
case J9BCnewarray: genNewArray(nextByte()); _bcIndex += 2; break;
case J9BCanewarray: genANewArray(next2Bytes()); _bcIndex += 3; break;
case J9BCmultianewarray: genMultiANewArray(next2Bytes(), _code[_bcIndex+3]); _bcIndex += 4; break;
case J9BCiinc: genInc(); _bcIndex += 3; break;
case J9BCiincw: genIncLong(); _bcIndex += 5; break;
case J9BCwide:
{
int32_t wopcode = _code[++_bcIndex];
TR_J9ByteCode wbc = convertOpCodeToByteCodeEnum(wopcode);
if (_bcIndex > lastIndex)
lastIndex = _bcIndex;
if (wbc == J9BCiinc)
{ genIncLong(); _bcIndex += 5; break; }
switch (wbc)
{
case J9BCiload: loadAuto(TR::Int32, next2Bytes()); break;
case J9BClload: loadAuto(TR::Int64, next2Bytes()); break;
case J9BCfload: loadAuto(TR::Float, next2Bytes()); break;
case J9BCdload: loadAuto(TR::Double, next2Bytes()); break;
case J9BCaload: loadAuto(TR::Address, next2Bytes()); break;
case J9BCistore: storeAuto(TR::Int32, next2Bytes()); break;
case J9BClstore: storeAuto(TR::Int64, next2Bytes()); break;
case J9BCfstore: storeAuto(TR::Float, next2Bytes()); break;
case J9BCdstore: storeAuto(TR::Double, next2Bytes()); break;
case J9BCastore: storeAuto(TR::Address, next2Bytes()); break;
default: break;
}
_bcIndex += 3;
break;
}
case J9BCgenericReturn:
case J9BCReturnC:
case J9BCReturnS:
case J9BCReturnB:
case J9BCReturnZ:
_bcIndex = genReturn(method()->returnOpCode(), method()->isSynchronized());
break;
case J9BCaconst_init:
{
if (TR::Compiler->om.areValueTypesEnabled())
{
genAconst_init(next2Bytes());
_bcIndex += 3;
}
else
{
fej9()->unsupportedByteCode(comp(), opcode);
}
break;
}
case J9BCwithfield:
if (TR::Compiler->om.areValueTypesEnabled())
{
genWithField(next2Bytes());
_bcIndex += 3;
}
else
{
fej9()->unsupportedByteCode(comp(), opcode);
}
break;
case J9BCbreakpoint:
fej9()->unsupportedByteCode(comp(), opcode);
case J9BCunknown:
fej9()->unknownByteCode(comp(), opcode);
break;
default:
break;
}
if (comp()->getOption(TR_TraceILGen))
{
TR::StackMemoryRegion stackMemoryRegion(*comp()->trMemory());
TR_BitVector beforeTreesInserted(comp()->getNodeCount(), trMemory(), stackAlloc, growable);
TR_BitVector afterTreesInserted (comp()->getNodeCount(), trMemory(), stackAlloc, growable);
comp()->getDebug()->saveNodeChecklist(beforeTreesInserted);
printTrees(comp(), traceStart->getNextTreeTop(), traceStop, "trees inserted");
comp()->getDebug()->saveNodeChecklist(afterTreesInserted);
// Commoning in the "stack after" printout should match that in the
// "trees inserted" printout.
//
// NOTE: this is disabled because it prints (potentially large) trees
// twice for no particular benefit. Instead, we have opted to have
// the "stack after" printout appear to be "commoned" with the "trees
// inserted" printout. This might cause some minor confusion when the
// "stack after" section contains nodes with refcount=1 that appear to
// be commoned, but this overall clarity seems to favour the terser format.
//
//comp()->getDebug()->restoreNodeChecklist(beforeTreesInserted);
printStack(comp(), _stack, "stack after");
traceMsg(comp(), " ============================================================\n");
// Commoning from now on will reflect trees already inserted, not
// those that happened to appear on the stack. (The desirability
// of the resulting verbosity is debatable.)
//
comp()->getDebug()->restoreNodeChecklist(afterTreesInserted);
}
}
if( _blocksToInline) // partial inlining - only generate goto if its in the list of blocks.
{
if(_blocksToInline->getHighestBCIndex() > lastIndex)
{
lastIndex = _blocksToInline->getHighestBCIndex();
//printf("Walker: setting lastIndex to %d\n",lastIndex);
}
if(_blocksToInline->getLowestBCIndex() < firstIndex)
{
firstIndex = _blocksToInline->getLowestBCIndex();
//printf("Walker: setting firstIndex to %d\n",firstIndex);
}
}
// join the basic blocks
//
TR::Block * lastBlock = NULL, * nextBlock, * block = blocks(firstIndex);
if (firstIndex == 0)
cfg()->addEdge(cfg()->getStart(), block);
else
prevBlock->getExit()->join(block->getEntry());
for (i = firstIndex; block; lastBlock = block, block = nextBlock)
{
while (block->getNextBlock())
{
TR_ASSERT( block->isAdded(), "Block should have already been added\n" );
block = block->getNextBlock();
}
block->setIsAdded();
for (nextBlock = 0; !nextBlock && ++i <= lastIndex; )
if (isGenerated(i) && blocks(i) && !blocks(i)->isAdded())
nextBlock = blocks(i);
// If an exception range ends with an if and the fall through is
// in the main-line code then we have to generate a fall through block
// which contains a goto to jump back to the main-line code.
//
TR::Node * lastRealNode = block->getLastRealTreeTop()->getNode();
if (!nextBlock && lastRealNode->getOpCode().isIf())
{
nextBlock = TR::Block::createEmptyBlock(comp());
i = lastIndex;
if(_blocksToInline)
{
if(!blocks(i+3))
{
TR_ASSERT(_blocksToInline->hasGeneratedRestartTree(),"Fall Thru Block doesn't exist and we don't have a restart tree.\n");
nextBlock->append(
TR::TreeTop::create(comp(),
TR::Node::create(lastRealNode, TR::Goto, 0, _blocksToInline->getGeneratedRestartTree())));
}
else
{
nextBlock->append(
TR::TreeTop::create(comp(),
TR::Node::create(lastRealNode, TR::Goto, 0, blocks(i + 3)->getEntry())));
}
}
else
{
TR_ASSERT(blocks(i + 3), "can't find the fall thru block");
nextBlock->append(
TR::TreeTop::create(comp(),
TR::Node::create(lastRealNode, TR::Goto, 0, blocks(i + 3)->getEntry())));
}
}
block->getExit()->getNode()->copyByteCodeInfo(lastRealNode);
cfg()->insertBefore(block, nextBlock);
}
if(_blocksToInline && _blocksToInline->hasGeneratedRestartTree())
{
_blocksToInline->getGeneratedRestartTree()->getEnclosingBlock()->setIsCold();
_blocksToInline->getGeneratedRestartTree()->getEnclosingBlock()->setFrequency(1);
}
return lastBlock;
}
//----------------------------------------------
// walker helper routines
//----------------------------------------------
int32_t
TR_J9ByteCodeIlGenerator::cmp(TR::ILOpCodes cmpOpcode, TR::ILOpCodes * combinedOpcodes, int32_t & lastIndex)
{
int32_t nextBCIndex = _bcIndex + 1;
uint8_t nextOpcode = _code[nextBCIndex];
// can't generate the async check here if someone is jumping to it
//
if (convertOpCodeToByteCodeEnum(nextOpcode) == J9BCasyncCheck && blocks(nextBCIndex) == 0)
{
genAsyncCheck();
nextBCIndex = ++_bcIndex + 1;
nextOpcode = _code[nextBCIndex];
if (_bcIndex > lastIndex)
lastIndex = _bcIndex;
}
TR::ILOpCodes combinedOpcode;
switch (convertOpCodeToByteCodeEnum(nextOpcode))
{
case J9BCifeq: combinedOpcode = combinedOpcodes[0]; break;
case J9BCifne: combinedOpcode = combinedOpcodes[1]; break;
case J9BCiflt: combinedOpcode = combinedOpcodes[2]; break;
case J9BCifge: combinedOpcode = combinedOpcodes[3]; break;
case J9BCifgt: combinedOpcode = combinedOpcodes[4]; break;
case J9BCifle: combinedOpcode = combinedOpcodes[5]; break;
default: combinedOpcode = TR::BadILOp; break;
}
// don't combine the opcodes if someone is jumping to the if
//
if (combinedOpcode != TR::BadILOp && blocks(nextBCIndex) == 0)
return cmpFollowedByIf(nextOpcode, combinedOpcode, lastIndex);
genBinary(cmpOpcode);
genUnary(TR::b2i);
return _bcIndex + 1;
}
int32_t
TR_J9ByteCodeIlGenerator::cmpFollowedByIf(uint8_t ifOpcode, TR::ILOpCodes combinedOpcode, int32_t & lastIndex)
{
int32_t branchOffset = next2BytesSigned(2); // The 2 bytes after the compare bytecode is the branch offset
// If asynccheck is needed, generate it before incrementing _bcIndex such that it has the bytecode index of
// the compare bytecode.
if (branchOffset <= 0)
{
genAsyncCheck();
}
if (++_bcIndex > lastIndex)
lastIndex = _bcIndex;
return genIfImpl(combinedOpcode);
}
//----------------------------------------------
// gen helper routines
//----------------------------------------------
TR::SymbolReference *
TR_J9ByteCodeIlGenerator::placeholderWithDummySignature()
{
// Note: signatures should always be correct. Only call this to pass the
// result to something like genNodeAndPopChildren which will expand the
// signature properly.
if (comp()->getOption(TR_TraceMethodIndex))
traceMsg(comp(), "placeholderWithDummySignature using owning symbol M%p _methodSymbol: M%p\n", comp()->getJittedMethodSymbol(), _methodSymbol);
// Note that we use comp()->getJittedMethodSymbol() instead of _methodSymbol here.
// The caller doesn't matter for this special method, and there's no need to make
// potentially hundreds of symbols for the same method.
//
return comp()->getSymRefTab()->methodSymRefFromName(comp()->getJittedMethodSymbol(), JSR292_ILGenMacros, JSR292_placeholder, JSR292_placeholderSig, TR::MethodSymbol::Static);
}
TR::SymbolReference *
TR_J9ByteCodeIlGenerator::placeholderWithSignature(const char *prefix, int prefixLength, const char *middle, int middleLength, const char *suffix, int suffixLength)
{
return symRefWithArtificialSignature(placeholderWithDummySignature(),
".#.#.#",
prefix, prefixLength,
middle, middleLength,
suffix, suffixLength);
}
TR::SymbolReference *
TR_J9ByteCodeIlGenerator::symRefWithArtificialSignature(TR::SymbolReference *original, const char *effectiveSigFormat, ...)
{
TR::StackMemoryRegion stackMemoryRegion(*comp()->trMemory());
va_list args;
va_start(args, effectiveSigFormat);
char *effectiveSig = vartificialSignature(stackAlloc, effectiveSigFormat, args);
va_end(args);
TR::SymbolReference *result = comp()->getSymRefTab()->methodSymRefWithSignature(original, effectiveSig, strlen(effectiveSig));
return result;
}
static int32_t processArtificialSignature(char *result, const char *format, va_list args)
{
int32_t resultLength = 0;
char *cur = result;
for (int32_t i = 0; format[i]; i++)
{
int32_t length = -1;
const char *startChar = NULL;
if (format[i] == '.') // period is the ONLY character (besides null) that can never appear in a method signature
{
// Formatting code
switch (format[++i])
{
case '@': // insert a single given arg out of a given signature
{
char *sig = va_arg(args, char*);
int n = va_arg(args, int);
startChar = nthSignatureArgument(n, sig+1);
length = nextSignatureArgument(startChar) - startChar;
break;
}
case '-': // insert a given range of args out of a given signature
{
char *sig = va_arg(args, char*);
int firstN = va_arg(args, int);
int lastN = va_arg(args, int);
if (lastN >= firstN)
{
startChar = nthSignatureArgument(firstN, sig+1);
length = nthSignatureArgument(lastN+1, sig+1) - startChar;
}
else
{
startChar = "";
length = 0;
}
break;
}
case '*': // insert args from a given one onward, out of a given signature
{
char *sig = va_arg(args, char*);
int firstN = va_arg(args, int);
startChar = nthSignatureArgument(firstN, sig+1);
length = strchr(startChar, ')') - startChar;
break;
}
case '$': // insert return type from a given signature
{
char *sig = va_arg(args, char*);
startChar = strchr(sig, ')') + 1;
length = nextSignatureArgument(startChar) - startChar;
break;
}
case '?': // insert a given null-terminated string
{
startChar = va_arg(args, char*);
length = strlen(startChar);
break;
}
case '#': // insert a given number of characters out of a given string
{
startChar = va_arg(args, char*);
length = va_arg(args, int);
break;
}
default: // literal character
TR_ASSERT(0, "Unexpected artificial signature formatting character '%c'", format[i]);
// If we reach this point, either TR has a bug, or we have actually somehow
// encountered a signature that legitimately had a period in it. In the latter
// case, proceed on the assumption that the period was a literal character;
// if TR has a bug, we will very likely crash soon enough anyway.
//
startChar = format + i - 1; // back up to the period
length = 2;
break;
}
}
else
{
// Literal character
startChar = format + i;
length = 1;
}
TR_ASSERT(length >= 0, "assertion failure");
TR_ASSERT(startChar != NULL, "assertion failure");
resultLength += length;
if (result)
cur += sprintf(cur, "%.*s", length, startChar);
}
return resultLength;
}
char *TR_J9ByteCodeIlGenerator::artificialSignature(TR_AllocationKind allocKind, const char *format, ...)
{
va_list args;
va_start(args, format);
char *result = vartificialSignature(allocKind, format, args);
va_end(args);
return result;
}
char *TR_J9ByteCodeIlGenerator::vartificialSignature(TR_AllocationKind allocKind, const char *format, va_list args)
{
// Compute size
//
va_list argsCopy;
va_copy(argsCopy, args);
int32_t resultLength = processArtificialSignature(NULL, format, argsCopy);
va_copy_end(argsCopy);
// Produce formatted signature
//
char *result = (char*)trMemory()->allocateMemory(resultLength+1, allocKind);
processArtificialSignature(result, format, args);
return result;
}
void
TR_J9ByteCodeIlGenerator::genArgPlaceholderCall()
{
// Create argument load nodes
//
int32_t numNodesGenerated = 0;
ListIterator<TR::ParameterSymbol> i(&_methodSymbol->getParameterList());
for (TR::ParameterSymbol *parm = i.getFirst(); parm; parm = i.getNext())
{
if (parm->getSlot() >= _argPlaceholderSlot)
{
// What a convoluted way to get a symref from a symbol...
TR::SymbolReference *symRef = _methodSymbol->getParmSymRef(parm->getSlot());
push(TR::Node::createLoad(symRef));
numNodesGenerated++;
}
}
// Create placeholder call with the proper signature
//
char *callerSignature = _methodSymbol->getResolvedMethod()->signatureChars();
char *callerExpandedArgsStart = callerSignature + _argPlaceholderSignatureOffset;
int32_t lengthOfExpandedArgs = strcspn(callerExpandedArgsStart, ")");
TR::SymbolReference *placeholderSymRef = placeholderWithSignature("(", 1, callerExpandedArgsStart, lengthOfExpandedArgs, ")I", 2);
push(genNodeAndPopChildren(TR::icall, numNodesGenerated, placeholderSymRef));
}
static bool isPlaceholderCall(TR::Node *node)
{
if (node->getOpCode().isCall() && node->getSymbol()->getResolvedMethodSymbol())
return node->getSymbol()->castToResolvedMethodSymbol()->getMandatoryRecognizedMethod() == TR::java_lang_invoke_ILGenMacros_placeholder;
else
return false;
}
int32_t
TR_J9ByteCodeIlGenerator::expandPlaceholderCall()
{
TR::Node *placeholder = pop();
TR_ASSERT(isPlaceholderCall(placeholder), "expandPlaceholderCall expects placeholder call on top of stack");
if (comp()->getOption(TR_TraceILGen))
traceMsg(comp(), " Expanding placeholder call %s\n", comp()->getDebug()->getName(placeholder->getSymbolReference()));
for (int i = 0; i < placeholder->getNumChildren(); i++)
push(placeholder->getAndDecChild(i));
return placeholder->getNumChildren()-1; // there was already 1 for the placeholder itself
}
TR::SymbolReference *
TR_J9ByteCodeIlGenerator::expandPlaceholderSignature(TR::SymbolReference *symRef, int32_t numArgs)
{
return expandPlaceholderSignature(symRef, numArgs, numArgs);
}
TR::SymbolReference *
TR_J9ByteCodeIlGenerator::expandPlaceholderSignature(TR::SymbolReference *symRef, int32_t numArgs, int32_t firstArgStackDepth)
{
if (!symRef->getSymbol()->getResolvedMethodSymbol())
return symRef;
TR_ResolvedMethod *originalMethod = symRef->getSymbol()->castToResolvedMethodSymbol()->getResolvedMethod();
int32_t firstArgStackOffset = _stack->size() - firstArgStackDepth;
int32_t currentArgSignatureOffset = 1; // skip parenthesis
for (int32_t childIndex = originalMethod->isStatic()? 0 : 1; childIndex < numArgs; childIndex++)
{
int32_t explicitArgIndex = childIndex - (originalMethod->isStatic()? 0 : 1);
TR_ResolvedMethod *symRefMethod = symRef->getSymbol()->castToResolvedMethodSymbol()->getResolvedMethod();
char *signatureChars = symRefMethod->signatureChars();
int nextArgSignatureOffset = nextSignatureArgument(signatureChars + currentArgSignatureOffset) - signatureChars;
TR_ASSERT(signatureChars[currentArgSignatureOffset] != ')', "expandPlaceholderSignature must not walk past the end of the argument portion of the signature");