File: DFGCorrectableJumpPoint.h

package info (click to toggle)
qtwebkit 2.3.4.dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 290,116 kB
  • ctags: 272,544
  • sloc: cpp: 1,417,496; python: 85,048; ansic: 39,353; perl: 38,858; ruby: 10,313; objc: 9,505; xml: 8,679; asm: 3,864; yacc: 2,458; sh: 1,237; lex: 813; makefile: 592; java: 228; php: 79
file content (164 lines) | stat: -rw-r--r-- 5,145 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Copyright (C) 2011 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

#ifndef DFGCorrectableJumpPoint_h
#define DFGCorrectableJumpPoint_h

#if ENABLE(DFG_JIT)

#include "LinkBuffer.h"
#include "MacroAssembler.h"

namespace JSC { namespace DFG {

// This is a type-safe union of MacroAssembler::Jump and CodeLocationJump.
// Furthermore, it supports the notion of branching (possibly conditionally, but
// also possibly jumping unconditionally) to an out-of-line patchable jump.
// Thus it goes through three states:
//
// 1) Label of unpatchable branch or jump (i.e. MacroAssembler::Jump).
// 2) Label of patchable jump (i.e. MacroAssembler::PatchableJump).
// 3) Corrected post-linking label of patchable jump (i.e. CodeLocationJump).
//
// The setting of state (1) corresponds to planting the in-line unpatchable
// branch or jump. The state transition (1)->(2) corresponds to linking the
// in-line branch or jump to the out-of-line patchable jump, and recording
// the latter's label. The state transition (2)->(3) corresponds to recording
// the out-of-line patchable jump's location after branch compaction has
// completed.
//
// You can also go directly from the first state to the third state, if you
// wish to use this class for in-line patchable jumps.

class CorrectableJumpPoint {
public:
    CorrectableJumpPoint(MacroAssembler::Jump check)
        : m_codeOffset(check.m_label.m_offset)
#ifndef NDEBUG
        , m_mode(InitialJump)
#endif
    {
#if CPU(ARM_THUMB2)
        m_type = check.m_type;
        m_condition = check.m_condition;
#endif
    }
    
    bool isSet()
    {
        return m_codeOffset != std::numeric_limits<uint32_t>::max();
    }
    
    void switchToLateJump(MacroAssembler::PatchableJump check)
    {
#ifndef NDEBUG
        ASSERT(m_mode == InitialJump);
        m_mode = LateJump;
#endif
        // Late jumps should only ever be real jumps.
#if CPU(ARM_THUMB2)
        ASSERT(check.m_jump.m_type == ARMv7Assembler::JumpNoConditionFixedSize);
        ASSERT(check.m_jump.m_condition == ARMv7Assembler::ConditionInvalid);
        m_type = ARMv7Assembler::JumpNoConditionFixedSize;
        m_condition = ARMv7Assembler::ConditionInvalid;
#endif
        m_codeOffset = check.m_jump.m_label.m_offset;
    }
    
    void correctInitialJump(LinkBuffer& linkBuffer)
    {
        ASSERT(m_mode == InitialJump);
#if CPU(ARM_THUMB2)
        ASSERT(m_type == ARMv7Assembler::JumpNoConditionFixedSize);
        ASSERT(m_condition == ARMv7Assembler::ConditionInvalid);
#endif
        correctJump(linkBuffer);
    }
    
    void correctLateJump(LinkBuffer& linkBuffer)
    {
        ASSERT(m_mode == LateJump);
        correctJump(linkBuffer);
    }
    
    MacroAssembler::Jump initialJump() const
    {
        ASSERT(m_mode == InitialJump);
        return getJump();
    }
    
    MacroAssembler::Jump lateJump() const
    {
        ASSERT(m_mode == LateJump);
        return getJump();
    }
    
    CodeLocationJump codeLocationForRepatch(CodeBlock*) const;
    
private:
    void correctJump(LinkBuffer& linkBuffer)
    {
#ifndef NDEBUG
        m_mode = CorrectedJump;
#endif
        MacroAssembler::Label label;
        label.m_label.m_offset = m_codeOffset;
        m_codeOffset = linkBuffer.offsetOf(label);
    }
    
    MacroAssembler::Jump getJump() const
    {
        MacroAssembler::Jump jump;
        jump.m_label.m_offset = m_codeOffset;
#if CPU(ARM_THUMB2)
        jump.m_type = m_type;
        jump.m_condition = m_condition;
#endif
        return jump;
    }
    
    unsigned m_codeOffset;

#if CPU(ARM_THUMB2)
    ARMv7Assembler::JumpType m_type : 8;
    ARMv7Assembler::Condition m_condition : 8;
#endif

#ifndef NDEBUG
    enum Mode {
        InitialJump,
        LateJump,
        CorrectedJump
    };

    Mode m_mode;
#endif
};

} } // namespace JSC::DFG

#endif // ENABLE(DFG_JIT)

#endif // DFGCorrectableJumpPoint_h