From cf5e1065e06e6c1736ff996aff3cab5ca368d294 Mon Sep 17 00:00:00 2001 From: Dhruv Chopra Date: Wed, 26 Jun 2019 22:22:44 -0400 Subject: [PATCH] Initialize fieldClassReg for static unresolved reads When generating code for a watched field event, if an unresolved static field is being read, we do not intialize the fieldClassReg correctly. The fieldClassReg is used to test if a field is being watched. Failure to initialize this register correctly results in an invalid test being generated at runtime, causing a bug. This commit correctly initializes the fieldClassReg for the missing corner case. Signed-off-by: Dhruv Chopra --- runtime/compiler/x/codegen/J9TreeEvaluator.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/runtime/compiler/x/codegen/J9TreeEvaluator.cpp b/runtime/compiler/x/codegen/J9TreeEvaluator.cpp index 3df08253d89..7dead415a4d 100644 --- a/runtime/compiler/x/codegen/J9TreeEvaluator.cpp +++ b/runtime/compiler/x/codegen/J9TreeEvaluator.cpp @@ -12760,11 +12760,15 @@ J9::X86::TreeEvaluator::generateTestAndReportFieldWatchInstructions(TR::CodeGene } else { - fieldClassReg = cg->allocateRegister(); if (isWrite) { + fieldClassReg = cg->allocateRegister(); generateRegMemInstruction(LRegMem(), node, fieldClassReg, generateX86MemoryReference(sideEffectRegister, fej9->getOffsetOfClassFromJavaLangClassField(), cg), cg); } + else + { + fieldClassReg = sideEffectRegister; + } classFlagsMemRef = generateX86MemoryReference(fieldClassReg, fej9->getOffsetOfClassFlags(), cg); } } @@ -12787,7 +12791,7 @@ J9::X86::TreeEvaluator::generateTestAndReportFieldWatchInstructions(TR::CodeGene deps->stopAddingConditions(); generateLabelInstruction(LABEL, node, endLabel, deps, cg); - if (isInstanceField || (!isResolved) || isAOTCompile) + if (isInstanceField || (!isResolved && isWrite) || isAOTCompile) { cg->stopUsingRegister(fieldClassReg); }