assignment_id_(GetNextId(isolate)),
block_start_(false),
block_end_(false),
- is_monomorphic_(false),
- receiver_types_(NULL) {
+ is_monomorphic_(false) {
ASSERT(Token::IsAssignmentOp(op));
if (is_compound()) {
binary_operation_ =
void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
// Record type feedback from the oracle in the AST.
is_monomorphic_ = oracle->LoadIsMonomorphicNormal(this);
+ receiver_types_.Clear();
if (key()->IsPropertyName()) {
if (oracle->LoadIsBuiltin(this, Builtins::kLoadIC_ArrayLength)) {
is_array_length_ = true;
Literal* lit_key = key()->AsLiteral();
ASSERT(lit_key != NULL && lit_key->handle()->IsString());
Handle<String> name = Handle<String>::cast(lit_key->handle());
- ZoneMapList* types = oracle->LoadReceiverTypes(this, name);
- receiver_types_ = types;
+ oracle->LoadReceiverTypes(this, name, &receiver_types_);
}
} else if (oracle->LoadIsBuiltin(this, Builtins::kKeyedLoadIC_String)) {
is_string_access_ = true;
} else if (is_monomorphic_) {
- monomorphic_receiver_type_ = oracle->LoadMonomorphicReceiverType(this);
+ receiver_types_.Add(oracle->LoadMonomorphicReceiverType(this));
} else if (oracle->LoadIsMegamorphicWithTypeInfo(this)) {
- receiver_types_ = new ZoneMapList(kMaxKeyedPolymorphism);
- oracle->CollectKeyedReceiverTypes(this->id(), receiver_types_);
+ receiver_types_.Reserve(kMaxKeyedPolymorphism);
+ oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_);
}
}
Property* prop = target()->AsProperty();
ASSERT(prop != NULL);
is_monomorphic_ = oracle->StoreIsMonomorphicNormal(this);
+ receiver_types_.Clear();
if (prop->key()->IsPropertyName()) {
Literal* lit_key = prop->key()->AsLiteral();
ASSERT(lit_key != NULL && lit_key->handle()->IsString());
Handle<String> name = Handle<String>::cast(lit_key->handle());
- ZoneMapList* types = oracle->StoreReceiverTypes(this, name);
- receiver_types_ = types;
+ oracle->StoreReceiverTypes(this, name, &receiver_types_);
} else if (is_monomorphic_) {
// Record receiver type for monomorphic keyed stores.
- monomorphic_receiver_type_ = oracle->StoreMonomorphicReceiverType(this);
+ receiver_types_.Add(oracle->StoreMonomorphicReceiverType(this));
} else if (oracle->StoreIsMegamorphicWithTypeInfo(this)) {
- receiver_types_ = new ZoneMapList(kMaxKeyedPolymorphism);
- oracle->CollectKeyedReceiverTypes(this->id(), receiver_types_);
+ receiver_types_.Reserve(kMaxKeyedPolymorphism);
+ oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_);
}
}
void CountOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
is_monomorphic_ = oracle->StoreIsMonomorphicNormal(this);
+ receiver_types_.Clear();
if (is_monomorphic_) {
// Record receiver type for monomorphic keyed stores.
- monomorphic_receiver_type_ = oracle->StoreMonomorphicReceiverType(this);
+ receiver_types_.Add(oracle->StoreMonomorphicReceiverType(this));
} else if (oracle->StoreIsMegamorphicWithTypeInfo(this)) {
- receiver_types_ = new ZoneMapList(kMaxKeyedPolymorphism);
- oracle->CollectKeyedReceiverTypes(this->id(), receiver_types_);
+ receiver_types_.Reserve(kMaxKeyedPolymorphism);
+ oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_);
}
}
Literal* key = property->key()->AsLiteral();
ASSERT(key != NULL && key->handle()->IsString());
Handle<String> name = Handle<String>::cast(key->handle());
- receiver_types_ = oracle->CallReceiverTypes(this, name, call_kind);
+ receiver_types_.Clear();
+ oracle->CallReceiverTypes(this, name, call_kind, &receiver_types_);
#ifdef DEBUG
if (FLAG_enable_slow_asserts) {
- if (receiver_types_ != NULL) {
- int length = receiver_types_->length();
- for (int i = 0; i < length; i++) {
- Handle<Map> map = receiver_types_->at(i);
- ASSERT(!map.is_null() && *map != NULL);
- }
+ int length = receiver_types_.length();
+ for (int i = 0; i < length; i++) {
+ Handle<Map> map = receiver_types_.at(i);
+ ASSERT(!map.is_null() && *map != NULL);
}
}
#endif
check_type_ = oracle->GetCallCheckType(this);
if (is_monomorphic_) {
Handle<Map> map;
- if (receiver_types_ != NULL && receiver_types_->length() > 0) {
+ if (receiver_types_.length() > 0) {
ASSERT(check_type_ == RECEIVER_MAP_CHECK);
- map = receiver_types_->at(0);
+ map = receiver_types_.at(0);
} else {
ASSERT(check_type_ != RECEIVER_MAP_CHECK);
holder_ = Handle<JSObject>(
#include "factory.h"
#include "jsregexp.h"
#include "runtime.h"
+#include "small-pointer-list.h"
#include "token.h"
#include "variables.h"
};
+class SmallMapList {
+ public:
+ SmallMapList() {}
+ explicit SmallMapList(int capacity) : list_(capacity) {}
+
+ void Reserve(int capacity) { list_.Reserve(capacity); }
+ void Clear() { list_.Clear(); }
+
+ bool is_empty() const { return list_.is_empty(); }
+ int length() const { return list_.length(); }
+
+ void Add(Handle<Map> handle) {
+ list_.Add(handle.location());
+ }
+
+ Handle<Map> at(int i) const {
+ return Handle<Map>(list_.at(i));
+ }
+
+ Handle<Map> first() const { return at(0); }
+ Handle<Map> last() const { return at(length() - 1); }
+
+ private:
+ // The list stores pointers to Map*, that is Map**, so it's GC safe.
+ SmallPointerList<Map*> list_;
+
+ DISALLOW_COPY_AND_ASSIGN(SmallMapList);
+};
+
+
class Expression: public AstNode {
public:
enum Context {
UNREACHABLE();
return false;
}
- virtual ZoneMapList* GetReceiverTypes() {
+ virtual SmallMapList* GetReceiverTypes() {
UNREACHABLE();
return NULL;
}
- virtual Handle<Map> GetMonomorphicReceiverType() {
- UNREACHABLE();
- return Handle<Map>();
+ Handle<Map> GetMonomorphicReceiverType() {
+ ASSERT(IsMonomorphic());
+ SmallMapList* types = GetReceiverTypes();
+ ASSERT(types != NULL && types->length() == 1);
+ return types->at(0);
}
unsigned id() const { return id_; }
key_(key),
pos_(pos),
type_(type),
- receiver_types_(NULL),
is_monomorphic_(false),
is_array_length_(false),
is_string_length_(false),
// Type feedback information.
void RecordTypeFeedback(TypeFeedbackOracle* oracle);
virtual bool IsMonomorphic() { return is_monomorphic_; }
- virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; }
+ virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
virtual bool IsArrayLength() { return is_array_length_; }
- virtual Handle<Map> GetMonomorphicReceiverType() {
- return monomorphic_receiver_type_;
- }
private:
Expression* obj_;
int pos_;
Type type_;
- ZoneMapList* receiver_types_;
+ SmallMapList receiver_types_;
bool is_monomorphic_ : 1;
bool is_array_length_ : 1;
bool is_string_length_ : 1;
bool is_string_access_ : 1;
bool is_function_prototype_ : 1;
- Handle<Map> monomorphic_receiver_type_;
};
pos_(pos),
is_monomorphic_(false),
check_type_(RECEIVER_MAP_CHECK),
- receiver_types_(NULL),
return_id_(GetNextId(isolate)) {
}
void RecordTypeFeedback(TypeFeedbackOracle* oracle,
CallKind call_kind);
- virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; }
+ virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
virtual bool IsMonomorphic() { return is_monomorphic_; }
CheckType check_type() const { return check_type_; }
Handle<JSFunction> target() { return target_; }
bool is_monomorphic_;
CheckType check_type_;
- ZoneMapList* receiver_types_;
+ SmallMapList receiver_types_;
Handle<JSFunction> target_;
Handle<JSObject> holder_;
Handle<JSGlobalPropertyCell> cell_;
expression_(expr),
pos_(pos),
assignment_id_(GetNextId(isolate)),
- count_id_(GetNextId(isolate)),
- receiver_types_(NULL) { }
+ count_id_(GetNextId(isolate)) {}
DECLARE_NODE_TYPE(CountOperation)
void RecordTypeFeedback(TypeFeedbackOracle* oracle);
virtual bool IsMonomorphic() { return is_monomorphic_; }
- virtual Handle<Map> GetMonomorphicReceiverType() {
- return monomorphic_receiver_type_;
- }
- virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; }
+ virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
// Bailout support.
int AssignmentId() const { return assignment_id_; }
int pos_;
int assignment_id_;
int count_id_;
- Handle<Map> monomorphic_receiver_type_;
- ZoneMapList* receiver_types_;
+ SmallMapList receiver_types_;
};
// Type feedback information.
void RecordTypeFeedback(TypeFeedbackOracle* oracle);
virtual bool IsMonomorphic() { return is_monomorphic_; }
- virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; }
- virtual Handle<Map> GetMonomorphicReceiverType() {
- return monomorphic_receiver_type_;
- }
+ virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; }
// Bailout support.
int CompoundLoadId() const { return compound_load_id_; }
bool block_end_;
bool is_monomorphic_;
- ZoneMapList* receiver_types_;
- Handle<Map> monomorphic_receiver_type_;
+ SmallMapList receiver_types_;
};
HLoadNamedFieldPolymorphic::HLoadNamedFieldPolymorphic(HValue* context,
HValue* object,
- ZoneMapList* types,
+ SmallMapList* types,
Handle<String> name)
: types_(Min(types->length(), kMaxLoadPolymorphism)),
name_(name),
public:
HLoadNamedFieldPolymorphic(HValue* context,
HValue* object,
- ZoneMapList* types,
+ SmallMapList* types,
Handle<String> name);
HValue* context() { return OperandAt(0); }
HValue* object() { return OperandAt(1); }
- ZoneMapList* types() { return &types_; }
+ SmallMapList* types() { return &types_; }
Handle<String> name() { return name_; }
bool need_generic() { return need_generic_; }
virtual bool DataEquals(HValue* value);
private:
- ZoneMapList types_;
+ SmallMapList types_;
Handle<String> name_;
bool need_generic_;
};
ASSERT(!name.is_null());
LookupResult lookup;
- ZoneMapList* types = expr->GetReceiverTypes();
+ SmallMapList* types = expr->GetReceiverTypes();
bool is_monomorphic = expr->IsMonomorphic() &&
ComputeStoredField(types->first(), name, &lookup);
void HGraphBuilder::HandlePolymorphicStoreNamedField(Assignment* expr,
HValue* object,
HValue* value,
- ZoneMapList* types,
+ SmallMapList* types,
Handle<String> name) {
// TODO(ager): We should recognize when the prototype chains for different
// maps are identical. In that case we can avoid repeatedly generating the
Handle<String> name = Handle<String>::cast(key->handle());
ASSERT(!name.is_null());
- ZoneMapList* types = expr->GetReceiverTypes();
+ SmallMapList* types = expr->GetReceiverTypes();
LookupResult lookup;
if (expr->IsMonomorphic()) {
*has_side_effects = false;
AddInstruction(new(zone()) HCheckNonSmi(object));
AddInstruction(HCheckInstanceType::NewIsSpecObject(object));
- ZoneMapList* maps = prop->GetReceiverTypes();
+ SmallMapList* maps = prop->GetReceiverTypes();
bool todo_external_array = false;
static const int kNumElementTypes = JSObject::kElementsKindCount;
} else if (expr->key()->IsPropertyName()) {
Handle<String> name = expr->key()->AsLiteral()->AsPropertyName();
- ZoneMapList* types = expr->GetReceiverTypes();
+ SmallMapList* types = expr->GetReceiverTypes();
HValue* obj = Pop();
if (expr->IsMonomorphic()) {
void HGraphBuilder::HandlePolymorphicCallNamed(Call* expr,
HValue* receiver,
- ZoneMapList* types,
+ SmallMapList* types,
Handle<String> name) {
// TODO(ager): We should recognize when the prototype chains for different
// maps are identical. In that case we can avoid repeatedly generating the
Handle<String> name = prop->key()->AsLiteral()->AsPropertyName();
- ZoneMapList* types = expr->GetReceiverTypes();
+ SmallMapList* types = expr->GetReceiverTypes();
HValue* receiver =
environment()->ExpressionStackAt(expr->arguments()->length());
if (expr->IsMonomorphic()) {
- Handle<Map> receiver_map =
- (types == NULL) ? Handle<Map>::null() : types->first();
+ Handle<Map> receiver_map = (types == NULL || types->is_empty())
+ ? Handle<Map>::null()
+ : types->first();
if (TryInlineBuiltinFunction(expr,
receiver,
receiver_map,
void HandlePolymorphicStoreNamedField(Assignment* expr,
HValue* object,
HValue* value,
- ZoneMapList* types,
+ SmallMapList* types,
Handle<String> name);
void HandlePolymorphicCallNamed(Call* expr,
HValue* receiver,
- ZoneMapList* types,
+ SmallMapList* types,
Handle<String> name);
void HandleLiteralCompareTypeof(CompareOperation* compare_expr,
Expression* expr,
public:
SmallPointerList() : data_(kEmptyTag) {}
+ explicit SmallPointerList(int capacity) : data_(kEmptyTag) {
+ Reserve(capacity);
+ }
+
+ void Reserve(int capacity) {
+ if (capacity < 2) return;
+ if ((data_ & kTagMask) == kListTag) {
+ if (list()->capacity() >= capacity) return;
+ int old_length = list()->length();
+ list()->AddBlock(NULL, capacity - list()->capacity());
+ list()->Rewind(old_length);
+ return;
+ }
+ PointerList* list = new PointerList(capacity);
+ if ((data_ & kTagMask) == kSingletonTag) {
+ list->Add(single_value());
+ }
+ ASSERT(IsAligned(reinterpret_cast<intptr_t>(list), kPointerAlignment));
+ data_ = reinterpret_cast<intptr_t>(list) | kListTag;
+ }
+
+ void Clear() {
+ data_ = kEmptyTag;
+ }
+
bool is_empty() const { return length() == 0; }
int length() const {
#include "api.h"
#include "arguments.h"
+#include "ast.h"
#include "code-stubs.h"
#include "gdb-jit.h"
#include "ic-inl.h"
}
-void StubCache::CollectMatchingMaps(ZoneMapList* types,
+void StubCache::CollectMatchingMaps(SmallMapList* types,
String* name,
Code::Flags flags) {
for (int i = 0; i < kPrimaryTableSize; i++) {
// invalidate the cache whenever a prototype map is changed. The stub
// validates the map chain as in the mono-morphic case.
+class SmallMapList;
class StubCache;
+
class SCTableReference {
public:
Address address() const { return address_; }
void Clear();
// Collect all maps that match the name and flags.
- void CollectMatchingMaps(ZoneMapList* types,
+ void CollectMatchingMaps(SmallMapList* types,
String* name,
Code::Flags flags);
}
-ZoneMapList* TypeFeedbackOracle::LoadReceiverTypes(Property* expr,
- Handle<String> name) {
+void TypeFeedbackOracle::LoadReceiverTypes(Property* expr,
+ Handle<String> name,
+ SmallMapList* types) {
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, NORMAL);
- return CollectReceiverTypes(expr->id(), name, flags);
+ CollectReceiverTypes(expr->id(), name, flags, types);
}
-ZoneMapList* TypeFeedbackOracle::StoreReceiverTypes(Assignment* expr,
- Handle<String> name) {
+void TypeFeedbackOracle::StoreReceiverTypes(Assignment* expr,
+ Handle<String> name,
+ SmallMapList* types) {
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::STORE_IC, NORMAL);
- return CollectReceiverTypes(expr->id(), name, flags);
+ CollectReceiverTypes(expr->id(), name, flags, types);
}
-ZoneMapList* TypeFeedbackOracle::CallReceiverTypes(Call* expr,
- Handle<String> name,
- CallKind call_kind) {
+void TypeFeedbackOracle::CallReceiverTypes(Call* expr,
+ Handle<String> name,
+ CallKind call_kind,
+ SmallMapList* types) {
int arity = expr->arguments()->length();
// Note: Currently we do not take string extra ic data into account
OWN_MAP,
NOT_IN_LOOP,
arity);
- return CollectReceiverTypes(expr->id(), name, flags);
+ CollectReceiverTypes(expr->id(), name, flags, types);
}
}
-ZoneMapList* TypeFeedbackOracle::CollectReceiverTypes(unsigned ast_id,
- Handle<String> name,
- Code::Flags flags) {
+void TypeFeedbackOracle::CollectReceiverTypes(unsigned ast_id,
+ Handle<String> name,
+ Code::Flags flags,
+ SmallMapList* types) {
Isolate* isolate = Isolate::Current();
Handle<Object> object = GetInfo(ast_id);
- if (object->IsUndefined() || object->IsSmi()) return NULL;
+ if (object->IsUndefined() || object->IsSmi()) return;
if (*object == isolate->builtins()->builtin(Builtins::kStoreIC_GlobalProxy)) {
// TODO(fschneider): We could collect the maps and signal that
// we need a generic store (or load) here.
ASSERT(Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC);
- return NULL;
} else if (object->IsMap()) {
- ZoneMapList* types = new ZoneMapList(1);
types->Add(Handle<Map>::cast(object));
- return types;
} else if (Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC) {
- ZoneMapList* types = new ZoneMapList(4);
+ types->Reserve(4);
ASSERT(object->IsCode());
isolate->stub_cache()->CollectMatchingMaps(types, *name, flags);
- return types->length() > 0 ? types : NULL;
- } else {
- return NULL;
}
}
-void TypeFeedbackOracle::CollectKeyedReceiverTypes(
- unsigned ast_id,
- ZoneMapList* types) {
+void TypeFeedbackOracle::CollectKeyedReceiverTypes(unsigned ast_id,
+ SmallMapList* types) {
Handle<Object> object = GetInfo(ast_id);
if (!object->IsCode()) return;
Handle<Code> code = Handle<Code>::cast(object);
// Forward declarations.
class Assignment;
-class UnaryOperation;
class BinaryOperation;
class Call;
+class CaseClause;
class CompareOperation;
-class CountOperation;
class CompilationInfo;
+class CountOperation;
class Property;
-class CaseClause;
+class SmallMapList;
+class UnaryOperation;
+
class TypeFeedbackOracle BASE_EMBEDDED {
public:
Handle<Map> LoadMonomorphicReceiverType(Property* expr);
Handle<Map> StoreMonomorphicReceiverType(Expression* expr);
- ZoneMapList* LoadReceiverTypes(Property* expr, Handle<String> name);
- ZoneMapList* StoreReceiverTypes(Assignment* expr, Handle<String> name);
- ZoneMapList* CallReceiverTypes(Call* expr,
- Handle<String> name,
- CallKind call_kind);
+ void LoadReceiverTypes(Property* expr,
+ Handle<String> name,
+ SmallMapList* types);
+ void StoreReceiverTypes(Assignment* expr,
+ Handle<String> name,
+ SmallMapList* types);
+ void CallReceiverTypes(Call* expr,
+ Handle<String> name,
+ CallKind call_kind,
+ SmallMapList* types);
void CollectKeyedReceiverTypes(unsigned ast_id,
- ZoneMapList* types);
+ SmallMapList* types);
CheckType GetCallCheckType(Call* expr);
Handle<JSObject> GetPrototypeForPrimitiveCheck(CheckType check);
TypeInfo IncrementType(CountOperation* expr);
private:
- ZoneMapList* CollectReceiverTypes(unsigned ast_id,
- Handle<String> name,
- Code::Flags flags);
+ void CollectReceiverTypes(unsigned ast_id,
+ Handle<String> name,
+ Code::Flags flags,
+ SmallMapList* types);
void SetInfo(unsigned ast_id, Object* target);
};
-// Introduce a convenience type for zone lists of map handles.
-typedef ZoneList<Handle<Map> > ZoneMapList;
-
-
// ZoneScopes keep track of the current parsing and compilation
// nesting and cleans up generated ASTs in the Zone when exiting the
// outer-most scope.