source: webkit/trunk/JavaScriptCore/runtime/JSStaticScopeObject.cpp@ 58986

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

2010-05-07 Oliver Hunt <[email protected]>

Reviewed by Geoffrey Garen.

Optimize access to the global object from a function that uses eval
https://bugs.webkit.org/show_bug.cgi?id=38644

Add op_resolve_global_dynamic, a variant of op_resolve_global that
checks each node in the scope chain for dynamically inserted properties
and falls back to the normal resolve logic in that case.

  • JavaScriptCore.exp:
  • bytecode/CodeBlock.cpp: (JSC::isGlobalResolve): (JSC::CodeBlock::printStructures): (JSC::CodeBlock::dump): (JSC::CodeBlock::derefStructures):
  • bytecode/Opcode.h:
  • bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::findScopedProperty):

Now take an additional reference parameter to used to indicate that
there were nodes that may gain dynamic properties

(JSC::BytecodeGenerator::emitResolve):
(JSC::BytecodeGenerator::emitResolveBase):
(JSC::BytecodeGenerator::emitResolveWithBase):

deal with additional argument to findScopedProperty

  • bytecompiler/BytecodeGenerator.h:
  • bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallResolveNode::emitBytecode): (JSC::PostfixResolveNode::emitBytecode): (JSC::PrefixResolveNode::emitBytecode): (JSC::ReadModifyResolveNode::emitBytecode): (JSC::AssignResolveNode::emitBytecode):

These functions use findScopedProperty directly in order to
optimise lookup. They cannot trivially handle any degree of
dynamism in the lookup so we just give up in such case.

  • interpreter/Interpreter.cpp: (JSC::Interpreter::resolveGlobalDynamic): (JSC::Interpreter::execute): (JSC::Interpreter::privateExecute):
  • interpreter/Interpreter.h:
  • jit/JIT.cpp: (JSC::JIT::privateCompileMainPass): (JSC::JIT::privateCompileSlowCases):
  • jit/JIT.h:
  • jit/JITOpcodes.cpp: (JSC::JIT::emit_op_resolve_global): (JSC::JIT::emit_op_resolve_global_dynamic): (JSC::JIT::emitSlow_op_resolve_global): (JSC::JIT::emitSlow_op_resolve_global_dynamic):

Happily resolve_global_dynamic can share the slow case!

  • jit/JITStubs.h: (JSC::):
  • runtime/JSActivation.cpp: (JSC::JSActivation::isDynamicScope):
  • runtime/JSActivation.h:
  • runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::isDynamicScope):
  • runtime/JSGlobalObject.h:
  • runtime/JSStaticScopeObject.cpp: (JSC::JSStaticScopeObject::isDynamicScope):
  • runtime/JSStaticScopeObject.h:
  • runtime/JSVariableObject.h:
File size: 2.5 KB
Line 
1/*
2 * Copyright (C) 2008, 2009 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
28#include "JSStaticScopeObject.h"
29
30namespace JSC {
31
32ASSERT_CLASS_FITS_IN_CELL(JSStaticScopeObject);
33
34void JSStaticScopeObject::markChildren(MarkStack& markStack)
35{
36 JSVariableObject::markChildren(markStack);
37 markStack.append(d()->registerStore.jsValue());
38}
39
40JSObject* JSStaticScopeObject::toThisObject(ExecState* exec) const
41{
42 return exec->globalThisValue();
43}
44
45void JSStaticScopeObject::put(ExecState*, const Identifier& propertyName, JSValue value, PutPropertySlot&)
46{
47 if (symbolTablePut(propertyName, value))
48 return;
49
50 ASSERT_NOT_REACHED();
51}
52
53void JSStaticScopeObject::putWithAttributes(ExecState*, const Identifier& propertyName, JSValue value, unsigned attributes)
54{
55 if (symbolTablePutWithAttributes(propertyName, value, attributes))
56 return;
57
58 ASSERT_NOT_REACHED();
59}
60
61bool JSStaticScopeObject::isDynamicScope(bool&) const
62{
63 return false;
64}
65
66JSStaticScopeObject::~JSStaticScopeObject()
67{
68 ASSERT(d());
69 delete d();
70}
71
72inline bool JSStaticScopeObject::getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot& slot)
73{
74 return symbolTableGet(propertyName, slot);
75}
76
77}
Note: See TracBrowser for help on using the repository browser.