ComputeLoadNonexistent(Handle name, Handle receiver); Handle ComputeLoadField(Handle name, Handle receiver, Handle holder, int field_index); Handle ComputeLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeLoadNormal(); Handle ComputeLoadGlobal(Handle name, Handle receiver, Handle holder, Handle cell, bool is_dont_delete); // --- Handle ComputeKeyedLoadField(Handle name, Handle receiver, Handle holder, int field_index); Handle ComputeKeyedLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeKeyedLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeKeyedLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeLoadField(Handle name, Handle receiver, Handle holder, int field_index); Handle ComputeLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeLoadNormal(); Handle ComputeLoadGlobal(Handle name, Handle receiver, Handle holder, Handle cell, bool is_dont_delete); // --- Handle ComputeKeyedLoadField(Handle name, Handle receiver, Handle holder, int field_index); Handle ComputeKeyedLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeKeyedLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeKeyedLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeLoadNormal(); Handle ComputeLoadGlobal(Handle name, Handle receiver, Handle holder, Handle cell, bool is_dont_delete); // --- Handle ComputeKeyedLoadField(Handle name, Handle receiver, Handle holder, int field_index); Handle ComputeKeyedLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeKeyedLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeKeyedLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeLoadNormal(); Handle ComputeLoadGlobal(Handle name, Handle receiver, Handle holder, Handle cell, bool is_dont_delete); // --- Handle ComputeKeyedLoadField(Handle name, Handle receiver, Handle holder, int field_index); Handle ComputeKeyedLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeKeyedLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeKeyedLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeLoadNormal(); Handle ComputeLoadGlobal(Handle name, Handle receiver, Handle holder, Handle cell, bool is_dont_delete); // --- Handle ComputeKeyedLoadField(Handle name, Handle receiver, Handle holder, int field_index); Handle ComputeKeyedLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeKeyedLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeKeyedLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeLoadNormal(); Handle ComputeLoadGlobal(Handle name, Handle receiver, Handle holder, Handle cell, bool is_dont_delete); // --- Handle ComputeKeyedLoadField(Handle name, Handle receiver, Handle holder, int field_index); Handle ComputeKeyedLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeKeyedLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeKeyedLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeLoadGlobal(Handle name, Handle receiver, Handle holder, Handle cell, bool is_dont_delete); // --- Handle ComputeKeyedLoadField(Handle name, Handle receiver, Handle holder, int field_index); Handle ComputeKeyedLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeKeyedLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeKeyedLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeKeyedLoadField(Handle name, Handle receiver, Handle holder, int field_index); Handle ComputeKeyedLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeKeyedLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeKeyedLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeKeyedLoadCallback(Handle name, Handle receiver, Handle holder, Handle callback); Handle ComputeKeyedLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeKeyedLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeKeyedLoadConstant(Handle name, Handle receiver, Handle holder, Handle value); Handle ComputeKeyedLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeKeyedLoadInterceptor(Handle name, Handle receiver, Handle holder); Handle ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeKeyedLoadArrayLength(Handle name, Handle receiver); Handle ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeKeyedLoadStringLength(Handle name, Handle receiver); Handle ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeKeyedLoadFunctionPrototype(Handle name, Handle receiver); // --- Handle ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeStoreNormal(StrictModeFlag strict_mode); Handle ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeStoreGlobal(Handle name, Handle receiver, Handle cell, StrictModeFlag strict_mode); Handle ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeStoreCallback(Handle name, Handle receiver, Handle callback, StrictModeFlag strict_mode); Handle ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeStoreInterceptor(Handle name, Handle receiver, StrictModeFlag strict_mode); // --- Handle ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeKeyedStoreField(Handle name, Handle receiver, int field_index, Handle transition, StrictModeFlag strict_mode); Handle ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeKeyedLoadOrStoreElement(Handle receiver, KeyedIC::StubKind stub_kind, StrictModeFlag strict_mode); // --- Handle ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallField(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, int index); Handle ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallConstant(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder, Handle function); Handle ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallInterceptor(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle object, Handle holder); Handle ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallGlobal(int argc, Code::Kind, Code::ExtraICState extra_state, Handle name, Handle receiver, Handle holder, Handle cell, Handle function); // --- Handle ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallInitialize(int argc, RelocInfo::Mode mode); Handle ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeKeyedCallInitialize(int argc); Handle ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallPreMonomorphic(int argc, Code::Kind kind, Code::ExtraICState extra_state); Handle ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallNormal(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallArguments(int argc, Code::Kind kind); Handle ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallMegamorphic(int argc, Code::Kind kind, Code::ExtraICState state); Handle ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallMiss(int argc, Code::Kind kind, Code::ExtraICState 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(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallDebugBreak(int argc, Code::Kind kind); Handle ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
ComputeCallDebugPrepareStepIn(int argc, Code::Kind kind); #endif // Update cache for entry hash(name, map). Code* Set(String* 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, String* name, Code::Flags flags, Handle global_context); // 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(); } 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, 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(String* 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 == String::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(String* name, Code::Flags flags, int seed) { // Use the seed from the primary cache in the secondary cache. uint32_t string_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 - string_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 String::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) >> String::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*, LoadCallbackProperty); 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); // The stub compilers compile stubs for the stub cache. class StubCompiler BASE_EMBEDDED { public: explicit StubCompiler(Isolate* isolate) : isolate_(isolate), 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, 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); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileCallDebugPrepareStepIn(Code::Flags flags); #endif // Static functions for generating parts of stubs. static void GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, int index, Register prototype); // 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, Handle holder, int index); 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, bool support_wrappers); static void GenerateLoadFunctionPrototype(MacroAssembler* masm, Register receiver, Register scratch1, Register scratch2, Label* miss_label); static void GenerateStoreField(MacroAssembler* masm, Handle object, int index, Handle transition, Register receiver_reg, Register name_reg, Register scratch, Label* miss_label); static void GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind); static void GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm); // 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 object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, Label* miss) { return CheckPrototypes(object, object_reg, holder, holder_reg, scratch1, scratch2, name, kInvalidProtoDepth, miss); } Register CheckPrototypes(Handle object, Register object_reg, Handle holder, Register holder_reg, Register scratch1, Register scratch2, Handle name, int save_at_depth, Label* miss); protected: Handle GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
GetCodeWithFlags(Code::Flags flags, const char* name); Handle GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
GetCodeWithFlags(Code::Flags flags, Handle name); MacroAssembler* masm() { return &masm_; } void set_failure(Failure* failure) { failure_ = failure; } void GenerateLoadField(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, int index, Handle name, Label* miss); void GenerateLoadCallback(Handle object, Handle holder, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle callback, Handle name, Label* miss); void GenerateLoadConstant(Handle object, Handle holder, Register receiver, Register scratch1, Register scratch2, Register scratch3, Handle value, Handle name, Label* miss); void GenerateLoadInterceptor(Handle object, Handle holder, LookupResult* lookup, Register receiver, Register name_reg, Register scratch1, Register scratch2, Register scratch3, Handle name, Label* miss); static void LookupPostInterceptor(Handle holder, Handle name, LookupResult* lookup); Isolate* isolate() { return isolate_; } Heap* heap() { return isolate()->heap(); } Factory* factory() { return isolate()->factory(); } private: Isolate* isolate_; MacroAssembler masm_; Failure* failure_; }; class LoadStubCompiler: public StubCompiler { public: explicit LoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadNonexistent(Handle name, Handle object, Handle last); Handle CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadField(Handle object, Handle holder, int index, Handle name); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadConstant(Handle object, Handle holder, Handle value, Handle name); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadGlobal(Handle object, Handle holder, Handle cell, Handle name, bool is_dont_delete); private: Handle GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
GetCode(PropertyType type, Handle name); }; class KeyedLoadStubCompiler: public StubCompiler { public: explicit KeyedLoadStubCompiler(Isolate* isolate) : StubCompiler(isolate) { } Handle CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadField(Handle name, Handle object, Handle holder, int index); Handle CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadCallback(Handle name, Handle object, Handle holder, Handle callback); Handle CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadConstant(Handle name, Handle object, Handle holder, Handle value); Handle CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadInterceptor(Handle object, Handle holder, Handle name); Handle CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadArrayLength(Handle name); Handle CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadStringLength(Handle name); Handle CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadFunctionPrototype(Handle name); Handle CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadElement(Handle receiver_map); Handle CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileLoadPolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_ics); static void GenerateLoadExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateLoadFastElement(MacroAssembler* masm); static void GenerateLoadFastDoubleElement(MacroAssembler* masm); static void GenerateLoadDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); }; class StoreStubCompiler: public StubCompiler { public: StoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode) : StubCompiler(isolate), strict_mode_(strict_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileStoreCallback(Handle object, Handle callback, Handle name); Handle CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileStoreInterceptor(Handle object, Handle name); Handle CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileStoreGlobal(Handle object, Handle holder, Handle name); private: Handle GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
GetCode(PropertyType type, Handle name); StrictModeFlag strict_mode_; }; class KeyedStoreStubCompiler: public StubCompiler { public: KeyedStoreStubCompiler(Isolate* isolate, StrictModeFlag strict_mode, KeyedAccessGrowMode grow_mode) : StubCompiler(isolate), strict_mode_(strict_mode), grow_mode_(grow_mode) { } Handle CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileStoreField(Handle object, int index, Handle transition, Handle name); Handle CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileStoreElement(Handle receiver_map); Handle CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileStorePolymorphic(MapHandleList* receiver_maps, CodeHandleList* handler_stubs, MapHandleList* transitioned_maps); static void GenerateStoreFastElement(MacroAssembler* masm, bool is_js_array, ElementsKind element_kind, KeyedAccessGrowMode grow_mode); static void GenerateStoreFastDoubleElement(MacroAssembler* masm, bool is_js_array, KeyedAccessGrowMode grow_mode); static void GenerateStoreExternalArray(MacroAssembler* masm, ElementsKind elements_kind); static void GenerateStoreDictionaryElement(MacroAssembler* masm); private: Handle GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
GetCode(PropertyType type, Handle name, InlineCacheState state = MONOMORPHIC); StrictModeFlag strict_mode_; KeyedAccessGrowMode grow_mode_; }; // 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) class CallOptimization; class CallStubCompiler: public StubCompiler { public: CallStubCompiler(Isolate* isolate, int argc, Code::Kind kind, Code::ExtraICState extra_state, InlineCacheHolderFlag cache_holder); Handle CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileCallField(Handle object, Handle holder, int index, Handle name); Handle CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileCallConstant(Handle object, Handle holder, Handle function, Handle name, CheckType check); Handle CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileCallInterceptor(Handle object, Handle holder, Handle name); Handle CompileCallGlobal(Handle object, Handle holder, Handle
CompileCallGlobal(Handle object, Handle holder, Handle