From da281be7a873600606603395a1bb6b7607fda349 Mon Sep 17 00:00:00 2001 From: Eric Faust Date: Wed, 28 Aug 2013 16:12:59 -0700 Subject: [PATCH] Bug 909989 - Part 1: Implement DataPtr to refer to objects in runtimeData_. (r=nbp) --- js/src/jit/CodeGenerator.cpp | 4 ++-- js/src/jit/shared/CodeGenerator-shared.h | 27 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/js/src/jit/CodeGenerator.cpp b/js/src/jit/CodeGenerator.cpp index 6107a92f990..c508396a4c5 100644 --- a/js/src/jit/CodeGenerator.cpp +++ b/js/src/jit/CodeGenerator.cpp @@ -95,7 +95,7 @@ class OutOfLineUpdateCache : bool CodeGeneratorShared::addCache(LInstruction *lir, size_t cacheIndex) { - IonCache *cache = reinterpret_cast(&runtimeData_[cacheIndex]); + DataPtr cache(this, cacheIndex); MInstruction *mir = lir->mirRaw()->toInstruction(); if (mir->resumePoint()) cache->setScriptedLocation(mir->block()->info().script(), @@ -119,7 +119,7 @@ CodeGeneratorShared::addCache(LInstruction *lir, size_t cacheIndex) bool CodeGenerator::visitOutOfLineCache(OutOfLineUpdateCache *ool) { - IonCache *cache = reinterpret_cast(&runtimeData_[ool->getCacheIndex()]); + DataPtr cache(this, ool->getCacheIndex()); // Register the location of the OOL path in the IC. cache->setFallbackLabel(masm.labelForPatch()); diff --git a/js/src/jit/shared/CodeGenerator-shared.h b/js/src/jit/shared/CodeGenerator-shared.h index 7dbb52ff045..a1352446473 100644 --- a/js/src/jit/shared/CodeGenerator-shared.h +++ b/js/src/jit/shared/CodeGenerator-shared.h @@ -205,6 +205,33 @@ class CodeGeneratorShared : public LInstructionVisitor void verifyOsiPointRegs(LSafepoint *safepoint); #endif + public: + + // When appending to runtimeData_, the vector might realloc, leaving pointers + // int the origianl vector stale and unusable. DataPtr acts like a pointer, + // but allows safety in the face of potentially realloc'ing vector appends. + friend class DataPtr; + template + class DataPtr + { + CodeGeneratorShared *cg_; + size_t index_; + + T *lookup() { + return reinterpret_cast(&cg_->runtimeData_[index_]); + } + public: + DataPtr(CodeGeneratorShared *cg, size_t index) + : cg_(cg), index_(index) { } + + T * operator ->() { + return lookup(); + } + T * operator *() { + return lookup(); + } + }; + protected: size_t allocateData(size_t size) {