source: webkit/trunk/JavaScriptCore/interpreter/CallFrame.h@ 59742

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

JavaScriptCore: Simplified handling of 'arguments' -- 1.2% SunSpider speedup
https://bugs.webkit.org/show_bug.cgi?id=39200

Reviewed by Darin Adler.

Removed the reserved OptionalCalleeArguments slot from the CallFrame.
Now, slots for 'arguments' are allocated and initialized only by
functions that might need them.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::dump): Updated for new bytecode operands.

(JSC::CodeBlock::CodeBlock):

  • bytecode/CodeBlock.h:

(JSC::unmodifiedArgumentsRegister): Added a helper function for mapping
from the arguments register to its unmodified counterpart.

(JSC::CodeBlock::setArgumentsRegister):
(JSC::CodeBlock::argumentsRegister):
(JSC::CodeBlock::usesArguments): Changed from a "usesArguments" bool to
an optional int index representing the arguments register.

  • bytecode/Opcode.h: Updated for new bytecode operands.
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::addVar): Factored out a helper function for
allocating an anonymous var.

(JSC::BytecodeGenerator::BytecodeGenerator): Merged / simplified some
arguments vs activation logic, and added code to allocate the arguments
registers when needed.

(JSC::BytecodeGenerator::createArgumentsIfNecessary): Updated for new bytecode operands.

(JSC::BytecodeGenerator::emitCallEval): No need to create the arguments
object before calling eval; the activation object will lazily create the
arguments object if eval resolves it.

(JSC::BytecodeGenerator::emitReturn): Updated for new bytecode operands.

(JSC::BytecodeGenerator::emitPushScope):
(JSC::BytecodeGenerator::emitPushNewScope): Ditto emitCallEval.

  • bytecompiler/BytecodeGenerator.h:

(JSC::BytecodeGenerator::addVar): Factored out a helper function for
allocating an anonymous var.

(JSC::BytecodeGenerator::registerFor): No more need for special handling
of the arguments registers; they're allocated just like normal registers
now.

  • interpreter/CallFrame.h:

(JSC::ExecState::callerFrame):
(JSC::ExecState::init):

  • interpreter/CallFrameClosure.h:

(JSC::CallFrameClosure::resetCallFrame): Nixed optionalCalleeArguments.

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::dumpRegisters):
(JSC::Interpreter::unwindCallFrame):
(JSC::Interpreter::privateExecute):
(JSC::Interpreter::retrieveArguments): Opcodes accessing 'arguments' now
take operands specifying registers, just like all other opcodes.
JSActivation::copyRegisters is no longer responsible for tearing off the
arguments object; instead, the VM is responsible for both.

Also, a behavior change: Each access to f.arguments creates a new object,
unless f itself uses 'arguments'. This matches Chrome, and is necessary
for the optimization. f.arguments is a nonstandard, deprecated feature,
so high fidelity to a given implementation is not necessarily a goal.
Also, as illustrated by the new test case, the identity of f.arguments
has been broken since 2008, except in the case where f itself accesses
f.arguments -- but nobody seemed to notice. So, hopefully this change won't
break the web.

  • interpreter/Register.h: Nixed the special arguments accessor. It's no

longer needed.

  • interpreter/RegisterFile.h:

(JSC::RegisterFile::):

  • jit/JITCall.cpp:

(JSC::JIT::compileOpCallInitializeCallFrame):
(JSC::JIT::compileOpCall):

  • jit/JITOpcodes.cpp:

(JSC::JIT::emit_op_tear_off_activation):
(JSC::JIT::emit_op_tear_off_arguments):
(JSC::JIT::emit_op_create_arguments):
(JSC::JIT::emit_op_init_arguments):

  • jit/JITOpcodes32_64.cpp:

(JSC::JIT::emit_op_tear_off_activation):
(JSC::JIT::emit_op_tear_off_arguments):
(JSC::JIT::emit_op_create_arguments):
(JSC::JIT::emit_op_init_arguments): The actual optimization: Removed
OptionalCalleeArguments from the callframe slot. Now, it doesn't need
to be initialized for most calls.

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • jit/JITStubs.h:

(JSC::): Updated stubs to support arbitrary 'arguments' registers,
instead of hard-coding something in the call frame.

  • runtime/Arguments.h:

