]>
git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGCorrectableJumpPoint.h
2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef DFGCorrectableJumpPoint_h
27 #define DFGCorrectableJumpPoint_h
31 #include "LinkBuffer.h"
32 #include "MacroAssembler.h"
34 namespace JSC
{ namespace DFG
{
36 // This is a type-safe union of MacroAssembler::Jump and CodeLocationJump.
37 // Furthermore, it supports the notion of branching (possibly conditionally, but
38 // also possibly jumping unconditionally) to an out-of-line patchable jump.
39 // Thus it goes through three states:
41 // 1) Label of unpatchable branch or jump (i.e. MacroAssembler::Jump).
42 // 2) Label of patchable jump (i.e. MacroAssembler::PatchableJump).
43 // 3) Corrected post-linking label of patchable jump (i.e. CodeLocationJump).
45 // The setting of state (1) corresponds to planting the in-line unpatchable
46 // branch or jump. The state transition (1)->(2) corresponds to linking the
47 // in-line branch or jump to the out-of-line patchable jump, and recording
48 // the latter's label. The state transition (2)->(3) corresponds to recording
49 // the out-of-line patchable jump's location after branch compaction has
52 // You can also go directly from the first state to the third state, if you
53 // wish to use this class for in-line patchable jumps.
55 class CorrectableJumpPoint
{
57 CorrectableJumpPoint(MacroAssembler::Jump check
)
58 : m_codeOffset(check
.m_label
.m_offset
)
64 m_type
= check
.m_type
;
65 m_condition
= check
.m_condition
;
69 void switchToLateJump(MacroAssembler::PatchableJump check
)
72 ASSERT(m_mode
== InitialJump
);
75 // Late jumps should only ever be real jumps.
77 ASSERT(check
.m_jump
.m_type
== ARMv7Assembler::JumpNoConditionFixedSize
);
78 ASSERT(check
.m_jump
.m_condition
== ARMv7Assembler::ConditionInvalid
);
79 m_type
= ARMv7Assembler::JumpNoConditionFixedSize
;
80 m_condition
= ARMv7Assembler::ConditionInvalid
;
82 m_codeOffset
= check
.m_jump
.m_label
.m_offset
;
85 void correctInitialJump(LinkBuffer
& linkBuffer
)
87 ASSERT(m_mode
== InitialJump
);
89 ASSERT(m_type
== ARMv7Assembler::JumpNoConditionFixedSize
);
90 ASSERT(m_condition
== ARMv7Assembler::ConditionInvalid
);
92 correctJump(linkBuffer
);
95 void correctLateJump(LinkBuffer
& linkBuffer
)
97 ASSERT(m_mode
== LateJump
);
98 correctJump(linkBuffer
);
101 MacroAssembler::Jump
initialJump() const
103 ASSERT(m_mode
== InitialJump
);
107 MacroAssembler::Jump
lateJump() const
109 ASSERT(m_mode
== LateJump
);
113 CodeLocationJump
codeLocationForRepatch(CodeBlock
*) const;
116 void correctJump(LinkBuffer
& linkBuffer
)
119 m_mode
= CorrectedJump
;
121 MacroAssembler::Label label
;
122 label
.m_label
.m_offset
= m_codeOffset
;
123 m_codeOffset
= linkBuffer
.offsetOf(label
);
126 MacroAssembler::Jump
getJump() const
128 MacroAssembler::Jump jump
;
129 jump
.m_label
.m_offset
= m_codeOffset
;
131 jump
.m_type
= m_type
;
132 jump
.m_condition
= m_condition
;
137 unsigned m_codeOffset
;
140 ARMv7Assembler::JumpType m_type
: 8;
141 ARMv7Assembler::Condition m_condition
: 8;
155 } } // namespace JSC::DFG
157 #endif // ENABLE(DFG_JIT)
159 #endif // DFGCorrectableJumpPoint_h