2012-02-10 12:36:05 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2010-03-24 15:29:41 +00:00
|
|
|
|
2015-08-20 07:44:00 +00:00
|
|
|
#include "src/type-info.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-26 16:22:34 +00:00
|
|
|
#include "src/ast/ast.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/code-stubs.h"
|
|
|
|
#include "src/compiler.h"
|
2014-09-16 12:51:33 +00:00
|
|
|
#include "src/ic/ic.h"
|
2014-08-22 11:43:39 +00:00
|
|
|
#include "src/ic/stub-cache.h"
|
2015-08-20 07:44:00 +00:00
|
|
|
#include "src/objects-inl.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2010-03-24 15:29:41 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
2014-09-18 09:59:53 +00:00
|
|
|
TypeFeedbackOracle::TypeFeedbackOracle(
|
2015-01-23 15:19:34 +00:00
|
|
|
Isolate* isolate, Zone* zone, Handle<Code> code,
|
|
|
|
Handle<TypeFeedbackVector> feedback_vector, Handle<Context> native_context)
|
|
|
|
: native_context_(native_context), isolate_(isolate), zone_(zone) {
|
2011-06-20 12:33:08 +00:00
|
|
|
BuildDictionary(code);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(dictionary_->IsDictionary());
|
2014-04-30 10:51:01 +00:00
|
|
|
// We make a copy of the feedback vector because a GC could clear
|
|
|
|
// the type feedback info contained therein.
|
|
|
|
// TODO(mvstanton): revisit the decision to copy when we weakly
|
|
|
|
// traverse the feedback vector at GC time.
|
2015-01-23 15:19:34 +00:00
|
|
|
feedback_vector_ = TypeFeedbackVector::Copy(isolate, feedback_vector);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
static uint32_t IdToKey(TypeFeedbackId ast_id) {
|
|
|
|
return static_cast<uint32_t>(ast_id.ToInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Object> TypeFeedbackOracle::GetInfo(TypeFeedbackId ast_id) {
|
|
|
|
int entry = dictionary_->FindEntry(IdToKey(ast_id));
|
2013-06-07 13:21:20 +00:00
|
|
|
if (entry != UnseededNumberDictionary::kNotFound) {
|
|
|
|
Object* value = dictionary_->ValueAt(entry);
|
2013-06-12 15:03:44 +00:00
|
|
|
if (value->IsCell()) {
|
|
|
|
Cell* cell = Cell::cast(value);
|
2014-01-21 16:22:52 +00:00
|
|
|
return Handle<Object>(cell->value(), isolate());
|
2013-06-07 13:21:20 +00:00
|
|
|
} else {
|
2014-01-21 16:22:52 +00:00
|
|
|
return Handle<Object>(value, isolate());
|
2013-06-07 13:21:20 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-21 16:22:52 +00:00
|
|
|
return Handle<Object>::cast(isolate()->factory()->undefined_value());
|
2013-06-07 13:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-10 13:22:10 +00:00
|
|
|
Handle<Object> TypeFeedbackOracle::GetInfo(FeedbackVectorSlot slot) {
|
|
|
|
DCHECK(slot.ToInt() >= 0 && slot.ToInt() < feedback_vector_->length());
|
2015-04-02 09:39:32 +00:00
|
|
|
Handle<Object> undefined =
|
|
|
|
Handle<Object>::cast(isolate()->factory()->undefined_value());
|
2014-10-20 11:42:56 +00:00
|
|
|
Object* obj = feedback_vector_->Get(slot);
|
2015-04-02 09:39:32 +00:00
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
// Slots do not embed direct pointers to maps, functions. Instead
|
|
|
|
// a WeakCell is always used.
|
2015-02-04 09:46:05 +00:00
|
|
|
if (obj->IsWeakCell()) {
|
|
|
|
WeakCell* cell = WeakCell::cast(obj);
|
|
|
|
if (cell->cleared()) return undefined;
|
|
|
|
obj = cell->value();
|
|
|
|
}
|
|
|
|
|
2015-07-16 19:43:21 +00:00
|
|
|
if (obj->IsJSFunction() || obj->IsAllocationSite() || obj->IsSymbol() ||
|
2015-08-11 09:45:25 +00:00
|
|
|
obj->IsSimd128Value()) {
|
2014-02-10 21:38:17 +00:00
|
|
|
return Handle<Object>(obj, isolate());
|
|
|
|
}
|
2015-03-24 15:37:14 +00:00
|
|
|
|
2015-02-04 09:46:05 +00:00
|
|
|
return undefined;
|
2014-02-10 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-15 01:24:40 +00:00
|
|
|
InlineCacheState TypeFeedbackOracle::LoadInlineCacheState(
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorSlot slot) {
|
2015-07-30 10:37:58 +00:00
|
|
|
if (!slot.IsInvalid()) {
|
2015-09-28 08:23:35 +00:00
|
|
|
FeedbackVectorSlotKind kind = feedback_vector_->GetKind(slot);
|
|
|
|
if (kind == FeedbackVectorSlotKind::LOAD_IC) {
|
2015-07-30 10:37:58 +00:00
|
|
|
LoadICNexus nexus(feedback_vector_, slot);
|
|
|
|
return nexus.StateFromFeedback();
|
2015-09-28 08:23:35 +00:00
|
|
|
} else if (kind == FeedbackVectorSlotKind::KEYED_LOAD_IC) {
|
2015-07-30 10:37:58 +00:00
|
|
|
KeyedLoadICNexus nexus(feedback_vector_, slot);
|
|
|
|
return nexus.StateFromFeedback();
|
|
|
|
}
|
2014-11-27 16:36:18 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 01:24:40 +00:00
|
|
|
// If we can't find an IC, assume we've seen *something*, but we don't know
|
|
|
|
// what. PREMONOMORPHIC roughly encodes this meaning.
|
|
|
|
return PREMONOMORPHIC;
|
2014-11-27 16:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
bool TypeFeedbackOracle::StoreIsUninitialized(FeedbackVectorSlot slot) {
|
2015-08-28 09:01:22 +00:00
|
|
|
if (!slot.IsInvalid()) {
|
2015-09-28 08:23:35 +00:00
|
|
|
FeedbackVectorSlotKind kind = feedback_vector_->GetKind(slot);
|
|
|
|
if (kind == FeedbackVectorSlotKind::STORE_IC) {
|
2015-08-28 09:01:22 +00:00
|
|
|
StoreICNexus nexus(feedback_vector_, slot);
|
2015-09-04 08:36:29 +00:00
|
|
|
return nexus.StateFromFeedback() == UNINITIALIZED;
|
2015-09-28 08:23:35 +00:00
|
|
|
} else if (kind == FeedbackVectorSlotKind::KEYED_STORE_IC) {
|
2015-08-28 09:01:22 +00:00
|
|
|
KeyedStoreICNexus nexus(feedback_vector_, slot);
|
2015-09-04 08:36:29 +00:00
|
|
|
return nexus.StateFromFeedback() == UNINITIALIZED;
|
2015-08-28 09:01:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
bool TypeFeedbackOracle::CallIsUninitialized(FeedbackVectorSlot slot) {
|
2014-11-20 17:07:34 +00:00
|
|
|
Handle<Object> value = GetInfo(slot);
|
|
|
|
return value->IsUndefined() ||
|
|
|
|
value.is_identical_to(
|
|
|
|
TypeFeedbackVector::UninitializedSentinel(isolate()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
bool TypeFeedbackOracle::CallIsMonomorphic(FeedbackVectorSlot slot) {
|
2014-02-10 21:38:17 +00:00
|
|
|
Handle<Object> value = GetInfo(slot);
|
2014-05-26 13:59:24 +00:00
|
|
|
return value->IsAllocationSite() || value->IsJSFunction();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-10 13:22:10 +00:00
|
|
|
bool TypeFeedbackOracle::CallNewIsMonomorphic(FeedbackVectorSlot slot) {
|
2014-02-10 21:38:17 +00:00
|
|
|
Handle<Object> info = GetInfo(slot);
|
2015-09-16 15:12:24 +00:00
|
|
|
return info->IsAllocationSite() || info->IsJSFunction();
|
2012-01-27 13:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-10 13:22:10 +00:00
|
|
|
byte TypeFeedbackOracle::ForInType(FeedbackVectorSlot feedback_vector_slot) {
|
2014-02-10 21:38:17 +00:00
|
|
|
Handle<Object> value = GetInfo(feedback_vector_slot);
|
2014-04-30 10:51:01 +00:00
|
|
|
return value.is_identical_to(
|
2014-09-18 12:31:31 +00:00
|
|
|
TypeFeedbackVector::UninitializedSentinel(isolate()))
|
|
|
|
? ForInStatement::FAST_FOR_IN
|
|
|
|
: ForInStatement::SLOW_FOR_IN;
|
2012-03-02 11:33:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-28 09:01:22 +00:00
|
|
|
void TypeFeedbackOracle::GetStoreModeAndKeyType(
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorSlot slot, KeyedAccessStoreMode* store_mode,
|
2015-08-28 09:01:22 +00:00
|
|
|
IcCheckType* key_type) {
|
2015-09-10 15:02:21 +00:00
|
|
|
if (!slot.IsInvalid() &&
|
2015-09-28 08:23:35 +00:00
|
|
|
feedback_vector_->GetKind(slot) ==
|
|
|
|
FeedbackVectorSlotKind::KEYED_STORE_IC) {
|
2015-08-28 09:01:22 +00:00
|
|
|
KeyedStoreICNexus nexus(feedback_vector_, slot);
|
|
|
|
*store_mode = nexus.GetKeyedAccessStoreMode();
|
|
|
|
*key_type = nexus.GetKeyType();
|
|
|
|
} else {
|
|
|
|
*store_mode = STANDARD_STORE;
|
|
|
|
*key_type = ELEMENT;
|
2014-12-15 13:36:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
Handle<JSFunction> TypeFeedbackOracle::GetCallTarget(FeedbackVectorSlot slot) {
|
2015-12-04 07:33:44 +00:00
|
|
|
Handle<Object> info = GetInfo(slot);
|
2014-05-26 13:59:24 +00:00
|
|
|
if (info->IsAllocationSite()) {
|
|
|
|
return Handle<JSFunction>(isolate()->native_context()->array_function());
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
2014-03-19 13:39:09 +00:00
|
|
|
|
2014-05-28 08:39:33 +00:00
|
|
|
return Handle<JSFunction>::cast(info);
|
2011-09-27 11:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-10 13:22:10 +00:00
|
|
|
Handle<JSFunction> TypeFeedbackOracle::GetCallNewTarget(
|
|
|
|
FeedbackVectorSlot slot) {
|
2015-12-04 07:33:44 +00:00
|
|
|
Handle<Object> info = GetInfo(slot);
|
2015-09-16 15:12:24 +00:00
|
|
|
if (info->IsJSFunction()) {
|
2013-03-01 16:06:34 +00:00
|
|
|
return Handle<JSFunction>::cast(info);
|
|
|
|
}
|
2014-03-19 13:39:09 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(info->IsAllocationSite());
|
2014-03-19 13:39:09 +00:00
|
|
|
return Handle<JSFunction>(isolate()->native_context()->array_function());
|
2012-02-28 09:05:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-10 13:22:10 +00:00
|
|
|
Handle<AllocationSite> TypeFeedbackOracle::GetCallAllocationSite(
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorSlot slot) {
|
2014-05-26 13:59:24 +00:00
|
|
|
Handle<Object> info = GetInfo(slot);
|
|
|
|
if (info->IsAllocationSite()) {
|
|
|
|
return Handle<AllocationSite>::cast(info);
|
|
|
|
}
|
|
|
|
return Handle<AllocationSite>::null();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-10 13:22:10 +00:00
|
|
|
Handle<AllocationSite> TypeFeedbackOracle::GetCallNewAllocationSite(
|
|
|
|
FeedbackVectorSlot slot) {
|
2014-02-10 21:38:17 +00:00
|
|
|
Handle<Object> info = GetInfo(slot);
|
2015-09-16 15:12:24 +00:00
|
|
|
if (info->IsAllocationSite()) {
|
2014-01-20 09:48:05 +00:00
|
|
|
return Handle<AllocationSite>::cast(info);
|
|
|
|
}
|
|
|
|
return Handle<AllocationSite>::null();
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 13:21:20 +00:00
|
|
|
|
2013-06-21 11:10:06 +00:00
|
|
|
void TypeFeedbackOracle::CompareType(TypeFeedbackId id,
|
2014-01-21 16:22:52 +00:00
|
|
|
Type** left_type,
|
|
|
|
Type** right_type,
|
|
|
|
Type** combined_type) {
|
2013-06-12 17:20:37 +00:00
|
|
|
Handle<Object> info = GetInfo(id);
|
2013-07-02 16:31:39 +00:00
|
|
|
if (!info->IsCode()) {
|
|
|
|
// For some comparisons we don't have ICs, e.g. LiteralCompareTypeof.
|
2014-01-21 16:22:52 +00:00
|
|
|
*left_type = *right_type = *combined_type = Type::None(zone());
|
2013-07-02 16:31:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-06-12 17:20:37 +00:00
|
|
|
Handle<Code> code = Handle<Code>::cast(info);
|
|
|
|
|
|
|
|
Handle<Map> map;
|
|
|
|
Map* raw_map = code->FindFirstMap();
|
2015-03-26 11:21:52 +00:00
|
|
|
if (raw_map != NULL) Map::TryUpdate(handle(raw_map)).ToHandle(&map);
|
2012-11-14 15:59:45 +00:00
|
|
|
|
2013-06-12 17:20:37 +00:00
|
|
|
if (code->is_compare_ic_stub()) {
|
2014-09-05 08:04:37 +00:00
|
|
|
CompareICStub stub(code->stub_key(), isolate());
|
2014-09-16 12:51:33 +00:00
|
|
|
*left_type = CompareICState::StateToType(zone(), stub.left());
|
|
|
|
*right_type = CompareICState::StateToType(zone(), stub.right());
|
|
|
|
*combined_type = CompareICState::StateToType(zone(), stub.state(), map);
|
2013-06-12 17:20:37 +00:00
|
|
|
} else if (code->is_compare_nil_ic_stub()) {
|
2014-04-24 06:25:42 +00:00
|
|
|
CompareNilICStub stub(isolate(), code->extra_ic_state());
|
2014-01-21 16:22:52 +00:00
|
|
|
*combined_type = stub.GetType(zone(), map);
|
|
|
|
*left_type = *right_type = stub.GetInputType(zone(), map);
|
2011-12-09 09:26:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-14 17:02:39 +00:00
|
|
|
void TypeFeedbackOracle::BinaryType(TypeFeedbackId id,
|
2014-01-21 16:22:52 +00:00
|
|
|
Type** left,
|
|
|
|
Type** right,
|
|
|
|
Type** result,
|
2013-12-04 09:27:48 +00:00
|
|
|
Maybe<int>* fixed_right_arg,
|
2014-01-02 15:31:27 +00:00
|
|
|
Handle<AllocationSite>* allocation_site,
|
2013-12-02 13:14:07 +00:00
|
|
|
Token::Value op) {
|
2013-06-14 17:02:39 +00:00
|
|
|
Handle<Object> object = GetInfo(id);
|
2013-07-02 16:31:39 +00:00
|
|
|
if (!object->IsCode()) {
|
2013-10-04 08:17:11 +00:00
|
|
|
// For some binary ops we don't have ICs, e.g. Token::COMMA, but for the
|
2013-12-02 13:14:07 +00:00
|
|
|
// operations covered by the BinaryOpIC we should always have them.
|
2014-09-16 12:51:33 +00:00
|
|
|
DCHECK(op < BinaryOpICState::FIRST_TOKEN ||
|
|
|
|
op > BinaryOpICState::LAST_TOKEN);
|
2014-01-21 16:22:52 +00:00
|
|
|
*left = *right = *result = Type::None(zone());
|
2015-03-02 11:26:55 +00:00
|
|
|
*fixed_right_arg = Nothing<int>();
|
2014-01-02 15:31:27 +00:00
|
|
|
*allocation_site = Handle<AllocationSite>::null();
|
2013-07-02 16:31:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
Handle<Code> code = Handle<Code>::cast(object);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_EQ(Code::BINARY_OP_IC, code->kind());
|
2014-09-16 12:51:33 +00:00
|
|
|
BinaryOpICState state(isolate(), code->extra_ic_state());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_EQ(op, state.op());
|
2013-06-14 17:02:39 +00:00
|
|
|
|
2015-12-01 09:03:10 +00:00
|
|
|
*left = state.GetLeftType();
|
|
|
|
*right = state.GetRightType();
|
|
|
|
*result = state.GetResultType();
|
2013-12-04 09:27:48 +00:00
|
|
|
*fixed_right_arg = state.fixed_right_arg();
|
2014-01-02 15:31:27 +00:00
|
|
|
|
|
|
|
AllocationSite* first_allocation_site = code->FindFirstAllocationSite();
|
|
|
|
if (first_allocation_site != NULL) {
|
|
|
|
*allocation_site = handle(first_allocation_site);
|
|
|
|
} else {
|
|
|
|
*allocation_site = Handle<AllocationSite>::null();
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 14:16:08 +00:00
|
|
|
|
2014-01-21 16:22:52 +00:00
|
|
|
Type* TypeFeedbackOracle::CountType(TypeFeedbackId id) {
|
2013-11-28 13:16:51 +00:00
|
|
|
Handle<Object> object = GetInfo(id);
|
2014-01-21 16:22:52 +00:00
|
|
|
if (!object->IsCode()) return Type::None(zone());
|
2011-04-29 09:21:18 +00:00
|
|
|
Handle<Code> code = Handle<Code>::cast(object);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_EQ(Code::BINARY_OP_IC, code->kind());
|
2014-09-16 12:51:33 +00:00
|
|
|
BinaryOpICState state(isolate(), code->extra_ic_state());
|
2015-12-01 09:03:10 +00:00
|
|
|
return state.GetLeftType();
|
2011-04-29 09:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-27 16:36:18 +00:00
|
|
|
bool TypeFeedbackOracle::HasOnlyStringMaps(SmallMapList* receiver_types) {
|
|
|
|
bool all_strings = receiver_types->length() > 0;
|
|
|
|
for (int i = 0; i < receiver_types->length(); i++) {
|
|
|
|
all_strings &= receiver_types->at(i)->IsStringMap();
|
|
|
|
}
|
|
|
|
return all_strings;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
void TypeFeedbackOracle::PropertyReceiverTypes(FeedbackVectorSlot slot,
|
2015-03-10 15:06:10 +00:00
|
|
|
Handle<Name> name,
|
2014-11-27 16:36:18 +00:00
|
|
|
SmallMapList* receiver_types) {
|
|
|
|
receiver_types->Clear();
|
2015-07-30 10:37:58 +00:00
|
|
|
if (!slot.IsInvalid()) {
|
|
|
|
LoadICNexus nexus(feedback_vector_, slot);
|
|
|
|
Code::Flags flags = Code::ComputeHandlerFlags(Code::LOAD_IC);
|
|
|
|
CollectReceiverTypes(&nexus, name, flags, receiver_types);
|
|
|
|
}
|
2014-11-27 16:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TypeFeedbackOracle::KeyedPropertyReceiverTypes(
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorSlot slot, SmallMapList* receiver_types, bool* is_string,
|
2014-12-19 13:40:59 +00:00
|
|
|
IcCheckType* key_type) {
|
2014-11-27 16:36:18 +00:00
|
|
|
receiver_types->Clear();
|
2015-07-30 10:37:58 +00:00
|
|
|
if (slot.IsInvalid()) {
|
|
|
|
*is_string = false;
|
|
|
|
*key_type = ELEMENT;
|
|
|
|
} else {
|
|
|
|
KeyedLoadICNexus nexus(feedback_vector_, slot);
|
|
|
|
CollectReceiverTypes<FeedbackNexus>(&nexus, receiver_types);
|
|
|
|
*is_string = HasOnlyStringMaps(receiver_types);
|
|
|
|
*key_type = nexus.FindFirstName() != NULL ? PROPERTY : ELEMENT;
|
|
|
|
}
|
2013-11-28 15:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
void TypeFeedbackOracle::AssignmentReceiverTypes(FeedbackVectorSlot slot,
|
2015-08-28 09:01:22 +00:00
|
|
|
Handle<Name> name,
|
|
|
|
SmallMapList* receiver_types) {
|
|
|
|
receiver_types->Clear();
|
|
|
|
Code::Flags flags = Code::ComputeHandlerFlags(Code::STORE_IC);
|
|
|
|
CollectReceiverTypes(slot, name, flags, receiver_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TypeFeedbackOracle::KeyedAssignmentReceiverTypes(
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorSlot slot, SmallMapList* receiver_types,
|
2015-08-28 09:01:22 +00:00
|
|
|
KeyedAccessStoreMode* store_mode, IcCheckType* key_type) {
|
|
|
|
receiver_types->Clear();
|
|
|
|
CollectReceiverTypes(slot, receiver_types);
|
|
|
|
GetStoreModeAndKeyType(slot, store_mode, key_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
void TypeFeedbackOracle::CountReceiverTypes(FeedbackVectorSlot slot,
|
2015-09-10 15:02:21 +00:00
|
|
|
SmallMapList* receiver_types) {
|
|
|
|
receiver_types->Clear();
|
|
|
|
if (!slot.IsInvalid()) CollectReceiverTypes(slot, receiver_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
void TypeFeedbackOracle::CollectReceiverTypes(FeedbackVectorSlot slot,
|
2015-08-28 09:01:22 +00:00
|
|
|
Handle<Name> name,
|
|
|
|
Code::Flags flags,
|
|
|
|
SmallMapList* types) {
|
|
|
|
StoreICNexus nexus(feedback_vector_, slot);
|
|
|
|
CollectReceiverTypes<FeedbackNexus>(&nexus, name, flags, types);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-27 16:36:18 +00:00
|
|
|
template <class T>
|
2015-03-10 15:06:10 +00:00
|
|
|
void TypeFeedbackOracle::CollectReceiverTypes(T* obj, Handle<Name> name,
|
2014-11-27 16:36:18 +00:00
|
|
|
Code::Flags flags,
|
|
|
|
SmallMapList* types) {
|
2013-12-12 14:57:00 +00:00
|
|
|
if (FLAG_collect_megamorphic_maps_from_stub_cache &&
|
2014-11-27 16:36:18 +00:00
|
|
|
obj->ic_state() == MEGAMORPHIC) {
|
2012-06-11 12:42:31 +00:00
|
|
|
types->Reserve(4, zone());
|
2014-01-21 16:22:52 +00:00
|
|
|
isolate()->stub_cache()->CollectMatchingMaps(
|
2013-12-12 14:57:00 +00:00
|
|
|
types, name, flags, native_context_, zone());
|
|
|
|
} else {
|
2014-11-27 16:36:18 +00:00
|
|
|
CollectReceiverTypes<T>(obj, types);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
void TypeFeedbackOracle::CollectReceiverTypes(FeedbackVectorSlot slot,
|
2015-08-28 09:01:22 +00:00
|
|
|
SmallMapList* types) {
|
2015-09-28 08:23:35 +00:00
|
|
|
FeedbackVectorSlotKind kind = feedback_vector_->GetKind(slot);
|
|
|
|
if (kind == FeedbackVectorSlotKind::STORE_IC) {
|
2015-09-10 15:02:21 +00:00
|
|
|
StoreICNexus nexus(feedback_vector_, slot);
|
|
|
|
CollectReceiverTypes<FeedbackNexus>(&nexus, types);
|
|
|
|
} else {
|
2015-09-28 08:23:35 +00:00
|
|
|
DCHECK_EQ(FeedbackVectorSlotKind::KEYED_STORE_IC, kind);
|
2015-09-10 15:02:21 +00:00
|
|
|
KeyedStoreICNexus nexus(feedback_vector_, slot);
|
|
|
|
CollectReceiverTypes<FeedbackNexus>(&nexus, types);
|
|
|
|
}
|
2015-08-28 09:01:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-27 16:36:18 +00:00
|
|
|
template <class T>
|
|
|
|
void TypeFeedbackOracle::CollectReceiverTypes(T* obj, SmallMapList* types) {
|
2013-12-12 14:57:00 +00:00
|
|
|
MapHandleList maps;
|
2014-11-27 16:36:18 +00:00
|
|
|
if (obj->ic_state() == MONOMORPHIC) {
|
|
|
|
Map* map = obj->FindFirstMap();
|
2013-12-12 14:57:00 +00:00
|
|
|
if (map != NULL) maps.Add(handle(map));
|
2014-11-27 16:36:18 +00:00
|
|
|
} else if (obj->ic_state() == POLYMORPHIC) {
|
|
|
|
obj->FindAllMaps(&maps);
|
2013-12-12 14:57:00 +00:00
|
|
|
} else {
|
|
|
|
return;
|
2011-06-20 10:19:00 +00:00
|
|
|
}
|
2013-12-12 14:57:00 +00:00
|
|
|
types->Reserve(maps.length(), zone());
|
|
|
|
for (int i = 0; i < maps.length(); i++) {
|
|
|
|
Handle<Map> map(maps.at(i));
|
2015-03-26 11:21:52 +00:00
|
|
|
if (IsRelevantFeedback(*map, *native_context_)) {
|
|
|
|
types->AddMapIfMissing(maps.at(i), zone());
|
2013-12-12 14:57:00 +00:00
|
|
|
}
|
2013-07-09 08:22:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-25 04:32:07 +00:00
|
|
|
uint16_t TypeFeedbackOracle::ToBooleanTypes(TypeFeedbackId id) {
|
2013-04-24 11:32:17 +00:00
|
|
|
Handle<Object> object = GetInfo(id);
|
2011-07-25 14:08:36 +00:00
|
|
|
return object->IsCode() ? Handle<Code>::cast(object)->to_boolean_state() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
// Things are a bit tricky here: The iterator for the RelocInfos and the infos
|
|
|
|
// themselves are not GC-safe, so we first get all infos, then we create the
|
|
|
|
// dictionary (possibly triggering GC), and finally we relocate the collected
|
|
|
|
// infos before we process them.
|
|
|
|
void TypeFeedbackOracle::BuildDictionary(Handle<Code> code) {
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
2012-06-11 12:42:31 +00:00
|
|
|
ZoneList<RelocInfo> infos(16, zone());
|
2014-01-21 16:22:52 +00:00
|
|
|
HandleScope scope(isolate());
|
2011-06-20 12:33:08 +00:00
|
|
|
GetRelocInfos(code, &infos);
|
|
|
|
CreateDictionary(code, &infos);
|
|
|
|
ProcessRelocInfos(&infos);
|
|
|
|
// Allocate handle in the parent scope.
|
|
|
|
dictionary_ = scope.CloseAndEscape(dictionary_);
|
2011-03-30 15:31:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
void TypeFeedbackOracle::GetRelocInfos(Handle<Code> code,
|
|
|
|
ZoneList<RelocInfo>* infos) {
|
|
|
|
int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID);
|
|
|
|
for (RelocIterator it(*code, mask); !it.done(); it.next()) {
|
2012-06-11 12:42:31 +00:00
|
|
|
infos->Add(*it.rinfo(), zone());
|
2011-06-20 12:33:08 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
void TypeFeedbackOracle::CreateDictionary(Handle<Code> code,
|
|
|
|
ZoneList<RelocInfo>* infos) {
|
2013-06-03 15:32:22 +00:00
|
|
|
AllowHeapAllocation allocation_allowed;
|
2014-03-12 17:18:49 +00:00
|
|
|
Code* old_code = *code;
|
2014-04-25 07:56:13 +00:00
|
|
|
dictionary_ = UnseededNumberDictionary::New(isolate(), infos->length());
|
2014-03-12 17:18:49 +00:00
|
|
|
RelocateRelocInfos(infos, old_code, *code);
|
2011-06-20 12:33:08 +00:00
|
|
|
}
|
2011-03-07 16:09:56 +00:00
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
|
|
|
|
void TypeFeedbackOracle::RelocateRelocInfos(ZoneList<RelocInfo>* infos,
|
2014-03-12 17:18:49 +00:00
|
|
|
Code* old_code,
|
|
|
|
Code* new_code) {
|
2011-06-20 12:33:08 +00:00
|
|
|
for (int i = 0; i < infos->length(); i++) {
|
|
|
|
RelocInfo* info = &(*infos)[i];
|
2014-03-12 17:18:49 +00:00
|
|
|
info->set_host(new_code);
|
|
|
|
info->set_pc(new_code->instruction_start() +
|
|
|
|
(info->pc() - old_code->instruction_start()));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
void TypeFeedbackOracle::ProcessRelocInfos(ZoneList<RelocInfo>* infos) {
|
|
|
|
for (int i = 0; i < infos->length(); i++) {
|
2011-10-24 13:53:08 +00:00
|
|
|
RelocInfo reloc_entry = (*infos)[i];
|
|
|
|
Address target_address = reloc_entry.target_address();
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId ast_id =
|
|
|
|
TypeFeedbackId(static_cast<unsigned>((*infos)[i].data()));
|
2011-10-24 13:53:08 +00:00
|
|
|
Code* target = Code::GetCodeFromTargetAddress(target_address);
|
|
|
|
switch (target->kind()) {
|
2013-12-12 14:57:00 +00:00
|
|
|
case Code::LOAD_IC:
|
|
|
|
case Code::STORE_IC:
|
2011-10-24 13:53:08 +00:00
|
|
|
case Code::KEYED_LOAD_IC:
|
|
|
|
case Code::KEYED_STORE_IC:
|
|
|
|
case Code::BINARY_OP_IC:
|
|
|
|
case Code::COMPARE_IC:
|
|
|
|
case Code::TO_BOOLEAN_IC:
|
2013-04-24 11:32:17 +00:00
|
|
|
case Code::COMPARE_NIL_IC:
|
2011-06-20 12:33:08 +00:00
|
|
|
SetInfo(ast_id, target);
|
2011-10-24 13:53:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-20 12:33:08 +00:00
|
|
|
|
2012-08-06 14:13:09 +00:00
|
|
|
void TypeFeedbackOracle::SetInfo(TypeFeedbackId ast_id, Object* target) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(dictionary_->FindEntry(IdToKey(ast_id)) ==
|
2012-08-06 14:13:09 +00:00
|
|
|
UnseededNumberDictionary::kNotFound);
|
2011-06-20 12:33:08 +00:00
|
|
|
// Dictionary has been allocated with sufficient size for all elements.
|
2014-04-07 12:55:06 +00:00
|
|
|
DisallowHeapAllocation no_need_to_resize_dictionary;
|
|
|
|
HandleScope scope(isolate());
|
2014-04-24 10:39:50 +00:00
|
|
|
USE(UnseededNumberDictionary::AtNumberPut(
|
|
|
|
dictionary_, IdToKey(ast_id), handle(target, isolate())));
|
2011-06-20 12:33:08 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:26:22 +00:00
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|