| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Review notes: | 5 // Review notes: |
| 6 // | 6 // |
| 7 // - The use of macros in these inline functions may seem superfluous | 7 // - The use of macros in these inline functions may seem superfluous |
| 8 // but it is absolutely needed to make sure gcc generates optimal | 8 // but it is absolutely needed to make sure gcc generates optimal |
| 9 // code. gcc is not happy when attempting to inline too deep. | 9 // code. gcc is not happy when attempting to inline too deep. |
| 10 // | 10 // |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 bool HeapObject::Is##Type() const { return map() == GetHeap()->type##_map(); } | 155 bool HeapObject::Is##Type() const { return map() == GetHeap()->type##_map(); } |
| 156 SIMD128_TYPES(SIMD128_TYPE_CHECKER) | 156 SIMD128_TYPES(SIMD128_TYPE_CHECKER) |
| 157 #undef SIMD128_TYPE_CHECKER | 157 #undef SIMD128_TYPE_CHECKER |
| 158 | 158 |
| 159 // TODO(cbruni): remove once all the isolate-based versions are in place. | 159 // TODO(cbruni): remove once all the isolate-based versions are in place. |
| 160 #define IS_TYPE_FUNCTION_DEF(type_) \ | 160 #define IS_TYPE_FUNCTION_DEF(type_) \ |
| 161 bool Object::Is##type_() const { \ | 161 bool Object::Is##type_() const { \ |
| 162 return IsHeapObject() && HeapObject::cast(this)->Is##type_(); \ | 162 return IsHeapObject() && HeapObject::cast(this)->Is##type_(); \ |
| 163 } | 163 } |
| 164 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DEF) | 164 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DEF) |
| 165 #undef IS_TYPE_FUNCTION_DEF |
| 166 |
| 167 #define IS_TYPE_FUNCTION_DEF(Type, Value) \ |
| 168 bool Object::Is##Type(Isolate* isolate) const { \ |
| 169 return this == isolate->heap()->Value(); \ |
| 170 } \ |
| 171 bool HeapObject::Is##Type(Isolate* isolate) const { \ |
| 172 return this == isolate->heap()->Value(); \ |
| 173 } |
| 165 ODDBALL_LIST(IS_TYPE_FUNCTION_DEF) | 174 ODDBALL_LIST(IS_TYPE_FUNCTION_DEF) |
| 166 #undef IS_TYPE_FUNCTION_DEF | 175 #undef IS_TYPE_FUNCTION_DEF |
| 167 | 176 |
| 168 bool HeapObject::IsTheHole(Isolate* isolate) const { | |
| 169 return this == isolate->heap()->the_hole_value(); | |
| 170 } | |
| 171 | |
| 172 bool HeapObject::IsUndefined(Isolate* isolate) const { | |
| 173 return this == isolate->heap()->undefined_value(); | |
| 174 } | |
| 175 | |
| 176 bool Object::IsTheHole(Isolate* isolate) const { | |
| 177 return this == isolate->heap()->the_hole_value(); | |
| 178 } | |
| 179 | |
| 180 bool Object::IsUndefined(Isolate* isolate) const { | |
| 181 return this == isolate->heap()->undefined_value(); | |
| 182 } | |
| 183 | |
| 184 bool HeapObject::IsString() const { | 177 bool HeapObject::IsString() const { |
| 185 return map()->instance_type() < FIRST_NONSTRING_TYPE; | 178 return map()->instance_type() < FIRST_NONSTRING_TYPE; |
| 186 } | 179 } |
| 187 | 180 |
| 188 bool HeapObject::IsName() const { | 181 bool HeapObject::IsName() const { |
| 189 return map()->instance_type() <= LAST_NAME_TYPE; | 182 return map()->instance_type() <= LAST_NAME_TYPE; |
| 190 } | 183 } |
| 191 | 184 |
| 192 bool HeapObject::IsUniqueName() const { | 185 bool HeapObject::IsUniqueName() const { |
| 193 return IsInternalizedString() || IsSymbol(); | 186 return IsInternalizedString() || IsSymbol(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } else { | 287 } else { |
| 295 if (filter & SKIP_STRINGS) return true; | 288 if (filter & SKIP_STRINGS) return true; |
| 296 } | 289 } |
| 297 return false; | 290 return false; |
| 298 } | 291 } |
| 299 | 292 |
| 300 | 293 |
| 301 Handle<Object> Object::NewStorageFor(Isolate* isolate, | 294 Handle<Object> Object::NewStorageFor(Isolate* isolate, |
| 302 Handle<Object> object, | 295 Handle<Object> object, |
| 303 Representation representation) { | 296 Representation representation) { |
| 304 if (representation.IsSmi() && object->IsUninitialized()) { | 297 if (representation.IsSmi() && object->IsUninitialized(isolate)) { |
| 305 return handle(Smi::FromInt(0), isolate); | 298 return handle(Smi::FromInt(0), isolate); |
| 306 } | 299 } |
| 307 if (!representation.IsDouble()) return object; | 300 if (!representation.IsDouble()) return object; |
| 308 double value; | 301 double value; |
| 309 if (object->IsUninitialized()) { | 302 if (object->IsUninitialized(isolate)) { |
| 310 value = 0; | 303 value = 0; |
| 311 } else if (object->IsMutableHeapNumber()) { | 304 } else if (object->IsMutableHeapNumber()) { |
| 312 value = HeapNumber::cast(*object)->value(); | 305 value = HeapNumber::cast(*object)->value(); |
| 313 } else { | 306 } else { |
| 314 value = object->Number(); | 307 value = object->Number(); |
| 315 } | 308 } |
| 316 return isolate->factory()->NewHeapNumber(value, MUTABLE); | 309 return isolate->factory()->NewHeapNumber(value, MUTABLE); |
| 317 } | 310 } |
| 318 | 311 |
| 319 | 312 |
| 320 Handle<Object> Object::WrapForRead(Isolate* isolate, | 313 Handle<Object> Object::WrapForRead(Isolate* isolate, |
| 321 Handle<Object> object, | 314 Handle<Object> object, |
| 322 Representation representation) { | 315 Representation representation) { |
| 323 DCHECK(!object->IsUninitialized()); | 316 DCHECK(!object->IsUninitialized(isolate)); |
| 324 if (!representation.IsDouble()) { | 317 if (!representation.IsDouble()) { |
| 325 DCHECK(object->FitsRepresentation(representation)); | 318 DCHECK(object->FitsRepresentation(representation)); |
| 326 return object; | 319 return object; |
| 327 } | 320 } |
| 328 return isolate->factory()->NewHeapNumber(HeapNumber::cast(*object)->value()); | 321 return isolate->factory()->NewHeapNumber(HeapNumber::cast(*object)->value()); |
| 329 } | 322 } |
| 330 | 323 |
| 331 | 324 |
| 332 StringShape::StringShape(const String* str) | 325 StringShape::StringShape(const String* str) |
| 333 : type_(str->map()->instance_type()) { | 326 : type_(str->map()->instance_type()) { |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 #define MAKE_STRUCT_PREDICATE(NAME, Name, name) \ | 941 #define MAKE_STRUCT_PREDICATE(NAME, Name, name) \ |
| 949 bool Object::Is##Name() const { \ | 942 bool Object::Is##Name() const { \ |
| 950 return IsHeapObject() && HeapObject::cast(this)->Is##Name(); \ | 943 return IsHeapObject() && HeapObject::cast(this)->Is##Name(); \ |
| 951 } \ | 944 } \ |
| 952 bool HeapObject::Is##Name() const { \ | 945 bool HeapObject::Is##Name() const { \ |
| 953 return map()->instance_type() == NAME##_TYPE; \ | 946 return map()->instance_type() == NAME##_TYPE; \ |
| 954 } | 947 } |
| 955 STRUCT_LIST(MAKE_STRUCT_PREDICATE) | 948 STRUCT_LIST(MAKE_STRUCT_PREDICATE) |
| 956 #undef MAKE_STRUCT_PREDICATE | 949 #undef MAKE_STRUCT_PREDICATE |
| 957 | 950 |
| 958 #define MAKE_ODDBALL_PREDICATE(Name) \ | |
| 959 bool HeapObject::Is##Name() const { \ | |
| 960 return IsOddball() && Oddball::cast(this)->kind() == Oddball::k##Name; \ | |
| 961 } | |
| 962 ODDBALL_LIST(MAKE_ODDBALL_PREDICATE) | |
| 963 | |
| 964 #undef MAKE_ODDBALL_PREDICATE | |
| 965 double Object::Number() const { | 951 double Object::Number() const { |
| 966 DCHECK(IsNumber()); | 952 DCHECK(IsNumber()); |
| 967 return IsSmi() | 953 return IsSmi() |
| 968 ? static_cast<double>(reinterpret_cast<const Smi*>(this)->value()) | 954 ? static_cast<double>(reinterpret_cast<const Smi*>(this)->value()) |
| 969 : reinterpret_cast<const HeapNumber*>(this)->value(); | 955 : reinterpret_cast<const HeapNumber*>(this)->value(); |
| 970 } | 956 } |
| 971 | 957 |
| 972 | 958 |
| 973 bool Object::IsNaN() const { | 959 bool Object::IsNaN() const { |
| 974 return this->IsHeapNumber() && std::isnan(HeapNumber::cast(this)->value()); | 960 return this->IsHeapNumber() && std::isnan(HeapNumber::cast(this)->value()); |
| 975 } | 961 } |
| 976 | 962 |
| 977 | 963 |
| 978 bool Object::IsMinusZero() const { | 964 bool Object::IsMinusZero() const { |
| 979 return this->IsHeapNumber() && | 965 return this->IsHeapNumber() && |
| 980 i::IsMinusZero(HeapNumber::cast(this)->value()); | 966 i::IsMinusZero(HeapNumber::cast(this)->value()); |
| 981 } | 967 } |
| 982 | 968 |
| 983 | 969 |
| 984 Representation Object::OptimalRepresentation() { | 970 Representation Object::OptimalRepresentation() { |
| 985 if (!FLAG_track_fields) return Representation::Tagged(); | 971 if (!FLAG_track_fields) return Representation::Tagged(); |
| 986 if (IsSmi()) { | 972 if (IsSmi()) { |
| 987 return Representation::Smi(); | 973 return Representation::Smi(); |
| 988 } else if (FLAG_track_double_fields && IsHeapNumber()) { | 974 } else if (FLAG_track_double_fields && IsHeapNumber()) { |
| 989 return Representation::Double(); | 975 return Representation::Double(); |
| 990 } else if (FLAG_track_computed_fields && IsUninitialized()) { | 976 } else if (FLAG_track_computed_fields && |
| 977 IsUninitialized(HeapObject::cast(this)->GetIsolate())) { |
| 991 return Representation::None(); | 978 return Representation::None(); |
| 992 } else if (FLAG_track_heap_object_fields) { | 979 } else if (FLAG_track_heap_object_fields) { |
| 993 DCHECK(IsHeapObject()); | 980 DCHECK(IsHeapObject()); |
| 994 return Representation::HeapObject(); | 981 return Representation::HeapObject(); |
| 995 } else { | 982 } else { |
| 996 return Representation::Tagged(); | 983 return Representation::Tagged(); |
| 997 } | 984 } |
| 998 } | 985 } |
| 999 | 986 |
| 1000 | 987 |
| (...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2194 } | 2181 } |
| 2195 } | 2182 } |
| 2196 | 2183 |
| 2197 void JSObject::WriteToField(int descriptor, PropertyDetails details, | 2184 void JSObject::WriteToField(int descriptor, PropertyDetails details, |
| 2198 Object* value) { | 2185 Object* value) { |
| 2199 DCHECK(details.type() == DATA); | 2186 DCHECK(details.type() == DATA); |
| 2200 DisallowHeapAllocation no_gc; | 2187 DisallowHeapAllocation no_gc; |
| 2201 FieldIndex index = FieldIndex::ForDescriptor(map(), descriptor); | 2188 FieldIndex index = FieldIndex::ForDescriptor(map(), descriptor); |
| 2202 if (details.representation().IsDouble()) { | 2189 if (details.representation().IsDouble()) { |
| 2203 // Nothing more to be done. | 2190 // Nothing more to be done. |
| 2204 if (value->IsUninitialized()) return; | 2191 if (value->IsUninitialized(this->GetIsolate())) { |
| 2192 return; |
| 2193 } |
| 2205 if (IsUnboxedDoubleField(index)) { | 2194 if (IsUnboxedDoubleField(index)) { |
| 2206 RawFastDoublePropertyAtPut(index, value->Number()); | 2195 RawFastDoublePropertyAtPut(index, value->Number()); |
| 2207 } else { | 2196 } else { |
| 2208 HeapNumber* box = HeapNumber::cast(RawFastPropertyAt(index)); | 2197 HeapNumber* box = HeapNumber::cast(RawFastPropertyAt(index)); |
| 2209 DCHECK(box->IsMutableHeapNumber()); | 2198 DCHECK(box->IsMutableHeapNumber()); |
| 2210 box->set_value(value->Number()); | 2199 box->set_value(value->Number()); |
| 2211 } | 2200 } |
| 2212 } else { | 2201 } else { |
| 2213 RawFastPropertyAtPut(index, value); | 2202 RawFastPropertyAtPut(index, value); |
| 2214 } | 2203 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2291 return Object::ToUint32(index) && *index != kMaxUInt32; | 2280 return Object::ToUint32(index) && *index != kMaxUInt32; |
| 2292 } | 2281 } |
| 2293 | 2282 |
| 2294 | 2283 |
| 2295 void Object::VerifyApiCallResultType() { | 2284 void Object::VerifyApiCallResultType() { |
| 2296 #if DEBUG | 2285 #if DEBUG |
| 2297 if (IsSmi()) return; | 2286 if (IsSmi()) return; |
| 2298 DCHECK(IsHeapObject()); | 2287 DCHECK(IsHeapObject()); |
| 2299 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); | 2288 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); |
| 2300 if (!(IsString() || IsSymbol() || IsJSReceiver() || IsHeapNumber() || | 2289 if (!(IsString() || IsSymbol() || IsJSReceiver() || IsHeapNumber() || |
| 2301 IsSimd128Value() || IsUndefined(isolate) || IsTrue() || IsFalse() || | 2290 IsSimd128Value() || IsUndefined(isolate) || IsTrue(isolate) || |
| 2302 IsNull())) { | 2291 IsFalse(isolate) || IsNull(isolate))) { |
| 2303 FATAL("API call returned invalid object"); | 2292 FATAL("API call returned invalid object"); |
| 2304 } | 2293 } |
| 2305 #endif // DEBUG | 2294 #endif // DEBUG |
| 2306 } | 2295 } |
| 2307 | 2296 |
| 2308 | 2297 |
| 2309 Object* FixedArray::get(int index) const { | 2298 Object* FixedArray::get(int index) const { |
| 2310 SLOW_DCHECK(index >= 0 && index < this->length()); | 2299 SLOW_DCHECK(index >= 0 && index < this->length()); |
| 2311 return READ_FIELD(this, kHeaderSize + index * kPointerSize); | 2300 return READ_FIELD(this, kHeaderSize + index * kPointerSize); |
| 2312 } | 2301 } |
| (...skipping 2974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5287 BytecodeArray* AbstractCode::GetBytecodeArray() { | 5276 BytecodeArray* AbstractCode::GetBytecodeArray() { |
| 5288 return BytecodeArray::cast(this); | 5277 return BytecodeArray::cast(this); |
| 5289 } | 5278 } |
| 5290 | 5279 |
| 5291 Object* Map::prototype() const { | 5280 Object* Map::prototype() const { |
| 5292 return READ_FIELD(this, kPrototypeOffset); | 5281 return READ_FIELD(this, kPrototypeOffset); |
| 5293 } | 5282 } |
| 5294 | 5283 |
| 5295 | 5284 |
| 5296 void Map::set_prototype(Object* value, WriteBarrierMode mode) { | 5285 void Map::set_prototype(Object* value, WriteBarrierMode mode) { |
| 5297 DCHECK(value->IsNull() || value->IsJSReceiver()); | 5286 DCHECK(value->IsNull(GetIsolate()) || value->IsJSReceiver()); |
| 5298 WRITE_FIELD(this, kPrototypeOffset, value); | 5287 WRITE_FIELD(this, kPrototypeOffset, value); |
| 5299 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kPrototypeOffset, value, mode); | 5288 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kPrototypeOffset, value, mode); |
| 5300 } | 5289 } |
| 5301 | 5290 |
| 5302 | 5291 |
| 5303 LayoutDescriptor* Map::layout_descriptor_gc_safe() { | 5292 LayoutDescriptor* Map::layout_descriptor_gc_safe() { |
| 5304 Object* layout_desc = READ_FIELD(this, kLayoutDecriptorOffset); | 5293 Object* layout_desc = READ_FIELD(this, kLayoutDecriptorOffset); |
| 5305 return LayoutDescriptor::cast_gc_safe(layout_desc); | 5294 return LayoutDescriptor::cast_gc_safe(layout_desc); |
| 5306 } | 5295 } |
| 5307 | 5296 |
| (...skipping 2008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7316 void AccessorPair::set(AccessorComponent component, Object* value) { | 7305 void AccessorPair::set(AccessorComponent component, Object* value) { |
| 7317 if (component == ACCESSOR_GETTER) { | 7306 if (component == ACCESSOR_GETTER) { |
| 7318 set_getter(value); | 7307 set_getter(value); |
| 7319 } else { | 7308 } else { |
| 7320 set_setter(value); | 7309 set_setter(value); |
| 7321 } | 7310 } |
| 7322 } | 7311 } |
| 7323 | 7312 |
| 7324 | 7313 |
| 7325 void AccessorPair::SetComponents(Object* getter, Object* setter) { | 7314 void AccessorPair::SetComponents(Object* getter, Object* setter) { |
| 7326 if (!getter->IsNull()) set_getter(getter); | 7315 Isolate* isolate = GetIsolate(); |
| 7327 if (!setter->IsNull()) set_setter(setter); | 7316 if (!getter->IsNull(isolate)) set_getter(getter); |
| 7317 if (!setter->IsNull(isolate)) set_setter(setter); |
| 7328 } | 7318 } |
| 7329 | 7319 |
| 7330 | 7320 |
| 7331 bool AccessorPair::Equals(AccessorPair* pair) { | 7321 bool AccessorPair::Equals(AccessorPair* pair) { |
| 7332 return (this == pair) || pair->Equals(getter(), setter()); | 7322 return (this == pair) || pair->Equals(getter(), setter()); |
| 7333 } | 7323 } |
| 7334 | 7324 |
| 7335 | 7325 |
| 7336 bool AccessorPair::Equals(Object* getter_value, Object* setter_value) { | 7326 bool AccessorPair::Equals(Object* getter_value, Object* setter_value) { |
| 7337 return (getter() == getter_value) && (setter() == setter_value); | 7327 return (getter() == getter_value) && (setter() == setter_value); |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7913 #undef WRITE_INT64_FIELD | 7903 #undef WRITE_INT64_FIELD |
| 7914 #undef READ_BYTE_FIELD | 7904 #undef READ_BYTE_FIELD |
| 7915 #undef WRITE_BYTE_FIELD | 7905 #undef WRITE_BYTE_FIELD |
| 7916 #undef NOBARRIER_READ_BYTE_FIELD | 7906 #undef NOBARRIER_READ_BYTE_FIELD |
| 7917 #undef NOBARRIER_WRITE_BYTE_FIELD | 7907 #undef NOBARRIER_WRITE_BYTE_FIELD |
| 7918 | 7908 |
| 7919 } // namespace internal | 7909 } // namespace internal |
| 7920 } // namespace v8 | 7910 } // namespace v8 |
| 7921 | 7911 |
| 7922 #endif // V8_OBJECTS_INL_H_ | 7912 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |