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

View File

@ -172,27 +172,17 @@ class IC {
static inline void SetTargetAtAddress(Address address, Code* target);
static void PostPatching(Address address, Code* target, Code* old_target);
virtual void UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<String> name,
StrictModeFlag strict_mode) {
set_target(*handler);
}
void UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<String> name,
StrictModeFlag strict_mode);
bool UpdatePolymorphicIC(State state,
Handle<HeapObject> receiver,
Handle<String> name,
Handle<Code> code,
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);
bool IsTransitionedMapOfMonomorphicTarget(Map* receiver_map);
void PatchCache(State state,
@ -408,17 +398,6 @@ class LoadIC: public IC {
Handle<Object> object,
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,
Handle<JSObject> receiver,
Handle<String> name);
@ -496,10 +475,6 @@ class KeyedLoadIC: public LoadIC {
}
// 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,
Handle<JSObject> receiver,
Handle<String> name);
@ -594,17 +569,6 @@ class StoreIC: public IC {
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
// lookup result.
void UpdateCaches(LookupResult* lookup,
@ -715,11 +679,6 @@ class KeyedStoreIC: public StoreIC {
KeyedAccessStoreMode store_mode,
StrictModeFlag strict_mode);
virtual void UpdateMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<String> name,
StrictModeFlag strict_mode);
private:
void set_target(Code* code) {
// Strict mode must be preserved across IC patching.

View File

@ -3756,7 +3756,8 @@ Code::StubType Code::type() {
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());
}

View File

@ -4863,6 +4863,9 @@ class Code: public HeapObject {
// [flags]: Access to specific code flags.
inline Kind kind();
inline Kind handler_kind() {
return static_cast<Kind>(arguments_count());
}
inline InlineCacheState 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.
inline bool is_inline_cache_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_keyed_load_stub() { return kind() == KEYED_LOAD_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> handler,
Handle<Name> name) {
Handle<Code> StubCache::ComputeMonomorphicIC(Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<Name> name,
StrictModeFlag strict_mode) {
Code::Kind kind = handler->handler_kind();
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;
LoadStubCompiler ic_compiler(isolate());
ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
HeapObject::UpdateMapCodeCache(receiver, name, ic);
return ic;
}
Handle<Code> StubCache::ComputeMonomorphicKeyedLoadIC(
Handle<HeapObject> receiver,
Handle<Code> handler,
Handle<Name> name) {
Handle<Map> map(receiver->map());
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);
if (kind == Code::LOAD_IC) {
LoadStubCompiler ic_compiler(isolate());
ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
} else if (kind == Code::KEYED_LOAD_IC) {
KeyedLoadStubCompiler ic_compiler(isolate());
ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
} else if (kind == Code::STORE_IC) {
StoreStubCompiler ic_compiler(isolate(), strict_mode);
ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
} else {
ASSERT(kind == Code::KEYED_STORE_IC);
KeyedStoreStubCompiler ic_compiler(isolate(), strict_mode, STANDARD_STORE);
ic = ic_compiler.CompileMonomorphicIC(map, handler, name);
}
HeapObject::UpdateMapCodeCache(receiver, name, ic);
return ic;
@ -1072,30 +1035,25 @@ Handle<Code> StubCache::ComputeLoadElementPolymorphic(
}
Handle<Code> StubCache::ComputePolymorphicLoadIC(MapHandleList* receiver_maps,
CodeHandleList* handlers,
int number_of_valid_maps,
Handle<Name> name) {
LoadStubCompiler ic_compiler(isolate_);
Code::StubType type = number_of_valid_maps == 1 ? handlers->at(0)->type()
Handle<Code> StubCache::ComputePolymorphicIC(MapHandleList* receiver_maps,
CodeHandleList* handlers,
int number_of_valid_maps,
Handle<Name> name,
StrictModeFlag strict_mode) {
Handle<Code> handler = handlers->at(0);
Code::Kind kind = handler->handler_kind();
Code::StubType type = number_of_valid_maps == 1 ? handler->type()
: Code::NORMAL;
Handle<Code> ic = ic_compiler.CompilePolymorphicIC(
receiver_maps, handlers, name, type, PROPERTY);
return ic;
}
Handle<Code> StubCache::ComputePolymorphicStoreIC(MapHandleList* receiver_maps,
CodeHandleList* handlers,
int number_of_valid_maps,
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;
if (kind == Code::LOAD_IC) {
LoadStubCompiler ic_compiler(isolate_);
return ic_compiler.CompilePolymorphicIC(
receiver_maps, handlers, name, type, PROPERTY);
} else {
ASSERT(kind == Code::STORE_IC);
StoreStubCompiler ic_compiler(isolate_, strict_mode);
return ic_compiler.CompilePolymorphicIC(
receiver_maps, handlers, name, type, PROPERTY);
}
}
@ -1973,8 +1931,7 @@ Handle<Code> BaseLoadStoreStubCompiler::GetICCode(Code::Kind kind,
Code::StubType type,
Handle<Name> name,
InlineCacheState state) {
Code::Flags flags = Code::ComputeFlags(
kind, state, extra_state(), type);
Code::Flags flags = Code::ComputeFlags(kind, state, extra_state(), type);
Handle<Code> code = GetCodeWithFlags(flags, name);
PROFILE(isolate(), CodeCreateEvent(log_kind(code), *code, *name));
JitEvent(name, code);
@ -1982,22 +1939,9 @@ Handle<Code> BaseLoadStoreStubCompiler::GetICCode(Code::Kind kind,
}
Handle<Code> BaseLoadStubCompiler::GetCode(Code::Kind kind,
Code::StubType type,
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) {
Handle<Code> BaseLoadStoreStubCompiler::GetCode(Code::Kind kind,
Code::StubType type,
Handle<Name> name) {
ASSERT(type != Code::NORMAL);
Code::Flags flags = Code::ComputeFlags(
Code::HANDLER, MONOMORPHIC, extra_state(), type, kind);

View File

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