source: webkit/trunk/JavaScriptCore/kjs/SmallStrings.cpp@ 37747

Last change on this file since 37747 was 37257, checked in by Darin Adler, 17 years ago

JavaScriptCore:

2008-10-03 Darin Adler <Darin Adler>

Reviewed by Geoff Garen.

Remove m_globalObject and m_globalData from ExecState.

SunSpider says this is a wash (slightly faster but not statistically
significant); which is good enough since it's a preparation step and
not supposed to be a spedup.

  • API/JSCallbackFunction.cpp: (JSC::JSCallbackFunction::JSCallbackFunction):
  • kjs/ArrayConstructor.cpp: (JSC::ArrayConstructor::ArrayConstructor):
  • kjs/BooleanConstructor.cpp: (JSC::BooleanConstructor::BooleanConstructor):
  • kjs/DateConstructor.cpp: (JSC::DateConstructor::DateConstructor):
  • kjs/ErrorConstructor.cpp: (JSC::ErrorConstructor::ErrorConstructor):
  • kjs/FunctionPrototype.cpp: (JSC::FunctionPrototype::FunctionPrototype):
  • kjs/JSFunction.cpp: (JSC::JSFunction::JSFunction):
  • kjs/NativeErrorConstructor.cpp: (JSC::NativeErrorConstructor::NativeErrorConstructor):
  • kjs/NumberConstructor.cpp: (JSC::NumberConstructor::NumberConstructor):
  • kjs/ObjectConstructor.cpp: (JSC::ObjectConstructor::ObjectConstructor):
  • kjs/PrototypeFunction.cpp: (JSC::PrototypeFunction::PrototypeFunction):
  • kjs/RegExpConstructor.cpp: (JSC::RegExpConstructor::RegExpConstructor):
  • kjs/StringConstructor.cpp: (JSC::StringConstructor::StringConstructor): Pass JSGlobalData* instead of ExecState* to the InternalFunction constructor.
  • API/OpaqueJSString.cpp: Added now-needed include.
  • VM/CTI.cpp: (JSC::CTI::emitSlowScriptCheck): Changed to use ARGS_globalData instead of ARGS_exec.
  • VM/CTI.h: Added a new argument to the CTI, the global data pointer. While it's possible to get to the global data pointer using the ExecState pointer, it's slow enough that it's better to just keep it around in the CTI arguments.
  • VM/CodeBlock.h: Moved the CodeType enum here from ExecState.h.
  • VM/Machine.cpp: (JSC::Machine::execute): Pass fewer arguments when constructing ExecState, and pass the global data pointer when invoking CTI. (JSC::Machine::firstCallFrame): Added. Used to get the dynamic global object, which is in the scope chain of the first call frame. (JSC::Machine::cti_op_add): Use globalData instead of exec when possible, to keep fast cases fast, since it's now more expensive to get to it through the exec pointer. (JSC::Machine::cti_timeout_check): Ditto. (JSC::Machine::cti_op_put_by_id_second): Ditto. (JSC::Machine::cti_op_get_by_id_second): Ditto. (JSC::Machine::cti_op_mul): Ditto. (JSC::Machine::cti_vm_compile): Ditto. (JSC::Machine::cti_op_get_by_val): Ditto. (JSC::Machine::cti_op_sub): Ditto. (JSC::Machine::cti_op_put_by_val): Ditto. (JSC::Machine::cti_op_put_by_val_array): Ditto. (JSC::Machine::cti_op_negate): Ditto. (JSC::Machine::cti_op_div): Ditto. (JSC::Machine::cti_op_pre_dec): Ditto. (JSC::Machine::cti_op_post_inc): Ditto. (JSC::Machine::cti_op_lshift): Ditto. (JSC::Machine::cti_op_bitand): Ditto. (JSC::Machine::cti_op_rshift): Ditto. (JSC::Machine::cti_op_bitnot): Ditto. (JSC::Machine::cti_op_mod): Ditto. (JSC::Machine::cti_op_post_dec): Ditto. (JSC::Machine::cti_op_urshift): Ditto. (JSC::Machine::cti_op_bitxor): Ditto. (JSC::Machine::cti_op_bitor): Ditto. (JSC::Machine::cti_op_call_eval): Ditto. (JSC::Machine::cti_op_throw): Ditto. (JSC::Machine::cti_op_is_string): Ditto. (JSC::Machine::cti_op_debug): Ditto. (JSC::Machine::cti_vm_throw): Ditto.
  • VM/Machine.h: Added firstCallFrame.
  • kjs/DebuggerCallFrame.cpp: (JSC::DebuggerCallFrame::evaluate): Pass fewer arguments when constructing ExecState.
  • kjs/ExecState.cpp: Deleted contents. Later we'll remove the file altogether.
  • kjs/ExecState.h: Removed m_globalObject and m_globalData. Moved CodeType into another header. (JSC::ExecState::ExecState): Take only a single argument, a call frame pointer. (JSC::ExecState::dynamicGlobalObject): Get the object from the first call frame since it's no longer stored. (JSC::ExecState::globalData): Get the global data from the scope chain, since we no longer store a pointer to it here. (JSC::ExecState::identifierTable): Ditto. (JSC::ExecState::propertyNames): Ditto. (JSC::ExecState::emptyList): Ditto. (JSC::ExecState::lexer): Ditto. (JSC::ExecState::parser): Ditto. (JSC::ExecState::machine): Ditto. (JSC::ExecState::arrayTable): Ditto. (JSC::ExecState::dateTable): Ditto. (JSC::ExecState::mathTable): Ditto. (JSC::ExecState::numberTable): Ditto. (JSC::ExecState::regExpTable): Ditto. (JSC::ExecState::regExpConstructorTable): Ditto. (JSC::ExecState::stringTable): Ditto. (JSC::ExecState::heap): Ditto.
  • kjs/FunctionConstructor.cpp: (JSC::FunctionConstructor::FunctionConstructor): Pass JSGlobalData* instead of ExecState* to the InternalFunction constructor. (JSC::constructFunction): Pass the global data pointer when constructing a new scope chain.
  • kjs/InternalFunction.cpp: (JSC::InternalFunction::InternalFunction): Take a JSGlobalData* instead of an ExecState*. Later we can change more places to work this way -- it's more efficient to take the type you need since the caller might already have it.
  • kjs/InternalFunction.h: Ditto.
  • kjs/JSCell.h: (JSC::JSCell::operator new): Added an overload that takes a JSGlobalData* so you can construct without an ExecState*.
  • kjs/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): Moved creation of the global scope chain in here, since it now requires a pointer to the global data. Moved the initialization of the call frame in here since it requires the global scope chain node. Removed the extra argument to ExecState when creating the global ExecState*.
  • kjs/JSGlobalObject.h: Removed initialization of globalScopeChain and the call frame from the JSGlobalObjectData constructor. Added a thisValue argument to the init function.
  • kjs/JSNumberCell.cpp: Added versions of jsNumberCell that take JSGlobalData* rather than ExecState*.
  • kjs/JSNumberCell.h: (JSC::JSNumberCell::operator new): Added a version that takes JSGlobalData*. (JSC::JSNumberCell::JSNumberCell): Ditto. (JSC::jsNumber): Ditto.
  • kjs/JSString.cpp: (JSC::jsString): Ditto. (JSC::jsSubstring): Ditto. (JSC::jsOwnedString): Ditto.
  • kjs/JSString.h: (JSC::JSString::JSString): Changed to take JSGlobalData*. (JSC::jsEmptyString): Added a version that takes JSGlobalData*. (JSC::jsSingleCharacterString): Ditto. (JSC::jsSingleCharacterSubstring): Ditto. (JSC::jsNontrivialString): Ditto. (JSC::JSString::getIndex): Ditto. (JSC::jsString): Ditto. (JSC::jsSubstring): Ditto. (JSC::jsOwnedString): Ditto.
  • kjs/ScopeChain.h: Added a globalData pointer to each node. (JSC::ScopeChainNode::ScopeChainNode): Initialize the globalData pointer. (JSC::ScopeChainNode::push): Set the global data pointer in the new node. (JSC::ScopeChain::ScopeChain): Take a globalData argument.
  • kjs/SmallStrings.cpp: (JSC::SmallStrings::createEmptyString): Take JSGlobalData* instead of ExecState*. (JSC::SmallStrings::createSingleCharacterString): Ditto.
  • kjs/SmallStrings.h: (JSC::SmallStrings::emptyString): Ditto. (JSC::SmallStrings::singleCharacterString): Ditto.

