Commit 9abfab09 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Types: cache lub bitset to avoid heap access

R=verwaest@chromium.org
BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19786 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 364c02e7
...@@ -141,9 +141,11 @@ int TypeImpl<Config>::LubBitset() { ...@@ -141,9 +141,11 @@ int TypeImpl<Config>::LubBitset() {
} }
return bitset; return bitset;
} else if (this->IsClass()) { } else if (this->IsClass()) {
return LubBitset(*this->AsClass()); int bitset = Config::lub_bitset(this);
return bitset ? bitset : LubBitset(*this->AsClass());
} else { } else {
return LubBitset(*this->AsConstant()); int bitset = Config::lub_bitset(this);
return bitset ? bitset : LubBitset(*this->AsConstant());
} }
} }
...@@ -548,9 +550,9 @@ typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert( ...@@ -548,9 +550,9 @@ typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert(
if (type->IsBitset()) { if (type->IsBitset()) {
return Config::from_bitset(type->AsBitset(), region); return Config::from_bitset(type->AsBitset(), region);
} else if (type->IsClass()) { } else if (type->IsClass()) {
return Config::from_class(type->AsClass(), region); return Config::from_class(type->AsClass(), type->LubBitset(), region);
} else if (type->IsConstant()) { } else if (type->IsConstant()) {
return Config::from_constant(type->AsConstant(), region); return Config::from_constant(type->AsConstant(), type->LubBitset(), region);
} else { } else {
ASSERT(type->IsUnion()); ASSERT(type->IsUnion());
typename OtherType::UnionedHandle unioned = type->AsUnion(); typename OtherType::UnionedHandle unioned = type->AsUnion();
......
...@@ -87,12 +87,17 @@ namespace internal { ...@@ -87,12 +87,17 @@ namespace internal {
// Consequently, do not use pointer equality for type tests, always use Is! // Consequently, do not use pointer equality for type tests, always use Is!
// //
// Internally, all 'primitive' types, and their unions, are represented as // Internally, all 'primitive' types, and their unions, are represented as
// bitsets via smis. Class is a heap pointer to the respective map. Only // bitsets. Class is a heap pointer to the respective map. Only Constant's, or
// Constant's, or unions containing Class'es or Constant's, require allocation. // unions containing Class'es or Constant's, currently require allocation.
// Note that the bitset representation is closed under both Union and Intersect. // Note that the bitset representation is closed under both Union and Intersect.
// //
// The type representation is heap-allocated, so cannot (currently) be used in // There are two type representations, using different allocation:
// a concurrent compilation context. //
// - class Type (zone-allocated, for compiler and concurrent compilation)
// - class HeapType (heap-allocated, for persistent types)
//
// Both provide the same API, and the Convert method can be used to interconvert
// them. For zone types, no query method touches the heap, only constructors do.
#define BITSET_TYPE_LIST(V) \ #define BITSET_TYPE_LIST(V) \
...@@ -147,14 +152,15 @@ namespace internal { ...@@ -147,14 +152,15 @@ namespace internal {
// static Handle<Unioned>::type as_union(Type*); // static Handle<Unioned>::type as_union(Type*);
// static Type* from_bitset(int bitset); // static Type* from_bitset(int bitset);
// static Handle<Type>::type from_bitset(int bitset, Region*); // static Handle<Type>::type from_bitset(int bitset, Region*);
// static Handle<Type>::type from_class(i::Handle<i::Map>, Region*) // static Handle<Type>::type from_class(i::Handle<Map>, int lub, Region*);
// static Handle<Type>::type from_constant(i::Handle<i::Object>, Region*); // static Handle<Type>::type from_constant(i::Handle<Object>, int, Region*);
// static Handle<Type>::type from_union(Handle<Unioned>::type); // static Handle<Type>::type from_union(Handle<Unioned>::type);
// static Handle<Unioned>::type union_create(int size, Region*); // static Handle<Unioned>::type union_create(int size, Region*);
// static void union_shrink(Handle<Unioned>::type, int size); // static void union_shrink(Handle<Unioned>::type, int size);
// static Handle<Type>::type union_get(Handle<Unioned>::type, int); // static Handle<Type>::type union_get(Handle<Unioned>::type, int);
// static void union_set(Handle<Unioned>::type, int, Handle<Type>::type); // static void union_set(Handle<Unioned>::type, int, Handle<Type>::type);
// static int union_length(Handle<Unioned>::type); // static int union_length(Handle<Unioned>::type);
// static int lub_bitset(Type*);
// } // }
template<class Config> template<class Config>
class TypeImpl : public Config::Base { class TypeImpl : public Config::Base {
...@@ -171,10 +177,10 @@ class TypeImpl : public Config::Base { ...@@ -171,10 +177,10 @@ class TypeImpl : public Config::Base {
#undef DEFINE_TYPE_CONSTRUCTOR #undef DEFINE_TYPE_CONSTRUCTOR
static TypeHandle Class(i::Handle<i::Map> map, Region* region) { static TypeHandle Class(i::Handle<i::Map> map, Region* region) {
return Config::from_class(map, region); return Config::from_class(map, LubBitset(*map), region);
} }
static TypeHandle Constant(i::Handle<i::Object> value, Region* region) { static TypeHandle Constant(i::Handle<i::Object> value, Region* region) {
return Config::from_constant(value, region); return Config::from_constant(value, LubBitset(*value), region);
} }
static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg); static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg);
...@@ -335,7 +341,7 @@ struct ZoneTypeConfig { ...@@ -335,7 +341,7 @@ struct ZoneTypeConfig {
} }
template<class T> template<class T>
static void tagged_set(Tagged* tagged, int i, T value) { static void tagged_set(Tagged* tagged, int i, T value) {
tagged->at(i + 1) = reinterpret_cast<T>(value); tagged->at(i + 1) = reinterpret_cast<void*>(value);
} }
static int tagged_length(Tagged* tagged) { static int tagged_length(Tagged* tagged) {
return tagged->length() - 1; return tagged->length() - 1;
...@@ -375,11 +381,11 @@ struct ZoneTypeConfig { ...@@ -375,11 +381,11 @@ struct ZoneTypeConfig {
} }
static i::Handle<i::Map> as_class(Type* type) { static i::Handle<i::Map> as_class(Type* type) {
ASSERT(is_class(type)); ASSERT(is_class(type));
return i::Handle<i::Map>(tagged_get<i::Map**>(as_tagged(type), 0)); return i::Handle<i::Map>(tagged_get<i::Map**>(as_tagged(type), 1));
} }
static i::Handle<i::Object> as_constant(Type* type) { static i::Handle<i::Object> as_constant(Type* type) {
ASSERT(is_constant(type)); ASSERT(is_constant(type));
return i::Handle<i::Object>(tagged_get<i::Object**>(as_tagged(type), 0)); return i::Handle<i::Object>(tagged_get<i::Object**>(as_tagged(type), 1));
} }
static Unioned* as_union(Type* type) { static Unioned* as_union(Type* type) {
ASSERT(is_union(type)); ASSERT(is_union(type));
...@@ -399,14 +405,16 @@ struct ZoneTypeConfig { ...@@ -399,14 +405,16 @@ struct ZoneTypeConfig {
static Type* from_tagged(Tagged* tagged) { static Type* from_tagged(Tagged* tagged) {
return reinterpret_cast<Type*>(tagged); return reinterpret_cast<Type*>(tagged);
} }
static Type* from_class(i::Handle<i::Map> map, Zone* zone) { static Type* from_class(i::Handle<i::Map> map, int lub, Zone* zone) {
Tagged* tagged = tagged_create(kClassTag, 1, zone); Tagged* tagged = tagged_create(kClassTag, 2, zone);
tagged_set(tagged, 0, map.location()); tagged_set(tagged, 0, lub);
tagged_set(tagged, 1, map.location());
return from_tagged(tagged); return from_tagged(tagged);
} }
static Type* from_constant(i::Handle<i::Object> value, Zone* zone) { static Type* from_constant(i::Handle<i::Object> value, int lub, Zone* zone) {
Tagged* tagged = tagged_create(kConstantTag, 1, zone); Tagged* tagged = tagged_create(kConstantTag, 2, zone);
tagged_set(tagged, 0, value.location()); tagged_set(tagged, 0, lub);
tagged_set(tagged, 1, value.location());
return from_tagged(tagged); return from_tagged(tagged);
} }
static Type* from_union(Unioned* unioned) { static Type* from_union(Unioned* unioned) {
...@@ -434,6 +442,10 @@ struct ZoneTypeConfig { ...@@ -434,6 +442,10 @@ struct ZoneTypeConfig {
static int union_length(Unioned* unioned) { static int union_length(Unioned* unioned) {
return tagged_length(tagged_from_union(unioned)); return tagged_length(tagged_from_union(unioned));
} }
static int lub_bitset(Type* type) {
ASSERT(is_class(type) || is_constant(type));
return tagged_get<intptr_t>(as_tagged(type), 0);
}
}; };
...@@ -475,11 +487,12 @@ struct HeapTypeConfig { ...@@ -475,11 +487,12 @@ struct HeapTypeConfig {
static i::Handle<Type> from_bitset(int bitset, Isolate* isolate) { static i::Handle<Type> from_bitset(int bitset, Isolate* isolate) {
return i::handle(from_bitset(bitset), isolate); return i::handle(from_bitset(bitset), isolate);
} }
static i::Handle<Type> from_class(i::Handle<i::Map> map, Isolate* isolate) { static i::Handle<Type> from_class(
i::Handle<i::Map> map, int lub, Isolate* isolate) {
return i::Handle<Type>::cast(i::Handle<Object>::cast(map)); return i::Handle<Type>::cast(i::Handle<Object>::cast(map));
} }
static i::Handle<Type> from_constant( static i::Handle<Type> from_constant(
i::Handle<i::Object> value, Isolate* isolate) { i::Handle<i::Object> value, int lub, Isolate* isolate) {
i::Handle<Box> box = isolate->factory()->NewBox(value); i::Handle<Box> box = isolate->factory()->NewBox(value);
return i::Handle<Type>::cast(i::Handle<Object>::cast(box)); return i::Handle<Type>::cast(i::Handle<Object>::cast(box));
} }
...@@ -506,6 +519,9 @@ struct HeapTypeConfig { ...@@ -506,6 +519,9 @@ struct HeapTypeConfig {
static int union_length(i::Handle<Unioned> unioned) { static int union_length(i::Handle<Unioned> unioned) {
return unioned->length(); return unioned->length();
} }
static int lub_bitset(Type* type) {
return 0; // kNone, which causes recomputation.
}
}; };
typedef TypeImpl<ZoneTypeConfig> Type; typedef TypeImpl<ZoneTypeConfig> Type;
......
...@@ -190,10 +190,10 @@ struct ZoneRep { ...@@ -190,10 +190,10 @@ struct ZoneRep {
return static_cast<int>(reinterpret_cast<intptr_t>(t) >> 1); return static_cast<int>(reinterpret_cast<intptr_t>(t) >> 1);
} }
static Map* AsClass(Type* t) { static Map* AsClass(Type* t) {
return *reinterpret_cast<Map**>(AsTagged(t)->at(1)); return *reinterpret_cast<Map**>(AsTagged(t)->at(2));
} }
static Object* AsConstant(Type* t) { static Object* AsConstant(Type* t) {
return *reinterpret_cast<Object**>(AsTagged(t)->at(1)); return *reinterpret_cast<Object**>(AsTagged(t)->at(2));
} }
static ZoneList<Type*>* AsUnion(Type* t) { static ZoneList<Type*>* AsUnion(Type* t) {
return reinterpret_cast<ZoneList<Type*>*>(AsTagged(t)); return reinterpret_cast<ZoneList<Type*>*>(AsTagged(t));
......
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