Skip to content

Commit 25f0b72

Browse files
authored
Merge pull request #20146 from nbhuiyan/mem-segment-vh-0
Inline SegmentViewVarHandle operations in JDK21+
2 parents 0213b04 + c41c05f commit 25f0b72

13 files changed

+180
-16
lines changed

runtime/compiler/codegen/J9RecognizedMethodsEnum.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,9 @@
11651165
java_lang_invoke_VarHandleByteArrayAsX_ArrayHandle_method,
11661166
java_lang_invoke_VarHandleByteArrayAsX_ByteBufferHandle_method,
11671167

1168+
jdk_internal_foreign_layout_ValueLayouts_AbstractValueLayout_accessHandle,
1169+
java_lang_foreign_MemorySegment_method,
1170+
11681171
// Clone and Deep Copy
11691172
java_lang_J9VMInternals_is32Bit,
11701173
java_lang_J9VMInternals_isClassModifierPublic,

runtime/compiler/control/JITClientCompilationThread.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,16 @@ handleServerMessage(JITServer::ClientStream *client, TR_J9VM *fe, JITServer::Mes
12141214
client->write(response, mhIndex, mhObj);
12151215
}
12161216
break;
1217+
case MessageType::VM_getLayoutVarHandle:
1218+
{
1219+
auto recv = client->getRecvData<TR::KnownObjectTable::Index>();
1220+
TR::KnownObjectTable::Index vhIndex = fe->getLayoutVarHandle(comp, std::get<0>(recv));
1221+
uintptr_t* vhObj = NULL;
1222+
if (vhIndex != TR::KnownObjectTable::UNKNOWN)
1223+
vhObj = knot->getPointerLocation(vhIndex);
1224+
client->write(response, vhIndex, vhObj);
1225+
}
1226+
break;
12171227
#endif // J9VM_OPT_OPENJDK_METHODHANDLE
12181228
case MessageType::VM_isStable:
12191229
{

runtime/compiler/env/VMJ9.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5131,6 +5131,41 @@ TR_J9VMBase::getMemberNameFieldKnotIndexFromMethodHandleKnotIndex(TR::Compilatio
51315131
return knot->getOrCreateIndex(mnObject);
51325132
}
51335133

5134+
TR::KnownObjectTable::Index
5135+
TR_J9VMBase::getLayoutVarHandle(TR::Compilation *comp, TR::KnownObjectTable::Index layoutIndex)
5136+
{
5137+
TR::VMAccessCriticalSection getLayoutVarHandle(this);
5138+
TR::KnownObjectTable::Index result = TR::KnownObjectTable::UNKNOWN;
5139+
TR::KnownObjectTable *knot = comp->getKnownObjectTable();
5140+
if (!knot) return result;
5141+
5142+
const char * const layoutClassName =
5143+
"jdk/internal/foreign/layout/ValueLayouts$AbstractValueLayout";
5144+
const int layoutClassNameLen = (int)strlen(layoutClassName);
5145+
TR_OpaqueClassBlock *layoutClass =
5146+
getSystemClassFromClassName(layoutClassName, layoutClassNameLen);
5147+
5148+
TR_OpaqueClassBlock *layoutObjClass =
5149+
getObjectClassFromKnownObjectIndex(comp, layoutIndex);
5150+
5151+
if (layoutClass == NULL ||
5152+
layoutObjClass == NULL ||
5153+
isInstanceOf(layoutObjClass, layoutClass, true, true) != TR_yes)
5154+
{
5155+
if (comp->getOption(TR_TraceOptDetails))
5156+
traceMsg(comp, "getLayoutVarHandle: failed ValueLayouts$AbstractValueLayout type check.\n");
5157+
return result;
5158+
}
5159+
5160+
uintptr_t layoutObj = knot->getPointer(layoutIndex);
5161+
uintptr_t vhObject = getReferenceField(layoutObj,
5162+
"handle",
5163+
"Ljava/lang/invoke/VarHandle;");
5164+
if (!vhObject) return result;
5165+
result = knot->getOrCreateIndex(vhObject);
5166+
return result;
5167+
}
5168+
51345169
TR::KnownObjectTable::Index
51355170
TR_J9VMBase::getMethodHandleTableEntryIndex(TR::Compilation *comp, TR::KnownObjectTable::Index vhIndex, TR::KnownObjectTable::Index adIndex)
51365171
{

runtime/compiler/env/VMJ9.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,18 @@ class TR_J9VMBase : public TR_FrontEnd
455455
*/
456456
virtual TR::KnownObjectTable::Index getMethodHandleTableEntryIndex(TR::Compilation *comp, TR::KnownObjectTable::Index vhIndex, TR::KnownObjectTable::Index adIndex);
457457

458+
/**
459+
* @brief Get the known object index of a cached MemorySegmentView VarHandle belonging to a value Layout object.
460+
* When the Layout object is known, we can evaluate the result of
461+
* jdk/internal/foreign/layout/ValueLayouts$AbstractValueLayout.accessHandle()Ljava/lang/invoke/VarHandle;
462+
* as long as the layout object's handle field is not null.
463+
*
464+
* @param comp the compilation
465+
* @param layoutIndex the ValueLayout$AbstractValueLayout object index
466+
* @return TR::KnownObjectTable::Index the known object index of the MemorySegmentView VarHandle, TR::KnownObjectTable::UNKNOWN otherwise
467+
*/
468+
virtual TR::KnownObjectTable::Index getLayoutVarHandle(TR::Compilation *comp, TR::KnownObjectTable::Index layoutIndex);
469+
458470
virtual TR::Method * createMethod(TR_Memory *, TR_OpaqueClassBlock *, int32_t);
459471
virtual TR_ResolvedMethod * createResolvedMethod(TR_Memory *, TR_OpaqueMethodBlock *, TR_ResolvedMethod * = 0, TR_OpaqueClassBlock * = 0);
460472
virtual TR_ResolvedMethod * createResolvedMethodWithVTableSlot(TR_Memory *, uint32_t vTableSlot, TR_OpaqueMethodBlock * aMethod, TR_ResolvedMethod * owningMethod = 0, TR_OpaqueClassBlock * classForNewInstance = 0);

runtime/compiler/env/VMJ9Server.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,22 @@ TR_J9ServerVM::getMethodHandleTableEntryIndex(TR::Compilation *comp, TR::KnownOb
24162416
return mhIndex;
24172417
}
24182418

2419+
TR::KnownObjectTable::Index
2420+
TR_J9ServerVM::getLayoutVarHandle(TR::Compilation *comp, TR::KnownObjectTable::Index layoutIndex)
2421+
{
2422+
TR::KnownObjectTable *knot = comp->getKnownObjectTable();
2423+
if (!knot) return TR::KnownObjectTable::UNKNOWN;
2424+
2425+
JITServer::ServerStream *stream = _compInfoPT->getMethodBeingCompiled()->_stream;
2426+
stream->write(JITServer::MessageType::VM_getLayoutVarHandle, layoutIndex);
2427+
auto recv = stream->read<TR::KnownObjectTable::Index, uintptr_t *>();
2428+
2429+
TR::KnownObjectTable::Index vhIndex = std::get<0>(recv);
2430+
knot->updateKnownObjectTableAtServer(vhIndex, std::get<1>(recv));
2431+
return vhIndex;
2432+
2433+
}
2434+
24192435
#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */
24202436

24212437
TR::KnownObjectTable::Index

runtime/compiler/env/VMJ9Server.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class TR_J9ServerVM: public TR_J9VM
245245
virtual UDATA getVMTargetOffset() override;
246246
virtual UDATA getVMIndexOffset() override;
247247
virtual TR::KnownObjectTable::Index getMethodHandleTableEntryIndex(TR::Compilation *comp, TR::KnownObjectTable::Index vhIndex, TR::KnownObjectTable::Index adIndex) override;
248+
virtual TR::KnownObjectTable::Index getLayoutVarHandle(TR::Compilation *comp, TR::KnownObjectTable::Index layoutIndex) override;
248249
#endif
249250
virtual TR::KnownObjectTable::Index getMemberNameFieldKnotIndexFromMethodHandleKnotIndex(TR::Compilation *comp, TR::KnownObjectTable::Index mhIndex, const char *fieldName) override;
250251
virtual bool isMethodHandleExpectedType(TR::Compilation *comp, TR::KnownObjectTable::Index mhIndex, TR::KnownObjectTable::Index expectedTypeIndex) override;

runtime/compiler/env/j9method.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3678,6 +3678,12 @@ void TR_ResolvedJ9Method::construct()
36783678
{ TR::unknownMethod}
36793679
};
36803680

3681+
static X ValueLayoutsAbstractValueLayoutMethods[] =
3682+
{
3683+
{x(TR::jdk_internal_foreign_layout_ValueLayouts_AbstractValueLayout_accessHandle, "accessHandle", "()Ljava/lang/invoke/VarHandle;")},
3684+
{TR::unknownMethod}
3685+
};
3686+
36813687
static X ILGenMacrosMethods[] =
36823688
{
36833689
{ TR::java_lang_invoke_ILGenMacros_placeholder , 11, "placeholder", (int16_t)-1, "*"},
@@ -4364,13 +4370,19 @@ void TR_ResolvedJ9Method::construct()
43644370
{ 0 }
43654371
};
43664372

4373+
static Y class60[] =
4374+
{
4375+
{ "jdk/internal/foreign/layout/ValueLayouts$AbstractValueLayout", ValueLayoutsAbstractValueLayoutMethods },
4376+
{ 0 }
4377+
};
4378+
43674379
static Y * recognizedClasses[] =
43684380
{
43694381
0, 0, 0, class13, class14, class15, class16, class17, class18, class19,
43704382
class20, class21, class22, class23, class24, class25, 0, class27, class28, class29,
43714383
class30, class31, class32, class33, class34, class35, class36, 0, class38, class39,
43724384
class40, class41, class42, class43, class44, class45, class46, class47, class48, class49,
4373-
class50, 0, 0, class53, 0, class55
4385+
class50, 0, 0, class53, 0, class55, 0, 0, 0, 0, class60
43744386
};
43754387

43764388
const int32_t minRecognizedClassLength = 10;
@@ -4762,6 +4774,10 @@ void TR_ResolvedJ9Method::construct()
47624774
setRecognizedMethodInfo(TR::java_lang_invoke_VarHandleByteArrayAsX_ByteBufferHandle_method);
47634775
}
47644776
}
4777+
else if ((classNameLen == 31) && !strncmp(className, "java/lang/foreign/MemorySegment", 31))
4778+
{
4779+
setRecognizedMethodInfo(TR::java_lang_foreign_MemorySegment_method);
4780+
}
47654781
#endif
47664782
else if ((classNameLen >= 59 + 3 && classNameLen <= 59 + 7) && !strncmp(className, "java/lang/invoke/ArrayVarHandle$ArrayVarHandleOperations$Op", 59))
47674783
{
@@ -6644,7 +6660,7 @@ TR_ResolvedJ9Method::getResolvedInterfaceMethod(TR::Compilation * comp, TR_Opaqu
66446660
if (m)
66456661
{
66466662
c = m->classOfMethod();
6647-
if (c && !fej9->isInterfaceClass(c))
6663+
if (c)
66486664
{
66496665
TR::DebugCounter::incStaticDebugCounter(comp, "resources.resolvedMethods/interface");
66506666
TR::DebugCounter::incStaticDebugCounter(comp, "resources.resolvedMethods/interface:#bytes", sizeof(TR_ResolvedJ9Method));

runtime/compiler/net/CommunicationStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class CommunicationStream
128128
// likely to lose an increment when merging/rebasing/etc.
129129
//
130130
static const uint8_t MAJOR_NUMBER = 1;
131-
static const uint16_t MINOR_NUMBER = 66; // ID: x8xfrdqf9UCc8E2OiuMO
131+
static const uint16_t MINOR_NUMBER = 67; // ID: eJ9ynEzY1XevZygVpTws
132132
static const uint8_t PATCH_NUMBER = 0;
133133
static uint32_t CONFIGURATION_FLAGS;
134134

runtime/compiler/net/MessageTypes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ const char *messageNames[] =
191191
"VM_inSnapshotMode",
192192
"VM_isInvokeCacheEntryAnArray",
193193
"VM_getMethodHandleTableEntryIndex",
194+
"VM_getLayoutVarHandle",
194195
"CompInfo_isCompiled",
195196
"CompInfo_getPCIfCompiled",
196197
"CompInfo_getInvocationCount",

runtime/compiler/net/MessageTypes.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ enum MessageType : uint16_t
200200
VM_inSnapshotMode,
201201
VM_isInvokeCacheEntryAnArray,
202202
VM_getMethodHandleTableEntryIndex,
203+
VM_getLayoutVarHandle,
203204

204205
// For static TR::CompilationInfo methods
205206
CompInfo_isCompiled,

0 commit comments

Comments
 (0)