Skip to content

Commit

Permalink
Merge pull request #16002 from 0xdaryl/xloom.final
Browse files Browse the repository at this point in the history
x64 JIT support for virtual threads (Loom)
  • Loading branch information
joransiu committed Sep 29, 2022
2 parents 76202be + 38d4516 commit 5a8ae64
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 250 deletions.
6 changes: 0 additions & 6 deletions runtime/compiler/control/J9Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,12 +1342,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
/**
* 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

0 comments on commit 5a8ae64

Please sign in to comment.