source: webkit/trunk/JavaScriptCore/kjs/JSGlobalData.h@ 37337

Last change on this file since 37337 was 37323, checked in by [email protected], 17 years ago

2008-10-05 Maciej Stachowiak <[email protected]>

Reviewed by Oliver Hunt.



The problem is that dynamicGlobalObject had become O(N) in number
of call frames, but unwinding the stack for an exception called it
for every call frame, resulting in O(N2) behavior for an
exception thrown from inside deep recursion.

Instead of doing it that way, stash the dynamic global object in JSGlobalData.


  • JavaScriptCore.exp:
  • VM/Machine.cpp: (JSC::DynamicGlobalObjectScope::DynamicGlobalObjectScope): Helper class to temporarily store and later restore a dynamicGlobalObject in JSGlobalData. (JSC::DynamicGlobalObjectScope::~DynamicGlobalObjectScope): (JSC::Machine::execute): In each version, establish a DynamicGlobalObjectScope. For ProgramNode, always establish set new dynamicGlobalObject, for FunctionBody and Eval, only if none is currently set.
  • VM/Machine.h:
  • kjs/ExecState.h:
  • kjs/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData): Ininitalize new dynamicGlobalObject field to 0.
  • kjs/JSGlobalData.h:
  • kjs/JSGlobalObject.h: (JSC::ExecState::dynamicGlobalObject): Moved here from ExecState for benefit of inlining. Return lexical global object if this is a globalExec(), otherwise look in JSGlobalData for the one stashed there.
  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1/*
2 * Copyright (C) 2008 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 <wtf/Forward.h>
33#include <wtf/HashMap.h>
34#include <wtf/RefCounted.h>
35#include "collector.h"
36#include "SmallStrings.h"
37
38struct OpaqueJSClass;
39struct OpaqueJSClassContextData;
40
41namespace JSC {
42
43 class ArgList;
44 class CommonIdentifiers;
45 class Heap;
46 class IdentifierTable;
47 class JSGlobalObject;
48 class JSObject;
49 class Lexer;
50 class Machine;
51 class Parser;
52 class ParserRefCounted;
53 class StructureID;
54 class UString;
55 struct HashTable;
56
57 class JSGlobalData : public RefCounted<JSGlobalData> {
58 public:
59 static bool sharedInstanceExists();
60 static JSGlobalData& sharedInstance();
61
62 static PassRefPtr<JSGlobalData> create();
63 ~JSGlobalData();
64
65 Machine* machine;
66
67 JSValue* exception;
68#if ENABLE(CTI)
69 void* throwReturnAddress;
70#endif
71
72 const HashTable* arrayTable;
73 const HashTable* dateTable;
74 const HashTable* mathTable;
75 const HashTable* numberTable;
76 const HashTable* regExpTable;
77 const HashTable* regExpConstructorTable;
78 const HashTable* stringTable;
79
80 RefPtr<StructureID> nullProtoStructureID;
81 RefPtr<StructureID> activationStructureID;
82 RefPtr<StructureID> staticScopeStructureID;
83 RefPtr<StructureID> stringStructureID;
84 RefPtr<StructureID> numberStructureID;
85
86 IdentifierTable* identifierTable;
87 CommonIdentifiers* propertyNames;
88 const ArgList* 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.
89
90 SmallStrings smallStrings;
91
92 HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData;
93
94 HashSet<ParserRefCounted*>* newParserObjects;
95 HashCountedSet<ParserRefCounted*>* parserObjectExtraRefCounts;
96
97 Lexer* lexer;
98 Parser* parser;
99
100 JSGlobalObject* head;
101 JSGlobalObject* dynamicGlobalObject;
102
103 bool isSharedInstance;
104
105 struct ClientData {
106 virtual ~ClientData() = 0;
107 };
108
109 ClientData* clientData;
110
111 HashSet<JSObject*> arrayVisitedElements;
112
113 Heap heap;
114
115 private:
116 JSGlobalData(bool isShared = false);
117
118 static JSGlobalData*& sharedInstanceInternal();
119 };
120
121}
122
123#endif
Note: See TracBrowser for help on using the repository browser.