| 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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 // TODO(sof): promptly free the previous object. | 567 // TODO(sof): promptly free the previous object. |
| 568 if (!size) { | 568 if (!size) { |
| 569 // If the new size is 0 this is considered equivalent to free(previous). | 569 // If the new size is 0 this is considered equivalent to free(previous). |
| 570 return nullptr; | 570 return nullptr; |
| 571 } | 571 } |
| 572 | 572 |
| 573 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); | 573 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); |
| 574 HeapObjectHeader* previousHeader = HeapObjectHeader::fromPayload(previous); | 574 HeapObjectHeader* previousHeader = HeapObjectHeader::fromPayload(previous); |
| 575 BasePage* page = pageFromObject(previousHeader); | 575 BasePage* page = pageFromObject(previousHeader); |
| 576 ASSERT(page); | 576 ASSERT(page); |
| 577 int arenaIndex = page->arena()->arenaIndex(); | |
| 578 // Recompute the effective heap index if previous allocation | |
| 579 // was on the normal arenas or a large object. | |
| 580 if (isNormalArenaIndex(arenaIndex) || arenaIndex == BlinkGC::LargeObjectAren
aIndex) | |
| 581 arenaIndex = arenaIndexForObjectSize(size); | |
| 582 | 577 |
| 578 // Determine arena index of new allocation. |
| 579 int arenaIndex; |
| 580 if (size >= largeObjectSizeThreshold) { |
| 581 arenaIndex = BlinkGC::LargeObjectArenaIndex; |
| 582 } else { |
| 583 arenaIndex = page->arena()->arenaIndex(); |
| 584 if (isNormalArenaIndex(arenaIndex) || arenaIndex == BlinkGC::LargeObject
ArenaIndex) |
| 585 arenaIndex = arenaIndexForObjectSize(size); |
| 586 } |
| 587 |
| 588 size_t gcInfoIndex = GCInfoTrait<T>::index(); |
| 583 // TODO(haraken): We don't support reallocate() for finalizable objects. | 589 // TODO(haraken): We don't support reallocate() for finalizable objects. |
| 584 ASSERT(!ThreadHeap::gcInfo(previousHeader->gcInfoIndex())->hasFinalizer()); | 590 ASSERT(!ThreadHeap::gcInfo(previousHeader->gcInfoIndex())->hasFinalizer()); |
| 585 ASSERT(previousHeader->gcInfoIndex() == GCInfoTrait<T>::index()); | 591 ASSERT(previousHeader->gcInfoIndex() == gcInfoIndex); |
| 586 const char* typeName = WTF_HEAP_PROFILER_TYPE_NAME(T); | |
| 587 HeapAllocHooks::freeHookIfEnabled(static_cast<Address>(previous)); | 592 HeapAllocHooks::freeHookIfEnabled(static_cast<Address>(previous)); |
| 588 Address address = ThreadHeap::allocateOnArenaIndex(state, size, arenaIndex,
GCInfoTrait<T>::index(), typeName); | 593 Address address; |
| 594 if (arenaIndex == BlinkGC::LargeObjectArenaIndex) { |
| 595 address = page->arena()->allocateLargeObject(allocationSizeFromSize(size
), gcInfoIndex); |
| 596 } else { |
| 597 const char* typeName = WTF_HEAP_PROFILER_TYPE_NAME(T); |
| 598 address = ThreadHeap::allocateOnArenaIndex(state, size, arenaIndex, gcIn
foIndex, typeName); |
| 599 } |
| 589 size_t copySize = previousHeader->payloadSize(); | 600 size_t copySize = previousHeader->payloadSize(); |
| 590 if (copySize > size) | 601 if (copySize > size) |
| 591 copySize = size; | 602 copySize = size; |
| 592 memcpy(address, previous, copySize); | 603 memcpy(address, previous, copySize); |
| 593 return address; | 604 return address; |
| 594 } | 605 } |
| 595 | 606 |
| 596 template<typename Derived> | 607 template<typename Derived> |
| 597 template<typename T> | 608 template<typename T> |
| 598 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) | 609 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) |
| 599 { | 610 { |
| 600 T** cell = reinterpret_cast<T**>(object); | 611 T** cell = reinterpret_cast<T**>(object); |
| 601 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) | 612 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) |
| 602 *cell = nullptr; | 613 *cell = nullptr; |
| 603 } | 614 } |
| 604 | 615 |
| 605 } // namespace blink | 616 } // namespace blink |
| 606 | 617 |
| 607 #endif // Heap_h | 618 #endif // Heap_h |
| OLD | NEW |