| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "JSGlobalData.h" | 30 #include "JSGlobalData.h" |
| 31 | 31 |
| 32 #include "ArgList.h" | 32 #include "ArgList.h" |
| 33 #include "Collector.h" | 33 #include "Collector.h" |
| 34 #include "CommonIdentifiers.h" | 34 #include "CommonIdentifiers.h" |
| 35 #include "FunctionConstructor.h" | 35 #include "FunctionConstructor.h" |
| 36 #include "Interpreter.h" | 36 #include "Interpreter.h" |
| 37 #include "JSActivation.h" | 37 #include "JSActivation.h" |
| 38 #include "JSArray.h" |
| 39 #include "JSByteArray.h" |
| 38 #include "JSClassRef.h" | 40 #include "JSClassRef.h" |
| 39 #include "JSLock.h" | 41 #include "JSLock.h" |
| 40 #include "JSNotAnObject.h" | 42 #include "JSNotAnObject.h" |
| 41 #include "JSStaticScopeObject.h" | 43 #include "JSStaticScopeObject.h" |
| 42 #include "Parser.h" | 44 #include "Parser.h" |
| 43 #include "Lexer.h" | 45 #include "Lexer.h" |
| 44 #include "Lookup.h" | 46 #include "Lookup.h" |
| 45 #include "Nodes.h" | 47 #include "Nodes.h" |
| 46 | 48 |
| 47 #if ENABLE(JSC_MULTIPLE_THREADS) | 49 #if ENABLE(JSC_MULTIPLE_THREADS) |
| 48 #include <wtf/Threading.h> | 50 #include <wtf/Threading.h> |
| 49 #endif | 51 #endif |
| 50 | 52 |
| 51 #if PLATFORM(MAC) | 53 #if PLATFORM(MAC) |
| 52 #include "ProfilerServer.h" | 54 #include "ProfilerServer.h" |
| 53 #endif | 55 #endif |
| 54 | 56 |
| 55 using namespace WTF; | 57 using namespace WTF; |
| 56 | 58 |
| 57 namespace JSC { | 59 namespace JSC { |
| 58 | 60 |
| 59 extern const HashTable arrayTable; | 61 extern const HashTable arrayTable; |
| 60 extern const HashTable dateTable; | 62 extern const HashTable dateTable; |
| 61 extern const HashTable mathTable; | 63 extern const HashTable mathTable; |
| 62 extern const HashTable numberTable; | 64 extern const HashTable numberTable; |
| 63 extern const HashTable regExpTable; | 65 extern const HashTable regExpTable; |
| 64 extern const HashTable regExpConstructorTable; | 66 extern const HashTable regExpConstructorTable; |
| 65 extern const HashTable stringTable; | 67 extern const HashTable stringTable; |
| 66 | 68 |
| 67 JSGlobalData::JSGlobalData(bool isShared) | 69 struct VPtrSet { |
| 70 VPtrSet(); |
| 71 |
| 72 void* jsArrayVPtr; |
| 73 void* jsByteArrayVPtr; |
| 74 void* jsStringVPtr; |
| 75 void* jsFunctionVPtr; |
| 76 }; |
| 77 |
| 78 VPtrSet::VPtrSet() |
| 79 { |
| 80 // Bizarrely, calling fastMalloc here is faster than allocating space on the
stack. |
| 81 void* storage = fastMalloc(sizeof(CollectorBlock)); |
| 82 |
| 83 JSCell* jsArray = new (storage) JSArray(JSArray::createStructure(jsNull())); |
| 84 jsArrayVPtr = jsArray->vptr(); |
| 85 jsArray->~JSCell(); |
| 86 |
| 87 JSCell* jsByteArray = new (storage) JSByteArray(JSByteArray::VPtrStealingHac
k); |
| 88 jsByteArrayVPtr = jsByteArray->vptr(); |
| 89 jsByteArray->~JSCell(); |
| 90 |
| 91 JSCell* jsString = new (storage) JSString(JSString::VPtrStealingHack); |
| 92 jsStringVPtr = jsString->vptr(); |
| 93 jsString->~JSCell(); |
| 94 |
| 95 JSCell* jsFunction = new (storage) JSFunction(JSFunction::createStructure(js
Null())); |
| 96 jsFunctionVPtr = jsFunction->vptr(); |
| 97 jsFunction->~JSCell(); |
| 98 |
| 99 fastFree(storage); |
| 100 } |
| 101 |
| 102 JSGlobalData::JSGlobalData(bool isShared, const VPtrSet& vptrSet) |
| 68 : isSharedInstance(isShared) | 103 : isSharedInstance(isShared) |
| 69 , clientData(0) | 104 , clientData(0) |
| 70 , interpreter(new Interpreter) | |
| 71 , exception(noValue()) | |
| 72 , initializingLazyNumericCompareFunction(false) | |
| 73 , arrayTable(new HashTable(JSC::arrayTable)) | 105 , arrayTable(new HashTable(JSC::arrayTable)) |
| 74 , dateTable(new HashTable(JSC::dateTable)) | 106 , dateTable(new HashTable(JSC::dateTable)) |
| 75 , mathTable(new HashTable(JSC::mathTable)) | 107 , mathTable(new HashTable(JSC::mathTable)) |
| 76 , numberTable(new HashTable(JSC::numberTable)) | 108 , numberTable(new HashTable(JSC::numberTable)) |
| 77 , regExpTable(new HashTable(JSC::regExpTable)) | 109 , regExpTable(new HashTable(JSC::regExpTable)) |
| 78 , regExpConstructorTable(new HashTable(JSC::regExpConstructorTable)) | 110 , regExpConstructorTable(new HashTable(JSC::regExpConstructorTable)) |
| 79 , stringTable(new HashTable(JSC::stringTable)) | 111 , stringTable(new HashTable(JSC::stringTable)) |
| 80 , activationStructure(JSActivation::createStructure(jsNull())) | 112 , activationStructure(JSActivation::createStructure(jsNull())) |
| 81 , interruptedExecutionErrorStructure(JSObject::createStructure(jsNull())) | 113 , interruptedExecutionErrorStructure(JSObject::createStructure(jsNull())) |
| 82 , staticScopeStructure(JSStaticScopeObject::createStructure(jsNull())) | 114 , staticScopeStructure(JSStaticScopeObject::createStructure(jsNull())) |
| 83 , stringStructure(JSString::createStructure(jsNull())) | 115 , stringStructure(JSString::createStructure(jsNull())) |
| 84 , notAnObjectErrorStubStructure(JSNotAnObjectErrorStub::createStructure(jsNu
ll())) | 116 , notAnObjectErrorStubStructure(JSNotAnObjectErrorStub::createStructure(jsNu
ll())) |
| 85 , notAnObjectStructure(JSNotAnObject::createStructure(jsNull())) | 117 , notAnObjectStructure(JSNotAnObject::createStructure(jsNull())) |
| 86 #if !USE(ALTERNATE_JSIMMEDIATE) | 118 #if !USE(ALTERNATE_JSIMMEDIATE) |
| 87 , numberStructure(JSNumberCell::createStructure(jsNull())) | 119 , numberStructure(JSNumberCell::createStructure(jsNull())) |
| 88 #endif | 120 #endif |
| 121 , jsArrayVPtr(vptrSet.jsArrayVPtr) |
| 122 , jsByteArrayVPtr(vptrSet.jsByteArrayVPtr) |
| 123 , jsStringVPtr(vptrSet.jsStringVPtr) |
| 124 , jsFunctionVPtr(vptrSet.jsFunctionVPtr) |
| 89 , identifierTable(createIdentifierTable()) | 125 , identifierTable(createIdentifierTable()) |
| 90 , propertyNames(new CommonIdentifiers(this)) | 126 , propertyNames(new CommonIdentifiers(this)) |
| 91 , emptyList(new ArgList) | 127 , emptyList(new ArgList) |
| 92 , lexer(new Lexer(this)) | 128 , lexer(new Lexer(this)) |
| 93 , parser(new Parser) | 129 , parser(new Parser) |
| 130 , interpreter(new Interpreter) |
| 131 #if ENABLE(JIT) |
| 132 , jitStubs(this) |
| 133 #endif |
| 134 , heap(this) |
| 135 , exception(noValue()) |
| 136 , initializingLazyNumericCompareFunction(false) |
| 94 , newParserObjects(0) | 137 , newParserObjects(0) |
| 95 , parserObjectExtraRefCounts(0) | 138 , parserObjectExtraRefCounts(0) |
| 96 , head(0) | 139 , head(0) |
| 97 , dynamicGlobalObject(0) | 140 , dynamicGlobalObject(0) |
| 98 , scopeNodeBeingReparsed(0) | 141 , scopeNodeBeingReparsed(0) |
| 99 , heap(this) | |
| 100 { | 142 { |
| 101 #if PLATFORM(MAC) | 143 #if PLATFORM(MAC) |
| 102 startProfilerServerIfNeeded(); | 144 startProfilerServerIfNeeded(); |
| 103 #endif | 145 #endif |
| 104 interpreter->initialize(this); | |
| 105 } | 146 } |
| 106 | 147 |
| 107 JSGlobalData::~JSGlobalData() | 148 JSGlobalData::~JSGlobalData() |
| 108 { | 149 { |
| 109 // By the time this is destroyed, heap.destroy() must already have been call
ed. | 150 // By the time this is destroyed, heap.destroy() must already have been call
ed. |
| 110 | 151 |
| 111 delete interpreter; | 152 delete interpreter; |
| 112 #ifndef NDEBUG | 153 #ifndef NDEBUG |
| 113 // Zeroing out to make the behavior more predictable when someone attempts t
o use a deleted instance. | 154 // Zeroing out to make the behavior more predictable when someone attempts t
o use a deleted instance. |
| 114 interpreter = 0; | 155 interpreter = 0; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 138 | 179 |
| 139 delete propertyNames; | 180 delete propertyNames; |
| 140 deleteIdentifierTable(identifierTable); | 181 deleteIdentifierTable(identifierTable); |
| 141 | 182 |
| 142 delete newParserObjects; | 183 delete newParserObjects; |
| 143 delete parserObjectExtraRefCounts; | 184 delete parserObjectExtraRefCounts; |
| 144 | 185 |
| 145 delete clientData; | 186 delete clientData; |
| 146 } | 187 } |
| 147 | 188 |
| 148 PassRefPtr<JSGlobalData> JSGlobalData::create() | 189 PassRefPtr<JSGlobalData> JSGlobalData::create(bool isShared) |
| 149 { | 190 { |
| 150 return adoptRef(new JSGlobalData); | 191 return adoptRef(new JSGlobalData(isShared, VPtrSet())); |
| 151 } | 192 } |
| 152 | 193 |
| 153 PassRefPtr<JSGlobalData> JSGlobalData::createLeaked() | 194 PassRefPtr<JSGlobalData> JSGlobalData::createLeaked() |
| 154 { | 195 { |
| 155 #ifndef NDEBUG | 196 #ifndef NDEBUG |
| 156 Structure::startIgnoringLeaks(); | 197 Structure::startIgnoringLeaks(); |
| 157 RefPtr<JSGlobalData> data = create(); | 198 RefPtr<JSGlobalData> data = create(); |
| 158 Structure::stopIgnoringLeaks(); | 199 Structure::stopIgnoringLeaks(); |
| 159 return data.release(); | 200 return data.release(); |
| 160 #else | 201 #else |
| 161 return create(); | 202 return create(); |
| 162 #endif | 203 #endif |
| 163 } | 204 } |
| 164 | 205 |
| 165 bool JSGlobalData::sharedInstanceExists() | 206 bool JSGlobalData::sharedInstanceExists() |
| 166 { | 207 { |
| 167 return sharedInstanceInternal(); | 208 return sharedInstanceInternal(); |
| 168 } | 209 } |
| 169 | 210 |
| 170 JSGlobalData& JSGlobalData::sharedInstance() | 211 JSGlobalData& JSGlobalData::sharedInstance() |
| 171 { | 212 { |
| 172 JSGlobalData*& instance = sharedInstanceInternal(); | 213 JSGlobalData*& instance = sharedInstanceInternal(); |
| 173 if (!instance) { | 214 if (!instance) { |
| 174 instance = new JSGlobalData(true); | 215 instance = create(true).releaseRef(); |
| 175 #if ENABLE(JSC_MULTIPLE_THREADS) | 216 #if ENABLE(JSC_MULTIPLE_THREADS) |
| 176 instance->makeUsableFromMultipleThreads(); | 217 instance->makeUsableFromMultipleThreads(); |
| 177 #endif | 218 #endif |
| 178 } | 219 } |
| 179 return *instance; | 220 return *instance; |
| 180 } | 221 } |
| 181 | 222 |
| 182 JSGlobalData*& JSGlobalData::sharedInstanceInternal() | 223 JSGlobalData*& JSGlobalData::sharedInstanceInternal() |
| 183 { | 224 { |
| 184 ASSERT(JSLock::currentThreadIsHoldingLock()); | 225 ASSERT(JSLock::currentThreadIsHoldingLock()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 199 | 240 |
| 200 return lazyNumericCompareFunction; | 241 return lazyNumericCompareFunction; |
| 201 } | 242 } |
| 202 | 243 |
| 203 JSGlobalData::ClientData::~ClientData() | 244 JSGlobalData::ClientData::~ClientData() |
| 204 { | 245 { |
| 205 } | 246 } |
| 206 | 247 |
| 207 } // namespace JSC | 248 } // namespace JSC |
| 208 | 249 |
| OLD | NEW |