HeapSlot * ForkJoinNursery::reallocateSlots(JSObject *obj, HeapSlot *oldSlots, uint32_t oldCount, uint32_t newCount) { if (newCount & mozilla::tl::MulOverflowMask<sizeof(HeapSlot)>::value) return nullptr; size_t oldSize = oldCount * sizeof(HeapSlot); size_t newSize = newCount * sizeof(HeapSlot); if (!isInsideNewspace(obj)) { JS_ASSERT_IF(oldSlots, !isInsideNewspace(oldSlots)); return static_cast<HeapSlot *>(cx_->realloc_(oldSlots, oldSize, newSize)); } if (!isInsideNewspace(oldSlots)) return reallocateHugeSlots(oldSlots, oldSize, newSize); // No-op if we're shrinking, we can't make use of the freed portion. if (newCount < oldCount) return oldSlots; HeapSlot *newSlots = allocateSlots(obj, newCount); if (!newSlots) return nullptr; js_memcpy(newSlots, oldSlots, oldSize); return newSlots; }
block_id StorageManager::allocateNewBlockOrBlob(const std::size_t num_slots, BlockHandle *handle, const int numa_node) { DEBUG_ASSERT(num_slots > 0); DEBUG_ASSERT(handle != nullptr); handle->block_memory = allocateSlots(num_slots, numa_node); handle->block_memory_size = num_slots; return ++block_index_; }
StorageManager::BlockHandle StorageManager::loadBlockOrBlob( const block_id block, const int numa_node) { // The caller of this function holds an exclusive lock on this block/blob's // mutex in the lock manager. The caller has ensured that the block is not // already loaded before this function gets called. size_t num_slots = file_manager_->numSlots(block); DEBUG_ASSERT(num_slots != 0); void *block_buffer = allocateSlots(num_slots, numa_node); const bool status = file_manager_->readBlockOrBlob(block, block_buffer, kSlotSizeBytes * num_slots); CHECK(status) << "Failed to read block from persistent storage: " << block; BlockHandle loaded_handle; loaded_handle.block_memory = block_buffer; loaded_handle.block_memory_size = num_slots; return loaded_handle; }
ObjectElements * ForkJoinNursery::allocateElements(JSObject *obj, uint32_t nelems) { JS_ASSERT(nelems >= ObjectElements::VALUES_PER_HEADER); return reinterpret_cast<ObjectElements *>(allocateSlots(obj, nelems)); }