source: webkit/trunk/JavaScriptCore/runtime/JSGlobalData.h@ 52040

Last change on this file since 52040 was 52040, checked in by [email protected], 15 years ago

JavaScriptCore: Changed GC from mark-sweep to mark-allocate.

Reviewed by Sam Weinig.

Added WeakGCMap to keep WebCore blissfully ignorant about objects that
have become garbage but haven't run their destructors yet.

1% SunSpider speedup.
7.6% v8 speedup (37% splay speedup).
17% speedup on bench-alloc-nonretained.js.
18% speedup on bench-alloc-retained.js.

  • API/JSBase.cpp:

(JSGarbageCollect):

files.

  • debugger/Debugger.cpp:

(JSC::Debugger::recompileAllJSFunctions): Updated to use the Collector
iterator abstraction.

  • jsc.cpp:

(functionGC): Updated for rename.

  • runtime/Collector.cpp: Slightly reduced the number of allocations per

collection, so that small workloads only allocate on collector block,
rather than two.

(JSC::Heap::Heap): Updated to use the new allocateBlock function.

(JSC::Heap::destroy): Updated to use the new freeBlocks function.

(JSC::Heap::allocateBlock): New function to initialize a block when
allocating it.

(JSC::Heap::freeBlock): Consolidated the responsibility for running
destructors into this function.

(JSC::Heap::freeBlocks): Updated to use freeBlock.

(JSC::Heap::recordExtraCost): Sweep the heap in this reporting function,
so that allocation, which is more common, doesn't have to check extraCost.

(JSC::Heap::heapAllocate): Run destructors right before recycling a
garbage cell. This has better cache utilization than a separate sweep phase.

(JSC::Heap::resizeBlocks):
(JSC::Heap::growBlocks):
(JSC::Heap::shrinkBlocks): New set of functions for managing the size of
the heap, now that the heap doesn't maintain any information about its
size.

(JSC::isPointerAligned):
(JSC::isHalfCellAligned):
(JSC::isPossibleCell):
(JSC::isCellAligned):
(JSC::Heap::markConservatively): Cleaned up this code a bit.

(JSC::Heap::clearMarkBits):
(JSC::Heap::markedCells): Some helper functions for examining the the mark
bitmap.

(JSC::Heap::sweep): Simplified this function by using a DeadObjectIterator.

(JSC::Heap::markRoots): Reordered some operations for clarity.

(JSC::Heap::objectCount):
(JSC::Heap::addToStatistics):
(JSC::Heap::statistics): Rewrote these functions to calculate an object
count on demand, since the heap doesn't maintain this information by
itself.

(JSC::Heap::reset): New function for resetting the heap once we've
exhausted heap space.

(JSC::Heap::collectAllGarbage): This function matches the old collect()
behavior, but it's now an uncommon function used only by API.

  • runtime/Collector.h:

(JSC::CollectorBitmap::count):
(JSC::CollectorBitmap::isEmpty): Added some helper functions for managing
the collector mark bitmap.

(JSC::Heap::reportExtraMemoryCost): Changed reporting from cell equivalents
to bytes, so it's easier to understand.

  • runtime/CollectorHeapIterator.h:

(JSC::CollectorHeapIterator::CollectorHeapIterator):
(JSC::CollectorHeapIterator::operator!=):
(JSC::CollectorHeapIterator::operator*):
(JSC::CollectorHeapIterator::advance):
(JSC::::LiveObjectIterator):
(JSC::::operator):
(JSC::::DeadObjectIterator):
(JSC::::ObjectIterator): New iterators for encapsulating details about
heap layout, and what's live and dead on the heap.

  • runtime/JSArray.cpp:

(JSC::JSArray::putSlowCase):
(JSC::JSArray::increaseVectorLength): Delay reporting extra cost until
we're fully constructed, so the heap mark phase won't visit us in an
invalid state.

  • runtime/JSCell.h:

(JSC::JSCell::):
(JSC::JSCell::createDummyStructure):
(JSC::JSCell::JSCell):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):

  • runtime/JSGlobalData.h: Added a dummy cell to simplify allocation logic.
  • runtime/JSString.h:

(JSC::jsSubstring): Don't report extra cost for substrings, since they
share a buffer that's already reported extra cost.

  • runtime/Tracing.d:
  • runtime/Tracing.h: Changed these dtrace hooks not to report object

counts, since they're no longer cheap to compute.

  • runtime/UString.h: Updated for renames.
  • runtime/WeakGCMap.h: Added.

