mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 13:05:12 +00:00
UserspaceEmulator: Inline some very hot functions
This improves the browser's load time on welcome.html by ~2%.
This commit is contained in:
parent
1b9a85e4f1
commit
da413a464a
Notes:
sideshowbarker
2024-07-19 01:20:47 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/da413a464a1
6 changed files with 33 additions and 34 deletions
|
@ -199,14 +199,6 @@ int Emulator::exec()
|
|||
return m_exit_status;
|
||||
}
|
||||
|
||||
bool Emulator::is_in_malloc_or_free() const
|
||||
{
|
||||
return (m_cpu.base_eip() >= m_malloc_symbol_start && m_cpu.base_eip() < m_malloc_symbol_end)
|
||||
|| (m_cpu.base_eip() >= m_free_symbol_start && m_cpu.base_eip() < m_free_symbol_end)
|
||||
|| (m_cpu.base_eip() >= m_realloc_symbol_start && m_cpu.base_eip() < m_realloc_symbol_end)
|
||||
|| (m_cpu.base_eip() >= m_malloc_size_symbol_start && m_cpu.base_eip() < m_malloc_size_symbol_end);
|
||||
}
|
||||
|
||||
Vector<FlatPtr> Emulator::raw_backtrace()
|
||||
{
|
||||
Vector<FlatPtr, 128> backtrace;
|
||||
|
|
|
@ -185,4 +185,12 @@ private:
|
|||
FlatPtr m_signal_trampoline { 0 };
|
||||
};
|
||||
|
||||
ALWAYS_INLINE bool Emulator::is_in_malloc_or_free() const
|
||||
{
|
||||
return (m_cpu.base_eip() >= m_malloc_symbol_start && m_cpu.base_eip() < m_malloc_symbol_end)
|
||||
|| (m_cpu.base_eip() >= m_free_symbol_start && m_cpu.base_eip() < m_free_symbol_end)
|
||||
|| (m_cpu.base_eip() >= m_realloc_symbol_start && m_cpu.base_eip() < m_realloc_symbol_end)
|
||||
|| (m_cpu.base_eip() >= m_malloc_size_symbol_start && m_cpu.base_eip() < m_malloc_size_symbol_end);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -162,22 +162,6 @@ void MallocTracer::target_did_realloc(Badge<SoftCPU>, FlatPtr address, size_t si
|
|||
existing_mallocation->malloc_backtrace = m_emulator.raw_backtrace();
|
||||
}
|
||||
|
||||
Mallocation* MallocTracer::find_mallocation(const Region& region, FlatPtr address)
|
||||
{
|
||||
if (!region.is_mmap())
|
||||
return nullptr;
|
||||
if (!static_cast<const MmapRegion&>(region).is_malloc_block())
|
||||
return nullptr;
|
||||
auto* malloc_data = static_cast<MmapRegion&>(const_cast<Region&>(region)).malloc_metadata();
|
||||
if (!malloc_data)
|
||||
return nullptr;
|
||||
auto& mallocation = malloc_data->mallocation_for_address(address);
|
||||
if (!mallocation.used)
|
||||
return nullptr;
|
||||
ASSERT(mallocation.contains(address));
|
||||
return &mallocation;
|
||||
}
|
||||
|
||||
Mallocation* MallocTracer::find_mallocation(FlatPtr address)
|
||||
{
|
||||
auto* region = m_emulator.mmu().find_region({ 0x23, address });
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "MmapRegion.h"
|
||||
#include "SoftMMU.h"
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/HashMap.h>
|
||||
|
@ -92,4 +93,20 @@ private:
|
|||
bool m_auditing_enabled { true };
|
||||
};
|
||||
|
||||
ALWAYS_INLINE Mallocation* MallocTracer::find_mallocation(const Region& region, FlatPtr address)
|
||||
{
|
||||
if (!region.is_mmap())
|
||||
return nullptr;
|
||||
if (!static_cast<const MmapRegion&>(region).is_malloc_block())
|
||||
return nullptr;
|
||||
auto* malloc_data = static_cast<MmapRegion&>(const_cast<Region&>(region)).malloc_metadata();
|
||||
if (!malloc_data)
|
||||
return nullptr;
|
||||
auto& mallocation = malloc_data->mallocation_for_address(address);
|
||||
if (!mallocation.used)
|
||||
return nullptr;
|
||||
ASSERT(mallocation.contains(address));
|
||||
return &mallocation;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,15 +39,6 @@ SoftMMU::SoftMMU(Emulator& emulator)
|
|||
{
|
||||
}
|
||||
|
||||
Region* SoftMMU::find_region(X86::LogicalAddress address)
|
||||
{
|
||||
if (address.selector() == 0x28)
|
||||
return m_tls_region.ptr();
|
||||
|
||||
size_t page_index = (address.offset() & ~(PAGE_SIZE - 1)) / PAGE_SIZE;
|
||||
return m_page_to_region_map[page_index];
|
||||
}
|
||||
|
||||
void SoftMMU::add_region(NonnullOwnPtr<Region> region)
|
||||
{
|
||||
ASSERT(!find_region({ 0x20, region->base() }));
|
||||
|
|
|
@ -53,7 +53,14 @@ public:
|
|||
void write32(X86::LogicalAddress, ValueWithShadow<u32>);
|
||||
void write64(X86::LogicalAddress, ValueWithShadow<u64>);
|
||||
|
||||
Region* find_region(X86::LogicalAddress);
|
||||
ALWAYS_INLINE Region* find_region(X86::LogicalAddress address)
|
||||
{
|
||||
if (address.selector() == 0x28)
|
||||
return m_tls_region.ptr();
|
||||
|
||||
size_t page_index = (address.offset() & ~(PAGE_SIZE - 1)) / PAGE_SIZE;
|
||||
return m_page_to_region_map[page_index];
|
||||
}
|
||||
|
||||
void add_region(NonnullOwnPtr<Region>);
|
||||
void remove_region(Region&);
|
||||
|
|
Loading…
Add table
Reference in a new issue