WebCore:

2008-10-03 Darin Adler <Darin Adler>

Reviewed by Geoff Garen.

Remove m_globalObject and m_globalData from ExecState.

  • bindings/js/JSDOMWindowBase.cpp: (WebCore::JSDOMWindowBase::JSDOMWindowBaseData::JSDOMWindowBaseData): Removed an argument now that JSGlobalObject doesn't need it any more. (WebCore::JSDOMWindowBase::JSDOMWindowBase): Removed the argument from the JSDOMWindowBaseData constructor, and added the this argument to the JSGlobalObject constructor. This is because a couple key bits of initialization moved from the data constructor to the JSGlobalObject constructor.
  • bindings/js/JSDOMWindowBase.h: Ditto.
  • bridge/qt/qt_runtime.cpp: (JSC::Bindings::QtRuntimeMethod::QtRuntimeMethod):
  • bridge/runtime_method.cpp: (JSC::RuntimeMethod::RuntimeMethod): Pass JSGlobalData* instead of ExecState* to the InternalFunction constructor.
  • Property svn:eol-style set to native
File size: 3.4 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 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "SmallStrings.h"
28
29#include "JSGlobalObject.h"
30#include "JSString.h"
31
32namespace JSC {
33
34class SmallStringsStorage {
35public:
36 SmallStringsStorage();
37 ~SmallStringsStorage();
38
39 UString::Rep* rep(unsigned char character) { return &reps[character]; }
40
41private:
42 UChar characters[0x100];
43 UString::Rep* reps;
44};
45
46SmallStringsStorage::SmallStringsStorage()
47 : reps(static_cast<UString::Rep*>(fastZeroedMalloc(sizeof(UString::Rep) * 0x100)))
48{
49 for (unsigned i = 0; i < 0x100; ++i) {
50 characters[i] = i;
51 reps[i].offset = i;
52 reps[i].len = 1;
53 reps[i].rc = 1;
54 reps[i].baseString = &reps[0];
55 }
56 reps[0].rc = 0x101;
57 reps[0].buf = characters;
58
59 // make sure UString doesn't try to reuse the buffer by pretending we have one more character in it
60 reps[0].usedCapacity = 0x101;
61 reps[0].capacity = 0x101;
62}
63
64SmallStringsStorage::~SmallStringsStorage()
65{
66 fastFree(reps);
67}
68
69SmallStrings::SmallStrings()
70 : m_emptyString(0)
71 , m_storage(0)
72{
73 for (unsigned i = 0; i < 0x100; ++i)
74 m_singleCharacterStrings[i] = 0;
75}
76
77SmallStrings::~SmallStrings()
78{
79}
80
81void SmallStrings::mark()
82{
83 if (m_emptyString && !m_emptyString->marked())
84 m_emptyString->mark();
85 for (unsigned i = 0; i < 0x100; ++i) {
86 if (m_singleCharacterStrings[i] && !m_singleCharacterStrings[i]->marked())
87 m_singleCharacterStrings[i]->mark();
88 }
89}
90
91void SmallStrings::createEmptyString(JSGlobalData* globalData)
92{
93 ASSERT(!m_emptyString);
94 m_emptyString = new (globalData) JSString(globalData, "", JSString::HasOtherOwner);
95}
96
97void SmallStrings::createSingleCharacterString(JSGlobalData* globalData, unsigned char character)
98{
99 if (!m_storage)
100 m_storage.set(new SmallStringsStorage);
101 ASSERT(!m_singleCharacterStrings[character]);
102 m_singleCharacterStrings[character] = new (globalData) JSString(globalData, m_storage->rep(character), JSString::HasOtherOwner);
103}
104
105UString::Rep* SmallStrings::singleCharacterStringRep(unsigned char character)
106{
107 if (!m_storage)
108 m_storage.set(new SmallStringsStorage);
109 return m_storage->rep(character);
110}
111
112}
Note: See TracBrowser for help on using the repository browser.