From 50c7913e7fe4edd63b30495d32467dc669c1f5d4 Mon Sep 17 00:00:00 2001 From: "Nicolas B. Pierron" Date: Tue, 16 Apr 2019 13:56:46 +0000 Subject: [PATCH] Bug 1534840 part 0 - Clarify table case generation in CodeGenerator::visitOutOfLineSwitch. r=sstangl Differential Revision: https://phabricator.services.mozilla.com/D26520 --HG-- extra : moz-landing-system : lando --- js/src/jit/CodeGenerator.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/js/src/jit/CodeGenerator.cpp b/js/src/jit/CodeGenerator.cpp index 254ec887289f..580407d5d776 100644 --- a/js/src/jit/CodeGenerator.cpp +++ b/js/src/jit/CodeGenerator.cpp @@ -12067,20 +12067,21 @@ void CodeGenerator::visitOutOfLineSwitch( MOZ_CRASH(); #else masm.haltingAlign(sizeof(void*)); + // Bind the address of the jump table and reserve the space for code + // pointers to jump in the newly generated code. masm.bind(jumpTable->start()); masm.addCodeLabel(*jumpTable->start()); + for (size_t i = 0, e = labels.length(); i < e; i++) { + jumpTable->addTableEntry(masm); + } #endif } - // Add table entries if the table is inlined. - for (size_t i = 0, e = labels.length(); i < e; i++) { - jumpTable->addTableEntry(masm); - } - + // Register all reserved pointers of the jump table to target labels. The + // entries of the jump table need to be absolute addresses and thus must be + // patched after codegen is finished. auto& codeLabels = jumpTable->codeLabels(); for (size_t i = 0, e = codeLabels.length(); i < e; i++) { - // The entries of the jump table need to be absolute addresses and thus - // must be patched after codegen is finished. auto& cl = codeLabels[i]; cl.target()->bind(labels[i].offset()); masm.addCodeLabel(cl);