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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 TYPE_CHECKER(HeapNumber, HEAP_NUMBER_TYPE) | 148 TYPE_CHECKER(HeapNumber, HEAP_NUMBER_TYPE) |
149 TYPE_CHECKER(MutableHeapNumber, MUTABLE_HEAP_NUMBER_TYPE) | 149 TYPE_CHECKER(MutableHeapNumber, MUTABLE_HEAP_NUMBER_TYPE) |
150 TYPE_CHECKER(Symbol, SYMBOL_TYPE) | 150 TYPE_CHECKER(Symbol, SYMBOL_TYPE) |
151 TYPE_CHECKER(Simd128Value, SIMD128_VALUE_TYPE) | 151 TYPE_CHECKER(Simd128Value, SIMD128_VALUE_TYPE) |
152 | 152 |
153 #define SIMD128_TYPE_CHECKER(TYPE, Type, type, lane_count, lane_type) \ | 153 #define SIMD128_TYPE_CHECKER(TYPE, Type, type, lane_count, lane_type) \ |
154 bool HeapObject::Is##Type() const { return map() == GetHeap()->type##_map(); } | 154 bool HeapObject::Is##Type() const { return map() == GetHeap()->type##_map(); } |
155 SIMD128_TYPES(SIMD128_TYPE_CHECKER) | 155 SIMD128_TYPES(SIMD128_TYPE_CHECKER) |
156 #undef SIMD128_TYPE_CHECKER | 156 #undef SIMD128_TYPE_CHECKER |
157 | 157 |
158 // TODO(cbruni): remove once all the isolate-based versions are in place. | 158 // TODO(cbruni): remove once all the isolate-based versions are in place. |
Michael Starzinger
2016/06/08 15:58:20
nit: This TODO should actually be addressed by thi
| |
159 #define IS_TYPE_FUNCTION_DEF(type_) \ | 159 #define IS_TYPE_FUNCTION_DEF(type_) \ |
160 bool Object::Is##type_() const { \ | 160 bool Object::Is##type_() const { \ |
161 return IsHeapObject() && HeapObject::cast(this)->Is##type_(); \ | 161 return IsHeapObject() && HeapObject::cast(this)->Is##type_(); \ |
162 } | 162 } |
163 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DEF) | 163 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DEF) |
164 #undef IS_TYPE_FUNCTION_DEF | |
165 | |
166 #define IS_TYPE_FUNCTION_DEF(Type, Value) \ | |
167 bool Object::Is##Type(Isolate* isolate) const { \ | |
168 return this == isolate->heap()->Value(); \ | |
169 } \ | |
170 bool HeapObject::Is##Type(Isolate* isolate) const { \ | |
171 return this == isolate->heap()->Value(); \ | |
172 } | |
164 ODDBALL_LIST(IS_TYPE_FUNCTION_DEF) | 173 ODDBALL_LIST(IS_TYPE_FUNCTION_DEF) |
165 #undef IS_TYPE_FUNCTION_DEF | 174 #undef IS_TYPE_FUNCTION_DEF |
166 | 175 |
167 bool HeapObject::IsTheHole(Isolate* isolate) const { | |
168 return this == isolate->heap()->the_hole_value(); | |
169 } | |
170 | |
171 bool HeapObject::IsUndefined(Isolate* isolate) const { | |
172 return this == isolate->heap()->undefined_value(); | |
173 } | |
174 | |
175 bool Object::IsTheHole(Isolate* isolate) const { | |
176 return this == isolate->heap()->the_hole_value(); | |
177 } | |
178 | |
179 bool Object::IsUndefined(Isolate* isolate) const { | |
180 return this == isolate->heap()->undefined_value(); | |
181 } | |
182 | |
183 bool HeapObject::IsString() const { | 176 bool HeapObject::IsString() const { |
184 return map()->instance_type() < FIRST_NONSTRING_TYPE; | 177 return map()->instance_type() < FIRST_NONSTRING_TYPE; |
185 } | 178 } |
186 | 179 |
187 bool HeapObject::IsName() const { | 180 bool HeapObject::IsName() const { |
188 return map()->instance_type() <= LAST_NAME_TYPE; | 181 return map()->instance_type() <= LAST_NAME_TYPE; |
189 } | 182 } |
190 | 183 |
191 bool HeapObject::IsUniqueName() const { | 184 bool HeapObject::IsUniqueName() const { |
192 return IsInternalizedString() || IsSymbol(); | 185 return IsInternalizedString() || IsSymbol(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 } else { | 286 } else { |
294 if (filter & SKIP_STRINGS) return true; | 287 if (filter & SKIP_STRINGS) return true; |
295 } | 288 } |
296 return false; | 289 return false; |
297 } | 290 } |
298 | 291 |
299 | 292 |
300 Handle<Object> Object::NewStorageFor(Isolate* isolate, | 293 Handle<Object> Object::NewStorageFor(Isolate* isolate, |
301 Handle<Object> object, | 294 Handle<Object> object, |
302 Representation representation) { | 295 Representation representation) { |
303 if (representation.IsSmi() && object->IsUninitialized()) { | 296 if (representation.IsSmi() && object->IsUninitialized(isolate)) { |
304 return handle(Smi::FromInt(0), isolate); | 297 return handle(Smi::FromInt(0), isolate); |
305 } | 298 } |
306 if (!representation.IsDouble()) return object; | 299 if (!representation.IsDouble()) return object; |
307 double value; | 300 double value; |
308 if (object->IsUninitialized()) { | 301 if (object->IsUninitialized(isolate)) { |
309 value = 0; | 302 value = 0; |
310 } else if (object->IsMutableHeapNumber()) { | 303 } else if (object->IsMutableHeapNumber()) { |
311 value = HeapNumber::cast(*object)->value(); | 304 value = HeapNumber::cast(*object)->value(); |
312 } else { | 305 } else { |
313 value = object->Number(); | 306 value = object->Number(); |
314 } | 307 } |
315 return isolate->factory()->NewHeapNumber(value, MUTABLE); | 308 return isolate->factory()->NewHeapNumber(value, MUTABLE); |
316 } | 309 } |
317 | 310 |
318 | 311 |
319 Handle<Object> Object::WrapForRead(Isolate* isolate, | 312 Handle<Object> Object::WrapForRead(Isolate* isolate, |
320 Handle<Object> object, | 313 Handle<Object> object, |
321 Representation representation) { | 314 Representation representation) { |
322 DCHECK(!object->IsUninitialized()); | 315 DCHECK(!object->IsUninitialized(isolate)); |
323 if (!representation.IsDouble()) { | 316 if (!representation.IsDouble()) { |
324 DCHECK(object->FitsRepresentation(representation)); | 317 DCHECK(object->FitsRepresentation(representation)); |
325 return object; | 318 return object; |
326 } | 319 } |
327 return isolate->factory()->NewHeapNumber(HeapNumber::cast(*object)->value()); | 320 return isolate->factory()->NewHeapNumber(HeapNumber::cast(*object)->value()); |
328 } | 321 } |
329 | 322 |
330 | 323 |
331 StringShape::StringShape(const String* str) | 324 StringShape::StringShape(const String* str) |
332 : type_(str->map()->instance_type()) { | 325 : type_(str->map()->instance_type()) { |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
947 #define MAKE_STRUCT_PREDICATE(NAME, Name, name) \ | 940 #define MAKE_STRUCT_PREDICATE(NAME, Name, name) \ |
948 bool Object::Is##Name() const { \ | 941 bool Object::Is##Name() const { \ |
949 return IsHeapObject() && HeapObject::cast(this)->Is##Name(); \ | 942 return IsHeapObject() && HeapObject::cast(this)->Is##Name(); \ |
950 } \ | 943 } \ |
951 bool HeapObject::Is##Name() const { \ | 944 bool HeapObject::Is##Name() const { \ |
952 return map()->instance_type() == NAME##_TYPE; \ | 945 return map()->instance_type() == NAME##_TYPE; \ |
953 } | 946 } |
954 STRUCT_LIST(MAKE_STRUCT_PREDICATE) | 947 STRUCT_LIST(MAKE_STRUCT_PREDICATE) |
955 #undef MAKE_STRUCT_PREDICATE | 948 #undef MAKE_STRUCT_PREDICATE |
956 | 949 |
957 #define MAKE_ODDBALL_PREDICATE(Name) \ | |
958 bool HeapObject::Is##Name() const { \ | |
959 return IsOddball() && Oddball::cast(this)->kind() == Oddball::k##Name; \ | |
960 } | |
961 ODDBALL_LIST(MAKE_ODDBALL_PREDICATE) | |
962 | |
963 #undef MAKE_ODDBALL_PREDICATE | |
964 double Object::Number() const { | 950 double Object::Number() const { |
965 DCHECK(IsNumber()); | 951 DCHECK(IsNumber()); |
966 return IsSmi() | 952 return IsSmi() |
967 ? static_cast<double>(reinterpret_cast<const Smi*>(this)->value()) | 953 ? static_cast<double>(reinterpret_cast<const Smi*>(this)->value()) |
968 : reinterpret_cast<const HeapNumber*>(this)->value(); | 954 : reinterpret_cast<const HeapNumber*>(this)->value(); |
969 } | 955 } |
970 | 956 |
971 | 957 |
972 bool Object::IsNaN() const { | 958 bool Object::IsNaN() const { |
973 return this->IsHeapNumber() && std::isnan(HeapNumber::cast(this)->value()); | 959 return this->IsHeapNumber() && std::isnan(HeapNumber::cast(this)->value()); |
974 } | 960 } |
975 | 961 |
976 | 962 |
977 bool Object::IsMinusZero() const { | 963 bool Object::IsMinusZero() const { |
978 return this->IsHeapNumber() && | 964 return this->IsHeapNumber() && |
979 i::IsMinusZero(HeapNumber::cast(this)->value()); | 965 i::IsMinusZero(HeapNumber::cast(this)->value()); |
980 } | 966 } |
981 | 967 |
982 | 968 |
983 Representation Object::OptimalRepresentation() { | 969 Representation Object::OptimalRepresentation() { |
984 if (!FLAG_track_fields) return Representation::Tagged(); | 970 if (!FLAG_track_fields) return Representation::Tagged(); |
985 if (IsSmi()) { | 971 if (IsSmi()) { |
986 return Representation::Smi(); | 972 return Representation::Smi(); |
987 } else if (FLAG_track_double_fields && IsHeapNumber()) { | 973 } else if (FLAG_track_double_fields && IsHeapNumber()) { |
988 return Representation::Double(); | 974 return Representation::Double(); |
989 } else if (FLAG_track_computed_fields && IsUninitialized()) { | 975 } else if (FLAG_track_computed_fields && |
976 IsUninitialized(HeapObject::cast(this)->GetIsolate())) { | |
990 return Representation::None(); | 977 return Representation::None(); |
991 } else if (FLAG_track_heap_object_fields) { | 978 } else if (FLAG_track_heap_object_fields) { |
992 DCHECK(IsHeapObject()); | 979 DCHECK(IsHeapObject()); |
993 return Representation::HeapObject(); | 980 return Representation::HeapObject(); |
994 } else { | 981 } else { |
995 return Representation::Tagged(); | 982 return Representation::Tagged(); |
996 } | 983 } |
997 } | 984 } |
998 | 985 |
999 | 986 |
(...skipping 1194 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->IsSmi() && |
2192 value->IsUninitialized(HeapObject::cast(value)->GetIsolate())) { | |
Michael Starzinger
2016/06/08 15:58:20
nit: Just use "this->GetIsolate()" here, avoiding
Camillo Bruni
2016/06/10 09:28:57
tunnelvision.
| |
2193 return; | |
2194 } | |
2205 if (IsUnboxedDoubleField(index)) { | 2195 if (IsUnboxedDoubleField(index)) { |
2206 RawFastDoublePropertyAtPut(index, value->Number()); | 2196 RawFastDoublePropertyAtPut(index, value->Number()); |
2207 } else { | 2197 } else { |
2208 HeapNumber* box = HeapNumber::cast(RawFastPropertyAt(index)); | 2198 HeapNumber* box = HeapNumber::cast(RawFastPropertyAt(index)); |
2209 DCHECK(box->IsMutableHeapNumber()); | 2199 DCHECK(box->IsMutableHeapNumber()); |
2210 box->set_value(value->Number()); | 2200 box->set_value(value->Number()); |
2211 } | 2201 } |
2212 } else { | 2202 } else { |
2213 RawFastPropertyAtPut(index, value); | 2203 RawFastPropertyAtPut(index, value); |
2214 } | 2204 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2291 return Object::ToUint32(index) && *index != kMaxUInt32; | 2281 return Object::ToUint32(index) && *index != kMaxUInt32; |
2292 } | 2282 } |
2293 | 2283 |
2294 | 2284 |
2295 void Object::VerifyApiCallResultType() { | 2285 void Object::VerifyApiCallResultType() { |
2296 #if DEBUG | 2286 #if DEBUG |
2297 if (IsSmi()) return; | 2287 if (IsSmi()) return; |
2298 DCHECK(IsHeapObject()); | 2288 DCHECK(IsHeapObject()); |
2299 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); | 2289 Isolate* isolate = HeapObject::cast(this)->GetIsolate(); |
2300 if (!(IsString() || IsSymbol() || IsJSReceiver() || IsHeapNumber() || | 2290 if (!(IsString() || IsSymbol() || IsJSReceiver() || IsHeapNumber() || |
2301 IsSimd128Value() || IsUndefined(isolate) || IsTrue() || IsFalse() || | 2291 IsSimd128Value() || IsUndefined(isolate) || IsTrue(isolate) || |
2302 IsNull())) { | 2292 IsFalse(isolate) || IsNull(isolate))) { |
2303 FATAL("API call returned invalid object"); | 2293 FATAL("API call returned invalid object"); |
2304 } | 2294 } |
2305 #endif // DEBUG | 2295 #endif // DEBUG |
2306 } | 2296 } |
2307 | 2297 |
2308 | 2298 |
2309 Object* FixedArray::get(int index) const { | 2299 Object* FixedArray::get(int index) const { |
2310 SLOW_DCHECK(index >= 0 && index < this->length()); | 2300 SLOW_DCHECK(index >= 0 && index < this->length()); |
2311 return READ_FIELD(this, kHeaderSize + index * kPointerSize); | 2301 return READ_FIELD(this, kHeaderSize + index * kPointerSize); |
2312 } | 2302 } |
(...skipping 2990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5303 BytecodeArray* AbstractCode::GetBytecodeArray() { | 5293 BytecodeArray* AbstractCode::GetBytecodeArray() { |
5304 return BytecodeArray::cast(this); | 5294 return BytecodeArray::cast(this); |
5305 } | 5295 } |
5306 | 5296 |
5307 Object* Map::prototype() const { | 5297 Object* Map::prototype() const { |
5308 return READ_FIELD(this, kPrototypeOffset); | 5298 return READ_FIELD(this, kPrototypeOffset); |
5309 } | 5299 } |
5310 | 5300 |
5311 | 5301 |
5312 void Map::set_prototype(Object* value, WriteBarrierMode mode) { | 5302 void Map::set_prototype(Object* value, WriteBarrierMode mode) { |
5313 DCHECK(value->IsNull() || value->IsJSReceiver()); | 5303 DCHECK(value->IsNull(GetIsolate()) || value->IsJSReceiver()); |
5314 WRITE_FIELD(this, kPrototypeOffset, value); | 5304 WRITE_FIELD(this, kPrototypeOffset, value); |
5315 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kPrototypeOffset, value, mode); | 5305 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kPrototypeOffset, value, mode); |
5316 } | 5306 } |
5317 | 5307 |
5318 | 5308 |
5319 LayoutDescriptor* Map::layout_descriptor_gc_safe() { | 5309 LayoutDescriptor* Map::layout_descriptor_gc_safe() { |
5320 Object* layout_desc = READ_FIELD(this, kLayoutDecriptorOffset); | 5310 Object* layout_desc = READ_FIELD(this, kLayoutDecriptorOffset); |
5321 return LayoutDescriptor::cast_gc_safe(layout_desc); | 5311 return LayoutDescriptor::cast_gc_safe(layout_desc); |
5322 } | 5312 } |
5323 | 5313 |
(...skipping 2008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7332 void AccessorPair::set(AccessorComponent component, Object* value) { | 7322 void AccessorPair::set(AccessorComponent component, Object* value) { |
7333 if (component == ACCESSOR_GETTER) { | 7323 if (component == ACCESSOR_GETTER) { |
7334 set_getter(value); | 7324 set_getter(value); |
7335 } else { | 7325 } else { |
7336 set_setter(value); | 7326 set_setter(value); |
7337 } | 7327 } |
7338 } | 7328 } |
7339 | 7329 |
7340 | 7330 |
7341 void AccessorPair::SetComponents(Object* getter, Object* setter) { | 7331 void AccessorPair::SetComponents(Object* getter, Object* setter) { |
7342 if (!getter->IsNull()) set_getter(getter); | 7332 Isolate* isolate = GetIsolate(); |
7343 if (!setter->IsNull()) set_setter(setter); | 7333 if (!getter->IsNull(isolate)) set_getter(getter); |
7334 if (!setter->IsNull(isolate)) set_setter(setter); | |
7344 } | 7335 } |
7345 | 7336 |
7346 | 7337 |
7347 bool AccessorPair::Equals(AccessorPair* pair) { | 7338 bool AccessorPair::Equals(AccessorPair* pair) { |
7348 return (this == pair) || pair->Equals(getter(), setter()); | 7339 return (this == pair) || pair->Equals(getter(), setter()); |
7349 } | 7340 } |
7350 | 7341 |
7351 | 7342 |
7352 bool AccessorPair::Equals(Object* getter_value, Object* setter_value) { | 7343 bool AccessorPair::Equals(Object* getter_value, Object* setter_value) { |
7353 return (getter() == getter_value) && (setter() == setter_value); | 7344 return (getter() == getter_value) && (setter() == setter_value); |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7929 #undef WRITE_INT64_FIELD | 7920 #undef WRITE_INT64_FIELD |
7930 #undef READ_BYTE_FIELD | 7921 #undef READ_BYTE_FIELD |
7931 #undef WRITE_BYTE_FIELD | 7922 #undef WRITE_BYTE_FIELD |
7932 #undef NOBARRIER_READ_BYTE_FIELD | 7923 #undef NOBARRIER_READ_BYTE_FIELD |
7933 #undef NOBARRIER_WRITE_BYTE_FIELD | 7924 #undef NOBARRIER_WRITE_BYTE_FIELD |
7934 | 7925 |
7935 } // namespace internal | 7926 } // namespace internal |
7936 } // namespace v8 | 7927 } // namespace v8 |
7937 | 7928 |
7938 #endif // V8_OBJECTS_INL_H_ | 7929 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |