Skip to content

Commit

Permalink
Merge pull request #2874 from jdmpapin/aot-nestmates
Browse files Browse the repository at this point in the history
Add TR_J2IVirtualThunkPointer relocation kind
  • Loading branch information
andrewcraik authored Sep 17, 2018
2 parents 0870483 + 0da7fa8 commit 1bd7735
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 9 deletions.
17 changes: 17 additions & 0 deletions runtime/compiler/arm/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ uint8_t *J9::ARM::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterated
cursor += SIZEPOINTER;
break;
}

case TR_J2IVirtualThunkPointer:
{
auto info = (TR_RelocationRecordInformation*)relocation->getTargetAddress();

*(uintptrj_t *)cursor = (uintptrj_t)info->data2; // inlined site index
cursor += SIZEPOINTER;

*(uintptrj_t *)cursor = (uintptrj_t)info->data1; // constantPool
cursor += SIZEPOINTER;

*(uintptrj_t *)cursor = (uintptrj_t)info->data3; // offset to J2I virtual thunk pointer
cursor += SIZEPOINTER;
}
break;

case TR_CheckMethodEnter:
case TR_CheckMethodExit:
{
Expand Down Expand Up @@ -742,6 +758,7 @@ uint32_t J9::ARM::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_Nu
16, // TR_ArbitraryClassAddress = 58,
28, // TR_DebugCounter = 59
4, // TR_ClassUnloadAssumption = 60
16, // TR_J2IVirtualThunkPointer = 61
};


Expand Down
18 changes: 18 additions & 0 deletions runtime/compiler/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,24 @@ J9::AheadOfTimeCompile::dumpRelocationData()
}
}
break;
case TR_J2IVirtualThunkPointer:
cursor++; // unused field
cursor += is64BitTarget ? 4 : 0;
ep1 = cursor;
ep2 = cursor + sizeof(uintptrj_t);
ep3 = cursor + 2 * sizeof(uintptrj_t);
cursor += 3 * sizeof(uintptrj_t);
self()->traceRelocationOffsets(cursor, offsetSize, endOfCurrentRecord, orderedPair);
if (isVerbose)
{
traceMsg(
self()->comp(),
"\nInlined site index %lld, constant pool 0x%llx, offset to j2i thunk pointer 0x%llx",
(int64_t)*(uintptrj_t*)ep1,
(uint64_t)*(uintptrj_t*)ep2,
(uint64_t)*(uintptrj_t*)ep3);
}
break;
case TR_Trampolines:
// constant pool address is placed as the last word of the header
//traceMsg(self()->comp(), "\nConstant pool %x\n", *(uint32_t *)++cursor);
Expand Down
17 changes: 17 additions & 0 deletions runtime/compiler/p/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,21 @@ uint8_t *J9::Power::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterat
}
break;

case TR_J2IVirtualThunkPointer:
{
auto info = (TR_RelocationRecordInformation*)relocation->getTargetAddress();

*(uintptrj_t *)cursor = (uintptrj_t)info->data2; // inlined site index
cursor += SIZEPOINTER;

*(uintptrj_t *)cursor = (uintptrj_t)info->data1; // constantPool
cursor += SIZEPOINTER;

*(uintptrj_t *)cursor = (uintptrj_t)info->data3; // offset to J2I virtual thunk pointer
cursor += SIZEPOINTER;
}
break;

case TR_CheckMethodEnter:
case TR_CheckMethodExit:
{
Expand Down Expand Up @@ -891,6 +906,7 @@ uint32_t J9::Power::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_
32, // TR_ArbitraryClassAddress = 58,
56, // TR_DebugCounter = 59
8, // TR_ClassUnloadAssumption = 60
32, // TR_J2IVirtualThunkPointer = 61
};
#else
uint32_t J9::Power::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_NumExternalRelocationKinds] =
Expand Down Expand Up @@ -956,6 +972,7 @@ uint32_t J9::Power::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_
16, // TR_ArbitraryClassAddress = 58,
28, // TR_DebugCounter = 59
4, // TR_ClassUnloadAssumption = 60
16, // TR_J2IVirtualThunkPointer = 61
};

