From 45f4d7aed2af5e6c698a9a04a1d93005228f7b63 Mon Sep 17 00:00:00 2001 From: Irwin D'Souza Date: Mon, 13 May 2019 10:15:57 -0400 Subject: [PATCH 1/2] Add Feature Flag for TM Signed-off-by: Irwin D'Souza --- runtime/compiler/runtime/RelocationRuntime.cpp | 12 ++++++++++++ runtime/compiler/runtime/RelocationRuntime.hpp | 1 + 2 files changed, 13 insertions(+) diff --git a/runtime/compiler/runtime/RelocationRuntime.cpp b/runtime/compiler/runtime/RelocationRuntime.cpp index cf8eeed11c7..f970568a190 100644 --- a/runtime/compiler/runtime/RelocationRuntime.cpp +++ b/runtime/compiler/runtime/RelocationRuntime.cpp @@ -936,6 +936,8 @@ TR_SharedCacheRelocationRuntime::checkAOTHeaderFlags(TR_FrontEnd *fe, TR_AOTHead defaultMessage = generateError("AOT header validation failed: Concurrent Scavenge feature mismatch."); if ((featureFlags & TR_FeatureFlag_SoftwareReadBarrier) != (hdrInCache->featureFlags & TR_FeatureFlag_SoftwareReadBarrier)) defaultMessage = generateError("AOT header validation failed: Software Read Barrier feature mismatch."); + if ((featureFlags & TR_FeatureFlag_UsesTM) != (hdrInCache->featureFlags & TR_FeatureFlag_UsesTM)) + defaultMessage = generateError("AOT header validation failed: TM feature mismatch."); if ((featureFlags & TR_FeatureFlag_SanityCheckEnd) != (hdrInCache->featureFlags & TR_FeatureFlag_SanityCheckEnd)) defaultMessage = generateError("AOT header validation failed: Trailing sanity bit mismatch."); @@ -1283,6 +1285,16 @@ TR_SharedCacheRelocationRuntime::generateFeatureFlags(TR_FrontEnd *fe) if (fej9->isAsyncCompilation()) featureFlags |= TR_FeatureFlag_AsyncCompilation; + + if (!TR::Options::getCmdLineOptions()->getOption(TR_DisableTM) && + !TR::Options::getAOTCmdLineOptions()->getOption(TR_DisableTM)) + { + if (TR::Compiler->target.cpu.supportsTransactionalMemoryInstructions()) + { + featureFlags |= TR_FeatureFlag_UsesTM; + } + } + return featureFlags; } diff --git a/runtime/compiler/runtime/RelocationRuntime.hpp b/runtime/compiler/runtime/RelocationRuntime.hpp index 11f126a62d6..bae82c7cf65 100644 --- a/runtime/compiler/runtime/RelocationRuntime.hpp +++ b/runtime/compiler/runtime/RelocationRuntime.hpp @@ -80,6 +80,7 @@ typedef enum TR_AOTFeatureFlags TR_FeatureFlag_AsyncCompilation = 0x00000400, //async compilation - switch to interpreter code NOT generated TR_FeatureFlag_ConcurrentScavenge = 0x00000800, TR_FeatureFlag_SoftwareReadBarrier = 0x00001000, + TR_FeatureFlag_UsesTM = 0x00002000, TR_FeatureFlag_SanityCheckEnd = 0x80000000 } TR_AOTFeatureFlags; From 4b442e6db0855938e7191d31d9decdeaa5a38a74 Mon Sep 17 00:00:00 2001 From: Irwin D'Souza Date: Mon, 13 May 2019 10:27:27 -0400 Subject: [PATCH 2/2] Check whether TM is disabled on a per-method basis It is possible to disable TM for just a particular method. This commit ensures that under AOT, if TM was disabled for a paticular method in the compile run, then it should also be disabled in the load run. Signed-off-by: Irwin D'Souza --- runtime/compiler/control/CompilationThread.cpp | 1 + runtime/compiler/control/rossa.cpp | 1 + runtime/compiler/control/rossa.h | 1 + runtime/compiler/runtime/J9Runtime.hpp | 1 + runtime/compiler/runtime/MetaData.cpp | 5 +++++ runtime/compiler/runtime/RelocationRuntime.cpp | 6 ++++++ 6 files changed, 15 insertions(+) diff --git a/runtime/compiler/control/CompilationThread.cpp b/runtime/compiler/control/CompilationThread.cpp index 23ece5717ae..647e32d7c58 100644 --- a/runtime/compiler/control/CompilationThread.cpp +++ b/runtime/compiler/control/CompilationThread.cpp @@ -1803,6 +1803,7 @@ bool TR::CompilationInfo::shouldRetryCompilation(TR_MethodToBeCompiled *entry, T case compilationAotValidateStringCompressionFailure: case compilationSymbolValidationManagerFailure: case compilationAOTNoSupportForAOTFailure: + case compilationAOTValidateTMFailure: // switch to JIT for these cases (we don't want to relocate again) entry->_doNotUseAotCodeFromSharedCache = true; tryCompilingAgain = true; diff --git a/runtime/compiler/control/rossa.cpp b/runtime/compiler/control/rossa.cpp index 7d7794a7269..b23abbe1d41 100644 --- a/runtime/compiler/control/rossa.cpp +++ b/runtime/compiler/control/rossa.cpp @@ -197,6 +197,7 @@ char *compilationErrorNames[]={ "compilationEnforceProfiling", //49 "compilationSymbolValidationManagerFailure", //50 "compilationAOTNoSupportForAOTFailure", //51 + "compilationAOTValidateTMFailure", //52 "compilationMaxError" }; diff --git a/runtime/compiler/control/rossa.h b/runtime/compiler/control/rossa.h index de3a78cb428..4a1d297c080 100644 --- a/runtime/compiler/control/rossa.h +++ b/runtime/compiler/control/rossa.h @@ -75,6 +75,7 @@ typedef enum { compilationEnforceProfiling = 49, compilationSymbolValidationManagerFailure = 50, compilationAOTNoSupportForAOTFailure = 51, + compilationAOTValidateTMFailure = 52, /* please insert new codes before compilationMaxError which is used in jar2jxe to test the error codes range */ /* If new codes are added then add the corresponding names in compilationErrorNames table in rossa.cpp */ compilationMaxError /* must be the last one */ diff --git a/runtime/compiler/runtime/J9Runtime.hpp b/runtime/compiler/runtime/J9Runtime.hpp index 4aef4a6d94d..c997e5cc7f0 100644 --- a/runtime/compiler/runtime/J9Runtime.hpp +++ b/runtime/compiler/runtime/J9Runtime.hpp @@ -170,6 +170,7 @@ typedef struct TR_AOTMethodHeader { #define TR_AOTMethodHeader_UsesEnableStringCompressionFolding 0x00000008 #define TR_AOTMethodHeader_StringCompressionEnabled 0x00000010 #define TR_AOTMethodHeader_UsesSymbolValidationManager 0x00000020 +#define TR_AOTMethodHeader_TMDisabled 0x00000040 diff --git a/runtime/compiler/runtime/MetaData.cpp b/runtime/compiler/runtime/MetaData.cpp index 066162b68f1..0c8405860bd 100644 --- a/runtime/compiler/runtime/MetaData.cpp +++ b/runtime/compiler/runtime/MetaData.cpp @@ -1523,6 +1523,11 @@ createMethodMetaData( aotMethodHeaderEntry->flags |= TR_AOTMethodHeader_IsNotCapableOfMethodEnterTracing; } + if (comp->getOption(TR_DisableTM)) + { + aotMethodHeaderEntry->flags |= TR_AOTMethodHeader_TMDisabled; + } + // totalAllocated space is in comp object TR_ASSERT(comp->getTotalNeededDataCacheSpace() == aotMethodHeaderEntry->compileMethodDataSize, "Size missmatach"); } diff --git a/runtime/compiler/runtime/RelocationRuntime.cpp b/runtime/compiler/runtime/RelocationRuntime.cpp index f970568a190..5b4eed9ce80 100644 --- a/runtime/compiler/runtime/RelocationRuntime.cpp +++ b/runtime/compiler/runtime/RelocationRuntime.cpp @@ -240,6 +240,12 @@ TR_RelocationRuntime::prepareRelocateAOTCodeAndData(J9VMThread* vmThread, comp->setOption(TR_UseSymbolValidationManager); } + if ((_aotMethodHeaderEntry->flags & TR_AOTMethodHeader_TMDisabled) && !comp->getOption(TR_DisableTM)) + { + setReturnCode(compilationAOTValidateTMFailure); + return NULL; + } + _exceptionTableCacheEntry = (J9JITDataCacheHeader *)((uint8_t *)cacheEntry + _aotMethodHeaderEntry->offsetToExceptionTable); if (_exceptionTableCacheEntry->type == J9_JIT_DCE_EXCEPTION_INFO)