ic.h revision a7e24c173cf37484693b9abb38e494fa7bd7baeb
1a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Copyright 2006-2009 the V8 project authors. All rights reserved. 2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Redistribution and use in source and binary forms, with or without 3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// modification, are permitted provided that the following conditions are 4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// met: 5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Redistributions of source code must retain the above copyright 7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// notice, this list of conditions and the following disclaimer. 8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Redistributions in binary form must reproduce the above 9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// copyright notice, this list of conditions and the following 10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// disclaimer in the documentation and/or other materials provided 11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// with the distribution. 12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Neither the name of Google Inc. nor the names of its 13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// contributors may be used to endorse or promote products derived 14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// from this software without specific prior written permission. 15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_IC_H_ 29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8_IC_H_ 30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include "assembler.h" 32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace v8 { 34a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal { 35a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 36a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// IC_UTIL_LIST defines all utility functions called from generated 37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// inline caching code. The argument for the macro, ICU, is the function name. 38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define IC_UTIL_LIST(ICU) \ 39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(LoadIC_Miss) \ 40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(KeyedLoadIC_Miss) \ 41a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(CallIC_Miss) \ 42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(StoreIC_Miss) \ 43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(SharedStoreIC_ExtendStorage) \ 44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(KeyedStoreIC_Miss) \ 45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /* Utilities for IC stubs. */ \ 46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(LoadCallbackProperty) \ 47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(StoreCallbackProperty) \ 48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(LoadPropertyWithInterceptorOnly) \ 49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(LoadPropertyWithInterceptorForLoad) \ 50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(LoadPropertyWithInterceptorForCall) \ 51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ICU(StoreInterceptorProperty) 52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// IC is the base class for LoadIC, StoreIC, CallIC, KeyedLoadIC, 55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// and KeyedStoreIC. 56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass IC { 58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // The ids for utility called from the generated code. 61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block enum UtilityId { 62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block #define CONST_NAME(name) k##name, 63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IC_UTIL_LIST(CONST_NAME) 64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block #undef CONST_NAME 65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block kUtilityCount 66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block }; 67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Looks up the address of the named utility. 69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Address AddressFromUtilityId(UtilityId id); 70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Alias the inline cache state type to make the IC code more readable. 72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block typedef InlineCacheState State; 73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // The IC code is either invoked with no extra frames on the stack 75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // or with a single extra frame for supporting calls. 76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block enum FrameDepth { 77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block NO_EXTRA_FRAME = 0, 78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block EXTRA_CALL_FRAME = 1 79a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block }; 80a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Construct the IC structure with the given number of extra 82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // JavaScript frames on the stack. 83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block explicit IC(FrameDepth depth); 84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Get the call-site target; used for determining the state. 86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Code* target() { return GetTargetAtAddress(address()); } 87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Address address(); 88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Compute the current IC state based on the target stub and the receiver. 90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static State StateFrom(Code* target, Object* receiver); 91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Clear the inline cache to initial state. 93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void Clear(Address address); 94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Computes the reloc info for this IC. This is a fairly expensive 96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // operation as it has to search through the heap to find the code 97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // object that contains this IC site. 98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block RelocInfo::Mode ComputeMode(); 99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Returns if this IC is for contextual (no explicit receiver) 101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // access to properties. 102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool is_contextual() { 103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return ComputeMode() == RelocInfo::CODE_TARGET_CONTEXT; 104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Returns the map to use for caching stubs for a given object. 107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // This method should not be called with undefined or null. 108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline Map* GetCodeCacheMapForObject(Object* object); 109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block protected: 111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Address fp() const { return fp_; } 112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Address pc() const { return *pc_address_; } 113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef ENABLE_DEBUGGER_SUPPORT 115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Computes the address in the original code when the code running is 116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // containing break points (calls to DebugBreakXXX builtins). 117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Address OriginalCodeAddress(); 118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Set the call-site target. 121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void set_target(Code* code) { SetTargetAtAddress(address(), code); } 122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG 124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void TraceIC(const char* type, 125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<String> name, 126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block State old_state, 127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Code* new_target, 128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char* extra_info = ""); 129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Failure* TypeError(const char* type, 132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> object, 133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<String> name); 134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Failure* ReferenceError(const char* type, Handle<String> name); 135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Access the target code for the given IC address. 137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline Code* GetTargetAtAddress(Address address); 138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline void SetTargetAtAddress(Address address, Code* target); 139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Frame pointer for the frame that uses (calls) the IC. 142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Address fp_; 143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // All access to the program counter of an IC structure is indirect 145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // to make the code GC safe. This feature is crucial since 146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // GetProperty and SetProperty are called and they in turn might 147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // invoke the garbage collector. 148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Address* pc_address_; 149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block DISALLOW_IMPLICIT_CONSTRUCTORS(IC); 151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// An IC_Utility encapsulates IC::UtilityId. It exists mainly because you 155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// cannot make forward declarations to an enum. 156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass IC_Utility { 157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block explicit IC_Utility(IC::UtilityId id) 159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block : address_(IC::AddressFromUtilityId(id)), id_(id) {} 160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Address address() const { return address_; } 162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IC::UtilityId id() const { return id_; } 164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Address address_; 166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IC::UtilityId id_; 167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass CallIC: public IC { 171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block CallIC() : IC(EXTRA_CALL_FRAME) { ASSERT(target()->is_call_stub()); } 173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Object* LoadFunction(State state, Handle<Object> object, Handle<String> name); 175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Code generator routines. 178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateInitialize(MacroAssembler* masm, int argc); 179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateMiss(MacroAssembler* masm, int argc); 180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateMegamorphic(MacroAssembler* masm, int argc); 181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateNormal(MacroAssembler* masm, int argc); 182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void Generate(MacroAssembler* masm, 185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int argc, 186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const ExternalReference& f); 187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Update the inline cache and the global stub cache based on the 189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // lookup result. 190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void UpdateCaches(LookupResult* lookup, 191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block State state, 192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> object, 193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<String> name); 194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Returns a JSFunction if the object can be called as a function, 196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // and patches the stack to be ready for the call. 197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Otherwise, it returns the undefined value. 198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Object* TryCallAsFunction(Object* object); 199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void Clear(Address address, Code* target); 201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class IC; 202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass LoadIC: public IC { 206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block LoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_load_stub()); } 208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Object* Load(State state, Handle<Object> object, Handle<String> name); 210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Code generator routines. 212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateInitialize(MacroAssembler* masm); 213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GeneratePreMonomorphic(MacroAssembler* masm); 214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateMiss(MacroAssembler* masm); 215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateMegamorphic(MacroAssembler* masm); 216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateNormal(MacroAssembler* masm); 217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Specialized code generator routines. 219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateArrayLength(MacroAssembler* masm); 220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateStringLength(MacroAssembler* masm); 221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateFunctionPrototype(MacroAssembler* masm); 222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // The offset from the inlined patch site to the start of the 224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // inlined load instruction. It is architecture-dependent, and not 225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // used on ARM. 226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static const int kOffsetToLoadInstruction; 227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void Generate(MacroAssembler* masm, const ExternalReference& f); 230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Update the inline cache and the global stub cache based on the 232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // lookup result. 233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void UpdateCaches(LookupResult* lookup, 234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block State state, 235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> object, 236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<String> name); 237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Stub accessors. 239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* megamorphic_stub() { 240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::LoadIC_Megamorphic); 241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* initialize_stub() { 243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::LoadIC_Initialize); 244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* pre_monomorphic_stub() { 246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::LoadIC_PreMonomorphic); 247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void Clear(Address address, Code* target); 250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Clear the use of the inlined version. 252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void ClearInlinedVersion(Address address); 253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool PatchInlinedLoad(Address address, Object* map, int index); 255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class IC; 257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass KeyedLoadIC: public IC { 261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block KeyedLoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_keyed_load_stub()); } 263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Object* Load(State state, Handle<Object> object, Handle<Object> key); 265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Code generator routines. 267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateMiss(MacroAssembler* masm); 268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateInitialize(MacroAssembler* masm); 269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GeneratePreMonomorphic(MacroAssembler* masm); 270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateGeneric(MacroAssembler* masm); 271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Clear the use of the inlined version. 273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void ClearInlinedVersion(Address address); 274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void Generate(MacroAssembler* masm, const ExternalReference& f); 277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Update the inline cache. 279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void UpdateCaches(LookupResult* lookup, 280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block State state, 281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> object, 282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<String> name); 283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Stub accessors. 285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* initialize_stub() { 286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::KeyedLoadIC_Initialize); 287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* megamorphic_stub() { 289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::KeyedLoadIC_Generic); 290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* generic_stub() { 292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::KeyedLoadIC_Generic); 293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* pre_monomorphic_stub() { 295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::KeyedLoadIC_PreMonomorphic); 296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void Clear(Address address, Code* target); 299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Support for patching the map that is checked in an inlined 301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // version of keyed load. 302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool PatchInlinedLoad(Address address, Object* map); 303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class IC; 305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass StoreIC: public IC { 309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block StoreIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_store_stub()); } 311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Object* Store(State state, 313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> object, 314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<String> name, 315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> value); 316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Code generators for stub routines. Only called once at startup. 318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateInitialize(MacroAssembler* masm); 319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateMiss(MacroAssembler* masm); 320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateMegamorphic(MacroAssembler* masm); 321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateExtendStorage(MacroAssembler* masm); 322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void Generate(MacroAssembler* masm, const ExternalReference& f); 325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Update the inline cache and the global stub cache based on the 327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // lookup result. 328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void UpdateCaches(LookupResult* lookup, 329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block State state, Handle<JSObject> receiver, 330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<String> name, 331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> value); 332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Stub accessors. 334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* megamorphic_stub() { 335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::StoreIC_Megamorphic); 336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* initialize_stub() { 338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::StoreIC_Initialize); 339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void Clear(Address address, Code* target); 342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class IC; 343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass KeyedStoreIC: public IC { 347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block KeyedStoreIC() : IC(NO_EXTRA_FRAME) { } 349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Object* Store(State state, 351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> object, 352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> name, 353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> value); 354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Code generators for stub routines. Only called once at startup. 356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateInitialize(MacroAssembler* masm); 357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateMiss(MacroAssembler* masm); 358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateGeneric(MacroAssembler* masm); 359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void GenerateExtendStorage(MacroAssembler* masm); 360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Clear the inlined version so the IC is always hit. 362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void ClearInlinedVersion(Address address); 363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Restore the inlined version so the fast case can get hit. 365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void RestoreInlinedVersion(Address address); 366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void Generate(MacroAssembler* masm, const ExternalReference& f); 369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Update the inline cache. 371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void UpdateCaches(LookupResult* lookup, 372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block State state, 373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<JSObject> receiver, 374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<String> name, 375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Object> value); 376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Stub accessors. 378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* initialize_stub() { 379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::KeyedStoreIC_Initialize); 380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* megamorphic_stub() { 382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::KeyedStoreIC_Generic); 383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Code* generic_stub() { 385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Builtins::builtin(Builtins::KeyedStoreIC_Generic); 386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void Clear(Address address, Code* target); 389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Support for patching the map that is checked in an inlined 391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // version of keyed store. 392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // The address is the patch point for the IC call 393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // (Assembler::kCallTargetAddressOffset before the end of 394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // the call/return address). 395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // The map is the new map that the inlined code should check against. 396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool PatchInlinedStore(Address address, Object* map); 397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class IC; 399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} } // namespace v8::internal 403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif // V8_IC_H_ 405