Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x64 JIT support for virtual threads (Loom) #15552

Merged
merged 7 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions runtime/compiler/control/J9Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,12 +1331,6 @@ void J9::Options::preProcessMmf(J9JavaVM *vm, J9JITConfig *jitConfig)
#endif

// { RTSJ Support Begin

#if defined(J9VM_OPT_REAL_TIME_LOCKING_SUPPORT)
self()->setOption(TR_DisableMonitorOpts);
#endif


value = mmf->j9gc_modron_getConfigurationValueForKey(vm, j9gc_modron_configuration_allocationType,&value) ?value:0;
if (j9gc_modron_allocation_type_segregated == value)
self()->setRealTimeGC(true);
Expand Down
40 changes: 5 additions & 35 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,11 @@ UDATA TR_J9VMBase::thisThreadGetPublicFlagsOffset() {return offs
UDATA TR_J9VMBase::thisThreadGetJavaPCOffset() {return offsetof(J9VMThread, pc);}
UDATA TR_J9VMBase::thisThreadGetJavaSPOffset() {return offsetof(J9VMThread, sp);}

#if JAVA_SPEC_VERSION >= 19
uintptr_t TR_J9VMBase::thisThreadGetOwnedMonitorCountOffset() {return offsetof(J9VMThread, ownedMonitorCount);}
uintptr_t TR_J9VMBase::thisThreadGetCallOutCountOffset() {return offsetof(J9VMThread, callOutCount);}
#endif

UDATA TR_J9VMBase::thisThreadGetSystemSPOffset()
{
#if defined(J9VM_JIT_FREE_SYSTEM_STACK_POINTER)
Expand Down Expand Up @@ -1708,47 +1713,12 @@ TR_J9VMBase::getObjectSizeClass(uintptr_t objectSize)
return 0;
}

UDATA
TR_J9VMBase::thisThreadMonitorCacheOffset()
{
#if defined(J9VM_OPT_REAL_TIME_LOCKING_SUPPORT)
return offsetof(J9VMThread, monitorCache);
#else
TR_ASSERT(0,"no monitorCache thread slot");
return 0;
#endif
}

UDATA
TR_J9VMBase::thisThreadOSThreadOffset()
{
return offsetof(J9VMThread, osThread);
}

UDATA
TR_J9VMBase::getMonitorNextOffset()
{
#if defined(J9VM_OPT_REAL_TIME_LOCKING_SUPPORT)
return offsetof(J9ThreadAbstractMonitor, next);
#else
TR_ASSERT(0,"no next field in J9ThreadAbstractMonitor");
return 0;
#endif
}

UDATA
TR_J9VMBase::getMonitorOwnerOffset()
{
return offsetof(J9ThreadAbstractMonitor, owner);
}

UDATA
TR_J9VMBase::getMonitorEntryCountOffset()
{
return offsetof(J9ThreadAbstractMonitor, count);
}


UDATA
TR_J9VMBase::getRealtimeSizeClassesOffset()
{
Expand Down
10 changes: 4 additions & 6 deletions runtime/compiler/env/VMJ9.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,10 @@ class TR_J9VMBase : public TR_FrontEnd
virtual uintptr_t thisThreadGetJavaPCOffset();
virtual uintptr_t thisThreadGetJavaSPOffset();
virtual uintptr_t thisThreadGetJavaLiteralsOffset();

#if JAVA_SPEC_VERSION >= 19
virtual uintptr_t thisThreadGetOwnedMonitorCountOffset();
virtual uintptr_t thisThreadGetCallOutCountOffset();
#endif
// Move to CompilerEnv VM?
virtual uintptr_t thisThreadGetSystemSPOffset();

Expand Down Expand Up @@ -682,13 +685,8 @@ class TR_J9VMBase : public TR_FrontEnd
virtual uintptr_t getCellSizeForSizeClass(uintptr_t);
virtual uintptr_t getObjectSizeClass(uintptr_t);

uintptr_t thisThreadMonitorCacheOffset();
uintptr_t thisThreadOSThreadOffset();

uintptr_t getMonitorNextOffset();
uintptr_t getMonitorOwnerOffset();
uintptr_t getMonitorEntryCountOffset();

uintptr_t getRealtimeSizeClassesOffset();
uintptr_t getSmallCellSizesOffset();
uintptr_t getSizeClassesIndexOffset();
Expand Down
28 changes: 26 additions & 2 deletions runtime/compiler/x/amd64/codegen/AMD64JNILinkage.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corp. and others
* Copyright (c) 2000, 2022 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
Expand Down Expand Up @@ -1350,6 +1350,18 @@ TR::Register *J9::X86::AMD64::JNILinkage::buildDirectJNIDispatch(TR::Node *callN

if (isGPUHelper)
callNode->setSymbolReference(callSymRef); //change back to callSymRef afterwards

#if JAVA_SPEC_VERSION >= 19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On monitor entry and exit code, we only update the counter if it is >= Java19 and 64-Bit platform, should we be guarding the code with 64-Bit platform check as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This file is specific to 64-bit only (AMD64) and an additional 64-bit check would be redundant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have look at that more carefully, thanks a lot for pointing this out.
Though, I actually want to see if @gacholio's suggestion on Z PR for Loom #15752 (comment) also applies to all other codegens?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really a policy decision, not a technical one. It's quite unlikely that 32-bit will make a return, though Z is perhaps the one place where it might be requested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @gacholio for the explanation. It makes sense.

/**
* For virtual threads, bump the callOutCounter. It is safe and most efficient to
* do this unconditionally. No need to check for overflow.
*/
generateMemInstruction(
TR::InstOpCode::INC8Mem,
callNode,
generateX86MemoryReference(vmThreadReg, fej9->thisThreadGetCallOutCountOffset(), cg()),
cg());
#endif
}

// Switch from the Java stack to the C stack:
Expand Down Expand Up @@ -1398,7 +1410,7 @@ TR::Register *J9::X86::AMD64::JNILinkage::buildDirectJNIDispatch(TR::Node *callN
targetAddress = (uintptr_t)callSymbol1->getResolvedMethod()->startAddressForJNIMethod(comp());
}

TR::Instruction *callInstr = generateMethodDispatch(callNode, isJNIGCPoint, targetAddress);
TR::Instruction *callInstr = generateMethodDispatch(callNode, isJNIGCPoint, targetAddress);

if (isGPUHelper)
callNode->setSymbolReference(callSymRef); //change back to callSymRef afterwards
Expand Down Expand Up @@ -1469,6 +1481,18 @@ TR::Register *J9::X86::AMD64::JNILinkage::buildDirectJNIDispatch(TR::Node *callN

if (createJNIFrame)
{
#if JAVA_SPEC_VERSION >= 19
/**
* For virtual threads, decrement the callOutCounter. It is safe and most efficient to
* do this unconditionally. No need to check for underflow.
*/
generateMemInstruction(
TR::InstOpCode::DEC8Mem,
callNode,
generateX86MemoryReference(vmThreadReg, fej9->thisThreadGetCallOutCountOffset(), cg()),
cg());
#endif

generateRegMemInstruction(
TR::InstOpCode::ADDRegMem(),
callNode,
Expand Down
Loading