mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibJS: Align Instructions as void* and roundup variably sized ones sizes
Both is indeed needed, the standard alignment would have been 4, but some Instructions, like Jumps need an alignment of 8 Fixes #12127.
This commit is contained in:
parent
89408d5f64
commit
911506af9f
Notes:
sideshowbarker
2024-07-17 08:42:05 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/911506af9f Pull-request: https://github.com/SerenityOS/serenity/pull/15112 Reviewed-by: https://github.com/alimpfard ✅ Reviewed-by: https://github.com/davidot Reviewed-by: https://github.com/linusg
|
@ -65,12 +65,15 @@ public:
|
|||
OpType& emit_with_extra_register_slots(size_t extra_register_slots, Args&&... args)
|
||||
{
|
||||
VERIFY(!is_current_block_terminated());
|
||||
|
||||
size_t size_to_allocate = round_up_to_power_of_two(sizeof(OpType) + extra_register_slots * sizeof(Register), alignof(void*));
|
||||
|
||||
// If the block doesn't have enough space, switch to another block
|
||||
if constexpr (!OpType::IsTerminator)
|
||||
ensure_enough_space(sizeof(OpType) + extra_register_slots * sizeof(Register));
|
||||
ensure_enough_space(size_to_allocate);
|
||||
|
||||
void* slot = next_slot();
|
||||
grow(sizeof(OpType) + extra_register_slots * sizeof(Register));
|
||||
grow(size_to_allocate);
|
||||
new (slot) OpType(forward<Args>(args)...);
|
||||
if constexpr (OpType::IsTerminator)
|
||||
m_current_basic_block->terminate({});
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
class Instruction {
|
||||
class alignas(void*) Instruction {
|
||||
public:
|
||||
constexpr static bool IsTerminator = false;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
||||
#include <LibJS/Bytecode/IdentifierTable.h>
|
||||
#include <LibJS/Bytecode/Instruction.h>
|
||||
|
@ -990,9 +991,9 @@ ALWAYS_INLINE void Instruction::replace_references(BasicBlock const& from, Basic
|
|||
ALWAYS_INLINE size_t Instruction::length() const
|
||||
{
|
||||
if (type() == Type::NewArray)
|
||||
return static_cast<Op::NewArray const&>(*this).length_impl();
|
||||
return round_up_to_power_of_two(static_cast<Op::NewArray const&>(*this).length_impl(), alignof(void*));
|
||||
if (type() == Type::CopyObjectExcludingProperties)
|
||||
return static_cast<Op::CopyObjectExcludingProperties const&>(*this).length_impl();
|
||||
return round_up_to_power_of_two(static_cast<Op::CopyObjectExcludingProperties const&>(*this).length_impl(), alignof(void*));
|
||||
|
||||
#define __BYTECODE_OP(op) \
|
||||
case Type::op: \
|
||||
|
|
Loading…
Reference in a new issue