OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 void mark(); | 219 void mark(); |
220 void unmark(); | 220 void unmark(); |
221 | 221 |
222 Address payload(); | 222 Address payload(); |
223 size_t payloadSize(); | 223 size_t payloadSize(); |
224 Address payloadEnd(); | 224 Address payloadEnd(); |
225 | 225 |
226 // TODO(633030): Make |checkHeader| and |zapMagic| private. This class should | 226 // TODO(633030): Make |checkHeader| and |zapMagic| private. This class should |
227 // manage its integrity on its own, without requiring outside callers to | 227 // manage its integrity on its own, without requiring outside callers to |
228 // explicitly check. | 228 // explicitly check. |
229 bool checkHeader() const; | 229 void checkHeader() const; |
230 | |
230 // Zap magic number with a new magic number that means there was once an | 231 // Zap magic number with a new magic number that means there was once an |
231 // object allocated here, but it was freed because nobody marked it during | 232 // object allocated here, but it was freed because nobody marked it during |
232 // GC. | 233 // GC. |
233 void zapMagic(); | 234 void zapMagic(); |
234 | 235 |
235 void finalize(Address, size_t); | 236 void finalize(Address, size_t); |
236 static HeapObjectHeader* fromPayload(const void*); | 237 static HeapObjectHeader* fromPayload(const void*); |
237 | 238 |
238 static const uint32_t zappedMagic = 0xDEAD4321; | 239 static const uint32_t zappedMagic = 0xDEAD4321; |
239 | 240 |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
828 NO_SANITIZE_ADDRESS inline size_t HeapObjectHeader::size() const { | 829 NO_SANITIZE_ADDRESS inline size_t HeapObjectHeader::size() const { |
829 size_t result = m_encoded & headerSizeMask; | 830 size_t result = m_encoded & headerSizeMask; |
830 // Large objects should not refer to header->size(). | 831 // Large objects should not refer to header->size(). |
831 // The actual size of a large object is stored in | 832 // The actual size of a large object is stored in |
832 // LargeObjectPage::m_payloadSize. | 833 // LargeObjectPage::m_payloadSize. |
833 ASSERT(result != largeObjectSizeInHeader); | 834 ASSERT(result != largeObjectSizeInHeader); |
834 ASSERT(!pageFromObject(this)->isLargeObjectPage()); | 835 ASSERT(!pageFromObject(this)->isLargeObjectPage()); |
835 return result; | 836 return result; |
836 } | 837 } |
837 | 838 |
838 NO_SANITIZE_ADDRESS inline bool HeapObjectHeader::checkHeader() const { | 839 NO_SANITIZE_ADDRESS inline void HeapObjectHeader::checkHeader() const { |
839 return m_magic == getMagic(); | 840 ASSERT(m_magic == getMagic()); |
sof
2017/02/16 18:50:04
ASSERT => DCHECK
jbroman
2017/02/16 19:08:09
DCHECK_EQ?
| |
840 } | 841 } |
841 | 842 |
842 inline Address HeapObjectHeader::payload() { | 843 inline Address HeapObjectHeader::payload() { |
843 return reinterpret_cast<Address>(this) + sizeof(HeapObjectHeader); | 844 return reinterpret_cast<Address>(this) + sizeof(HeapObjectHeader); |
844 } | 845 } |
845 | 846 |
846 inline Address HeapObjectHeader::payloadEnd() { | 847 inline Address HeapObjectHeader::payloadEnd() { |
847 return reinterpret_cast<Address>(this) + size(); | 848 return reinterpret_cast<Address>(this) + size(); |
848 } | 849 } |
849 | 850 |
850 NO_SANITIZE_ADDRESS inline size_t HeapObjectHeader::payloadSize() { | 851 NO_SANITIZE_ADDRESS inline size_t HeapObjectHeader::payloadSize() { |
851 size_t size = m_encoded & headerSizeMask; | 852 size_t size = m_encoded & headerSizeMask; |
852 if (UNLIKELY(size == largeObjectSizeInHeader)) { | 853 if (UNLIKELY(size == largeObjectSizeInHeader)) { |
853 ASSERT(pageFromObject(this)->isLargeObjectPage()); | 854 ASSERT(pageFromObject(this)->isLargeObjectPage()); |
854 return static_cast<LargeObjectPage*>(pageFromObject(this))->payloadSize(); | 855 return static_cast<LargeObjectPage*>(pageFromObject(this))->payloadSize(); |
855 } | 856 } |
856 ASSERT(!pageFromObject(this)->isLargeObjectPage()); | 857 ASSERT(!pageFromObject(this)->isLargeObjectPage()); |
857 return size - sizeof(HeapObjectHeader); | 858 return size - sizeof(HeapObjectHeader); |
858 } | 859 } |
859 | 860 |
860 inline HeapObjectHeader* HeapObjectHeader::fromPayload(const void* payload) { | 861 inline HeapObjectHeader* HeapObjectHeader::fromPayload(const void* payload) { |
861 Address addr = reinterpret_cast<Address>(const_cast<void*>(payload)); | 862 Address addr = reinterpret_cast<Address>(const_cast<void*>(payload)); |
862 HeapObjectHeader* header = | 863 HeapObjectHeader* header = |
863 reinterpret_cast<HeapObjectHeader*>(addr - sizeof(HeapObjectHeader)); | 864 reinterpret_cast<HeapObjectHeader*>(addr - sizeof(HeapObjectHeader)); |
864 ASSERT(header->checkHeader()); | 865 header->checkHeader(); |
865 return header; | 866 return header; |
866 } | 867 } |
867 | 868 |
868 inline uint32_t HeapObjectHeader::getMagic() const { | 869 inline uint32_t HeapObjectHeader::getMagic() const { |
869 const uintptr_t random1 = | 870 const uintptr_t random1 = |
870 ~(reinterpret_cast<uintptr_t>( | 871 ~(reinterpret_cast<uintptr_t>( |
871 base::trace_event::MemoryAllocatorDump::kNameSize) >> | 872 base::trace_event::MemoryAllocatorDump::kNameSize) >> |
872 16); | 873 16); |
873 | 874 |
874 #if OS(WIN) | 875 #if OS(WIN) |
(...skipping 15 matching lines...) Expand all Loading... | |
890 const uint32_t random = (random1 & 0x0FFFFUL) | (random2 & 0xFFFF0000UL); | 891 const uint32_t random = (random1 & 0x0FFFFUL) | (random2 & 0xFFFF0000UL); |
891 #else | 892 #else |
892 #error architecture not supported | 893 #error architecture not supported |
893 #endif | 894 #endif |
894 | 895 |
895 return random; | 896 return random; |
896 } | 897 } |
897 | 898 |
898 NO_SANITIZE_ADDRESS inline bool HeapObjectHeader::isWrapperHeaderMarked() | 899 NO_SANITIZE_ADDRESS inline bool HeapObjectHeader::isWrapperHeaderMarked() |
899 const { | 900 const { |
900 ASSERT(checkHeader()); | 901 checkHeader(); |
901 return m_encoded & headerWrapperMarkBitMask; | 902 return m_encoded & headerWrapperMarkBitMask; |
902 } | 903 } |
903 | 904 |
904 NO_SANITIZE_ADDRESS inline void HeapObjectHeader::markWrapperHeader() { | 905 NO_SANITIZE_ADDRESS inline void HeapObjectHeader::markWrapperHeader() { |
905 ASSERT(checkHeader()); | 906 checkHeader(); |
906 ASSERT(!isWrapperHeaderMarked()); | 907 ASSERT(!isWrapperHeaderMarked()); |
907 m_encoded |= headerWrapperMarkBitMask; | 908 m_encoded |= headerWrapperMarkBitMask; |
908 } | 909 } |
909 | 910 |
910 NO_SANITIZE_ADDRESS inline void HeapObjectHeader::unmarkWrapperHeader() { | 911 NO_SANITIZE_ADDRESS inline void HeapObjectHeader::unmarkWrapperHeader() { |
911 ASSERT(checkHeader()); | 912 checkHeader(); |
912 ASSERT(isWrapperHeaderMarked()); | 913 ASSERT(isWrapperHeaderMarked()); |
913 m_encoded &= ~headerWrapperMarkBitMask; | 914 m_encoded &= ~headerWrapperMarkBitMask; |
914 } | 915 } |
915 | 916 |
916 NO_SANITIZE_ADDRESS inline bool HeapObjectHeader::isMarked() const { | 917 NO_SANITIZE_ADDRESS inline bool HeapObjectHeader::isMarked() const { |
917 ASSERT(checkHeader()); | 918 checkHeader(); |
918 return m_encoded & headerMarkBitMask; | 919 return m_encoded & headerMarkBitMask; |
919 } | 920 } |
920 | 921 |
921 NO_SANITIZE_ADDRESS inline void HeapObjectHeader::mark() { | 922 NO_SANITIZE_ADDRESS inline void HeapObjectHeader::mark() { |
922 ASSERT(checkHeader()); | 923 checkHeader(); |
923 ASSERT(!isMarked()); | 924 ASSERT(!isMarked()); |
924 m_encoded = m_encoded | headerMarkBitMask; | 925 m_encoded = m_encoded | headerMarkBitMask; |
925 } | 926 } |
926 | 927 |
927 NO_SANITIZE_ADDRESS inline void HeapObjectHeader::unmark() { | 928 NO_SANITIZE_ADDRESS inline void HeapObjectHeader::unmark() { |
928 ASSERT(checkHeader()); | 929 checkHeader(); |
929 ASSERT(isMarked()); | 930 ASSERT(isMarked()); |
930 m_encoded &= ~headerMarkBitMask; | 931 m_encoded &= ~headerMarkBitMask; |
931 } | 932 } |
932 | 933 |
933 inline Address NormalPageArena::allocateObject(size_t allocationSize, | 934 inline Address NormalPageArena::allocateObject(size_t allocationSize, |
934 size_t gcInfoIndex) { | 935 size_t gcInfoIndex) { |
935 if (LIKELY(allocationSize <= m_remainingAllocationSize)) { | 936 if (LIKELY(allocationSize <= m_remainingAllocationSize)) { |
936 Address headerAddress = m_currentAllocationPoint; | 937 Address headerAddress = m_currentAllocationPoint; |
937 m_currentAllocationPoint += allocationSize; | 938 m_currentAllocationPoint += allocationSize; |
938 m_remainingAllocationSize -= allocationSize; | 939 m_remainingAllocationSize -= allocationSize; |
939 ASSERT(gcInfoIndex > 0); | 940 ASSERT(gcInfoIndex > 0); |
940 new (NotNull, headerAddress) HeapObjectHeader(allocationSize, gcInfoIndex); | 941 new (NotNull, headerAddress) HeapObjectHeader(allocationSize, gcInfoIndex); |
941 Address result = headerAddress + sizeof(HeapObjectHeader); | 942 Address result = headerAddress + sizeof(HeapObjectHeader); |
942 ASSERT(!(reinterpret_cast<uintptr_t>(result) & allocationMask)); | 943 ASSERT(!(reinterpret_cast<uintptr_t>(result) & allocationMask)); |
943 | 944 |
944 SET_MEMORY_ACCESSIBLE(result, allocationSize - sizeof(HeapObjectHeader)); | 945 SET_MEMORY_ACCESSIBLE(result, allocationSize - sizeof(HeapObjectHeader)); |
945 ASSERT(findPageFromAddress(headerAddress + allocationSize - 1)); | 946 ASSERT(findPageFromAddress(headerAddress + allocationSize - 1)); |
946 return result; | 947 return result; |
947 } | 948 } |
948 return outOfLineAllocate(allocationSize, gcInfoIndex); | 949 return outOfLineAllocate(allocationSize, gcInfoIndex); |
949 } | 950 } |
950 | 951 |
951 inline NormalPageArena* NormalPage::arenaForNormalPage() const { | 952 inline NormalPageArena* NormalPage::arenaForNormalPage() const { |
952 return static_cast<NormalPageArena*>(arena()); | 953 return static_cast<NormalPageArena*>(arena()); |
953 } | 954 } |
954 | 955 |
955 } // namespace blink | 956 } // namespace blink |
956 | 957 |
957 #endif // HeapPage_h | 958 #endif // HeapPage_h |
OLD | NEW |