Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(942)

Unified Diff: src/types-inl.h

Issue 224733023: Reland "Refactoring to allow adding new structured types" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/types-inl.h
diff --git a/src/types-inl.h b/src/types-inl.h
index 941fda797c880e4d66fd37a4f0abcf1093b8fdf2..d6c69c44009f64ddf8ce29d98b11d79f37d241f4 100644
--- a/src/types-inl.h
+++ b/src/types-inl.h
@@ -14,92 +14,32 @@ namespace v8 {
namespace internal {
// static
-ZoneTypeConfig::Tagged* ZoneTypeConfig::tagged_create(
- Tag tag, int size, Zone* zone) {
- Tagged* tagged = new(zone) Tagged(size + 1, zone);
- tagged->Add(reinterpret_cast<void*>(tag), zone);
- tagged->AddBlock(NULL, size, zone);
- return tagged;
-}
-
-
-// static
-void ZoneTypeConfig::tagged_shrink(Tagged* tagged, int size) {
- tagged->Rewind(size + 1);
-}
-
-
-// static
-ZoneTypeConfig::Tag ZoneTypeConfig::tagged_tag(Tagged* tagged) {
- return static_cast<Tag>(reinterpret_cast<intptr_t>(tagged->at(0)));
-}
-
-
-// static
-template<class T>
-T ZoneTypeConfig::tagged_get(Tagged* tagged, int i) {
- return reinterpret_cast<T>(tagged->at(i + 1));
-}
-
-
-// static
-template<class T>
-void ZoneTypeConfig::tagged_set(Tagged* tagged, int i, T value) {
- tagged->at(i + 1) = reinterpret_cast<void*>(value);
-}
-
-
-// static
-int ZoneTypeConfig::tagged_length(Tagged* tagged) {
- return tagged->length() - 1;
-}
-
-
-// static
Type* ZoneTypeConfig::handle(Type* type) {
return type;
}
// static
-bool ZoneTypeConfig::is(Type* type, Tag tag) {
- return is_tagged(type) && tagged_tag(as_tagged(type)) == tag;
-}
-
-
-// static
bool ZoneTypeConfig::is_bitset(Type* type) {
return reinterpret_cast<intptr_t>(type) & 1;
}
// static
-bool ZoneTypeConfig::is_tagged(Type* type) {
+bool ZoneTypeConfig::is_struct(Type* type) {
return !is_bitset(type);
}
// static
bool ZoneTypeConfig::is_class(Type* type) {
- return is(type, kClassTag);
+ return is_struct(type) && struct_tag(as_struct(type)) == Type::kClassTag;
}
// static
bool ZoneTypeConfig::is_constant(Type* type) {
- return is(type, kConstantTag);
-}
-
-
-// static
-bool ZoneTypeConfig::is_union(Type* type) {
- return is(type, kUnionTag);
-}
-
-
-// static
-bool ZoneTypeConfig::tagged_is_union(Tagged* tagged) {
- return is(from_tagged(tagged), kUnionTag);
+ return is_struct(type) && struct_tag(as_struct(type)) == Type::kConstantTag;
}
@@ -111,37 +51,24 @@ int ZoneTypeConfig::as_bitset(Type* type) {
// static
-ZoneTypeConfig::Tagged* ZoneTypeConfig::as_tagged(Type* type) {
- ASSERT(is_tagged(type));
- return reinterpret_cast<Tagged*>(type);
+ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) {
+ ASSERT(is_struct(type));
+ return reinterpret_cast<Struct*>(type);
}
// static
i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) {
ASSERT(is_class(type));
- return i::Handle<i::Map>(tagged_get<i::Map**>(as_tagged(type), 1));
+ return i::Handle<i::Map>(static_cast<i::Map**>(as_struct(type)[3]));
}
// static
i::Handle<i::Object> ZoneTypeConfig::as_constant(Type* type) {
ASSERT(is_constant(type));
- return i::Handle<i::Object>(tagged_get<i::Object**>(as_tagged(type), 1));
-}
-
-
-// static
-ZoneTypeConfig::Unioned* ZoneTypeConfig::as_union(Type* type) {
- ASSERT(is_union(type));
- return tagged_as_union(as_tagged(type));
-}
-
-
-// static
-ZoneTypeConfig::Unioned* ZoneTypeConfig::tagged_as_union(Tagged* tagged) {
- ASSERT(tagged_is_union(tagged));
- return reinterpret_cast<Unioned*>(tagged);
+ return i::Handle<i::Object>(
+ static_cast<i::Object**>(as_struct(type)[3]));
}
@@ -158,80 +85,81 @@ ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) {
// static
-ZoneTypeConfig::Type* ZoneTypeConfig::from_tagged(Tagged* tagged) {
- return reinterpret_cast<Type*>(tagged);
+ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structured) {
+ return reinterpret_cast<Type*>(structured);
}
// static
ZoneTypeConfig::Type* ZoneTypeConfig::from_class(
i::Handle<i::Map> map, int lub, Zone* zone) {
- Tagged* tagged = tagged_create(kClassTag, 2, zone);
- tagged_set(tagged, 0, lub);
- tagged_set(tagged, 1, map.location());
- return from_tagged(tagged);
+ Struct* structured = struct_create(Type::kClassTag, 2, zone);
+ structured[2] = from_bitset(lub);
+ structured[3] = map.location();
+ return from_struct(structured);
}
// static
ZoneTypeConfig::Type* ZoneTypeConfig::from_constant(
i::Handle<i::Object> value, int lub, Zone* zone) {
- Tagged* tagged = tagged_create(kConstantTag, 2, zone);
- tagged_set(tagged, 0, lub);
- tagged_set(tagged, 1, value.location());
- return from_tagged(tagged);
+ Struct* structured = struct_create(Type::kConstantTag, 2, zone);
+ structured[2] = from_bitset(lub);
+ structured[3] = value.location();
+ return from_struct(structured);
}
// static
-ZoneTypeConfig::Type* ZoneTypeConfig::from_union(Unioned* unioned) {
- return from_tagged(tagged_from_union(unioned));
+ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create(
+ int tag, int length, Zone* zone) {
+ Struct* structured = reinterpret_cast<Struct*>(
+ zone->New(sizeof(void*) * (length + 2))); // NOLINT
+ structured[0] = reinterpret_cast<void*>(tag);
+ structured[1] = reinterpret_cast<void*>(length);
+ return structured;
}
// static
-ZoneTypeConfig::Tagged* ZoneTypeConfig::tagged_from_union(Unioned* unioned) {
- return reinterpret_cast<Tagged*>(unioned);
+void ZoneTypeConfig::struct_shrink(Struct* structured, int length) {
+ ASSERT(0 <= length && length <= struct_length(structured));
+ structured[1] = reinterpret_cast<void*>(length);
}
// static
-ZoneTypeConfig::Unioned* ZoneTypeConfig::union_create(int size, Zone* zone) {
- return tagged_as_union(tagged_create(kUnionTag, size, zone));
+int ZoneTypeConfig::struct_tag(Struct* structured) {
+ int tag = reinterpret_cast<intptr_t>(structured[0]);
+ return tag;
}
// static
-void ZoneTypeConfig::union_shrink(Unioned* unioned, int size) {
- tagged_shrink(tagged_from_union(unioned), size);
+int ZoneTypeConfig::struct_length(Struct* structured) {
+ int length = reinterpret_cast<intptr_t>(structured[1]);
+ return length;
}
// static
-ZoneTypeConfig::Type* ZoneTypeConfig::union_get(Unioned* unioned, int i) {
- Type* type = tagged_get<Type*>(tagged_from_union(unioned), i);
- ASSERT(!is_union(type));
- return type;
+Type* ZoneTypeConfig::struct_get(Struct* structured, int i) {
+ ASSERT(0 <= i && i <= struct_length(structured));
+ return static_cast<Type*>(structured[2 + i]);
}
// static
-void ZoneTypeConfig::union_set(Unioned* unioned, int i, Type* type) {
- ASSERT(!is_union(type));
- tagged_set(tagged_from_union(unioned), i, type);
-}
-
-
-// static
-int ZoneTypeConfig::union_length(Unioned* unioned) {
- return tagged_length(tagged_from_union(unioned));
+void ZoneTypeConfig::struct_set(Struct* structured, int i, Type* type) {
+ ASSERT(0 <= i && i <= struct_length(structured));
+ structured[2 + i] = type;
}
// static
int ZoneTypeConfig::lub_bitset(Type* type) {
ASSERT(is_class(type) || is_constant(type));
- return static_cast<int>(tagged_get<intptr_t>(as_tagged(type), 0));
+ return as_bitset(struct_get(as_struct(type), 0));
}
// -------------------------------------------------------------------------- //
@@ -261,7 +189,7 @@ bool HeapTypeConfig::is_constant(Type* type) {
// static
-bool HeapTypeConfig::is_union(Type* type) {
+bool HeapTypeConfig::is_struct(Type* type) {
return type->IsFixedArray();
}
@@ -286,8 +214,8 @@ i::Handle<i::Object> HeapTypeConfig::as_constant(Type* type) {
// static
-i::Handle<HeapTypeConfig::Unioned> HeapTypeConfig::as_union(Type* type) {
- return i::handle(i::FixedArray::cast(type));
+i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) {
+ return i::handle(Struct::cast(type));
}
@@ -320,45 +248,51 @@ i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_constant(
// static
-i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_union(
- i::Handle<Unioned> unioned) {
- return i::Handle<Type>::cast(i::Handle<Object>::cast(unioned));
+i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_struct(
+ i::Handle<Struct> structured) {
+ return i::Handle<Type>::cast(i::Handle<Object>::cast(structured));
+}
+
+
+// static
+i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::struct_create(
+ int tag, int length, Isolate* isolate) {
+ i::Handle<Struct> structured = isolate->factory()->NewFixedArray(length + 1);
+ structured->set(0, i::Smi::FromInt(tag));
+ return structured;
}
// static
-i::Handle<HeapTypeConfig::Unioned> HeapTypeConfig::union_create(
- int size, Isolate* isolate) {
- return isolate->factory()->NewFixedArray(size);
+void HeapTypeConfig::struct_shrink(i::Handle<Struct> structured, int length) {
+ structured->Shrink(length + 1);
}
// static
-void HeapTypeConfig::union_shrink(i::Handle<Unioned> unioned, int size) {
- unioned->Shrink(size);
+int HeapTypeConfig::struct_tag(i::Handle<Struct> structured) {
+ return static_cast<i::Smi*>(structured->get(0))->value();
}
// static
-i::Handle<HeapTypeConfig::Type> HeapTypeConfig::union_get(
- i::Handle<Unioned> unioned, int i) {
- Type* type = static_cast<Type*>(unioned->get(i));
- ASSERT(!is_union(type));
- return i::handle(type, unioned->GetIsolate());
+int HeapTypeConfig::struct_length(i::Handle<Struct> structured) {
+ return structured->length() - 1;
}
// static
-void HeapTypeConfig::union_set(
- i::Handle<Unioned> unioned, int i, i::Handle<Type> type) {
- ASSERT(!is_union(*type));
- unioned->set(i, *type);
+i::Handle<HeapTypeConfig::Type> HeapTypeConfig::struct_get(
+ i::Handle<Struct> structured, int i) {
+ Type* type = static_cast<Type*>(structured->get(i + 1));
+ return i::handle(type, structured->GetIsolate());
}
// static
-int HeapTypeConfig::union_length(i::Handle<Unioned> unioned) {
- return unioned->length();
+void HeapTypeConfig::struct_set(
+ i::Handle<Struct> structured, int i, i::Handle<Type> type) {
+ structured->set(i + 1, *type);
}
« no previous file with comments | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698