diff --git a/runtime/compiler/compile/J9SymbolReferenceTable.cpp b/runtime/compiler/compile/J9SymbolReferenceTable.cpp index 4d34b810d84..cbbe1428122 100644 --- a/runtime/compiler/compile/J9SymbolReferenceTable.cpp +++ b/runtime/compiler/compile/J9SymbolReferenceTable.cpp @@ -1356,7 +1356,14 @@ J9::SymbolReferenceTable::findOrCreateCurrentThreadSymbolRef() TR_J9VMBase *fej9 = (TR_J9VMBase *)(fe()); TR::Symbol * sym = TR::RegisterMappedSymbol::createMethodMetaDataSymbol(trHeapMemory(), "CurrentThread"); sym->setDataType(TR::Address); - sym->setImmutableField(); + if (fej9->isJ9VMThreadCurrentThreadImmutable()) + { + sym->setImmutableField(); + } + else + { + sym->setVolatile(); + } element(currentThreadSymbol) = new (trHeapMemory()) TR::SymbolReference(self(), currentThreadSymbol, sym); element(currentThreadSymbol)->setOffset(fej9->thisThreadGetCurrentThreadOffset()); } diff --git a/runtime/compiler/env/VMJ9.cpp b/runtime/compiler/env/VMJ9.cpp index 00cd757aad1..55d7b154b80 100644 --- a/runtime/compiler/env/VMJ9.cpp +++ b/runtime/compiler/env/VMJ9.cpp @@ -9376,6 +9376,16 @@ TR_J9VMBase::isSnapshotModeEnabled() #endif /* defined(J9VM_OPT_CRIU_SUPPORT) */ } +bool +TR_J9VMBase::isJ9VMThreadCurrentThreadImmutable() + { +#if JAVA_SPEC_VERSION >= 19 + return false; +#else + return true; +#endif /* JAVA_SPEC_VERSION >= 19 */ + } + // Native method bodies // #if defined(TR_HOST_X86) diff --git a/runtime/compiler/env/VMJ9.h b/runtime/compiler/env/VMJ9.h index b03ea9bc64c..60563a91ba2 100644 --- a/runtime/compiler/env/VMJ9.h +++ b/runtime/compiler/env/VMJ9.h @@ -1361,6 +1361,13 @@ class TR_J9VMBase : public TR_FrontEnd */ bool isSnapshotModeEnabled(); + /** + * \brief Answers whether or not Thread.currentThread() is immutable. + * + * \return True if Thread.currentThread() is immutable. + */ + virtual bool isJ9VMThreadCurrentThreadImmutable(); + protected: enum // _flags