source: webkit/trunk/JavaScriptCore/VM/CodeBlock.h@ 36016

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

JavaScriptCore:

2008-09-01 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler.

First cut at inline caching for access to vanilla JavaScript properties.


SunSpider says 4% faster. Tests heavy on dictionary-like access have
regressed a bit -- we have a lot of room to improve in this area,
but this patch is over-ripe as-is.


JSCells now have a StructureID that uniquely identifies their layout,
and holds their prototype.


JSValue::put takes a PropertySlot& argument, so it can fill in details
about where it put a value, for the sake of caching.

  • VM/CodeGenerator.cpp: (KJS::CodeGenerator::CodeGenerator): Avoid calling removeDirect if we can, since it disables inline caching in the global object. This can probably improve in the future.
  • kjs/JSGlobalObject.cpp: Nixed reset(), since it complicates caching, and wasn't really necessary.
  • kjs/JSObject.cpp: Tweaked getter / setter behavior not to rely on the IsGetterSetter flag, since the flag was buggy. This is necessary in order to avoid accidentally accessing a getter / setter as a normal property.


Also changed getter / setter creation to honor ReadOnly, matching Mozilla.


  • kjs/PropertyMap.cpp: Nixed clear(), since it complicates caching and isn't necessary.
  • kjs/Shell.cpp: Moved SamplingTool dumping outside the loop. This allows you to aggregate sampling of multiple files (or the same file repeatedly), which helped me track down regressions.
  • kjs/ustring.h: Moved IdentifierRepHash here to share it.

WebCore:

2008-09-01 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler.

First cut at inline caching for access to vanilla JavaScript properties.

Updated for JavaScriptCore changes. Mostly mechanical addition of StructureIDs
to WebCore classes, and PutPropertySlot& arguments to put functions.

(WebCore::JSCSSStyleDeclaration::customPut): Be sure to play nice with
inline caching for global properties, so global assignment can be optimized.

  • ForwardingHeaders/kjs/StructureID.h: Added.
  • bindings/js/JSDOMBinding.h: (WebCore::DOMObject::DOMObject):
  • bindings/js/JSDOMWindowBase.cpp: (WebCore::JSDOMWindowBase::put):
  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSDOMWindowCustom.h: (WebCore::JSDOMWindow::customPut):
  • bindings/js/JSDOMWindowShell.cpp: (WebCore::JSDOMWindowShell::JSDOMWindowShell): (WebCore::JSDOMWindowShell::put):
  • bindings/js/JSDOMWindowShell.h:
  • bindings/js/JSEventTargetBase.h: (WebCore::JSEventTargetBase::put):
  • bindings/js/JSEventTargetNode.h: (WebCore::JSEventTargetNode::put):
  • bindings/js/JSHTMLAppletElementCustom.cpp: (WebCore::JSHTMLAppletElement::customPut):
  • bindings/js/JSHTMLEmbedElementCustom.cpp: (WebCore::JSHTMLEmbedElement::customPut):
  • bindings/js/JSHTMLInputElementBase.cpp: (WebCore::JSHTMLInputElementBase::put):
  • bindings/js/JSHTMLInputElementBase.h:
  • bindings/js/JSHTMLObjectElementCustom.cpp: (WebCore::JSHTMLObjectElement::customPut):
  • bindings/js/JSHistoryCustom.cpp: (WebCore::JSHistory::customPut):
  • bindings/js/JSInspectedObjectWrapper.cpp: (WebCore::JSInspectedObjectWrapper::wrap): (WebCore::JSInspectedObjectWrapper::JSInspectedObjectWrapper):
  • bindings/js/JSInspectedObjectWrapper.h:
  • bindings/js/JSInspectorCallbackWrapper.cpp: (WebCore::JSInspectorCallbackWrapper::wrap): (WebCore::JSInspectorCallbackWrapper::JSInspectorCallbackWrapper):
  • bindings/js/JSInspectorCallbackWrapper.h:
  • bindings/js/JSLocationCustom.cpp: (WebCore::JSLocation::customPut):
  • bindings/js/JSPluginElementFunctions.cpp: (WebCore::runtimeObjectCustomPut):
  • bindings/js/JSPluginElementFunctions.h:
  • bindings/js/JSQuarantinedObjectWrapper.cpp: (WebCore::JSQuarantinedObjectWrapper::JSQuarantinedObjectWrapper): (WebCore::JSQuarantinedObjectWrapper::put):
  • bindings/js/JSQuarantinedObjectWrapper.h:
  • bindings/js/JSStorageCustom.cpp: (WebCore::JSStorage::customPut):
  • bindings/objc/WebScriptObject.mm: (-[WebScriptObject setValue:forKey:]):
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/NP_jsobject.cpp: (_NPN_SetProperty):
  • bridge/jni/jni_jsobject.mm: (JavaJSObject::setMember):
  • bridge/objc/objc_class.mm: (KJS::Bindings::ObjcClass::fallbackObject):
  • bridge/objc/objc_runtime.h:
  • bridge/objc/objc_runtime.mm: (ObjcFallbackObjectImp::ObjcFallbackObjectImp): (ObjcFallbackObjectImp::put):
  • bridge/runtime.cpp: (KJS::Bindings::Instance::createRuntimeObject):
  • bridge/runtime_array.cpp: (RuntimeArray::put):
  • bridge/runtime_array.h:
  • bridge/runtime_object.cpp: (RuntimeObjectImp::RuntimeObjectImp): (RuntimeObjectImp::put):
  • bridge/runtime_object.h:

