Ignore:
Timestamp:
Feb 24, 2022, 3:13:46 AM (3 years ago)
Author:
[email protected]
Message:

[JSC] Respect bytecode alignment in BytecodeRewriter
https://bugs.webkit.org/show_bug.cgi?id=237092

Patch by Geza Lore <Geza Lore> on 2022-02-24
Reviewed by Yusuke Suzuki.

Note: This patch only affects bytecode generation on platforms which
set CPU(NEEDS_ALIGNED_ACCESS), which are ARMv7 and MIPS. On all other
platforms the generated bytecode is identical.

The previous BytecodeRewriter::removeBytecode method unconditionally
removed the given instruction, which could then break the required
alignment of subsequent wide ops. While this could be fixed by
inserting padding after the removal, all current uses of
removeBytecode are such that they constitute one half of a replace.
Instead of adding unnecessary padding, added an explicit
replaceBytecodeWithFragment method that removes the old instruction
and replaces it with the given fragment, while maintaining alignment
of the subsequent bytecode. This yields fewer nops. If removeBytecode
turns out to be necessary later, use replaceBytecodeWithFragment with
an empty fragment.

  • bytecode/BytecodeGeneratorification.cpp:

(JSC::BytecodeGeneratorification::run):

  • bytecode/BytecodeRewriter.h:

(JSC::BytecodeRewriter::Fragment::align):
(JSC::BytecodeRewriter::insertFragmentAfter):
(JSC::BytecodeRewriter::replaceBytecodeWithFragment):

  • bytecompiler/BytecodeGeneratorBaseInlines.h:

(JSC::BytecodeGeneratorBase<Traits>::alignWideOpcode32):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGeneratorBaseInlines.h

    r276609 r290421  
    115115#if CPU(NEEDS_ALIGNED_ACCESS)
    116116    size_t opcodeSize = 1;
    117     size_t prefixAndOpcodeSize = opcodeSize + PaddingBySize<OpcodeSize::Wide16>::value;
     117    size_t prefixAndOpcodeSize = opcodeSize + PaddingBySize<OpcodeSize::Wide32>::value;
    118118    while ((m_writer.position() + prefixAndOpcodeSize) % OpcodeSize::Wide32)
    119119        Traits::OpNop::template emit<OpcodeSize::Narrow>(this);
Note: See TracChangeset for help on using the changeset viewer.