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

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

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

Reviewed by Oliver.


  • enable polymorphic inline caching of properties of primitives


1.012x speedup on SunSpider.

We create special structure IDs for JSString and
JSNumberCell. Unlike normal structure IDs, these cannot hold the
true prototype. Due to JS autoboxing semantics, the prototype used
when looking up string or number properties depends on the lexical
global object of the call site, not the creation site. Thus we
enable StructureIDs to handle this quirk for primitives.


Everything else should be straightforward.


  • VM/CTI.cpp: (JSC::CTI::privateCompileGetByIdProto): (JSC::CTI::privateCompileGetByIdChain):
  • VM/CTI.h: (JSC::CTI::compileGetByIdProto): (JSC::CTI::compileGetByIdChain):
  • VM/JSPropertyNameIterator.h: (JSC::JSPropertyNameIterator::JSPropertyNameIterator):
  • VM/Machine.cpp: (JSC::Machine::Machine): (JSC::cachePrototypeChain): (JSC::Machine::tryCachePutByID): (JSC::Machine::tryCacheGetByID): (JSC::Machine::privateExecute): (JSC::Machine::tryCTICachePutByID): (JSC::Machine::tryCTICacheGetByID):
  • kjs/GetterSetter.h: (JSC::GetterSetter::GetterSetter):
  • kjs/JSCell.h:
  • kjs/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData):
  • kjs/JSGlobalData.h:
  • kjs/JSGlobalObject.h: (JSC::StructureID::prototypeForLookup):
  • kjs/JSNumberCell.h: (JSC::JSNumberCell::JSNumberCell): (JSC::jsNumberCell):
  • kjs/JSObject.h: (JSC::JSObject::prototype):
  • kjs/JSString.cpp: (JSC::jsString): (JSC::jsSubstring): (JSC::jsOwnedString):
  • kjs/JSString.h: (JSC::JSString::JSString): (JSC::JSString::): (JSC::jsSingleCharacterString): (JSC::jsSingleCharacterSubstring): (JSC::jsNontrivialString):
  • kjs/SmallStrings.cpp: (JSC::SmallStrings::createEmptyString): (JSC::SmallStrings::createSingleCharacterString):
  • kjs/StructureID.cpp: (JSC::StructureID::StructureID): (JSC::StructureID::addPropertyTransition): (JSC::StructureID::getterSetterTransition): (JSC::StructureIDChain::StructureIDChain):
  • kjs/StructureID.h: (JSC::StructureID::create): (JSC::StructureID::storedPrototype):
  • 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 "JSString.h"
30
31namespace JSC {
32
33class SmallStringsStorage {
34public:
35 SmallStringsStorage();
36 ~SmallStringsStorage();
37
38 UString::Rep* rep(unsigned char character) { return &reps[character]; }
39
40private:
41 UChar characters[0x100];
42 UString::Rep* reps;
43};
44
45SmallStringsStorage::SmallStringsStorage()
46 : reps(static_cast<UString::Rep*>(fastZeroedMalloc(sizeof(UString::Rep) * 0x100)))
47{
48 for (unsigned i = 0; i < 0x100; ++i) {
49 characters[i] = i;
50 reps[i].offset = i;
51 reps[i].len = 1;
52 reps[i].rc = 1;
53 reps[i].baseString = &reps[0];
54 }
55 reps[0].rc = 0x101;
56 reps[0].buf = characters;
57
58 // make sure UString doesn't try to reuse the buffer by pretending we have one more character in it
59 reps[0].usedCapacity = 0x101;
60 reps[0].capacity = 0x101;
61}
62
63SmallStringsStorage::~SmallStringsStorage()
64{
65 fastFree(reps);
66}
67
68SmallStrings::SmallStrings()
69 : m_emptyString(0)
70 , m_storage(0)
71{
72 for (unsigned i = 0; i < 0x100; ++i)
73 m_singleCharacterStrings[i] = 0;
74}
75
76SmallStrings::~SmallStrings()
77{
78}
79
80void SmallStrings::mark()
81{
82 if (m_emptyString && !m_emptyString->marked())
83 m_emptyString->mark();
84 for (unsigned i = 0; i < 0x100; ++i) {
85 if (m_singleCharacterStrings[i] && !m_singleCharacterStrings[i]->marked())
86 m_singleCharacterStrings[i]->mark();
87 }
88}
89
90void SmallStrings::createEmptyString(ExecState* exec)
91{
92 ASSERT(!m_emptyString);
93 m_emptyString = new (exec) JSString(exec, "", JSString::HasOtherOwner);
94}
95
96void SmallStrings::createSingleCharacterString(ExecState* exec, unsigned char character)
97{
98 if (!m_storage)
99 m_storage.set(new SmallStringsStorage);
100 ASSERT(!m_singleCharacterStrings[character]);
101 m_singleCharacterStrings[character] = new (exec) JSString(exec, m_storage->rep(character), JSString::HasOtherOwner);
102}
103
104UString::Rep* SmallStrings::singleCharacterStringRep(unsigned char character)
105{
106 if (!m_storage)
107 m_storage.set(new SmallStringsStorage);
108 return m_storage->rep(character);
109}
110
111}
Note: See TracBrowser for help on using the repository browser.