-
Notifications
You must be signed in to change notification settings - Fork 746
/
Copy pathClassFileOracle.cpp
2819 lines (2556 loc) · 112 KB
/
ClassFileOracle.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 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
*******************************************************************************/
/*
* ClassFileOracle.cpp
*/
#include "ClassFileOracle.hpp"
#include "BufferManager.hpp"
#include "ConstantPoolMap.hpp"
#include "ROMClassCreationContext.hpp"
#include "ROMClassVerbosePhase.hpp"
#include "j9port.h"
#include "jbcmap.h"
#include "ut_j9bcu.h"
#include "util_api.h"
#include "j9protos.h"
/* The array entries must be in same order as the enums in ClassFileOracle.hpp */
ClassFileOracle::KnownAnnotation ClassFileOracle::_knownAnnotations[] = {
#define FRAMEITERATORSKIP_SIGNATURE "Ljava/lang/invoke/MethodHandle$FrameIteratorSkip;"
{FRAMEITERATORSKIP_SIGNATURE, sizeof(FRAMEITERATORSKIP_SIGNATURE)},
#undef FRAMEITERATORSKIP_SIGNATURE
#define SUN_REFLECT_CALLERSENSITIVE_SIGNATURE "Lsun/reflect/CallerSensitive;"
{SUN_REFLECT_CALLERSENSITIVE_SIGNATURE, sizeof(SUN_REFLECT_CALLERSENSITIVE_SIGNATURE)},
#undef SUN_REFLECT_CALLERSENSITIVE_SIGNATURE
#define JDK_INTERNAL_REFLECT_CALLERSENSITIVE_SIGNATURE "Ljdk/internal/reflect/CallerSensitive;"
{JDK_INTERNAL_REFLECT_CALLERSENSITIVE_SIGNATURE, sizeof(JDK_INTERNAL_REFLECT_CALLERSENSITIVE_SIGNATURE)},
#undef JDK_INTERNAL_REFLECT_CALLERSENSITIVE_SIGNATURE
#if JAVA_SPEC_VERSION >= 18
#define JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_SIGNATURE "Ljdk/internal/reflect/CallerSensitiveAdapter;"
{JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_SIGNATURE, sizeof(JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_SIGNATURE)},
#undef JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_SIGNATURE
#endif /* JAVA_SPEC_VERSION >= 18 */
#define JAVA8_CONTENDED_SIGNATURE "Lsun/misc/Contended;" /* TODO remove this if VM does not support Java 8 */
{JAVA8_CONTENDED_SIGNATURE, sizeof(JAVA8_CONTENDED_SIGNATURE)},
#undef JAVA8_CONTENDED_SIGNATURE
#define CONTENDED_SIGNATURE "Ljdk/internal/vm/annotation/Contended;"
{CONTENDED_SIGNATURE, sizeof(CONTENDED_SIGNATURE)},
#undef CONTENDED_SIGNATURE
{J9_UNMODIFIABLE_CLASS_ANNOTATION, sizeof(J9_UNMODIFIABLE_CLASS_ANNOTATION)},
#define VALUEBASED_SIGNATURE "Ljdk/internal/ValueBased;"
{VALUEBASED_SIGNATURE, sizeof(VALUEBASED_SIGNATURE)},
#undef VALUEBASED_SIGNATURE
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
#if JAVA_SPEC_VERSION >= 16
#define HIDDEN_SIGNATURE "Ljdk/internal/vm/annotation/Hidden;"
#else /* JAVA_SPEC_VERSION >= 16 */
#define HIDDEN_SIGNATURE "Ljava/lang/invoke/LambdaForm$Hidden;"
#endif /* JAVA_SPEC_VERSION >= 16 */
{HIDDEN_SIGNATURE, sizeof(HIDDEN_SIGNATURE)},
#undef HIDDEN_SIGNATURE
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
#if JAVA_SPEC_VERSION >= 16
#define SCOPED_SIGNATURE "Ljdk/internal/misc/ScopedMemoryAccess$Scoped;"
{SCOPED_SIGNATURE, sizeof(SCOPED_SIGNATURE)},
#undef SCOPED_SIGNATURE
#endif /* JAVA_SPEC_VERSION >= 16 */
#if defined(J9VM_OPT_CRIU_SUPPORT)
#define NOTCHECKPOINTSAFE_SIGNATURE "Lopenj9/internal/criu/NotCheckpointSafe;"
{NOTCHECKPOINTSAFE_SIGNATURE, sizeof(NOTCHECKPOINTSAFE_SIGNATURE)},
#undef NOTCHECKPOINTSAFE_SIGNATURE
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
#if JAVA_SPEC_VERSION >= 20
#define JVMTIMOUNTTRANSITION_SIGNATURE "Ljdk/internal/vm/annotation/JvmtiMountTransition;"
{JVMTIMOUNTTRANSITION_SIGNATURE , sizeof(JVMTIMOUNTTRANSITION_SIGNATURE)},
#undef JVMTIMOUNTTRANSITION_SIGNATURE
#endif /* JAVA_SPEC_VERSION >= 20 */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
#define NULLRESTRICTED_SIGNATURE "Ljdk/internal/vm/annotation/NullRestricted;"
{NULLRESTRICTED_SIGNATURE , sizeof(NULLRESTRICTED_SIGNATURE)},
#undef NULLRESTRICTED_SIGNATURE
#define IMPLICITLYCONSTRUCTIBLE_SIGNATURE "Ljdk/internal/vm/annotation/ImplicitlyConstructible;"
{IMPLICITLYCONSTRUCTIBLE_SIGNATURE , sizeof(IMPLICITLYCONSTRUCTIBLE_SIGNATURE)},
#undef IMPLICITLYCONSTRUCTIBLE_SIGNATURE
#define LOOSELYCONSISTENTVALUE_SIGNATURE "Ljdk/internal/vm/annotation/LooselyConsistentValue;"
{LOOSELYCONSISTENTVALUE_SIGNATURE , sizeof(LOOSELYCONSISTENTVALUE_SIGNATURE)},
#undef LOOSELYCONSISTENTVALUE_SIGNATURE
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
{0, 0}
};
bool
ClassFileOracle::containsKnownAnnotation(UDATA knownAnnotationSet, UDATA knownAnnotation)
{
UDATA knownAnnotationBit = (UDATA) 1 << knownAnnotation;
return (knownAnnotationSet & knownAnnotationBit) == knownAnnotationBit;
}
UDATA
ClassFileOracle::addAnnotationBit(UDATA annotationBits, UDATA knownAnnotation)
{
UDATA knownAnnotationBit = (UDATA) 1 << knownAnnotation;
return annotationBits |= knownAnnotationBit;
}
U_16
ClassFileOracle::LocalVariablesIterator::getGenericSignatureIndex()
{
Trc_BCU_Assert_NotEquals(NULL, _localVariableTable);
Trc_BCU_Assert_NotEquals(NULL, _localVariablesInfo[_index].localVariableTypeTableAttribute);
/* If the localVariableTable and localVariableTypeTable are in the same order, return the signatureIndex */
J9CfrLocalVariableTypeTableEntry* localVariableTypeTable = _localVariablesInfo[_index].localVariableTypeTableAttribute->localVariableTypeTable;
if ((_localVariableTableIndex < _localVariablesInfo[_index].localVariableTypeTableAttribute->localVariableTypeTableLength)
&& (_localVariableTable[_localVariableTableIndex].index == localVariableTypeTable[_localVariableTableIndex].index)
&& (_localVariableTable[_localVariableTableIndex].startPC == localVariableTypeTable[_localVariableTableIndex].startPC)
&& (_localVariableTable[_localVariableTableIndex].length == localVariableTypeTable[_localVariableTableIndex].length)) {
return localVariableTypeTable[_localVariableTableIndex].signatureIndex;
}
/* Scan for matching localVariableTypeTable entry */
for (U_16 localVariableTypeTableIndex = 0;
localVariableTypeTableIndex < _localVariablesInfo[_index].localVariableTypeTableAttribute->localVariableTypeTableLength;
++localVariableTypeTableIndex) {
if ((_localVariableTable[_localVariableTableIndex].index == localVariableTypeTable[localVariableTypeTableIndex].index)
&& (_localVariableTable[_localVariableTableIndex].startPC == localVariableTypeTable[localVariableTypeTableIndex].startPC)
&& (_localVariableTable[_localVariableTableIndex].length == localVariableTypeTable[localVariableTypeTableIndex].length)) {
return localVariableTypeTable[localVariableTypeTableIndex].signatureIndex;
}
}
Trc_BCU_Assert_ShouldNeverHappen();
return 0;
}
bool
ClassFileOracle::LocalVariablesIterator::hasGenericSignature()
{
Trc_BCU_Assert_NotEquals(NULL, _localVariableTable);
/* Check if the current local variable isn't generic */
if (NULL == _localVariablesInfo[_index].localVariableTypeTableAttribute) {
return false;
}
/* Check if the localVariableTable and localVariableTypeTable are in the same order */
J9CfrLocalVariableTypeTableEntry* localVariableTypeTable = _localVariablesInfo[_index].localVariableTypeTableAttribute->localVariableTypeTable;
if ((_localVariableTableIndex < _localVariablesInfo[_index].localVariableTypeTableAttribute->localVariableTypeTableLength)
&& (_localVariableTable[_localVariableTableIndex].index == localVariableTypeTable[_localVariableTableIndex].index)
&& (_localVariableTable[_localVariableTableIndex].startPC == localVariableTypeTable[_localVariableTableIndex].startPC)
&& (_localVariableTable[_localVariableTableIndex].length == localVariableTypeTable[_localVariableTableIndex].length)) {
return true;
}
/* Scan for matching localVariableTypeTable entry */
for (U_16 localVariableTypeTableIndex = 0;
localVariableTypeTableIndex < _localVariablesInfo[_index].localVariableTypeTableAttribute->localVariableTypeTableLength;
++localVariableTypeTableIndex) {
if ((_localVariableTable[_localVariableTableIndex].index == localVariableTypeTable[localVariableTypeTableIndex].index)
&& (_localVariableTable[_localVariableTableIndex].startPC == localVariableTypeTable[localVariableTypeTableIndex].startPC)
&& (_localVariableTable[_localVariableTableIndex].length == localVariableTypeTable[localVariableTypeTableIndex].length)) {
return true;
}
}
return false;
}
ClassFileOracle::ClassFileOracle(BufferManager *bufferManager, J9CfrClassFile *classFile, ConstantPoolMap *constantPoolMap,
U_8 * verifyExcludeAttribute, U_8 * romBuilderClassFileBuffer, ROMClassCreationContext *context) :
_buildResult(OK),
_bufferManager(bufferManager),
_classFile(classFile),
_constantPoolMap(constantPoolMap),
_verifyExcludeAttribute(verifyExcludeAttribute),
_romBuilderClassFileBuffer(romBuilderClassFileBuffer),
_context(context),
_singleScalarStaticCount(0),
_objectStaticCount(0),
_doubleScalarStaticCount(0),
_memberAccessFlags(0),
_innerClassCount(0),
_enclosedInnerClassCount(0),
#if JAVA_SPEC_VERSION >= 11
_nestMembersCount(0),
_nestHost(0),
#endif /* JAVA_SPEC_VERSION >= 11 */
_maxBranchCount(1), /* This is required to support buffer size calculations for stackmap support code */
_outerClassNameIndex(0),
_simpleNameIndex(0),
_hasEmptyFinalizeMethod(false),
_hasFinalFields(false),
_hasNonStaticNonAbstractMethods(false),
_hasFinalizeMethod(false),
_isCloneable(false),
_isSerializable(false),
_isSynthetic(false),
_hasVerifyExcludeAttribute(false),
_hasFrameIteratorSkipAnnotation(false),
_hasClinit(false),
_annotationRefersDoubleSlotEntry(false),
_fieldsInfo(NULL),
_methodsInfo(NULL),
_recordComponentsInfo(NULL),
_genericSignature(NULL),
_enclosingMethod(NULL),
_sourceFile(NULL),
_sourceDebugExtension(NULL),
_annotationsAttribute(NULL),
_typeAnnotationsAttribute(NULL),
_innerClasses(NULL),
_bootstrapMethodsAttribute(NULL),
#if JAVA_SPEC_VERSION >= 11
_nestMembers(NULL),
#endif /* JAVA_SPEC_VERSION >= 11 */
_isClassContended(false),
_isClassUnmodifiable(context->isClassUnmodifiable()),
_isInnerClass(false),
_needsStaticConstantInit(false),
_isRecord(false),
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
_hasNonStaticSynchronizedMethod(false),
_loadableDescriptorsAttribute(NULL),
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
_hasImplicitCreationAttribute(false),
_implicitCreationFlags(0),
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
_recordComponentCount(0),
_permittedSubclassesAttribute(NULL),
_isSealed(false),
_isClassValueBased(false)
{
Trc_BCU_Assert_NotEquals( classFile, NULL );
ROMClassVerbosePhase v(_context, ClassFileAnalysis, &_buildResult);
/* Quick check against expected class name */
_buildResult = _context->checkClassName(getUTF8Data(getClassNameIndex()), getUTF8Length(getClassNameIndex()));
if (OK != _buildResult) {
return;
}
_fieldsInfo = (FieldInfo *) _bufferManager->alloc(getFieldsCount() * sizeof(FieldInfo));
_methodsInfo = (MethodInfo *) _bufferManager->alloc(getMethodsCount() * sizeof(MethodInfo));
if ( (NULL == _fieldsInfo) || (NULL == _methodsInfo) ) {
Trc_BCU_ClassFileOracle_OutOfMemory((U_32)getUTF8Length(getClassNameIndex()), getUTF8Data(getClassNameIndex()));
_buildResult = OutOfMemory;
return;
}
memset(_fieldsInfo, 0, getFieldsCount() * sizeof(FieldInfo));
memset(_methodsInfo, 0, getMethodsCount() * sizeof(MethodInfo));
_constantPoolMap->setClassFileOracleAndInitialize(this);
if ( !constantPoolMap->isOK() ) {
_buildResult = _constantPoolMap->getBuildResult();
return;
}
/* analyze class file */
if (OK == _buildResult) {
walkHeader();
}
if (OK == _buildResult) {
walkAttributes();
}
if (_context->isClassHidden()) {
checkHiddenClass();
}
if (OK == _buildResult) {
walkInterfaces();
}
if (OK == _buildResult) {
walkMethods();
}
if (OK == _buildResult) {
walkFields();
}
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
if (OK == _buildResult) {
if (J9_IS_CLASSFILE_VALUETYPE(_classFile)) {
if (_hasNonStaticSynchronizedMethod) {
_buildResult = InvalidValueType;
}
}
}
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
if (OK == _buildResult) {
_constantPoolMap->computeConstantPoolMapAndSizes();
if (!constantPoolMap->isOK()) {
_buildResult = _constantPoolMap->getBuildResult();
} else {
#if defined(J9VM_OPT_METHOD_HANDLE)
/* computeConstantPoolMapAndSizes must complete successfully before calling findVarHandleMethodRefs */
_constantPoolMap->findVarHandleMethodRefs();
if (!constantPoolMap->isOK()) {
_buildResult = _constantPoolMap->getBuildResult();
}
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
}
}
}
ClassFileOracle::~ClassFileOracle()
{
if (NULL != _methodsInfo && OutOfMemory != _buildResult) {
for (U_16 methodIndex = 0; methodIndex < _classFile->methodsCount; ++methodIndex) {
_bufferManager->free(_methodsInfo[methodIndex].stackMapFramesInfo);
_bufferManager->free(_methodsInfo[methodIndex].localVariablesInfo);
_bufferManager->free(_methodsInfo[methodIndex].lineNumbersInfoCompressed);
}
}
_bufferManager->free(_methodsInfo);
_bufferManager->free(_fieldsInfo);
}
void
ClassFileOracle::walkHeader()
{
ROMClassVerbosePhase v(_context, ClassFileHeaderAnalysis);
markConstantUTF8AsReferenced(getClassNameIndex());
U_16 superClassNameIndex = getSuperClassNameIndex();
if (0 != superClassNameIndex) { /* java/lang/Object has no super class */
markConstantUTF8AsReferenced(superClassNameIndex);
}
}
void
ClassFileOracle::walkFields()
{
ROMClassVerbosePhase v(_context, ClassFileFieldsAnalysis);
U_16 fieldsCount = getFieldsCount();
/* CMVC 197718 : After the first compliance offense is detected, if we do not stop, annotations on subsequent fields
* will not be parsed, resulting in all subsequent valid fields to be noted as not having proper @Length annotation, hence overwriting
* the good error message. Checking (OK == _buildResult) in for-loop condition achieves the desired error handling behavior.
*/
for (U_16 fieldIndex = 0; (OK == _buildResult) && (fieldIndex < fieldsCount); fieldIndex++) {
J9CfrField *field = &_classFile->fields[fieldIndex];
U_8 fieldChar = _classFile->constantPool[field->descriptorIndex].bytes[0];
bool isStatic = (0 != (field->accessFlags & CFR_ACC_STATIC));
markConstantUTF8AsReferenced(field->nameIndex);
markConstantUTF8AsReferenced(field->descriptorIndex);
if (isStatic) {
if (NULL != field->constantValueAttribute) {
_needsStaticConstantInit = true;
U_16 constantValueIndex = field->constantValueAttribute->constantValueIndex;
if (CFR_CONSTANT_String == _classFile->constantPool[constantValueIndex].tag) {
markStringAsReferenced(constantValueIndex);
}
}
if ((IS_CLASS_SIGNATURE(fieldChar))
|| ('[' == fieldChar)
) {
_objectStaticCount++;
} else if (('D' == fieldChar) || ('J' == fieldChar)) {
_doubleScalarStaticCount++;
} else {
_singleScalarStaticCount++;
}
} else {
if (0 != (field->accessFlags & CFR_ACC_FINAL)) {
/* if the class has any final instance fields, mark it so that we can generate
* the appropriate memory barriers when its constructors run. See
* JBreturnFromConstructor
*/
_hasFinalFields = true;
}
}
for (U_16 attributeIndex = 0; (OK == _buildResult) && (attributeIndex < field->attributesCount); ++attributeIndex) {
J9CfrAttribute * attrib = field->attributes[attributeIndex];
switch (attrib->tag) {
case CFR_ATTRIBUTE_Signature: {
J9CfrAttributeSignature *signature = (J9CfrAttributeSignature *) attrib;
markConstantUTF8AsReferenced(signature->signatureIndex);
_fieldsInfo[fieldIndex].hasGenericSignature = true;
_fieldsInfo[fieldIndex].genericSignatureIndex = signature->signatureIndex;
break;
}
case CFR_ATTRIBUTE_Synthetic:
_fieldsInfo[fieldIndex].isSynthetic = true;
break;
case CFR_ATTRIBUTE_RuntimeVisibleAnnotations: {
J9CfrAttributeRuntimeVisibleAnnotations *attribAnnotations = (J9CfrAttributeRuntimeVisibleAnnotations *)attrib;
UDATA knownAnnotations = 0;
if ((NULL != _context->javaVM()) && (J9_ARE_ALL_BITS_SET(_context->javaVM()->extendedRuntimeFlags, J9_EXTENDED_RUNTIME_ALLOW_CONTENDED_FIELDS)) &&
(_context->isBootstrapLoader() || (J9_ARE_ALL_BITS_SET(_context->javaVM()->extendedRuntimeFlags, J9_EXTENDED_RUNTIME_ALLOW_APPLICATION_CONTENDED_FIELDS)))) {
knownAnnotations = addAnnotationBit(knownAnnotations, CONTENDED_ANNOTATION);
knownAnnotations = addAnnotationBit(knownAnnotations, JAVA8_CONTENDED_ANNOTATION);
}
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
knownAnnotations = addAnnotationBit(knownAnnotations, NULLRESTRICTED_ANNOTATION);
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
if (0 == attribAnnotations->rawDataLength) {
UDATA foundAnnotations = walkAnnotations(attribAnnotations->numberOfAnnotations, attribAnnotations->annotations, knownAnnotations);
if (containsKnownAnnotation(foundAnnotations, CONTENDED_ANNOTATION) || containsKnownAnnotation(foundAnnotations, JAVA8_CONTENDED_ANNOTATION)) {
_fieldsInfo[fieldIndex].isFieldContended = true;
}
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (containsKnownAnnotation(foundAnnotations, NULLRESTRICTED_ANNOTATION)) {
if (!IS_CLASS_SIGNATURE(fieldChar)) {
if ('[' == fieldChar) {
throwGenericErrorWithCustomMsg(J9NLS_CFR_NO_NULLRESTRICTED_IN_ARRAYFIELD__ID, fieldIndex);
} else { /* primitive type */
throwGenericErrorWithCustomMsg(J9NLS_CFR_NO_NULLRESTRICTED_IN_PRIMITIVEFIELD__ID, fieldIndex);
}
}
_fieldsInfo[fieldIndex].isNullRestricted = true;
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
}
_fieldsInfo[fieldIndex].annotationsAttribute = attribAnnotations;
break;
}
case CFR_ATTRIBUTE_RuntimeVisibleTypeAnnotations: {
J9CfrAttributeRuntimeVisibleTypeAnnotations *typeAnnotations = (J9CfrAttributeRuntimeVisibleTypeAnnotations *)attrib;
if (0 == typeAnnotations->rawDataLength) { /* rawDataLength non-zero in case of error in the attribute */
walkTypeAnnotations(typeAnnotations->numberOfAnnotations, typeAnnotations->typeAnnotations);
}
_fieldsInfo[fieldIndex].typeAnnotationsAttribute = typeAnnotations;
break;
}
case CFR_ATTRIBUTE_ConstantValue:
/* Fall through */
case CFR_ATTRIBUTE_Deprecated:
/* Do nothing */
break;
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
case CFR_ATTRIBUTE_NullRestricted:
/* JVMS: There must not be a NullRestricted attribute in the attributes table of a field_info
* structure whose descriptor_index references a primitive type or an array type.*/
if (!IS_CLASS_SIGNATURE(fieldChar)) {
if ('[' == fieldChar) {
throwGenericErrorWithCustomMsg(J9NLS_CFR_NO_NULLRESTRICTED_IN_ARRAYFIELD__ID, fieldIndex);
} else { /* primitive type */
throwGenericErrorWithCustomMsg(J9NLS_CFR_NO_NULLRESTRICTED_IN_PRIMITIVEFIELD__ID, fieldIndex);
}
}
_fieldsInfo[fieldIndex].isNullRestricted = true;
break;
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
default:
Trc_BCU_ClassFileOracle_walkFields_UnknownAttribute((U_32)attrib->tag, (U_32)getUTF8Length(attrib->nameIndex), getUTF8Data(attrib->nameIndex), attrib->length);
break;
}
}
}
}
void
ClassFileOracle::walkAttributes()
{
ROMClassVerbosePhase v(_context, ClassFileAttributesAnalysis);
for (U_16 attributeIndex = 0; attributeIndex < _classFile->attributesCount; attributeIndex++) {
J9CfrAttribute *attrib = _classFile->attributes[attributeIndex];
switch (attrib->tag) {
case CFR_ATTRIBUTE_InnerClasses: {
J9CfrAttributeInnerClasses *classes = (J9CfrAttributeInnerClasses*)attrib;
U_16 thisClassUTF8 = UTF8_INDEX_FROM_CLASS_INDEX(_classFile->constantPool, _classFile->thisClass);
for (U_16 classIndex = 0; classIndex < classes->numberOfClasses; classIndex++) {
J9CfrClassesEntry *entry = &(classes->classes[classIndex]);
U_16 outerClassUTF8 = UTF8_INDEX_FROM_CLASS_INDEX(_classFile->constantPool, entry->outerClassInfoIndex);
U_16 innerClassUTF8 = UTF8_INDEX_FROM_CLASS_INDEX(_classFile->constantPool, entry->innerClassInfoIndex);
/* In some cases, there might be two entries for the same class.
* But the UTF8 classname entry will be only one.
* Therefore comparing the UTF8 will find the matches, while comparing the class entries will not
*/
if (outerClassUTF8 == thisClassUTF8) {
/* Member class - mark the class' name. */
markClassNameAsReferenced(entry->innerClassInfoIndex);
_innerClassCount += 1;
} else if (innerClassUTF8 == thisClassUTF8) {
_isInnerClass = true;
_memberAccessFlags = entry->innerClassAccessFlags;
/* We are an inner class - a member? */
if (entry->outerClassInfoIndex != 0) {
/* We are a member class - mark the outer class name. */
markClassNameAsReferenced(entry->outerClassInfoIndex);
_outerClassNameIndex = outerClassUTF8;
}
if (entry->innerNameIndex != 0) {
/* mark the simple class name of member, local, and anonymous classes */
markConstantUTF8AsReferenced(entry->innerNameIndex);
_simpleNameIndex = entry->innerNameIndex;
}
} else {
/* Count all entries in the InnerClass attribute (except the inner class itself) so as
* to check the InnerClass attribute between the inner classes and the enclosing class.
* See getDeclaringClass() for details.
*/
markClassNameAsReferenced(entry->innerClassInfoIndex);
_enclosedInnerClassCount += 1;
}
}
Trc_BCU_Assert_Equals(NULL, _innerClasses);
_innerClasses = classes;
break;
}
case CFR_ATTRIBUTE_Signature:
_genericSignature = (J9CfrAttributeSignature *)attrib;
markConstantUTF8AsReferenced(_genericSignature->signatureIndex);
break;
case CFR_ATTRIBUTE_EnclosingMethod:
_enclosingMethod = (J9CfrAttributeEnclosingMethod *)attrib;
markClassAsReferenced(_enclosingMethod->classIndex);
if (0 != _enclosingMethod->methodIndex) {
markNameAndDescriptorAsReferenced(_enclosingMethod->methodIndex);
}
break;
case CFR_ATTRIBUTE_Synthetic:
_isSynthetic = true;
break;
case CFR_ATTRIBUTE_SourceFile:
if (!hasSourceFile() && _context->shouldPreserveSourceFileName()) {
_sourceFile = (J9CfrAttributeSourceFile *)attrib;
markConstantUTF8AsReferenced(_sourceFile->sourceFileIndex);
}
break;
case CFR_ATTRIBUTE_SourceDebugExtension:
if (!hasSourceDebugExtension()) {
_sourceDebugExtension = (J9CfrAttributeUnknown *)attrib;
}
break;
case CFR_ATTRIBUTE_RuntimeVisibleAnnotations: {
UDATA knownAnnotations = 0;
if ((NULL != _context->javaVM()) && J9_ARE_ALL_BITS_SET(_context->javaVM()->extendedRuntimeFlags, J9_EXTENDED_RUNTIME_ALLOW_CONTENDED_FIELDS) &&
(_context->isBootstrapLoader() || (J9_ARE_ALL_BITS_SET(_context->javaVM()->extendedRuntimeFlags, J9_EXTENDED_RUNTIME_ALLOW_APPLICATION_CONTENDED_FIELDS)))) {
knownAnnotations = addAnnotationBit(knownAnnotations, CONTENDED_ANNOTATION);
knownAnnotations = addAnnotationBit(knownAnnotations, JAVA8_CONTENDED_ANNOTATION);
}
knownAnnotations = addAnnotationBit(knownAnnotations, UNMODIFIABLE_ANNOTATION);
knownAnnotations = addAnnotationBit(knownAnnotations, VALUEBASED_ANNOTATION);
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
knownAnnotations = addAnnotationBit(knownAnnotations, IMPLICITLYCONSTRUCTIBLE_ANNOTATION);
knownAnnotations = addAnnotationBit(knownAnnotations, LOOSELYCONSISTENTVALUE_ANNOTATION);
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
_annotationsAttribute = (J9CfrAttributeRuntimeVisibleAnnotations *)attrib;
if (0 == _annotationsAttribute->rawDataLength) {
UDATA foundAnnotations = walkAnnotations(_annotationsAttribute->numberOfAnnotations, _annotationsAttribute->annotations, knownAnnotations);
if (containsKnownAnnotation(foundAnnotations, CONTENDED_ANNOTATION) || containsKnownAnnotation(foundAnnotations, JAVA8_CONTENDED_ANNOTATION)) {
_isClassContended = true;
}
if (containsKnownAnnotation(foundAnnotations, UNMODIFIABLE_ANNOTATION)) {
_isClassUnmodifiable = true;
}
if (containsKnownAnnotation(foundAnnotations, VALUEBASED_ANNOTATION)) {
_isClassValueBased = true;
}
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
if (containsKnownAnnotation(foundAnnotations, IMPLICITLYCONSTRUCTIBLE_ANNOTATION)) {
_hasImplicitCreationAttribute = true;
_implicitCreationFlags |= J9AccImplicitCreateHasDefaultValue;
}
if (containsKnownAnnotation(foundAnnotations, LOOSELYCONSISTENTVALUE_ANNOTATION)) {
_hasImplicitCreationAttribute = true;
_implicitCreationFlags |= J9AccImplicitCreateNonAtomic;
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
}
break;
}
case CFR_ATTRIBUTE_RuntimeVisibleTypeAnnotations: {
J9CfrAttributeRuntimeVisibleTypeAnnotations *typeAnnotations = (J9CfrAttributeRuntimeVisibleTypeAnnotations *)attrib;
if (0 == typeAnnotations->rawDataLength) { /* rawDataLength non-zero in case of error in the attribute */
walkTypeAnnotations(typeAnnotations->numberOfAnnotations, typeAnnotations->typeAnnotations);
}
_typeAnnotationsAttribute = typeAnnotations;
break;
}
case CFR_ATTRIBUTE_BootstrapMethods: {
_bootstrapMethodsAttribute = (J9CfrAttributeBootstrapMethods *)attrib;
for (U_16 methodIndex = 0; methodIndex < _bootstrapMethodsAttribute->numberOfBootstrapMethods; methodIndex++) {
J9CfrBootstrapMethod *bootstrapMethod = _bootstrapMethodsAttribute->bootstrapMethods + methodIndex;
markMethodHandleAsReferenced(bootstrapMethod->bootstrapMethodIndex);
for (U_16 argumentIndex = 0; argumentIndex < bootstrapMethod->numberOfBootstrapArguments; argumentIndex++) {
U_16 argCpIndex = bootstrapMethod->bootstrapArguments[argumentIndex];
markConstantBasedOnCpType(argCpIndex, false);
}
}
break;
}
case CFR_ATTRIBUTE_Record: {
_isRecord = true;
walkRecordComponents((J9CfrAttributeRecord *)attrib);
break;
}
case CFR_ATTRIBUTE_PermittedSubclasses: {
/* PermittedSubclasses verification is for Java version >= 15 */
if ((_classFile->majorVersion > 59)
|| ((59 == _classFile->majorVersion) && (65535 == _classFile->minorVersion))
) {
_isSealed = true;
_permittedSubclassesAttribute = (J9CfrAttributePermittedSubclasses *)attrib;
for (U_16 numberOfClasses = 0; numberOfClasses < _permittedSubclassesAttribute->numberOfClasses; numberOfClasses++) {
U_16 classCpIndex = _permittedSubclassesAttribute->classes[numberOfClasses];
markClassAsReferenced(classCpIndex);
}
}
break;
}
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
case CFR_ATTRIBUTE_LoadableDescriptors: {
_loadableDescriptorsAttribute = (J9CfrAttributeLoadableDescriptors *)attrib;
for (U_16 numberOfDescriptors = 0; numberOfDescriptors < _loadableDescriptorsAttribute->numberOfDescriptors; numberOfDescriptors++) {
U_16 descriptorCpIndex = _loadableDescriptorsAttribute->descriptors[numberOfDescriptors];
markConstantUTF8AsReferenced(descriptorCpIndex);
}
break;
}
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)
case CFR_ATTRIBUTE_ImplicitCreation: {
_hasImplicitCreationAttribute = true;
_implicitCreationFlags = ((J9CfrAttributeImplicitCreation *)attrib)->implicitCreationFlags;
break;
}
#endif /* defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES) */
#if JAVA_SPEC_VERSION >= 11
case CFR_ATTRIBUTE_NestMembers:
/* ignore CFR_ATTRIBUTE_NestMembers for hidden classes, as the nest members never know the name of hidden classes */
if (!_context->isClassHidden()) {
_nestMembers = (J9CfrAttributeNestMembers *)attrib;
_nestMembersCount = _nestMembers->numberOfClasses;
/* The classRefs are never resolved & therefore do not need to
* be kept in the constant pool.
*/
for (U_16 i = 0; i < _nestMembersCount; i++) {
U_16 classNameIndex = UTF8_INDEX_FROM_CLASS_INDEX(_classFile->constantPool, _nestMembers->classes[i]);
markConstantUTF8AsReferenced(classNameIndex);
}
}
break;
case CFR_ATTRIBUTE_NestHost: {
/* Ignore CFR_ATTRIBUTE_NestHost for hidden classes, as the nest host of a hidden class is not decided by CFR_ATTRIBUTE_NestHost.
* The nesthost of a hidden class is its host class if ClassOption.NESTMATE is used or itself if ClassOption.NESTMATE is not used. */
if (!_context->isClassHidden()) {
U_16 hostClassIndex = ((J9CfrAttributeNestHost *)attrib)->hostClassIndex;
_nestHost = UTF8_INDEX_FROM_CLASS_INDEX(_classFile->constantPool, hostClassIndex);
markConstantUTF8AsReferenced(_nestHost);
}
break;
}
#endif /* JAVA_SPEC_VERSION >= 11 */
default:
Trc_BCU_ClassFileOracle_walkAttributes_UnknownAttribute((U_32)attrib->tag, (U_32)getUTF8Length(attrib->nameIndex), getUTF8Data(attrib->nameIndex), attrib->length);
break;
}
if (!_hasVerifyExcludeAttribute && (NULL != _verifyExcludeAttribute)) {
U_8 *found = (U_8 *) strstr((const char *)_verifyExcludeAttribute, (const char *)getUTF8Data(attrib->nameIndex));
if ((NULL != found)
&& ((found == _verifyExcludeAttribute) || (';' == (*(found - 1))))
&& (('\0' == found[getUTF8Length(attrib->nameIndex)]) || (';' == found[getUTF8Length(attrib->nameIndex)]))) {
_hasVerifyExcludeAttribute = true;
}
}
}
}
void
ClassFileOracle::checkHiddenClass()
{
ROMClassVerbosePhase v(_context, ClassFileAttributesAnalysis);
/* Hidden Class cannot be a record or enum. */
U_16 superClassNameIndex = getSuperClassNameIndex();
bool isEnum = false;
/**
* See test case jdk/java/lang/invoke/defineHiddenClass/BasicTest.emptyHiddenClass().
* A normal Enum cannot be defined as a hidden class. But an empty enum class that does not
* define constants of its type can still be defined as a hidden class.
* So when setting isEnum, add a check for field count.
*/
if (0 != superClassNameIndex) {
isEnum = J9_ARE_ALL_BITS_SET(_classFile->accessFlags, CFR_ACC_ENUM) &&
J9UTF8_DATA_EQUALS(getUTF8Data(superClassNameIndex), getUTF8Length(superClassNameIndex), "java/lang/Enum", LITERAL_STRLEN("java/lang/Enum")) &&
(getFieldsCount() > 0);
}
if (_isRecord || isEnum) {
PORT_ACCESS_FROM_PORT(_context->portLibrary());
char msg[] = "Hidden Class cannot be a record or enum";
UDATA len = sizeof(msg);
char *error = (char *) j9mem_allocate_memory(len, J9MEM_CATEGORY_CLASSES);
if (NULL != error) {
strcpy(error, msg);
_context->recordCFRError((U_8*)error);
}
_buildResult = InvalidClassType;
}
}
void
ClassFileOracle::walkRecordComponents(J9CfrAttributeRecord *attrib)
{
ROMClassVerbosePhase v(_context, ClassFileAttributesRecordAnalysis);
if (0 == attrib->numberOfRecordComponents) {
return;
}
_recordComponentCount = attrib->numberOfRecordComponents;
_recordComponentsInfo = (RecordComponentInfo *) _bufferManager->alloc(_recordComponentCount * sizeof(RecordComponentInfo));
if (NULL == _recordComponentsInfo) {
Trc_BCU_ClassFileOracle_OutOfMemory((U_32)getUTF8Length(getClassNameIndex()), getUTF8Data(getClassNameIndex()));
_buildResult = OutOfMemory;
return;
}
memset(_recordComponentsInfo, 0, _recordComponentCount * sizeof(RecordComponentInfo));
for (U_16 i = 0; i < _recordComponentCount; i++) {
J9CfrRecordComponent* recordComponent = &attrib->recordComponents[i];
markConstantUTF8AsReferenced(recordComponent->nameIndex);
_recordComponentsInfo[i].nameIndex = recordComponent->nameIndex;
markConstantUTF8AsReferenced(recordComponent->descriptorIndex);
_recordComponentsInfo[i].descriptorIndex = recordComponent->descriptorIndex;
/* track record component attributes */
for (U_16 j = 0; j < recordComponent->attributesCount; j++) {
J9CfrAttribute* recordComponentAttr = recordComponent->attributes[j];
switch(recordComponentAttr->tag) {
case CFR_ATTRIBUTE_Signature: {
J9CfrAttributeSignature *signature = (J9CfrAttributeSignature *) recordComponentAttr;
markConstantUTF8AsReferenced(signature->signatureIndex);
_recordComponentsInfo[i].hasGenericSignature = true;
_recordComponentsInfo[i].genericSignatureIndex = signature->signatureIndex;
break;
}
case CFR_ATTRIBUTE_RuntimeVisibleAnnotations: {
J9CfrAttributeRuntimeVisibleAnnotations *recordComponentAnnotations = (J9CfrAttributeRuntimeVisibleAnnotations *)recordComponentAttr;
if (0 == recordComponentAnnotations->rawDataLength) {
walkAnnotations(recordComponentAnnotations->numberOfAnnotations, recordComponentAnnotations->annotations, 0);
}
_recordComponentsInfo[i].annotationsAttribute = recordComponentAnnotations;
break;
}
case CFR_ATTRIBUTE_RuntimeVisibleTypeAnnotations: {
J9CfrAttributeRuntimeVisibleTypeAnnotations *recordComponentTypeAnnotations = (J9CfrAttributeRuntimeVisibleTypeAnnotations *)recordComponentAttr;
if (0 == recordComponentTypeAnnotations->rawDataLength) {
walkTypeAnnotations(recordComponentTypeAnnotations->numberOfAnnotations, recordComponentTypeAnnotations->typeAnnotations);
}
_recordComponentsInfo[i].typeAnnotationsAttribute = recordComponentTypeAnnotations;
break;
}
default:
Trc_BCU_ClassFileOracle_walkRecordComponents_UnknownAttribute((U_32)attrib->tag, (U_32)getUTF8Length(attrib->nameIndex), getUTF8Data(attrib->nameIndex), attrib->length);
break;
}
}
}
}
class ClassFileOracle::InterfaceVisitor : public ClassFileOracle::ConstantPoolIndexVisitor
{
public:
InterfaceVisitor(ClassFileOracle *classFileOracle, ConstantPoolMap *constantPoolMap) :
_classFileOracle(classFileOracle),
_constantPoolMap(constantPoolMap),
_wasCloneableSeen(false),
_wasSerializableSeen(false)
{
}
void visitConstantPoolIndex(U_16 cpIndex)
{
_constantPoolMap->markConstantUTF8AsReferenced(cpIndex);
#define CLONEABLE_NAME "java/lang/Cloneable"
if( _classFileOracle->isUTF8AtIndexEqualToString(cpIndex, CLONEABLE_NAME, sizeof(CLONEABLE_NAME)) ) {
_wasCloneableSeen = true;
}
#undef CLONEABLE_NAME
#define SERIALIZABLE_NAME "java/io/Serializable"
if( _classFileOracle->isUTF8AtIndexEqualToString(cpIndex, SERIALIZABLE_NAME, sizeof(SERIALIZABLE_NAME)) ) {
_wasSerializableSeen = true;
}
#undef SERIALIZABLE_NAME
}
bool wasCloneableSeen() const { return _wasCloneableSeen; }
bool wasSerializableSeen() const { return _wasSerializableSeen; }
private:
ClassFileOracle *_classFileOracle;
ConstantPoolMap *_constantPoolMap;
bool _wasCloneableSeen;
bool _wasSerializableSeen;
};
void
ClassFileOracle::walkInterfaces()
{
ROMClassVerbosePhase v(_context, ClassFileInterfacesAnalysis);
InterfaceVisitor interfaceVisitor(this, _constantPoolMap);
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
interfacesDo(&interfaceVisitor, 0);
#else /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
interfacesDo(&interfaceVisitor);
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
_isCloneable = interfaceVisitor.wasCloneableSeen();
_isSerializable = interfaceVisitor.wasSerializableSeen();
}
void
ClassFileOracle::walkMethods()
{
ROMClassVerbosePhase v(_context, ClassFileMethodsAnalysis);
U_16 methodsCount = getMethodsCount();
/* We check (OK == _buildResult) because walkMethodCodeAttribute() may fail to alloc the bytecode fixup table. */
for (U_16 methodIndex = 0; (methodIndex < methodsCount) && (OK == _buildResult); ++methodIndex) {
U_16 nameIndex = _classFile->methods[methodIndex].nameIndex;
U_16 descIndex = _classFile->methods[methodIndex].descriptorIndex;
markConstantUTF8AsReferenced(nameIndex);
markConstantUTF8AsReferenced(descIndex);
walkMethodAttributes(methodIndex);
_methodsInfo[methodIndex].modifiers |= _classFile->methods[methodIndex].accessFlags;
/* Is this an empty method, a getter, a forwarder or <clinit>?
* Note that <clinit> is checked after empty, so we will consider
* classes with an empty <clinit> to not have one.
*/
if (methodIsEmpty(methodIndex)) {
_methodsInfo[methodIndex].modifiers |= J9AccEmptyMethod;
} else if (methodIsGetter(methodIndex)) {
_methodsInfo[methodIndex].modifiers |= J9AccGetterMethod;
} else if (methodIsClinit(methodIndex)) {
_hasClinit = true;
}
if (methodIsObjectConstructor(methodIndex)) {
_methodsInfo[methodIndex].modifiers |= J9AccMethodObjectConstructor;
}
/* does the method belong in vtables? */
if (methodIsVirtual(methodIndex)) {
_methodsInfo[methodIndex].modifiers |= J9AccMethodVTable;
}
/* Does this class contain non-static, non-abstract methods? */
if (!_hasNonStaticNonAbstractMethods) {
_hasNonStaticNonAbstractMethods = methodIsNonStaticNonAbstract(methodIndex);
}
/* Look for an instance selector whose name is finalize()V */
if (methodIsFinalize(methodIndex)) {
_hasFinalizeMethod = true;
/* If finalize() is empty, mark this class so it does not inherit CFR_ACC_FINALIZE_NEEDED from its superclass */
if (0 != (_methodsInfo[methodIndex].modifiers & J9AccEmptyMethod)) {
_hasEmptyFinalizeMethod = true;
}
}
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
if (!_hasNonStaticSynchronizedMethod) {
_hasNonStaticSynchronizedMethod = methodIsNonStaticSynchronized(methodIndex);
}
#endif /* defined(J9VM_OPT_VALHALLA_VALUE_TYPES) */
computeSendSlotCount(methodIndex);
walkMethodThrownExceptions(methodIndex);
walkMethodCodeAttribute(methodIndex);
walkMethodMethodParametersAttribute(methodIndex);
}
}
void
ClassFileOracle::walkMethodAttributes(U_16 methodIndex)
{
ROMCLASS_VERBOSE_PHASE_HOT(_context, ClassFileMethodAttributesAnalysis);
for (U_16 methodAttrIndex = 0; (methodAttrIndex < _classFile->methods[methodIndex].attributesCount) && (OK == _buildResult); ++methodAttrIndex){
J9CfrAttribute *attrib = _classFile->methods[methodIndex].attributes[methodAttrIndex];
switch (attrib->tag) {
case CFR_ATTRIBUTE_Synthetic:
_methodsInfo[methodIndex].modifiers |= J9AccSynthetic;
break;
case CFR_ATTRIBUTE_Signature: {
J9CfrAttributeSignature *signature = (J9CfrAttributeSignature *) attrib;
markConstantUTF8AsReferenced(signature->signatureIndex);
_methodsInfo[methodIndex].modifiers |= J9AccMethodHasGenericSignature;
_methodsInfo[methodIndex].genericSignatureIndex = signature->signatureIndex;
break;
}
case CFR_ATTRIBUTE_RuntimeVisibleAnnotations: {
UDATA knownAnnotations = 0;
knownAnnotations = addAnnotationBit(knownAnnotations, FRAMEITERATORSKIP_ANNOTATION);
knownAnnotations = addAnnotationBit(knownAnnotations, SUN_REFLECT_CALLERSENSITIVE_ANNOTATION);
knownAnnotations = addAnnotationBit(knownAnnotations, JDK_INTERNAL_REFLECT_CALLERSENSITIVE_ANNOTATION);
#if JAVA_SPEC_VERSION >= 18
knownAnnotations = addAnnotationBit(knownAnnotations, JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_ANNOTATION);
#endif /* JAVA_SPEC_VERSION >= 18*/
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
knownAnnotations = addAnnotationBit(knownAnnotations, HIDDEN_ANNOTATION);
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
#if JAVA_SPEC_VERSION >= 16
knownAnnotations = addAnnotationBit(knownAnnotations, SCOPED_ANNOTATION);
#endif /* JAVA_SPEC_VERSION >= 16*/
#if defined(J9VM_OPT_CRIU_SUPPORT)
knownAnnotations = addAnnotationBit(knownAnnotations, NOT_CHECKPOINT_SAFE_ANNOTATION);
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
#if JAVA_SPEC_VERSION >= 20
knownAnnotations = addAnnotationBit(knownAnnotations, JVMTIMOUNTTRANSITION_ANNOTATION);
#endif /* JAVA_SPEC_VERSION >= 20 */
J9CfrAttributeRuntimeVisibleAnnotations *attribAnnotations = (J9CfrAttributeRuntimeVisibleAnnotations *)attrib;
if (0 == attribAnnotations->rawDataLength) { /* rawDataLength non-zero in case of error in the attribute */
UDATA foundAnnotations = walkAnnotations(attribAnnotations->numberOfAnnotations, attribAnnotations->annotations, knownAnnotations);
if (containsKnownAnnotation(foundAnnotations, SUN_REFLECT_CALLERSENSITIVE_ANNOTATION)
|| containsKnownAnnotation(foundAnnotations, JDK_INTERNAL_REFLECT_CALLERSENSITIVE_ANNOTATION)
#if JAVA_SPEC_VERSION >= 18
|| containsKnownAnnotation(foundAnnotations, JDK_INTERNAL_REFLECT_CALLERSENSITIVEADAPTER_ANNOTATION)
#endif /* JAVA_SPEC_VERSION >= 18*/
) {
_methodsInfo[methodIndex].modifiers |= J9AccMethodCallerSensitive;
}
if (_context->isBootstrapLoader()) {
/* Only check for FrameIteratorSkip annotation on bootstrap classes */
if (containsKnownAnnotation(foundAnnotations, FRAMEITERATORSKIP_ANNOTATION)) {
_methodsInfo[methodIndex].modifiers |= J9AccMethodFrameIteratorSkip;
}
}
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
if (containsKnownAnnotation(foundAnnotations, HIDDEN_ANNOTATION)) {
/* J9AccMethodFrameIteratorSkip is reused for Hidden Annotation when OpenJDK MH is enabled
* Hidden annotation is used by OpenJDK to tag LambdaForm generated methods which is similar
* to the thunkArchetype methods as they both need to be skipped during stackwalk when
* verifying the caller
*/
_methodsInfo[methodIndex].modifiers |= J9AccMethodFrameIteratorSkip;
}
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
#if JAVA_SPEC_VERSION >= 16
if (containsKnownAnnotation(foundAnnotations, SCOPED_ANNOTATION)) {
/* J9AccMethodHasExtendedModifiers in the modifiers is set when the ROM class is written */
_methodsInfo[methodIndex].extendedModifiers |= CFR_METHOD_EXT_HAS_SCOPED_ANNOTATION;
}
#endif /* JAVA_SPEC_VERSION >= 16*/
#if defined(J9VM_OPT_CRIU_SUPPORT)
if (containsKnownAnnotation(foundAnnotations, NOT_CHECKPOINT_SAFE_ANNOTATION)) {
/* J9AccMethodHasExtendedModifiers in the modifiers is set when the ROM class is written */
_methodsInfo[methodIndex].extendedModifiers |= CFR_METHOD_EXT_NOT_CHECKPOINT_SAFE_ANNOTATION;
}
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
#if JAVA_SPEC_VERSION >= 20
if (containsKnownAnnotation(foundAnnotations, JVMTIMOUNTTRANSITION_ANNOTATION)) {
/* JvmtiMountTransition annotation is used by OpenJDK to tag methods which should be hidden for JVMTI and stackwalk */
_methodsInfo[methodIndex].extendedModifiers |= CFR_METHOD_EXT_JVMTIMOUNTTRANSITION_ANNOTATION;
}
#endif /* JAVA_SPEC_VERSION >= 20 */
}
_methodsInfo[methodIndex].annotationsAttribute = attribAnnotations;
_methodsInfo[methodIndex].modifiers |= J9AccMethodHasMethodAnnotations;
break;
}
case CFR_ATTRIBUTE_RuntimeVisibleParameterAnnotations: {
J9CfrAttributeRuntimeVisibleParameterAnnotations *attribParameterAnnotations = (J9CfrAttributeRuntimeVisibleParameterAnnotations *)attrib;
for (U_8 parameterAnnotationIndex = 0;
(parameterAnnotationIndex < attribParameterAnnotations->numberOfParameters) && (OK == _buildResult);
++parameterAnnotationIndex) {
walkAnnotations(