Reduce code duplication in IC updating.

BUG=
R=ulan@chromium.org

Review URL: https://chromiumcodereview.appspot.com/25033003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17034 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
verwaest@chromium.org 2013-10-01 09:30:07 +00:00
parent 191bcf20cc
commit 63b584474f
6 changed files with 74 additions and 242 deletions

View File

@ -996,7 +996,7 @@ bool IC::UpdatePolymorphicIC(State state,
Handle<String> name, Handle<String> name,
Handle<Code> code, Handle<Code> code,
StrictModeFlag strict_mode) { StrictModeFlag strict_mode) {
if (code->kind() != Code::HANDLER) return false; if (!code->is_handler()) return false;
MapHandleList receiver_maps; MapHandleList receiver_maps;
CodeHandleList handlers; CodeHandleList handlers;
@ -1045,72 +1045,19 @@ bool IC::UpdatePolymorphicIC(State state,
handlers.Add(code); handlers.Add(code);
} }
Handle<Code> ic = ComputePolymorphicIC( Handle<Code> ic = isolate()->stub_cache()->ComputePolymorphicIC(
&receiver_maps, &handlers, number_of_valid_maps, name, strict_mode); &receiver_maps, &handlers, number_of_valid_maps, name, strict_mode);
set_target(*ic); set_target(*ic);
return true; return true;
} }
Handle<Code> LoadIC::ComputePolymorphicIC(MapHandleList* receiver_maps, void IC::UpdateMonomorphicIC(Handle<HeapObject> receiver,
CodeHandleList* handlers, Handle<Code> handler,
int number_of_valid_maps, Handle<String> name,
Handle<Name> name, StrictModeFlag strict_mode) {
StrictModeFlag strict_mode) { if (!handler->is_handler()) return set_target(*handler);
return isolate()->stub_cache()->ComputePolymorphicLoadIC( Handle<Code> ic = isolate()->stub_cache()->ComputeMonomorphicIC(
receiver_maps, handlers, number_of_valid_maps, name);
}
Handle<Code> StoreIC::ComputePolymorphicIC(MapHandleList* receiver_maps,
CodeHandleList* handlers,
int number_of_valid_maps,
Handle<Name> name,
StrictModeFlag strict_mode) {
return isolate()->stub_cache()->ComputePolymorphicStoreIC(
receiver_maps, handlers, number_of_valid_maps, name, strict_mode);
}
void LoadIC::UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<String> name,
StrictModeFlag strict_mode) {
if (handler->is_load_stub()) return set_target(*handler);
Handle<Code> ic = isolate()->stub_cache()->ComputeMonomorphicLoadIC(
receiver, handler, name);
set_target(*ic);
}
void KeyedLoadIC::UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<String> name,
StrictModeFlag strict_mode) {
if (handler->is_keyed_load_stub()) return set_target(*handler);
Handle<Code> ic = isolate()->stub_cache()->ComputeMonomorphicKeyedLoadIC(
receiver, handler, name);
set_target(*ic);
}
void StoreIC::UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<String> name,
StrictModeFlag strict_mode) {
if (handler->is_store_stub()) return set_target(*handler);
Handle<Code> ic = isolate()->stub_cache()->ComputeMonomorphicStoreIC(
receiver, handler, name, strict_mode);
set_target(*ic);
}
void KeyedStoreIC::UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<String> name,
StrictModeFlag strict_mode) {
if (handler->is_keyed_store_stub()) return set_target(*handler);
Handle<Code> ic = isolate()->stub_cache()->ComputeMonomorphicKeyedStoreIC(
receiver, handler, name, strict_mode); receiver, handler, name, strict_mode);
set_target(*ic); set_target(*ic);
} }
@ -1188,7 +1135,6 @@ void IC::PatchCache(State state,
} }
break; break;
case MEGAMORPHIC: case MEGAMORPHIC:
// Update the stub cache.
UpdateMegamorphicCache(receiver->map(), *name, *code); UpdateMegamorphicCache(receiver->map(), *name, *code);
break; break;
case POLYMORPHIC: case POLYMORPHIC:

View File

