AK+Kernel: Help the compiler inline a bunch of trivial methods

If these methods get inlined, the compiler is able to statically eliminate most
of the assertions. Alas, it doesn't realize this, and believes inlining them to
be too expensive. So give it a strong hint that it's not the case.

This *decreases* the kernel binary size.
This commit is contained in:
Sergey Bugaev 2020-05-20 14:59:31 +03:00 committed by Andreas Kling
parent 36dcbce161
commit d2b500fbcb
6 changed files with 51 additions and 56 deletions

View file

@ -39,14 +39,14 @@ template<typename T>
class RefPtr;
template<typename T>
inline void ref_if_not_null(T* ptr)
ALWAYS_INLINE void ref_if_not_null(T* ptr)
{
if (ptr)
ptr->ref();
}
template<typename T>
inline void unref_if_not_null(T* ptr)
ALWAYS_INLINE void unref_if_not_null(T* ptr)
{
if (ptr)
ptr->unref();
@ -59,42 +59,42 @@ public:
enum AdoptTag { Adopt };
NonnullRefPtr(const T& object)
ALWAYS_INLINE NonnullRefPtr(const T& object)
: m_ptr(const_cast<T*>(&object))
{
m_ptr->ref();
}
template<typename U>
NonnullRefPtr(const U& object)
ALWAYS_INLINE NonnullRefPtr(const U& object)
: m_ptr(&const_cast<U&>(object))
{
m_ptr->ref();
}
NonnullRefPtr(AdoptTag, T& object)
ALWAYS_INLINE NonnullRefPtr(AdoptTag, T& object)
: m_ptr(&object)
{
}
NonnullRefPtr(NonnullRefPtr&& other)
ALWAYS_INLINE NonnullRefPtr(NonnullRefPtr&& other)
: m_ptr(&other.leak_ref())
{
}
template<typename U>
NonnullRefPtr(NonnullRefPtr<U>&& other)
ALWAYS_INLINE NonnullRefPtr(NonnullRefPtr<U>&& other)
: m_ptr(&other.leak_ref())
{
}
NonnullRefPtr(const NonnullRefPtr& other)
ALWAYS_INLINE NonnullRefPtr(const NonnullRefPtr& other)
: m_ptr(const_cast<T*>(other.ptr()))
{
m_ptr->ref();
}
template<typename U>
NonnullRefPtr(const NonnullRefPtr<U>& other)
ALWAYS_INLINE NonnullRefPtr(const NonnullRefPtr<U>& other)
: m_ptr(const_cast<U*>(other.ptr()))
{
m_ptr->ref();
}
~NonnullRefPtr()
ALWAYS_INLINE ~NonnullRefPtr()
{
unref_if_not_null(m_ptr);
m_ptr = nullptr;
@ -133,7 +133,7 @@ public:
return *this;
}
NonnullRefPtr& operator=(NonnullRefPtr&& other)
ALWAYS_INLINE NonnullRefPtr& operator=(NonnullRefPtr&& other)
{
NonnullRefPtr ptr(move(other));
swap(ptr);
@ -155,62 +155,62 @@ public:
return *this;
}
[[nodiscard]] T& leak_ref()
[[nodiscard]] ALWAYS_INLINE T& leak_ref()
{
ASSERT(m_ptr);
return *exchange(m_ptr, nullptr);
}
T* ptr()
ALWAYS_INLINE T* ptr()
{
ASSERT(m_ptr);
return m_ptr;
}
const T* ptr() const
ALWAYS_INLINE const T* ptr() const
{
ASSERT(m_ptr);
return m_ptr;
}
T* operator->()
ALWAYS_INLINE T* operator->()
{
ASSERT(m_ptr);
return m_ptr;
}
const T* operator->() const
ALWAYS_INLINE const T* operator->() const
{
ASSERT(m_ptr);
return m_ptr;
}
T& operator*()
ALWAYS_INLINE T& operator*()
{
ASSERT(m_ptr);
return *m_ptr;
}
const T& operator*() const
ALWAYS_INLINE const T& operator*() const
{
ASSERT(m_ptr);
return *m_ptr;
}
operator T*()
ALWAYS_INLINE operator T*()
{
ASSERT(m_ptr);
return m_ptr;
}
operator const T*() const
ALWAYS_INLINE operator const T*() const
{
ASSERT(m_ptr);
return m_ptr;
}
operator T&()
ALWAYS_INLINE operator T&()
{
ASSERT(m_ptr);
return *m_ptr;
}
operator const T&() const
ALWAYS_INLINE operator const T&() const
{
ASSERT(m_ptr);
return *m_ptr;

View file

@ -57,25 +57,25 @@ constexpr auto call_one_ref_left_if_present(...) -> FalseType
class RefCountedBase {
public:
void ref() const
ALWAYS_INLINE void ref() const
{
ASSERT(m_ref_count);
++m_ref_count;
}
int ref_count() const
ALWAYS_INLINE int ref_count() const
{
return m_ref_count;
}
protected:
RefCountedBase() {}
~RefCountedBase()
ALWAYS_INLINE ~RefCountedBase()
{
ASSERT(!m_ref_count);
}
void deref_base() const
ALWAYS_INLINE void deref_base() const
{
ASSERT(m_ref_count);
--m_ref_count;

View file

@ -63,21 +63,21 @@ public:
: m_ptr(other.leak_ref())
{
}
RefPtr(const NonnullRefPtr<T>& other)
ALWAYS_INLINE RefPtr(const NonnullRefPtr<T>& other)
: m_ptr(const_cast<T*>(other.ptr()))
{
ASSERT(m_ptr);
m_ptr->ref();
}
template<typename U>
RefPtr(const NonnullRefPtr<U>& other)
ALWAYS_INLINE RefPtr(const NonnullRefPtr<U>& other)
: m_ptr(const_cast<U*>(other.ptr()))
{
ASSERT(m_ptr);
m_ptr->ref();
}
template<typename U>
RefPtr(NonnullRefPtr<U>&& other)
ALWAYS_INLINE RefPtr(NonnullRefPtr<U>&& other)
: m_ptr(&other.leak_ref())
{
ASSERT(m_ptr);
@ -98,7 +98,7 @@ public:
{
ref_if_not_null(m_ptr);
}
~RefPtr()
ALWAYS_INLINE ~RefPtr()
{
clear();
#ifdef SANITIZE_PTRS
@ -121,7 +121,7 @@ public:
::swap(m_ptr, other.m_ptr);
}
RefPtr& operator=(RefPtr&& other)
ALWAYS_INLINE RefPtr& operator=(RefPtr&& other)
{
RefPtr tmp = move(other);
swap(tmp);
@ -129,7 +129,7 @@ public:
}
template<typename U>
RefPtr& operator=(RefPtr<U>&& other)
ALWAYS_INLINE RefPtr& operator=(RefPtr<U>&& other)
{
RefPtr tmp = move(other);
swap(tmp);
@ -137,7 +137,7 @@ public:
}
template<typename U>
RefPtr& operator=(NonnullRefPtr<U>&& other)
ALWAYS_INLINE RefPtr& operator=(NonnullRefPtr<U>&& other)
{
RefPtr tmp = move(other);
swap(tmp);
@ -145,7 +145,7 @@ public:
return *this;
}
RefPtr& operator=(const NonnullRefPtr<T>& other)
ALWAYS_INLINE RefPtr& operator=(const NonnullRefPtr<T>& other)
{
RefPtr tmp = other;
swap(tmp);
@ -154,7 +154,7 @@ public:
}
template<typename U>
RefPtr& operator=(const NonnullRefPtr<U>& other)
ALWAYS_INLINE RefPtr& operator=(const NonnullRefPtr<U>& other)
{
RefPtr tmp = other;
swap(tmp);
@ -162,7 +162,7 @@ public:
return *this;
}
RefPtr& operator=(const RefPtr& other)
ALWAYS_INLINE RefPtr& operator=(const RefPtr& other)
{
RefPtr tmp = other;
swap(tmp);
@ -170,21 +170,21 @@ public:
}
template<typename U>
RefPtr& operator=(const RefPtr<U>& other)
ALWAYS_INLINE RefPtr& operator=(const RefPtr<U>& other)
{
RefPtr tmp = other;
swap(tmp);
return *this;
}
RefPtr& operator=(const T* ptr)
ALWAYS_INLINE RefPtr& operator=(const T* ptr)
{
RefPtr tmp = ptr;
swap(tmp);
return *this;
}
RefPtr& operator=(const T& object)
ALWAYS_INLINE RefPtr& operator=(const T& object)
{
RefPtr tmp = object;
swap(tmp);
@ -197,7 +197,7 @@ public:
return *this;
}
void clear()
ALWAYS_INLINE void clear()
{
unref_if_not_null(m_ptr);
m_ptr = nullptr;
@ -216,35 +216,35 @@ public:
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, *leak_ref());
}
T* ptr() { return m_ptr; }
const T* ptr() const { return m_ptr; }
ALWAYS_INLINE T* ptr() { return m_ptr; }
ALWAYS_INLINE const T* ptr() const { return m_ptr; }
T* operator->()
ALWAYS_INLINE T* operator->()
{
ASSERT(m_ptr);
return m_ptr;
}
const T* operator->() const
ALWAYS_INLINE const T* operator->() const
{
ASSERT(m_ptr);
return m_ptr;
}
T& operator*()
ALWAYS_INLINE T& operator*()
{
ASSERT(m_ptr);
return *m_ptr;
}
const T& operator*() const
ALWAYS_INLINE const T& operator*() const
{
ASSERT(m_ptr);
return *m_ptr;
}
operator const T*() const { return m_ptr; }
operator T*() { return m_ptr; }
ALWAYS_INLINE operator const T*() const { return m_ptr; }
ALWAYS_INLINE operator T*() { return m_ptr; }
operator bool() { return !!m_ptr; }

View file

@ -69,13 +69,13 @@ public:
{
}
KResultOr(T&& value)
ALWAYS_INLINE KResultOr(T&& value)
{
new (&m_storage) T(move(value));
}
template<typename U>
KResultOr(U&& value)
ALWAYS_INLINE KResultOr(U&& value)
{
new (&m_storage) T(move(value));
}

View file

@ -384,11 +384,6 @@ void Thread::send_urgent_signal_to_self(u8 signal)
(void)block<SemiPermanentBlocker>(SemiPermanentBlocker::Reason::Signal);
}
bool Thread::has_unmasked_pending_signals() const
{
return m_pending_signals & ~m_signal_mask;
}
ShouldUnblockThread Thread::dispatch_one_pending_signal()
{
ASSERT_INTERRUPTS_DISABLED();

View file

@ -362,7 +362,7 @@ public:
ShouldUnblockThread dispatch_one_pending_signal();
ShouldUnblockThread dispatch_signal(u8 signal);
bool has_unmasked_pending_signals() const;
bool has_unmasked_pending_signals() const { return m_pending_signals & ~m_signal_mask; }
void terminate_due_to_signal(u8 signal);
bool should_ignore_signal(u8 signal) const;
bool has_signal_handler(u8 signal) const;