#endif
Expand Down
63 changes: 55 additions & 8 deletions runtime/compiler/runtime/RelocationRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,11 @@ struct TR_RelocationRecordConstantPoolWithIndexBinaryTemplate : public TR_Reloca

typedef TR_RelocationRecordConstantPoolWithIndexBinaryTemplate TR_RelocationRecordClassObjectBinaryTemplate;

struct TR_RelocationRecordThunksBinaryTemplate : public TR_RelocationRecordConstantPoolBinaryTemplate
struct TR_RelocationRecordJ2IVirtualThunkPointerBinaryTemplate : public TR_RelocationRecordConstantPoolBinaryTemplate
{
UDATA _thunkAddress;
IDATA _offsetToJ2IVirtualThunkPointer;
};

typedef TR_RelocationRecordThunksBinaryTemplate TR_RelocationRecordThunksJXEBinaryTemplate;

struct TR_RelocationRecordInlinedAllocationBinaryTemplate : public TR_RelocationRecordConstantPoolWithIndexBinaryTemplate
{
UDATA _branchOffset;
Expand Down Expand Up @@ -428,6 +426,9 @@ TR_RelocationRecord::create(TR_RelocationRecord *storage, TR_RelocationRuntime *
case TR_Thunks:
reloRecord = new (storage) TR_RelocationRecordThunks(reloRuntime, record);
break;
case TR_J2IVirtualThunkPointer:
reloRecord = new (storage) TR_RelocationRecordJ2IVirtualThunkPointer(reloRuntime, record);
break;
case TR_GlobalValue:
reloRecord = new (storage) TR_RelocationRecordGlobalValue(reloRuntime, record);
break;
Expand Down Expand Up @@ -1710,11 +1711,16 @@ TR_RelocationRecordThunks::applyRelocation(TR_RelocationRuntime *reloRuntime, TR
reloTarget->storeAddress((uint8_t *)newConstantPool, reloLocation);
uintptrj_t cpIndex = reloTarget->loadThunkCPIndex(reloLocation);
RELO_LOG(reloRuntime->reloLogger(), 6, "\t\tapplyRelocation: loadThunkCPIndex is %d\n", cpIndex);
return relocateAndRegisterThunk(reloRuntime, reloTarget, newConstantPool, cpIndex);
return relocateAndRegisterThunk(reloRuntime, reloTarget, newConstantPool, cpIndex, reloLocation);
}

int32_t
TR_RelocationRecordThunks::relocateAndRegisterThunk(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uintptrj_t cp, uintptr_t cpIndex)
TR_RelocationRecordThunks::relocateAndRegisterThunk(
TR_RelocationRuntime *reloRuntime,
TR_RelocationTarget *reloTarget,
uintptrj_t cp,
uintptr_t cpIndex,
uint8_t *reloLocation)
{
J9JITConfig *jitConfig = reloRuntime->jitConfig();
J9JavaVM *javaVM = reloRuntime->jitConfig()->javaVM;
Expand All @@ -1734,10 +1740,12 @@ TR_RelocationRecordThunks::relocateAndRegisterThunk(TR_RelocationRuntime *reloRu
// Everything below is run with VM Access in hand
TR::VMAccessCriticalSection relocateAndRegisterThunkCriticalSection(reloRuntime->fej9());

if (j9ThunkLookupNameAndSig(jitConfig, nameAndSignature))
void *existingThunk = j9ThunkLookupNameAndSig(jitConfig, nameAndSignature);
if (existingThunk != NULL)
{
/* Matching thunk found */
RELO_LOG(reloRuntime->reloLogger(), 6, "\t\t\trelocateAndRegisterThunk:found matching thunk %p\n");
RELO_LOG(reloRuntime->reloLogger(), 6, "\t\t\trelocateAndRegisterThunk:found matching thunk %p\n", existingThunk);
relocateJ2IVirtualThunkPointer(reloTarget, reloLocation, existingThunk);
return 0; // return successful
}

Expand Down Expand Up @@ -1786,6 +1794,8 @@ TR_RelocationRecordThunks::relocateAndRegisterThunk(TR_RelocationRuntime *reloRu

if (J9_EVENT_IS_HOOKED(javaVM->hookInterface, J9HOOK_VM_DYNAMIC_CODE_LOAD))
ALWAYS_TRIGGER_J9HOOK_VM_DYNAMIC_CODE_LOAD(javaVM->hookInterface, javaVM->internalVMFunctions->currentVMThread(javaVM), NULL, (void *) thunkAddress, *((uint32_t *)thunkAddress - 2), "JIT virtual thunk", NULL);

relocateJ2IVirtualThunkPointer(reloTarget, reloLocation, thunkAddress);
}
else
{
Expand All @@ -1804,6 +1814,43 @@ TR_RelocationRecordThunks::relocateAndRegisterThunk(TR_RelocationRuntime *reloRu
return 0;
}

// TR_J2IVirtualThunkPointer Relocation
char *
TR_RelocationRecordJ2IVirtualThunkPointer::name()
{
return "TR_J2IVirtualThunkPointer";
}

int32_t
TR_RelocationRecordJ2IVirtualThunkPointer::bytesInHeaderAndPayload()
{
return sizeof(TR_RelocationRecordJ2IVirtualThunkPointerBinaryTemplate);
}

void
TR_RelocationRecordJ2IVirtualThunkPointer::relocateJ2IVirtualThunkPointer(
TR_RelocationTarget *reloTarget,
uint8_t *reloLocation,
void *thunk)
{
TR_ASSERT_FATAL(thunk != NULL, "expected a j2i virtual thunk for relocation\n");

// For uniformity with TR_Thunks, the reloLocation is not the location of the
// J2I thunk pointer, but rather the location of the constant pool address.
// Find the J2I thunk pointer relative to that.
reloLocation += offsetToJ2IVirtualThunkPointer(reloTarget);
reloTarget->storeAddress((uint8_t *)thunk, reloLocation);
}

uintptrj_t
TR_RelocationRecordJ2IVirtualThunkPointer::offsetToJ2IVirtualThunkPointer(
TR_RelocationTarget *reloTarget)
{
auto recordData = (TR_RelocationRecordJ2IVirtualThunkPointerBinaryTemplate *)_record;
auto offsetEA = (uintptrj_t *) &recordData->_offsetToJ2IVirtualThunkPointer;
return reloTarget->loadRelocationRecordValue(offsetEA);
}

// TR_PicTrampolines Relocation
char *
TR_RelocationRecordPicTrampolines::name()
Expand Down
23 changes: 22 additions & 1 deletion runtime/compiler/runtime/RelocationRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,30 @@ class TR_RelocationRecordThunks : public TR_RelocationRecordConstantPool
virtual int32_t applyRelocation(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uint8_t *reloLocation);

protected:
virtual int32_t relocateAndRegisterThunk(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uintptrj_t cp, uintptr_t cpIndex);
int32_t relocateAndRegisterThunk(TR_RelocationRuntime *reloRuntime, TR_RelocationTarget *reloTarget, uintptrj_t cp, uintptr_t cpIndex, uint8_t *reloLocation);

/** Relocate the J2I virtual thunk pointer, if applicable */
virtual void relocateJ2IVirtualThunkPointer(TR_RelocationTarget *reloTarget, uint8_t *reloLocation, void *thunk)
{
// nothing to relocate
}
};

class TR_RelocationRecordJ2IVirtualThunkPointer : public TR_RelocationRecordThunks
{
public:
TR_RelocationRecordJ2IVirtualThunkPointer() {}

TR_RelocationRecordJ2IVirtualThunkPointer(TR_RelocationRuntime *reloRuntime, TR_RelocationRecordBinaryTemplate *record)
: TR_RelocationRecordThunks(reloRuntime, record) {}

virtual char *name();
virtual int32_t bytesInHeaderAndPayload();

protected:
virtual void relocateJ2IVirtualThunkPointer(TR_RelocationTarget *reloTarget, uint8_t *reloLocation, void *thunk);
uintptrj_t offsetToJ2IVirtualThunkPointer(TR_RelocationTarget *reloTarget);
};

class TR_RelocationRecordTrampolines : public TR_RelocationRecordConstantPool
{
Expand Down
18 changes: 18 additions & 0 deletions runtime/compiler/x/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,22 @@ uint8_t *J9::X86::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::Iterated
}
break;

case TR_J2IVirtualThunkPointer:
{
// Note: thunk relos should only be created for 64 bit
auto info = (TR_RelocationRecordInformation*)relocation->getTargetAddress();

*(uintptrj_t *)cursor = (uintptrj_t)info->data2; // inlined site index
cursor += SIZEPOINTER;

*(uintptrj_t *)cursor = (uintptrj_t)info->data1; // constantPool
cursor += SIZEPOINTER;

*(uintptrj_t *)cursor = (uintptrj_t)info->data3; // offset to J2I virtual thunk pointer
cursor += SIZEPOINTER;
}
break;

case TR_PicTrampolines:
{
TR_ASSERT(TR::Compiler->target.is64Bit(), "TR_PicTrampolines not supported on 32-bit");
Expand Down Expand Up @@ -687,6 +703,7 @@ uint32_t J9::X86::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_Nu
32, // TR_ArbitraryClassAddress = 58,
56, // TR_DebugCounter = 59
8, // TR_ClassUnloadAssumption = 60
32, // TR_J2IVirtualThunkPointer = 61,
#else

12, // TR_ConstantPool = 0
Expand Down Expand Up @@ -750,6 +767,7 @@ uint32_t J9::X86::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_Nu
16, // TR_ArbitraryClassAddress = 58,
28, // TR_DebugCounter = 59
4, // TR_ClassUnloadAssumption = 60
16, // TR_J2IVirtualThunkPointer = 61,
#endif
};

17 changes: 17 additions & 0 deletions runtime/compiler/z/codegen/J9AheadOfTimeCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,21 @@ uint8_t *J9::Z::AheadOfTimeCompile::initializeAOTRelocationHeader(TR::IteratedEx
}
break;

case TR_J2IVirtualThunkPointer:
{
auto info = (TR_RelocationRecordInformation*)relocation->getTargetAddress();

*(uintptrj_t *)cursor = (uintptrj_t)info->data2; // inlined site index
cursor += SIZEPOINTER;

*(uintptrj_t *)cursor = (uintptrj_t)info->data1; // constantPool
cursor += SIZEPOINTER;

*(uintptrj_t *)cursor = (uintptrj_t)info->data3; // offset to J2I virtual thunk pointer
cursor += SIZEPOINTER;
}
break;

case TR_CheckMethodEnter:
case TR_CheckMethodExit:
{
Expand Down Expand Up @@ -1009,6 +1024,7 @@ uint32_t J9::Z::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_NumE
32, // TR_ArbitraryClassAddress = 58,
56, // TR_DebugCounter = 59
8, // TR_ClassUnloadAssumption = 60
32, // TR_J2IVirtualThunkPointer = 61
};

#else
Expand Down Expand Up @@ -1076,6 +1092,7 @@ uint32_t J9::Z::AheadOfTimeCompile::_relocationTargetTypeToHeaderSizeMap[TR_NumE
16, // TR_ArbitraryClassAddress = 58,
28, // TR_DebugCounter = 59
4, // TR_ClassUnloadAssumption = 60
16, // TR_J2IVirtualThunkPointer = 61
};

#endif
Expand Down

0 comments on commit 1bd7735

Please sign in to comment.