@ -172,27 +172,17 @@ class IC {
static inline void SetTargetAtAddress(Address address, Code* target); static inline void SetTargetAtAddress(Address address, Code* target);
static void PostPatching(Address address, Code* target, Code* old_target); static void PostPatching(Address address, Code* target, Code* old_target);
virtual void UpdateMonomorphicIC(Handle<HeapObject> receiver, void UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler, Handle<Code> handler,
Handle<String> name, Handle<String> name,
StrictModeFlag strict_mode) { StrictModeFlag strict_mode);
set_target(*handler);
}
bool UpdatePolymorphicIC(State state, bool UpdatePolymorphicIC(State state,
Handle<HeapObject> receiver, Handle<HeapObject> receiver,
Handle<String> name, Handle<String> name,
Handle<Code> code, Handle<Code> code,
StrictModeFlag strict_mode); StrictModeFlag strict_mode);
virtual Handle<Code> ComputePolymorphicIC(MapHandleList* receiver_maps,
CodeHandleList* handlers,
int number_of_valid_maps,
Handle<Name> name,
StrictModeFlag strict_mode) {
UNREACHABLE();
return Handle<Code>::null();
};
void CopyICToMegamorphicCache(Handle<String> name); void CopyICToMegamorphicCache(Handle<String> name);
bool IsTransitionedMapOfMonomorphicTarget(Map* receiver_map); bool IsTransitionedMapOfMonomorphicTarget(Map* receiver_map);
void PatchCache(State state, void PatchCache(State state,
@ -408,17 +398,6 @@ class LoadIC: public IC {
Handle<Object> object, Handle<Object> object,
Handle<String> name); Handle<String> name);
virtual void UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<String> name,
StrictModeFlag strict_mode);
virtual Handle<Code> ComputePolymorphicIC(MapHandleList* receiver_maps,
CodeHandleList* handlers,
int number_of_valid_maps,
Handle<Name> name,
StrictModeFlag strict_mode);
virtual Handle<Code> ComputeLoadHandler(LookupResult* lookup, virtual Handle<Code> ComputeLoadHandler(LookupResult* lookup,
Handle<JSObject> receiver, Handle<JSObject> receiver,
Handle<String> name); Handle<String> name);
@ -496,10 +475,6 @@ class KeyedLoadIC: public LoadIC {
} }
// Update the inline cache. // Update the inline cache.
virtual void UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<String> name,
StrictModeFlag strict_mode);
virtual Handle<Code> ComputeLoadHandler(LookupResult* lookup, virtual Handle<Code> ComputeLoadHandler(LookupResult* lookup,
Handle<JSObject> receiver, Handle<JSObject> receiver,
Handle<String> name); Handle<String> name);
@ -594,17 +569,6 @@ class StoreIC: public IC {
return isolate()->builtins()->StoreIC_GlobalProxy_Strict(); return isolate()->builtins()->StoreIC_GlobalProxy_Strict();
} }
virtual void UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<String> name,
StrictModeFlag strict_mode);
virtual Handle<Code> ComputePolymorphicIC(MapHandleList* receiver_maps,
CodeHandleList* handlers,
int number_of_valid_maps,
Handle<Name> name,
StrictModeFlag strict_mode);
// Update the inline cache and the global stub cache based on the // Update the inline cache and the global stub cache based on the
// lookup result. // lookup result.
void UpdateCaches(LookupResult* lookup, void UpdateCaches(LookupResult* lookup,
@ -715,11 +679,6 @@ class KeyedStoreIC: public StoreIC {
KeyedAccessStoreMode store_mode, KeyedAccessStoreMode store_mode,
StrictModeFlag strict_mode); StrictModeFlag strict_mode);
virtual void UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<String> name,
StrictModeFlag strict_mode);
private: private:
void set_target(Code* code) { void set_target(Code* code) {
// Strict mode must be preserved across IC patching. // Strict mode must be preserved across IC patching.

View File

@ -3756,7 +3756,8 @@ Code::StubType Code::type() {
int Code::arguments_count() { int Code::arguments_count() {
ASSERT(is_call_stub() || is_keyed_call_stub() || kind() == STUB); ASSERT(is_call_stub() || is_keyed_call_stub() ||
kind() == STUB || is_handler());
return ExtractArgumentsCountFromFlags(flags()); return ExtractArgumentsCountFromFlags(flags());
} }

View File

@ -4863,6 +4863,9 @@ class Code: public HeapObject {
// [flags]: Access to specific code flags. // [flags]: Access to specific code flags.
inline Kind kind(); inline Kind kind();
inline Kind handler_kind() {
return static_cast<Kind>(arguments_count());
}
inline InlineCacheState ic_state(); // Only valid for IC stubs. inline InlineCacheState ic_state(); // Only valid for IC stubs.
inline ExtraICState extra_ic_state(); // Only valid for IC stubs. inline ExtraICState extra_ic_state(); // Only valid for IC stubs.
@ -4881,6 +4884,7 @@ class Code: public HeapObject {
// Testers for IC stub kinds. // Testers for IC stub kinds.
inline bool is_inline_cache_stub(); inline bool is_inline_cache_stub();
inline bool is_debug_stub(); inline bool is_debug_stub();
inline bool is_handler() { return kind() == HANDLER; }
inline bool is_load_stub() { return kind() == LOAD_IC; } inline bool is_load_stub() { return kind() == LOAD_IC; }
inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; } inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; }
inline bool is_store_stub() { return kind() == STORE_IC; } inline bool is_store_stub() { return kind() == STORE_IC; }

View File

@ -165,66 +165,29 @@ Handle<Code> StubCache::FindStoreHandler(Handle<Name> name,
} }
Handle<Code> StubCache::ComputeMonomorphicLoadIC(Handle<HeapObject> receiver, Handle<Code> StubCache::ComputeMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler, Handle<Code> handler,
Handle<Name> name) { Handle<Name> name,
StrictModeFlag strict_mode) {
Code::Kind kind = handler->handler_kind();
Handle<Map> map(receiver->map()); Handle<Map> map(receiver->map());
Handle<Code> ic = FindIC(name, map, Code::LOAD_IC, handler->type()); Handle<Code> ic = FindIC(name, map, kind, handler->type(), strict_mode);
if (!ic.is_null()) return ic; if (!ic.is_null()) return ic;
LoadStubCompiler ic_compiler(isolate()); if (kind == Code::LOAD_IC) {
ic = ic_compiler.CompileMonomorphicIC(map, handler, name); LoadStubCompiler ic_compiler(isolate());
ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
HeapObject::UpdateMapCodeCache(receiver, name, ic); } else if (kind == Code::KEYED_LOAD_IC) {
return ic; KeyedLoadStubCompiler ic_compiler(isolate());
} ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
} else if (kind == Code::STORE_IC) {
StoreStubCompiler ic_compiler(isolate(), strict_mode);
Handle<Code> StubCache::ComputeMonomorphicKeyedLoadIC( ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
Handle<HeapObject> receiver, } else {
Handle<Code> handler, ASSERT(kind == Code::KEYED_STORE_IC);
Handle<Name> name) { KeyedStoreStubCompiler ic_compiler(isolate(), strict_mode, STANDARD_STORE);
Handle<Map> map(receiver->map()); ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
Handle<Code> ic = FindIC(name, map, Code::KEYED_LOAD_IC, handler->type()); }
if (!ic.is_null()) return ic;
KeyedLoadStubCompiler ic_compiler(isolate());
ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
HeapObject::UpdateMapCodeCache(receiver, name, ic);
return ic;
}
Handle<Code> StubCache::ComputeMonomorphicStoreIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<Name> name,
StrictModeFlag strict_mode) {
Handle<Map> map(receiver->map());
Handle<Code> ic = FindIC(
name, map, Code::STORE_IC, handler->type(), strict_mode);
if (!ic.is_null()) return ic;
StoreStubCompiler ic_compiler(isolate(), strict_mode);
ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
HeapObject::UpdateMapCodeCache(receiver, name, ic);
return ic;
}
Handle<Code> StubCache::ComputeMonomorphicKeyedStoreIC(
Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<Name> name,
StrictModeFlag strict_mode) {
Handle<Map> map(receiver->map());
Handle<Code> ic = FindIC(
name, map, Code::KEYED_STORE_IC, handler->type(), strict_mode);
if (!ic.is_null()) return ic;
KeyedStoreStubCompiler ic_compiler(isolate(), strict_mode, STANDARD_STORE);
ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
HeapObject::UpdateMapCodeCache(receiver, name, ic); HeapObject::UpdateMapCodeCache(receiver, name, ic);
return ic; return ic;
@ -1072,30 +1035,25 @@ Handle<Code> StubCache::ComputeLoadElementPolymorphic(
} }
Handle<Code> StubCache::ComputePolymorphicLoadIC(MapHandleList* receiver_maps, Handle<Code> StubCache::ComputePolymorphicIC(MapHandleList* receiver_maps,
CodeHandleList* handlers, CodeHandleList* handlers,
int number_of_valid_maps, int number_of_valid_maps,
Handle<Name> name) { Handle<Name> name,
LoadStubCompiler ic_compiler(isolate_); StrictModeFlag strict_mode) {
Code::StubType type = number_of_valid_maps == 1 ? handlers->at(0)->type() Handle<Code> handler = handlers->at(0);
Code::Kind kind = handler->handler_kind();
Code::StubType type = number_of_valid_maps == 1 ? handler->type()
: Code::NORMAL; : Code::NORMAL;
Handle<Code> ic = ic_compiler.CompilePolymorphicIC( if (kind == Code::LOAD_IC) {
receiver_maps, handlers, name, type, PROPERTY); LoadStubCompiler ic_compiler(isolate_);
return ic; return ic_compiler.CompilePolymorphicIC(
} receiver_maps, handlers, name, type, PROPERTY);
} else {
ASSERT(kind == Code::STORE_IC);
Handle<Code> StubCache::ComputePolymorphicStoreIC(MapHandleList* receiver_maps, StoreStubCompiler ic_compiler(isolate_, strict_mode);
CodeHandleList* handlers, return ic_compiler.CompilePolymorphicIC(
int number_of_valid_maps, receiver_maps, handlers, name, type, PROPERTY);
Handle<Name> name, }
StrictModeFlag strict_mode) {
StoreStubCompiler ic_compiler(isolate_, strict_mode);
Code::StubType type = number_of_valid_maps == 1 ? handlers->at(0)->type()
: Code::NORMAL;
Handle<Code> ic = ic_compiler.CompilePolymorphicIC(
receiver_maps, handlers, name, type, PROPERTY);
return ic;
} }
@ -1973,8 +1931,7 @@ Handle<Code> BaseLoadStoreStubCompiler::GetICCode(Code::Kind kind,
Code::StubType type, Code::StubType type,
Handle<Name> name, Handle<Name> name,
InlineCacheState state) { InlineCacheState state) {
Code::Flags flags = Code::ComputeFlags( Code::Flags flags = Code::ComputeFlags(kind, state, extra_state(), type);
kind, state, extra_state(), type);
Handle<Code> code = GetCodeWithFlags(flags, name); Handle<Code> code = GetCodeWithFlags(flags, name);
PROFILE(isolate(), CodeCreateEvent(log_kind(code), *code, *name)); PROFILE(isolate(), CodeCreateEvent(log_kind(code), *code, *name));
JitEvent(name, code); JitEvent(name, code);
@ -1982,22 +1939,9 @@ Handle<Code> BaseLoadStoreStubCompiler::GetICCode(Code::Kind kind,
} }
Handle<Code> BaseLoadStubCompiler::GetCode(Code::Kind kind, Handle<Code> BaseLoadStoreStubCompiler::GetCode(Code::Kind kind,
Code::StubType type, Code::StubType type,
Handle<Name> name) { Handle<Name> name) {
ASSERT(type != Code::NORMAL);
Code::Flags flags = Code::ComputeFlags(
Code::HANDLER, MONOMORPHIC, Code::kNoExtraICState, type, kind);
Handle<Code> code = GetCodeWithFlags(flags, name);
PROFILE(isolate(), CodeCreateEvent(log_kind(code), *code, *name));
JitEvent(name, code);
return code;
}
Handle<Code> BaseStoreStubCompiler::GetCode(Code::Kind kind,
Code::StubType type,
Handle<Name> name) {
ASSERT(type != Code::NORMAL); ASSERT(type != Code::NORMAL);
Code::Flags flags = Code::ComputeFlags( Code::Flags flags = Code::ComputeFlags(
Code::HANDLER, MONOMORPHIC, extra_state(), type, kind); Code::HANDLER, MONOMORPHIC, extra_state(), type, kind);

View File

@ -104,23 +104,10 @@ class StubCache {
Code::StubType type, Code::StubType type,
StrictModeFlag strict_mode); StrictModeFlag strict_mode);
Handle<Code> ComputeMonomorphicLoadIC(Handle<HeapObject> receiver, Handle<Code> ComputeMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler, Handle<Code> handler,
Handle<Name> name); Handle<Name> name,
StrictModeFlag strict_mode);
Handle<Code> ComputeMonomorphicKeyedLoadIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<Name> name);
Handle<Code> ComputeMonomorphicStoreIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<Name> name,
StrictModeFlag strict_mode);
Handle<Code> ComputeMonomorphicKeyedStoreIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<Name> name,
StrictModeFlag strict_mode);
// Computes the right stub matching. Inserts the result in the // Computes the right stub matching. Inserts the result in the
// cache before returning. This might compile a stub if needed. // cache before returning. This might compile a stub if needed.
@ -326,16 +313,11 @@ class StubCache {
KeyedAccessStoreMode store_mode, KeyedAccessStoreMode store_mode,
StrictModeFlag strict_mode); StrictModeFlag strict_mode);
Handle<Code> ComputePolymorphicLoadIC(MapHandleList* receiver_maps, Handle<Code> ComputePolymorphicIC(MapHandleList* receiver_maps,
CodeHandleList* handlers, CodeHandleList* handlers,
int number_of_valid_maps, int number_of_valid_maps,
Handle<Name> name); Handle<Name> name,
StrictModeFlag strict_mode);
Handle<Code> ComputePolymorphicStoreIC(MapHandleList* receiver_maps,
CodeHandleList* handlers,
int number_of_valid_maps,
Handle<Name> name,
StrictModeFlag strict_mode);
// Finds the Code object stored in the Heap::non_monomorphic_cache(). // Finds the Code object stored in the Heap::non_monomorphic_cache().
Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind); Code* FindCallInitialize(int argc, RelocInfo::Mode mode, Code::Kind kind);
@ -697,6 +679,10 @@ class BaseLoadStoreStubCompiler: public StubCompiler {
Handle<Name> name, Handle<Name> name,
Label* success); Label* success);
Handle<Code> GetCode(Code::Kind kind,
Code::StubType type,
Handle<Name> name);
Handle<Code> GetICCode(Code::Kind kind, Handle<Code> GetICCode(Code::Kind kind,
Code::StubType type, Code::StubType type,
Handle<Name> name, Handle<Name> name,
@ -788,10 +774,6 @@ class BaseLoadStubCompiler: public BaseLoadStoreStubCompiler {
Handle<Name> name, Handle<Name> name,
LookupResult* lookup); LookupResult* lookup);
Handle<Code> GetCode(Code::Kind kind,
Code::StubType type,
Handle<Name> name);
virtual Register receiver() { return registers_[0]; } virtual Register receiver() { return registers_[0]; }
virtual Register name() { return registers_[1]; } virtual Register name() { return registers_[1]; }
virtual Register scratch1() { return registers_[2]; } virtual Register scratch1() { return registers_[2]; }
@ -942,10 +924,6 @@ class BaseStoreStubCompiler: public BaseLoadStoreStubCompiler {
virtual void HandlerFrontendFooter(Handle<Name> name, virtual void HandlerFrontendFooter(Handle<Name> name,
Label* success, Label* success,
Label* miss); Label* miss);
Handle<Code> GetCode(Code::Kind kind,
Code::StubType type,
Handle<Name> name);
void GenerateRestoreName(MacroAssembler* masm, void GenerateRestoreName(MacroAssembler* masm,
Label* label, Label* label,
Handle<Name> name); Handle<Name> name);