/
ROMClassWriter.cpp
2003 lines (1790 loc) · 74.8 KB
/
ROMClassWriter.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 (c) 2001, 2020 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
*******************************************************************************/
/*
* ROMClassWriter.cpp
*/
#include "ROMClassWriter.hpp"
#include "BufferManager.hpp"
#include "ClassFileOracle.hpp"
#include "ConstantPoolMap.hpp"
#include "Cursor.hpp"
#include "SRPKeyProducer.hpp"
#include "ROMClassVerbosePhase.hpp"
#include "bcnames.h"
#include "cfreader.h"
#include "j9.h"
#include "j9protos.h"
#include "ut_j9bcu.h"
const U_8 PARAM_VOID = 0;
const U_8 PARAM_BOOLEAN = 1;
const U_8 PARAM_BYTE = 2;
const U_8 PARAM_CHAR = 3;
const U_8 PARAM_SHORT = 4;
const U_8 PARAM_FLOAT = 5;
const U_8 PARAM_INT = 6;
const U_8 PARAM_DOUBLE = 7;
const U_8 PARAM_LONG = 8;
const U_8 PARAM_OBJECT = 9;
class ROMClassWriter::CheckSize
{
public:
CheckSize(Cursor *cursor, UDATA expectedSize) :
_cursor(cursor),
_expectedSize(expectedSize),
_start(cursor->getCount())
{
}
~CheckSize()
{
Trc_BCU_Assert_Equals(_cursor->getCount() - _start, _expectedSize);
}
private:
Cursor *_cursor;
UDATA _expectedSize;
UDATA _start;
};
class ROMClassWriter::AnnotationElementWriter : public ClassFileOracle::AnnotationElementVisitor
{
public:
AnnotationElementWriter(Cursor *cursor, ConstantPoolMap *constantPoolMap, ClassFileOracle *classFileOracle) :
_constantPoolMap(constantPoolMap),
_cursor(cursor),
_classFileOracle(classFileOracle)
{
}
virtual void visitConstant(U_16 elementNameIndex, U_16 cpIndex, U_8 elementType)
{
_cursor->writeU8(elementType, Cursor::GENERIC);
_cursor->writeBigEndianU16(_constantPoolMap->getROMClassCPIndexForAnnotation(cpIndex), Cursor::GENERIC);
}
virtual void visitEnum(U_16 elementNameIndex, U_16 typeNameIndex, U_16 constNameIndex)
{
_cursor->writeU8('e', Cursor::GENERIC);
_cursor->writeBigEndianU16(_constantPoolMap->getROMClassCPIndexForAnnotation(typeNameIndex), Cursor::GENERIC);
_cursor->writeBigEndianU16(_constantPoolMap->getROMClassCPIndexForAnnotation(constNameIndex), Cursor::GENERIC);
}
virtual void visitClass(U_16 elementNameIndex, U_16 cpIndex)
{
AnnotationElementWriter::visitConstant(elementNameIndex, cpIndex, 'c');
}
virtual void visitArray(U_16 elementNameIndex, U_16 elementCount, ClassFileOracle::ArrayAnnotationElements *arrayAnnotationElements)
{
_cursor->writeU8('[', Cursor::GENERIC);
_cursor->writeBigEndianU16(elementCount, Cursor::GENERIC);
AnnotationElementWriter annotationElementWriter(_cursor, _constantPoolMap, _classFileOracle);
arrayAnnotationElements->elementsDo(&annotationElementWriter);
}
virtual void visitNestedAnnotation(U_16 elementNameIndex, ClassFileOracle::NestedAnnotation *nestedAnnotation);
protected:
ConstantPoolMap *_constantPoolMap;
Cursor *_cursor;
ClassFileOracle *_classFileOracle;
};
class ROMClassWriter::AnnotationWriter :
public ROMClassWriter::AnnotationElementWriter,
public ClassFileOracle::AnnotationsAttributeVisitor,
public ClassFileOracle::AnnotationVisitor
{
public:
AnnotationWriter(Cursor *cursor, ConstantPoolMap *constantPoolMap, ClassFileOracle *classFileOracle) :
AnnotationElementWriter(cursor, constantPoolMap, classFileOracle)
{
}
void visitConstant(U_16 elementNameIndex, U_16 cpIndex, U_8 elementType)
{
writeElementName(elementNameIndex);
AnnotationElementWriter::visitConstant(elementNameIndex, cpIndex, elementType);
}
void visitEnum(U_16 elementNameIndex, U_16 typeNameIndex, U_16 constNameIndex)
{
writeElementName(elementNameIndex);
AnnotationElementWriter::visitEnum(elementNameIndex, typeNameIndex, constNameIndex);
}
void visitClass(U_16 elementNameIndex, U_16 cpIndex)
{
writeElementName(elementNameIndex);
AnnotationElementWriter::visitClass(elementNameIndex, cpIndex);
}
void visitArray(U_16 elementNameIndex, U_16 elementCount, ClassFileOracle::ArrayAnnotationElements *arrayAnnotationElements)
{
writeElementName(elementNameIndex);
AnnotationElementWriter::visitArray(elementNameIndex, elementCount, arrayAnnotationElements);
}
void visitNestedAnnotation(U_16 elementNameIndex, ClassFileOracle::NestedAnnotation *nestedAnnotation)
{
writeElementName(elementNameIndex);
AnnotationElementWriter::visitNestedAnnotation(elementNameIndex, nestedAnnotation);
}
void visitAnnotationsAttribute(U_16 fieldOrMethodIndex, U_32 length, U_16 numberOfAnnotations)
{
writeAnnotationAttribute(length);
_cursor->writeBigEndianU16(numberOfAnnotations, Cursor::GENERIC);
}
void visitDefaultAnnotationAttribute(U_16 fieldOrMethodIndex, U_32 length)
{
writeAnnotationAttribute(length);
}
void visitParameterAnnotationsAttribute(U_16 fieldOrMethodIndex, U_32 length, U_8 numberOfParameters)
{
writeAnnotationAttribute(length);
_cursor->writeU8(numberOfParameters, Cursor::GENERIC);
}
void visitTypeAnnotationsAttribute(U_16 fieldOrMethodIndex, U_32 length, U_16 numberOfAnnotations)
{
writeAnnotationAttribute(length);
_cursor->writeBigEndianU16(numberOfAnnotations, Cursor::GENERIC);
}
void visitAnnotation(U_16 typeIndex, U_16 elementValuePairCount)
{
_cursor->writeBigEndianU16(_constantPoolMap->getROMClassCPIndexForReference(typeIndex), Cursor::GENERIC);
_cursor->writeBigEndianU16(elementValuePairCount, Cursor::GENERIC);
}
void visitTypeAnnotation(U_8 targetType, J9CfrTypeAnnotationTargetInfo *targetInfo, J9CfrTypePath *typePath)
{
_cursor->writeU8(targetType, Cursor::GENERIC);
switch (targetType) { /* use values from the JVM spec. Java SE 8 Edition, table 4.7.20-A&B */
case CFR_TARGET_TYPE_TypeParameterGenericClass:
case CFR_TARGET_TYPE_TypeParameterGenericMethod:
_cursor->writeU8(targetInfo->typeParameterTarget.typeParameterIndex, Cursor::GENERIC);
break;
case CFR_TARGET_TYPE_TypeInExtends:
_cursor->writeBigEndianU16(targetInfo->supertypeTarget.supertypeIndex, Cursor::GENERIC);
break;
case CFR_TARGET_TYPE_TypeInBoundOfGenericClass:
case CFR_TARGET_TYPE_TypeInBoundOfGenericMethod:
_cursor->writeU8(targetInfo->typeParameterBoundTarget.typeParameterIndex, Cursor::GENERIC);
_cursor->writeU8(targetInfo->typeParameterBoundTarget.boundIndex, Cursor::GENERIC);
break;
case CFR_TARGET_TYPE_TypeInFieldDecl:
case CFR_TARGET_TYPE_ReturnType:
case CFR_TARGET_TYPE_ReceiverType: /* empty_target */
break;
case CFR_TARGET_TYPE_TypeInFormalParam:
_cursor->writeU8(targetInfo->methodFormalParameterTarget.formalParameterIndex, Cursor::GENERIC);
break;
case CFR_TARGET_TYPE_TypeInThrows:
_cursor->writeBigEndianU16(targetInfo->throwsTarget.throwsTypeIndex, Cursor::GENERIC);
break;
case CFR_TARGET_TYPE_TypeInLocalVar:
case CFR_TARGET_TYPE_TypeInResourceVar: {
J9CfrLocalvarTarget *t = &(targetInfo->localvarTarget);
_cursor->writeBigEndianU16(t->tableLength, Cursor::GENERIC);
for (U_32 ti=0; ti < t->tableLength; ++ti) {
J9CfrLocalvarTargetEntry *te = &(t->table[ti]);
_cursor->writeBigEndianU16(te->startPC, Cursor::GENERIC);
_cursor->writeBigEndianU16(te->length, Cursor::GENERIC);
_cursor->writeBigEndianU16(te->index, Cursor::GENERIC);
}
};
break;
case CFR_TARGET_TYPE_TypeInExceptionParam:
_cursor->writeBigEndianU16(targetInfo->catchTarget.exceptiontableIndex, Cursor::GENERIC);
break;
case CFR_TARGET_TYPE_TypeInInstanceof:
case CFR_TARGET_TYPE_TypeInNew:
case CFR_TARGET_TYPE_TypeInMethodrefNew:
case CFR_TARGET_TYPE_TypeInMethodrefIdentifier:
_cursor->writeBigEndianU16(targetInfo->offsetTarget.offset, Cursor::GENERIC);
break;
case CFR_TARGET_TYPE_TypeInCast:
case CFR_TARGET_TYPE_TypeForGenericConstructorInNew:
case CFR_TARGET_TYPE_TypeForGenericMethodInvocation:
case CFR_TARGET_TYPE_TypeForGenericConstructorInMethodRef:
case CFR_TARGET_TYPE_TypeForGenericMethodInvocationInMethodRef:
_cursor->writeBigEndianU16(targetInfo->typeArgumentTarget.offset, Cursor::GENERIC);
_cursor->writeU8(targetInfo->typeArgumentTarget.typeArgumentIndex, Cursor::GENERIC);
break;
default:
break;
}
_cursor->writeU8(typePath->pathLength, Cursor::GENERIC);
for (U_8 pathIndex = 0; pathIndex < typePath->pathLength; ++pathIndex) {
J9CfrTypePathEntry* pathEntry = &(typePath->path[pathIndex]);
_cursor->writeU8(pathEntry->typePathKind, Cursor::GENERIC);
_cursor->writeU8(pathEntry->typeArgumentIndex, Cursor::GENERIC);
}
}
void visitMalformedAnnotationsAttribute(U_32 rawDataLength, U_8 *rawAttributeData)
{
writeAnnotationAttribute(rawDataLength);
for (U_32 byteIndex = 0; byteIndex < rawDataLength; ++byteIndex) {
_cursor->writeU8(rawAttributeData[byteIndex], Cursor::GENERIC);
}
}
void visitParameter(U_16 numberOfAnnotations)
{
_cursor->writeBigEndianU16(numberOfAnnotations, Cursor::GENERIC);
}
private:
void writeElementName(U_16 elementNameIndex)
{
_cursor->writeBigEndianU16(_constantPoolMap->getROMClassCPIndexForReference(elementNameIndex), Cursor::GENERIC);
}
void writeAnnotationAttribute(U_32 length)
{
_cursor->writeU32(length, Cursor::GENERIC); /* Native Endian */
}
};
ROMClassWriter::ROMClassWriter(BufferManager *bufferManager, ClassFileOracle *classFileOracle, SRPKeyProducer *srpKeyProducer, ConstantPoolMap *constantPoolMap, ROMClassCreationContext *context) :
_bufferManager(bufferManager),
_classFileOracle(classFileOracle),
_srpKeyProducer(srpKeyProducer),
_constantPoolMap(constantPoolMap),
_srpOffsetTable(NULL),
_context(context),
_buildResult(OK),
_interfacesSRPKey(srpKeyProducer->generateKey()),
_methodsSRPKey(srpKeyProducer->generateKey()),
_fieldsSRPKey(srpKeyProducer->generateKey()),
_cpDescriptionShapeSRPKey(srpKeyProducer->generateKey()),
_innerClassesSRPKey(srpKeyProducer->generateKey()),
#if JAVA_SPEC_VERSION >= 11
_nestMembersSRPKey(srpKeyProducer->generateKey()),
#endif /* JAVA_SPEC_VERSION >= 11 */
_optionalInfoSRPKey(srpKeyProducer->generateKey()),
_enclosingMethodSRPKey(srpKeyProducer->generateKey()),
_sourceDebugExtensionSRPKey(srpKeyProducer->generateKey()),
_intermediateClassDataSRPKey(srpKeyProducer->generateKey()),
_annotationInfoClassSRPKey(srpKeyProducer->generateKey()),
_typeAnnotationInfoSRPKey(srpKeyProducer->generateKey()),
_recordInfoSRPKey(srpKeyProducer->generateKey()),
_callSiteDataSRPKey(srpKeyProducer->generateKey()),
_staticSplitTableSRPKey(srpKeyProducer->generateKey()),
_specialSplitTableSRPKey(srpKeyProducer->generateKey()),
_varHandleMethodTypeLookupTableSRPKey(srpKeyProducer->generateKey()),
_permittedSubclassesInfoSRPKey(srpKeyProducer->generateKey())
{
_methodNotes = (MethodNotes *) _bufferManager->alloc(classFileOracle->getMethodsCount() * sizeof(MethodNotes));
if (NULL == _methodNotes) {
_buildResult = OutOfMemory;
return;
}
memset(_methodNotes, 0, classFileOracle->getMethodsCount() * sizeof(MethodNotes));
}
ROMClassWriter::~ROMClassWriter()
{
_bufferManager->free(_methodNotes);
}
void
ROMClassWriter::writeROMClass(Cursor *cursor,
Cursor *lineNumberCursor,
Cursor *variableInfoCursor,
Cursor *utf8Cursor,
Cursor *classDataCursor,
U_32 romSize, U_32 modifiers, U_32 extraModifiers, U_32 optionalFlags,
MarkOrWrite markOrWrite)
{
bool markAndCountOnly = (MARK_AND_COUNT_ONLY== markOrWrite);
/*
* Write the J9ROMClass structure (AKA Header).
*/
if (markAndCountOnly) {
if (!_context->isIntermediateDataAClassfile()) {
if (NULL == _context->intermediateClassData()) {
/* In case intermediate data is not explicitly provided in the _context,
* ROMClass being created can itself be used as intermediateClassData.
*/
cursor->mark(_intermediateClassDataSRPKey);
} else {
_srpOffsetTable->setInternedAt(_intermediateClassDataSRPKey, _context->intermediateClassData());
}
}
cursor->skip(sizeof(J9ROMClass));
} else {
CheckSize _(cursor, sizeof(J9ROMClass));
cursor->writeU32(romSize, Cursor::ROM_SIZE);
cursor->writeU32(_classFileOracle->getSingleScalarStaticCount(), Cursor::GENERIC);
cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(_classFileOracle->getClassNameIndex()), Cursor::SRP_TO_UTF8_CLASS_NAME);
cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(_classFileOracle->getSuperClassNameIndex()), Cursor::SRP_TO_UTF8);
cursor->writeU32(modifiers, Cursor::GENERIC);
cursor->writeU32(extraModifiers, Cursor::GENERIC);
cursor->writeU32(_classFileOracle->getInterfacesCount(), Cursor::GENERIC);
cursor->writeSRP(_interfacesSRPKey, Cursor::SRP_TO_GENERIC);
cursor->writeU32(_classFileOracle->getMethodsCount(), Cursor::GENERIC);
cursor->writeSRP(_methodsSRPKey, Cursor::SRP_TO_GENERIC);
cursor->writeU32(_classFileOracle->getFieldsCount(), Cursor::GENERIC);
cursor->writeSRP(_fieldsSRPKey, Cursor::SRP_TO_GENERIC);
cursor->writeU32(_classFileOracle->getObjectStaticCount(), Cursor::GENERIC);
cursor->writeU32(_classFileOracle->getDoubleScalarStaticCount(), Cursor::GENERIC);
cursor->writeU32(_constantPoolMap->getRAMConstantPoolCount(), Cursor::GENERIC);
cursor->writeU32(_constantPoolMap->getROMConstantPoolCount(), Cursor::GENERIC);
cursor->writeWSRP(_intermediateClassDataSRPKey, Cursor::SRP_TO_INTERMEDIATE_CLASS_DATA);
if (NULL == _context->intermediateClassData()) {
/* In case intermediate data is not explicitly provided in the _context,
* ROMClass being created is itself used as intermediateClassData,
* therefore intermediateDataLength should be the ROMClass size.
*/
cursor->writeU32(romSize, Cursor::INTERMEDIATE_CLASS_DATA_LENGTH);
} else {
cursor->writeU32(_context->intermediateClassDataLength(), Cursor::INTERMEDIATE_CLASS_DATA_LENGTH);
}
cursor->writeU32(OBJECT_HEADER_SHAPE_MIXED, Cursor::GENERIC);
cursor->writeSRP(_cpDescriptionShapeSRPKey, Cursor::SRP_TO_GENERIC);
cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(_classFileOracle->getOuterClassNameIndex()), Cursor::SRP_TO_UTF8);
cursor->writeU32(_classFileOracle->getMemberAccessFlags(), Cursor::GENERIC);
cursor->writeU32(_classFileOracle->getInnerClassCount(), Cursor::GENERIC);
cursor->writeSRP(_innerClassesSRPKey, Cursor::SRP_TO_GENERIC);
#if JAVA_SPEC_VERSION >= 11
cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(_classFileOracle->getNestHostNameIndex()), Cursor::SRP_TO_UTF8);
cursor->writeU16(_classFileOracle->getNestMembersCount(), Cursor::GENERIC);
cursor->writeU16(0, Cursor::GENERIC); /* padding */
cursor->writeSRP(_nestMembersSRPKey, Cursor::SRP_TO_GENERIC);
#endif /* JAVA_SPEC_VERSION >= 11 */
cursor->writeU16(_classFileOracle->getMajorVersion(), Cursor::GENERIC);
cursor->writeU16(_classFileOracle->getMinorVersion(), Cursor::GENERIC);
cursor->writeU32(optionalFlags, Cursor::OPTIONAL_FLAGS);
cursor->writeSRP(_optionalInfoSRPKey, Cursor::SRP_TO_GENERIC);
cursor->writeU32(_classFileOracle->getMaxBranchCount(), Cursor::GENERIC);
cursor->writeU32(_constantPoolMap->getMethodTypeCount(), Cursor::GENERIC);
cursor->writeU32(_constantPoolMap->getVarHandleMethodTypeCount(), Cursor::GENERIC);
cursor->writeU32(_classFileOracle->getBootstrapMethodCount(), Cursor::GENERIC);
cursor->writeU32(_constantPoolMap->getCallSiteCount(), Cursor::GENERIC);
cursor->writeSRP(_callSiteDataSRPKey, Cursor::SRP_TO_GENERIC);
cursor->writeU32(_classFileOracle->getClassFileSize(), Cursor::CLASS_FILE_SIZE);
cursor->writeU32((U_32)_classFileOracle->getConstantPoolCount(), Cursor::GENERIC);
cursor->writeU16(_constantPoolMap->getStaticSplitEntryCount(), Cursor::GENERIC);
cursor->writeU16(_constantPoolMap->getSpecialSplitEntryCount(), Cursor::GENERIC);
cursor->writeSRP(_staticSplitTableSRPKey, Cursor::SRP_TO_GENERIC);
cursor->writeSRP(_specialSplitTableSRPKey, Cursor::SRP_TO_GENERIC);
cursor->writeSRP(_varHandleMethodTypeLookupTableSRPKey, Cursor::SRP_TO_GENERIC);
cursor->padToAlignment(sizeof(U_64), Cursor::GENERIC);
}
/*
* Write the rest of the contiguous portion of the ROMClass
*/
cursor->setClassNameIndex((_classFileOracle->getClassNameIndex()));
writeConstantPool(cursor, markAndCountOnly);
writeFields(cursor, markAndCountOnly);
writeInterfaces(cursor, markAndCountOnly);
writeInnerClasses(cursor, markAndCountOnly);
#if JAVA_SPEC_VERSION >= 11
writeNestMembers(cursor, markAndCountOnly);
#endif /* JAVA_SPEC_VERSION >= 11 */
writeNameAndSignatureBlock(cursor);
writeMethods(cursor, lineNumberCursor, variableInfoCursor, markAndCountOnly);
writeConstantPoolShapeDescriptions(cursor, markAndCountOnly);
writeAnnotationInfo(cursor);
writeSourceDebugExtension(cursor);
writeRecordComponents(cursor, markAndCountOnly);
writePermittedSubclasses(cursor, markAndCountOnly);
writeOptionalInfo(cursor);
writeCallSiteData(cursor, markAndCountOnly);
writeVarHandleMethodTypeLookupTable(cursor, markAndCountOnly);
writeStaticSplitTable(cursor, markAndCountOnly);
writeSpecialSplitTable(cursor, markAndCountOnly);
/* aligned to U_64 required by the shared classes */
cursor->padToAlignment(sizeof(U_64), Cursor::GENERIC);
/*
* Write UTF8s
*/
if ( NULL != utf8Cursor ) {
ROMClassVerbosePhase v(_context, markAndCountOnly ? MarkAndCountUTF8s : WriteUTF8s);
writeUTF8s(utf8Cursor);
}
/*
* Write Intermediate Class File bytes if
* (-Xshareclasses:enableBCI is specified and class file has not been modified by BCI agent) or
* (re-transformation is enabled and -Xshareclasses:enableBCI is not present).
*/
if ((NULL != classDataCursor)
&& !_srpOffsetTable->isInterned(_intermediateClassDataSRPKey)
) {
classDataCursor->mark(_intermediateClassDataSRPKey);
classDataCursor->writeData(_context->intermediateClassData(), _context->intermediateClassDataLength(), Cursor::INTERMEDIATE_CLASS_DATA);
/* aligned to U_64 required by the shared classes */
classDataCursor->padToAlignment(sizeof(U_64), Cursor::GENERIC);
}
}
/*
* Global table for ROMClassWriter::ConstantPoolWriter::visitMethodHandle().
*/
static const UDATA splitTypeMap[] = {
0, /* UNUSED */
ConstantPoolMap::GET_FIELD, /* GETFIELD */
ConstantPoolMap::GET_STATIC, /* GETSTATIC */
ConstantPoolMap::PUT_FIELD, /* PUTFIELD */
ConstantPoolMap::PUT_STATIC, /* PUTSTATIC */
ConstantPoolMap::INVOKE_VIRTUAL, /* INVOKEVIRTUAL */
ConstantPoolMap::INVOKE_STATIC, /* INVOKESTATIC */
ConstantPoolMap::INVOKE_SPECIAL, /* INVOKESPECIAL */
ConstantPoolMap::INVOKE_SPECIAL, /* NEWINVOKESPECIAL */
ConstantPoolMap::INVOKE_INTERFACE /* INVOKEINTERFACE */
};
class ROMClassWriter::ConstantPoolWriter : public ConstantPoolMap::ConstantPoolVisitor
{
public:
ConstantPoolWriter(Cursor *cursor, SRPKeyProducer *srpKeyProducer, ConstantPoolMap *constantPoolMap) :
_cursor(cursor),
_srpKeyProducer(srpKeyProducer),
_constantPoolMap(constantPoolMap)
{
}
void visitClass(U_16 cfrCPIndex)
{
/* if the cfrCPIndex is for the class name, the data type should be SRP_TO_UTF8_CLASS_NAME to avoid comparing lambda class names */
U_16 classNameIndex = _cursor->getClassNameIndex();
if (((U_16)-1 != classNameIndex) && (_srpKeyProducer->mapCfrConstantPoolIndexToKey(classNameIndex) == _srpKeyProducer->mapCfrConstantPoolIndexToKey(cfrCPIndex))) {
_cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(cfrCPIndex), Cursor::SRP_TO_UTF8_CLASS_NAME);
} else {
_cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(cfrCPIndex), Cursor::SRP_TO_UTF8);
}
_cursor->writeU32(BCT_J9DescriptionCpTypeClass, Cursor::GENERIC);
}
void visitString(U_16 cfrCPIndex)
{
_cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(cfrCPIndex), Cursor::SRP_TO_UTF8);
_cursor->writeU32(BCT_J9DescriptionCpTypeObject, Cursor::GENERIC);
}
void visitMethodType(U_16 cfrCPIndex, U_16 originFlags)
{
/* Assumes format: { SRP to UTF8, cpType } */
_cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(cfrCPIndex), Cursor::SRP_TO_UTF8);
_cursor->writeU32((originFlags << BCT_J9DescriptionCpTypeShift) | BCT_J9DescriptionCpTypeMethodType, Cursor::GENERIC);
}
void visitMethodHandle(U_16 cfrKind, U_16 cfrCPIndex)
{
U_32 cpIndex = _constantPoolMap->getROMClassCPIndex(cfrCPIndex, splitTypeMap[cfrKind]);
Trc_BCU_Assert_NotEquals(cpIndex, 0);
/* assumes format: { U32 cpIndex, (cfrKind << 4) || cpType } */
_cursor->writeU32(cpIndex, Cursor::GENERIC);
_cursor->writeU32((cfrKind << BCT_J9DescriptionCpTypeShift) | BCT_J9DescriptionCpTypeMethodHandle, Cursor::GENERIC);
}
void visitConstantDynamic(U_16 bsmIndex, U_16 cfrCPIndex, U_32 primitiveFlag)
{
/* assumes format: { SRP to NameAndSignature, primitiveFlag || (bsmIndex << 4) || cpType } */
_cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(cfrCPIndex), Cursor::SRP_TO_NAME_AND_SIGNATURE);
_cursor->writeU32((bsmIndex << BCT_J9DescriptionCpTypeShift) | BCT_J9DescriptionCpTypeConstantDynamic | primitiveFlag, Cursor::GENERIC);
}
void visitSingleSlotConstant(U_32 slot1)
{
_cursor->writeU32(slot1, Cursor::GENERIC);
_cursor->writeU32(BCT_J9DescriptionCpTypeScalar, Cursor::GENERIC);
}
void visitDoubleSlotConstant(U_32 slot1, U_32 slot2)
{
#ifdef J9VM_ENV_DATA64
_cursor->writeU64(slot1, slot2, Cursor::GENERIC);
#else
_cursor->writeU32(slot1, Cursor::GENERIC);
_cursor->writeU32(slot2, Cursor::GENERIC);
#endif
}
void visitFieldOrMethod(U_16 classRefCPIndex, U_16 nameAndSignatureCfrCPIndex)
{
_cursor->writeU32(classRefCPIndex, Cursor::GENERIC);
_cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(nameAndSignatureCfrCPIndex), Cursor::SRP_TO_NAME_AND_SIGNATURE);
}
private:
Cursor *_cursor;
SRPKeyProducer *_srpKeyProducer;
ConstantPoolMap *_constantPoolMap;
};
void
ROMClassWriter::writeConstantPool(Cursor *cursor, bool markAndCountOnly)
{
UDATA constantPoolSize = UDATA(_constantPoolMap->getROMConstantPoolCount()) * sizeof(J9ROMConstantPoolItem);
if (markAndCountOnly) {
cursor->skip(constantPoolSize);
} else {
CheckSize _(cursor, constantPoolSize);
/* Write the zeroth entry */
cursor->writeU32(0, Cursor::GENERIC);
cursor->writeU32(0, Cursor::GENERIC);
ConstantPoolWriter writer(cursor, _srpKeyProducer, _constantPoolMap);
_constantPoolMap->constantPoolDo(&writer);
}
}
/*
* The ROM class field has the following layout:
* J9ROMFieldShape
* 4 or 8 bytes unsigned constant value if this is a static const field
* 4 bytes SRP to generic field signature if the field has a generic signature
* 4 bytes length of annotation data in bytes, followed by annotation data. Omitted if there are no field annotations.
* 4 bytes length of type annotation data in bytes followed by type annotation data. Omitted if there are no type annotations.
*/
void
ROMClassWriter::writeFields(Cursor *cursor, bool markAndCountOnly)
{
cursor->mark(_fieldsSRPKey);
ClassFileOracle::FieldIterator iterator = _classFileOracle->getFieldIterator();
while ( iterator.isNotDone() ) {
if (markAndCountOnly) {
cursor->skip(sizeof(J9ROMFieldShape));
} else {
CheckSize _(cursor, sizeof(J9ROMFieldShape));
cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(iterator.getNameIndex()), Cursor::SRP_TO_UTF8);
cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(iterator.getDescriptorIndex()), Cursor::SRP_TO_UTF8);
U_32 fieldSignatureFlags(fieldModifiersLookupTable[iterator.getFirstByteOfDescriptor() - 'A']);
U_32 modifiers(iterator.getAccessFlags() | (fieldSignatureFlags << 16));
if (iterator.isConstant()) {
modifiers |= J9FieldFlagConstant;
}
if (iterator.hasGenericSignature()) {
modifiers |= J9FieldFlagHasGenericSignature;
}
if (iterator.isSynthetic()) {
/* handle the synthetic attribute. In java 1.5 synthetic may be specified in the access flags as well so do not unset bit here */
modifiers |= J9AccSynthetic;
}
if (iterator.isFieldContended()) {
modifiers |= J9FieldFlagIsContended;
}
if (iterator.hasAnnotation()) {
modifiers |= J9FieldFlagHasFieldAnnotations;
}
if (iterator.hasTypeAnnotation()) {
modifiers |= J9FieldFlagHasTypeAnnotations;
}
cursor->writeU32(modifiers, Cursor::GENERIC);
}
if (iterator.isConstant()) { // Check not absolutely necessary, but might provide small performance win
if (iterator.isConstantFloat() || iterator.isConstantInteger()) {
cursor->writeU32(iterator.getConstantValueSlot1(), Cursor::GENERIC);
} else if (iterator.isConstantDouble() || iterator.isConstantLong()) {
cursor->writeU32(iterator.getConstantValueSlot1(), Cursor::GENERIC);
cursor->writeU32(iterator.getConstantValueSlot2(), Cursor::GENERIC);
} else if (iterator.isConstantString()) {
cursor->writeU32(U_32(_constantPoolMap->getROMClassCPIndexForReference(iterator.getConstantValueConstantPoolIndex())), Cursor::GENERIC);
}
}
if (iterator.hasGenericSignature()) {
if (markAndCountOnly) { // TODO check if this is a performance win
cursor->skip(sizeof(J9SRP));
} else {
cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(iterator.getGenericSignatureIndex()), Cursor::SRP_TO_UTF8);
}
}
if (iterator.hasAnnotation()) {
/*
* u_32 length
* length * u_8
* pad to u_32 size
*/
AnnotationWriter annotationWriter(cursor, _constantPoolMap, _classFileOracle);
_classFileOracle->fieldAnnotationDo(iterator.getFieldIndex(), &annotationWriter, &annotationWriter, &annotationWriter);
cursor->padToAlignment(sizeof(U_32), Cursor::GENERIC);
}
if (iterator.hasTypeAnnotation()) {
AnnotationWriter annotationWriter(cursor, _constantPoolMap, _classFileOracle);
_classFileOracle->fieldTypeAnnotationDo(iterator.getFieldIndex(), &annotationWriter, &annotationWriter, &annotationWriter);
cursor->padToAlignment(sizeof(U_32), Cursor::GENERIC);
}
iterator.next();
}
}
/* mapping characters A..Z,[ */
const U_8 primitiveArrayTypeCharConversion[] = {
0, CFR_STACKMAP_TYPE_BYTE_ARRAY, CFR_STACKMAP_TYPE_CHAR_ARRAY, CFR_STACKMAP_TYPE_DOUBLE_ARRAY,
0, CFR_STACKMAP_TYPE_FLOAT_ARRAY, 0, 0,
CFR_STACKMAP_TYPE_INT_ARRAY, CFR_STACKMAP_TYPE_LONG_ARRAY, 0, 0,
0, 0, 0, 0,
0, 0, CFR_STACKMAP_TYPE_SHORT_ARRAY, 0,
0, 0, 0, 0,
0, CFR_STACKMAP_TYPE_BOOL_ARRAY, 0};
class ROMClassWriter::CallSiteWriter : public ConstantPoolMap::CallSiteVisitor
{
public:
CallSiteWriter(Cursor *cursor) :
_cursor(cursor)
{
}
void visitCallSite(U_16 nameAndSignatureIndex, U_16 bootstrapMethodIndex)
{
_cursor->writeU16(bootstrapMethodIndex, Cursor::GENERIC);
}
private:
Cursor *_cursor;
};
class ROMClassWriter::Helper :
private ClassFileOracle::ConstantPoolIndexVisitor,
private ClassFileOracle::ExceptionHandlerVisitor,
private ClassFileOracle::StackMapFrameVisitor,
private ClassFileOracle::VerificationTypeInfoVisitor,
private ClassFileOracle::BootstrapMethodVisitor,
private ClassFileOracle::MethodParametersVisitor,
private ConstantPoolMap::SplitEntryVisitor,
private ConstantPoolMap::CallSiteVisitor
{
public:
Helper(Cursor *cursor, bool markAndCountOnly,
ClassFileOracle *classFileOracle, SRPKeyProducer *srpKeyProducer, SRPOffsetTable *srpOffsetTable, ConstantPoolMap *constantPoolMap,
UDATA expectedSize) :
_cursor(cursor),
_classFileOracle(classFileOracle),
_srpKeyProducer(srpKeyProducer),
_srpOffsetTable(srpOffsetTable),
_constantPoolMap(constantPoolMap),
_markAndCountOnly(markAndCountOnly)
{
if (_markAndCountOnly) {
_cursor->skip(expectedSize);
}
}
void writeInnerClasses()
{
if (!_markAndCountOnly) {
_classFileOracle->innerClassesDo(this); /* visitConstantPoolIndex */
}
}
#if JAVA_SPEC_VERSION >= 11
void writeNestMembers()
{
if (!_markAndCountOnly) {
_classFileOracle->nestMembersDo(this); /* visitConstantPoolIndex */
}
}
#endif /* JAVA_SPEC_VERSION >= 11 */
void writeInterfaces()
{
if (!_markAndCountOnly) {
_classFileOracle->interfacesDo(this); /* visitConstantPoolIndex */
}
}
void writeNameAndSignatureBlock()
{
if (!_markAndCountOnly) {
for (ClassFileOracle::NameAndTypeIterator iterator = _classFileOracle->getNameAndTypeIterator();
iterator.isNotDone();
iterator.next()) {
U_16 cpIndex = iterator.getCPIndex();
if (_constantPoolMap->isNATConstantReferenced(cpIndex)) {
U_16 nameIndex = iterator.getNameIndex();
U_16 descriptorIndex = iterator.getDescriptorIndex();
_cursor->mark(_srpKeyProducer->mapCfrConstantPoolIndexToKey(cpIndex));
_cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(nameIndex), Cursor::SRP_TO_UTF8);
_cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(descriptorIndex), Cursor::SRP_TO_UTF8);
}
}
}
}
void writeUTF8Block()
{
if (!_markAndCountOnly) {
for (ClassFileOracle::UTF8Iterator iterator = _classFileOracle->getUTF8Iterator();
iterator.isNotDone();
iterator.next()) {
U_16 cpIndex = iterator.getCPIndex();
if (_constantPoolMap->isUTF8ConstantReferenced(cpIndex)) {
UDATA key = _srpKeyProducer->mapCfrConstantPoolIndexToKey(cpIndex);
if (!_srpOffsetTable->isInterned(key)) {
U_8* utf8Data = iterator.getUTF8Data();
U_16 utf8Length = iterator.getUTF8Length();
_cursor->mark(key);
_cursor->writeUTF8(utf8Data, utf8Length, Cursor::GENERIC);
}
}
}
}
}
void writeExceptionBlock(ClassFileOracle::MethodIterator *iterator)
{
if (!_markAndCountOnly) {
iterator->exceptionHandlersDo(this); /* visitExceptionHandler */
iterator->exceptionsThrownDo(this); /* visitConstantPoolIndex */
}
}
void writeMethodParameters(ClassFileOracle::MethodIterator *iterator)
{
if (!_markAndCountOnly) {
iterator->methodParametersDo(this); /* visitMethodParameters */
}
}
void writeStackMap(ClassFileOracle::MethodIterator *methodIterator)
{
if (!_markAndCountOnly) {
methodIterator->stackMapFramesDo(this); /* visitStackMapFrame */
}
}
void writeCallSiteData()
{
if (!_markAndCountOnly) {
CallSiteWriter callSiteWriter(_cursor);
_constantPoolMap->callSitesDo(this); /* visitCallSite */
_constantPoolMap->callSitesDo(&callSiteWriter);
}
}
void writeVarHandleMethodTypeLookupTable()
{
if (!_markAndCountOnly) {
U_16 lookupTableCount = _constantPoolMap->getVarHandleMethodTypeCount();
if (lookupTableCount > 0) {
U_16 *lookupTable = _constantPoolMap->getVarHandleMethodTypeLookupTable();
/* The lookup table is a U_16[], so we need to pad it in order to keep the J9ROMClass alignment. */
U_16 lookupTablePaddedCount = _constantPoolMap->getVarHandleMethodTypePaddedCount();
U_16 *lookupTablePadding = lookupTable + lookupTableCount;
UDATA lookupTablePaddingLength = lookupTablePaddedCount - lookupTableCount;
/* Write the data section of the array */
_cursor->writeData((U_8 *)lookupTable, lookupTableCount * sizeof(U_16), Cursor::GENERIC);
/* Write the padding section of the array */
if (lookupTablePaddingLength > 0) {
_cursor->writeData((U_8 *)lookupTablePadding, lookupTablePaddingLength * sizeof(U_16), Cursor::GENERIC);
}
}
}
}
void writeBootstrapMethods()
{
if (!_markAndCountOnly) {
_classFileOracle->bootstrapMethodsDo(this); /* visitBootstrapMethod */
}
}
void writeStaticSplitTable()
{
if (!_markAndCountOnly) {
_constantPoolMap->staticSplitEntriesDo(this); /* visitSplitEntry */
}
}
void writeSpecialSplitTable()
{
if (!_markAndCountOnly) {
_constantPoolMap->specialSplitEntriesDo(this); /* visitSplitEntry */
}
}
private:
/*
* Implement interfaces
*/
void visitConstantPoolIndex(U_16 cpIndex)
{
_cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(cpIndex), Cursor::SRP_TO_UTF8);
}
void visitMethodParameters(U_16 cpIndex, U_16 flag) {
if (0 == cpIndex) {
_cursor->writeU32(0, Cursor::GENERIC);
} else {
_cursor->writeSRP(_srpKeyProducer->mapCfrConstantPoolIndexToKey(cpIndex), Cursor::SRP_TO_UTF8);
}
_cursor->writeU16(flag, Cursor::GENERIC);
}
void visitExceptionHandler(U_32 startPC, U_32 endPC, U_32 handlerPC, U_16 exceptionClassCPIndex)
{
_cursor->writeU32(startPC, Cursor::GENERIC);
_cursor->writeU32(endPC, Cursor::GENERIC);
_cursor->writeU32(handlerPC, Cursor::GENERIC);
_cursor->writeU32(_constantPoolMap->getROMClassCPIndexForReference(exceptionClassCPIndex), Cursor::GENERIC);
}
void visitStackMapObject(U_8 slotType, U_16 classCPIndex, U_16 classNameCPIndex)
{
U_8 *nameData = _classFileOracle->getUTF8Data(classNameCPIndex);
U_16 nameLength = _classFileOracle->getUTF8Length(classNameCPIndex);
/* special conversion of primitive array objects
* detect whether or not this is a primitive array e.g.,
* [I or [[F, etc..
* vs. an array of Objects e.g.,
* [Lcom/ibm/foo/Bar;
*/
if ((nameData[0] == '[') && (nameData[nameLength - 1] != ';')) {
/*
* This is a primitive array object.
*
* Encode the primitive array type in the tag field.
* One of:
* CFR_STACKMAP_TYPE_BYTE_ARRAY
* CFR_STACKMAP_TYPE_BOOL_ARRAY
* CFR_STACKMAP_TYPE_CHAR_ARRAY
* CFR_STACKMAP_TYPE_DOUBLE_ARRAY
* CFR_STACKMAP_TYPE_FLOAT_ARRAY
* CFR_STACKMAP_TYPE_INT_ARRAY
* CFR_STACKMAP_TYPE_LONG_ARRAY
* CFR_STACKMAP_TYPE_SHORT_ARRAY
*/
_cursor->writeU8(primitiveArrayTypeCharConversion[nameData[nameLength - 1] - 'A'], Cursor::GENERIC);
/* Also, encode the arity beyond 1
* (i.e., number of dimensions of the array - 1)
* in the next 2 bytes in Big Endian (since we are maintaining Sun StackMapTable format).
*
* The reason for encoding arity - 1 in verification type info in Stack maps for primitive array special cases are:
* The newarray and anewarray bytecodes assume that the array has only a single dimension.
* To create a multidimension array, multianewarray must be used.
* The primitive array access bytecodes (ie: iaload) can only be used on single dimension arrays.
* aaload must be used to access every dimension prior to the base dimension in a multi-arity primitive array.
* The constants in vrfytbl.c are based off the constants for the primitive types, and can't have the arity of 1 encoded if the constant is to be used for both purposes.
* (See rtverify.c verifyBytecodes() - the RTV_ARRAY_FETCH_PUSH & RTV_ARRAY_STORE cases of the switch)
* In addition, the code all through the verifier assumes this condition.
* Notes:
* See util/vrfytbl.c for bytecode tables.
* See constant definitions in cfreader.h and oti/bytecodewalk.h.
* bcverify/bcverify.c simulateStack() is the other place that creates stack maps.
*/
_cursor->writeBigEndianU16(nameLength - 2, Cursor::GENERIC);
} else {
/*
* Object_variable_info
* u1 tag
* u2 cpIndex (ROMClass constant pool index)
*/
_cursor->writeU8(slotType, Cursor::GENERIC);
_cursor->writeBigEndianU16(_constantPoolMap->getROMClassCPIndexForReference(classCPIndex), Cursor::GENERIC);
}
}
void visitStackMapNewObject(U_8 slotType, U_16 offset)
{
/*
* Uninitialized_variable_info
* u1 tag
* u2 offset (offset of the new instruction that created the object being stored in the location)
*/
_cursor->writeU8(slotType, Cursor::GENERIC);
/* output the offset delta */
_cursor->writeBigEndianU16(offset, Cursor::GENERIC);
}
void visitStackMapItem(U_8 slotType)
{
_cursor->writeU8(slotType, Cursor::GENERIC);
}
void visitStackMapFrame(U_16 localsCount, U_16 stackItemsCount, U_16 offsetDelta, U_8 frameType, ClassFileOracle::VerificationTypeInfo *typeInfo)
{
/*
* Stack Map Frame:
* consists of a 1 byte tag followed by zero or more bytes depending on the tag
*
* union stack_map_frame {
* SAME
* SAME_LOCALS_1_STACK
* Reserved
* SAME_LOCALS_1_STACK_EXTENDED
* CHOP
* SAME_EXTENDED
* APPEND
* FULL
* }
*/
/* output the frame tag */
_cursor->writeU8(frameType, Cursor::GENERIC);
if (CFR_STACKMAP_SAME_LOCALS_1_STACK > frameType) { /* 0..63 */
/* SAME frame - no extra data */
} else if (CFR_STACKMAP_SAME_LOCALS_1_STACK_END > frameType) { /* 64..127 */
/*
* SAME_LOCALS_1_STACK {
* TypeInfo stackItems[1]
* };
*/
typeInfo->stackItemsDo(this);
} else if (CFR_STACKMAP_SAME_LOCALS_1_STACK_EXTENDED > frameType) { /* 128..246 */
/* Reserved frame types - no extra data */
Trc_BCU_Assert_ShouldNeverHappen();
} else if (CFR_STACKMAP_SAME_LOCALS_1_STACK_EXTENDED == frameType) { /* 247 */
/*
* SAME_LOCALS_1_STACK_EXTENDED {
* U_16 offsetDelta
* TypeInfo stackItems[1]
* };
*/
_cursor->writeBigEndianU16(offsetDelta, Cursor::GENERIC);