(JSC::JSActivation::copyRegisters): Removed some obfuscatory abstraction.

  • runtime/Executable.h:

(JSC::FunctionExecutable::generatedByteCode): Added a helper for accessing
the 'arguments' register. In a future patch, that kind of data should
probably move out of CodeBlock and into Executable.

  • runtime/JSActivation.cpp:

(JSC::JSActivation::getOwnPropertySlot):
(JSC::JSActivation::argumentsGetter):

  • runtime/JSActivation.h: Simplified / fixed access to 'arguments' via

the activation object. It now implements the same behavior implemented
by optimized variable access in the VM. This simplifies some other
things, too -- like eval code generation.

LayoutTests: Simplified handling of 'arguments' -- 1.2% SunSpider speedup
https://bugs.webkit.org/show_bug.cgi?id=39200

Reviewed by Darin Adler.

  • fast/js/function-dot-arguments-expected.txt:
  • fast/js/script-tests/function-dot-arguments.js:

(argumentsIdentity): Updated to match new behavior.

  • fast/js/function-dot-arguments2-expected.txt:
  • fast/js/function-dot-arguments2.html: New tests for some things that

weren't covered before.

  • fast/js/global-recursion-on-full-stack.html: Rejiggered the stack

usage in this test. Since stack usage is more efficient now, you
need a slightly different usage pattern to hit the exact thing this
test wanted to test.

  • fast/js/kde/script-tests/function_arguments.js:

(f): Updated to more specifically test what this was trying to test,
to avoid just testing the identity of f.arguments.

  • Property svn:eol-style set to native
