Allocate Structures in a separate part of the Heap
https://bugs.webkit.org/show_bug.cgi?id=92420
Reviewed by Filip Pizlo.
To fix our issue with destruction/finalization of Structures before their objects, we can move Structures to a separate
part of the Heap that will be swept after all other objects. This first patch will just be separating Structures
out into their own separate MarkedAllocator. Everything else will behave identically.
* heap/Heap.h: New function to allocate Structures in the Heap.
(Heap):
(JSC):
(JSC::Heap::allocateStructure):
* heap/MarkedAllocator.cpp: Pass whether or not we're allocated Structures to the MarkedBlock.
(JSC::MarkedAllocator::allocateBlock):
* heap/MarkedAllocator.h: Add tracking for whether or not we're allocating only Structures.
(JSC::MarkedAllocator::onlyContainsStructures):
(MarkedAllocator):
(JSC::MarkedAllocator::MarkedAllocator):
(JSC::MarkedAllocator::init):
* heap/MarkedBlock.cpp: Add tracking for whether or not we're allocating only Structures. We need this to be able to
distinguish the various MarkedBlock types in MarkedSpace::allocatorFor(MarkedBlock*).
(JSC::MarkedBlock::create):
(JSC::MarkedBlock::MarkedBlock):
* heap/MarkedBlock.h:
(MarkedBlock):
(JSC::MarkedBlock::onlyContainsStructures):
(JSC):
* heap/MarkedSpace.cpp: Include the new Structure allocator in all the places that all the other allocators are used/modified.
(JSC::MarkedSpace::MarkedSpace):
(JSC::MarkedSpace::resetAllocators):
(JSC::MarkedSpace::canonicalizeCellLivenessData):
(JSC::MarkedSpace::isPagedOut):
* heap/MarkedSpace.h: Add new MarkedAllocator just for Structures.
(MarkedSpace):
(JSC::MarkedSpace::allocatorFor):
(JSC::MarkedSpace::allocateStructure):
(JSC):
(JSC::MarkedSpace::forEachBlock):
* runtime/Structure.h: Move all of the functions that call allocateCell<Structure> down below the explicit template specialization
for allocateCell<Structure>. The new inline specialization for allocateCell directly calls the allocateStructure() function in the
Heap.
(Structure):
(JSC::Structure):
(JSC):
(JSC::Structure::create):
(JSC::Structure::createStructure):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@123813 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/runtime/Structure.h b/Source/JavaScriptCore/runtime/Structure.h
index 712ea6bb..8e41781 100644
--- a/Source/JavaScriptCore/runtime/Structure.h
+++ b/Source/JavaScriptCore/runtime/Structure.h
@@ -68,14 +68,7 @@
typedef JSCell Base;
- static Structure* create(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype, const TypeInfo& typeInfo, const ClassInfo* classInfo)
- {
- ASSERT(globalData.structureStructure);
- ASSERT(classInfo);
- Structure* structure = new (NotNull, allocateCell<Structure>(globalData.heap)) Structure(globalData, globalObject, prototype, typeInfo, classInfo);
- structure->finishCreation(globalData);
- return structure;
- }
+ static Structure* create(JSGlobalData&, JSGlobalObject*, JSValue prototype, const TypeInfo&, const ClassInfo*);
protected:
void finishCreation(JSGlobalData& globalData)
@@ -330,13 +323,7 @@
return OBJECT_OFFSETOF(Structure, m_typeInfo) + TypeInfo::typeOffset();
}
- static Structure* createStructure(JSGlobalData& globalData)
- {
- ASSERT(!globalData.structureStructure);
- Structure* structure = new (NotNull, allocateCell<Structure>(globalData.heap)) Structure(globalData);
- structure->finishCreation(globalData, CreatingEarlyCell);
- return structure;
- }
+ static Structure* createStructure(JSGlobalData&);
bool transitionWatchpointSetHasBeenInvalidated() const
{
@@ -368,13 +355,7 @@
Structure(JSGlobalData&);
Structure(JSGlobalData&, const Structure*);
- static Structure* create(JSGlobalData& globalData, const Structure* structure)
- {
- ASSERT(globalData.structureStructure);
- Structure* newStructure = new (NotNull, allocateCell<Structure>(globalData.heap)) Structure(globalData, structure);
- newStructure->finishCreation(globalData);
- return newStructure;
- }
+ static Structure* create(JSGlobalData&, const Structure*);
typedef enum {
NoneDictionaryKind = 0,
@@ -461,6 +442,42 @@
unsigned m_staticFunctionReified;
};
+ template <> inline void* allocateCell<Structure>(Heap& heap)
+ {
+#if ENABLE(GC_VALIDATION)
+ ASSERT(!heap.globalData()->isInitializingObject());
+ heap.globalData()->setInitializingObjectClass(&Structure::s_info);
+#endif
+ JSCell* result = static_cast<JSCell*>(heap.allocateStructure());
+ result->clearStructure();
+ return result;
+ }
+
+ inline Structure* Structure::create(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue prototype, const TypeInfo& typeInfo, const ClassInfo* classInfo)
+ {
+ ASSERT(globalData.structureStructure);
+ ASSERT(classInfo);
+ Structure* structure = new (NotNull, allocateCell<Structure>(globalData.heap)) Structure(globalData, globalObject, prototype, typeInfo, classInfo);
+ structure->finishCreation(globalData);
+ return structure;
+ }
+
+ inline Structure* Structure::createStructure(JSGlobalData& globalData)
+ {
+ ASSERT(!globalData.structureStructure);
+ Structure* structure = new (NotNull, allocateCell<Structure>(globalData.heap)) Structure(globalData);
+ structure->finishCreation(globalData, CreatingEarlyCell);
+ return structure;
+ }
+
+ inline Structure* Structure::create(JSGlobalData& globalData, const Structure* structure)
+ {
+ ASSERT(globalData.structureStructure);
+ Structure* newStructure = new (NotNull, allocateCell<Structure>(globalData.heap)) Structure(globalData, structure);
+ newStructure->finishCreation(globalData);
+ return newStructure;
+ }
+
inline PropertyOffset Structure::get(JSGlobalData& globalData, PropertyName propertyName)
{
ASSERT(structure()->classInfo() == &s_info);