LayoutTests:

2008-09-01 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler.

First cut at inline caching for access to vanilla JavaScript properties.


Tests for things I broke along the way.


  • fast/dom/getter-on-window-object2-expected.txt:
  • fast/js/pic: Added.
  • fast/js/pic/cached-deleted-properties-expected.txt: Added.
  • fast/js/pic/cached-deleted-properties.html: Added.
  • fast/js/pic/cached-getter-dictionary-and-proto-expected.txt: Added.
  • fast/js/pic/cached-getter-dictionary-and-proto.html: Added.
  • fast/js/pic/cached-getter-setter-expected.txt: Added.
  • fast/js/pic/cached-getter-setter.html: Added.
  • fast/js/pic/cached-prototype-setter-expected.txt: Added.
  • fast/js/pic/cached-prototype-setter.html: Added.
  • fast/js/pic/cached-single-entry-transition-expected.txt: Added.
  • fast/js/pic/cached-single-entry-transition.html: Added.
  • fast/js/pic/get-empty-string-expected.txt: Added.
  • fast/js/pic/get-empty-string.html: Added.
  • fast/js/pic/get-set-proxy-object-expected.txt: Added.
  • fast/js/pic/get-set-proxy-object.html: Added.
  • fast/js/pic/rehash-poisons-structure-expected.txt: Added.
  • fast/js/pic/rehash-poisons-structure.html: Added.
