Source/JavaScriptCore/ChangeLog

 12011-04-04 Geoffrey Garen <ggaren@apple.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Fixed a weak-handle-related leak in RegisterFile
 6 https://bugs.webkit.org/show_bug.cgi?id=57793
 7
 8 * interpreter/RegisterFile.cpp: Nixed leaky GlobalObjectNotifier.
 9 * interpreter/RegisterFile.h:
 10 (JSC::RegisterFile::GlobalObjectOwner::finalize):
 11 (JSC::RegisterFile::RegisterFile): Replaced GlobalObjectNotifier with
 12 a per-RegisterFile weak handle owner, which does not leak.
 13
 14 * runtime/WeakGCPtr.h:
 15 (JSC::WeakGCPtr::set): Allow set() to take a context argument, since
 16 RegisterFile now needs this. (Seems like it was an accidental omission
 17 all along.)
 18
1192011-04-04 Geoffrey Garen <ggaren@apple.com>
220
321 Reviewed by Oliver Hunt.
82875

Source/JavaScriptCore/interpreter/RegisterFile.cpp

@@void RegisterFile::releaseExcessCapacity
7272
7373void RegisterFile::setGlobalObject(JSGlobalObject* globalObject)
7474{
75  m_globalObject.set(globalObject->globalData(), globalObject, RegisterFile::globalObjectCollectedNotifier());
76 }
77 
78 class GlobalObjectNotifier : public WeakHandleOwner {
79 public:
80  void finalize(Handle<Unknown> value, void*)
81  {
82  JSGlobalObject* globalObject = asGlobalObject(value.get());
83  globalObject->globalData().interpreter->registerFile().setNumGlobals(0);
84  }
85 };
86 
87 WeakHandleOwner* RegisterFile::globalObjectCollectedNotifier()
88 {
89  // This will leak alas, but we only create one of them, and it doesn't
90  // take up any significant amount of space.
91  static GlobalObjectNotifier* notifier = new GlobalObjectNotifier;
92  return notifier;
 75 m_globalObject.set(globalObject->globalData(), globalObject, &m_globalObjectOwner, this);
9376}
9477
9578JSGlobalObject* RegisterFile::globalObject()
82871

Source/JavaScriptCore/interpreter/RegisterFile.h

@@namespace JSC {
135135 static size_t committedByteCount();
136136 static void initializeThreading();
137137
138  static WeakHandleOwner* globalObjectCollectedNotifier();
139 
140138 Register* const * addressOfEnd() const
141139 {
142140 return &m_end;

@@namespace JSC {
155153 PageReservation m_reservation;
156154
157155 WeakGCPtr<JSGlobalObject> m_globalObject; // The global object whose vars are currently stored in the register file.
 156 class GlobalObjectOwner : public WeakHandleOwner {
 157 virtual void finalize(Handle<Unknown>, void* context)
 158 {
 159 static_cast<RegisterFile*>(context)->setNumGlobals(0);
 160 }
 161 } m_globalObjectOwner;
158162 };
159163
160164 inline RegisterFile::RegisterFile(JSGlobalData& globalData, size_t capacity, size_t maxGlobals)

@@namespace JSC {
163167 , m_start(0)
164168 , m_end(0)
165169 , m_max(0)
166  , m_globalObject(globalData, RegisterFile::globalObjectCollectedNotifier())
 170 , m_globalObject(globalData, &m_globalObjectOwner, this)
167171 {
168172 ASSERT(maxGlobals && isPageAligned(maxGlobals));
169173 ASSERT(capacity && isPageAligned(capacity));
82871

Source/JavaScriptCore/runtime/WeakGCPtr.h

@@public:
7777 HandleHeap::heapFor(m_slot)->deallocate(m_slot);
7878 }
7979
80  void set(JSGlobalData& globalData, ExternalType value, WeakHandleOwner* weakOwner)
 80 void set(JSGlobalData& globalData, ExternalType value, WeakHandleOwner* weakOwner = 0, void* context = 0)
8181 {
8282 if (!this->m_slot) {
8383 this->m_slot = globalData.allocateGlobalHandle();
84  HandleHeap::heapFor(this->m_slot)->makeWeak(this->m_slot, weakOwner);
 84 HandleHeap::heapFor(this->m_slot)->makeWeak(this->m_slot, weakOwner, context);
8585 }
8686 ASSERT(HandleHeap::heapFor(this->m_slot)->hasWeakOwner(this->m_slot, weakOwner));
8787 this->internalSet(value);
82871