-
Notifications
You must be signed in to change notification settings - Fork 748
/
Copy pathMHInterpreter.inc
2243 lines (2020 loc) · 93.3 KB
/
MHInterpreter.inc
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 2001
*
* 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 "clang_comp.h"
#include "j9cfg.h"
#include "VM_MethodHandleKinds.h"
#include "MHInterpreter.hpp"
#include "VMAccess.hpp"
#if defined(MH_TRACE)
static const char * const names[] = {
"J9_METHOD_HANDLE_KIND_BOUND",
"J9_METHOD_HANDLE_KIND_GET_FIELD",
"J9_METHOD_HANDLE_KIND_GET_STATIC_FIELD",
"J9_METHOD_HANDLE_KIND_PUT_FIELD",
"J9_METHOD_HANDLE_KIND_PUT_STATIC_FIELD",
"J9_METHOD_HANDLE_KIND_VIRTUAL",
"J9_METHOD_HANDLE_KIND_STATIC",
"J9_METHOD_HANDLE_KIND_SPECIAL",
"J9_METHOD_HANDLE_KIND_CONSTRUCTOR",
"J9_METHOD_HANDLE_KIND_INTERFACE",
"J9_METHOD_HANDLE_KIND_COLLECT",
"J9_METHOD_HANDLE_KIND_INVOKE_EXACT",
"J9_METHOD_HANDLE_KIND_INVOKE_GENERIC",
"J9_METHOD_HANDLE_KIND_ASTYPE",
"J9_METHOD_HANDLE_KIND_DYNAMIC_INVOKER",
"J9_METHOD_HANDLE_KIND_FILTER_RETURN",
"J9_METHOD_HANDLE_KIND_EXPLICITCAST",
"J9_METHOD_HANDLE_KIND_VARARGS_COLLECTOR",
"J9_METHOD_HANDLE_KIND_PASSTHROUGH",
"J9_METHOD_HANDLE_KIND_SPREAD",
"J9_METHOD_HANDLE_KIND_INSERT",
"J9_METHOD_HANDLE_KIND_PERMUTE",
"J9_METHOD_HANDLE_KIND_CONSTANT_OBJECT",
"J9_METHOD_HANDLE_KIND_CONSTANT_INT",
"J9_METHOD_HANDLE_KIND_CONSTANT_FLOAT",
"J9_METHOD_HANDLE_KIND_CONSTANT_LONG",
"J9_METHOD_HANDLE_KIND_CONSTANT_DOUBLE",
"J9_METHOD_HANDLE_KIND_FOLD_HANDLE",
"J9_METHOD_HANDLE_KIND_GUARD_WITH_TEST",
"J9_METHOD_HANDLE_KIND_FILTER_ARGUMENTS",
"J9_METHOD_HANDLE_KIND_VARHANDLE_INVOKE_EXACT",
"J9_METHOD_HANDLE_KIND_VARHANDLE_INVOKE_GENERIC"
};
#endif /* defined(MH_TRACE) */
VM_BytecodeAction
VM_MHInterpreter::dispatchLoop(j9object_t methodHandle)
{
VM_BytecodeAction nextAction = EXECUTE_BYTECODE;
J9Method *method = NULL;
while(true) {
U_32 kind = getMethodHandleKind(methodHandle);
Assert_VM_mhStackHandleMatch(doesMHandStackMHMatch(methodHandle));
#if defined(MH_TRACE)
printf("#(%p)# dispatchLoop: MH=%p\tkind=%x\t%s\n", _currentThread, methodHandle, kind, names[kind]);
#endif /* defined(MH_TRACE) */
switch(kind) {
case J9_METHOD_HANDLE_KIND_CONSTANT_OBJECT:
dropAllArgumentsLeavingMH(methodHandle);
*((j9object_t *) _currentThread->sp) = J9VMJAVALANGINVOKECONSTANTOBJECTHANDLE_VALUE(_currentThread, methodHandle);
goto returnFromSend;
case J9_METHOD_HANDLE_KIND_CONSTANT_INT:
dropAllArgumentsLeavingMH(methodHandle);
*((I_32 *) _currentThread->sp) = J9VMJAVALANGINVOKECONSTANTINTHANDLE_VALUE(_currentThread, methodHandle);
goto returnFromSend;
case J9_METHOD_HANDLE_KIND_CONSTANT_FLOAT:
dropAllArgumentsLeavingMH(methodHandle);
*((U_32 *) _currentThread->sp) = J9VMJAVALANGINVOKECONSTANTFLOATHANDLE_VALUE(_currentThread, methodHandle);
goto returnFromSend;
case J9_METHOD_HANDLE_KIND_CONSTANT_LONG:
dropAllArgumentsLeavingMH(methodHandle);
_currentThread->sp -= 1;
*((I_64 *) _currentThread->sp) = J9VMJAVALANGINVOKECONSTANTLONGHANDLE_VALUE(_currentThread, methodHandle);
goto returnFromSend;
case J9_METHOD_HANDLE_KIND_CONSTANT_DOUBLE:
dropAllArgumentsLeavingMH(methodHandle);
_currentThread->sp -= 1;
*((U_64 *) _currentThread->sp) = J9VMJAVALANGINVOKECONSTANTDOUBLEHANDLE_VALUE(_currentThread, methodHandle);
goto returnFromSend;
case J9_METHOD_HANDLE_KIND_EXPLICITCAST: /* fall through */
case J9_METHOD_HANDLE_KIND_ASTYPE:
methodHandle = convertArgumentsForAsType(methodHandle);
if (VM_VMHelpers::exceptionPending(_currentThread)) {
goto throwCurrentException;
}
break;
case J9_METHOD_HANDLE_KIND_SPREAD:
methodHandle = spreadForAsSpreader(methodHandle);
if (VM_VMHelpers::exceptionPending(_currentThread)) {
goto throwCurrentException;
}
break;
case J9_METHOD_HANDLE_KIND_PERMUTE:
methodHandle = permuteForPermuteHandle(methodHandle);
if (VM_VMHelpers::exceptionPending(_currentThread)) {
goto throwCurrentException;
}
break;
case J9_METHOD_HANDLE_KIND_INSERT:
methodHandle = insertArgumentsForInsertHandle(methodHandle);
if (VM_VMHelpers::exceptionPending(_currentThread)) {
goto throwCurrentException;
}
break;
case J9_METHOD_HANDLE_KIND_PASSTHROUGH: {
j9object_t type = getMethodHandleMethodType(methodHandle);
U_32 slotCount = getMethodTypeArgSlots(type);
methodHandle = J9VMJAVALANGINVOKEPASSTHROUGHHANDLE_EQUIVALENT(_currentThread, methodHandle);
((j9object_t *)_currentThread->sp)[slotCount] = methodHandle;
break;
}
case J9_METHOD_HANDLE_KIND_VARARGS_COLLECTOR: {
j9object_t type = getMethodHandleMethodType(methodHandle);
U_32 slotCount = getMethodTypeArgSlots(type);
methodHandle = J9VMJAVALANGINVOKEVARARGSCOLLECTORHANDLE_NEXT(_currentThread, methodHandle);
((j9object_t *)_currentThread->sp)[slotCount] = methodHandle;
break;
}
case J9_METHOD_HANDLE_KIND_STATIC: {
methodHandle = initializeClassIfNeeded(methodHandle);
if (VM_VMHelpers::exceptionPending(_currentThread)) {
goto throwCurrentException;
}
/* fall through */
}
case J9_METHOD_HANDLE_KIND_SPECIAL: {
j9object_t type = getMethodHandleMethodType(methodHandle);
U_32 slotCount = getMethodTypeArgSlots(type);
shiftStackedArguments(slotCount);
if (J9_METHOD_HANDLE_KIND_SPECIAL == kind) {
if (NULL == ((j9object_t*)_currentThread->sp)[slotCount]) {
nextAction = THROW_NPE;
goto done;
}
}
_currentThread->sp += 1;
method = (J9Method *)getVMSlot(methodHandle);
goto runMethod;
}
case J9_METHOD_HANDLE_KIND_VIRTUAL: {
j9object_t type = getMethodHandleMethodType(methodHandle);
U_32 slotCount = getMethodTypeArgSlots(type);
shiftStackedArguments(slotCount);
j9object_t receiver = ((j9object_t*)_currentThread->sp)[slotCount];
if (NULL != receiver) {
_currentThread->sp += 1;
J9Class *clazz = J9OBJECT_CLAZZ(_currentThread, receiver);
method = *(J9Method **)((UDATA)clazz + getVMSlot(methodHandle));
goto runMethod;
}
nextAction = THROW_NPE;
goto done;
}
case J9_METHOD_HANDLE_KIND_INTERFACE: {
j9object_t type = getMethodHandleMethodType(methodHandle);
U_32 slotCount = getMethodTypeArgSlots(type);
shiftStackedArguments(slotCount);
j9object_t receiver = ((j9object_t*)_currentThread->sp)[slotCount];
if (NULL != receiver) {
_currentThread->sp += 1;
J9Class *receiverClazz = J9OBJECT_CLAZZ(_currentThread, receiver);
J9Class *interfaceClazz = J9VM_J9CLASS_FROM_HEAPCLASS(_currentThread, J9VMJAVALANGINVOKEPRIMITIVEHANDLE_REFERENCECLASS(_currentThread, methodHandle));
method = convertITableIndexToVirtualMethod(receiverClazz, interfaceClazz, getVMSlot(methodHandle));
if (NULL != method) {
J9ROMMethod *romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
if (J9_ARE_NO_BITS_SET(romMethod->modifiers, J9AccPublic)) {
prepareForExceptionThrow(_currentThread);
setIllegalAccessErrorNonPublicInvokeInterface(_currentThread, method);
goto throwCurrentException;
}
goto runMethod;
}
prepareForExceptionThrow(_currentThread);
setCurrentExceptionUTF(_currentThread, J9VMCONSTANTPOOL_JAVALANGINCOMPATIBLECLASSCHANGEERROR, NULL);
goto throwCurrentException;
}
nextAction = THROW_NPE;
goto done;
}
case J9_METHOD_HANDLE_KIND_BOUND: {
j9object_t type = getMethodHandleMethodType(methodHandle);
U_32 slotCount = getMethodTypeArgSlots(type);
j9object_t receiver = J9VMJAVALANGINVOKERECEIVERBOUNDHANDLE_RECEIVER(_currentThread, methodHandle);
U_32 modifiers = getPrimitiveHandleModifiers(methodHandle);
method = (J9Method*)getVMSlot(methodHandle);
if (J9AccStatic != (modifiers & J9AccStatic)) {
if (NULL == receiver) {
nextAction = THROW_NPE;
goto done;
}
}
((j9object_t*)_currentThread->sp)[slotCount] = receiver;
goto runMethod;
}
case J9_METHOD_HANDLE_KIND_DYNAMIC_INVOKER: {
j9object_t type = getMethodHandleMethodType(methodHandle);
U_32 slotCount = getMethodTypeArgSlots(type);
j9object_t callsite = J9VMJAVALANGINVOKEDYNAMICINVOKERHANDLE_SITE(_currentThread, methodHandle);
if (isVolatileCallsite(callsite)) {
methodHandle = J9VMJAVALANGINVOKEVOLATILECALLSITE_TARGET(_currentThread, callsite);
VM_AtomicSupport::readBarrier();
} else {
methodHandle = J9VMJAVALANGINVOKEMUTABLECALLSITE_TARGET(_currentThread, callsite);
/* MutableCallSite.target is currently volatile - therefore readbarrier required */
VM_AtomicSupport::readBarrier();
}
((j9object_t*)_currentThread->sp)[slotCount] = methodHandle;
break;
}
case J9_METHOD_HANDLE_KIND_INVOKE_EXACT: {
j9object_t type = getMethodHandleMethodType(methodHandle);
U_32 slotCount = getMethodTypeArgSlots(type);
shiftStackedArguments(slotCount);
j9object_t receiver = ((j9object_t*)_currentThread->sp)[slotCount];
_currentThread->sp += 1;
if (NULL != receiver) {
j9object_t nextType = J9VMJAVALANGINVOKEINVOKEEXACTHANDLE_NEXTTYPE(_currentThread, methodHandle);
j9object_t receiverType = getMethodHandleMethodType(receiver);
if (receiverType == nextType) {
methodHandle = receiver;
break;
}
nextAction = THROW_WRONG_METHOD_TYPE;
} else {
/* receiver == null */
nextAction = THROW_NPE;
}
goto done;
}
case J9_METHOD_HANDLE_KIND_INVOKE_GENERIC: {
methodHandle = doInvokeGeneric(methodHandle);
if (VM_VMHelpers::exceptionPending(_currentThread)) {
goto throwCurrentException;
} else if (NULL == methodHandle) {
nextAction = THROW_NPE;
goto done;
}
break;
}
case J9_METHOD_HANDLE_KIND_FILTER_RETURN: {
j9object_t type = getMethodHandleMethodType(methodHandle);
U_32 slotCount = getMethodTypeArgSlots(type);
j9object_t returnFilter = J9VMJAVALANGINVOKEFILTERRETURNHANDLE_FILTER(_currentThread, methodHandle);
insertPlaceHolderFrame(slotCount, returnFilter, J9VMJAVALANGINVOKEMETHODHANDLE_RETURNFILTERPLACEHOLDER_METHOD(_vm));
methodHandle = J9VMJAVALANGINVOKECONVERTHANDLE_NEXT(_currentThread, methodHandle);
((j9object_t *)_currentThread->sp)[slotCount] = methodHandle;
break;
}
case J9_METHOD_HANDLE_KIND_FOLD_HANDLE: {
methodHandle = foldForFoldArguments(methodHandle);
if (VM_VMHelpers::exceptionPending(_currentThread)) {
goto throwCurrentException;
}
break;
}
case J9_METHOD_HANDLE_KIND_GUARD_WITH_TEST: {
/* Get GWT_Handle.type and GWT_Handle.type.argSlots (GWT - GuardWithTest) */
/* [... GWT_Handle args] */
j9object_t guardType = getMethodHandleMethodType(methodHandle);
U_32 guardArgSlots = getMethodTypeArgSlots(guardType);
/* [... GWT_Handle args descriptionBytes MethodTypeFrame] */
UDATA *spPriorToFrameBuild = _currentThread->sp;
(void)buildMethodTypeFrame(_currentThread, guardType);
/* [... GWT_Handle args descriptionBytes MethodTypeFrame GWT_Handle args] */
_currentThread->sp -= (guardArgSlots + 1);
memcpy(_currentThread->sp, spPriorToFrameBuild, sizeof(UDATA) * (guardArgSlots+1));
/* [... GWT_Handle args descriptionBytes MethodTypeFrame GWT_Handle PlaceHolderFrame GWT_Handle args] */
insertPlaceHolderFrame(guardArgSlots, methodHandle, J9VMJAVALANGINVOKEMETHODHANDLE_GUARDWITHTESTPLACEHOLDER_METHOD(_vm));
/* Get GWT_Handle.guard (testHandle), testHandle.type and testHandle.type.argSlots */
methodHandle = J9VMJAVALANGINVOKEGUARDWITHTESTHANDLE_GUARD(_currentThread, methodHandle);
j9object_t testType = getMethodHandleMethodType(methodHandle);
U_32 testArgSlots = getMethodTypeArgSlots(testType);
/* Replace GWT_Handle with testHandle and adjust sp according to testHandle.type.argSlots */
/* [... GWT_Handle args descriptionBytes MethodTypeFrame GWT_Handle PlaceHolderFrame testHandle args] */
((j9object_t *)_currentThread->sp)[guardArgSlots] = methodHandle;
_currentThread->sp += (guardArgSlots - testArgSlots);
break;
}
case J9_METHOD_HANDLE_KIND_FILTER_ARGUMENTS: {
/* Get FAH.type and FAH.type.argSlots [FAH (parent) - FilterArgumentsHandle] */
/* [... FAH args] */
j9object_t parentHandle = methodHandle;
j9object_t parentType = getMethodHandleMethodType(methodHandle);
j9object_t filters = J9VMJAVALANGINVOKEFILTERARGUMENTSHANDLE_FILTERS(_currentThread, methodHandle);
U_32 filtersLength = J9INDEXABLEOBJECT_SIZE(_currentThread, filters);
U_32 startPosition = (U_32) J9VMJAVALANGINVOKEFILTERARGUMENTSHANDLE_STARTPOS(_currentThread, methodHandle);
methodHandle = J9VMJAVALANGINVOKEFILTERARGUMENTSHANDLE_NEXT(_currentThread, methodHandle);
j9object_t nextType = getMethodHandleMethodType(methodHandle);
U_32 nextArgSlots = getMethodTypeArgSlots(nextType);
/* Check if there are filters to be applied */
Assert_VM_true(filtersLength > 0);
/* [... FAH args MTFrame] (MTFrame - descriptionBytes + MethodTypeFrame) */
(void)buildMethodTypeFrame(_currentThread, parentType);
/* [... FAH args MTFrame FAH.next UpdatedArgs] */
UDATA *nextPtr = _currentThread->sp - 1; /* Store pointer to FAH.next */
_currentThread->sp -= (nextArgSlots + 1);
((j9object_t *)_currentThread->sp)[nextArgSlots] = methodHandle;
memset(_currentThread->sp, 0, nextArgSlots * sizeof(UDATA *));
/* [... FAH args MTFrame FAH.next UpdatedArgs MTFrame] */
J9SFMethodTypeFrame *frameNext = buildMethodTypeFrame(_currentThread, nextType);
/* [... FAH args MTFrame FAH.next UpdatedArgs MTFrame FAH index parentOffset nextOffset PlaceHolderFrame FAH] */
_currentThread->sp -= 1;
insertFourArgumentPlaceHolderFrame(0, parentHandle, 0, 0, 0, J9VMJAVALANGINVOKEMETHODHANDLE_FILTERARGUMENTSPLACEHOLDER_METHOD(_vm));
/* Accessing FAH.type.arguments[] and its attributes for future operations */
j9object_t parentTypeArguments = J9VMJAVALANGINVOKEMETHODTYPE_PTYPES(_currentThread, parentType);
UDATA *parentPtr = UNTAGGED_A0(frameNext); /* Store pointer to parent */
/* Copy identical args between parent and next */
J9Class *currentClass = NULL;
U_32 offset = 0;
for (U_32 i = 0; i < startPosition; i++) {
currentClass = J9VM_J9CLASS_FROM_HEAPCLASS(_currentThread, J9JAVAARRAYOFOBJECT_LOAD(_currentThread, parentTypeArguments, i));
*--nextPtr = *--parentPtr;
offset += 1;
if ((_vm->doubleReflectClass == currentClass) || (_vm->longReflectClass == currentClass)) {
*--nextPtr = *--parentPtr;
offset += 1;
}
}
UDATA *offsetPtr = _currentThread->arg0EA - 2; /* Pointer to parentOffset */
*(U_32 *)(offsetPtr - 1) = offset; /* Update nextOffset */
/* [... FAH args MTFrame FAH.next UpdatedArgs MTFrame FAH index parentOffset nextOffset PlaceHolderFrame FAH.filters[0] arg] */
J9Class *startClass = J9VM_J9CLASS_FROM_HEAPCLASS(_currentThread, J9JAVAARRAYOFOBJECT_LOAD(_currentThread, parentTypeArguments, startPosition));
methodHandle = J9JAVAARRAYOFOBJECT_LOAD(_currentThread, filters, 0);
*(j9object_t *)_currentThread->sp = methodHandle;
*--(_currentThread->sp) = *--parentPtr;
offset += 1;
if ((_vm->doubleReflectClass == startClass) || (_vm->longReflectClass == startClass)) {
*--(_currentThread->sp) = *--parentPtr;
offset += 1;
}
*(U_32 *) offsetPtr = offset; /* Update parentOffset */
break;
}
case J9_METHOD_HANDLE_KIND_CONSTRUCTOR: {
methodHandle = initializeClassIfNeeded(methodHandle);
if (VM_VMHelpers::exceptionPending(_currentThread)) {
goto throwCurrentException;
}
j9object_t type = getMethodHandleMethodType(methodHandle);
U_32 slotCount = getMethodTypeArgSlots(type);
J9Class *allocateClass = J9VM_J9CLASS_FROM_HEAPCLASS(
_currentThread,
J9VMJAVALANGINVOKEPRIMITIVEHANDLE_REFERENCECLASS(_currentThread, methodHandle));
method = (J9Method*)getVMSlot(methodHandle);
j9object_t newObject = _objectAllocate->inlineAllocateObject(_currentThread, allocateClass);
if (NULL == newObject) {
UDATA *spPriorToFrameBuild = _currentThread->sp;
J9SFMethodTypeFrame * frame = buildMethodTypeFrame(_currentThread, type);
newObject = _vm->memoryManagerFunctions->J9AllocateObject(
_currentThread,
allocateClass,
J9_GC_ALLOCATE_OBJECT_NON_INSTRUMENTABLE);
if (NULL == newObject) {
goto throwHeapOOM;
}
restoreMethodTypeFrame(frame, spPriorToFrameBuild);
}
insertPlaceHolderFrame(slotCount, newObject, J9VMJAVALANGINVOKEMETHODHANDLERESOLVER_CONSTRUCTORPLACEHOLDER_METHOD(_vm));
goto runMethod;
}
case J9_METHOD_HANDLE_KIND_GET_FIELD: {
UDATA const objectHeaderSize = J9VMTHREAD_OBJECT_HEADER_SIZE(_currentThread);
j9object_t type = getMethodHandleMethodType(methodHandle);
UDATA fieldOffset = getVMSlot(methodHandle);
J9Class *fieldClass = getMethodTypeReturnClass(type);
U_32 modifiers = getPrimitiveHandleModifiers(methodHandle);
j9object_t object = *(j9object_t *)_currentThread->sp;
_currentThread->sp += 1;
if (NULL == object) {
nextAction = THROW_NPE;
goto done;
}
bool isVolatile = (J9AccVolatile == (modifiers & J9AccVolatile));
fieldOffset += objectHeaderSize;
if (J9ROMCLASS_IS_PRIMITIVE_TYPE(fieldClass->romClass)) {
if (8 == ((J9ROMReflectClass *)(fieldClass->romClass))->elementSize) {
_currentThread->sp -= 1;
*(U_64*)_currentThread->sp =
_objectAccessBarrier->inlineMixedObjectReadU64(_currentThread, object, fieldOffset, isVolatile);
} else {
*(U_32*)_currentThread->sp =
_objectAccessBarrier->inlineMixedObjectReadU32(_currentThread, object, fieldOffset, isVolatile);
}
} else {
*(j9object_t*)_currentThread->sp =
_objectAccessBarrier->inlineMixedObjectReadObject(_currentThread, object, fieldOffset, isVolatile);
}
goto returnFromSend;
}
case J9_METHOD_HANDLE_KIND_PUT_FIELD: {
UDATA const objectHeaderSize = J9VMTHREAD_OBJECT_HEADER_SIZE(_currentThread);
j9object_t type = getMethodHandleMethodType(methodHandle);
UDATA fieldOffset = getVMSlot(methodHandle);
/* Loading index 1 because MethodType has form: (instanceClass, fieldClass)V */
j9object_t fieldClassObject =
_objectAccessBarrier->inlineIndexableObjectReadObject(_currentThread, getMethodTypeArguments(type), 1);
J9Class *fieldClass = J9VM_J9CLASS_FROM_HEAPCLASS(_currentThread, fieldClassObject);
U_32 modifiers = getPrimitiveHandleModifiers(methodHandle);
fieldOffset += objectHeaderSize;
bool isVolatile = (J9AccVolatile == (modifiers & J9AccVolatile));
if (J9ROMCLASS_IS_PRIMITIVE_TYPE(fieldClass->romClass)) {
if (8 == ((J9ROMReflectClass *)(fieldClass->romClass))->elementSize) {
j9object_t objectref = *(j9object_t*)(_currentThread->sp + 2);
if (NULL == objectref) {
nextAction = THROW_NPE;
goto done;
}
_objectAccessBarrier->inlineMixedObjectStoreU64(_currentThread, objectref, fieldOffset, *(U_64*)_currentThread->sp, isVolatile);
_currentThread->sp += 3;
} else {
j9object_t objectref = *(j9object_t*)(_currentThread->sp + 1);
if (NULL == objectref) {
nextAction = THROW_NPE;
goto done;
}
U_32 value = *(U_32*)_currentThread->sp;
narrow32BitValue(fieldClass, value);
_objectAccessBarrier->inlineMixedObjectStoreU32(_currentThread, objectref, fieldOffset, value, isVolatile);
_currentThread->sp += 2;
}
} else {
j9object_t objectref = *(j9object_t*)(_currentThread->sp + 1);
if (NULL == objectref) {
nextAction = THROW_NPE;
goto done;
}
_objectAccessBarrier->inlineMixedObjectStoreObject(_currentThread, objectref, fieldOffset, *(j9object_t*)_currentThread->sp, isVolatile);
_currentThread->sp += 2;
}
_currentThread->sp += 1; /* remove MethodHandle */
goto returnFromSend;
}
case J9_METHOD_HANDLE_KIND_GET_STATIC_FIELD: {
methodHandle = initializeClassIfNeeded(methodHandle);
if (VM_VMHelpers::exceptionPending(_currentThread)) {
goto throwCurrentException;
}
J9Class* defc = getPrimitiveHandleDefc(methodHandle);
UDATA srcAddress = getVMSlot(methodHandle);
srcAddress &= ~J9_SUN_FIELD_OFFSET_MASK;
srcAddress += (UDATA)defc->ramStatics;
U_32 modifiers = getPrimitiveHandleModifiers(methodHandle);
j9object_t type = getMethodHandleMethodType(methodHandle);
J9Class *fieldClass = getMethodTypeReturnClass(type);
bool isVolatile = (J9StaticFieldRefVolatile == (modifiers & J9StaticFieldRefVolatile));
{
if (J9ROMCLASS_IS_PRIMITIVE_TYPE(fieldClass->romClass)) {
if (8 == ((J9ROMReflectClass *)(fieldClass->romClass))->elementSize) {
_currentThread->sp -=1;
*(U_64*)_currentThread->sp =
_objectAccessBarrier->inlineStaticReadU64(_currentThread, defc, (U_64 *)srcAddress, isVolatile);
} else {
*(U_32*)_currentThread->sp =
_objectAccessBarrier->inlineStaticReadU32(_currentThread, defc, (U_32*)srcAddress, isVolatile);
}
} else {
*(j9object_t*)_currentThread->sp =
_objectAccessBarrier->inlineStaticReadObject(_currentThread, defc, (j9object_t*)srcAddress, isVolatile);
}
}
goto returnFromSend;
}
case J9_METHOD_HANDLE_KIND_PUT_STATIC_FIELD: {
methodHandle = initializeClassIfNeeded(methodHandle);
if (VM_VMHelpers::exceptionPending(_currentThread)) {
goto throwCurrentException;
}
j9object_t type = getMethodHandleMethodType(methodHandle);
J9Class* defc = getPrimitiveHandleDefc(methodHandle);
UDATA srcAddress = getVMSlot(methodHandle);
srcAddress &= ~J9_SUN_FIELD_OFFSET_MASK;
srcAddress += (UDATA)defc->ramStatics;
j9object_t fieldClassObject =
J9JAVAARRAYOFOBJECT_LOAD(_currentThread, getMethodTypeArguments(type), 0);
J9Class *fieldClass = J9VM_J9CLASS_FROM_HEAPCLASS(_currentThread, fieldClassObject);
U_32 modifiers = getPrimitiveHandleModifiers(methodHandle);
bool isVolatile = (J9StaticFieldRefVolatile == (modifiers & J9StaticFieldRefVolatile));
if (J9ROMCLASS_IS_PRIMITIVE_TYPE(fieldClass->romClass)) {
if (8 == ((J9ROMReflectClass *)(fieldClass->romClass))->elementSize) {
_objectAccessBarrier->inlineStaticStoreU64(_currentThread, defc, (U_64*)srcAddress, *(U_64*)_currentThread->sp, isVolatile);
_currentThread->sp += 3;
} else {
U_32 value = *(U_32*)_currentThread->sp;
narrow32BitValue(fieldClass, value);
_objectAccessBarrier->inlineStaticStoreU32(_currentThread, defc, (U_32*)srcAddress, value, isVolatile);
_currentThread->sp += 2;
}
} else {
_objectAccessBarrier->inlineStaticStoreObject(_currentThread, defc, (j9object_t*)srcAddress, *(j9object_t*)_currentThread->sp, isVolatile);
_currentThread->sp += 2;
}
goto returnFromSend;
}
case J9_METHOD_HANDLE_KIND_COLLECT: {
BOOLEAN foundHeapOOM = FALSE;
methodHandle = collectForAsCollector(methodHandle, &foundHeapOOM);
if (foundHeapOOM) {
goto throwHeapOOM;
}
break;
}
#if defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11)
case J9_METHOD_HANDLE_KIND_VARHANDLE_INVOKE_EXACT:
/* fallthrough */
case J9_METHOD_HANDLE_KIND_VARHANDLE_INVOKE_GENERIC: {
j9object_t type = getMethodHandleMethodType(methodHandle);
U_32 slotCount = getMethodTypeArgSlots(type);
j9object_t varHandle = ((j9object_t*)_currentThread->sp)[slotCount - 1];
if (NULL == varHandle) {
nextAction = THROW_NPE;
goto done;
}
I_32 operation = J9VMJAVALANGINVOKEVARHANDLEINVOKEHANDLE_OPERATION(_currentThread, methodHandle);
/* Get MethodHandle for this operation from the VarHandle's handleTable */
j9object_t handleTable = J9VMJAVALANGINVOKEVARHANDLE_HANDLETABLE(_currentThread, varHandle);
j9object_t methodHandleFromTable = J9JAVAARRAYOFOBJECT_LOAD(_currentThread, handleTable, operation);
if (NULL == methodHandleFromTable) {
/* Building a method type (MT) frame makes the stack walkable since looking up the class below may
* cause a GC or another exception. Also, the MT frame will make it easier to debug and service the
* error as the VarHandle will be on the stack and findable with DDR. The MT frame does not need to
* be restored since throwing the exception will handle it appropriately.
*/
buildMethodTypeFrame(_currentThread, type);
prepareExceptionUsingClassName(_currentThread, "java/lang/UnsupportedOperationException");
goto throwCurrentException;
}
j9object_t handleTypeFromTable = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, methodHandleFromTable);
j9object_t accessModeType = J9VMJAVALANGINVOKEVARHANDLEINVOKEHANDLE_ACCESSMODETYPE(_currentThread, methodHandle);
if (accessModeType == handleTypeFromTable) {
methodHandle = methodHandleFromTable;
} else if (J9_METHOD_HANDLE_KIND_VARHANDLE_INVOKE_GENERIC == kind) {
UDATA * spPriorToFrameBuild = _currentThread->sp;
/* We need to do a callin to get an asType handle */
J9SFMethodTypeFrame* currentTypeFrame = buildMethodTypeFrame(_currentThread, type);
/* Convert absolute values to A0 relative offsets */
IDATA spOffset = spPriorToFrameBuild - _currentThread->arg0EA;
IDATA frameOffset = (UDATA*)currentTypeFrame - _currentThread->arg0EA;
sendForGenericInvoke(_currentThread, methodHandleFromTable, accessModeType, FALSE /* dropFirstArg */);
methodHandle = (j9object_t)_currentThread->returnValue;
if (VM_VMHelpers::exceptionPending(_currentThread)) {
goto throwCurrentException;
}
/* Convert A0 relative offsets to absolute values */
spPriorToFrameBuild = _currentThread->arg0EA + spOffset;
currentTypeFrame = (J9SFMethodTypeFrame*)(_currentThread->arg0EA + frameOffset);
/* Pop the frame */
_currentThread->literals = currentTypeFrame->savedCP;
_currentThread->pc = currentTypeFrame->savedPC;
_currentThread->arg0EA = UNTAGGED_A0(currentTypeFrame);
_currentThread->sp = spPriorToFrameBuild;
} else {
nextAction = THROW_WRONG_METHOD_TYPE;
goto done;
}
/* Get VarHandle again in case GC moved it */
varHandle = ((j9object_t*)_currentThread->sp)[slotCount - 1];
/* Remove old handle from stack */
shiftStackedArguments(slotCount);
/* Put VarHandle as last argument */
*(j9object_t*)_currentThread->sp = varHandle;
/* Interpret access mode handle */
((j9object_t*)_currentThread->sp)[slotCount] = methodHandle;
break;
}
#endif /* defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11) */
default:
Assert_VM_unreachable();
break;
}
void * compiledEntryPoint = VM_VMHelpers::methodHandleCompiledEntryPoint(_vm, _currentThread, methodHandle);
if (NULL != compiledEntryPoint) {
_currentThread->tempSlot = (UDATA)methodHandle;
_currentThread->floatTemp1 = compiledEntryPoint;
nextAction = GOTO_RUN_METHODHANDLE_COMPILED;
#if defined(MH_TRACE)
printf("#(%p)# dispatchLoop run MH %p compiled. Entrypoint = %p\n", _currentThread, methodHandle, compiledEntryPoint);
#endif /* defined(MH_TRACE) */
goto done;
}
}
runMethod: {
#if defined(MH_TRACE)
printf("#(%p)# dispatchLoop run method=%p\n", _currentThread, method);
#endif /* defined(MH_TRACE) */
_currentThread->tempSlot = (UDATA)method;
nextAction = GOTO_RUN_METHOD_FROM_METHOD_HANDLE;
goto done;
}
returnFromSend: {
nextAction = returnFromSend();
goto done;
}
throwCurrentException: {
#if defined(MH_TRACE)
printf("#(%p)# dispatchLoop throw current exception %p\n", _currentThread, _currentThread->currentException);
#endif /* defined(MH_TRACE) */
nextAction = GOTO_THROW_CURRENT_EXCEPTION;
goto done;
}
throwHeapOOM: {
#if defined(MH_TRACE)
printf("#(%p)# dispatchLoop throw heap OOM\n", _currentThread);
#endif /* defined(MH_TRACE) */
nextAction = THROW_HEAP_OOM;
goto done;
}
done:
#if defined(MH_TRACE)
printf("#(%p)# dispatchLoop done - nextAction=%d\n", _currentThread, (I_32)nextAction);
#endif /* defined(MH_TRACE) */
return nextAction;
}
VM_BytecodeAction
VM_MHInterpreter::impdep1()
{
VM_BytecodeAction rc = EXECUTE_BYTECODE;
/* NOTE: bp calculation assumes that there is only ever a single argument on the stack */
UDATA *bp = _currentThread->arg0EA - (sizeof(J9SFStackFrame)/sizeof(UDATA*));
J9SFStackFrame *frame = (J9SFStackFrame*)(bp);
if (J9VMJAVALANGINVOKEMETHODHANDLERESOLVER_CONSTRUCTORPLACEHOLDER_METHOD(_vm) == _currentThread->literals) {
/* restore frame for constructor: leave objectRef on stack & increment PC */
_currentThread->sp = _currentThread->arg0EA;
_currentThread->literals = frame->savedCP;
_currentThread->pc = frame->savedPC + 3;
_currentThread->arg0EA = UNTAGGED_A0(frame);
} else if (J9VMJAVALANGINVOKEMETHODHANDLE_RETURNFILTERPLACEHOLDER_METHOD(_vm) == _currentThread->literals) {
rc = GOTO_RUN_METHODHANDLE;
/* Get the filterHandle.type.arguments[0] to determine the kind of value on the stack */
j9object_t filterHandle = *(j9object_t*)_currentThread->arg0EA;
j9object_t filterType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, filterHandle);
j9object_t argTypes = J9VMJAVALANGINVOKEMETHODTYPE_PTYPES(_currentThread, filterType);
UDATA returnSlots = J9INDEXABLEOBJECT_SIZE(_currentThread, argTypes);
/* Determine how many slots to pop off the stack */
UDATA returnValue0 = 0;
UDATA returnValue1 = 0;
if (0 != returnSlots) {
j9object_t returnClass = _objectAccessBarrier->inlineIndexableObjectReadObject(_currentThread, argTypes, 0);
J9Class *argTypeClass = J9VM_J9CLASS_FROM_HEAPCLASS(_currentThread, returnClass);
returnSlots = 1;
returnValue0 = _currentThread->sp[0];
if ((_vm->doubleReflectClass == argTypeClass) || (_vm->longReflectClass == argTypeClass)) {
returnSlots = 2;
returnValue1 = _currentThread->sp[1];
}
}
_currentThread->sp = _currentThread->arg0EA - returnSlots;
_currentThread->literals = frame->savedCP;
_currentThread->pc = frame->savedPC;
_currentThread->arg0EA = UNTAGGED_A0(frame);
if (0 != returnSlots) {
_currentThread->sp[0] = returnValue0;
if (2 == returnSlots) {
_currentThread->sp[1] = returnValue1;
}
}
_currentThread->tempSlot = (UDATA) filterHandle;
} else if (J9VMJAVALANGINVOKEMETHODHANDLE_FOLDHANDLEPLACEHOLDER_METHOD(_vm) == _currentThread->literals) {
rc = GOTO_RUN_METHODHANDLE;
_currentThread->tempSlot = (UDATA) insertReturnValueForFoldArguments();
} else if (J9VMJAVALANGINVOKEMETHODHANDLE_GUARDWITHTESTPLACEHOLDER_METHOD(_vm) == _currentThread->literals) {
rc = GOTO_RUN_METHODHANDLE;
/* [... GWT_Handle args descriptionBytes MethodTypeFrame args GWT_Handle PlaceHolderFrame testHandleReturnValue] */
j9object_t guardHandle = *(j9object_t*)_currentThread->arg0EA;
j9object_t guardType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, guardHandle);
U_32 guardArgSlots = (U_32)J9VMJAVALANGINVOKEMETHODTYPE_ARGSLOTS(_currentThread, guardType);
/* Locally store the boolean return value from the testHandle */
I_32 testReturnValue = *(I_32*)_currentThread->sp;
/* Set local variables to restore state of the _currentThread during updateVMStruct */
UDATA *mhPtr = UNTAGGED_A0(frame);
bp = (UDATA *)(((J9SFStackFrame*)(bp+1)) + 1);
J9SFMethodTypeFrame *mtFrame = (J9SFMethodTypeFrame*)(bp);
_currentThread->literals = mtFrame->savedCP;
_currentThread->pc = mtFrame->savedPC;
_currentThread->arg0EA = UNTAGGED_A0(mtFrame);
_currentThread->sp = mhPtr - guardArgSlots;
/* Overwrite initial GWT_Handle with either GWT_Handle.trueTarget or GWT_Handle.falseTarget based upon testHandleReturnValue */
j9object_t nextHandle = NULL;
if (0 == testReturnValue) {
nextHandle = J9VMJAVALANGINVOKEGUARDWITHTESTHANDLE_FALSETARGET(_currentThread, guardHandle);
} else {
nextHandle = J9VMJAVALANGINVOKEGUARDWITHTESTHANDLE_TRUETARGET(_currentThread, guardHandle);
}
*(j9object_t*)(mhPtr) = nextHandle;
_currentThread->tempSlot = (UDATA) nextHandle;
} else if (J9VMJAVALANGINVOKEMETHODHANDLE_FILTERARGUMENTSPLACEHOLDER_METHOD(_vm) == _currentThread->literals) {
rc = GOTO_RUN_METHODHANDLE;
/* [... FAH[1] args MTFrame FAH.next UpdatedArgs MTFrame FAH[2] index parentOffset nextOffset PlaceHolderFrame filterReturnValue] */
j9object_t parentHandle = *(j9object_t *)_currentThread->arg0EA;
j9object_t parentType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, parentHandle);
j9object_t parentTypeArguments = J9VMJAVALANGINVOKEMETHODTYPE_PTYPES(_currentThread, parentType);
j9object_t filters = J9VMJAVALANGINVOKEFILTERARGUMENTSHANDLE_FILTERS(_currentThread, parentHandle);
U_32 filtersLength = J9INDEXABLEOBJECT_SIZE(_currentThread, filters);
U_32 startPosition = (U_32) J9VMJAVALANGINVOKEFILTERARGUMENTSHANDLE_STARTPOS(_currentThread, parentHandle);
j9object_t nextHandle = J9VMJAVALANGINVOKEFILTERARGUMENTSHANDLE_NEXT(_currentThread, parentHandle);
j9object_t nextType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, nextHandle);
U_32 nextArgSlots = (U_32)J9VMJAVALANGINVOKEMETHODTYPE_ARGSLOTS(_currentThread, nextType);
j9object_t nextTypeArguments = J9VMJAVALANGINVOKEMETHODTYPE_PTYPES(_currentThread, nextType);
U_32 *index = (U_32 *)(_currentThread->arg0EA - 1);
U_32 *parentOffset = (U_32 *)(_currentThread->arg0EA - 2);
U_32 *nextOffset = (U_32 *)(_currentThread->arg0EA - 3);
frame = ((J9SFStackFrame*)(_currentThread->arg0EA - 3)) - 1; /* Recalculate frame location while taking into account 4 placeHolderMethod arguments */
J9SFMethodTypeFrame *mtNextFrame = (J9SFMethodTypeFrame*)(_currentThread->arg0EA + 1);
UDATA *parentPtr = UNTAGGED_A0(mtNextFrame); /* Pointer to FAH[1] */
UDATA *nextPtr = UNTAGGED_A0(frame); /* Pointer to FAH.next */
/* Update FAH.next arguments using filterReturnValue */
J9Class *returnClass = J9VM_J9CLASS_FROM_HEAPCLASS(_currentThread, J9JAVAARRAYOFOBJECT_LOAD(_currentThread, nextTypeArguments, (startPosition + *index)));
U_32 returnArgSlots = 0;
if (_vm->voidReflectClass != returnClass) {
returnArgSlots += 1;
if ((_vm->doubleReflectClass == returnClass) || (_vm->longReflectClass == returnClass)) {
returnArgSlots += 1;
}
}
parentPtr -= *parentOffset;
*nextOffset += returnArgSlots;
nextPtr -= *nextOffset;
memmove(nextPtr, _currentThread->sp, returnArgSlots * sizeof(UDATA *));
_currentThread->sp += returnArgSlots;
/* Get the next non-null filterMH while treating intermediate null filterMHs as identity functions */
j9object_t currentFilterHandle = NULL;
J9Class *currentParentClass = NULL;
U_32 offset = 0;
U_32 i = (*index + 1);
for (; i < filtersLength; i++) {
currentFilterHandle = J9JAVAARRAYOFOBJECT_LOAD(_currentThread, filters, i);
currentParentClass = J9VM_J9CLASS_FROM_HEAPCLASS(_currentThread, J9JAVAARRAYOFOBJECT_LOAD(_currentThread, parentTypeArguments, (startPosition + i)));
if (NULL == currentFilterHandle) {
if (_vm->voidReflectClass != currentParentClass) {
*--nextPtr = *--parentPtr;
offset += 1;
if ((_vm->doubleReflectClass == currentParentClass) || (_vm->longReflectClass == currentParentClass)) {
*--nextPtr = *--parentPtr;
offset += 1;
}
}
} else {
break;
}
}
*parentOffset += offset;
*nextOffset += offset;
*index = i;
if (filtersLength == *index) { /* All filterMHs have been processed */
/* Copy trailing parent args into next args */
for (U_32 i = (*nextOffset + 1); i <= nextArgSlots; i++) {
*--nextPtr = *--parentPtr;
}
UDATA *srcPtr = UNTAGGED_A0(frame); /* Pointer to FAH.next */
UDATA *destPtr = UNTAGGED_A0(mtNextFrame); /* Pointer to FAH[1] */
/* Restore initial thread state */
J9SFMethodTypeFrame *mtParentFrame = (J9SFMethodTypeFrame *)(srcPtr + 1);
_currentThread->literals = mtParentFrame->savedCP;
_currentThread->pc = mtParentFrame->savedPC;
_currentThread->arg0EA = UNTAGGED_A0(mtParentFrame);
_currentThread->sp = destPtr - nextArgSlots;
/* [... FAH.next UpdatedArgs] */
memmove(destPtr - nextArgSlots, srcPtr - nextArgSlots, (nextArgSlots + 1) * sizeof(UDATA *));
_currentThread->tempSlot = (UDATA) nextHandle;
} else { /* Prepare next non-null filterMH for processing */
_currentThread->sp -= 1;
*(j9object_t *)(_currentThread->sp) = currentFilterHandle;
_currentThread->tempSlot = (UDATA) currentFilterHandle;
U_32 nextFilterArgumentSlots = 0;
if (_vm->voidReflectClass != currentParentClass) {
nextFilterArgumentSlots += 1;
if ((_vm->doubleReflectClass == currentParentClass) || (_vm->longReflectClass == currentParentClass)) {
nextFilterArgumentSlots += 1;
}
}
*parentOffset += nextFilterArgumentSlots;
parentPtr -= nextFilterArgumentSlots;
_currentThread->sp -= nextFilterArgumentSlots;
memmove(_currentThread->sp, parentPtr, nextFilterArgumentSlots * sizeof(UDATA *));
_currentThread->pc -= 3; /* Point to impdep1 */
}
} else {
Assert_VM_unreachable();
}
return rc;
}
j9object_t
VM_MHInterpreter::convertArgumentsForAsType(j9object_t methodHandle)
{
j9object_t result = NULL;
j9object_t currentType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, methodHandle);
U_32 currentArgSlots = (U_32)J9VMJAVALANGINVOKEMETHODTYPE_ARGSLOTS(_currentThread, currentType);
j9object_t nextHandle = J9VMJAVALANGINVOKECONVERTHANDLE_NEXT(_currentThread, methodHandle);
j9object_t nextType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, nextHandle);
U_32 nextArgSlots = (U_32)J9VMJAVALANGINVOKEMETHODTYPE_ARGSLOTS(_currentThread, nextType);
UDATA explicitCast = (J9VMJAVALANGINVOKEMETHODHANDLE_KIND(_currentThread, methodHandle) == J9_METHOD_HANDLE_KIND_EXPLICITCAST);
UDATA requiresBoxing = (UDATA)J9VMJAVALANGINVOKECONVERTHANDLE_REQUIRESBOXING(_currentThread, methodHandle);
UDATA * currentArgs = NULL;
UDATA * nextArgs = NULL;
UDATA * finalSP = NULL;
J9SFMethodTypeFrame * currentTypeFrame = NULL;
J9SFMethodTypeFrame * nextTypeFrame = NULL;
UDATA rc = 0;
ClassCastExceptionData exceptionData;
memset(&exceptionData, 0, sizeof(ClassCastExceptionData));
currentArgs = _currentThread->sp + currentArgSlots;
finalSP = currentArgs - nextArgSlots;
if (0 != requiresBoxing) {
/* Lay down a frame to describe the current args */
currentTypeFrame = buildMethodTypeFrame(_currentThread, currentType);
/* Reserve space for all of the new arguments, zero them, and drop another method type frame to describe them */
*--(_currentThread->sp) = (UDATA) nextHandle;
nextArgs = _currentThread->sp;
_currentThread->sp -= nextArgSlots;
memset(_currentThread->sp, 0, nextArgSlots * sizeof(UDATA *));
nextTypeFrame = buildMethodTypeFrame(_currentThread, nextType);
/* Convert the arguments */
rc = convertArguments(currentArgs, ¤tTypeFrame->methodType, nextArgs, &nextTypeFrame->methodType, explicitCast, &exceptionData);
if (NO_EXCEPTION != rc) {
/* In the case of a return value being non-zero, throw the exception */
goto fail;
}
/* Remove the method type frames */
_currentThread->literals = currentTypeFrame->savedCP;
_currentThread->pc = currentTypeFrame->savedPC;
_currentThread->arg0EA = UNTAGGED_A0(currentTypeFrame);
} else {
/* If we don't require boxing, do the operations on the java stack
* but don't move the sp until the operations are complete or an exception is thrown
*/
UDATA *tempSP = _currentThread->sp;
/* Reserve space for all of the new arguments, and zero them */
*--(tempSP) = (UDATA) nextHandle;
nextArgs = tempSP;
tempSP -= nextArgSlots;
memset(tempSP, 0, nextArgSlots * sizeof(UDATA *));
/* Convert the arguments */
rc = convertArguments(currentArgs, ¤tType, nextArgs, &nextType, explicitCast, &exceptionData);
if (NO_EXCEPTION != rc) {
/* In the case of a return value being non-zero, throw the exception.
* First we need to make the stack walkable by building a valid frame.
*/
buildMethodTypeFrame(_currentThread, currentType);
goto fail;
}
}
/* Move the new arguments (including the next MethodHandle) into their final position */
_currentThread->sp = finalSP;
memmove(finalSP, nextArgs - nextArgSlots, (nextArgSlots + 1) * sizeof(UDATA *));
/* Return the next handle from its new location on the stack */
result = (j9object_t) finalSP[nextArgSlots];
done:
return result;
fail:
/* In the case of a return value being non-zero, throw the exception */
if (NULL_POINTER_EXCEPTION == rc) {
setCurrentException(_currentThread, J9VMCONSTANTPOOL_JAVALANGNULLPOINTEREXCEPTION, NULL);
} else if (CLASS_CAST_EXCEPTION == rc) {
setClassCastException(_currentThread, exceptionData.currentClass, exceptionData.nextClass);
} else {
setCurrentException(_currentThread, J9VMCONSTANTPOOL_JAVALANGINTERNALERROR, NULL);
}
goto done;
}
j9object_t
VM_MHInterpreter::doInvokeGeneric(j9object_t methodHandle)
{
j9object_t castType = J9VMJAVALANGINVOKEINVOKEGENERICHANDLE_CASTTYPE(_currentThread, methodHandle);
j9object_t currentType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, methodHandle);
U_32 currentArgSlots = (U_32)J9VMJAVALANGINVOKEMETHODTYPE_ARGSLOTS(_currentThread, currentType);
const U_32 slotsOffsetToTargetHandle = currentArgSlots - 1;
j9object_t targetHandle = *(j9object_t*)(_currentThread->sp + slotsOffsetToTargetHandle);
/* If receiver handle is null, return directly and a NPE will be thrown by the caller */
if (targetHandle == NULL) {
return targetHandle;
}
j9object_t targetType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, targetHandle);
/* There are three cases here:
* - The target handle's type correctly matches the stack, we can directly invoke that handle
* - A previous asType result correctly matches the stack, we can overwrite the target and invoke that
* - We need to do a callin to create the correct as type, we can overwrite the target and invoke that
*/
if (targetType != castType) {
J9SFMethodTypeFrame *currentTypeFrame = NULL;
UDATA * spPriorToFrameBuild = _currentThread->sp;
j9object_t cachedHandle = J9VMJAVALANGINVOKEMETHODHANDLE_PREVIOUSASTYPE(_currentThread, targetHandle);
IDATA spOffset = 0;
IDATA frameOffset = 0;
if (cachedHandle != NULL) {
j9object_t cachedHandleType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, cachedHandle);
if (cachedHandleType == castType) {
*(j9object_t*)(_currentThread->sp + slotsOffsetToTargetHandle) = cachedHandle;
targetHandle = cachedHandle;
goto done;
}
}
/* We need to do a callin to get an asType handle */
currentTypeFrame = buildMethodTypeFrame(_currentThread, currentType);
/* Convert absolute values to A0 relative offsets */
spOffset = spPriorToFrameBuild - _currentThread->arg0EA;
frameOffset = (UDATA*)currentTypeFrame - _currentThread->arg0EA;
sendForGenericInvoke(_currentThread, targetHandle, castType, FALSE);
targetHandle = (j9object_t)_currentThread->returnValue;