File size: 6.3 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich <[email protected]>
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef CodeBlock_h
31#define CodeBlock_h
32
33#include "Instruction.h"
34#include "JSGlobalObject.h"
35#include "nodes.h"
36#include "SourceRange.h"
37#include "ustring.h"
38#include <wtf/RefPtr.h>
39#include <wtf/Vector.h>
40
41namespace KJS {
42
43 class ExecState;
44
45 static ALWAYS_INLINE int missingThisObjectMarker() { return std::numeric_limits<int>::max(); }
46
47 struct HandlerInfo {
48 uint32_t start;
49 uint32_t end;
50 uint32_t target;
51 uint32_t scopeDepth;
52 };
53
54 struct ExpressionRangeInfo {
55 enum { MaxOffset = (1 << 7) - 1,
56 MaxDivot = (1 << 25) - 1
57 };
58 uint32_t instructionOffset : 25;
59 uint32_t divotPoint : 25;
60 uint32_t startOffset : 7;
61 uint32_t endOffset : 7;
62 };
63
64 struct LineInfo {
65 uint32_t instructionOffset;
66 int32_t lineNumber;
67 };
68
69 typedef HashMap<RefPtr<UString::Rep>, int32_t> StringJumpTable;
70 struct SimpleJumpTable {
71 Vector<int32_t> branchOffsets;
72 int32_t min;
73 int32_t offsetForValue(int32_t value, int32_t defaultOffset);
74 void add(int32_t key, int32_t offset) {
75 if (!branchOffsets[key])
76 branchOffsets[key] = offset;
77 }
78 };
79
80 struct CodeBlock {
81 CodeBlock(ScopeNode* ownerNode_, CodeType codeType_, PassRefPtr<SourceProvider> source_, unsigned sourceOffset_)
82 : ownerNode(ownerNode_)
83 , globalData(0)
84 , numTemporaries(0)
85 , numVars(0)
86 , numParameters(0)
87 , numLocals(0)
88 , needsFullScopeChain(ownerNode_->usesEval() || ownerNode_->needsClosure())
89 , usesEval(ownerNode_->usesEval())
90 , codeType(codeType_)
91 , source(source_)
92 , sourceOffset(sourceOffset_)
93 {
94 }
95
96 ~CodeBlock();
97
98#if !defined(NDEBUG) || ENABLE(SAMPLING_TOOL)
99 void dump(ExecState*) const;
100 void printStructureIDs(const Instruction*) const;
101 void printStructureID(const char* name, const Instruction*, int operand) const;
102#endif
103 int expressionRangeForVPC(const Instruction*, int& divot, int& startOffset, int& endOffset);
104 int lineNumberForVPC(const Instruction* vPC);
105 bool getHandlerForVPC(const Instruction* vPC, Instruction*& target, int& scopeDepth);
106
107 void mark();
108 void refStructureIDs(Instruction* vPC) const;
109 void derefStructureIDs(Instruction* vPC) const;
110
111 ScopeNode* ownerNode;
112 JSGlobalData* globalData;
113
114 int numConstants;
115 int numTemporaries;
116 int numVars;
117 int numParameters;
118 int numLocals;
119 int thisRegister;
120 bool needsFullScopeChain;
121 bool usesEval;
122 CodeType codeType;
123 RefPtr<SourceProvider> source;
124 unsigned sourceOffset;
125
126 Vector<Instruction> instructions;
127 Vector<size_t> structureIDInstructions;
128
129 // Constant pool
130 Vector<Identifier> identifiers;
131 Vector<RefPtr<FuncDeclNode> > functions;
132 Vector<RefPtr<FuncExprNode> > functionExpressions;
133 Vector<Register> constantRegisters;
134 Vector<JSValue*> unexpectedConstants;
135 Vector<RefPtr<RegExp> > regexps;
136 Vector<HandlerInfo> exceptionHandlers;
137 Vector<ExpressionRangeInfo> expressionInfo;
138 Vector<LineInfo> lineInfo;
139
140 Vector<SimpleJumpTable> immediateSwitchJumpTables;
141 Vector<SimpleJumpTable> characterSwitchJumpTables;
142 Vector<StringJumpTable> stringSwitchJumpTables;
143
144 private:
145#if !defined(NDEBUG) || ENABLE(SAMPLING_TOOL)
146 void dump(ExecState*, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator&) const;
147#endif
148 };
149
150 // Program code is not marked by any function, so we make the global object
151 // responsible for marking it.
152
153 struct ProgramCodeBlock : public CodeBlock {
154 ProgramCodeBlock(ScopeNode* ownerNode_, CodeType codeType_, JSGlobalObject* globalObject_, PassRefPtr<SourceProvider> source_)
155 : CodeBlock(ownerNode_, codeType_, source_, 0)
156 , globalObject(globalObject_)
157 {
158 globalObject->codeBlocks().add(this);
159 }
160
161 ~ProgramCodeBlock()
162 {
163 if (globalObject)
164 globalObject->codeBlocks().remove(this);
165 }
166
167 JSGlobalObject* globalObject; // For program and eval nodes, the global object that marks the constant pool.
168 };
169
170 struct EvalCodeBlock : public ProgramCodeBlock {
171 EvalCodeBlock(ScopeNode* ownerNode_, JSGlobalObject* globalObject_, PassRefPtr<SourceProvider> source_)
172 : ProgramCodeBlock(ownerNode_, EvalCode, globalObject_, source_)
173 {
174 }
175 };
176
177} // namespace KJS
178
179#endif // CodeBlock_h
Note: See TracBrowser for help on using the repository browser.