Bug 909989 - Part 1: Implement DataPtr to refer to objects in runtimeData_. (r=nbp)

This commit is contained in:
Eric Faust 2013-08-28 16:12:59 -07:00
parent 68d7d9ce8b
commit da281be7a8
2 changed files with 29 additions and 2 deletions

View File

@ -95,7 +95,7 @@ class OutOfLineUpdateCache :
bool
CodeGeneratorShared::addCache(LInstruction *lir, size_t cacheIndex)
{
IonCache *cache = reinterpret_cast<IonCache *>(&runtimeData_[cacheIndex]);
DataPtr<IonCache> 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<IonCache *>(&runtimeData_[ool->getCacheIndex()]);
DataPtr<IonCache> cache(this, ool->getCacheIndex());
// Register the location of the OOL path in the IC.
cache->setFallbackLabel(masm.labelForPatch());

View File

@ -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 <typename T>
class DataPtr
{
CodeGeneratorShared *cg_;
size_t index_;
T *lookup() {
return reinterpret_cast<T *>(&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) {