Commit 8764f87a authored by verwaest's avatar verwaest Committed by Commit bot

Turn StoreIC::Megamorphic into a builtin, get rid of the non-monomorphic-cache

BUG=

Review URL: https://codereview.chromium.org/1864703003

Cr-Commit-Position: refs/heads/master@{#35376}
parent 70c4216b
......@@ -4667,6 +4667,14 @@ static void Generate_StoreIC_Setter_ForDeopt(MacroAssembler* masm) {
NamedStoreHandlerCompiler::GenerateStoreViaSetterForDeopt(masm);
}
static void Generate_StoreIC_Megamorphic(MacroAssembler* masm) {
StoreIC::GenerateMegamorphic(masm);
}
static void Generate_StoreIC_Megamorphic_Strict(MacroAssembler* masm) {
StoreIC::GenerateMegamorphic(masm);
}
static void Generate_KeyedStoreIC_Megamorphic(MacroAssembler* masm) {
KeyedStoreIC::GenerateMegamorphic(masm, SLOPPY);
......
......@@ -247,8 +247,11 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
V(StoreIC_Setter_ForDeopt, STORE_IC, MONOMORPHIC, \
StoreICState::kStrictModeState) \
\
V(KeyedStoreIC_Megamorphic, KEYED_STORE_IC, MEGAMORPHIC, kNoExtraICState) \
V(StoreIC_Megamorphic, STORE_IC, MEGAMORPHIC, kNoExtraICState) \
V(StoreIC_Megamorphic_Strict, STORE_IC, MEGAMORPHIC, \
StoreICState::kStrictModeState) \
\
V(KeyedStoreIC_Megamorphic, KEYED_STORE_IC, MEGAMORPHIC, kNoExtraICState) \
V(KeyedStoreIC_Megamorphic_Strict, KEYED_STORE_IC, MEGAMORPHIC, \
StoreICState::kStrictModeState) \
\
......
......@@ -2695,10 +2695,6 @@ void Heap::CreateInitialObjects() {
// expanding the dictionary during bootstrapping.
set_code_stubs(*UnseededNumberDictionary::New(isolate(), 128));
// Create the non_monomorphic_cache used in stub-cache.cc. The initial size
// is set to avoid expanding the dictionary during bootstrapping.
set_non_monomorphic_cache(*UnseededNumberDictionary::New(isolate(), 64));
set_instanceof_cache_function(Smi::FromInt(0));
set_instanceof_cache_map(Smi::FromInt(0));
set_instanceof_cache_answer(Smi::FromInt(0));
......@@ -2901,7 +2897,6 @@ bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) {
case kInstanceofCacheMapRootIndex:
case kInstanceofCacheAnswerRootIndex:
case kCodeStubsRootIndex:
case kNonMonomorphicCacheRootIndex:
case kEmptyScriptRootIndex:
case kSymbolRegistryRootIndex:
case kScriptListRootIndex:
......
......@@ -162,7 +162,6 @@ using v8::MemoryPressureLevel;
V(HeapNumber, minus_infinity_value, MinusInfinityValue) \
V(JSObject, message_listeners, MessageListeners) \
V(UnseededNumberDictionary, code_stubs, CodeStubs) \
V(UnseededNumberDictionary, non_monomorphic_cache, NonMonomorphicCache) \
V(Code, js_entry_code, JsEntryCode) \
V(Code, js_construct_entry_code, JsConstructEntryCode) \
V(FixedArray, natives_source_cache, NativesSourceCache) \
......@@ -977,11 +976,6 @@ class Heap {
roots_[kCodeStubsRootIndex] = value;
}
// Sets the non_monomorphic_cache_ (only used when expanding the dictionary).
void SetRootNonMonomorphicCache(UnseededNumberDictionary* value) {
roots_[kNonMonomorphicCacheRootIndex] = value;
}
void SetRootMaterializedObjects(FixedArray* objects) {
roots_[kMaterializedObjectsRootIndex] = objects;
}
......
......@@ -747,7 +747,7 @@ void StoreIC::GenerateMegamorphic(MacroAssembler* masm) {
Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::STORE_IC));
masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, flags,
receiver, name, r3, r4, r5, r6);
receiver, name, r5, r6, r7, r8);
// Cache miss: Jump to runtime.
GenerateMiss(masm);
......
......@@ -729,14 +729,14 @@ void KeyedStoreIC::GenerateMegamorphic(MacroAssembler* masm,
void StoreIC::GenerateMegamorphic(MacroAssembler* masm) {
Register receiver = StoreDescriptor::ReceiverRegister();
Register name = StoreDescriptor::NameRegister();
DCHECK(!AreAliased(receiver, name, StoreDescriptor::ValueRegister(), x3, x4,
x5, x6));
DCHECK(!AreAliased(receiver, name, StoreDescriptor::ValueRegister(), x5, x6,
x7, x8));
// Probe the stub cache.
Code::Flags flags =
Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(Code::STORE_IC));
masm->isolate()->stub_cache()->GenerateProbe(masm, Code::STORE_IC, flags,
receiver, name, x3, x4, x5, x6);
receiver, name, x5, x6, x7, x8);
// Cache miss: Jump to runtime.
GenerateMiss(masm);
......
......@@ -43,90 +43,35 @@ Handle<Code> PropertyICCompiler::ComputeKeyedLoadMonomorphicHandler(
return stub;
}
Handle<Code> PropertyICCompiler::ComputeKeyedStoreMonomorphicHandler(
Handle<Map> receiver_map, LanguageMode language_mode,
KeyedAccessStoreMode store_mode) {
Handle<Map> receiver_map, KeyedAccessStoreMode store_mode) {
Isolate* isolate = receiver_map->GetIsolate();
ExtraICState extra_state =
KeyedStoreIC::ComputeExtraICState(language_mode, store_mode);
DCHECK(store_mode == STANDARD_STORE ||
store_mode == STORE_AND_GROW_NO_TRANSITION ||
store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS ||
store_mode == STORE_NO_TRANSITION_HANDLE_COW);
PropertyICCompiler compiler(isolate, Code::KEYED_STORE_IC, extra_state);
PropertyICCompiler compiler(isolate);
Handle<Code> code =
compiler.CompileKeyedStoreMonomorphicHandler(receiver_map, store_mode);
return code;
}
static void FillCache(Isolate* isolate, Handle<Code> code) {
Handle<UnseededNumberDictionary> dictionary = UnseededNumberDictionary::Set(
isolate->factory()->non_monomorphic_cache(), code->flags(), code);
isolate->heap()->SetRootNonMonomorphicCache(*dictionary);
}
Handle<Code> PropertyICCompiler::ComputeStore(Isolate* isolate,
InlineCacheState ic_state,
ExtraICState extra_state) {
DCHECK_EQ(MEGAMORPHIC, ic_state);
Code::Flags flags = Code::ComputeFlags(Code::STORE_IC, ic_state, extra_state);
Handle<UnseededNumberDictionary> cache =
isolate->factory()->non_monomorphic_cache();
int entry = cache->FindEntry(isolate, flags);
if (entry != -1) return Handle<Code>(Code::cast(cache->ValueAt(entry)));
PropertyICCompiler compiler(isolate, Code::STORE_IC);
Handle<Code> code = compiler.CompileStoreMegamorphic(flags);
FillCache(isolate, code);
return code;
}
void PropertyICCompiler::ComputeKeyedStorePolymorphicHandlers(
MapHandleList* receiver_maps, MapHandleList* transitioned_maps,
CodeHandleList* handlers, KeyedAccessStoreMode store_mode,
LanguageMode language_mode) {
CodeHandleList* handlers, KeyedAccessStoreMode store_mode) {
Isolate* isolate = receiver_maps->at(0)->GetIsolate();
DCHECK(store_mode == STANDARD_STORE ||
store_mode == STORE_AND_GROW_NO_TRANSITION ||
store_mode == STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS ||
store_mode == STORE_NO_TRANSITION_HANDLE_COW);
ExtraICState extra_state =
KeyedStoreIC::ComputeExtraICState(language_mode, store_mode);
PropertyICCompiler compiler(isolate, Code::KEYED_STORE_IC, extra_state);
PropertyICCompiler compiler(isolate);
compiler.CompileKeyedStorePolymorphicHandlers(
receiver_maps, transitioned_maps, handlers, store_mode);
}
Handle<Code> PropertyICCompiler::CompileStoreMegamorphic(Code::Flags flags) {
StoreIC::GenerateMegamorphic(masm());
Handle<Code> code = GetCodeWithFlags(flags, "CompileStoreMegamorphic");
PROFILE(isolate(), CodeCreateEvent(Logger::STORE_MEGAMORPHIC_TAG,
AbstractCode::cast(*code), 0));
return code;
}
Handle<Code> PropertyICCompiler::GetCode(Code::Kind kind, Handle<Name> name,
InlineCacheState state) {
Code::Flags flags =
Code::ComputeFlags(kind, state, extra_ic_state_, cache_holder());
Handle<Code> code = GetCodeWithFlags(flags, name);
PROFILE(isolate(),
CodeCreateEvent(log_kind(code), AbstractCode::cast(*code), *name));
#ifdef DEBUG
code->VerifyEmbeddedObjects();
#endif
return code;
}
void PropertyICCompiler::CompileKeyedStorePolymorphicHandlers(
MapHandleList* receiver_maps, MapHandleList* transitioned_maps,
CodeHandleList* handlers, KeyedAccessStoreMode store_mode) {
......
......@@ -13,21 +13,15 @@ namespace internal {
class PropertyICCompiler : public PropertyAccessCompiler {
public:
// Named
static Handle<Code> ComputeStore(Isolate* isolate, InlineCacheState ic_state,
ExtraICState extra_state);
// Keyed
static Handle<Code> ComputeKeyedLoadMonomorphicHandler(
Handle<Map> receiver_map, ExtraICState extra_ic_state);
static Handle<Code> ComputeKeyedStoreMonomorphicHandler(
Handle<Map> receiver_map, LanguageMode language_mode,
KeyedAccessStoreMode store_mode);
Handle<Map> receiver_map, KeyedAccessStoreMode store_mode);
static void ComputeKeyedStorePolymorphicHandlers(
MapHandleList* receiver_maps, MapHandleList* transitioned_maps,
CodeHandleList* handlers, KeyedAccessStoreMode store_mode,
LanguageMode language_mode);
CodeHandleList* handlers, KeyedAccessStoreMode store_mode);
// Helpers
// TODO(verwaest): Move all uses of these helpers to the PropertyICCompiler
......@@ -37,13 +31,9 @@ class PropertyICCompiler : public PropertyAccessCompiler {
private:
PropertyICCompiler(Isolate* isolate, Code::Kind kind,
ExtraICState extra_ic_state = kNoExtraICState,
CacheHolderFlag cache_holder = kCacheOnReceiver)
: PropertyAccessCompiler(isolate, kind, cache_holder),
extra_ic_state_(extra_ic_state) {}
Handle<Code> CompileStoreMegamorphic(Code::Flags flags);
explicit PropertyICCompiler(Isolate* isolate)
: PropertyAccessCompiler(isolate, Code::KEYED_STORE_IC,
kCacheOnReceiver) {}
Handle<Code> CompileKeyedStoreMonomorphicHandler(
Handle<Map> receiver_map, KeyedAccessStoreMode store_mode);
......@@ -51,30 +41,6 @@ class PropertyICCompiler : public PropertyAccessCompiler {
MapHandleList* transitioned_maps,
CodeHandleList* handlers,
KeyedAccessStoreMode store_mode);
Handle<Code> GetCode(Code::Kind kind, Handle<Name> name,
InlineCacheState state = MONOMORPHIC);
Logger::LogEventsAndTags log_kind(Handle<Code> code) {
if (kind() == Code::LOAD_IC) {
return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG
: Logger::LOAD_POLYMORPHIC_IC_TAG;
} else if (kind() == Code::KEYED_LOAD_IC) {
return code->ic_state() == MONOMORPHIC
? Logger::KEYED_LOAD_IC_TAG
: Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG;
} else if (kind() == Code::STORE_IC) {
return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG
: Logger::STORE_POLYMORPHIC_IC_TAG;
} else {
DCHECK_EQ(Code::KEYED_STORE_IC, kind());
return code->ic_state() == MONOMORPHIC
? Logger::KEYED_STORE_IC_TAG
: Logger::KEYED_STORE_POLYMORPHIC_IC_TAG;
}
}
const ExtraICState extra_ic_state_;
};
......
......@@ -1431,8 +1431,9 @@ Handle<Code> StoreIC::initialize_stub_in_optimized_code(
return stub.GetCode();
}
return PropertyICCompiler::ComputeStore(isolate, initialization_state,
ComputeExtraICState(language_mode));
return is_strict(language_mode)
? isolate->builtins()->StoreIC_Megamorphic_Strict()
: isolate->builtins()->StoreIC_Megamorphic();
}
Handle<Code> StoreIC::slow_stub() const {
......@@ -1631,8 +1632,8 @@ void KeyedStoreIC::UpdateStoreElement(Handle<Map> receiver_map,
ComputeTransitionedMap(receiver_map, store_mode);
store_mode = GetNonTransitioningStoreMode(store_mode);
Handle<Code> handler =
PropertyICCompiler::ComputeKeyedStoreMonomorphicHandler(
monomorphic_map, language_mode(), store_mode);
PropertyICCompiler::ComputeKeyedStoreMonomorphicHandler(monomorphic_map,
store_mode);
return ConfigureVectorState(Handle<Name>(), monomorphic_map, handler);
}
......@@ -1658,7 +1659,7 @@ void KeyedStoreIC::UpdateStoreElement(Handle<Map> receiver_map,
store_mode = GetNonTransitioningStoreMode(store_mode);
Handle<Code> handler =
PropertyICCompiler::ComputeKeyedStoreMonomorphicHandler(
transitioned_receiver_map, language_mode(), store_mode);
transitioned_receiver_map, store_mode);
ConfigureVectorState(Handle<Name>(), transitioned_receiver_map, handler);
return;
}
......@@ -1671,8 +1672,8 @@ void KeyedStoreIC::UpdateStoreElement(Handle<Map> receiver_map,
// grow at the end of the array, handle OOB accesses or copy COW arrays
// and still stay MONOMORPHIC.
Handle<Code> handler =
PropertyICCompiler::ComputeKeyedStoreMonomorphicHandler(
receiver_map, language_mode(), store_mode);
PropertyICCompiler::ComputeKeyedStoreMonomorphicHandler(receiver_map,
store_mode);
return ConfigureVectorState(Handle<Name>(), receiver_map, handler);
}
}
......@@ -1733,8 +1734,7 @@ void KeyedStoreIC::UpdateStoreElement(Handle<Map> receiver_map,
MapHandleList transitioned_maps(target_receiver_maps.length());
CodeHandleList handlers(target_receiver_maps.length());
PropertyICCompiler::ComputeKeyedStorePolymorphicHandlers(
&target_receiver_maps, &transitioned_maps, &handlers, store_mode,
language_mode());
&target_receiver_maps, &transitioned_maps, &handlers, store_mode);
ConfigureVectorState(&target_receiver_maps, &transitioned_maps, &handlers);
}
......
......@@ -353,13 +353,6 @@ class KeyedLoadIC : public LoadIC {
static void GenerateRuntimeGetProperty(MacroAssembler* masm);
static void GenerateMegamorphic(MacroAssembler* masm);
// Bit mask to be tested against bit field for the cases when
// generic stub should go into slow case.
// Access check is necessary explicitly since generic stub does not perform
// map checks.
static const int kSlowCaseBitFieldMask =
(1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor);
static Handle<Code> initialize_stub_in_optimized_code(
Isolate* isolate, State initialization_state, ExtraICState extra_state);
static Handle<Code> ChooseMegamorphicStub(Isolate* isolate,
......
......@@ -177,13 +177,7 @@ void CodeSerializer::SerializeIC(Code* ic, HowToCode how_to_code,
return;
}
}
// The IC may also just be a piece of code kept in the non_monomorphic_cache.
// In that case, just serialize as a normal code object.
if (FLAG_trace_serializer) {
PrintF(" %s has no special handling\n", Code::Kind2String(ic->kind()));
}
DCHECK(ic->kind() == Code::LOAD_IC || ic->kind() == Code::STORE_IC);
SerializeGeneric(ic, how_to_code, where_to_point);
UNREACHABLE();
}
int CodeSerializer::AddCodeStubKey(uint32_t stub_key) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment