-
Notifications
You must be signed in to change notification settings - Fork 729
/
bcverify.c
2833 lines (2410 loc) · 91.8 KB
/
bcverify.c
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 (c) 1991, 2019 IBM Corp. and others
*
* 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] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
#include <string.h>
#include "bcvcfr.h"
#include "bcverify.h"
#include "j9bcvnls.h"
#include "cfreader.h"
#include "bcnames.h"
#include "pcstack.h"
#include "j9cp.h"
#include "j9protos.h"
#include "j9consts.h"
#include "omrthread.h"
#include "jvminit.h"
#include "vrfyconvert.h"
#include "bcverify_internal.h"
#include "vrfytbl.h"
#include "vmhook_internal.h"
#include "SCQueryFunctions.h"
#define _UTE_STATIC_
#include "ut_j9bcverify.h"
#include "bcverify.h"
/* Define for debug
#define DEBUG_BCV
*/
#define BYTECODE_MAP_DEFAULT_SIZE (2 * 1024)
#define STACK_MAPS_DEFAULT_SIZE (2 * 1024)
#define LIVE_STACK_DEFAULT_SIZE 256
#define ROOT_QUEUE_DEFAULT_SIZE 256
#define CLASSNAMELIST_DEFAULT_SIZE (128 * sizeof(UDATA *)) /* 128 pointers */
#define CLASSNAMESEGMENT_DEFAULT_SIZE 1024 /* 1k bytes - minimum of 8 bytes per classNameList entry */
#define BCV_INTERNAL_DEFAULT_SIZE (32*1024)
#define THIS_DLL_NAME J9_VERIFY_DLL_NAME
#define OPT_XVERIFY "-Xverify"
#define OPT_XVERIFY_COLON "-Xverify:"
#define OPT_ALL "all"
#define OPT_OPT "opt"
#define OPT_NO_OPT "noopt"
#define OPT_NO_FALLBACK "nofallback"
#define OPT_IGNORE_STACK_MAPS "ignorestackmaps"
#define OPT_EXCLUDEATTRIBUTE_EQUAL "excludeattribute="
#define OPT_BOOTCLASSPATH_STATIC "bootclasspathstatic"
#define OPT_DO_PROTECTED_ACCESS_CHECK "doProtectedAccessCheck"
static IDATA buildBranchMap (J9BytecodeVerificationData * verifyData);
static IDATA decompressStackMaps (J9BytecodeVerificationData * verifyData, IDATA localsCount, U_8 * stackMapData);
static VMINLINE IDATA parseLocals (J9BytecodeVerificationData * verifyData, U_8** stackMapData, J9BranchTargetStack * liveStack, IDATA localDelta, IDATA localsCount, IDATA maxLocals);
static VMINLINE IDATA parseStack (J9BytecodeVerificationData * verifyData, U_8** stackMapData, J9BranchTargetStack * liveStack, UDATA stackCount, UDATA maxStack);
static UDATA parseElement (J9BytecodeVerificationData * verifyData, U_8 ** stackMapData);
static VMINLINE void copyStack (J9BranchTargetStack *source, J9BranchTargetStack *destination);
static IDATA mergeObjectTypes (J9BytecodeVerificationData *verifyData, UDATA sourceType, UDATA * targetTypePointer);
static IDATA mergeStacks (J9BytecodeVerificationData * verifyData, UDATA target);
static J9UTF8 * mergeClasses(J9BytecodeVerificationData *verifyData, U_8* firstClass, UDATA firstLength, U_8* secondClass, UDATA secondLength, IDATA *reasonCode);
static void bcvHookClassesUnload (J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData);
static void printMethod (J9BytecodeVerificationData * verifyData);
static IDATA simulateStack (J9BytecodeVerificationData * verifyData);
static IDATA parseOptions (J9JavaVM *vm, char *optionValues, char **errorString);
static IDATA setVerifyState ( J9JavaVM *vm, char *option, char **errorString );
/**
* Walk the J9-format stack maps and set the uninitialized_this flag appropriately
* for each map. It is set to TRUE for the map, if the map's stack contains an
* uninitialized_this object.
* NOTE: This is only necessary for <init> methods.
*/
static void
setInitializedThisStatus(J9BytecodeVerificationData *verifyData)
{
J9BranchTargetStack * currentStack = NULL;
IDATA nextMapIndex = 0;
while (nextMapIndex < verifyData->stackMapsCount) {
currentStack = BCV_INDEX_STACK (nextMapIndex);
nextMapIndex++;
/* Ensure we're not a stack map for dead code */
if (currentStack->stackBaseIndex != -1) {
BOOLEAN flag_uninitialized = FALSE;
IDATA i = 0;
for (; i < currentStack->stackTopIndex; i++) {
if ((currentStack->stackElements[i] & BCV_SPECIAL_INIT) == BCV_SPECIAL_INIT) {
flag_uninitialized = TRUE;
break;
}
}
currentStack->uninitializedThis = flag_uninitialized;
}
}
}
/*
API
@verifyData - internal data structure
@firstClass - U_8 pointer to class name
@firstLength - UDATA length of class name
@secondClass - U_8 pointer to class name
@secondLength - UDATA length of class name
Answer the first common class shared by the two classes.
If one of the classes is a parent of the other, answer that class.
Return NULL on error.
sets reasonCode to BCV_FAIL on verification error
sets reasonCode to BCV_ERR_INSUFFICIENT_MEMORY on OOM
sets reasonCode to BCV_ERR_INTERNAL_ERROR otherwise
*/
#define SUPERCLASS(clazz) ((clazz)->superclasses[ J9CLASS_DEPTH(clazz) - 1 ])
static J9UTF8 *
mergeClasses(J9BytecodeVerificationData *verifyData, U_8* firstClass, UDATA firstLength, U_8* secondClass, UDATA secondLength, IDATA *reasonCode)
{
J9Class *sourceRAM, *targetRAM;
UDATA sourceDepth, targetDepth;
/* Go get the ROM class for the source and target. Check if it returns null immediately to prevent
* having to load the second class in an error case */
sourceRAM = j9rtv_verifierGetRAMClass( verifyData, verifyData->classLoader, firstClass, firstLength, reasonCode);
if (NULL == sourceRAM) {
return NULL;
}
targetRAM = j9rtv_verifierGetRAMClass( verifyData, verifyData->classLoader, secondClass, secondLength, reasonCode );
if (NULL == targetRAM) {
return NULL;
}
sourceRAM = J9_CURRENT_CLASS(sourceRAM);
sourceDepth = J9CLASS_DEPTH(sourceRAM);
targetDepth = J9CLASS_DEPTH(targetRAM);
/* walk up the chain until sourceROM == targetROM */
while( sourceRAM != targetRAM ) {
if( sourceDepth >= targetDepth ) {
sourceRAM = SUPERCLASS(sourceRAM);
if ( sourceRAM ) {
sourceDepth = J9CLASS_DEPTH(sourceRAM);
}
}
if (sourceRAM == targetRAM )
break;
if( sourceDepth <= targetDepth ) {
targetRAM = SUPERCLASS(targetRAM);
if ( targetRAM ) {
targetDepth = J9CLASS_DEPTH(targetRAM);
}
}
if( (sourceRAM == NULL) || (targetRAM == NULL) ) {
*reasonCode = BCV_FAIL;
return NULL;
}
}
/* good, both sourceROM and targetROM are the same class -- this is the new target class */
return( J9ROMCLASS_CLASSNAME( targetRAM->romClass ) );
}
#undef SUPERCLASS
/*
Determine the number of branch targets in this method.
Returns
count of unique branch targets and exception handler starts.
BCV_ERR_INTERNAL_ERROR for any unexpected error
*/
static IDATA
buildBranchMap (J9BytecodeVerificationData * verifyData)
{
J9ROMMethod *romMethod = verifyData->romMethod;
U_32 *bytecodeMap = verifyData->bytecodeMap;
U_8 *bcStart;
U_8 *bcIndex;
U_8 *bcEnd;
UDATA npairs, temp;
IDATA pc, start, high, low, pcs;
I_16 shortBranch;
I_32 longBranch;
UDATA bc, size;
UDATA count = 0;
bcStart = J9_BYTECODE_START_FROM_ROM_METHOD(romMethod);
bcIndex = bcStart;
bcEnd = bcStart + J9_BYTECODE_SIZE_FROM_ROM_METHOD(romMethod);
while (bcIndex < bcEnd) {
bc = *bcIndex;
size = J9JavaInstructionSizeAndBranchActionTable[bc];
if (size == 0) {
verifyData->errorPC = bcIndex - bcStart;
Trc_BCV_buildBranchMap_UnknownInstruction(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(romMethod)),
bc, verifyData->errorPC, verifyData->errorPC);
return BCV_ERR_INTERNAL_ERROR;
}
switch (size >> 4) {
case 5: /* switches */
start = bcIndex - bcStart;
pc = (start + 4) & ~3;
bcIndex = bcStart + pc;
longBranch = (I_32) PARAM_32(bcIndex, 0);
bcIndex += 4;
if (bytecodeMap[start + longBranch] == 0) {
bytecodeMap[start + longBranch] = BRANCH_TARGET;
count++;
}
low = (I_32) PARAM_32(bcIndex, 0);
bcIndex += 4;
low = (I_32) low;
if (bc == JBtableswitch) {
high = (I_32) PARAM_32(bcIndex, 0);
bcIndex += 4;
high = (I_32) high;
npairs = (UDATA) (high - low + 1);
pcs = 0;
} else {
npairs = (UDATA) low;
pcs = 4;
}
for (temp = 0; temp < npairs; temp++) {
bcIndex += pcs;
longBranch = (I_32) PARAM_32(bcIndex, 0);
bcIndex += 4;
if (bytecodeMap[start + longBranch] == 0) {
bytecodeMap[start + longBranch] = BRANCH_TARGET;
count++;
}
}
continue;
case 2: /* gotos */
if (bc == JBgotow) {
start = bcIndex - bcStart;
longBranch = (I_32) PARAM_32(bcIndex, 1);
if (bytecodeMap[start + longBranch] == 0) {
bytecodeMap[start + longBranch] = BRANCH_TARGET;
count++;
}
break;
} /* fall through for JBgoto */
case 1: /* ifs */
shortBranch = (I_16) PARAM_16(bcIndex, 1);
start = bcIndex - bcStart;
if (bytecodeMap[start + shortBranch] == 0) {
bytecodeMap[start + shortBranch] = BRANCH_TARGET;
count++;
}
break;
}
bcIndex += size & 7;
}
/* need to walk exceptions as well, since they are branch targets */
if (romMethod->modifiers & J9AccMethodHasExceptionInfo) {
J9ExceptionInfo * exceptionData = J9_EXCEPTION_DATA_FROM_ROM_METHOD(romMethod);
J9ExceptionHandler *handler;
if (exceptionData->catchCount) {
handler = J9EXCEPTIONINFO_HANDLERS(exceptionData);
for (temp=0; temp < (U_32) exceptionData->catchCount; temp++) {
pc = (IDATA) handler->startPC;
pcs = (IDATA) handler->handlerPC;
/* Avoid re-walking a handler that handles itself */
if (pc != pcs) {
bytecodeMap[pc] |= BRANCH_EXCEPTION_START;
}
if ((bytecodeMap[pcs] & BRANCH_TARGET) == 0) {
bytecodeMap[pcs] |= BRANCH_TARGET;
count++;
}
handler++;
}
}
}
Trc_BCV_buildBranchMap_branchCount(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(romMethod)),
count);
return count;
}
/*
Convert the StackMap Attribute maps to internal uncompressed stackmaps.
Returns
BCV_SUCCESS on success,
BCV_FAIL on verification error
*/
static IDATA
decompressStackMaps (J9BytecodeVerificationData * verifyData, IDATA localsCount, U_8 * stackMapData)
{
J9ROMMethod *romMethod = verifyData->romMethod;
UDATA maxStack = J9_MAX_STACK_FROM_ROM_METHOD(romMethod);
IDATA maxLocals = J9_ARG_COUNT_FROM_ROM_METHOD(romMethod) + J9_TEMP_COUNT_FROM_ROM_METHOD(romMethod);
UDATA length = (UDATA) J9_BYTECODE_SIZE_FROM_ROM_METHOD(romMethod);
UDATA i;
IDATA rc = BCV_SUCCESS;
J9BranchTargetStack *liveStack = (J9BranchTargetStack *)verifyData->liveStack;
J9BranchTargetStack *branchTargetStack = BCV_FIRST_STACK();
U_8 mapType;
UDATA mapPC = -1;
UDATA temp;
UDATA start = 0; /* Used in BUILD_VERIFY_ERROR */
UDATA mapIndex = 0;
UDATA errorModule = J9NLS_BCV_ERR_NO_ERROR__MODULE; /* default to BCV NLS catalog */
Trc_BCV_decompressStackMaps_Entry(verifyData->vmStruct, localsCount);
/* localsCount records the current locals depth as all stack maps (except full frame) are relative to the previous frame */
for (i = 0; i < (UDATA) verifyData->stackMapsCount; i++) {
IDATA localDelta = 0;
UDATA stackCount = 0;
NEXT_U8(mapType, stackMapData);
mapPC++;
if (mapType < CFR_STACKMAP_SAME_LOCALS_1_STACK) {
/* Same frame 0-63 */
mapPC += (UDATA) mapType;
/* done */
} else if (mapType < CFR_STACKMAP_SAME_LOCALS_1_STACK_END) {
/* Same with one stack entry frame 64-127 */
mapPC += (UDATA) ((UDATA) mapType - CFR_STACKMAP_SAME_LOCALS_1_STACK);
stackCount = 1;
} else {
mapPC += NEXT_U16(temp, stackMapData);
if (mapType == CFR_STACKMAP_SAME_LOCALS_1_STACK_EXTENDED) {
/* Same with one stack entry extended address frame 247 */
stackCount = 1;
} else if (mapType < CFR_STACKMAP_FULL) {
/* Chop 3-1 locals frame 248-250 */
/* Same with extended address frame 251 */
/* Append 1-3 locals frame 252-254 */
localDelta = ((IDATA) mapType) - CFR_STACKMAP_SAME_EXTENDED;
} else if (mapType == CFR_STACKMAP_FULL) {
/* Full frame 255 */
localDelta = NEXT_U16(temp, stackMapData);
localsCount = 0;
}
}
localsCount = parseLocals (verifyData, &stackMapData, liveStack, localDelta, localsCount, maxLocals);
if (localsCount < 0) {
BUILD_VERIFY_ERROR (errorModule, J9NLS_BCV_ERR_INCONSISTENT_STACK__ID);
/* Jazz 82615: Set the pc value of the current stackmap frame to show up in the error message frame work */
liveStack->pc = mapPC;
verifyData->errorPC = mapPC;
Trc_BCV_decompressStackMaps_LocalsArrayOverFlowUnderFlow(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(romMethod)),
i, mapPC);
rc = BCV_FAIL;
break;
}
if (mapType == CFR_STACKMAP_FULL) {
stackCount = NEXT_U16(temp, stackMapData);
}
if (BCV_SUCCESS != parseStack (verifyData, &stackMapData, liveStack, stackCount, maxStack)) {
BUILD_VERIFY_ERROR (errorModule, J9NLS_BCV_ERR_INCONSISTENT_STACK__ID);
/* Jazz 82615: Set the pc value of the current stackmap frame to show up in the error message frame work */
liveStack->pc = mapPC;
verifyData->errorPC = mapPC;
Trc_BCV_decompressStackMaps_StackArrayOverFlow(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(romMethod)),
i, mapPC);
rc = BCV_FAIL;
break;
}
if (mapPC >= length) {
/* should never get here - caught in staticverify.c checkStackMap */
BUILD_VERIFY_ERROR (errorModule, J9NLS_BCV_ERR_INCONSISTENT_STACK__ID);
Trc_BCV_decompressStackMaps_MapOutOfRange(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(romMethod)),
i, mapPC, length);
rc = BCV_FAIL;
break;
}
(verifyData->bytecodeMap)[mapPC] |= (mapIndex << BRANCH_INDEX_SHIFT) | BRANCH_TARGET;
mapIndex++;
copyStack (liveStack, branchTargetStack);
branchTargetStack->pc = mapPC;
/* Point to the next stack */
branchTargetStack = BCV_NEXT_STACK (branchTargetStack);
}
Trc_BCV_decompressStackMaps_Exit(verifyData->vmStruct, rc);
return rc;
}
/* Specifically returns BCV_ERR_INTERNAL_ERROR for failure */
static IDATA
parseLocals (J9BytecodeVerificationData * verifyData, U_8** stackMapData, J9BranchTargetStack * liveStack, IDATA localDelta, IDATA localsCount, IDATA maxLocals)
{
UDATA i;
UDATA stackEntry;
UDATA unusedLocals;
if (localDelta < 0) {
/* Clear the chopped elements */
for (;localDelta; localDelta++) {
localsCount--;
if (localsCount < 0) {
goto _underflow;
}
liveStack->stackElements[localsCount] = BCV_BASE_TYPE_TOP;
/* Check long/double type as long as there still remains local variables
* in the stackmap frame.
*/
if (localsCount > 0) {
/* Possibly remove a double or long (counts as 1 local, but two slots).
* A double or a long is pushed as <top, double|long>
*/
stackEntry = liveStack->stackElements[localsCount - 1];
if ((BCV_BASE_TYPE_DOUBLE == stackEntry) || (BCV_BASE_TYPE_LONG == stackEntry)) {
localsCount--;
if (localsCount < 0) {
goto _underflow;
}
liveStack->stackElements[localsCount] = BCV_BASE_TYPE_TOP;
}
}
}
} else {
for (;localDelta; localDelta--) {
stackEntry = parseElement (verifyData, stackMapData);
if (localsCount >= maxLocals) {
/* Overflow */
goto _overflow;
}
liveStack->stackElements[localsCount++] = stackEntry;
if ((BCV_BASE_TYPE_DOUBLE == stackEntry) || (BCV_BASE_TYPE_LONG == stackEntry)) {
if (localsCount >= maxLocals) {
/* Overflow */
goto _overflow;
}
liveStack->stackElements[localsCount++] = BCV_BASE_TYPE_TOP;
}
}
/* Clear the remaining locals */
unusedLocals = liveStack->stackBaseIndex - localsCount;
for (i = localsCount; i < (unusedLocals + localsCount); i++) {
liveStack->stackElements[i] = BCV_BASE_TYPE_TOP;
}
}
return localsCount;
_underflow:
/* Jazz 82615: Set the error code in the case of underflow on 'locals' in the current stackmap frame */
verifyData->errorDetailCode = BCV_ERR_STACKMAP_FRAME_LOCALS_UNDERFLOW;
Trc_BCV_parseLocals_LocalsArrayUnderFlow(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)));
return BCV_ERR_INTERNAL_ERROR;
_overflow:
/* Jazz 82615: Set the error code, the location of the last local variable allowed on 'locals'
* and the maximum local size in the case of overflow on 'locals' in the currrent stackmap frame.
*/
verifyData->errorDetailCode = BCV_ERR_STACKMAP_FRAME_LOCALS_OVERFLOW;
verifyData->errorCurrentFramePosition = (maxLocals > 0) ? (U_32)(maxLocals - 1) : 0;
verifyData->errorTempData = (UDATA)maxLocals;
Trc_BCV_parseLocals_LocalsArrayOverFlow(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)));
return BCV_ERR_INTERNAL_ERROR;
}
/*
* returns BCV_SUCCESS on success
* returns BCV_ERR_INTERNAL_ERROR on failure
*/
static IDATA
parseStack (J9BytecodeVerificationData * verifyData, U_8** stackMapData, J9BranchTargetStack * liveStack, UDATA stackCount, UDATA maxStack)
{
UDATA stackEntry;
UDATA* stackTop = RELOAD_STACKBASE(liveStack); /* Clears the stack */
UDATA* stackBase = stackTop;
for (;stackCount; stackCount--) {
stackEntry = parseElement (verifyData, stackMapData);
if ((UDATA) (stackTop - stackBase) >= maxStack) {
/* Jazz 82615: Set the error code and the location of wrong data type on 'stack' (only keep the maximum size for stack) */
verifyData->errorDetailCode = BCV_ERR_STACKMAP_FRAME_STACK_OVERFLOW;
verifyData->errorCurrentFramePosition = (U_32)(stackBase - liveStack->stackElements);
if (maxStack > 0) {
verifyData->errorCurrentFramePosition += (U_32)(maxStack - 1);
}
verifyData->errorTempData = maxStack;
return BCV_ERR_INTERNAL_ERROR;
}
PUSH(stackEntry);
if ((stackEntry == BCV_BASE_TYPE_DOUBLE) || (stackEntry == BCV_BASE_TYPE_LONG)) {
if ((UDATA) (stackTop - stackBase) >= maxStack) {
/* Jazz 82615: Set the error code and the location of wrong data type on 'stack' (only keep the maximum size for stack) */
verifyData->errorDetailCode = BCV_ERR_STACKMAP_FRAME_STACK_OVERFLOW;
verifyData->errorCurrentFramePosition = (U_32)(stackBase - liveStack->stackElements);
if (maxStack > 0) {
verifyData->errorCurrentFramePosition += (U_32)(maxStack - 1);
}
verifyData->errorTempData = maxStack;
return BCV_ERR_INTERNAL_ERROR;
}
PUSH(BCV_BASE_TYPE_TOP);
}
}
SAVE_STACKTOP(liveStack, stackTop);
return BCV_SUCCESS;
}
/*
* returns stackEntry
* No error path in this function
*/
static UDATA
parseElement (J9BytecodeVerificationData * verifyData, U_8** stackMapData)
{
J9ROMClass * romClass = verifyData->romClass;
U_8 entryType;
U_8 *mapData = *stackMapData;
U_16 cpIndex;
UDATA stackEntry;
NEXT_U8(entryType, mapData);
if (entryType < CFR_STACKMAP_TYPE_INIT_OBJECT) {
/* return primitive type */
stackEntry = verificationTokenDecode[entryType];
} else if (entryType == CFR_STACKMAP_TYPE_INIT_OBJECT) {
J9ROMMethod *romMethod = verifyData->romMethod;
J9UTF8* className = J9ROMCLASS_CLASSNAME(romClass);
stackEntry = convertClassNameToStackMapType(verifyData, J9UTF8_DATA(className), J9UTF8_LENGTH(className), BCV_SPECIAL_INIT, 0);
} else if (entryType == CFR_STACKMAP_TYPE_OBJECT) {
J9UTF8 *utf8string;
J9ROMConstantPoolItem *constantPool = J9_ROM_CP_FROM_ROM_CLASS(romClass);
NEXT_U16(cpIndex, mapData);
utf8string = J9ROMSTRINGREF_UTF8DATA((J9ROMStringRef *) (&constantPool[cpIndex]));
pushClassType(verifyData, utf8string, &stackEntry);
} else if (entryType == CFR_STACKMAP_TYPE_NEW_OBJECT) {
NEXT_U16(cpIndex, mapData);
stackEntry = BCV_SPECIAL_NEW | (((UDATA) cpIndex) << BCV_CLASS_INDEX_SHIFT);
} else {
/* Primitive arrays */
U_16 arity;
stackEntry = (UDATA) verificationTokenDecode[entryType];
NEXT_U16(arity, mapData);
stackEntry |= (((UDATA) arity) << BCV_ARITY_SHIFT);
}
*stackMapData = mapData;
return stackEntry;
}
static void
copyStack (J9BranchTargetStack *source, J9BranchTargetStack *destination)
{
UDATA pc = destination->pc;
memcpy((UDATA *) destination, (UDATA *) source, (source->stackTopIndex + BCV_TARGET_STACK_HEADER_UDATA_SIZE) * sizeof(UDATA));
destination->pc = pc;
}
/* returns
* BCV_SUCCESS : no merge necessary
* BCV_FAIL : cause a rewalk
* BCV_ERR_INSUFFICIENT_MEMORY : OOM - no rewalk
*/
static IDATA
mergeObjectTypes (J9BytecodeVerificationData *verifyData, UDATA sourceType, UDATA * targetTypePointer)
{
J9ROMClass * romClass = verifyData->romClass;
UDATA targetType = *targetTypePointer;
UDATA sourceIndex, targetIndex;
J9UTF8 *name;
UDATA classArity, targetArity, classIndex;
IDATA rc = BCV_SUCCESS;
U_8 *sourceName, *targetName;
UDATA sourceLength, targetLength;
U_32 *offset;
IDATA reasonCode = 0;
/* assume that sourceType and targetType are not equal */
/* if target is more general than source, then its fine */
rc = isClassCompatible( verifyData, sourceType, targetType, &reasonCode ) ;
if (TRUE == rc) {
return BCV_SUCCESS; /* no merge required */
} else { /* FALSE == rc */
/* VM error, no need to continue, return appropriate rc */
if (BCV_ERR_INTERNAL_ERROR == reasonCode) {
*targetTypePointer = (U_32)BCV_JAVA_LANG_OBJECT_INDEX << BCV_CLASS_INDEX_SHIFT;
Trc_BCV_mergeObjectTypes_UnableToLoadClass(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
sourceType, targetType);
return (IDATA) BCV_FAIL;
} else if (BCV_ERR_INSUFFICIENT_MEMORY == reasonCode) {
Trc_BCV_mergeObjectTypes_MergeClasses_OutOfMemoryException(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)));
return BCV_ERR_INSUFFICIENT_MEMORY;
}
}
/* Types were not compatible, thus target is not equal or more general than source */
/* NULL always loses to objects */
if (targetType == BCV_BASE_TYPE_NULL) {
Trc_BCV_mergeObjectTypes_NullTargetOverwritten(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
sourceType);
*targetTypePointer = sourceType;
/* cause a re-walk */
return (IDATA) BCV_FAIL;
}
/* if the source or target are base type arrays, decay them to object arrays of arity n-1 (or just Object) */
/* Base arrays already have an implicit arity of 1, so just keep the arity for object */
if (sourceType & BCV_TAG_BASE_ARRAY_OR_NULL) {
Trc_BCV_mergeObjectTypes_DecaySourceArray(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
sourceType);
sourceType = (sourceType & BCV_ARITY_MASK) | ((U_32)BCV_JAVA_LANG_OBJECT_INDEX << BCV_CLASS_INDEX_SHIFT);
}
if (targetType & BCV_TAG_BASE_ARRAY_OR_NULL) {
Trc_BCV_mergeObjectTypes_DecayTargetArray(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
targetType);
targetType = (targetType & BCV_ARITY_MASK) | ((U_32)BCV_JAVA_LANG_OBJECT_INDEX << BCV_CLASS_INDEX_SHIFT);
}
classArity = sourceType & BCV_ARITY_MASK;
targetArity = targetType & BCV_ARITY_MASK;
if (classArity == targetArity) {
/* Find the common parent class if the same arity */
sourceIndex = (sourceType & BCV_CLASS_INDEX_MASK) >> BCV_CLASS_INDEX_SHIFT;
targetIndex = (targetType & BCV_CLASS_INDEX_MASK) >> BCV_CLASS_INDEX_SHIFT;
offset = (U_32 *) verifyData->classNameList[sourceIndex];
sourceLength = (UDATA) J9UTF8_LENGTH(offset + 1);
if (offset[0] == 0) {
sourceName = J9UTF8_DATA(offset + 1);
} else {
sourceName = (U_8 *) ((UDATA) offset[0] + (UDATA) romClass);
}
offset = (U_32 *) verifyData->classNameList[targetIndex];
targetLength = (UDATA) J9UTF8_LENGTH(offset + 1);
if (offset[0] == 0) {
targetName = J9UTF8_DATA(offset + 1);
} else {
targetName = (U_8 *) ((UDATA) offset[0] + (UDATA) romClass);
}
name = mergeClasses(verifyData, sourceName, sourceLength, targetName, targetLength, &reasonCode);
if (NULL == name) {
if (BCV_ERR_INSUFFICIENT_MEMORY == reasonCode) {
Trc_BCV_mergeObjectTypes_MergeClasses_OutOfMemoryException(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)));
return BCV_ERR_INSUFFICIENT_MEMORY;
} else {
Trc_BCV_mergeObjectTypes_MergeClassesFail(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
sourceLength, sourceName, targetLength, targetName);
*targetTypePointer = sourceType;
/* cause a re-walk */
return (IDATA) BCV_FAIL;
}
}
classIndex = findClassName( verifyData, J9UTF8_DATA(name), J9UTF8_LENGTH(name) );
Trc_BCV_mergeObjectTypes_MergeClassesSucceed(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
sourceLength, sourceName, targetLength, targetName, J9UTF8_LENGTH(name), J9UTF8_DATA(name), classIndex);
} else {
/* Different arity means common parent class is the minimum arity of class Object */
classIndex = BCV_JAVA_LANG_OBJECT_INDEX;
Trc_BCV_mergeObjectTypes_MergeClassesMinimumArity(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
classArity, targetArity);
/* Find minimum common arity of arrays */
if( targetArity < classArity ) {
classArity = targetArity;
}
}
/* slam new type into targetTypePointer */
*targetTypePointer = classArity | ( classIndex << BCV_CLASS_INDEX_SHIFT );
Trc_BCV_mergeObjectTypes_MergedClass(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
*targetTypePointer);
/* cause a re-walk */
return (IDATA) BCV_FAIL;
}
/*
* returns BCV_SUCCESS on success
* returns BCV_FAIL on failure
* returns BCV_ERR_INSUFFICIENT_MEMORY on OOM */
static IDATA
mergeStacks (J9BytecodeVerificationData * verifyData, UDATA target)
{
J9ROMClass *romClass = verifyData->romClass;
J9ROMMethod *romMethod = verifyData->romMethod;
UDATA maxIndex = J9_ARG_COUNT_FROM_ROM_METHOD(romMethod) + J9_TEMP_COUNT_FROM_ROM_METHOD(romMethod);
U_32 *bytecodeMap = verifyData->bytecodeMap;
UDATA i = 0;
UDATA stackIndex;
IDATA rewalk = FALSE;
IDATA rc = BCV_SUCCESS;
UDATA *targetStackPtr, *targetStackTop, *sourceStackPtr, *sourceStackTop, *sourceStackTemps;
J9BranchTargetStack *liveStack = (J9BranchTargetStack *) verifyData->liveStack;
J9BranchTargetStack *targetStack;
stackIndex = bytecodeMap[target] >> BRANCH_INDEX_SHIFT;
targetStack = BCV_INDEX_STACK (stackIndex);
Trc_BCV_mergeStacks_Entry(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
target, target);
if (targetStack->stackBaseIndex == -1) {
/* Target location does not have a stack, so give the target our current stack */
copyStack(liveStack, targetStack);
verifyData->unwalkedQueue[verifyData->unwalkedQueueTail++] = target;
verifyData->unwalkedQueueTail %= (verifyData->rootQueueSize / sizeof(UDATA));
bytecodeMap[target] |= BRANCH_ON_UNWALKED_QUEUE;
Trc_BCV_mergeStacks_CopyStack(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
stackIndex, target, target);
goto _finished;
} else {
UDATA mergePC = (UDATA) -1;
U_32 resultArrayBase;
/* Check stack size equality */
if (targetStack->stackTopIndex != liveStack->stackTopIndex) {
rc = BCV_FAIL;
Trc_BCV_mergeStacks_DepthMismatch(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
stackIndex, target, target,
liveStack->stackTopIndex, targetStack->stackTopIndex);
goto _finished;
}
/* Now we have to merge stacks */
targetStackPtr = targetStack->stackElements;
targetStackTop = RELOAD_STACKTOP(targetStack);
sourceStackPtr = liveStack->stackElements;
sourceStackTop = RELOAD_STACKTOP(liveStack);
/* remember where the temps end */
sourceStackTemps = RELOAD_STACKBASE(liveStack);
Trc_BCV_mergeStacks_MergeStacks(verifyData->vmStruct,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(verifyData->romClass)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_NAME(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_NAME(verifyData->romMethod)),
(UDATA) J9UTF8_LENGTH(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
J9UTF8_DATA(J9ROMMETHOD_SIGNATURE(verifyData->romMethod)),
stackIndex, target, target);
while (sourceStackPtr != sourceStackTop) {
/* Merge if the source and target slots are not identical */
if (*sourceStackPtr != *targetStackPtr) {
UDATA sourceItem = *sourceStackPtr;
UDATA targetItem = *targetStackPtr;
/* Merge in the locals */
if (sourceStackPtr < sourceStackTemps ) {
/* Merge when either the source or target not an object */
if ((sourceItem | targetItem) & (BCV_BASE_OR_SPECIAL)) {
/* Mismatch results in undefined local - rewalk if modified stack */
if (*targetStackPtr != (UDATA) (BCV_BASE_TYPE_TOP)) {
*targetStackPtr = (UDATA) (BCV_BASE_TYPE_TOP);
rewalk = TRUE;
}
/* Merge two objects */
} else {
/* extra checks here to avoid calling local mapper unnecessarily */
/* Null source or java/lang/Object targets always work trivially */
if ((*sourceStackPtr != BCV_BASE_TYPE_NULL) && (*targetStackPtr != (BCV_JAVA_LANG_OBJECT_INDEX << BCV_CLASS_INDEX_SHIFT))) {
/* Null target always causes a re-walk - source is never null here */
if (*targetStackPtr == BCV_BASE_TYPE_NULL) {
*targetStackPtr = *sourceStackPtr;
rewalk = TRUE;
} else {
/* Use local mapper to check merge necessity in locals */
if ((verifyData->verificationFlags & J9_VERIFY_OPTIMIZE) && (maxIndex <= 32)) {
/* Only handle 32 locals or less */
UDATA index = (UDATA) (sourceStackPtr - liveStack->stackElements);
/* Reuse map in this merge if needed for multiple merges at same map */
if (mergePC == ((UDATA) -1)) {
mergePC = target;
if (j9localmap_LocalBitsForPC(verifyData->portLib, romClass, romMethod, mergePC, &resultArrayBase, NULL, NULL, NULL) != 0) {
/* local map error - force a full merge */
resultArrayBase = (U_32) -1;
}
}
if (resultArrayBase & (1 << index)) {
UDATA origSource = *sourceStackPtr;
UDATA origTarget = *targetStackPtr;
IDATA tempRC = mergeObjectTypes(verifyData, *sourceStackPtr, targetStackPtr);
/* Merge the objects - the result is live */
if (BCV_FAIL == tempRC) {
rewalk = TRUE;
} else if (BCV_ERR_INSUFFICIENT_MEMORY == tempRC) {
rc = BCV_ERR_INSUFFICIENT_MEMORY;
goto _finished;