(JSC::WeakGCMap::isEmpty):
(JSC::WeakGCMap::uncheckedGet):
(JSC::WeakGCMap::uncheckedBegin):
(JSC::WeakGCMap::uncheckedEnd):
(JSC::::get):
(JSC::::take):
(JSC::::set):
(JSC::::uncheckedRemove): Mentioned above.

  • wtf/StdLibExtras.h:

(WTF::bitCount): Added a bit population count function, so the heap can
count live objects to fulfill statistics questions.

JavaScriptGlue: Changed GC from mark-sweep to mark-allocate.

Reviewed by Sam Weinig.

  • JavaScriptGlue.cpp:

(JSCollect): Updated for rename. Fixed a bug where JSGlue would not check
to avoid nested GC calls.

WebCore: Changed GC from mark-sweep to mark-allocate.

Reviewed by Sam Weinig.

  • ForwardingHeaders/runtime/WeakGCMap.h: Added.
  • bindings/js/GCController.cpp:

(WebCore::collect):
(WebCore::GCController::gcTimerFired):
(WebCore::GCController::garbageCollectNow): Updated for rename.

  • bindings/js/JSDOMBinding.cpp:

(WebCore::removeWrappers):
(WebCore::hasCachedDOMObjectWrapperUnchecked):
(WebCore::hasCachedDOMObjectWrapper):
(WebCore::hasCachedDOMNodeWrapperUnchecked):
(WebCore::forgetDOMObject):
(WebCore::forgetDOMNode):
(WebCore::isObservableThroughDOM):
(WebCore::markDOMNodesForDocument):
(WebCore::markDOMObjectWrapper):
(WebCore::markDOMNodeWrapper):

  • bindings/js/JSDOMBinding.h: Changed DOM wrapper maps to be WeakGCMaps.

Don't ASSERT that an item must be in the WeakGCMap when its destructor
runs, since it might have been overwritten in the map first.

  • bindings/js/JSDocumentCustom.cpp:

(WebCore::toJS): Changed Document from a DOM object wrapper to a DOM node
wrapper, to simplify some code.

  • bindings/js/JSInspectedObjectWrapper.cpp:

(WebCore::JSInspectedObjectWrapper::JSInspectedObjectWrapper):
(WebCore::JSInspectedObjectWrapper::~JSInspectedObjectWrapper):

  • bindings/js/JSInspectorCallbackWrapper.cpp: Use a WeakGCMap for these

wrappers.

  • bindings/js/JSNodeCustom.cpp:

(WebCore::JSNode::markChildren): Updated for WeakGCMap and Document using
a DOM node wrapper instead of a DOM object wrapper.

  • bindings/js/JSSVGPODTypeWrapper.h:

(WebCore::JSSVGDynamicPODTypeWrapperCache::wrapperMap):
(WebCore::JSSVGDynamicPODTypeWrapperCache::lookupOrCreateWrapper):
(WebCore::JSSVGDynamicPODTypeWrapperCache::forgetWrapper):
(WebCore::::~JSSVGDynamicPODTypeWrapper): Shined a small beam of sanity
on this code. Use hashtable-based lookup in JSSVGPODTypeWrapper.h instead
of linear lookup through iteration, since that's what hashtables were
invented for. Make JSSVGPODTypeWrapper.h responsible for reomving itself
from the table, instead of its JS wrapper, to decouple these objects from
GC, and because these objects are refCounted, not solely owned by their
JS wrappers.

  • bindings/scripts/CodeGeneratorJS.pm:
  • dom/Document.h: Adopted changes above.
  • Property svn:eol-style set to native
