X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/4e4e5a6f2694187498445a6ac6f1634ce8141119..14957cd040308e3eeec43d26bae5d76da13fcd85:/runtime/JSVariableObject.h?ds=sidebyside diff --git a/runtime/JSVariableObject.h b/runtime/JSVariableObject.h index f2efcdf..89bb6b0 100644 --- a/runtime/JSVariableObject.h +++ b/runtime/JSVariableObject.h @@ -40,11 +40,11 @@ namespace JSC { class Register; - class JSVariableObject : public JSObject { + class JSVariableObject : public JSNonFinalObject { friend class JIT; public: - SymbolTable& symbolTable() const { return *d->symbolTable; } + SymbolTable& symbolTable() const { return *m_symbolTable; } virtual void putWithAttributes(ExecState*, const Identifier&, JSValue, unsigned attributes) = 0; @@ -54,58 +54,46 @@ namespace JSC { virtual bool isVariableObject() const; virtual bool isDynamicScope(bool& requiresDynamicChecks) const = 0; - Register& registerAt(int index) const { return d->registers[index]; } + WriteBarrier& registerAt(int index) const { return m_registers[index]; } - static PassRefPtr createStructure(JSValue prototype) + WriteBarrier* const * addressOfRegisters() const { return &m_registers; } + + static Structure* createStructure(JSGlobalData& globalData, JSValue prototype) { - return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount); + return Structure::create(globalData, prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount, &s_info); } protected: static const unsigned StructureFlags = OverridesGetPropertyNames | JSObject::StructureFlags; - // Subclasses of JSVariableObject can subclass this struct to add data - // without increasing their own size (since there's a hard limit on the - // size of a JSCell). - struct JSVariableObjectData { - JSVariableObjectData(SymbolTable* symbolTable, Register* registers) - : symbolTable(symbolTable) - , registers(registers) - { - ASSERT(symbolTable); - } - - SymbolTable* symbolTable; // Maps name -> offset from "r" in register file. - Register* registers; // "r" in the register file. - OwnArrayPtr registerArray; // Independent copy of registers, used when a variable object copies its registers out of the register file. - - private: - JSVariableObjectData(const JSVariableObjectData&); - JSVariableObjectData& operator=(const JSVariableObjectData&); - }; - - JSVariableObject(NonNullPassRefPtr structure, JSVariableObjectData* data) - : JSObject(structure) - , d(data) // Subclass owns this pointer. + + JSVariableObject(JSGlobalData& globalData, Structure* structure, SymbolTable* symbolTable, Register* registers) + : JSNonFinalObject(globalData, structure) + , m_symbolTable(symbolTable) + , m_registers(reinterpret_cast*>(registers)) { + ASSERT(m_symbolTable); + COMPILE_ASSERT(sizeof(WriteBarrier) == sizeof(Register), Register_should_be_same_size_as_WriteBarrier); } - Register* copyRegisterArray(Register* src, size_t count); - void setRegisters(Register* r, Register* registerArray); + PassOwnArrayPtr > copyRegisterArray(JSGlobalData&, WriteBarrier* src, size_t count, size_t callframeStarts); + void setRegisters(WriteBarrier* registers, PassOwnArrayPtr > registerArray); bool symbolTableGet(const Identifier&, PropertySlot&); bool symbolTableGet(const Identifier&, PropertyDescriptor&); bool symbolTableGet(const Identifier&, PropertySlot&, bool& slotIsWriteable); - bool symbolTablePut(const Identifier&, JSValue); - bool symbolTablePutWithAttributes(const Identifier&, JSValue, unsigned attributes); + bool symbolTablePut(JSGlobalData&, const Identifier&, JSValue); + bool symbolTablePutWithAttributes(JSGlobalData&, const Identifier&, JSValue, unsigned attributes); - JSVariableObjectData* d; + SymbolTable* m_symbolTable; // Maps name -> offset from "r" in register file. + WriteBarrier* m_registers; // "r" in the register file. + OwnArrayPtr > m_registerArray; // Independent copy of registers, used when a variable object copies its registers out of the register file. }; inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot) { - SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep()); + SymbolTableEntry entry = symbolTable().inlineGet(propertyName.impl()); if (!entry.isNull()) { - slot.setRegisterSlot(®isterAt(entry.getIndex())); + slot.setValue(registerAt(entry.getIndex()).get()); return true; } return false; @@ -113,55 +101,58 @@ namespace JSC { inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot, bool& slotIsWriteable) { - SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep()); + SymbolTableEntry entry = symbolTable().inlineGet(propertyName.impl()); if (!entry.isNull()) { - slot.setRegisterSlot(®isterAt(entry.getIndex())); + slot.setValue(registerAt(entry.getIndex()).get()); slotIsWriteable = !entry.isReadOnly(); return true; } return false; } - inline bool JSVariableObject::symbolTablePut(const Identifier& propertyName, JSValue value) + inline bool JSVariableObject::symbolTablePut(JSGlobalData& globalData, const Identifier& propertyName, JSValue value) { ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); - SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep()); + SymbolTableEntry entry = symbolTable().inlineGet(propertyName.impl()); if (entry.isNull()) return false; if (entry.isReadOnly()) return true; - registerAt(entry.getIndex()) = value; + registerAt(entry.getIndex()).set(globalData, this, value); return true; } - inline bool JSVariableObject::symbolTablePutWithAttributes(const Identifier& propertyName, JSValue value, unsigned attributes) + inline bool JSVariableObject::symbolTablePutWithAttributes(JSGlobalData& globalData, const Identifier& propertyName, JSValue value, unsigned attributes) { ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); - SymbolTable::iterator iter = symbolTable().find(propertyName.ustring().rep()); + SymbolTable::iterator iter = symbolTable().find(propertyName.impl()); if (iter == symbolTable().end()) return false; SymbolTableEntry& entry = iter->second; ASSERT(!entry.isNull()); entry.setAttributes(attributes); - registerAt(entry.getIndex()) = value; + registerAt(entry.getIndex()).set(globalData, this, value); return true; } - inline Register* JSVariableObject::copyRegisterArray(Register* src, size_t count) + inline PassOwnArrayPtr > JSVariableObject::copyRegisterArray(JSGlobalData& globalData, WriteBarrier* src, size_t count, size_t callframeStarts) { - Register* registerArray = new Register[count]; - memcpy(registerArray, src, count * sizeof(Register)); + OwnArrayPtr > registerArray = adoptArrayPtr(new WriteBarrier[count]); + for (size_t i = 0; i < callframeStarts; i++) + registerArray[i].set(globalData, this, src[i].get()); + for (size_t i = callframeStarts + RegisterFile::CallFrameHeaderSize; i < count; i++) + registerArray[i].set(globalData, this, src[i].get()); - return registerArray; + return registerArray.release(); } - inline void JSVariableObject::setRegisters(Register* registers, Register* registerArray) + inline void JSVariableObject::setRegisters(WriteBarrier* registers, PassOwnArrayPtr > registerArray) { - ASSERT(registerArray != d->registerArray.get()); - d->registerArray.set(registerArray); - d->registers = registers; + ASSERT(registerArray != m_registerArray); + m_registerArray = registerArray; + m_registers = registers; } } // namespace JSC