-
Notifications
You must be signed in to change notification settings - Fork 746
/
Copy pathROMClassBuilder.cpp
1661 lines (1519 loc) · 65.7 KB
/
ROMClassBuilder.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
*******************************************************************************/
/*
* ROMClassBuilder.cpp
*/
#include "ut_j9bcu.h"
#include "bcutil_api.h"
#include "stackmap_api.h"
#include "SCQueryFunctions.h"
#include "ROMClassBuilder.hpp"
#include "AllocationStrategy.hpp"
#include "BufferManager.hpp"
#include "ClassFileOracle.hpp"
#include "ClassFileParser.hpp"
#include "ClassFileWriter.hpp"
#include "ConstantPoolMap.hpp"
#include "ComparingCursor.hpp"
#include "Cursor.hpp"
#include "J9PortAllocationStrategy.hpp"
#include "ROMClassCreationContext.hpp"
#include "ROMClassStringInternManager.hpp"
#include "ROMClassSegmentAllocationStrategy.hpp"
#include "ROMClassVerbosePhase.hpp"
#include "ROMClassWriter.hpp"
#include "SCStoreTransaction.hpp"
#include "SCStringTransaction.hpp"
#include "SRPKeyProducer.hpp"
#include "SuppliedBufferAllocationStrategy.hpp"
#include "WritingCursor.hpp"
#include "j9protos.h"
#include "ut_j9bcu.h"
static const UDATA INITIAL_CLASS_FILE_BUFFER_SIZE = 4096;
static const UDATA INITIAL_BUFFER_MANAGER_SIZE = 32768 * 10;
ROMClassBuilder::ROMClassBuilder(J9JavaVM *javaVM, J9PortLibrary *portLibrary, UDATA maxStringInternTableSize, U_8 * verifyExcludeAttribute, VerifyClassFunction verifyClassFunction) :
_javaVM(javaVM),
_portLibrary(portLibrary),
_verifyExcludeAttribute(verifyExcludeAttribute),
_verifyClassFunction(verifyClassFunction),
_classFileParserBufferSize(INITIAL_CLASS_FILE_BUFFER_SIZE),
_bufferManagerSize(INITIAL_BUFFER_MANAGER_SIZE),
_classFileBuffer(NULL),
_bufferManagerBuffer(NULL),
_anonClassNameBuffer(NULL),
_anonClassNameBufferSize(0),
_stringInternTable(javaVM, portLibrary, maxStringInternTableSize)
{
}
ROMClassBuilder::~ROMClassBuilder()
{
PORT_ACCESS_FROM_PORT(_portLibrary);
if (_javaVM != NULL && _javaVM->dynamicLoadBuffers != NULL) {
if (_javaVM->dynamicLoadBuffers->classFileError == _classFileBuffer) {
/* Set dynamicLoadBuffers->classFileError to NULL to prevent a
* crash in j9bcutil_freeAllTranslationBuffers() on JVM shutdown
*/
_javaVM->dynamicLoadBuffers->classFileError = NULL;
}
}
j9mem_free_memory(_classFileBuffer);
j9mem_free_memory(_bufferManagerBuffer);
j9mem_free_memory(_anonClassNameBuffer);
}
ROMClassBuilder *
ROMClassBuilder::getROMClassBuilder(J9PortLibrary *portLibrary, J9JavaVM *vm)
{
PORT_ACCESS_FROM_PORT(portLibrary);
ROMClassBuilder *romClassBuilder = (ROMClassBuilder *)vm->dynamicLoadBuffers->romClassBuilder;
if ( NULL == romClassBuilder ) {
romClassBuilder = (ROMClassBuilder *)j9mem_allocate_memory(sizeof(ROMClassBuilder), J9MEM_CATEGORY_CLASSES);
if ( NULL != romClassBuilder ) {
J9BytecodeVerificationData * verifyBuffers = vm->bytecodeVerificationData;
new(romClassBuilder) ROMClassBuilder(vm, portLibrary,
vm->maxInvariantLocalTableNodeCount,
(NULL == verifyBuffers ? NULL : verifyBuffers->excludeAttribute),
(NULL == verifyBuffers ? NULL : j9bcv_verifyClassStructure));
if (romClassBuilder->isOK()) {
ROMClassBuilder **romClassBuilderPtr = (ROMClassBuilder **)&(vm->dynamicLoadBuffers->romClassBuilder);
*romClassBuilderPtr = romClassBuilder;
} else {
romClassBuilder->~ROMClassBuilder();
j9mem_free_memory(romClassBuilder);
romClassBuilder = NULL;
}
}
}
return romClassBuilder;
}
extern "C" void
shutdownROMClassBuilder(J9JavaVM *vm)
{
PORT_ACCESS_FROM_JAVAVM(vm);
ROMClassBuilder *romClassBuilder = (ROMClassBuilder *)vm->dynamicLoadBuffers->romClassBuilder;
if ( NULL != romClassBuilder ) {
vm->dynamicLoadBuffers->romClassBuilder = NULL;
romClassBuilder->~ROMClassBuilder();
j9mem_free_memory(romClassBuilder);
}
}
#if defined(J9DYN_TEST)
extern "C" IDATA
j9bcutil_compareRomClass(
U_8 * classFileBytes,
U_32 classFileSize,
J9PortLibrary * portLib,
struct J9BytecodeVerificationData * verifyBuffers,
UDATA bctFlags,
UDATA bcuFlags,
J9ROMClass *romClass)
{
ROMClassBuilder romClassBuilder(NULL, portLib, 0, NULL == verifyBuffers ? NULL : verifyBuffers->excludeAttribute, NULL == verifyBuffers ? NULL : j9bcv_verifyClassStructure);
ROMClassCreationContext context(portLib, classFileBytes, classFileSize, bctFlags, bcuFlags, romClass);
return (IDATA)romClassBuilder.buildROMClass(&context);
}
#endif
extern "C" IDATA
j9bcutil_buildRomClassIntoBuffer(
U_8 * classFileBytes,
UDATA classFileSize,
J9PortLibrary * portLib,
J9BytecodeVerificationData * verifyBuffers,
UDATA bctFlags,
UDATA bcuFlags,
UDATA findClassFlags,
U_8 * romSegment,
UDATA romSegmentSize,
U_8 * lineNumberBuffer,
UDATA lineNumberBufferSize,
U_8 * varInfoBuffer,
UDATA varInfoBufferSize,
U_8 ** classFileBufferPtr
)
{
SuppliedBufferAllocationStrategy suppliedBufferAllocationStrategy(romSegment, romSegmentSize, lineNumberBuffer, lineNumberBufferSize, varInfoBuffer, varInfoBufferSize);
ROMClassBuilder romClassBuilder(NULL, portLib, 0, NULL == verifyBuffers ? NULL : verifyBuffers->excludeAttribute, NULL == verifyBuffers ? NULL : j9bcv_verifyClassStructure);
ROMClassCreationContext context(portLib, classFileBytes, classFileSize, bctFlags, bcuFlags, findClassFlags, &suppliedBufferAllocationStrategy);
IDATA result = IDATA(romClassBuilder.buildROMClass(&context));
if (NULL != classFileBufferPtr) {
*classFileBufferPtr = romClassBuilder.releaseClassFileBuffer();
}
return result;
}
extern "C" IDATA
j9bcutil_buildRomClass(J9LoadROMClassData *loadData, U_8 * intermediateData, UDATA intermediateDataLength, J9JavaVM *javaVM, UDATA bctFlags, UDATA classFileBytesReplaced, UDATA isIntermediateROMClass, J9TranslationLocalBuffer *localBuffer)
{
PORT_ACCESS_FROM_JAVAVM(javaVM);
UDATA bcuFlags = javaVM->dynamicLoadBuffers->flags;
UDATA findClassFlags = loadData->options;
ROMClassSegmentAllocationStrategy romClassSegmentAllocationStrategy(javaVM, loadData->classLoader);
ROMClassBuilder *romClassBuilder = ROMClassBuilder::getROMClassBuilder(PORTLIB, javaVM);
if (NULL == romClassBuilder) {
return BCT_ERR_OUT_OF_MEMORY;
}
ROMClassCreationContext context(
PORTLIB, javaVM, loadData->classData, loadData->classDataLength, bctFlags, bcuFlags, findClassFlags, &romClassSegmentAllocationStrategy,
loadData->className, loadData->classNameLength, loadData->hostPackageName, loadData->hostPackageLength, intermediateData, (U_32) intermediateDataLength, loadData->romClass, loadData->classBeingRedefined,
loadData->classLoader, (0 != classFileBytesReplaced), (TRUE == isIntermediateROMClass), localBuffer);
BuildResult result = romClassBuilder->buildROMClass(&context);
loadData->romClass = context.romClass();
context.reportStatistics(localBuffer);
return IDATA(result);
}
extern "C" IDATA
j9bcutil_transformROMClass(J9JavaVM *javaVM, J9PortLibrary *portLibrary, J9ROMClass *romClass, U_8 **classData, U_32 *size)
{
ClassFileWriter classFileWriter(javaVM, portLibrary, romClass);
if (classFileWriter.isOK()) {
*size = (U_32) classFileWriter.classFileSize();
*classData = classFileWriter.classFileData();
}
return IDATA(classFileWriter.getResult());
}
BuildResult
ROMClassBuilder::buildROMClass(ROMClassCreationContext *context)
{
BuildResult result = OK;
ROMClassVerbosePhase v0(context, ROMClassCreation, &result);
context->recordLoadStart();
context->recordParseClassFileStart();
ClassFileParser classFileParser(_portLibrary, _verifyClassFunction);
result = classFileParser.parseClassFile(context, &_classFileParserBufferSize, &_classFileBuffer);
context->recordParseClassFileEnd();
if ( OK == result ) {
ROMClassVerbosePhase v1(context, ROMClassTranslation, &result);
context->recordTranslationStart();
result = OutOfMemory;
while( OutOfMemory == result ) {
BufferManager bufferManager = BufferManager(_portLibrary, _bufferManagerSize, &_bufferManagerBuffer);
if (!bufferManager.isOK()) {
/*
* not enough native memory to complete this ROMClass load
*/
break;
}
result = prepareAndLaydown( &bufferManager, &classFileParser, context );
if (OutOfMemory == result) {
context->recordOutOfMemory(_bufferManagerSize);
/* Restore the original method bytecodes, as we may have transformed them. */
classFileParser.restoreOriginalMethodBytecodes();
/* set up new bufferSize for top of loop */
_bufferManagerSize = _bufferManagerSize * 2;
}
}
}
if ( OK == result ) {
context->recordTranslationEnd();
}
context->recordLoadEnd(result);
return result;
}
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
BuildResult
ROMClassBuilder::injectInterfaces(ClassFileOracle *classFileOracle)
{
U_32 numOfInterfaces = 0;
_interfaceInjectionInfo.numOfInterfaces = numOfInterfaces;
return OK;
}
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
BuildResult
ROMClassBuilder::handleAnonClassName(J9CfrClassFile *classfile, ROMClassCreationContext *context)
{
J9CfrConstantPoolInfo* constantPool = classfile->constantPool;
U_32 cpThisClassUTF8Slot = constantPool[classfile->thisClass].slot1;
U_32 originalStringLength = constantPool[cpThisClassUTF8Slot].slot1;
const char* originalStringBytes = (const char*)constantPool[cpThisClassUTF8Slot].bytes;
U_16 newUtfCPEntry = classfile->constantPoolCount - 1; /* last cpEntry is reserved for anonClassName utf */
U_32 i = 0;
bool stringOrNASReferenceToClassName = false;
bool newCPEntry = true;
BuildResult result = OK;
char buf[ROM_ADDRESS_LENGTH + 1] = {0};
U_8 *hostPackageName = context->hostPackageName();
UDATA hostPackageLength = context->hostPackageLength();
PORT_ACCESS_FROM_PORT(_portLibrary);
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
/*
* Prevent generated LambdaForm classes from MethodHandles to be stored to the shared cache.
* When there are a large number of such classes in the shared cache, they trigger a lot of class comparisons.
* Performance can be much worse (compared to shared cache turned off).
*/
if (isLambdaFormClassName(originalStringBytes, originalStringLength, NULL/*deterministicPrefixLength*/)) {
context->addFindClassFlags(J9_FINDCLASS_FLAG_LAMBDAFORM);
#if defined(J9VM_OPT_SHARED_CLASSES)
if ((NULL != _javaVM) && (NULL != _javaVM->sharedClassConfig)) {
if (J9_ARE_NO_BITS_SET(_javaVM->sharedClassConfig->runtimeFlags2, J9SHR_RUNTIMEFLAG2_SHARE_LAMBDAFORM)) {
context->addFindClassFlags(J9_FINDCLASS_FLAG_DO_NOT_SHARE);
}
}
#endif /* defined(J9VM_OPT_SHARED_CLASSES) */
}
#if JAVA_SPEC_VERSION >= 15
/* InjectedInvoker is a hidden class without the strong attribute set. It
* is created by MethodHandleImpl.makeInjectedInvoker on the OpenJDK side.
* So, OpenJ9 does not have control over the implementation of InjectedInvoker.
* ROM class name for InjectedInvoker is set using the hidden class name, which
* contains the correct host class name. The below filter is used to reduce
* the number of memcmps when identifying if a hidden class is named
* InjectedInvoker. Class name for InjectedInvoker:
* - in class file bytecodes: "InjectedInvoker"; and
* - during hidden class creation: "<HOST_CLASS>$$InjectedInvoker".
*/
if (context->isClassHidden()
&& !context->isHiddenClassOptStrongSet()
/* In JDK17, InjectedInvoker does not have the nestmate attribute. In JDK18,
* InjectedInvoker has the nestmate attribute due to change in implementation.
* This filter checks for the nestmate attribute based upon the Java version
* in order to identify a InjectedInvoker class.
*/
#if JAVA_SPEC_VERSION <= 17
&& !context->isHiddenClassOptNestmateSet()
#else /* JAVA_SPEC_VERSION <= 17 */
&& context->isHiddenClassOptNestmateSet()
#endif /* JAVA_SPEC_VERSION <= 17 */
) {
#define J9_INJECTED_INVOKER_CLASSNAME "$$InjectedInvoker"
U_8 *nameData = context->className();
if (NULL != nameData) {
UDATA nameLength = context->classNameLength();
IDATA startIndex = nameLength - LITERAL_STRLEN(J9_INJECTED_INVOKER_CLASSNAME);
if (startIndex >= 0) {
/* start points to a location in class name for checking if it contains
* "$$InjectedInvoker".
*/
U_8 *start = nameData + startIndex;
if (0 == memcmp(
start, J9_INJECTED_INVOKER_CLASSNAME,
LITERAL_STRLEN(J9_INJECTED_INVOKER_CLASSNAME))
) {
originalStringBytes = (char *)nameData;
originalStringLength = (U_32)nameLength;
}
}
}
#undef J9_INJECTED_INVOKER_CLASSNAME
}
#endif /* JAVA_SPEC_VERSION >= 15 */
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
/* check if adding host package name to anonymous class is needed */
UDATA newHostPackageLength = 0;
if ((0 != memcmp(originalStringBytes, hostPackageName, hostPackageLength))
#if JAVA_SPEC_VERSION >= 22
/* Don't add the host package name if a package name already exists in the class name. */
&& (NULL == strchr(originalStringBytes, '/'))
#endif /* JAVA_SPEC_VERSION >= 22 */
) {
newHostPackageLength = hostPackageLength + 1;
}
UDATA newAnonClassNameLength = originalStringLength + 1 + ROM_ADDRESS_LENGTH + 1 + newHostPackageLength;
/* Find if there are any Constant_String or CFR_CONSTANT_NameAndType references to the className.
* If there are none we don't need to make a new cpEntry, we can overwrite the existing
* one since the only reference to it is the classRef
* Note: The check only applies to the existing cpEntries of the constant pool rather than
* the last cpEntry (not yet initialized) for the anonClassName.
*/
for (i = 0; i < newUtfCPEntry; i++) {
if ((CFR_CONSTANT_String == constantPool[i].tag)
|| (CFR_CONSTANT_NameAndType == constantPool[i].tag)
) {
if (cpThisClassUTF8Slot == constantPool[i].slot1) {
stringOrNASReferenceToClassName = TRUE;
}
}
}
if (!stringOrNASReferenceToClassName) {
/* do not need the new cpEntry so fix up classfile->constantPoolCount */
newCPEntry = FALSE;
newUtfCPEntry = cpThisClassUTF8Slot;
classfile->constantPoolCount -= 1;
}
J9CfrConstantPoolInfo *anonClassName = &classfile->constantPool[newUtfCPEntry];
/*
* alloc an array for the new name with the following format:
* [className]/[ROMClassAddress]\0
*/
if ((0 == _anonClassNameBufferSize) || (newAnonClassNameLength > _anonClassNameBufferSize)) {
j9mem_free_memory(_anonClassNameBuffer);
_anonClassNameBuffer = (U_8 *)j9mem_allocate_memory(newAnonClassNameLength, J9MEM_CATEGORY_CLASSES);
if (NULL == _anonClassNameBuffer) {
result = OutOfMemory;
goto done;
}
_anonClassNameBufferSize = newAnonClassNameLength;
}
constantPool[newUtfCPEntry].bytes = _anonClassNameBuffer;
if (newCPEntry) {
constantPool[classfile->lastUTF8CPIndex].nextCPIndex = newUtfCPEntry;
}
/* calculate the size of the new string and create new cpEntry*/
anonClassName->slot1 = (U_32)newAnonClassNameLength - 1;
if (newCPEntry) {
anonClassName->slot2 = 0;
anonClassName->tag = CFR_CONSTANT_Utf8;
anonClassName->flags1 = 0;
anonClassName->nextCPIndex = 0;
anonClassName->romAddress = 0;
}
constantPool[classfile->thisClass].slot1 = newUtfCPEntry;
/* copy the name into the new location and add the special character, fill the rest with zeroes */
if (newHostPackageLength > 0 ) {
memcpy(constantPool[newUtfCPEntry].bytes, hostPackageName, newHostPackageLength - 1);
*(U_8*)((UDATA) constantPool[newUtfCPEntry].bytes + newHostPackageLength - 1) = ANON_CLASSNAME_CHARACTER_SEPARATOR;
}
memcpy (constantPool[newUtfCPEntry].bytes + newHostPackageLength, originalStringBytes, originalStringLength);
*(U_8*)((UDATA) constantPool[newUtfCPEntry].bytes + newHostPackageLength + originalStringLength) = ANON_CLASSNAME_CHARACTER_SEPARATOR;
/*
* 0x<romAddress> will be appended to anon/hidden class name.
* Initialize the 0x<romAddress> part to 0x00000000 or 0x0000000000000000 (depending on the platforms).
*/
j9str_printf(buf, ROM_ADDRESS_LENGTH + 1, ROM_ADDRESS_FORMAT, 0);
memcpy(constantPool[newUtfCPEntry].bytes + newHostPackageLength + originalStringLength + 1, buf, ROM_ADDRESS_LENGTH + 1);
/* Mark if the class is a Lambda class. */
#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)
if (!context->isLambdaFormClass()
&& isLambdaClassName(reinterpret_cast<const char *>(_anonClassNameBuffer),
newAnonClassNameLength - 1, NULL/*deterministicPrefixLength*/)
) {
context->addFindClassFlags(J9_FINDCLASS_FLAG_LAMBDA);
}
#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
if (isLambdaClassName(reinterpret_cast<const char *>(_anonClassNameBuffer),
newAnonClassNameLength - 1, NULL/*deterministicPrefixLength*/)
) {
context->addFindClassFlags(J9_FINDCLASS_FLAG_LAMBDA);
}
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
/* search constantpool for all other identical classRefs. We have not actually
* tested this scenario as javac will not output more than one classRef or utfRef of the
* same kind.
*/
for (i = 0; i < classfile->constantPoolCount; i++) {
if (CFR_CONSTANT_Class == constantPool[i].tag) {
U_32 classNameSlot = constantPool[i].slot1;
if (classNameSlot != newUtfCPEntry) {
U_32 classNameLength = constantPool[classNameSlot].slot1;
if (J9UTF8_DATA_EQUALS(originalStringBytes, originalStringLength,
constantPool[classNameSlot].bytes, classNameLength))
{
/* if it is the same class, point to original class name slot */
constantPool[i].slot1 = newUtfCPEntry;
}
}
}
}
done:
return result;
}
U_8 *
ROMClassBuilder::releaseClassFileBuffer()
{
U_8 *result = _classFileBuffer;
_classFileBuffer = NULL;
return result;
}
void
ROMClassBuilder::getSizeInfo(ROMClassCreationContext *context, ROMClassWriter *romClassWriter, SRPOffsetTable *srpOffsetTable, bool *countDebugDataOutOfLine, SizeInformation *sizeInformation)
{
/* create a new scope to allow the ROMClassVerbosePhase to properly record the amount of time spent in
* preparation */
ROMClassVerbosePhase v(context, PrepareROMClass);
Cursor mainAreaCursor(RC_TAG, srpOffsetTable, context);
Cursor lineNumberCursor(LINE_NUMBER_TAG, srpOffsetTable, context);
Cursor variableInfoCursor(VARIABLE_INFO_TAG, srpOffsetTable, context);
Cursor utf8Cursor(UTF8_TAG, srpOffsetTable, context);
Cursor classDataCursor(INTERMEDIATE_TAG, srpOffsetTable, context);
/*
* The need to have separate lineNumber and variableInfo Cursors from mainAreaCursor only exists
* if it is possible to place debug information out of line. That is currently only done when
* shared classes is enabled and it is possible to share the class OR when the allocation strategy
* permits it.
*/
if (context->canPossiblyStoreDebugInfoOutOfLine()) {
/* It's possible that debug information can be stored out of line.
* Calculate sizes and offsets with out of line debug information.*/
*countDebugDataOutOfLine = true;
romClassWriter
->writeROMClass(&mainAreaCursor,
&lineNumberCursor,
&variableInfoCursor,
&utf8Cursor,
(context->isIntermediateDataAClassfile()) ? &classDataCursor : NULL,
0, 0, 0, 0,
ROMClassWriter::MARK_AND_COUNT_ONLY);
} else {
context->forceDebugDataInLine();
romClassWriter
->writeROMClass(&mainAreaCursor,
&mainAreaCursor,
&mainAreaCursor,
&utf8Cursor,
(context->isIntermediateDataAClassfile()) ? &classDataCursor : NULL,
0, 0, 0, 0,
ROMClassWriter::MARK_AND_COUNT_ONLY);
}
/* NOTE: the size of the VarHandle MethodType lookup table is already included in
* rcWithOutUTF8sSize; see ROMClassWriter::writeVarHandleMethodTypeLookupTable().
* VarHandleMethodTypeLookupTable is disabled for OpenJDK MethodHandles because
* it is not used.
*/
sizeInformation->rcWithOutUTF8sSize = mainAreaCursor.getCount();
sizeInformation->lineNumberSize = lineNumberCursor.getCount();
sizeInformation->variableInfoSize = variableInfoCursor.getCount();
sizeInformation->utf8sSize = utf8Cursor.getCount();
/* In case of intermediateData being stored as ROMClass, rawClassDataSize will be 0. */
sizeInformation->rawClassDataSize = classDataCursor.getCount();
}
BuildResult
ROMClassBuilder::prepareAndLaydown( BufferManager *bufferManager, ClassFileParser *classFileParser, ROMClassCreationContext *context )
{
bool countDebugDataOutOfLine = false;
BuildResult result = OK;
ROMClassVerbosePhase v0(context, ROMClassPrepareAndLayDown, &result);
PORT_ACCESS_FROM_PORT(_portLibrary);
/*
* If retransforming is enabled, intermediate class data is laid down after the first corresponding ROMClass.
* When a ROMClass is retransformed, the intermediateClassData of the new ROMClass points to the data laid down
* after the old ROMClass. Hence we only lay down intermediate class data if retransforming is enabled, but we
* are not currently retransforming.
*
* With -Xshareclasses:enableBCI sub-option, intermediateClassData is laid down for every ROMClass which is not
* modified by the BCI agent.
*/
Trc_BCU_Assert_False(context->isRetransforming() && !context->isRetransformAllowed());
if (context->isClassAnon() || context->isClassHidden()) {
BuildResult res = handleAnonClassName(classFileParser->getParsedClassFile(), context);
if (OK != res) {
return res;
}
}
ConstantPoolMap constantPoolMap(bufferManager, context);
ClassFileOracle classFileOracle(bufferManager, classFileParser->getParsedClassFile(), &constantPoolMap, _verifyExcludeAttribute, _classFileBuffer, context);
if ( !classFileOracle.isOK() ) {
return classFileOracle.getBuildResult();
}
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
result = injectInterfaces(&classFileOracle);
if (OK != result) {
return result;
}
SRPKeyProducer srpKeyProducer(&classFileOracle, &_interfaceInjectionInfo);
#else /* J9VM_OPT_VALHALLA_VALUE_TYPES */
SRPKeyProducer srpKeyProducer(&classFileOracle);
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
/*
* The ROMClassWriter must be constructed before the SRPOffsetTable because it generates additional SRP keys.
* There must be no SRP keys generated after the SRPOffsetTable is initialized.
*/
#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)
ROMClassWriter romClassWriter(bufferManager, &classFileOracle, &srpKeyProducer, &constantPoolMap, context, &_interfaceInjectionInfo);
#else /* J9VM_OPT_VALHALLA_VALUE_TYPES */
ROMClassWriter romClassWriter(bufferManager, &classFileOracle, &srpKeyProducer, &constantPoolMap, context);
#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */
if ( !romClassWriter.isOK() ) {
return romClassWriter.getBuildResult();
}
SRPOffsetTable srpOffsetTable(&srpKeyProducer, bufferManager, MAX_TAG, context);
if ( !srpOffsetTable.isOK() ) {
return srpOffsetTable.getBuildResult();
}
/* Pass the SRPOffsetTable to the ROMClassWriter to complete its initialization. */
romClassWriter.setSRPOffsetTable(&srpOffsetTable);
U_32 modifiers = classFileOracle.getAccessFlags();
U_32 extraModifiers = computeExtraModifiers(&classFileOracle, context);
U_32 optionalFlags = computeOptionalFlags(&classFileOracle, context);
/*
* calculate the amount of space required to write out this ROMClass without UTF8s
* and calculate the maximum amount of space required for UTF8s
* also prepare the SRP offset information
*/
SizeInformation sizeInformation;
getSizeInfo(context, &romClassWriter, &srpOffsetTable, &countDebugDataOutOfLine, &sizeInformation);
U_32 romSize = 0;
#if JAVA_SPEC_VERSION < 21
U_32 sizeToCompareForLambda = 0;
if (context->isLambdaClass()) {
/*
* romSize calculated from getSizeInfo() does not involve StringInternManager. It is only accurate for string intern disabled classes.
* Lambda classes in java 15 and up are strong hidden classes (defined with Option.STONG), which has the same lifecycle as its
* defining class loader. It is string intern enabled. So pass classFileSize instead of romSize to sizeToCompareForLambda.
*/
sizeToCompareForLambda = classFileOracle.getClassFileSize();
}
#endif /* JAVA_SPEC_VERSION < 21 */
if (context->shouldCompareROMClassForEquality()) {
ROMClassVerbosePhase v(context, CompareHashtableROMClass);
/*
* Check if the supplied ROMClass is identical to the one being created. If it is, simply return OK.
*
* This is done either when there is an orphan ROM class (without a RAM class) that has been created
* previously, or for ROMClass comparison on behalf of dyntest.
*/
J9ROMClass *romClass = context->romClass();
bool romClassIsShared = (j9shr_Query_IsAddressInCache(_javaVM, romClass, romClass->romSize) ? true : false);
if (compareROMClassForEquality(
reinterpret_cast<U_8 *>(romClass),
romClassIsShared,
&romClassWriter,
&srpOffsetTable,
&srpKeyProducer,
&classFileOracle,
modifiers,
extraModifiers,
optionalFlags,
#if JAVA_SPEC_VERSION < 21
sizeToCompareForLambda,
#endif /* JAVA_SPEC_VERSION < 21 */
context)
) {
return OK;
} else {
/* ROM classes not equal so remove from creation context */
context->recordROMClass(NULL);
/* need to recalculate size info and srp offsets, as comparing may have added bogus debug info */
srpOffsetTable.clear();
getSizeInfo(context, &romClassWriter, &srpOffsetTable, &countDebugDataOutOfLine, &sizeInformation);
}
#if defined(J9DYN_TEST)
if (NULL == context->allocationStrategy()) {
/*
* No allocationStrategy is a dyntest request to compare to the existing ROMClass supplied in romClassPtr.
*/
return GenericError;
}
#endif
}
UDATA maxRequiredSize = sizeInformation.rcWithOutUTF8sSize +
sizeInformation.lineNumberSize +
sizeInformation.variableInfoSize +
sizeInformation.utf8sSize +
sizeInformation.rawClassDataSize;
#if defined(J9VM_OPT_SHARED_CLASSES)
if (context->isROMClassShareable()) {
UDATA loadType = J9SHR_LOADTYPE_NORMAL;
if (context->isRedefining()) {
loadType = J9SHR_LOADTYPE_REDEFINED;
} else if (context->isRetransforming()) {
loadType = J9SHR_LOADTYPE_RETRANSFORMED;
} else if (context->isClassUnsafe()
|| context->isClassHidden()
|| (LOAD_LOCATION_UNKNOWN == context->loadLocation())
) {
/* For redefining/transforming, we still want loadType to be J9SHR_LOADTYPE_REDEFINED/J9SHR_LOADTYPE_RETRANSFORMED,
* so put these checks after the redefining/transforming checks.
*/
loadType = J9SHR_LOADTYPE_NOT_FROM_PATH;
}
SCStoreTransaction sharedStoreClassTransaction =
SCStoreTransaction(context->currentVMThread(),
context->classLoader(),
context->cpIndex(),
loadType,
classFileOracle.getUTF8Length(classFileOracle.getClassNameIndex()), classFileOracle.getUTF8Data(classFileOracle.getClassNameIndex()),
context->classFileBytesReplaced(),
context->isCreatingIntermediateROMClass());
if ( sharedStoreClassTransaction.isOK() ) {
/*
* Shared Classes is enabled, there may be an existing ROMClass
* that can be used in place of the one being created.
*
* Attempt to find it.
*
* Note: When comparing classes it is expected that the context contains the
* rom class being compared to. 'prevROMClass' is used to backup the romClass
* currently in the context, so the compare loop can set the romClass in the
* context accordingly.
*/
J9ROMClass * prevROMClass = context->romClass();
for (
J9ROMClass *existingROMClass = sharedStoreClassTransaction.nextSharedClassForCompare();
NULL != existingROMClass;
existingROMClass = sharedStoreClassTransaction.nextSharedClassForCompare()
) {
ROMClassVerbosePhase v(context, CompareSharedROMClass);
if (!context->isIntermediateDataAClassfile()
&& ((U_8 *)existingROMClass == context->intermediateClassData())
) {
/* 'existingROMClass' is same as the ROMClass corresponding to intermediate class data.
* Based on the assumption that an agent is actually modifying the class file
* instead of just returning a copy of the classbytes it receives,
* this comparison can be avoided.
*/
continue;
}
context->recordROMClass(existingROMClass);
if (compareROMClassForEquality(
reinterpret_cast<U_8 *>(existingROMClass),
/* romClassIsShared = */ true,
&romClassWriter,
&srpOffsetTable,
&srpKeyProducer,
&classFileOracle,
modifiers,
extraModifiers,
optionalFlags,
#if JAVA_SPEC_VERSION < 21
sizeToCompareForLambda,
#endif /* JAVA_SPEC_VERSION < 21 */
context)
) {
/*
* Found an existing ROMClass in the shared cache that is equivalent
* to the ROMClass that was about to be created.
* Make the found ROMClass available to our caller and leave the routine.
*/
/* no need to checkDebugInfoCompression when class comes from sharedClassCache since the romClass
* was validated when in was placed in the sharedClassCache */
return OK;
}
}
context->recordROMClass(prevROMClass);
/*
* A shared ROMClass equivalent to the one being created was NOT found.
*
* Attempt to obtain space in the shared cache to laydown (i.e., share)
* the ROMClass being created.
*/
ROMClassVerbosePhase v(context, CreateSharedClass);
J9RomClassRequirements sizeRequirements;
sizeRequirements.romClassMinimalSize =
U_32(sizeInformation.rcWithOutUTF8sSize
+ sizeInformation.utf8sSize + sizeInformation.rawClassDataSize);
sizeRequirements.romClassMinimalSize = ROUND_UP_TO_POWEROF2(sizeRequirements.romClassMinimalSize, sizeof(U_64));
sizeRequirements.romClassSizeFullSize =
U_32(sizeRequirements.romClassMinimalSize
+ sizeInformation.lineNumberSize
+ sizeInformation.variableInfoSize);
sizeRequirements.romClassSizeFullSize = ROUND_UP_TO_POWEROF2(sizeRequirements.romClassSizeFullSize, sizeof(U_64));
sizeRequirements.lineNumberTableSize = U_32(sizeInformation.lineNumberSize);
sizeRequirements.localVariableTableSize = U_32(sizeInformation.variableInfoSize);
/*
* Check sharedStoreClassTransaction.isCacheFull() here because for performance concerns on a full cache, we don't have write mutex if the cache is full/soft full.
* Without this check, j9shr_classStoreTransaction_createSharedClass() does not guarantee returning on checking J9SHR_RUNTIMEFLAG_AVAILABLE_SPACE_FULL in runtimeFlags,
* as another thread that has write mutex may unset this flag, leading to unexpected write operation to the cache without the write mutex.
*/
if (!sharedStoreClassTransaction.isCacheFull()) {
if ( sharedStoreClassTransaction.allocateSharedClass(&sizeRequirements) ){
J9ROMClass *romClassBuffer = (J9ROMClass*)sharedStoreClassTransaction.getRomClass();
/*
* Make note that the laydown is occurring in SharedClasses
*/
extraModifiers |= J9AccClassIsShared;
romSize = finishPrepareAndLaydown(
(U_8*)sharedStoreClassTransaction.getRomClass(),
(U_8*)sharedStoreClassTransaction.getLineNumberTable(),
(U_8*)sharedStoreClassTransaction.getLocalVariableTable(),
&sizeInformation, modifiers, extraModifiers, optionalFlags,
true, sharedStoreClassTransaction.hasSharedStringTableLock(),
&classFileOracle, &srpOffsetTable, &srpKeyProducer, &romClassWriter,
context, &constantPoolMap
);
fixReturnBytecodes(_portLibrary, romClassBuffer);
/*
* inform the shared class transaction what the final ROMSize is
*/
sharedStoreClassTransaction.updateSharedClassSize(romSize);
context->recordROMClass(romClassBuffer);
if ((NULL != _javaVM) && (_javaVM->extendedRuntimeFlags & J9_EXTENDED_RUNTIME_CHECK_DEBUG_INFO_COMPRESSION)) {
checkDebugInfoCompression(romClassBuffer, classFileOracle, &srpKeyProducer, &constantPoolMap, &srpOffsetTable);
}
return OK;
}
/* If sharedStoreClassTransaction.allocateSharedClass() returned false due to the shared cache softmx, unstored bytes is increased inside
* SH_CompositeCacheImpl::allocate(). No need to call sharedStoreClassTransaction.updateUnstoredBytes() here.
*/
} else {
sharedStoreClassTransaction.updateUnstoredBytes(sizeRequirements.romClassSizeFullSize);
}
}
/*
* There is insufficient space available in the shared cache
* to accommodate the ROMClass that is being built.
*
* Terminate the attempted Store Class Transaction.
*
* Simply exit the scope. This will invoke the destructor for
* sharedStoreClassTransaction and terminate the transaction.
*/
}
if (context->isIntermediateDataAClassfile()) {
/* For some reason we are not storing ROMClass in the cache.
* In case we earlier decided to store Intermediate Class File bytes along with ROMClass,
* need to check if we still need them. If not, modify sizeRequirements accordingly.
*
* We don't need to store Intermediate Class File if we fail to store ROMClass in the cache
* when running with -Xshareclasses:enableBCI and class file bytes are not modified and re-transformation is not enabled.
*/
if (context->shouldStripIntermediateClassData()) {
maxRequiredSize -= sizeInformation.rawClassDataSize;
sizeInformation.rawClassDataSize = 0;
}
/* In case ROMClass is not stored in cache, and we are re-transforming,
* try to re-use intermediateClassData from existing ROMClass.
*/
if (false == context->isReusingIntermediateClassData()) {
romClassWriter.reuseIntermediateClassData();
/* Modify size requirements if we are able to reuse intermediate class data now */
if (true == context->isReusingIntermediateClassData()) {
maxRequiredSize -= sizeInformation.rawClassDataSize;
sizeInformation.rawClassDataSize = 0;
}
}
}
#endif /* J9VM_OPT_SHARED_CLASSES */
/*
* Shared Classes is disabled, unavailable, or failed; use the regular allocation strategy.
*/
/*
* request the maximum amount of space to laydown this ROMClass
*/
U_8 *romClassBuffer = NULL;
U_8 *lineNumberBuffer = NULL;
U_8 *variableInfoBuffer = NULL;
AllocationStrategy::AllocatedBuffers allocatedBuffers;
if ( context->allocationStrategy()->allocateWithOutOfLineData( &allocatedBuffers,
sizeInformation.rcWithOutUTF8sSize + sizeInformation.utf8sSize + sizeInformation.rawClassDataSize,
sizeInformation.lineNumberSize, sizeInformation.variableInfoSize)
) {
romClassBuffer = allocatedBuffers.romClassBuffer;
lineNumberBuffer = allocatedBuffers.lineNumberBuffer;
variableInfoBuffer = allocatedBuffers.variableInfoBuffer;
} else {
/* Pad maxRequiredSize to the size to sizeof(U_64) in order to prevent memory corruption.
* This mirrors ROM class padding in finishPrepareAndLaydown when the final ROM class size
* is calculated.
*/
maxRequiredSize = ROUND_UP_TO_POWEROF2(maxRequiredSize, sizeof(U_64));
romClassBuffer = context->allocationStrategy()->allocate(maxRequiredSize);
}
if ( romClassBuffer == NULL ) {
return OutOfROM;
}
/*
* Use an if statement here and call finishPrepareAndLaydown() in both cases to allow the scope of SCStringTransaction() to survive the life of the call to
* finishPrepareAndLaydown(). Otherwise, the scope of SCStringTransaction() would end early and it would not be safe to us interned strings.
*/
if (J9_ARE_ANY_BITS_SET(context->findClassFlags(), J9_FINDCLASS_FLAG_ANON | J9_FINDCLASS_FLAG_HIDDEN)) {
U_16 classNameIndex = classFileOracle.getClassNameIndex();
U_8* classNameBytes = classFileOracle.getUTF8Data(classNameIndex);
U_16 classNameFullLength = classFileOracle.getUTF8Length(classNameIndex);
U_16 classNameRealLenghth = classNameFullLength - ROM_ADDRESS_LENGTH;
char* nameString = NULL;
char message[ROM_ADDRESS_LENGTH + 1];
if (J9_ARE_ALL_BITS_SET(context->findClassFlags(), J9_FINDCLASS_FLAG_REDEFINING)
|| J9_ARE_ALL_BITS_SET(context->findClassFlags(), J9_FINDCLASS_FLAG_RETRANSFORMING)
) {
/* When redefining we need to use the original class name */
nameString = ((char*) context->className() + classNameRealLenghth);
} else {
/* fix up the ROM className with segment Address
* write the name into a buffer first because j9str_printf automatically adds a NULL terminator
* at the end, and J9UTF8 are not NULL terminated
*/
j9str_printf(message, ROM_ADDRESS_LENGTH + 1, ROM_ADDRESS_FORMAT, (UDATA)romClassBuffer);
nameString = (char*) message;
}
memcpy((char*) (classNameBytes + classNameRealLenghth), nameString, ROM_ADDRESS_LENGTH);
}
#if defined(J9VM_OPT_SHARED_CLASSES)
if (NULL != context->javaVM()) {
SCStringTransaction scStringTransaction = SCStringTransaction(context->currentVMThread());
romSize = finishPrepareAndLaydown(romClassBuffer, lineNumberBuffer, variableInfoBuffer, &sizeInformation, modifiers, extraModifiers, optionalFlags,
false, scStringTransaction.isOK(), &classFileOracle, &srpOffsetTable, &srpKeyProducer, &romClassWriter, context, &constantPoolMap);
} else
#endif
{
romSize = finishPrepareAndLaydown(romClassBuffer, lineNumberBuffer, variableInfoBuffer, &sizeInformation, modifiers, extraModifiers, optionalFlags,
false, false, &classFileOracle, &srpOffsetTable, &srpKeyProducer, &romClassWriter, context, &constantPoolMap);
}
/* This assert will detect memory corruption when a new segment
* for the ROM class was allocated using maxRequiredSize.
*/
Trc_BCU_Assert_True_Level1(romSize <= maxRequiredSize);
/*
* inform the allocator what the final ROMSize is
*/
if (J9_ARE_ALL_BITS_SET(context->findClassFlags(), J9_FINDCLASS_FLAG_ANON)) {
/* for anonClasses lie about the size report that it is full so no one else can use the segment */
romSize = (U_32) ((ROMClassSegmentAllocationStrategy*) context->allocationStrategy())->getSegmentSize();
}
context->allocationStrategy()->updateFinalROMSize(romSize);
context->recordROMClass((J9ROMClass *)romClassBuffer);
if ((NULL != _javaVM) && (_javaVM->extendedRuntimeFlags & J9_EXTENDED_RUNTIME_CHECK_DEBUG_INFO_COMPRESSION)) {
checkDebugInfoCompression((J9ROMClass *)romClassBuffer, classFileOracle, &srpKeyProducer, &constantPoolMap, &srpOffsetTable);
}
return OK;
}
/*
* Test the compression of the ROMclass'debug information when running the command
* Tests the line number compression and the local variable table compression
* -Xcheck:vm:debuginfo
*/
void
ROMClassBuilder::checkDebugInfoCompression(J9ROMClass *romClass, ClassFileOracle classFileOracle, SRPKeyProducer *srpKeyProducer, ConstantPoolMap *constantPoolMap, SRPOffsetTable *srpOffsetTable)
{
PORT_ACCESS_FROM_PORT(_portLibrary);
J9ROMMethod *currentMethod;
currentMethod = (J9ROMMethod*)(J9ROMCLASS_ROMMETHODS(romClass));
for (ClassFileOracle::MethodIterator methodIterator = classFileOracle.getMethodIterator();
methodIterator.isNotDone();
methodIterator.next()) {
/* 1) Test the line number compression */
UDATA lineNumbersInfoSize = methodIterator.getLineNumbersCount() * sizeof (J9CfrLineNumberTableEntry);
if (0 != lineNumbersInfoSize) {
J9CfrLineNumberTableEntry *lineNumbersInfo = (J9CfrLineNumberTableEntry*)j9mem_allocate_memory(lineNumbersInfoSize, J9MEM_CATEGORY_CLASSES);
if (NULL != lineNumbersInfo) {
classFileOracle.sortLineNumberTable(methodIterator.getIndex(), lineNumbersInfo);
J9LineNumber lineNumber;
lineNumber.lineNumber = 0;
lineNumber.location = 0;
J9MethodDebugInfo *methodInfo = getMethodDebugInfoFromROMMethod(currentMethod);
if (NULL != methodInfo) {
U_8 *currentLineNumber = getLineNumberTable(methodInfo);
U_32 lineNumbersCount = getLineNumberCount(methodInfo);
UDATA index;
Trc_BCU_Assert_CorrectLineNumbersCount(lineNumbersCount, methodIterator.getLineNumbersCount());
if (0 != lineNumbersCount) {
for (index = 0; index < lineNumbersCount; index++) {
/* From the original class */
U_32 pcOriginal = lineNumbersInfo[index].startPC;
U_32 lineNumberOriginal = lineNumbersInfo[index].lineNumber;
/* From the compressed class */
getNextLineNumberFromTable(¤tLineNumber, &lineNumber);
if ((lineNumber.lineNumber != lineNumberOriginal) || (lineNumber.location != pcOriginal)) {
J9UTF8* name = J9ROMCLASS_CLASSNAME(romClass);
PORT_ACCESS_FROM_PORT(_portLibrary);
j9tty_printf(PORTLIB, "Error while uncompressing the debug information for the class %.*s\n", (UDATA)J9UTF8_LENGTH(name), J9UTF8_DATA(name));
j9tty_printf(PORTLIB, "lineNumber.lineNumber(%d) / lineNumberOriginal(%d)\n", lineNumber.lineNumber,lineNumberOriginal);
j9tty_printf(PORTLIB, "lineNumber.location(%d) / pcOriginal(%d)\n", lineNumber.location, pcOriginal);
Trc_BCU_Assert_ShouldNeverHappen_CompressionMissmatch();
}
}
}
}
j9mem_free_memory(lineNumbersInfo);
} else {
Trc_BCU_Assert_Compression_OutOfMemory();
}
}
/* 2) Test local variable table compression */