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 6666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6677 | 6677 |
6678 | 6678 |
6679 bool JSArrayBuffer::is_shared() { return IsShared::decode(bit_field()); } | 6679 bool JSArrayBuffer::is_shared() { return IsShared::decode(bit_field()); } |
6680 | 6680 |
6681 | 6681 |
6682 void JSArrayBuffer::set_is_shared(bool value) { | 6682 void JSArrayBuffer::set_is_shared(bool value) { |
6683 set_bit_field(IsShared::update(bit_field(), value)); | 6683 set_bit_field(IsShared::update(bit_field(), value)); |
6684 } | 6684 } |
6685 | 6685 |
6686 | 6686 |
6687 // static | |
6688 template <typename StaticVisitor> | |
6689 void JSArrayBuffer::JSArrayBufferIterateBody(Heap* heap, HeapObject* obj) { | |
6690 StaticVisitor::VisitPointers( | |
6691 heap, obj, | |
6692 HeapObject::RawField(obj, JSArrayBuffer::BodyDescriptor::kStartOffset), | |
6693 HeapObject::RawField(obj, | |
6694 JSArrayBuffer::kByteLengthOffset + kPointerSize)); | |
6695 StaticVisitor::VisitPointers( | |
6696 heap, obj, HeapObject::RawField(obj, JSArrayBuffer::kSize), | |
6697 HeapObject::RawField(obj, JSArrayBuffer::kSizeWithInternalFields)); | |
6698 } | |
6699 | |
6700 | |
6701 void JSArrayBuffer::JSArrayBufferIterateBody(HeapObject* obj, | |
6702 ObjectVisitor* v) { | |
6703 v->VisitPointers( | |
6704 HeapObject::RawField(obj, JSArrayBuffer::BodyDescriptor::kStartOffset), | |
6705 HeapObject::RawField(obj, | |
6706 JSArrayBuffer::kByteLengthOffset + kPointerSize)); | |
6707 v->VisitPointers( | |
6708 HeapObject::RawField(obj, JSArrayBuffer::kSize), | |
6709 HeapObject::RawField(obj, JSArrayBuffer::kSizeWithInternalFields)); | |
6710 } | |
6711 | |
6712 | |
6713 Object* JSArrayBufferView::byte_offset() const { | 6687 Object* JSArrayBufferView::byte_offset() const { |
6714 if (WasNeutered()) return Smi::FromInt(0); | 6688 if (WasNeutered()) return Smi::FromInt(0); |
6715 return Object::cast(READ_FIELD(this, kByteOffsetOffset)); | 6689 return Object::cast(READ_FIELD(this, kByteOffsetOffset)); |
6716 } | 6690 } |
6717 | 6691 |
6718 | 6692 |
6719 void JSArrayBufferView::set_byte_offset(Object* value, WriteBarrierMode mode) { | 6693 void JSArrayBufferView::set_byte_offset(Object* value, WriteBarrierMode mode) { |
6720 WRITE_FIELD(this, kByteOffsetOffset, value); | 6694 WRITE_FIELD(this, kByteOffsetOffset, value); |
6721 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kByteOffsetOffset, value, mode); | 6695 CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kByteOffsetOffset, value, mode); |
6722 } | 6696 } |
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7861 } | 7835 } |
7862 | 7836 |
7863 | 7837 |
7864 template<typename StaticVisitor> | 7838 template<typename StaticVisitor> |
7865 void Foreign::ForeignIterateBody() { | 7839 void Foreign::ForeignIterateBody() { |
7866 StaticVisitor::VisitExternalReference( | 7840 StaticVisitor::VisitExternalReference( |
7867 reinterpret_cast<Address*>(FIELD_ADDR(this, kForeignAddressOffset))); | 7841 reinterpret_cast<Address*>(FIELD_ADDR(this, kForeignAddressOffset))); |
7868 } | 7842 } |
7869 | 7843 |
7870 | 7844 |
7871 void FixedTypedArrayBase::FixedTypedArrayBaseIterateBody(ObjectVisitor* v) { | |
7872 v->VisitPointer( | |
7873 reinterpret_cast<Object**>(FIELD_ADDR(this, kBasePointerOffset))); | |
7874 } | |
7875 | |
7876 | |
7877 template <typename StaticVisitor> | |
7878 void FixedTypedArrayBase::FixedTypedArrayBaseIterateBody() { | |
7879 StaticVisitor::VisitPointer( | |
7880 reinterpret_cast<Object**>(FIELD_ADDR(this, kBasePointerOffset))); | |
7881 } | |
7882 | |
7883 | |
7884 void ExternalOneByteString::ExternalOneByteStringIterateBody(ObjectVisitor* v) { | 7845 void ExternalOneByteString::ExternalOneByteStringIterateBody(ObjectVisitor* v) { |
7885 typedef v8::String::ExternalOneByteStringResource Resource; | 7846 typedef v8::String::ExternalOneByteStringResource Resource; |
7886 v->VisitExternalOneByteString( | 7847 v->VisitExternalOneByteString( |
7887 reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); | 7848 reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); |
7888 } | 7849 } |
7889 | 7850 |
7890 | 7851 |
7891 template <typename StaticVisitor> | 7852 template <typename StaticVisitor> |
7892 void ExternalOneByteString::ExternalOneByteStringIterateBody() { | 7853 void ExternalOneByteString::ExternalOneByteStringIterateBody() { |
7893 typedef v8::String::ExternalOneByteStringResource Resource; | 7854 typedef v8::String::ExternalOneByteStringResource Resource; |
(...skipping 10 matching lines...) Expand all Loading... |
7904 | 7865 |
7905 | 7866 |
7906 template<typename StaticVisitor> | 7867 template<typename StaticVisitor> |
7907 void ExternalTwoByteString::ExternalTwoByteStringIterateBody() { | 7868 void ExternalTwoByteString::ExternalTwoByteStringIterateBody() { |
7908 typedef v8::String::ExternalStringResource Resource; | 7869 typedef v8::String::ExternalStringResource Resource; |
7909 StaticVisitor::VisitExternalTwoByteString( | 7870 StaticVisitor::VisitExternalTwoByteString( |
7910 reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); | 7871 reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); |
7911 } | 7872 } |
7912 | 7873 |
7913 | 7874 |
| 7875 template <typename ObjectVisitor> |
7914 void BodyDescriptorBase::IterateBodyImpl(HeapObject* obj, int start_offset, | 7876 void BodyDescriptorBase::IterateBodyImpl(HeapObject* obj, int start_offset, |
7915 int end_offset, ObjectVisitor* v) { | 7877 int end_offset, ObjectVisitor* v) { |
7916 if (!FLAG_unbox_double_fields || obj->map()->HasFastPointerLayout()) { | 7878 if (!FLAG_unbox_double_fields || obj->map()->HasFastPointerLayout()) { |
7917 IteratePointers(obj, start_offset, end_offset, v); | 7879 IteratePointers(obj, start_offset, end_offset, v); |
7918 } else { | 7880 } else { |
7919 DCHECK(FLAG_unbox_double_fields); | 7881 DCHECK(FLAG_unbox_double_fields); |
7920 DCHECK(IsAligned(start_offset, kPointerSize) && | 7882 DCHECK(IsAligned(start_offset, kPointerSize) && |
7921 IsAligned(end_offset, kPointerSize)); | 7883 IsAligned(end_offset, kPointerSize)); |
7922 | 7884 |
7923 LayoutDescriptorHelper helper(obj->map()); | 7885 LayoutDescriptorHelper helper(obj->map()); |
(...skipping 25 matching lines...) Expand all Loading... |
7949 int end_of_region_offset; | 7911 int end_of_region_offset; |
7950 if (helper.IsTagged(offset, end_offset, &end_of_region_offset)) { | 7912 if (helper.IsTagged(offset, end_offset, &end_of_region_offset)) { |
7951 IteratePointers<StaticVisitor>(heap, obj, offset, end_of_region_offset); | 7913 IteratePointers<StaticVisitor>(heap, obj, offset, end_of_region_offset); |
7952 } | 7914 } |
7953 offset = end_of_region_offset; | 7915 offset = end_of_region_offset; |
7954 } | 7916 } |
7955 } | 7917 } |
7956 } | 7918 } |
7957 | 7919 |
7958 | 7920 |
| 7921 template <typename ObjectVisitor> |
7959 void BodyDescriptorBase::IteratePointers(HeapObject* obj, int start_offset, | 7922 void BodyDescriptorBase::IteratePointers(HeapObject* obj, int start_offset, |
7960 int end_offset, ObjectVisitor* v) { | 7923 int end_offset, ObjectVisitor* v) { |
7961 v->VisitPointers(HeapObject::RawField(obj, start_offset), | 7924 v->VisitPointers(HeapObject::RawField(obj, start_offset), |
7962 HeapObject::RawField(obj, end_offset)); | 7925 HeapObject::RawField(obj, end_offset)); |
7963 } | 7926 } |
7964 | 7927 |
7965 | 7928 |
7966 template <typename StaticVisitor> | 7929 template <typename StaticVisitor> |
7967 void BodyDescriptorBase::IteratePointers(Heap* heap, HeapObject* obj, | 7930 void BodyDescriptorBase::IteratePointers(Heap* heap, HeapObject* obj, |
7968 int start_offset, int end_offset) { | 7931 int start_offset, int end_offset) { |
7969 StaticVisitor::VisitPointers(heap, obj, | 7932 StaticVisitor::VisitPointers(heap, obj, |
7970 HeapObject::RawField(obj, start_offset), | 7933 HeapObject::RawField(obj, start_offset), |
7971 HeapObject::RawField(obj, end_offset)); | 7934 HeapObject::RawField(obj, end_offset)); |
7972 } | 7935 } |
7973 | 7936 |
7974 | 7937 |
| 7938 template <typename ObjectVisitor> |
| 7939 void BodyDescriptorBase::IteratePointer(HeapObject* obj, int offset, |
| 7940 ObjectVisitor* v) { |
| 7941 v->VisitPointer(HeapObject::RawField(obj, offset)); |
| 7942 } |
| 7943 |
| 7944 |
| 7945 template <typename StaticVisitor> |
| 7946 void BodyDescriptorBase::IteratePointer(Heap* heap, HeapObject* obj, |
| 7947 int offset) { |
| 7948 StaticVisitor::VisitPointer(heap, obj, HeapObject::RawField(obj, offset)); |
| 7949 } |
| 7950 |
| 7951 |
7975 // Iterates the function object according to the visiting policy. | 7952 // Iterates the function object according to the visiting policy. |
7976 template <JSFunction::BodyVisitingPolicy body_visiting_policy> | 7953 template <JSFunction::BodyVisitingPolicy body_visiting_policy> |
7977 class JSFunction::BodyDescriptorImpl : public BodyDescriptorBase { | 7954 class JSFunction::BodyDescriptorImpl : public BodyDescriptorBase { |
7978 public: | 7955 public: |
7979 STATIC_ASSERT(kNonWeakFieldsEndOffset == kCodeEntryOffset); | 7956 STATIC_ASSERT(kNonWeakFieldsEndOffset == kCodeEntryOffset); |
7980 STATIC_ASSERT(kCodeEntryOffset + kPointerSize == kNextFunctionLinkOffset); | 7957 STATIC_ASSERT(kCodeEntryOffset + kPointerSize == kNextFunctionLinkOffset); |
7981 STATIC_ASSERT(kNextFunctionLinkOffset + kPointerSize == kSize); | 7958 STATIC_ASSERT(kNextFunctionLinkOffset + kPointerSize == kSize); |
7982 | 7959 |
| 7960 template <typename ObjectVisitor> |
7983 static inline void IterateBody(HeapObject* obj, int object_size, | 7961 static inline void IterateBody(HeapObject* obj, int object_size, |
7984 ObjectVisitor* v) { | 7962 ObjectVisitor* v) { |
7985 IteratePointers(obj, kPropertiesOffset, kNonWeakFieldsEndOffset, v); | 7963 IteratePointers(obj, kPropertiesOffset, kNonWeakFieldsEndOffset, v); |
7986 | 7964 |
7987 if (body_visiting_policy & kVisitCodeEntry) { | 7965 if (body_visiting_policy & kVisitCodeEntry) { |
7988 v->VisitCodeEntry(obj->address() + kCodeEntryOffset); | 7966 v->VisitCodeEntry(obj->address() + kCodeEntryOffset); |
7989 } | 7967 } |
7990 | 7968 |
7991 if (body_visiting_policy & kVisitNextFunction) { | 7969 if (body_visiting_policy & kVisitNextFunction) { |
7992 IteratePointers(obj, kNextFunctionLinkOffset, kSize, v); | 7970 IteratePointers(obj, kNextFunctionLinkOffset, kSize, v); |
(...skipping 25 matching lines...) Expand all Loading... |
8018 } | 7996 } |
8019 | 7997 |
8020 static inline int SizeOf(Map* map, HeapObject* object) { | 7998 static inline int SizeOf(Map* map, HeapObject* object) { |
8021 // TODO(ishell): v8:4531, fix when JFunctions are allowed to have in-object | 7999 // TODO(ishell): v8:4531, fix when JFunctions are allowed to have in-object |
8022 // properties | 8000 // properties |
8023 return JSFunction::kSize; | 8001 return JSFunction::kSize; |
8024 } | 8002 } |
8025 }; | 8003 }; |
8026 | 8004 |
8027 | 8005 |
| 8006 class JSArrayBuffer::BodyDescriptor : public BodyDescriptorBase { |
| 8007 public: |
| 8008 STATIC_ASSERT(kByteLengthOffset + kPointerSize == kBackingStoreOffset); |
| 8009 STATIC_ASSERT(kBackingStoreOffset + kPointerSize == kBitFieldSlot); |
| 8010 STATIC_ASSERT(kBitFieldSlot + kPointerSize == kSize); |
| 8011 |
| 8012 template <typename ObjectVisitor> |
| 8013 static inline void IterateBody(HeapObject* obj, int object_size, |
| 8014 ObjectVisitor* v) { |
| 8015 IteratePointers(obj, kPropertiesOffset, kBackingStoreOffset, v); |
| 8016 IteratePointers(obj, kSize, kSizeWithInternalFields, v); |
| 8017 |
| 8018 // TODO(ishell): v8:4531, fix when JSArrayBuffers are allowed to have |
| 8019 // in-object properties |
| 8020 // IterateBodyImpl(obj, kSize, object_size, v); |
| 8021 } |
| 8022 |
| 8023 template <typename StaticVisitor> |
| 8024 static inline void IterateBody(HeapObject* obj, int object_size) { |
| 8025 Heap* heap = obj->GetHeap(); |
| 8026 IteratePointers<StaticVisitor>(heap, obj, kPropertiesOffset, |
| 8027 kBackingStoreOffset); |
| 8028 IteratePointers<StaticVisitor>(heap, obj, kSize, kSizeWithInternalFields); |
| 8029 |
| 8030 // TODO(ishell): v8:4531, fix when JSArrayBuffers are allowed to have |
| 8031 // in-object properties |
| 8032 // IterateBodyImpl<StaticVisitor>(heap, obj, kSize, object_size); |
| 8033 } |
| 8034 |
| 8035 static inline int SizeOf(Map* map, HeapObject* object) { |
| 8036 // TODO(ishell): v8:4531, fix when JSArrayBuffers are allowed to have |
| 8037 // in-object properties |
| 8038 // return map->instance_size(); |
| 8039 return kSizeWithInternalFields; |
| 8040 } |
| 8041 }; |
| 8042 |
| 8043 |
| 8044 class BytecodeArray::BodyDescriptor : public BodyDescriptorBase { |
| 8045 public: |
| 8046 template <typename ObjectVisitor> |
| 8047 static inline void IterateBody(HeapObject* obj, int object_size, |
| 8048 ObjectVisitor* v) { |
| 8049 IteratePointer(obj, kConstantPoolOffset, v); |
| 8050 } |
| 8051 |
| 8052 template <typename StaticVisitor> |
| 8053 static inline void IterateBody(HeapObject* obj, int object_size) { |
| 8054 Heap* heap = obj->GetHeap(); |
| 8055 IteratePointer<StaticVisitor>(heap, obj, kConstantPoolOffset); |
| 8056 } |
| 8057 |
| 8058 static inline int SizeOf(Map* map, HeapObject* object) { |
| 8059 return SizeFor( |
| 8060 reinterpret_cast<FixedArray*>(object)->synchronized_length()); |
| 8061 } |
| 8062 }; |
| 8063 |
| 8064 |
| 8065 class FixedTypedArrayBase::BodyDescriptor : public BodyDescriptorBase { |
| 8066 public: |
| 8067 template <typename ObjectVisitor> |
| 8068 static inline void IterateBody(HeapObject* obj, int object_size, |
| 8069 ObjectVisitor* v) { |
| 8070 IteratePointer(obj, kBasePointerOffset, v); |
| 8071 } |
| 8072 |
| 8073 template <typename StaticVisitor> |
| 8074 static inline void IterateBody(HeapObject* obj, int object_size) { |
| 8075 Heap* heap = obj->GetHeap(); |
| 8076 IteratePointer<StaticVisitor>(heap, obj, kBasePointerOffset); |
| 8077 } |
| 8078 |
| 8079 static inline int SizeOf(Map* map, HeapObject* object) { |
| 8080 return reinterpret_cast<FixedTypedArrayBase*>(object)->size(); |
| 8081 } |
| 8082 }; |
| 8083 |
| 8084 |
| 8085 class JSWeakCollection::BodyDescriptor : public BodyDescriptorBase { |
| 8086 public: |
| 8087 template <typename ObjectVisitor> |
| 8088 static inline void IterateBody(HeapObject* obj, int object_size, |
| 8089 ObjectVisitor* v) { |
| 8090 IteratePointers(obj, kPropertiesOffset, kSize, v); |
| 8091 |
| 8092 // TODO(ishell): v8:4531, fix when JSWeakCollection are allowed to have |
| 8093 // in-object properties |
| 8094 // IterateBodyImpl(obj, kSize, object_size, v); |
| 8095 } |
| 8096 |
| 8097 template <typename StaticVisitor> |
| 8098 static inline void IterateBody(HeapObject* obj, int object_size) { |
| 8099 Heap* heap = obj->GetHeap(); |
| 8100 IteratePointers<StaticVisitor>(heap, obj, kPropertiesOffset, kSize); |
| 8101 |
| 8102 // TODO(ishell): v8:4531, fix when JSWeakCollection are allowed to have |
| 8103 // in-object properties |
| 8104 // IterateBodyImpl<StaticVisitor>(heap, obj, kSize, object_size); |
| 8105 } |
| 8106 |
| 8107 static inline int SizeOf(Map* map, HeapObject* object) { return kSize; } |
| 8108 }; |
| 8109 |
| 8110 |
8028 template<class Derived, class TableType> | 8111 template<class Derived, class TableType> |
8029 Object* OrderedHashTableIterator<Derived, TableType>::CurrentKey() { | 8112 Object* OrderedHashTableIterator<Derived, TableType>::CurrentKey() { |
8030 TableType* table(TableType::cast(this->table())); | 8113 TableType* table(TableType::cast(this->table())); |
8031 int index = Smi::cast(this->index())->value(); | 8114 int index = Smi::cast(this->index())->value(); |
8032 Object* key = table->KeyAt(index); | 8115 Object* key = table->KeyAt(index); |
8033 DCHECK(!key->IsTheHole()); | 8116 DCHECK(!key->IsTheHole()); |
8034 return key; | 8117 return key; |
8035 } | 8118 } |
8036 | 8119 |
8037 | 8120 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8151 #undef WRITE_INT64_FIELD | 8234 #undef WRITE_INT64_FIELD |
8152 #undef READ_BYTE_FIELD | 8235 #undef READ_BYTE_FIELD |
8153 #undef WRITE_BYTE_FIELD | 8236 #undef WRITE_BYTE_FIELD |
8154 #undef NOBARRIER_READ_BYTE_FIELD | 8237 #undef NOBARRIER_READ_BYTE_FIELD |
8155 #undef NOBARRIER_WRITE_BYTE_FIELD | 8238 #undef NOBARRIER_WRITE_BYTE_FIELD |
8156 | 8239 |
8157 } // namespace internal | 8240 } // namespace internal |
8158 } // namespace v8 | 8241 } // namespace v8 |
8159 | 8242 |
8160 #endif // V8_OBJECTS_INL_H_ | 8243 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |