Commit c2a53d25 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[ic] Cleanup accessor handling, fix cached property on global, remove cache-on-prototype support

BUG=v8:5561

Change-Id: I425ad7e670b8e9c701ff284ab1be3638a975a6d3
Reviewed-on: https://chromium-review.googlesource.com/455832
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43836}
parent 69da6fcd
......@@ -671,13 +671,6 @@ enum InlineCacheState {
GENERIC,
};
enum CacheHolderFlag {
kCacheOnPrototype,
kCacheOnPrototypeReceiverIsDictionary,
kCacheOnPrototypeReceiverIsPrimitive,
kCacheOnReceiver
};
enum WhereToStart { kStartAtReceiver, kStartAtPrototype };
// The Store Buffer (GC).
......
......@@ -34,11 +34,9 @@ class PropertyAccessCompiler BASE_EMBEDDED {
static void TailCallBuiltin(MacroAssembler* masm, Builtins::Name name);
protected:
PropertyAccessCompiler(Isolate* isolate, Code::Kind kind,
CacheHolderFlag cache_holder)
PropertyAccessCompiler(Isolate* isolate, Code::Kind kind)
: registers_(GetCallingConvention(isolate, kind)),
kind_(kind),
cache_holder_(cache_holder),
isolate_(isolate),
masm_(isolate, NULL, 256, CodeObjectRequired::kYes) {
// TODO(yangguo): remove this once we can serialize IC stubs.
......@@ -46,7 +44,6 @@ class PropertyAccessCompiler BASE_EMBEDDED {
}
Code::Kind kind() const { return kind_; }
CacheHolderFlag cache_holder() const { return cache_holder_; }
MacroAssembler* masm() { return &masm_; }
Isolate* isolate() const { return isolate_; }
Factory* factory() const { return isolate()->factory(); }
......@@ -67,8 +64,6 @@ class PropertyAccessCompiler BASE_EMBEDDED {
static void InitializePlatformSpecific(AccessCompilerData* data);
Code::Kind kind_;
CacheHolderFlag cache_holder_;
Isolate* isolate_;
MacroAssembler masm_;
// Ensure that MacroAssembler has a reasonable size.
......
......@@ -17,9 +17,8 @@ namespace internal {
Handle<Code> PropertyHandlerCompiler::Find(Handle<Name> name,
Handle<Map> stub_holder,
Code::Kind kind,
CacheHolderFlag cache_holder) {
Code::Flags flags = Code::ComputeHandlerFlags(kind, cache_holder);
Code::Kind kind) {
Code::Flags flags = Code::ComputeHandlerFlags(kind);
Code* code = stub_holder->LookupInCodeCache(*name, flags);
if (code == nullptr) return Handle<Code>();
return handle(code);
......@@ -27,7 +26,7 @@ Handle<Code> PropertyHandlerCompiler::Find(Handle<Name> name,
Handle<Code> PropertyHandlerCompiler::GetCode(Code::Kind kind,
Handle<Name> name) {
Code::Flags flags = Code::ComputeHandlerFlags(kind, cache_holder());
Code::Flags flags = Code::ComputeHandlerFlags(kind);
// Create code object in the heap.
CodeDesc desc;
......
......@@ -15,15 +15,12 @@ class CallOptimization;
class PropertyHandlerCompiler : public PropertyAccessCompiler {
public:
static Handle<Code> Find(Handle<Name> name, Handle<Map> map, Code::Kind kind,
CacheHolderFlag cache_holder);
static Handle<Code> Find(Handle<Name> name, Handle<Map> map, Code::Kind kind);
protected:
PropertyHandlerCompiler(Isolate* isolate, Code::Kind kind, Handle<Map> map,
Handle<JSObject> holder, CacheHolderFlag cache_holder)
: PropertyAccessCompiler(isolate, kind, cache_holder),
map_(map),
holder_(holder) {}
Handle<JSObject> holder)
: PropertyAccessCompiler(isolate, kind), map_(map), holder_(holder) {}
virtual ~PropertyHandlerCompiler() {}
......@@ -117,10 +114,8 @@ class PropertyHandlerCompiler : public PropertyAccessCompiler {
class NamedLoadHandlerCompiler : public PropertyHandlerCompiler {
public:
NamedLoadHandlerCompiler(Isolate* isolate, Handle<Map> map,
Handle<JSObject> holder,
CacheHolderFlag cache_holder)
: PropertyHandlerCompiler(isolate, Code::LOAD_IC, map, holder,
cache_holder) {}
Handle<JSObject> holder)
: PropertyHandlerCompiler(isolate, Code::LOAD_IC, map, holder) {}
virtual ~NamedLoadHandlerCompiler() {}
......@@ -159,8 +154,7 @@ class NamedStoreHandlerCompiler : public PropertyHandlerCompiler {
explicit NamedStoreHandlerCompiler(Isolate* isolate, Handle<Map> map,
Handle<JSObject> holder)
: PropertyHandlerCompiler(isolate, Code::STORE_IC, map, holder,
kCacheOnReceiver) {
: PropertyHandlerCompiler(isolate, Code::STORE_IC, map, holder) {
#ifdef DEBUG
if (Descriptor::kPassLastArgsOnStack) {
ZapStackArgumentsRegisterAliases();
......@@ -208,8 +202,8 @@ class ElementHandlerCompiler : public PropertyHandlerCompiler {
public:
explicit ElementHandlerCompiler(Isolate* isolate)
: PropertyHandlerCompiler(isolate, Code::KEYED_LOAD_IC,
Handle<Map>::null(), Handle<JSObject>::null(),
kCacheOnReceiver) {}
Handle<Map>::null(), Handle<JSObject>::null()) {
}
virtual ~ElementHandlerCompiler() {}
......
......@@ -90,40 +90,6 @@ bool IC::IsHandler(Object* object) {
(object->IsCode() && Code::cast(object)->is_handler());
}
Handle<Map> IC::GetHandlerCacheHolder(Handle<Map> receiver_map,
bool receiver_is_holder, Isolate* isolate,
CacheHolderFlag* flag) {
if (receiver_is_holder) {
*flag = kCacheOnReceiver;
return receiver_map;
}
Handle<JSFunction> builtin_ctor;
if (Map::GetConstructorFunction(receiver_map, isolate->native_context())
.ToHandle(&builtin_ctor)) {
*flag = kCacheOnPrototypeReceiverIsPrimitive;
return handle(HeapObject::cast(builtin_ctor->instance_prototype())->map());
}
*flag = receiver_map->is_dictionary_map()
? kCacheOnPrototypeReceiverIsDictionary
: kCacheOnPrototype;
// Callers must ensure that the prototype is non-null.
return handle(JSObject::cast(receiver_map->prototype())->map());
}
Handle<Map> IC::GetICCacheHolder(Handle<Map> map, Isolate* isolate,
CacheHolderFlag* flag) {
Handle<JSFunction> builtin_ctor;
if (Map::GetConstructorFunction(map, isolate->native_context())
.ToHandle(&builtin_ctor)) {
*flag = kCacheOnPrototype;
return handle(builtin_ctor->initial_map());
}
*flag = kCacheOnReceiver;
return map;
}
bool IC::AddressIsDeoptimizedCode() const {
return AddressIsDeoptimizedCode(isolate(), address());
}
......
This diff is collapsed.
......@@ -58,14 +58,6 @@ class IC {
return IsStoreIC() || IsStoreOwnIC() || IsKeyedStoreIC();
}
static inline Handle<Map> GetHandlerCacheHolder(Handle<Map> receiver_map,
bool receiver_is_holder,
Isolate* isolate,
CacheHolderFlag* flag);
static inline Handle<Map> GetICCacheHolder(Handle<Map> receiver_map,
Isolate* isolate,
CacheHolderFlag* flag);
// The ICs that don't pass slot and vector through the stack have to
// save/restore them in the dispatcher.
static bool ShouldPushPopSlotAndVector(Code::Kind kind);
......@@ -137,8 +129,7 @@ class IC {
return Handle<Code>::null();
}
virtual Handle<Object> CompileHandler(LookupIterator* lookup,
Handle<Object> value,
CacheHolderFlag cache_holder) {
Handle<Object> value) {
UNREACHABLE();
return Handle<Object>::null();
}
......@@ -287,8 +278,8 @@ class LoadIC : public IC {
Handle<Object> GetMapIndependentHandler(LookupIterator* lookup) override;
Handle<Object> CompileHandler(LookupIterator* lookup, Handle<Object> unused,
CacheHolderFlag cache_holder) override;
Handle<Object> CompileHandler(LookupIterator* lookup,
Handle<Object> unused) override;
private:
// Creates a data handler that represents a load of a field by given index.
......@@ -374,8 +365,8 @@ class StoreIC : public IC {
void UpdateCaches(LookupIterator* lookup, Handle<Object> value,
JSReceiver::StoreFromKeyed store_mode);
Handle<Object> GetMapIndependentHandler(LookupIterator* lookup) override;
Handle<Object> CompileHandler(LookupIterator* lookup, Handle<Object> value,
CacheHolderFlag cache_holder) override;
Handle<Object> CompileHandler(LookupIterator* lookup,
Handle<Object> value) override;
private:
Handle<Object> StoreTransition(Handle<Map> receiver_map,
......
......@@ -42,9 +42,9 @@ bool CommonStubCacheChecks(StubCache* stub_cache, Name* name, Map* map,
DCHECK(IC::IsHandler(handler));
if (handler->IsCode()) {
Code* code = Code::cast(handler);
Code::Flags expected_flags = Code::RemoveHolderFromFlags(
Code::ComputeHandlerFlags(stub_cache->ic_kind()));
Code::Flags flags = Code::RemoveHolderFromFlags(code->flags());
Code::Flags expected_flags =
Code::ComputeHandlerFlags(stub_cache->ic_kind());
Code::Flags flags = code->flags();
DCHECK_EQ(expected_flags, flags);
DCHECK_EQ(Code::HANDLER, Code::ExtractKindFromFlags(code->flags()));
}
......
......@@ -5182,18 +5182,15 @@ Address Code::constant_pool() {
return constant_pool;
}
Code::Flags Code::ComputeFlags(Kind kind, ExtraICState extra_ic_state,
CacheHolderFlag holder) {
Code::Flags Code::ComputeFlags(Kind kind, ExtraICState extra_ic_state) {
// Compute the bit mask.
unsigned int bits = KindField::encode(kind) |
ExtraICStateField::encode(extra_ic_state) |
CacheHolderField::encode(holder);
unsigned int bits =
KindField::encode(kind) | ExtraICStateField::encode(extra_ic_state);
return static_cast<Flags>(bits);
}
Code::Flags Code::ComputeHandlerFlags(Kind handler_kind,
CacheHolderFlag holder) {
return ComputeFlags(Code::HANDLER, handler_kind, holder);
Code::Flags Code::ComputeHandlerFlags(Kind handler_kind) {
return ComputeFlags(Code::HANDLER, handler_kind);
}
......@@ -5207,16 +5204,6 @@ ExtraICState Code::ExtractExtraICStateFromFlags(Flags flags) {
}
CacheHolderFlag Code::ExtractCacheHolderFromFlags(Flags flags) {
return CacheHolderField::decode(flags);
}
Code::Flags Code::RemoveHolderFromFlags(Flags flags) {
int bits = flags & ~CacheHolderField::kMask;
return static_cast<Flags>(bits);
}
Code* Code::GetCodeFromTargetAddress(Address address) {
HeapObject* code = HeapObject::FromAddress(address - Code::kHeaderSize);
// GetCodeFromTargetAddress might be called when marking objects during mark
......
......@@ -5116,18 +5116,13 @@ class Code: public HeapObject {
// Flags operations.
static inline Flags ComputeFlags(
Kind kind, ExtraICState extra_ic_state = kNoExtraICState,
CacheHolderFlag holder = kCacheOnReceiver);
Kind kind, ExtraICState extra_ic_state = kNoExtraICState);
static inline Flags ComputeHandlerFlags(
Kind handler_kind, CacheHolderFlag holder = kCacheOnReceiver);
static inline Flags ComputeHandlerFlags(Kind handler_kind);
static inline CacheHolderFlag ExtractCacheHolderFromFlags(Flags flags);
static inline Kind ExtractKindFromFlags(Flags flags);
static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags);
static inline Flags RemoveHolderFromFlags(Flags flags);
// Convert a target address into a code object.
static inline Code* GetCodeFromTargetAddress(Address address);
......@@ -5338,9 +5333,7 @@ class Code: public HeapObject {
// Flags layout. BitField<type, shift, size>.
class HasUnwindingInfoField : public BitField<bool, 0, 1> {};
class CacheHolderField
: public BitField<CacheHolderFlag, HasUnwindingInfoField::kNext, 2> {};
class KindField : public BitField<Kind, CacheHolderField::kNext, 5> {};
class KindField : public BitField<Kind, HasUnwindingInfoField::kNext, 5> {};
STATIC_ASSERT(NUMBER_OF_KINDS <= KindField::kMax);
class ExtraICStateField
: public BitField<ExtraICState, KindField::kNext,
......@@ -5403,9 +5396,6 @@ class Code: public HeapObject {
static const int kArgumentsBits = 16;
static const int kMaxArguments = (1 << kArgumentsBits) - 1;
// This constant should be encodable in an ARM instruction.
static const int kFlagsNotUsedInLookup = CacheHolderField::kMask;
private:
friend class RelocIterator;
friend class Deoptimizer; // For FindCodeAgeSequence.
......
......@@ -204,8 +204,7 @@ TEST(TryProbeStubCache) {
// Generate some number of handlers.
for (int i = 0; i < 30; i++) {
Code::Flags flags =
Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(ic_kind));
Code::Flags flags = Code::ComputeHandlerFlags(ic_kind);
handlers.push_back(CreateCodeWithFlags(flags));
}
......
......@@ -31,8 +31,7 @@ static Handle<Code> GetDummyCode(Isolate* isolate) {
nullptr, // unwinding_info
0, // unwinding_info_size
nullptr}; // origin
Code::Flags flags =
Code::ComputeFlags(Code::LOAD_IC, kNoExtraICState, kCacheOnReceiver);
Code::Flags flags = Code::ComputeFlags(Code::LOAD_IC, kNoExtraICState);
Handle<Code> self_ref;
return isolate->factory()->NewCode(desc, flags, self_ref);
}
......@@ -60,9 +59,7 @@ TEST(CodeCache) {
codes.Add(GetDummyCode(isolate));
}
Handle<Name> bad_name = isolate->factory()->NewSymbol();
Code::Flags bad_flags =
Code::ComputeFlags(Code::LOAD_IC, kNoExtraICState, kCacheOnPrototype);
DCHECK(bad_flags != codes[0]->flags());
Code::Flags flags = Code::ComputeFlags(Code::LOAD_IC, kNoExtraICState);
// Cache name/code pairs.
for (int i = 0; i < kEntries; i++) {
......@@ -70,9 +67,8 @@ TEST(CodeCache) {
Handle<Code> code = codes.at(i);
Map::UpdateCodeCache(map, name, code);
CHECK_EQ(*code, map->LookupInCodeCache(*name, code->flags()));
CHECK_NULL(map->LookupInCodeCache(*name, bad_flags));
}
CHECK_NULL(map->LookupInCodeCache(*bad_name, bad_flags));
CHECK_NULL(map->LookupInCodeCache(*bad_name, flags));
// Check that lookup works not only right after storing.
for (int i = 0; i < kEntries; i++) {
......
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