Skip to content

Commit a4af783

Browse files
authored
Merge pull request #18976 from cjjdespres/romclass-var-table-walk
Add var handle method type lookup table walking
2 parents f2a7cfb + 703bea7 commit a4af783

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed

runtime/compiler/control/JITServerHelpers.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -460,17 +460,14 @@ packArrayROMClassData(const J9ROMClass *romClass, ROMClassPackContext &ctx)
460460
// Calculate the size of the portion of a ROM class that occurs before its UTF8 string section (the pre-string section),
461461
// without any padding that may have been added during initial ROM class writing.
462462
//
463-
// Why is this necessary? The sections inside a ROMClass before the UTF8 string section are 32-bit aligned, but the
464-
// entire pre-string section needs to be 64-bit aligned. That means exactly four bytes of padding may have been added
465-
// to the end of the pre-string section during initial ROM class building. When we strip out the debug
466-
// info from a ROM class, we might reintroduce a misalignment in this pre-string section. Two scenarios are possible:
467-
//
468-
// 1. The original ROM class was padded, in which case the solution is to drop that four bytes of padding
469-
// 2. The original ROM class was not padded, in which case the solution is to introduce four bytes of padding
470-
//
471-
// We can only distinguish between scenarios (1) and (2) if we know the unpadded size of the pre-string section.
472-
// Once we have this information, we can calculate the aligned and padded size of the pre-string section (currently called the
473-
// packedNonStringSize) properly in packROMClass.
463+
// Why is this necessary? The sections inside a ROMClass before the UTF8 string section are not, taken together,
464+
// necessarily 64-bit aligned. The ROM class format requires the entire pre-string segment of the ROM class to
465+
// be 64-bit aligned, so padding may have been added between the last pre-string section and the UTF8 string section.
466+
// When we strip out the debug info from a ROM class, we might reintroduce a misalignment in this pre-string section.
467+
// Fixing this misalignment might require us to add more padding, or to drop some of the padding that was already added
468+
// during ROM class writing. We can only decide to do one or the other if we know the unpadded size of the pre-string
469+
// section. Once we have this information, we can calculate the aligned and padded size of the pre-string section
470+
// (currently called the packedNonStringSize) properly in packROMClass.
474471
static void
475472
sectionEndCallback(J9ROMClass *romClass, void *sectionPtr, uintptr_t sectionSize, const char *sectionName, void *userData)
476473
{
@@ -614,6 +611,10 @@ JITServerHelpers::packROMClass(J9ROMClass *romClass, TR_Memory *trMemory, TR_J9V
614611
end = (const uint8_t *)OMR::alignNoCheck((uintptr_t)end, sizeof(uint64_t));
615612
TR_ASSERT_FATAL(end == classEnd, "UTF8 section not stored at the end of ROMClass %.*s: %p != %p",
616613
name->length, name->data, end, classEnd);
614+
// A note to future debuggers: if the assert below failed and
615+
// ctx._preString < ctx._origUtf8SectionStart - ctx._origRomClassStart, then the most likely cause is that someone added a
616+
// new section to J9ROMClass and neglected to update romclasswalk.c. Either that or the size of a section is being calculated
617+
// incorrectly.
617618
TR_ASSERT_FATAL(OMR::alignNoCheck(ctx._preStringSize, sizeof(uint64_t)) == (ctx._origUtf8SectionStart - ctx._origRomClassStart),
618619
"Pre-string end offset in ROMClass %.*s must be within padding of the UTF8 section start: %lu %lu",
619620
name->length, name->data, ctx._preStringSize, ctx._origUtf8SectionStart - ctx._origRomClassStart);

runtime/oti/j9nonbuilder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,6 +3582,9 @@ typedef struct J9ROMClass {
35823582
#endif /* JAVA_SPEC_VERSION >= 11 */
35833583
#define J9ROMCLASS_OPTIONALINFO(base) SRP_GET((base)->optionalInfo, U_32*)
35843584
#define J9ROMCLASS_CALLSITEDATA(base) SRP_GET((base)->callSiteData, U_8*)
3585+
#if defined(J9VM_OPT_METHOD_HANDLE)
3586+
#define J9ROMCLASS_VARHANDLEMETHODTYPELOOKUPTABLE(base) SRP_GET((base)->varHandleMethodTypeLookupTable, U_16*)
3587+
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
35853588
#define J9ROMCLASS_STATICSPLITMETHODREFINDEXES(base) SRP_GET((base)->staticSplitMethodRefIndexes, U_16*)
35863589
#define J9ROMCLASS_SPECIALSPLITMETHODREFINDEXES(base) SRP_GET((base)->specialSplitMethodRefIndexes, U_16*)
35873590

runtime/util/romclasswalk.c

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ static void allSlotsInBytecodesDo (J9ROMClass* romClass, J9ROMMethod* method, J9
4646
static void allSlotsInCPShapeDescriptionDo (J9ROMClass* romClass, J9ROMClassWalkCallbacks* callbacks, void* userData);
4747
static void allSlotsInCallSiteDataDo (J9ROMClass* romClass, J9ROMClassWalkCallbacks* callbacks, void* userData);
4848
static UDATA allSlotsInMethodParametersDataDo(J9ROMClass* romClass, U_8* cursor, J9ROMClassWalkCallbacks* callbacks, void* userData);
49+
#if defined(J9VM_OPT_METHOD_HANDLE)
50+
static void allSlotsInVarHandleMethodTypeLookupTableDo(J9ROMClass* romClass, J9ROMClassWalkCallbacks* callbacks, void* userData);
51+
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
4952
static void allSlotsInStaticSplitMethodRefIndexesDo (J9ROMClass* romClass, J9ROMClassWalkCallbacks* callbacks, void* userData);
5053
static void allSlotsInSpecialSplitMethodRefIndexesDo (J9ROMClass* romClass, J9ROMClassWalkCallbacks* callbacks, void* userData);
5154
static void allSlotsInSourceDebugExtensionDo (J9ROMClass* romClass, J9SourceDebugExtension* sde, J9ROMClassWalkCallbacks* callbacks, void* userData);
@@ -55,7 +58,7 @@ static void nullSectionCallback(J9ROMClass*, void*, UDATA, const char*, void*);
5558
static BOOLEAN defaultValidateRangeCallback(J9ROMClass*, void*, UDATA, void*);
5659

5760
#define SLOT_CALLBACK(romClassPtr, slotType, structure, slotName) callbacks->slotCallback(romClassPtr, slotType, &structure->slotName, #slotName, userData)
58-
/*
61+
/*
5962
* Walk all slots in the J9ROMClass, calling callback for each slot.
6063
* Identify the type of slot using one of the J9ROM_ constants defined in the header file.
6164
* Note that NAS and UTF8 slots are treated specially, since, as invariants, they may
@@ -236,6 +239,9 @@ void allSlotsInROMClassDo(J9ROMClass* romClass,
236239
allSlotsInConstantPoolDo(romClass, callbacks, userData);
237240
allSlotsInCallSiteDataDo(romClass, callbacks, userData);
238241
allSlotsInOptionalInfoDo(romClass, callbacks, userData);
242+
#if defined(J9VM_OPT_METHOD_HANDLE)
243+
allSlotsInVarHandleMethodTypeLookupTableDo(romClass, callbacks, userData);
244+
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
239245
allSlotsInStaticSplitMethodRefIndexesDo(romClass, callbacks, userData);
240246
allSlotsInSpecialSplitMethodRefIndexesDo(romClass, callbacks, userData);
241247
}
@@ -328,15 +334,15 @@ static J9ROMMethod* allSlotsInROMMethodDo(J9ROMClass* romClass, J9ROMMethod* met
328334
cursor += allSlotsInAnnotationDo(romClass, (U_32 *)cursor, "methodAnnotation", callbacks, userData);
329335
}
330336

331-
337+
332338
if (J9ROMMETHOD_HAS_PARAMETER_ANNOTATIONS(method)) {
333339
cursor += allSlotsInAnnotationDo(romClass, (U_32 *)cursor, "parameterAnnotations", callbacks, userData);
334340
}
335341

336342
if (J9ROMMETHOD_HAS_DEFAULT_ANNOTATION(method)) {
337343
cursor += allSlotsInAnnotationDo(romClass, (U_32 *)cursor, "defaultAnnotation", callbacks, userData);
338344
}
339-
345+
340346
if (J9ROMMETHOD_HAS_METHOD_TYPE_ANNOTATIONS(extendedModifiers)) {
341347
cursor += allSlotsInAnnotationDo(romClass, (U_32 *)cursor, "methodTypeAnnotations", callbacks, userData);
342348
}
@@ -362,7 +368,7 @@ static J9ROMMethod* allSlotsInROMMethodDo(J9ROMClass* romClass, J9ROMMethod* met
362368
}
363369

364370
if (J9ROMMETHOD_HAS_METHOD_PARAMETERS(method)) {
365-
371+
366372
cursor += allSlotsInMethodParametersDataDo(romClass, (U_8*)cursor, callbacks, userData);
367373
}
368374

@@ -465,7 +471,7 @@ static void allSlotsInBytecodesDo(J9ROMClass* romClass, J9ROMMethod* method, J9R
465471
BOOLEAN rangeValid;
466472

467473
/* bytecodeSizeLow already walked */
468-
length = J9_BYTECODE_SIZE_FROM_ROM_METHOD(method);
474+
length = J9_BYTECODE_SIZE_FROM_ROM_METHOD(method);
469475

470476
if (length == 0) return;
471477
pc = bytecodes = J9_BYTECODE_START_FROM_ROM_METHOD(method); /* endian safe */
@@ -497,7 +503,7 @@ static void allSlotsInBytecodesDo(J9ROMClass* romClass, J9ROMMethod* method, J9R
497503
callbacks->slotCallback(romClass, J9ROM_U8, pc, "bcArg8", userData);
498504
pc += 1;
499505
break;
500-
506+
501507
/* Single 16-bit argument */
502508
case JBinvokeinterface2:
503509
callbacks->slotCallback(romClass, J9ROM_U8, pc, "bcArg8", userData);
@@ -618,7 +624,7 @@ static void allSlotsInBytecodesDo(J9ROMClass* romClass, J9ROMMethod* method, J9R
618624
pc += 4;
619625
}
620626
break;
621-
627+
622628

623629
case JBlookupswitch:
624630
switch((pc - bytecodes - 1) % 4) {
@@ -823,7 +829,7 @@ static void allSlotsInRecordDo(J9ROMClass* romClass, U_32* recordPointer, J9ROMC
823829
callbacks->sectionCallback(romClass, recordPointer, (UDATA)cursor - (UDATA)recordPointer, "recordInfo", userData);
824830
}
825831

826-
static void
832+
static void
827833
allSlotsInPermittedSubclassesDo(J9ROMClass* romClass, U_32* permittedSubclassesPointer, J9ROMClassWalkCallbacks* callbacks, void* userData)
828834
{
829835
BOOLEAN rangeValid = FALSE;
@@ -838,7 +844,7 @@ allSlotsInPermittedSubclassesDo(J9ROMClass* romClass, U_32* permittedSubclassesP
838844
callbacks->slotCallback(romClass, J9ROM_U32, cursor, "permittedSubclassesCount", userData);
839845
cursor += 1;
840846
permittedSubclassesCount = *permittedSubclassesPointer;
841-
847+
842848
for (; permittedSubclassesCount > 0; permittedSubclassesCount--) {
843849
rangeValid = callbacks->validateRangeCallback(romClass, cursor, sizeof(U_32), userData);
844850
if (FALSE == rangeValid) {
@@ -902,7 +908,7 @@ allSlotsInImplicitCreationAttributeDo(J9ROMClass* romClass, U_32* implicitCreati
902908
/*
903909
* See ROMClassWriter::writeOptionalInfo for illustration of the layout.
904910
*/
905-
static void
911+
static void
906912
allSlotsInOptionalInfoDo(J9ROMClass* romClass, J9ROMClassWalkCallbacks* callbacks, void* userData)
907913
{
908914
U_32 *optionalInfo;
@@ -1019,7 +1025,30 @@ allSlotsInOptionalInfoDo(J9ROMClass* romClass, J9ROMClassWalkCallbacks* callback
10191025
callbacks->sectionCallback(romClass, optionalInfo, (UDATA)cursor - (UDATA)optionalInfo, "optionalInfo", userData);
10201026
}
10211027

1022-
static void
1028+
#if defined(J9VM_OPT_METHOD_HANDLE)
1029+
static void
1030+
allSlotsInVarHandleMethodTypeLookupTableDo(J9ROMClass* romClass, J9ROMClassWalkCallbacks* callbacks, void* userData)
1031+
{
1032+
U_32 count = romClass->varHandleMethodTypeCount;
1033+
1034+
if (count > 0) {
1035+
U_16 *cursor = J9ROMCLASS_VARHANDLEMETHODTYPELOOKUPTABLE(romClass);
1036+
BOOLEAN rangeValid = callbacks->validateRangeCallback(romClass, cursor, count * sizeof(U_16), userData);
1037+
1038+
if (rangeValid) {
1039+
U_32 i = 0;
1040+
1041+
callbacks->sectionCallback(romClass, cursor, count * sizeof(U_16), "varHandleMethodTypeLookupTable", userData);
1042+
for (i = 0; i < count; i++) {
1043+
callbacks->slotCallback(romClass, J9ROM_U16, cursor, "cpIndex", userData);
1044+
cursor += 1;
1045+
}
1046+
}
1047+
}
1048+
}
1049+
#endif /* defined(J9VM_OPT_METHOD_HANDLE) */
1050+
1051+
static void
10231052
allSlotsInStaticSplitMethodRefIndexesDo(J9ROMClass* romClass, J9ROMClassWalkCallbacks* callbacks, void* userData)
10241053
{
10251054
U_16 count = romClass->staticSplitMethodRefCount;
@@ -1040,7 +1069,7 @@ allSlotsInStaticSplitMethodRefIndexesDo(J9ROMClass* romClass, J9ROMClassWalkCall
10401069
}
10411070
}
10421071

1043-
static void
1072+
static void
10441073
allSlotsInSpecialSplitMethodRefIndexesDo(J9ROMClass* romClass, J9ROMClassWalkCallbacks* callbacks, void* userData)
10451074
{
10461075
U_16 count = romClass->specialSplitMethodRefCount;
@@ -1441,7 +1470,7 @@ static void allSlotsInCallSiteDataDo (J9ROMClass* romClass, J9ROMClassWalkCallba
14411470
* U_16 argument[argumentCount];
14421471
* } bootStrapMethodData[romClass->bsmCount];
14431472
* }
1444-
*
1473+
*
14451474
* Note: SRP is 32 bits
14461475
*/
14471476
BOOLEAN rangeValid;

0 commit comments

Comments
 (0)