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

Unified Diff: src/objects-inl.h

Issue 1694403002: [runtime] Move heap-object type check helpers to HeapObject with wrapper on Object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: drop the dcheck Created 4 years, 10 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/objects.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index a8c5baf5104d1f739997209c84a7387fdd42132f..83f46e3484dcd8b48db2509518398543084742ea 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -54,14 +54,11 @@ int PropertyDetails::field_width_in_words() const {
return representation().IsDouble() ? kDoubleSize / kPointerSize : 1;
}
-
-#define TYPE_CHECKER(type, instancetype) \
- bool Object::Is##type() const { \
- return Object::IsHeapObject() && \
- HeapObject::cast(this)->map()->instance_type() == instancetype; \
+#define TYPE_CHECKER(type, instancetype) \
+ bool HeapObject::Is##type() const { \
+ return map()->instance_type() == instancetype; \
}
-
#define CAST_ACCESSOR(type) \
type* type::cast(Object* object) { \
SLOW_DCHECK(object->Is##type()); \
@@ -128,25 +125,20 @@ int PropertyDetails::field_width_in_words() const {
set_##field(BooleanBit::set(field(), offset, value)); \
}
-
-bool Object::IsFixedArrayBase() const {
+bool HeapObject::IsFixedArrayBase() const {
return IsFixedArray() || IsFixedDoubleArray() || IsFixedTypedArrayBase();
}
-
-bool Object::IsFixedArray() const {
- if (!IsHeapObject()) return false;
- InstanceType instance_type = HeapObject::cast(this)->map()->instance_type();
+bool HeapObject::IsFixedArray() const {
+ InstanceType instance_type = map()->instance_type();
return instance_type == FIXED_ARRAY_TYPE ||
instance_type == TRANSITION_ARRAY_TYPE;
}
// External objects are not extensible, so the map check is enough.
-bool Object::IsExternal() const {
- return Object::IsHeapObject() &&
- HeapObject::cast(this)->map() ==
- HeapObject::cast(this)->GetHeap()->external_map();
+bool HeapObject::IsExternal() const {
+ return map() == GetHeap()->external_map();
}
@@ -155,113 +147,90 @@ TYPE_CHECKER(MutableHeapNumber, MUTABLE_HEAP_NUMBER_TYPE)
TYPE_CHECKER(Symbol, SYMBOL_TYPE)
TYPE_CHECKER(Simd128Value, SIMD128_VALUE_TYPE)
-
#define SIMD128_TYPE_CHECKER(TYPE, Type, type, lane_count, lane_type) \
- bool Object::Is##Type() const { \
- return Object::IsHeapObject() && \
- HeapObject::cast(this)->map() == \
- HeapObject::cast(this)->GetHeap()->type##_map(); \
- }
+ bool HeapObject::Is##Type() const { return map() == GetHeap()->type##_map(); }
SIMD128_TYPES(SIMD128_TYPE_CHECKER)
#undef SIMD128_TYPE_CHECKER
+#define IS_TYPE_FUNCTION_DEF(type_) \
+ bool Object::Is##type_() const { \
+ return IsHeapObject() && HeapObject::cast(this)->Is##type_(); \
+ }
+HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DEF)
+ODDBALL_LIST(IS_TYPE_FUNCTION_DEF)
+#undef IS_TYPE_FUNCTION_DEF
-bool Object::IsString() const {
- return Object::IsHeapObject()
- && HeapObject::cast(this)->map()->instance_type() < FIRST_NONSTRING_TYPE;
+bool HeapObject::IsString() const {
+ return map()->instance_type() < FIRST_NONSTRING_TYPE;
}
-
-bool Object::IsName() const {
- STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
- return Object::IsHeapObject() &&
- HeapObject::cast(this)->map()->instance_type() <= LAST_NAME_TYPE;
+bool HeapObject::IsName() const {
+ return map()->instance_type() <= LAST_NAME_TYPE;
}
-
-bool Object::IsUniqueName() const {
+bool HeapObject::IsUniqueName() const {
return IsInternalizedString() || IsSymbol();
}
-
-bool Object::IsFunction() const {
+bool HeapObject::IsFunction() const {
STATIC_ASSERT(LAST_FUNCTION_TYPE == LAST_TYPE);
- return Object::IsHeapObject() &&
- HeapObject::cast(this)->map()->instance_type() >= FIRST_FUNCTION_TYPE;
+ return map()->instance_type() >= FIRST_FUNCTION_TYPE;
}
+bool HeapObject::IsCallable() const { return map()->is_callable(); }
-bool Object::IsCallable() const {
- return Object::IsHeapObject() && HeapObject::cast(this)->map()->is_callable();
-}
-
-
-bool Object::IsConstructor() const {
- return Object::IsHeapObject() &&
- HeapObject::cast(this)->map()->is_constructor();
-}
-
+bool HeapObject::IsConstructor() const { return map()->is_constructor(); }
-bool Object::IsTemplateInfo() const {
+bool HeapObject::IsTemplateInfo() const {
return IsObjectTemplateInfo() || IsFunctionTemplateInfo();
}
-
-bool Object::IsInternalizedString() const {
- if (!this->IsHeapObject()) return false;
- uint32_t type = HeapObject::cast(this)->map()->instance_type();
+bool HeapObject::IsInternalizedString() const {
+ uint32_t type = map()->instance_type();
STATIC_ASSERT(kNotInternalizedTag != 0);
return (type & (kIsNotStringMask | kIsNotInternalizedMask)) ==
(kStringTag | kInternalizedTag);
}
-
-bool Object::IsConsString() const {
+bool HeapObject::IsConsString() const {
if (!IsString()) return false;
return StringShape(String::cast(this)).IsCons();
}
-
-bool Object::IsSlicedString() const {
+bool HeapObject::IsSlicedString() const {
if (!IsString()) return false;
return StringShape(String::cast(this)).IsSliced();
}
-
-bool Object::IsSeqString() const {
+bool HeapObject::IsSeqString() const {
if (!IsString()) return false;
return StringShape(String::cast(this)).IsSequential();
}
-
-bool Object::IsSeqOneByteString() const {
+bool HeapObject::IsSeqOneByteString() const {
if (!IsString()) return false;
return StringShape(String::cast(this)).IsSequential() &&
String::cast(this)->IsOneByteRepresentation();
}
-
-bool Object::IsSeqTwoByteString() const {
+bool HeapObject::IsSeqTwoByteString() const {
if (!IsString()) return false;
return StringShape(String::cast(this)).IsSequential() &&
String::cast(this)->IsTwoByteRepresentation();
}
-
-bool Object::IsExternalString() const {
+bool HeapObject::IsExternalString() const {
if (!IsString()) return false;
return StringShape(String::cast(this)).IsExternal();
}
-
-bool Object::IsExternalOneByteString() const {
+bool HeapObject::IsExternalOneByteString() const {
if (!IsString()) return false;
return StringShape(String::cast(this)).IsExternal() &&
String::cast(this)->IsOneByteRepresentation();
}
-
-bool Object::IsExternalTwoByteString() const {
+bool HeapObject::IsExternalTwoByteString() const {
if (!IsString()) return false;
return StringShape(String::cast(this)).IsExternal() &&
String::cast(this)->IsTwoByteRepresentation();
@@ -661,10 +630,8 @@ TYPE_CHECKER(ByteArray, BYTE_ARRAY_TYPE)
TYPE_CHECKER(BytecodeArray, BYTECODE_ARRAY_TYPE)
TYPE_CHECKER(FreeSpace, FREE_SPACE_TYPE)
-
-bool Object::IsFiller() const {
- if (!Object::IsHeapObject()) return false;
- InstanceType instance_type = HeapObject::cast(this)->map()->instance_type();
+bool HeapObject::IsFiller() const {
+ InstanceType instance_type = map()->instance_type();
return instance_type == FREE_SPACE_TYPE || instance_type == FILLER_TYPE;
}
@@ -676,35 +643,23 @@ bool Object::IsFiller() const {
TYPED_ARRAYS(TYPED_ARRAY_TYPE_CHECKER)
#undef TYPED_ARRAY_TYPE_CHECKER
-
-bool Object::IsFixedTypedArrayBase() const {
- if (!Object::IsHeapObject()) return false;
-
- InstanceType instance_type =
- HeapObject::cast(this)->map()->instance_type();
+bool HeapObject::IsFixedTypedArrayBase() const {
+ InstanceType instance_type = map()->instance_type();
return (instance_type >= FIRST_FIXED_TYPED_ARRAY_TYPE &&
instance_type <= LAST_FIXED_TYPED_ARRAY_TYPE);
}
-
-bool Object::IsJSReceiver() const {
+bool HeapObject::IsJSReceiver() const {
STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
- return IsHeapObject() &&
- HeapObject::cast(this)->map()->instance_type() >= FIRST_JS_RECEIVER_TYPE;
+ return map()->instance_type() >= FIRST_JS_RECEIVER_TYPE;
}
-
-bool Object::IsJSObject() const {
+bool HeapObject::IsJSObject() const {
STATIC_ASSERT(LAST_JS_OBJECT_TYPE == LAST_TYPE);
- return IsHeapObject() && HeapObject::cast(this)->map()->IsJSObjectMap();
-}
-
-
-bool Object::IsJSProxy() const {
- if (!Object::IsHeapObject()) return false;
- return HeapObject::cast(this)->map()->IsJSProxyMap();
+ return map()->IsJSObjectMap();
}
+bool HeapObject::IsJSProxy() const { return map()->IsJSProxyMap(); }
TYPE_CHECKER(JSSet, JS_SET_TYPE)
TYPE_CHECKER(JSMap, JS_MAP_TYPE)
@@ -718,35 +673,25 @@ TYPE_CHECKER(FixedDoubleArray, FIXED_DOUBLE_ARRAY_TYPE)
TYPE_CHECKER(WeakFixedArray, FIXED_ARRAY_TYPE)
TYPE_CHECKER(TransitionArray, TRANSITION_ARRAY_TYPE)
-
-bool Object::IsJSWeakCollection() const {
+bool HeapObject::IsJSWeakCollection() const {
return IsJSWeakMap() || IsJSWeakSet();
}
+bool HeapObject::IsDescriptorArray() const { return IsFixedArray(); }
-bool Object::IsDescriptorArray() const {
- return IsFixedArray();
-}
-
-
-bool Object::IsArrayList() const { return IsFixedArray(); }
-
+bool HeapObject::IsArrayList() const { return IsFixedArray(); }
bool Object::IsLayoutDescriptor() const {
return IsSmi() || IsFixedTypedArrayBase();
}
+bool HeapObject::IsTypeFeedbackVector() const { return IsFixedArray(); }
-bool Object::IsTypeFeedbackVector() const { return IsFixedArray(); }
-
-
-bool Object::IsTypeFeedbackMetadata() const { return IsFixedArray(); }
-
-
-bool Object::IsLiteralsArray() const { return IsFixedArray(); }
+bool HeapObject::IsTypeFeedbackMetadata() const { return IsFixedArray(); }
+bool HeapObject::IsLiteralsArray() const { return IsFixedArray(); }
-bool Object::IsDeoptimizationInputData() const {
+bool HeapObject::IsDeoptimizationInputData() const {
// Must be a fixed array.
if (!IsFixedArray()) return false;
@@ -761,8 +706,7 @@ bool Object::IsDeoptimizationInputData() const {
return length >= 0 && length % DeoptimizationInputData::kDeoptEntrySize == 0;
}
-
-bool Object::IsDeoptimizationOutputData() const {
+bool HeapObject::IsDeoptimizationOutputData() const {
if (!IsFixedArray()) return false;
// There's actually no way to see the difference between a fixed array and
// a deoptimization data array. Since this is used for asserts we can check
@@ -771,27 +715,23 @@ bool Object::IsDeoptimizationOutputData() const {
return true;
}
-
-bool Object::IsHandlerTable() const {
+bool HeapObject::IsHandlerTable() const {
if (!IsFixedArray()) return false;
// There's actually no way to see the difference between a fixed array and
// a handler table array.
return true;
}
-
-bool Object::IsDependentCode() const {
+bool HeapObject::IsDependentCode() const {
if (!IsFixedArray()) return false;
// There's actually no way to see the difference between a fixed array and
// a dependent codes array.
return true;
}
-
-bool Object::IsContext() const {
- if (!Object::IsHeapObject()) return false;
- Map* map = HeapObject::cast(this)->map();
- Heap* heap = map->GetHeap();
+bool HeapObject::IsContext() const {
+ Map* map = this->map();
+ Heap* heap = GetHeap();
return (map == heap->function_context_map() ||
map == heap->catch_context_map() ||
map == heap->with_context_map() ||
@@ -801,26 +741,16 @@ bool Object::IsContext() const {
map == heap->script_context_map());
}
-
-bool Object::IsNativeContext() const {
- return Object::IsHeapObject() &&
- HeapObject::cast(this)->map() ==
- HeapObject::cast(this)->GetHeap()->native_context_map();
+bool HeapObject::IsNativeContext() const {
+ return map() == GetHeap()->native_context_map();
}
-
-bool Object::IsScriptContextTable() const {
- if (!Object::IsHeapObject()) return false;
- Map* map = HeapObject::cast(this)->map();
- Heap* heap = map->GetHeap();
- return map == heap->script_context_table_map();
+bool HeapObject::IsScriptContextTable() const {
+ return map() == GetHeap()->script_context_table_map();
}
-
-bool Object::IsScopeInfo() const {
- return Object::IsHeapObject() &&
- HeapObject::cast(this)->map() ==
- HeapObject::cast(this)->GetHeap()->scope_info_map();
+bool HeapObject::IsScopeInfo() const {
+ return map() == GetHeap()->scope_info_map();
}
@@ -845,17 +775,18 @@ TYPE_CHECKER(JSValue, JS_VALUE_TYPE)
TYPE_CHECKER(JSDate, JS_DATE_TYPE)
TYPE_CHECKER(JSMessageObject, JS_MESSAGE_OBJECT_TYPE)
-bool Object::IsAbstractCode() const { return IsBytecodeArray() || IsCode(); }
+bool HeapObject::IsAbstractCode() const {
+ return IsBytecodeArray() || IsCode();
+}
-bool Object::IsStringWrapper() const {
+bool HeapObject::IsStringWrapper() const {
return IsJSValue() && JSValue::cast(this)->value()->IsString();
}
TYPE_CHECKER(Foreign, FOREIGN_TYPE)
-
-bool Object::IsBoolean() const {
+bool HeapObject::IsBoolean() const {
return IsOddball() &&
((Oddball::cast(this)->kind() & Oddball::kNotBooleanMask) == 0);
}
@@ -866,8 +797,7 @@ TYPE_CHECKER(JSArrayBuffer, JS_ARRAY_BUFFER_TYPE)
TYPE_CHECKER(JSTypedArray, JS_TYPED_ARRAY_TYPE)
TYPE_CHECKER(JSDataView, JS_DATA_VIEW_TYPE)
-
-bool Object::IsJSArrayBufferView() const {
+bool HeapObject::IsJSArrayBufferView() const {
return IsJSDataView() || IsJSTypedArray();
}
@@ -879,22 +809,14 @@ template <> inline bool Is<JSArray>(Object* obj) {
return obj->IsJSArray();
}
-
-bool Object::IsHashTable() const {
- return Object::IsHeapObject() &&
- HeapObject::cast(this)->map() ==
- HeapObject::cast(this)->GetHeap()->hash_table_map();
-}
-
-
-bool Object::IsWeakHashTable() const {
- return IsHashTable();
+bool HeapObject::IsHashTable() const {
+ return map() == GetHeap()->hash_table_map();
}
+bool HeapObject::IsWeakHashTable() const { return IsHashTable(); }
-bool Object::IsDictionary() const {
- return IsHashTable() &&
- this != HeapObject::cast(this)->GetHeap()->string_table();
+bool HeapObject::IsDictionary() const {
+ return IsHashTable() && this != GetHeap()->string_table();
}
@@ -915,13 +837,9 @@ bool Object::IsUnseededNumberDictionary() const {
return IsDictionary();
}
+bool HeapObject::IsStringTable() const { return IsHashTable(); }
-bool Object::IsStringTable() const {
- return IsHashTable();
-}
-
-
-bool Object::IsNormalizedMapCache() const {
+bool HeapObject::IsNormalizedMapCache() const {
return NormalizedMapCache::IsNormalizedMapCache(this);
}
@@ -930,51 +848,34 @@ int NormalizedMapCache::GetIndex(Handle<Map> map) {
return map->Hash() % NormalizedMapCache::kEntries;
}
-
-bool NormalizedMapCache::IsNormalizedMapCache(const Object* obj) {
+bool NormalizedMapCache::IsNormalizedMapCache(const HeapObject* obj) {
if (!obj->IsFixedArray()) return false;
if (FixedArray::cast(obj)->length() != NormalizedMapCache::kEntries) {
return false;
}
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) {
- reinterpret_cast<NormalizedMapCache*>(const_cast<Object*>(obj))->
- NormalizedMapCacheVerify();
+ reinterpret_cast<NormalizedMapCache*>(const_cast<HeapObject*>(obj))
+ ->NormalizedMapCacheVerify();
}
#endif
return true;
}
+bool HeapObject::IsCompilationCacheTable() const { return IsHashTable(); }
-bool Object::IsCompilationCacheTable() const {
- return IsHashTable();
-}
-
-
-bool Object::IsCodeCacheHashTable() const {
- return IsHashTable();
-}
-
-
-bool Object::IsPolymorphicCodeCacheHashTable() const {
- return IsHashTable();
-}
+bool HeapObject::IsCodeCacheHashTable() const { return IsHashTable(); }
-
-bool Object::IsMapCache() const {
+bool HeapObject::IsPolymorphicCodeCacheHashTable() const {
return IsHashTable();
}
+bool HeapObject::IsMapCache() const { return IsHashTable(); }
-bool Object::IsObjectHashTable() const {
- return IsHashTable();
-}
-
+bool HeapObject::IsObjectHashTable() const { return IsHashTable(); }
-bool Object::IsOrderedHashTable() const {
- return IsHeapObject() &&
- HeapObject::cast(this)->map() ==
- HeapObject::cast(this)->GetHeap()->ordered_hash_table_map();
+bool HeapObject::IsOrderedHashTable() const {
+ return map() == GetHeap()->ordered_hash_table_map();
}
@@ -992,40 +893,30 @@ bool Object::IsPrimitive() const {
return IsSmi() || HeapObject::cast(this)->map()->IsPrimitiveMap();
}
-
-bool Object::IsJSGlobalProxy() const {
- bool result = IsHeapObject() &&
- (HeapObject::cast(this)->map()->instance_type() ==
- JS_GLOBAL_PROXY_TYPE);
- DCHECK(!result ||
- HeapObject::cast(this)->map()->is_access_check_needed());
+bool HeapObject::IsJSGlobalProxy() const {
+ bool result = map()->instance_type() == JS_GLOBAL_PROXY_TYPE;
+ DCHECK(!result || map()->is_access_check_needed());
return result;
}
TYPE_CHECKER(JSGlobalObject, JS_GLOBAL_OBJECT_TYPE)
-
-bool Object::IsUndetectableObject() const {
- return IsHeapObject()
- && HeapObject::cast(this)->map()->is_undetectable();
+bool HeapObject::IsUndetectableObject() const {
+ return map()->is_undetectable();
}
-
-bool Object::IsAccessCheckNeeded() const {
- if (!IsHeapObject()) return false;
+bool HeapObject::IsAccessCheckNeeded() const {
if (IsJSGlobalProxy()) {
const JSGlobalProxy* proxy = JSGlobalProxy::cast(this);
JSGlobalObject* global = proxy->GetIsolate()->context()->global_object();
return proxy->IsDetachedFrom(global);
}
- return HeapObject::cast(this)->map()->is_access_check_needed();
+ return map()->is_access_check_needed();
}
-
-bool Object::IsStruct() const {
- if (!IsHeapObject()) return false;
- switch (HeapObject::cast(this)->map()->instance_type()) {
+bool HeapObject::IsStruct() const {
+ switch (map()->instance_type()) {
#define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return true;
STRUCT_LIST(MAKE_STRUCT_CASE)
#undef MAKE_STRUCT_CASE
@@ -1033,56 +924,23 @@ bool Object::IsStruct() const {
}
}
-
-#define MAKE_STRUCT_PREDICATE(NAME, Name, name) \
- bool Object::Is##Name() const { \
- return Object::IsHeapObject() \
- && HeapObject::cast(this)->map()->instance_type() == NAME##_TYPE; \
+#define MAKE_STRUCT_PREDICATE(NAME, Name, name) \
+ bool Object::Is##Name() const { \
+ return IsHeapObject() && HeapObject::cast(this)->Is##Name(); \
+ } \
+ bool HeapObject::Is##Name() const { \
+ return map()->instance_type() == NAME##_TYPE; \
}
- STRUCT_LIST(MAKE_STRUCT_PREDICATE)
+STRUCT_LIST(MAKE_STRUCT_PREDICATE)
#undef MAKE_STRUCT_PREDICATE
+#define MAKE_ODDBALL_PREDICATE(Name) \
+ bool HeapObject::Is##Name() const { \
+ return IsOddball() && Oddball::cast(this)->kind() == Oddball::k##Name; \
+ }
+ODDBALL_LIST(MAKE_ODDBALL_PREDICATE)
-bool Object::IsUndefined() const {
- return IsOddball() && Oddball::cast(this)->kind() == Oddball::kUndefined;
-}
-
-
-bool Object::IsNull() const {
- return IsOddball() && Oddball::cast(this)->kind() == Oddball::kNull;
-}
-
-
-bool Object::IsTheHole() const {
- return IsOddball() && Oddball::cast(this)->kind() == Oddball::kTheHole;
-}
-
-
-bool Object::IsException() const {
- return IsOddball() && Oddball::cast(this)->kind() == Oddball::kException;
-}
-
-
-bool Object::IsUninitialized() const {
- return IsOddball() && Oddball::cast(this)->kind() == Oddball::kUninitialized;
-}
-
-
-bool Object::IsTrue() const {
- return IsOddball() && Oddball::cast(this)->kind() == Oddball::kTrue;
-}
-
-
-bool Object::IsFalse() const {
- return IsOddball() && Oddball::cast(this)->kind() == Oddball::kFalse;
-}
-
-
-bool Object::IsArgumentsMarker() const {
- return IsOddball() && Oddball::cast(this)->kind() == Oddball::kArgumentMarker;
-}
-
-
+#undef MAKE_ODDBALL_PREDICATE
double Object::Number() const {
DCHECK(IsNumber());
return IsSmi()
@@ -6766,15 +6624,13 @@ bool JSObject::HasFixedTypedArrayElements() {
return array->IsFixedTypedArrayBase();
}
-
-#define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size) \
-bool JSObject::HasFixed##Type##Elements() { \
- HeapObject* array = elements(); \
- DCHECK(array != NULL); \
- if (!array->IsHeapObject()) \
- return false; \
- return array->map()->instance_type() == FIXED_##TYPE##_ARRAY_TYPE; \
-}
+#define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size) \
+ bool JSObject::HasFixed##Type##Elements() { \
+ HeapObject* array = elements(); \
+ DCHECK(array != NULL); \
+ if (!array->IsHeapObject()) return false; \
+ return array->map()->instance_type() == FIXED_##TYPE##_ARRAY_TYPE; \
+ }
TYPED_ARRAYS(FIXED_TYPED_ELEMENTS_CHECK)
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698