File size: 7.5 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef CallFrame_h
24#define CallFrame_h
25
26#include "JSGlobalData.h"
27#include "RegisterFile.h"
28#include "ScopeChain.h"
29
30namespace JSC {
31
32 class Arguments;
33 class JSActivation;
34 class Interpreter;
35
36 // Represents the current state of script execution.
37 // Passed as the first argument to most functions.
38 class ExecState : private Register {
39 public:
40 JSFunction* callee() const { return this[RegisterFile::Callee].function(); }
41 CodeBlock* codeBlock() const { return this[RegisterFile::CodeBlock].Register::codeBlock(); }
42 ScopeChainNode* scopeChain() const
43 {
44 ASSERT(this[RegisterFile::ScopeChain].Register::scopeChain());
45 return this[RegisterFile::ScopeChain].Register::scopeChain();
46 }
47 int argumentCount() const { return this[RegisterFile::ArgumentCount].i(); }
48
49 JSValue thisValue();
50
51 // Global object in which execution began.
52 JSGlobalObject* dynamicGlobalObject();
53
54 // Global object in which the currently executing code was defined.
55 // Differs from dynamicGlobalObject() during function calls across web browser frames.
56 JSGlobalObject* lexicalGlobalObject() const
57 {
58 return scopeChain()->globalObject;
59 }
60
61 // Differs from lexicalGlobalObject because this will have DOM window shell rather than
62 // the actual DOM window, which can't be "this" for security reasons.
63 JSObject* globalThisValue() const
64 {
65 return scopeChain()->globalThis;
66 }
67
68 // FIXME: Elsewhere, we use JSGlobalData* rather than JSGlobalData&.
69 // We should make this more uniform and either use a reference everywhere
70 // or a pointer everywhere.
71 JSGlobalData& globalData() const
72 {
73 ASSERT(scopeChain()->globalData);
74 return *scopeChain()->globalData;
75 }
76
77 // Convenience functions for access to global data.
78 // It takes a few memory references to get from a call frame to the global data
79 // pointer, so these are inefficient, and should be used sparingly in new code.
80 // But they're used in many places in legacy code, so they're not going away any time soon.
81
82 void setException(JSValue exception) { globalData().exception = exception; }
83 void clearException() { globalData().exception = JSValue(); }
84 JSValue exception() const { return globalData().exception; }
85 JSValue* exceptionSlot() { return &globalData().exception; }
86 bool hadException() const { return globalData().exception; }
87
88 const CommonIdentifiers& propertyNames() const { return *globalData().propertyNames; }
89 const MarkedArgumentBuffer& emptyList() const { return *globalData().emptyList; }
90 Interpreter* interpreter() { return globalData().interpreter; }
91 Heap* heap() { return &globalData().heap; }
92#ifndef NDEBUG
93 void dumpCaller();
94#endif
95 static const HashTable* arrayTable(CallFrame* callFrame) { return callFrame->globalData().arrayTable; }
96 static const HashTable* dateTable(CallFrame* callFrame) { return callFrame->globalData().dateTable; }
97 static const HashTable* jsonTable(CallFrame* callFrame) { return callFrame->globalData().jsonTable; }
98 static const HashTable* mathTable(CallFrame* callFrame) { return callFrame->globalData().mathTable; }
99 static const HashTable* numberTable(CallFrame* callFrame) { return callFrame->globalData().numberTable; }
100 static const HashTable* regExpTable(CallFrame* callFrame) { return callFrame->globalData().regExpTable; }
101 static const HashTable* regExpConstructorTable(CallFrame* callFrame) { return callFrame->globalData().regExpConstructorTable; }
102 static const HashTable* stringTable(CallFrame* callFrame) { return callFrame->globalData().stringTable; }
103
104 static CallFrame* create(Register* callFrameBase) { return static_cast<CallFrame*>(callFrameBase); }
105 Register* registers() { return this; }
106
107 CallFrame& operator=(const Register& r) { *static_cast<Register*>(this) = r; return *this; }
108
109 CallFrame* callerFrame() const { return this[RegisterFile::CallerFrame].callFrame(); }
110 Instruction* returnPC() const { return this[RegisterFile::ReturnPC].vPC(); }
111
112 void setCallerFrame(CallFrame* callerFrame) { static_cast<Register*>(this)[RegisterFile::CallerFrame] = callerFrame; }
113 void setScopeChain(ScopeChainNode* scopeChain) { static_cast<Register*>(this)[RegisterFile::ScopeChain] = scopeChain; }
114
115 ALWAYS_INLINE void init(CodeBlock* codeBlock, Instruction* vPC, ScopeChainNode* scopeChain,
116 CallFrame* callerFrame, int returnValueRegister, int argc, JSFunction* function)
117 {
118 ASSERT(callerFrame); // Use noCaller() rather than 0 for the outer host call frame caller.
119
120 setCodeBlock(codeBlock);
121 setScopeChain(scopeChain);
122 setCallerFrame(callerFrame);
123 static_cast<Register*>(this)[RegisterFile::ReturnPC] = vPC; // This is either an Instruction* or a pointer into JIT generated code stored as an Instruction*.
124 static_cast<Register*>(this)[RegisterFile::ReturnValueRegister] = Register::withInt(returnValueRegister);
125 setArgumentCount(argc); // original argument count (for the sake of the "arguments" object)
126 setCallee(function);
127 }
128
129 // Read a register from the codeframe (or constant from the CodeBlock).
130 inline Register& r(int);
131
132 static CallFrame* noCaller() { return reinterpret_cast<CallFrame*>(HostCallFrameFlag); }
133 int returnValueRegister() const { return this[RegisterFile::ReturnValueRegister].i(); }
134
135 bool hasHostCallFrameFlag() const { return reinterpret_cast<intptr_t>(this) & HostCallFrameFlag; }
136 CallFrame* addHostCallFrameFlag() const { return reinterpret_cast<CallFrame*>(reinterpret_cast<intptr_t>(this) | HostCallFrameFlag); }
137 CallFrame* removeHostCallFrameFlag() { return reinterpret_cast<CallFrame*>(reinterpret_cast<intptr_t>(this) & ~HostCallFrameFlag); }
138
139 private:
140 void setArgumentCount(int count) { static_cast<Register*>(this)[RegisterFile::ArgumentCount] = Register::withInt(count); }
141 void setCallee(JSFunction* callee) { static_cast<Register*>(this)[RegisterFile::Callee] = callee; }
142 void setCodeBlock(CodeBlock* codeBlock) { static_cast<Register*>(this)[RegisterFile::CodeBlock] = codeBlock; }
143
144 static const intptr_t HostCallFrameFlag = 1;
145
146 ExecState();
147 ~ExecState();
148 };
149
150} // namespace JSC
151
152#endif // CallFrame_h
Note: See TracBrowser for help on using the repository browser.