File size: 6.1 KB
Line 
1/*
2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef JSGlobalData_h
30#define JSGlobalData_h
31
32#include "Collector.h"
33#include "DateInstanceCache.h"
34#include "ExecutableAllocator.h"
35#include "JITStubs.h"
36#include "JSValue.h"
37#include "MarkStack.h"
38#include "NumericStrings.h"
39#include "SmallStrings.h"
40#include "TimeoutChecker.h"
41#include "WeakRandom.h"
42#include <wtf/Forward.h>
43#include <wtf/HashMap.h>
44#include <wtf/RefCounted.h>
45
46struct OpaqueJSClass;
47struct OpaqueJSClassContextData;
48
49namespace JSC {
50
51 class CodeBlock;
52 class CommonIdentifiers;
53 class IdentifierTable;
54 class Interpreter;
55 class JSGlobalObject;
56 class JSObject;
57 class Lexer;
58 class Parser;
59 class Stringifier;
60 class Structure;
61 class UString;
62
63 struct HashTable;
64 struct Instruction;
65 struct VPtrSet;
66
67 struct DSTOffsetCache {
68 DSTOffsetCache()
69 {
70 reset();
71 }
72
73 void reset()
74 {
75 offset = 0.0;
76 start = 0.0;
77 end = -1.0;
78 increment = 0.0;
79 }
80
81 double offset;
82 double start;
83 double end;
84 double increment;
85 };
86
87 class JSGlobalData : public RefCounted<JSGlobalData> {
88 public:
89 struct ClientData {
90 virtual ~ClientData() = 0;
91 };
92
93 static bool sharedInstanceExists();
94 static JSGlobalData& sharedInstance();
95
96 static PassRefPtr<JSGlobalData> create(bool isShared = false);
97 static PassRefPtr<JSGlobalData> createLeaked();
98 ~JSGlobalData();
99
100#if ENABLE(JSC_MULTIPLE_THREADS)
101 // Will start tracking threads that use the heap, which is resource-heavy.
102 void makeUsableFromMultipleThreads() { heap.makeUsableFromMultipleThreads(); }
103#endif
104
105 bool isSharedInstance;
106 ClientData* clientData;
107
108 const HashTable* arrayTable;
109 const HashTable* dateTable;
110 const HashTable* jsonTable;
111 const HashTable* mathTable;
112 const HashTable* numberTable;
113 const HashTable* regExpTable;
114 const HashTable* regExpConstructorTable;
115 const HashTable* stringTable;
116
117 RefPtr<Structure> activationStructure;
118 RefPtr<Structure> interruptedExecutionErrorStructure;
119 RefPtr<Structure> staticScopeStructure;
120 RefPtr<Structure> stringStructure;
121 RefPtr<Structure> notAnObjectErrorStubStructure;
122 RefPtr<Structure> notAnObjectStructure;
123 RefPtr<Structure> propertyNameIteratorStructure;
124 RefPtr<Structure> getterSetterStructure;
125 RefPtr<Structure> apiWrapperStructure;
126 RefPtr<Structure> dummyMarkableCellStructure;
127
128#if USE(JSVALUE32)
129 RefPtr<Structure> numberStructure;
130#endif
131
132 void* jsArrayVPtr;
133 void* jsByteArrayVPtr;
134 void* jsStringVPtr;
135 void* jsFunctionVPtr;
136
137 IdentifierTable* identifierTable;
138 CommonIdentifiers* propertyNames;
139 const MarkedArgumentBuffer* emptyList; // Lists are supposed to be allocated on the stack to have their elements properly marked, which is not the case here - but this list has nothing to mark.
140 SmallStrings smallStrings;
141 NumericStrings numericStrings;
142 DateInstanceCache dateInstanceCache;
143
144#if ENABLE(ASSEMBLER)
145 ExecutableAllocator executableAllocator;
146#endif
147
148 Lexer* lexer;
149 Parser* parser;
150 Interpreter* interpreter;
151#if ENABLE(JIT)
152 JITThunks jitStubs;
153#endif
154 TimeoutChecker timeoutChecker;
155 Heap heap;
156
157 JSValue exception;
158#if ENABLE(JIT)
159 ReturnAddressPtr exceptionLocation;
160#endif
161
162 const Vector<Instruction>& numericCompareFunction(ExecState*);
163 Vector<Instruction> lazyNumericCompareFunction;
164 bool initializingLazyNumericCompareFunction;
165
166 HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData;
167
168 JSGlobalObject* head;
169 JSGlobalObject* dynamicGlobalObject;
170
171 HashSet<JSObject*> arrayVisitedElements;
172
173 CodeBlock* functionCodeBlockBeingReparsed;
174 Stringifier* firstStringifierToMark;
175
176 MarkStack markStack;
177
178 double cachedUTCOffset;
179 DSTOffsetCache dstOffsetCache;
180
181 UString cachedDateString;
182 double cachedDateStringValue;
183
184 WeakRandom weakRandom;
185
186#ifndef NDEBUG
187 bool mainThreadOnly;
188#endif
189
190 void resetDateCache();
191
192 void startSampling();
193 void stopSampling();
194 void dumpSampleData(ExecState* exec);
195 private:
196 JSGlobalData(bool isShared, const VPtrSet&);
197 static JSGlobalData*& sharedInstanceInternal();
198 void createNativeThunk();
199 };
200
201} // namespace JSC
202
203#endif // JSGlobalData_h
Note: See TracBrowser for help on using the repository browser.