source: webkit/trunk/JavaScriptCore/kjs/JSGlobalData.cpp@ 34412

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

Reviewed by Darin.

Combine per-thread objects into one, to make it easier to support legacy clients (for
which they shouldn't be really per-thread).

No change on SunSpider total.

  • kjs/JSGlobalData.cpp: Added. (KJS::JSGlobalData::JSGlobalData): (KJS::JSGlobalData::~JSGlobalData): (KJS::JSGlobalData::threadInstance):
  • kjs/JSGlobalData.h: Added. This class encapsulates all data that should be per-thread (or shared between legacy clients). It will also keep a Heap pointer, but right now, Heap (Collector) methods are all static.
  • kjs/identifier.h: (KJS::Identifier::Identifier): Added a constructor explicitly taking JSGlobalData to access IdentifierTable. Actually, all of them should, but this will be a separate patch.
  • kjs/identifier.cpp: (KJS::IdentifierTable::literalTable): (KJS::createIdentifierTable): (KJS::deleteIdentifierTable): (KJS::Identifier::add): (KJS::Identifier::addSlowCase): Combined IdentifierTable and LiteralIdentifierTable into a single class for simplicity.
  • kjs/grammar.y: kjsyyparse now takes JSGlobalData, not just a Lexer.
  • kjs/nodes.cpp: (KJS::Node::Node): (KJS::EvalFunctionCallNode::emitCode): (KJS::ScopeNode::ScopeNode): Changed to access Lexer and Parser via JSGlobalData::threadInstance(). This is also a temporary measure, they will need to use JSGlobalData explicitly.
  • VM/CodeGenerator.cpp: (KJS::CodeGenerator::CodeGenerator):
  • VM/CodeGenerator.h:
  • VM/Machine.cpp: (KJS::callEval):
  • kjs/CommonIdentifiers.cpp: (KJS::CommonIdentifiers::CommonIdentifiers):
  • kjs/CommonIdentifiers.h:
  • kjs/DebuggerCallFrame.cpp: (KJS::DebuggerCallFrame::evaluate):
  • kjs/ExecState.cpp: (KJS::ExecState::ExecState):
  • kjs/ExecState.h: (KJS::ExecState::globalData): (KJS::ExecState::identifierTable): (KJS::ExecState::propertyNames): (KJS::ExecState::emptyList): (KJS::ExecState::lexer): (KJS::ExecState::parser): (KJS::ExecState::arrayTable): (KJS::ExecState::dateTable): (KJS::ExecState::mathTable): (KJS::ExecState::numberTable): (KJS::ExecState::RegExpImpTable): (KJS::ExecState::RegExpObjectImpTable): (KJS::ExecState::stringTable):
  • kjs/InitializeThreading.cpp: (KJS::initializeThreadingOnce):
  • kjs/JSGlobalObject.cpp: (KJS::JSGlobalObject::init):
  • kjs/JSGlobalObject.h: (KJS::JSGlobalObject::JSGlobalObjectData::JSGlobalObjectData): (KJS::JSGlobalObject::head): (KJS::JSGlobalObject::globalData):
  • kjs/Parser.cpp: (KJS::Parser::parse):
  • kjs/Parser.h:
  • kjs/function.cpp: (KJS::FunctionImp::getParameterName): (KJS::IndexToNameMap::unMap): (KJS::globalFuncEval):
  • kjs/function_object.cpp: (KJS::FunctionObjectImp::construct):
  • kjs/interpreter.cpp: (KJS::Interpreter::checkSyntax): (KJS::Interpreter::evaluate):
  • kjs/lexer.cpp: (kjsyylex):
  • kjs/lexer.h:
  • kjs/testkjs.cpp: (prettyPrintScript): Updated for the above changes. Most of threadInstance uses here will need to be replaced with explicitly passed pointers to support legacy JSC clients.
  • Property svn:eol-style set to native
File size: 3.7 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#include "config.h"
30#include "JSGlobalData.h"
31
32#include "collector.h"
33#include "CommonIdentifiers.h"
34#include "lexer.h"
35#include "list.h"
36#include "lookup.h"
37#include "nodes.h"
38#include "parser.h"
39
40#if USE(MULTIPLE_THREADS)
41#include <wtf/ThreadSpecific.h>
42#endif
43
44using namespace WTF;
45
46namespace KJS {
47
48extern const HashTable arrayTable;
49extern const HashTable dateTable;
50extern const HashTable mathTable;
51extern const HashTable numberTable;
52extern const HashTable RegExpImpTable;
53extern const HashTable RegExpObjectImpTable;
54extern const HashTable stringTable;
55
56
57JSGlobalData::JSGlobalData()
58// : heap(new Heap)
59#if USE(MULTIPLE_THREADS)
60 : arrayTable(new HashTable(KJS::arrayTable))
61 , dateTable(new HashTable(KJS::dateTable))
62 , mathTable(new HashTable(KJS::mathTable))
63 , numberTable(new HashTable(KJS::numberTable))
64 , RegExpImpTable(new HashTable(KJS::RegExpImpTable))
65 , RegExpObjectImpTable(new HashTable(KJS::RegExpObjectImpTable))
66 , stringTable(new HashTable(KJS::stringTable))
67#else
68 : arrayTable(&KJS::arrayTable)
69 , dateTable(&KJS::dateTable)
70 , mathTable(&KJS::mathTable)
71 , numberTable(&KJS::numberTable)
72 , RegExpImpTable(&KJS::RegExpImpTable)
73 , RegExpObjectImpTable(&KJS::RegExpObjectImpTable)
74 , stringTable(&KJS::stringTable)
75#endif
76 , identifierTable(createIdentifierTable())
77 , propertyNames(new CommonIdentifiers(this))
78 , lexer(new Lexer)
79 , parser(new Parser)
80 , head(0)
81{
82}
83
84JSGlobalData::~JSGlobalData()
85{
86#if USE(MULTIPLE_THREADS)
87 delete[] arrayTable->table;
88 delete[] dateTable->table;
89 delete[] mathTable->table;
90 delete[] numberTable->table;
91 delete[] RegExpImpTable->table;
92 delete[] RegExpObjectImpTable->table;
93 delete[] stringTable->table;
94 delete arrayTable;
95 delete dateTable;
96 delete mathTable;
97 delete numberTable;
98 delete RegExpImpTable;
99 delete RegExpObjectImpTable;
100 delete stringTable;
101
102 delete parser;
103 delete lexer;
104
105 delete propertyNames;
106 deleteIdentifierTable(identifierTable);
107#endif
108}
109
110JSGlobalData& JSGlobalData::threadInstance()
111{
112#if USE(MULTIPLE_THREADS)
113 static ThreadSpecific<JSGlobalData> sharedInstance;
114 return *sharedInstance;
115#else
116 return globalSharedInstance();
117#endif
118}
119
120}
Note: See TracBrowser for help on using the repository browser.