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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
49 49
50 int PropertyDetails::field_width_in_words() const { 50 int PropertyDetails::field_width_in_words() const {
51 DCHECK(location() == kField); 51 DCHECK(location() == kField);
52 if (!FLAG_unbox_double_fields) return 1; 52 if (!FLAG_unbox_double_fields) return 1;
53 if (kDoubleSize == kPointerSize) return 1; 53 if (kDoubleSize == kPointerSize) return 1;
54 return representation().IsDouble() ? kDoubleSize / kPointerSize : 1; 54 return representation().IsDouble() ? kDoubleSize / kPointerSize : 1;
55 } 55 }
56 56
57 57 #define TYPE_CHECKER(type, instancetype) \
58 #define TYPE_CHECKER(type, instancetype) \ 58 bool HeapObject::Is##type() const { \
59 bool Object::Is##type() const { \ 59 return map()->instance_type() == instancetype; \
60 return Object::IsHeapObject() && \
61 HeapObject::cast(this)->map()->instance_type() == instancetype; \
62 } 60 }
63 61
64
65 #define CAST_ACCESSOR(type) \ 62 #define CAST_ACCESSOR(type) \
66 type* type::cast(Object* object) { \ 63 type* type::cast(Object* object) { \
67 SLOW_DCHECK(object->Is##type()); \ 64 SLOW_DCHECK(object->Is##type()); \
68 return reinterpret_cast<type*>(object); \ 65 return reinterpret_cast<type*>(object); \
69 } \ 66 } \
70 const type* type::cast(const Object* object) { \ 67 const type* type::cast(const Object* object) { \
71 SLOW_DCHECK(object->Is##type()); \ 68 SLOW_DCHECK(object->Is##type()); \
72 return reinterpret_cast<const type*>(object); \ 69 return reinterpret_cast<const type*>(object); \
73 } 70 }
74 71
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 118
122 119
123 #define BOOL_ACCESSORS(holder, field, name, offset) \ 120 #define BOOL_ACCESSORS(holder, field, name, offset) \
124 bool holder::name() const { \ 121 bool holder::name() const { \
125 return BooleanBit::get(field(), offset); \ 122 return BooleanBit::get(field(), offset); \
126 } \ 123 } \
127 void holder::set_##name(bool value) { \ 124 void holder::set_##name(bool value) { \
128 set_##field(BooleanBit::set(field(), offset, value)); \ 125 set_##field(BooleanBit::set(field(), offset, value)); \
129 } 126 }
130 127
131 128 bool HeapObject::IsFixedArrayBase() const {
132 bool Object::IsFixedArrayBase() const {
133 return IsFixedArray() || IsFixedDoubleArray() || IsFixedTypedArrayBase(); 129 return IsFixedArray() || IsFixedDoubleArray() || IsFixedTypedArrayBase();
134 } 130 }
135 131
136 132 bool HeapObject::IsFixedArray() const {
137 bool Object::IsFixedArray() const { 133 InstanceType instance_type = map()->instance_type();
138 if (!IsHeapObject()) return false;
139 InstanceType instance_type = HeapObject::cast(this)->map()->instance_type();
140 return instance_type == FIXED_ARRAY_TYPE || 134 return instance_type == FIXED_ARRAY_TYPE ||
141 instance_type == TRANSITION_ARRAY_TYPE; 135 instance_type == TRANSITION_ARRAY_TYPE;
142 } 136 }
143 137
144 138
145 // External objects are not extensible, so the map check is enough. 139 // External objects are not extensible, so the map check is enough.
146 bool Object::IsExternal() const { 140 bool HeapObject::IsExternal() const {
147 return Object::IsHeapObject() && 141 return map() == GetHeap()->external_map();
148 HeapObject::cast(this)->map() ==
149 HeapObject::cast(this)->GetHeap()->external_map();
150 } 142 }
151 143
152 144
153 TYPE_CHECKER(HeapNumber, HEAP_NUMBER_TYPE) 145 TYPE_CHECKER(HeapNumber, HEAP_NUMBER_TYPE)
154 TYPE_CHECKER(MutableHeapNumber, MUTABLE_HEAP_NUMBER_TYPE) 146 TYPE_CHECKER(MutableHeapNumber, MUTABLE_HEAP_NUMBER_TYPE)
155 TYPE_CHECKER(Symbol, SYMBOL_TYPE) 147 TYPE_CHECKER(Symbol, SYMBOL_TYPE)
156 TYPE_CHECKER(Simd128Value, SIMD128_VALUE_TYPE) 148 TYPE_CHECKER(Simd128Value, SIMD128_VALUE_TYPE)
157 149
158
159 #define SIMD128_TYPE_CHECKER(TYPE, Type, type, lane_count, lane_type) \ 150 #define SIMD128_TYPE_CHECKER(TYPE, Type, type, lane_count, lane_type) \
160 bool Object::Is##Type() const { \ 151 bool HeapObject::Is##Type() const { return map() == GetHeap()->type##_map(); }
161 return Object::IsHeapObject() && \
162 HeapObject::cast(this)->map() == \
163 HeapObject::cast(this)->GetHeap()->type##_map(); \
164 }
165 SIMD128_TYPES(SIMD128_TYPE_CHECKER) 152 SIMD128_TYPES(SIMD128_TYPE_CHECKER)
166 #undef SIMD128_TYPE_CHECKER 153 #undef SIMD128_TYPE_CHECKER
167 154
155 #define IS_TYPE_FUNCTION_DEF(type_) \
156 bool Object::Is##type_() const { \
157 return IsHeapObject() && HeapObject::cast(this)->Is##type_(); \
158 }
159 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DEF)
160 ODDBALL_LIST(IS_TYPE_FUNCTION_DEF)
161 #undef IS_TYPE_FUNCTION_DEF
168 162
169 bool Object::IsString() const { 163 bool HeapObject::IsString() const {
170 return Object::IsHeapObject() 164 return map()->instance_type() < FIRST_NONSTRING_TYPE;
171 && HeapObject::cast(this)->map()->instance_type() < FIRST_NONSTRING_TYPE;
172 } 165 }
173 166
174 167 bool HeapObject::IsName() const {
175 bool Object::IsName() const { 168 return map()->instance_type() <= LAST_NAME_TYPE;
176 STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
177 return Object::IsHeapObject() &&
178 HeapObject::cast(this)->map()->instance_type() <= LAST_NAME_TYPE;
179 } 169 }
180 170
181 171 bool HeapObject::IsUniqueName() const {
182 bool Object::IsUniqueName() const {
183 return IsInternalizedString() || IsSymbol(); 172 return IsInternalizedString() || IsSymbol();
184 } 173 }
185 174
186 175 bool HeapObject::IsFunction() const {
187 bool Object::IsFunction() const {
188 STATIC_ASSERT(LAST_FUNCTION_TYPE == LAST_TYPE); 176 STATIC_ASSERT(LAST_FUNCTION_TYPE == LAST_TYPE);
189 return Object::IsHeapObject() && 177 return map()->instance_type() >= FIRST_FUNCTION_TYPE;
190 HeapObject::cast(this)->map()->instance_type() >= FIRST_FUNCTION_TYPE;
191 } 178 }
192 179
180 bool HeapObject::IsCallable() const { return map()->is_callable(); }
193 181
194 bool Object::IsCallable() const { 182 bool HeapObject::IsConstructor() const { return map()->is_constructor(); }
195 return Object::IsHeapObject() && HeapObject::cast(this)->map()->is_callable();
196 }
197 183
198 184 bool HeapObject::IsTemplateInfo() const {
199 bool Object::IsConstructor() const {
200 return Object::IsHeapObject() &&
201 HeapObject::cast(this)->map()->is_constructor();
202 }
203
204
205 bool Object::IsTemplateInfo() const {
206 return IsObjectTemplateInfo() || IsFunctionTemplateInfo(); 185 return IsObjectTemplateInfo() || IsFunctionTemplateInfo();
207 } 186 }
208 187
209 188 bool HeapObject::IsInternalizedString() const {
210 bool Object::IsInternalizedString() const { 189 uint32_t type = map()->instance_type();
211 if (!this->IsHeapObject()) return false;
212 uint32_t type = HeapObject::cast(this)->map()->instance_type();
213 STATIC_ASSERT(kNotInternalizedTag != 0); 190 STATIC_ASSERT(kNotInternalizedTag != 0);
214 return (type & (kIsNotStringMask | kIsNotInternalizedMask)) == 191 return (type & (kIsNotStringMask | kIsNotInternalizedMask)) ==
215 (kStringTag | kInternalizedTag); 192 (kStringTag | kInternalizedTag);
216 } 193 }
217 194
218 195 bool HeapObject::IsConsString() const {
219 bool Object::IsConsString() const {
220 if (!IsString()) return false; 196 if (!IsString()) return false;
221 return StringShape(String::cast(this)).IsCons(); 197 return StringShape(String::cast(this)).IsCons();
222 } 198 }
223 199
224 200 bool HeapObject::IsSlicedString() const {
225 bool Object::IsSlicedString() const {
226 if (!IsString()) return false; 201 if (!IsString()) return false;
227 return StringShape(String::cast(this)).IsSliced(); 202 return StringShape(String::cast(this)).IsSliced();
228 } 203 }
229 204
230 205 bool HeapObject::IsSeqString() const {
231 bool Object::IsSeqString() const {
232 if (!IsString()) return false; 206 if (!IsString()) return false;
233 return StringShape(String::cast(this)).IsSequential(); 207 return StringShape(String::cast(this)).IsSequential();
234 } 208 }
235 209
236 210 bool HeapObject::IsSeqOneByteString() const {
237 bool Object::IsSeqOneByteString() const {
238 if (!IsString()) return false; 211 if (!IsString()) return false;
239 return StringShape(String::cast(this)).IsSequential() && 212 return StringShape(String::cast(this)).IsSequential() &&
240 String::cast(this)->IsOneByteRepresentation(); 213 String::cast(this)->IsOneByteRepresentation();
241 } 214 }
242 215
243 216 bool HeapObject::IsSeqTwoByteString() const {
244 bool Object::IsSeqTwoByteString() const {
245 if (!IsString()) return false; 217 if (!IsString()) return false;
246 return StringShape(String::cast(this)).IsSequential() && 218 return StringShape(String::cast(this)).IsSequential() &&
247 String::cast(this)->IsTwoByteRepresentation(); 219 String::cast(this)->IsTwoByteRepresentation();
248 } 220 }
249 221
250 222 bool HeapObject::IsExternalString() const {
251 bool Object::IsExternalString() const {
252 if (!IsString()) return false; 223 if (!IsString()) return false;
253 return StringShape(String::cast(this)).IsExternal(); 224 return StringShape(String::cast(this)).IsExternal();
254 } 225 }
255 226
256 227 bool HeapObject::IsExternalOneByteString() const {
257 bool Object::IsExternalOneByteString() const {
258 if (!IsString()) return false; 228 if (!IsString()) return false;
259 return StringShape(String::cast(this)).IsExternal() && 229 return StringShape(String::cast(this)).IsExternal() &&
260 String::cast(this)->IsOneByteRepresentation(); 230 String::cast(this)->IsOneByteRepresentation();
261 } 231 }
262 232
263 233 bool HeapObject::IsExternalTwoByteString() const {
264 bool Object::IsExternalTwoByteString() const {
265 if (!IsString()) return false; 234 if (!IsString()) return false;
266 return StringShape(String::cast(this)).IsExternal() && 235 return StringShape(String::cast(this)).IsExternal() &&
267 String::cast(this)->IsTwoByteRepresentation(); 236 String::cast(this)->IsTwoByteRepresentation();
268 } 237 }
269 238
270 239
271 bool Object::HasValidElements() { 240 bool Object::HasValidElements() {
272 // Dictionary is covered under FixedArray. 241 // Dictionary is covered under FixedArray.
273 return IsFixedArray() || IsFixedDoubleArray() || IsFixedTypedArrayBase(); 242 return IsFixedArray() || IsFixedDoubleArray() || IsFixedTypedArrayBase();
274 } 243 }
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 623
655 bool Object::IsNumber() const { 624 bool Object::IsNumber() const {
656 return IsSmi() || IsHeapNumber(); 625 return IsSmi() || IsHeapNumber();
657 } 626 }
658 627
659 628
660 TYPE_CHECKER(ByteArray, BYTE_ARRAY_TYPE) 629 TYPE_CHECKER(ByteArray, BYTE_ARRAY_TYPE)
661 TYPE_CHECKER(BytecodeArray, BYTECODE_ARRAY_TYPE) 630 TYPE_CHECKER(BytecodeArray, BYTECODE_ARRAY_TYPE)
662 TYPE_CHECKER(FreeSpace, FREE_SPACE_TYPE) 631 TYPE_CHECKER(FreeSpace, FREE_SPACE_TYPE)
663 632
664 633 bool HeapObject::IsFiller() const {
665 bool Object::IsFiller() const { 634 InstanceType instance_type = map()->instance_type();
666 if (!Object::IsHeapObject()) return false;
667 InstanceType instance_type = HeapObject::cast(this)->map()->instance_type();
668 return instance_type == FREE_SPACE_TYPE || instance_type == FILLER_TYPE; 635 return instance_type == FREE_SPACE_TYPE || instance_type == FILLER_TYPE;
669 } 636 }
670 637
671 638
672 639
673 #define TYPED_ARRAY_TYPE_CHECKER(Type, type, TYPE, ctype, size) \ 640 #define TYPED_ARRAY_TYPE_CHECKER(Type, type, TYPE, ctype, size) \
674 TYPE_CHECKER(Fixed##Type##Array, FIXED_##TYPE##_ARRAY_TYPE) 641 TYPE_CHECKER(Fixed##Type##Array, FIXED_##TYPE##_ARRAY_TYPE)
675 642
676 TYPED_ARRAYS(TYPED_ARRAY_TYPE_CHECKER) 643 TYPED_ARRAYS(TYPED_ARRAY_TYPE_CHECKER)
677 #undef TYPED_ARRAY_TYPE_CHECKER 644 #undef TYPED_ARRAY_TYPE_CHECKER
678 645
679 646 bool HeapObject::IsFixedTypedArrayBase() const {
680 bool Object::IsFixedTypedArrayBase() const { 647 InstanceType instance_type = map()->instance_type();
681 if (!Object::IsHeapObject()) return false;
682
683 InstanceType instance_type =
684 HeapObject::cast(this)->map()->instance_type();
685 return (instance_type >= FIRST_FIXED_TYPED_ARRAY_TYPE && 648 return (instance_type >= FIRST_FIXED_TYPED_ARRAY_TYPE &&
686 instance_type <= LAST_FIXED_TYPED_ARRAY_TYPE); 649 instance_type <= LAST_FIXED_TYPED_ARRAY_TYPE);
687 } 650 }
688 651
689 652 bool HeapObject::IsJSReceiver() const {
690 bool Object::IsJSReceiver() const {
691 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE); 653 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
692 return IsHeapObject() && 654 return map()->instance_type() >= FIRST_JS_RECEIVER_TYPE;
693 HeapObject::cast(this)->map()->instance_type() >= FIRST_JS_RECEIVER_TYPE;
694 } 655 }
695 656
696 657 bool HeapObject::IsJSObject() const {
697 bool Object::IsJSObject() const {
698 STATIC_ASSERT(LAST_JS_OBJECT_TYPE == LAST_TYPE); 658 STATIC_ASSERT(LAST_JS_OBJECT_TYPE == LAST_TYPE);
699 return IsHeapObject() && HeapObject::cast(this)->map()->IsJSObjectMap(); 659 return map()->IsJSObjectMap();
700 } 660 }
701 661
702 662 bool HeapObject::IsJSProxy() const { return map()->IsJSProxyMap(); }
703 bool Object::IsJSProxy() const {
704 if (!Object::IsHeapObject()) return false;
705 return HeapObject::cast(this)->map()->IsJSProxyMap();
706 }
707
708 663
709 TYPE_CHECKER(JSSet, JS_SET_TYPE) 664 TYPE_CHECKER(JSSet, JS_SET_TYPE)
710 TYPE_CHECKER(JSMap, JS_MAP_TYPE) 665 TYPE_CHECKER(JSMap, JS_MAP_TYPE)
711 TYPE_CHECKER(JSSetIterator, JS_SET_ITERATOR_TYPE) 666 TYPE_CHECKER(JSSetIterator, JS_SET_ITERATOR_TYPE)
712 TYPE_CHECKER(JSMapIterator, JS_MAP_ITERATOR_TYPE) 667 TYPE_CHECKER(JSMapIterator, JS_MAP_ITERATOR_TYPE)
713 TYPE_CHECKER(JSWeakMap, JS_WEAK_MAP_TYPE) 668 TYPE_CHECKER(JSWeakMap, JS_WEAK_MAP_TYPE)
714 TYPE_CHECKER(JSWeakSet, JS_WEAK_SET_TYPE) 669 TYPE_CHECKER(JSWeakSet, JS_WEAK_SET_TYPE)
715 TYPE_CHECKER(JSContextExtensionObject, JS_CONTEXT_EXTENSION_OBJECT_TYPE) 670 TYPE_CHECKER(JSContextExtensionObject, JS_CONTEXT_EXTENSION_OBJECT_TYPE)
716 TYPE_CHECKER(Map, MAP_TYPE) 671 TYPE_CHECKER(Map, MAP_TYPE)
717 TYPE_CHECKER(FixedDoubleArray, FIXED_DOUBLE_ARRAY_TYPE) 672 TYPE_CHECKER(FixedDoubleArray, FIXED_DOUBLE_ARRAY_TYPE)
718 TYPE_CHECKER(WeakFixedArray, FIXED_ARRAY_TYPE) 673 TYPE_CHECKER(WeakFixedArray, FIXED_ARRAY_TYPE)
719 TYPE_CHECKER(TransitionArray, TRANSITION_ARRAY_TYPE) 674 TYPE_CHECKER(TransitionArray, TRANSITION_ARRAY_TYPE)
720 675
721 676 bool HeapObject::IsJSWeakCollection() const {
722 bool Object::IsJSWeakCollection() const {
723 return IsJSWeakMap() || IsJSWeakSet(); 677 return IsJSWeakMap() || IsJSWeakSet();
724 } 678 }
725 679
680 bool HeapObject::IsDescriptorArray() const { return IsFixedArray(); }
726 681
727 bool Object::IsDescriptorArray() const { 682 bool HeapObject::IsArrayList() const { return IsFixedArray(); }
728 return IsFixedArray();
729 }
730
731
732 bool Object::IsArrayList() const { return IsFixedArray(); }
733
734 683
735 bool Object::IsLayoutDescriptor() const { 684 bool Object::IsLayoutDescriptor() const {
736 return IsSmi() || IsFixedTypedArrayBase(); 685 return IsSmi() || IsFixedTypedArrayBase();
737 } 686 }
738 687
688 bool HeapObject::IsTypeFeedbackVector() const { return IsFixedArray(); }
739 689
740 bool Object::IsTypeFeedbackVector() const { return IsFixedArray(); } 690 bool HeapObject::IsTypeFeedbackMetadata() const { return IsFixedArray(); }
741 691
692 bool HeapObject::IsLiteralsArray() const { return IsFixedArray(); }
742 693
743 bool Object::IsTypeFeedbackMetadata() const { return IsFixedArray(); } 694 bool HeapObject::IsDeoptimizationInputData() const {
744
745
746 bool Object::IsLiteralsArray() const { return IsFixedArray(); }
747
748
749 bool Object::IsDeoptimizationInputData() const {
750 // Must be a fixed array. 695 // Must be a fixed array.
751 if (!IsFixedArray()) return false; 696 if (!IsFixedArray()) return false;
752 697
753 // There's no sure way to detect the difference between a fixed array and 698 // There's no sure way to detect the difference between a fixed array and
754 // a deoptimization data array. Since this is used for asserts we can 699 // a deoptimization data array. Since this is used for asserts we can
755 // check that the length is zero or else the fixed size plus a multiple of 700 // check that the length is zero or else the fixed size plus a multiple of
756 // the entry size. 701 // the entry size.
757 int length = FixedArray::cast(this)->length(); 702 int length = FixedArray::cast(this)->length();
758 if (length == 0) return true; 703 if (length == 0) return true;
759 704
760 length -= DeoptimizationInputData::kFirstDeoptEntryIndex; 705 length -= DeoptimizationInputData::kFirstDeoptEntryIndex;
761 return length >= 0 && length % DeoptimizationInputData::kDeoptEntrySize == 0; 706 return length >= 0 && length % DeoptimizationInputData::kDeoptEntrySize == 0;
762 } 707 }
763 708
764 709 bool HeapObject::IsDeoptimizationOutputData() const {
765 bool Object::IsDeoptimizationOutputData() const {
766 if (!IsFixedArray()) return false; 710 if (!IsFixedArray()) return false;
767 // There's actually no way to see the difference between a fixed array and 711 // There's actually no way to see the difference between a fixed array and
768 // a deoptimization data array. Since this is used for asserts we can check 712 // a deoptimization data array. Since this is used for asserts we can check
769 // that the length is plausible though. 713 // that the length is plausible though.
770 if (FixedArray::cast(this)->length() % 2 != 0) return false; 714 if (FixedArray::cast(this)->length() % 2 != 0) return false;
771 return true; 715 return true;
772 } 716 }
773 717
774 718 bool HeapObject::IsHandlerTable() const {
775 bool Object::IsHandlerTable() const {
776 if (!IsFixedArray()) return false; 719 if (!IsFixedArray()) return false;
777 // There's actually no way to see the difference between a fixed array and 720 // There's actually no way to see the difference between a fixed array and
778 // a handler table array. 721 // a handler table array.
779 return true; 722 return true;
780 } 723 }
781 724
782 725 bool HeapObject::IsDependentCode() const {
783 bool Object::IsDependentCode() const {
784 if (!IsFixedArray()) return false; 726 if (!IsFixedArray()) return false;
785 // There's actually no way to see the difference between a fixed array and 727 // There's actually no way to see the difference between a fixed array and
786 // a dependent codes array. 728 // a dependent codes array.
787 return true; 729 return true;
788 } 730 }
789 731
790 732 bool HeapObject::IsContext() const {
791 bool Object::IsContext() const { 733 Map* map = this->map();
792 if (!Object::IsHeapObject()) return false; 734 Heap* heap = GetHeap();
793 Map* map = HeapObject::cast(this)->map();
794 Heap* heap = map->GetHeap();
795 return (map == heap->function_context_map() || 735 return (map == heap->function_context_map() ||
796 map == heap->catch_context_map() || 736 map == heap->catch_context_map() ||
797 map == heap->with_context_map() || 737 map == heap->with_context_map() ||
798 map == heap->native_context_map() || 738 map == heap->native_context_map() ||
799 map == heap->block_context_map() || 739 map == heap->block_context_map() ||
800 map == heap->module_context_map() || 740 map == heap->module_context_map() ||
801 map == heap->script_context_map()); 741 map == heap->script_context_map());
802 } 742 }
803 743
744 bool HeapObject::IsNativeContext() const {
745 return map() == GetHeap()->native_context_map();
746 }
804 747
805 bool Object::IsNativeContext() const { 748 bool HeapObject::IsScriptContextTable() const {
806 return Object::IsHeapObject() && 749 return map() == GetHeap()->script_context_table_map();
807 HeapObject::cast(this)->map() == 750 }
808 HeapObject::cast(this)->GetHeap()->native_context_map(); 751
752 bool HeapObject::IsScopeInfo() const {
753 return map() == GetHeap()->scope_info_map();
809 } 754 }
810 755
811 756
812 bool Object::IsScriptContextTable() const {
813 if (!Object::IsHeapObject()) return false;
814 Map* map = HeapObject::cast(this)->map();
815 Heap* heap = map->GetHeap();
816 return map == heap->script_context_table_map();
817 }
818
819
820 bool Object::IsScopeInfo() const {
821 return Object::IsHeapObject() &&
822 HeapObject::cast(this)->map() ==
823 HeapObject::cast(this)->GetHeap()->scope_info_map();
824 }
825
826
827 TYPE_CHECKER(JSBoundFunction, JS_BOUND_FUNCTION_TYPE) 757 TYPE_CHECKER(JSBoundFunction, JS_BOUND_FUNCTION_TYPE)
828 TYPE_CHECKER(JSFunction, JS_FUNCTION_TYPE) 758 TYPE_CHECKER(JSFunction, JS_FUNCTION_TYPE)
829 759
830 760
831 template <> inline bool Is<JSFunction>(Object* obj) { 761 template <> inline bool Is<JSFunction>(Object* obj) {
832 return obj->IsJSFunction(); 762 return obj->IsJSFunction();
833 } 763 }
834 764
835 765
836 TYPE_CHECKER(Code, CODE_TYPE) 766 TYPE_CHECKER(Code, CODE_TYPE)
837 TYPE_CHECKER(Oddball, ODDBALL_TYPE) 767 TYPE_CHECKER(Oddball, ODDBALL_TYPE)
838 TYPE_CHECKER(Cell, CELL_TYPE) 768 TYPE_CHECKER(Cell, CELL_TYPE)
839 TYPE_CHECKER(PropertyCell, PROPERTY_CELL_TYPE) 769 TYPE_CHECKER(PropertyCell, PROPERTY_CELL_TYPE)
840 TYPE_CHECKER(WeakCell, WEAK_CELL_TYPE) 770 TYPE_CHECKER(WeakCell, WEAK_CELL_TYPE)
841 TYPE_CHECKER(SharedFunctionInfo, SHARED_FUNCTION_INFO_TYPE) 771 TYPE_CHECKER(SharedFunctionInfo, SHARED_FUNCTION_INFO_TYPE)
842 TYPE_CHECKER(JSGeneratorObject, JS_GENERATOR_OBJECT_TYPE) 772 TYPE_CHECKER(JSGeneratorObject, JS_GENERATOR_OBJECT_TYPE)
843 TYPE_CHECKER(JSModule, JS_MODULE_TYPE) 773 TYPE_CHECKER(JSModule, JS_MODULE_TYPE)
844 TYPE_CHECKER(JSValue, JS_VALUE_TYPE) 774 TYPE_CHECKER(JSValue, JS_VALUE_TYPE)
845 TYPE_CHECKER(JSDate, JS_DATE_TYPE) 775 TYPE_CHECKER(JSDate, JS_DATE_TYPE)
846 TYPE_CHECKER(JSMessageObject, JS_MESSAGE_OBJECT_TYPE) 776 TYPE_CHECKER(JSMessageObject, JS_MESSAGE_OBJECT_TYPE)
847 777
848 bool Object::IsAbstractCode() const { return IsBytecodeArray() || IsCode(); } 778 bool HeapObject::IsAbstractCode() const {
779 return IsBytecodeArray() || IsCode();
780 }
849 781
850 bool Object::IsStringWrapper() const { 782 bool HeapObject::IsStringWrapper() const {
851 return IsJSValue() && JSValue::cast(this)->value()->IsString(); 783 return IsJSValue() && JSValue::cast(this)->value()->IsString();
852 } 784 }
853 785
854 786
855 TYPE_CHECKER(Foreign, FOREIGN_TYPE) 787 TYPE_CHECKER(Foreign, FOREIGN_TYPE)
856 788
857 789 bool HeapObject::IsBoolean() const {
858 bool Object::IsBoolean() const {
859 return IsOddball() && 790 return IsOddball() &&
860 ((Oddball::cast(this)->kind() & Oddball::kNotBooleanMask) == 0); 791 ((Oddball::cast(this)->kind() & Oddball::kNotBooleanMask) == 0);
861 } 792 }
862 793
863 794
864 TYPE_CHECKER(JSArray, JS_ARRAY_TYPE) 795 TYPE_CHECKER(JSArray, JS_ARRAY_TYPE)
865 TYPE_CHECKER(JSArrayBuffer, JS_ARRAY_BUFFER_TYPE) 796 TYPE_CHECKER(JSArrayBuffer, JS_ARRAY_BUFFER_TYPE)
866 TYPE_CHECKER(JSTypedArray, JS_TYPED_ARRAY_TYPE) 797 TYPE_CHECKER(JSTypedArray, JS_TYPED_ARRAY_TYPE)
867 TYPE_CHECKER(JSDataView, JS_DATA_VIEW_TYPE) 798 TYPE_CHECKER(JSDataView, JS_DATA_VIEW_TYPE)
868 799
869 800 bool HeapObject::IsJSArrayBufferView() const {
870 bool Object::IsJSArrayBufferView() const {
871 return IsJSDataView() || IsJSTypedArray(); 801 return IsJSDataView() || IsJSTypedArray();
872 } 802 }
873 803
874 804
875 TYPE_CHECKER(JSRegExp, JS_REGEXP_TYPE) 805 TYPE_CHECKER(JSRegExp, JS_REGEXP_TYPE)
876 806
877 807
878 template <> inline bool Is<JSArray>(Object* obj) { 808 template <> inline bool Is<JSArray>(Object* obj) {
879 return obj->IsJSArray(); 809 return obj->IsJSArray();
880 } 810 }
881 811
812 bool HeapObject::IsHashTable() const {
813 return map() == GetHeap()->hash_table_map();
814 }
882 815
883 bool Object::IsHashTable() const { 816 bool HeapObject::IsWeakHashTable() const { return IsHashTable(); }
884 return Object::IsHeapObject() && 817
885 HeapObject::cast(this)->map() == 818 bool HeapObject::IsDictionary() const {
886 HeapObject::cast(this)->GetHeap()->hash_table_map(); 819 return IsHashTable() && this != GetHeap()->string_table();
887 } 820 }
888 821
889 822
890 bool Object::IsWeakHashTable() const {
891 return IsHashTable();
892 }
893
894
895 bool Object::IsDictionary() const {
896 return IsHashTable() &&
897 this != HeapObject::cast(this)->GetHeap()->string_table();
898 }
899
900
901 bool Object::IsNameDictionary() const { 823 bool Object::IsNameDictionary() const {
902 return IsDictionary(); 824 return IsDictionary();
903 } 825 }
904 826
905 827
906 bool Object::IsGlobalDictionary() const { return IsDictionary(); } 828 bool Object::IsGlobalDictionary() const { return IsDictionary(); }
907 829
908 830
909 bool Object::IsSeededNumberDictionary() const { 831 bool Object::IsSeededNumberDictionary() const {
910 return IsDictionary(); 832 return IsDictionary();
911 } 833 }
912 834
913 835
914 bool Object::IsUnseededNumberDictionary() const { 836 bool Object::IsUnseededNumberDictionary() const {
915 return IsDictionary(); 837 return IsDictionary();
916 } 838 }
917 839
840 bool HeapObject::IsStringTable() const { return IsHashTable(); }
918 841
919 bool Object::IsStringTable() const { 842 bool HeapObject::IsNormalizedMapCache() const {
920 return IsHashTable();
921 }
922
923
924 bool Object::IsNormalizedMapCache() const {
925 return NormalizedMapCache::IsNormalizedMapCache(this); 843 return NormalizedMapCache::IsNormalizedMapCache(this);
926 } 844 }
927 845
928 846
929 int NormalizedMapCache::GetIndex(Handle<Map> map) { 847 int NormalizedMapCache::GetIndex(Handle<Map> map) {
930 return map->Hash() % NormalizedMapCache::kEntries; 848 return map->Hash() % NormalizedMapCache::kEntries;
931 } 849 }
932 850
933 851 bool NormalizedMapCache::IsNormalizedMapCache(const HeapObject* obj) {
934 bool NormalizedMapCache::IsNormalizedMapCache(const Object* obj) {
935 if (!obj->IsFixedArray()) return false; 852 if (!obj->IsFixedArray()) return false;
936 if (FixedArray::cast(obj)->length() != NormalizedMapCache::kEntries) { 853 if (FixedArray::cast(obj)->length() != NormalizedMapCache::kEntries) {
937 return false; 854 return false;
938 } 855 }
939 #ifdef VERIFY_HEAP 856 #ifdef VERIFY_HEAP
940 if (FLAG_verify_heap) { 857 if (FLAG_verify_heap) {
941 reinterpret_cast<NormalizedMapCache*>(const_cast<Object*>(obj))-> 858 reinterpret_cast<NormalizedMapCache*>(const_cast<HeapObject*>(obj))
942 NormalizedMapCacheVerify(); 859 ->NormalizedMapCacheVerify();
943 } 860 }
944 #endif 861 #endif
945 return true; 862 return true;
946 } 863 }
947 864
865 bool HeapObject::IsCompilationCacheTable() const { return IsHashTable(); }
948 866
949 bool Object::IsCompilationCacheTable() const { 867 bool HeapObject::IsCodeCacheHashTable() const { return IsHashTable(); }
868
869 bool HeapObject::IsPolymorphicCodeCacheHashTable() const {
950 return IsHashTable(); 870 return IsHashTable();
951 } 871 }
952 872
873 bool HeapObject::IsMapCache() const { return IsHashTable(); }
953 874
954 bool Object::IsCodeCacheHashTable() const { 875 bool HeapObject::IsObjectHashTable() const { return IsHashTable(); }
955 return IsHashTable(); 876
877 bool HeapObject::IsOrderedHashTable() const {
878 return map() == GetHeap()->ordered_hash_table_map();
956 } 879 }
957 880
958 881
959 bool Object::IsPolymorphicCodeCacheHashTable() const {
960 return IsHashTable();
961 }
962
963
964 bool Object::IsMapCache() const {
965 return IsHashTable();
966 }
967
968
969 bool Object::IsObjectHashTable() const {
970 return IsHashTable();
971 }
972
973
974 bool Object::IsOrderedHashTable() const {
975 return IsHeapObject() &&
976 HeapObject::cast(this)->map() ==
977 HeapObject::cast(this)->GetHeap()->ordered_hash_table_map();
978 }
979
980
981 bool Object::IsOrderedHashSet() const { 882 bool Object::IsOrderedHashSet() const {
982 return IsOrderedHashTable(); 883 return IsOrderedHashTable();
983 } 884 }
984 885
985 886
986 bool Object::IsOrderedHashMap() const { 887 bool Object::IsOrderedHashMap() const {
987 return IsOrderedHashTable(); 888 return IsOrderedHashTable();
988 } 889 }
989 890
990 891
991 bool Object::IsPrimitive() const { 892 bool Object::IsPrimitive() const {
992 return IsSmi() || HeapObject::cast(this)->map()->IsPrimitiveMap(); 893 return IsSmi() || HeapObject::cast(this)->map()->IsPrimitiveMap();
993 } 894 }
994 895
995 896 bool HeapObject::IsJSGlobalProxy() const {
996 bool Object::IsJSGlobalProxy() const { 897 bool result = map()->instance_type() == JS_GLOBAL_PROXY_TYPE;
997 bool result = IsHeapObject() && 898 DCHECK(!result || map()->is_access_check_needed());
998 (HeapObject::cast(this)->map()->instance_type() ==
999 JS_GLOBAL_PROXY_TYPE);
1000 DCHECK(!result ||
1001 HeapObject::cast(this)->map()->is_access_check_needed());
1002 return result; 899 return result;
1003 } 900 }
1004 901
1005 902
1006 TYPE_CHECKER(JSGlobalObject, JS_GLOBAL_OBJECT_TYPE) 903 TYPE_CHECKER(JSGlobalObject, JS_GLOBAL_OBJECT_TYPE)
1007 904
1008 905 bool HeapObject::IsUndetectableObject() const {
1009 bool Object::IsUndetectableObject() const { 906 return map()->is_undetectable();
1010 return IsHeapObject()
1011 && HeapObject::cast(this)->map()->is_undetectable();
1012 } 907 }
1013 908
1014 909 bool HeapObject::IsAccessCheckNeeded() const {
1015 bool Object::IsAccessCheckNeeded() const {
1016 if (!IsHeapObject()) return false;
1017 if (IsJSGlobalProxy()) { 910 if (IsJSGlobalProxy()) {
1018 const JSGlobalProxy* proxy = JSGlobalProxy::cast(this); 911 const JSGlobalProxy* proxy = JSGlobalProxy::cast(this);
1019 JSGlobalObject* global = proxy->GetIsolate()->context()->global_object(); 912 JSGlobalObject* global = proxy->GetIsolate()->context()->global_object();
1020 return proxy->IsDetachedFrom(global); 913 return proxy->IsDetachedFrom(global);
1021 } 914 }
1022 return HeapObject::cast(this)->map()->is_access_check_needed(); 915 return map()->is_access_check_needed();
1023 } 916 }
1024 917
1025 918 bool HeapObject::IsStruct() const {
1026 bool Object::IsStruct() const { 919 switch (map()->instance_type()) {
1027 if (!IsHeapObject()) return false;
1028 switch (HeapObject::cast(this)->map()->instance_type()) {
1029 #define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return true; 920 #define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return true;
1030 STRUCT_LIST(MAKE_STRUCT_CASE) 921 STRUCT_LIST(MAKE_STRUCT_CASE)
1031 #undef MAKE_STRUCT_CASE 922 #undef MAKE_STRUCT_CASE
1032 default: return false; 923 default: return false;
1033 } 924 }
1034 } 925 }
1035 926
1036 927 #define MAKE_STRUCT_PREDICATE(NAME, Name, name) \
1037 #define MAKE_STRUCT_PREDICATE(NAME, Name, name) \ 928 bool Object::Is##Name() const { \
1038 bool Object::Is##Name() const { \ 929 return IsHeapObject() && HeapObject::cast(this)->Is##Name(); \
1039 return Object::IsHeapObject() \ 930 } \
1040 && HeapObject::cast(this)->map()->instance_type() == NAME##_TYPE; \ 931 bool HeapObject::Is##Name() const { \
932 return map()->instance_type() == NAME##_TYPE; \
1041 } 933 }
1042 STRUCT_LIST(MAKE_STRUCT_PREDICATE) 934 STRUCT_LIST(MAKE_STRUCT_PREDICATE)
1043 #undef MAKE_STRUCT_PREDICATE 935 #undef MAKE_STRUCT_PREDICATE
1044 936
937 #define MAKE_ODDBALL_PREDICATE(Name) \
938 bool HeapObject::Is##Name() const { \
939 return IsOddball() && Oddball::cast(this)->kind() == Oddball::k##Name; \
940 }
941 ODDBALL_LIST(MAKE_ODDBALL_PREDICATE)
1045 942
1046 bool Object::IsUndefined() const { 943 #undef MAKE_ODDBALL_PREDICATE
1047 return IsOddball() && Oddball::cast(this)->kind() == Oddball::kUndefined;
1048 }
1049
1050
1051 bool Object::IsNull() const {
1052 return IsOddball() && Oddball::cast(this)->kind() == Oddball::kNull;
1053 }
1054
1055
1056 bool Object::IsTheHole() const {
1057 return IsOddball() && Oddball::cast(this)->kind() == Oddball::kTheHole;
1058 }
1059
1060
1061 bool Object::IsException() const {
1062 return IsOddball() && Oddball::cast(this)->kind() == Oddball::kException;
1063 }
1064
1065
1066 bool Object::IsUninitialized() const {
1067 return IsOddball() && Oddball::cast(this)->kind() == Oddball::kUninitialized;
1068 }
1069
1070
1071 bool Object::IsTrue() const {
1072 return IsOddball() && Oddball::cast(this)->kind() == Oddball::kTrue;
1073 }
1074
1075
1076 bool Object::IsFalse() const {
1077 return IsOddball() && Oddball::cast(this)->kind() == Oddball::kFalse;
1078 }
1079
1080
1081 bool Object::IsArgumentsMarker() const {
1082 return IsOddball() && Oddball::cast(this)->kind() == Oddball::kArgumentMarker;
1083 }
1084
1085
1086 double Object::Number() const { 944 double Object::Number() const {
1087 DCHECK(IsNumber()); 945 DCHECK(IsNumber());
1088 return IsSmi() 946 return IsSmi()
1089 ? static_cast<double>(reinterpret_cast<const Smi*>(this)->value()) 947 ? static_cast<double>(reinterpret_cast<const Smi*>(this)->value())
1090 : reinterpret_cast<const HeapNumber*>(this)->value(); 948 : reinterpret_cast<const HeapNumber*>(this)->value();
1091 } 949 }
1092 950
1093 951
1094 bool Object::IsNaN() const { 952 bool Object::IsNaN() const {
1095 return this->IsHeapNumber() && std::isnan(HeapNumber::cast(this)->value()); 953 return this->IsHeapNumber() && std::isnan(HeapNumber::cast(this)->value());
(...skipping 5663 matching lines...) Expand 10 before | Expand all | Expand 10 after
6759 bool JSObject::HasSlowStringWrapperElements() { 6617 bool JSObject::HasSlowStringWrapperElements() {
6760 return GetElementsKind() == SLOW_STRING_WRAPPER_ELEMENTS; 6618 return GetElementsKind() == SLOW_STRING_WRAPPER_ELEMENTS;
6761 } 6619 }
6762 6620
6763 bool JSObject::HasFixedTypedArrayElements() { 6621 bool JSObject::HasFixedTypedArrayElements() {
6764 HeapObject* array = elements(); 6622 HeapObject* array = elements();
6765 DCHECK(array != NULL); 6623 DCHECK(array != NULL);
6766 return array->IsFixedTypedArrayBase(); 6624 return array->IsFixedTypedArrayBase();
6767 } 6625 }
6768 6626
6769 6627 #define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size) \
6770 #define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size) \ 6628 bool JSObject::HasFixed##Type##Elements() { \
6771 bool JSObject::HasFixed##Type##Elements() { \ 6629 HeapObject* array = elements(); \
6772 HeapObject* array = elements(); \ 6630 DCHECK(array != NULL); \
6773 DCHECK(array != NULL); \ 6631 if (!array->IsHeapObject()) return false; \
6774 if (!array->IsHeapObject()) \ 6632 return array->map()->instance_type() == FIXED_##TYPE##_ARRAY_TYPE; \
6775 return false; \ 6633 }
6776 return array->map()->instance_type() == FIXED_##TYPE##_ARRAY_TYPE; \
6777 }
6778 6634
6779 TYPED_ARRAYS(FIXED_TYPED_ELEMENTS_CHECK) 6635 TYPED_ARRAYS(FIXED_TYPED_ELEMENTS_CHECK)
6780 6636
6781 #undef FIXED_TYPED_ELEMENTS_CHECK 6637 #undef FIXED_TYPED_ELEMENTS_CHECK
6782 6638
6783 6639
6784 bool JSObject::HasNamedInterceptor() { 6640 bool JSObject::HasNamedInterceptor() {
6785 return map()->has_named_interceptor(); 6641 return map()->has_named_interceptor();
6786 } 6642 }
6787 6643
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after
7844 #undef WRITE_INT64_FIELD 7700 #undef WRITE_INT64_FIELD
7845 #undef READ_BYTE_FIELD 7701 #undef READ_BYTE_FIELD
7846 #undef WRITE_BYTE_FIELD 7702 #undef WRITE_BYTE_FIELD
7847 #undef NOBARRIER_READ_BYTE_FIELD 7703 #undef NOBARRIER_READ_BYTE_FIELD
7848 #undef NOBARRIER_WRITE_BYTE_FIELD 7704 #undef NOBARRIER_WRITE_BYTE_FIELD
7849 7705
7850 } // namespace internal 7706 } // namespace internal
7851 } // namespace v8 7707 } // namespace v8
7852 7708
7853 #endif // V8_OBJECTS_INL_H_ 7709 #endif // V8_OBJECTS_INL_H_
OLDNEW
« 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