FindIC(Handle name, Handle stub_holder_map, Code::Kind kind, ExtraICState extra_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle FindHandler(Handle name, Handle map, Code::Kind kind, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle ComputeMonomorphicIC(Handle name, Handle type, Handle handler, ExtraICState extra_ic_state); Handle ComputeLoadNonexistent(Handle name, Handle type); Handle ComputeKeyedLoadElement(Handle receiver_map); Handle ComputeKeyedStoreElement(Handle receiver_map, StrictModeFlag strict_mode, KeyedAccessStoreMode store_mode); Handle ComputeCallField(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, PropertyIndex index); Handle ComputeCallConstant(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
FindHandler(Handle name, Handle map, Code::Kind kind, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle ComputeMonomorphicIC(Handle name, Handle type, Handle handler, ExtraICState extra_ic_state); Handle ComputeLoadNonexistent(Handle name, Handle type); Handle ComputeKeyedLoadElement(Handle receiver_map); Handle ComputeKeyedStoreElement(Handle receiver_map, StrictModeFlag strict_mode, KeyedAccessStoreMode store_mode); Handle ComputeCallField(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, PropertyIndex index); Handle ComputeCallConstant(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeMonomorphicIC(Handle name, Handle type, Handle handler, ExtraICState extra_ic_state); Handle ComputeLoadNonexistent(Handle name, Handle type); Handle ComputeKeyedLoadElement(Handle receiver_map); Handle ComputeKeyedStoreElement(Handle receiver_map, StrictModeFlag strict_mode, KeyedAccessStoreMode store_mode); Handle ComputeCallField(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, PropertyIndex index); Handle ComputeCallConstant(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
handler, ExtraICState extra_ic_state); Handle ComputeLoadNonexistent(Handle name, Handle type); Handle ComputeKeyedLoadElement(Handle receiver_map); Handle ComputeKeyedStoreElement(Handle receiver_map, StrictModeFlag strict_mode, KeyedAccessStoreMode store_mode); Handle ComputeCallField(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, PropertyIndex index); Handle ComputeCallConstant(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeLoadNonexistent(Handle name, Handle type); Handle ComputeKeyedLoadElement(Handle receiver_map); Handle ComputeKeyedStoreElement(Handle receiver_map, StrictModeFlag strict_mode, KeyedAccessStoreMode store_mode); Handle ComputeCallField(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, PropertyIndex index); Handle ComputeCallConstant(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeKeyedLoadElement(Handle receiver_map); Handle ComputeKeyedStoreElement(Handle receiver_map, StrictModeFlag strict_mode, KeyedAccessStoreMode store_mode); Handle ComputeCallField(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, PropertyIndex index); Handle ComputeCallConstant(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeKeyedStoreElement(Handle receiver_map, StrictModeFlag strict_mode, KeyedAccessStoreMode store_mode); Handle ComputeCallField(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, PropertyIndex index); Handle ComputeCallConstant(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallField(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, PropertyIndex index); Handle ComputeCallConstant(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallConstant(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallInterceptor(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallGlobal(int argc, Code::Kind, ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallPreMonomorphic(int argc, Code::Kind kind, ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallNormal(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallArguments(int argc); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallMegamorphic(int argc, Code::Kind kind, ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallMiss(int argc, Code::Kind kind, ExtraICState state); // --- Handle ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCompareNil(Handle receiver_map, CompareNilICStub& stub); // --- Handle ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeLoadElementPolymorphic(MapHandleList* receiver_maps); Handle ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeStoreElementPolymorphic(MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode, StrictModeFlag strict_mode); Handle ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, int number_of_valid_maps, Handle name, ExtraICState extra_ic_state); // Finds the Code object stored in the Heap::non_monomorphic_cache(). Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); #ifdef ENABLE_DEBUGGER_SUPPORT Handle ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(Name* name, Map* map, Code* code); // Clear the lookup table (@ mark compact collection). void Clear(); // Collect all maps that match the name and flags. void CollectMatchingMaps(SmallMapList* types, Handle name, Code::Flags flags, Handle native_context, Zone* zone); // Generate code for probing the stub cache table. // Arguments extra, extra2 and extra3 may be used to pass additional scratch // registers. Set to no_reg if not needed. void GenerateProbe(MacroAssembler* masm, Code::Flags flags, Register receiver, Register name, Register scratch, Register extra, Register extra2 = no_reg, Register extra3 = no_reg); enum Table { kPrimary, kSecondary }; SCTableReference key_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->key)); } SCTableReference map_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->map)); } SCTableReference value_reference(StubCache::Table table) { return SCTableReference( reinterpret_cast(&first_entry(table)->value)); } StubCache::Entry* first_entry(StubCache::Table table) { switch (table) { case StubCache::kPrimary: return StubCache::primary_; case StubCache::kSecondary: return StubCache::secondary_; } UNREACHABLE(); return NULL; } Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } // These constants describe the structure of the interceptor arguments on the // stack. The arguments are pushed by the (platform-specific) // PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and // LoadWithInterceptor. static const int kInterceptorArgsNameIndex = 0; static const int kInterceptorArgsInfoIndex = 1; static const int kInterceptorArgsThisIndex = 2; static const int kInterceptorArgsHolderIndex = 3; static const int kInterceptorArgsLength = 4; private: explicit StubCache(Isolate* isolate); Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
ComputeCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); // The stub cache has a primary and secondary level. The two levels have // different hashing algorithms in order to avoid simultaneous collisions // in both caches. Unlike a probing strategy (quadratic or otherwise) the // update strategy on updates is fairly clear and simple: Any existing entry // in the primary cache is moved to the secondary cache, and secondary cache // entries are overwritten. // Hash algorithm for the primary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) { // This works well because the heap object tag size and the hash // shift are equal. Shifting down the length field to get the // hash code would effectively throw away two bits of the hash // code. STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift); // Compute the hash of the name (use entire hash field). ASSERT(name->HasHashCode()); uint32_t field = name->hash_field(); // Using only the low bits in 64-bit mode is unlikely to increase the // risk of collision even if the heap is spread over an area larger than // 4Gb (and not at all if it isn't). uint32_t map_low32bits = static_cast(reinterpret_cast(map)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); // Base the offset on a simple combination of name, flags, and map. uint32_t key = (map_low32bits + field) ^ iflags; return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize); } // Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that // is scaled by 1 << kHeapObjectTagSize. static int SecondaryOffset(Name* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t name_low32bits = static_cast(reinterpret_cast(name)); // We always set the in_loop bit to zero when generating the lookup code // so do it here too so the hash codes match. uint32_t iflags = (static_cast(flags) & ~Code::kFlagsNotUsedInLookup); uint32_t key = (seed - name_low32bits) + iflags; return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize); } // Compute the entry for a given offset in exactly the same way as // we do in generated code. We generate an hash code that already // ends in Name::kHashShift 0s. Then we multiply it so it is a multiple // of sizeof(Entry). This makes it easier to avoid making mistakes // in the hashed offset computations. static Entry* entry(Entry* table, int offset) { const int multiplier = sizeof(*table) >> Name::kHashShift; return reinterpret_cast( reinterpret_cast(table) + offset * multiplier); } static const int kPrimaryTableBits = 11; static const int kPrimaryTableSize = (1 << kPrimaryTableBits); static const int kSecondaryTableBits = 9; static const int kSecondaryTableSize = (1 << kSecondaryTableBits); Entry primary_[kPrimaryTableSize]; Entry secondary_[kSecondaryTableSize]; Isolate* isolate_; friend class Isolate; friend class SCTableReference; DISALLOW_COPY_AND_ASSIGN(StubCache); }; // ------------------------------------------------------------------------ // Support functions for IC stubs for callbacks. DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreCallbackProperty); // Support functions for IC stubs for interceptors. DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorOnly); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad); DECLARE_RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall); DECLARE_RUNTIME_FUNCTION(MaybeObject*, StoreInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, CallInterceptorProperty); DECLARE_RUNTIME_FUNCTION(MaybeObject*, KeyedLoadPropertyWithInterceptor); enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER }; enum IcCheckType { ELEMENT, PROPERTY }; // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState) : isolate_(isolate), extra_ic_state_(extra_ic_state), masm_(isolate, NULL, 256), failure_(NULL) { } // Functions to compile either CallIC or KeyedCallIC. The specific kind // is extracted from the code flags. Handle CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallInitialize(Code::Flags flags); Handle CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallPreMonomorphic(Code::Flags flags); Handle CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallNormal(Code::Flags flags); Handle CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallMegamorphic(Code::Flags flags); Handle CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallArguments(Code::Flags flags); Handle CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallMiss(Code::Flags flags); #ifdef ENABLE_DEBUGGER_SUPPORT Handle CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallDebugBreak(Code::Flags flags); Handle CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // Helper function used to check that the dictionary doesn't contain // the property. This function may return false negatives, so miss_label // must always call a backup property check that is complete. // This function is safe to call if the receiver has fast properties. // Name must be unique and receiver must be a heap object. static void GenerateDictionaryNegativeLookup(MacroAssembler* masm, Label* miss_label, Register receiver, Handle name, Register r0, Register r1); // Generates prototype loading code that uses the objects from the // context we were in when this function was called. If the context // has changed, a jump to miss is performed. This ties the generated // code to a particular context and so must not be used in cases // where the generated code is not allowed to have references to // objects from a context. static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype, Label* miss); static void GenerateFastPropertyLoad(MacroAssembler* masm, Register dst, Register src, bool inobject, int index, Representation representation); static void GenerateLoadArrayLength(MacroAssembler* masm, Register receiver, Register scratch, Label* miss_label); static void GenerateLoadStringLength(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); // Generate code to check that a global property cell is empty. Create // the property cell at compilation time if no cell exists for the // property. static void GenerateCheckPropertyCell(MacroAssembler* masm, Handle global, Handle name, Register scratch, Label* miss); static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name); // Generates code that verifies that the property holder has not changed // (checking maps of objects in the prototype chain for fast and global // objects or doing negative lookup for slow objects, ensures that the // property cells for global objects are still empty) and checks that the map // of the holder has not changed. If necessary the function also generates // code for security check in case of global object holders. Helps to make // sure that the current IC is still valid. // // The scratch and holder registers are always clobbered, but the object // register is only clobbered if it the same as the holder register. The // function returns a register containing the holder - either object_reg or // holder_reg. // The function can optionally (when save_at_depth != // kInvalidProtoDepth) save the object at the given depth by moving // it to [esp + kPointerSize]. Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS) { return CheckPrototypes(type, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss, check); } Register CheckPrototypes(Handle type, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss, PrototypeCheckType check = CHECK_ALL_MAPS); void GenerateBooleanCheck(Register object, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
GetCodeWithFlags(Code::Flags flags, Handle name); ExtraICState extra_state() { return extra_ic_state_; } MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } static void GenerateTailCall(MacroAssembler* masm, Handle code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
code); private: Isolate* isolate_; const ExtraICState extra_ic_state_; MacroAssembler masm_; Failure* failure_; }; enum FrontendCheckType { PERFORM_INITIAL_CHECKS, SKIP_INITIAL_CHECKS }; class BaseLoadStoreStubCompiler: public StubCompiler { public: BaseLoadStoreStubCompiler(Isolate* isolate, Code::Kind kind, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : StubCompiler(isolate, extra_ic_state), kind_(kind), cache_holder_(cache_holder) { InitializeRegisters(); } virtual ~BaseLoadStoreStubCompiler() { } Handle CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileMonomorphicIC(Handle type, Handle handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
handler, Handle name); Handle CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompilePolymorphicIC(TypeHandleList* types, CodeHandleList* handlers, Handle name, Code::StubType type, IcCheckType check); virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss) { } static Builtins::Name MissBuiltin(Code::Kind kind) { switch (kind) { case Code::LOAD_IC: return Builtins::kLoadIC_Miss; case Code::STORE_IC: return Builtins::kStoreIC_Miss; case Code::KEYED_LOAD_IC: return Builtins::kKeyedLoadIC_Miss; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Miss; default: UNREACHABLE(); } return Builtins::kLoadIC_Miss; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss) = 0; virtual void HandlerFrontendFooter(Handle name, Label* miss) = 0; Register HandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name); Handle GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
GetCode(Code::Kind kind, Code::StubType type, Handle name); Handle GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
GetICCode(Code::Kind kind, Code::StubType type, Handle name, InlineCacheState state = MONOMORPHIC); Code::Kind kind() { return kind_; } Logger::LogEventsAndTags log_kind(Handle code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
code) { if (!code->is_inline_cache_stub()) return Logger::STUB_TAG; if (kind_ == Code::LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG : Logger::LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::KEYED_LOAD_IC) { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_LOAD_IC_TAG : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG; } else if (kind_ == Code::STORE_IC) { return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG : Logger::STORE_POLYMORPHIC_IC_TAG; } else { return code->ic_state() == MONOMORPHIC ? Logger::KEYED_STORE_IC_TAG : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG; } } void JitEvent(Handle name, Handle code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
code); virtual Register receiver() = 0; virtual Register name() = 0; virtual Register scratch1() = 0; virtual Register scratch2() = 0; virtual Register scratch3() = 0; void InitializeRegisters(); bool IncludesNumberType(TypeHandleList* types); Code::Kind kind_; InlineCacheHolderFlag cache_holder_; Register* registers_; }; class LoadStubCompiler: public BaseLoadStoreStubCompiler { public: LoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP, Code::Kind kind = Code::LOAD_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state, cache_holder) { } virtual ~LoadStubCompiler() { } Handle CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileLoadField(Handle type, Handle holder, Handle name, PropertyIndex index, Representation representation); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileLoadCallback(Handle type, Handle holder, Handle name, Handle callback); Handle CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileLoadCallback(Handle type, Handle holder, Handle name, const CallOptimization& call_optimization); Handle CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileLoadConstant(Handle type, Handle holder, Handle name, Handle value); Handle CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileLoadInterceptor(Handle type, Handle holder, Handle name); Handle CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileLoadViaGetter(Handle type, Handle holder, Handle name, Handle getter); static void GenerateLoadViaGetter(MacroAssembler* masm, Register receiver, Handle getter); Handle CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileLoadNonexistent(Handle type, Handle last, Handle name); Handle CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileLoadGlobal(Handle type, Handle holder, Handle cell, Handle name, bool is_dont_delete); static Register* registers(); protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); Register CallbackHandlerFrontend(Handle type, Register object_reg, Handle holder, Handle name, Handle callback); void NonexistentHandlerFrontend(Handle type, Handle last, Handle name); void GenerateLoadField(Register reg, Handle holder, PropertyIndex field, Representation representation); void GenerateLoadConstant(Handle value); void GenerateLoadCallback(Register reg, Handle callback); void GenerateLoadCallback(const CallOptimization& call_optimization); void GenerateLoadInterceptor(Register holder_reg, Handle object, Handle holder, LookupResult* lookup, Handle name); void GenerateLoadPostInterceptor(Register reg, Handle interceptor_holder, Handle name, LookupResult* lookup); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } virtual Register scratch1() { return registers_[2]; } virtual Register scratch2() { return registers_[3]; } virtual Register scratch3() { return registers_[4]; } Register scratch4() { return registers_[5]; } }; class KeyedLoadStubCompiler: public LoadStubCompiler { public: KeyedLoadStubCompiler(Isolate* isolate, ExtraICState extra_ic_state = kNoExtraICState, InlineCacheHolderFlag cache_holder = OWN_MAP) : LoadStubCompiler(isolate, extra_ic_state, cache_holder, Code::KEYED_LOAD_IC) { } Handle CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileLoadElement(Handle receiver_map); void CompileElementHandlers(MapHandleList* receiver_maps, CodeHandleList* handlers); static void GenerateLoadDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); private: virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; class StoreStubCompiler: public BaseLoadStoreStubCompiler { public: StoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state, Code::Kind kind = Code::STORE_IC) : BaseLoadStoreStubCompiler(isolate, kind, extra_ic_state) {} virtual ~StoreStubCompiler() { } Handle CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileStoreTransition(Handle object, LookupResult* lookup, Handle transition, Handle name); Handle CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileStoreField(Handle object, LookupResult* lookup, Handle name); void GenerateNegativeHolderLookup(MacroAssembler* masm, Handle holder, Register holder_reg, Handle name, Label* miss); void GenerateStoreTransition(MacroAssembler* masm, Handle object, LookupResult* lookup, Handle transition, Handle name, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Register scratch3, Label* miss_label, Label* slow); void GenerateStoreField(MacroAssembler* masm, Handle object, LookupResult* lookup, Register receiver_reg, Register name_reg, Register value_reg, Register scratch1, Register scratch2, Label* miss_label); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileStoreCallback(Handle object, Handle holder, Handle name, Handle callback); Handle CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileStoreCallback(Handle object, Handle holder, Handle name, const CallOptimization& call_optimization); static void GenerateStoreViaSetter(MacroAssembler* masm, Handle setter); Handle CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileStoreViaSetter(Handle object, Handle holder, Handle name, Handle setter); Handle CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileStoreInterceptor(Handle object, Handle name); static Builtins::Name SlowBuiltin(Code::Kind kind) { switch (kind) { case Code::STORE_IC: return Builtins::kStoreIC_Slow; case Code::KEYED_STORE_IC: return Builtins::kKeyedStoreIC_Slow; default: UNREACHABLE(); } return Builtins::kStoreIC_Slow; } protected: virtual Register HandlerFrontendHeader(Handle type, Register object_reg, Handle holder, Handle name, Label* miss); virtual void HandlerFrontendFooter(Handle name, Label* miss); void GenerateRestoreName(MacroAssembler* masm, Label* label, Handle name); virtual Register receiver() { return registers_[0]; } virtual Register name() { return registers_[1]; } Register value() { return registers_[2]; } virtual Register scratch1() { return registers_[3]; } virtual Register scratch2() { return registers_[4]; } virtual Register scratch3() { return registers_[5]; } protected: static Register* registers(); private: friend class BaseLoadStoreStubCompiler; }; class KeyedStoreStubCompiler: public StoreStubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, ExtraICState extra_ic_state) : StoreStubCompiler(isolate, extra_ic_state, Code::KEYED_STORE_IC) {} Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); Handle CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileStoreElementPolymorphic(MapHandleList* receiver_maps); static void GenerateStoreDictionaryElement(MacroAssembler* masm); protected: static Register* registers(); KeyedAccessStoreMode store_mode() { return KeyedStoreIC::GetKeyedAccessStoreMode(extra_state()); } private: Register transition_map() { return registers()[3]; } virtual void GenerateNameCheck(Handle name, Register name_reg, Label* miss); friend class BaseLoadStoreStubCompiler; }; // Subset of FUNCTIONS_WITH_ID_LIST with custom constant/global call // IC stubs. #define CUSTOM_CALL_IC_GENERATORS(V) \ V(ArrayPush) \ V(ArrayPop) \ V(StringCharCodeAt) \ V(StringCharAt) \ V(StringFromCharCode) \ V(MathFloor) \ V(MathAbs) \ V(ArrayCode) #define SITE_SPECIFIC_CALL_GENERATORS(V) \ V(ArrayCode) class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, ExtraICState extra_state, InlineCacheHolderFlag cache_holder = OWN_MAP); Handle CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallField(Handle object, Handle holder, PropertyIndex index, Handle name); // Patch the global proxy over the global object if the global object is the // receiver. void PatchGlobalProxy(Handle object); // Returns the register containing the holder of |name|. Register HandlerFrontendHeader(Handle object, Handle holder, Handle name, CheckType check, Label* miss); void HandlerFrontendFooter(Label* miss); void GenerateJumpFunctionIgnoreReceiver(Handle function); void GenerateJumpFunction(Handle object, Handle function); void GenerateJumpFunction(Handle object, Register function, Label* miss); // Use to call |actual_closure|, a closure with the same shared function info // as |function|. void GenerateJumpFunction(Handle object, Register actual_closure, Handle function); Handle CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallConstant(Handle object, Handle holder, Handle name, CheckType check, Handle function); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCallGlobal(Handle object, Handle holder, Handle cell, Handle function, Handle name); static bool HasCustomCallGenerator(Handle function); static bool CanBeCached(Handle function); private: // Compiles a custom call constant/global IC. For constant calls cell is // NULL. Returns an empty handle if there is no custom call code for the // given function. Handle CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
CompileCustomCall(Handle object, Handle holder, Handle cell, Handle function, Handle name, Code::StubType type); #define DECLARE_CALL_GENERATOR(name) \ Handle Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle
Compile##name##Call(Handle object, \ Handle holder, \ Handle cell, \ Handle