christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 | // All Rights Reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // - Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // |
| 11 | // - Redistribution in binary form must reproduce the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer in the |
| 13 | // documentation and/or other materials provided with the distribution. |
| 14 | // |
| 15 | // - Neither the name of Sun Microsystems or the names of contributors may |
| 16 | // be used to endorse or promote products derived from this software without |
| 17 | // specific prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 20 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 21 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 23 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | // The original source code covered by the above license above has been |
| 32 | // modified significantly by Google Inc. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 33 | // Copyright 2006-2009 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | |
| 35 | #ifndef V8_ASSEMBLER_H_ |
| 36 | #define V8_ASSEMBLER_H_ |
| 37 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 38 | #include "gdb-jit.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | #include "runtime.h" |
| 40 | #include "top.h" |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 41 | #include "token.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 43 | namespace v8 { |
| 44 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | // ----------------------------------------------------------------------------- |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 48 | // Common double constants. |
| 49 | |
| 50 | class DoubleConstant: public AllStatic { |
| 51 | public: |
| 52 | static const double min_int; |
| 53 | static const double one_half; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 54 | static const double minus_zero; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 55 | static const double negative_infinity; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | |
| 59 | // ----------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 60 | // Labels represent pc locations; they are typically jump or call targets. |
| 61 | // After declaration, a label can be freely used to denote known or (yet) |
| 62 | // unknown pc location. Assembler::bind() is used to bind a label to the |
| 63 | // current pc. A label can be bound only once. |
| 64 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 65 | class Label BASE_EMBEDDED { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 66 | public: |
| 67 | INLINE(Label()) { Unuse(); } |
| 68 | INLINE(~Label()) { ASSERT(!is_linked()); } |
| 69 | |
| 70 | INLINE(void Unuse()) { pos_ = 0; } |
| 71 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 72 | INLINE(bool is_bound() const) { return pos_ < 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 73 | INLINE(bool is_unused() const) { return pos_ == 0; } |
| 74 | INLINE(bool is_linked() const) { return pos_ > 0; } |
| 75 | |
| 76 | // Returns the position of bound or linked labels. Cannot be used |
| 77 | // for unused labels. |
| 78 | int pos() const; |
| 79 | |
| 80 | private: |
| 81 | // pos_ encodes both the binding state (via its sign) |
| 82 | // and the binding position (via its value) of a label. |
| 83 | // |
| 84 | // pos_ < 0 bound label, pos() returns the jump target position |
| 85 | // pos_ == 0 unused label |
| 86 | // pos_ > 0 linked label, pos() returns the last reference position |
| 87 | int pos_; |
| 88 | |
| 89 | void bind_to(int pos) { |
| 90 | pos_ = -pos - 1; |
| 91 | ASSERT(is_bound()); |
| 92 | } |
| 93 | void link_to(int pos) { |
| 94 | pos_ = pos + 1; |
| 95 | ASSERT(is_linked()); |
| 96 | } |
| 97 | |
| 98 | friend class Assembler; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 99 | friend class RegexpAssembler; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 100 | friend class Displacement; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 101 | friend class ShadowTarget; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 102 | friend class RegExpMacroAssemblerIrregexp; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 106 | // ----------------------------------------------------------------------------- |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 107 | // NearLabels are labels used for short jumps (in Intel jargon). |
| 108 | // NearLabels should be used if it can be guaranteed that the jump range is |
| 109 | // within -128 to +127. We already use short jumps when jumping backwards, |
| 110 | // so using a NearLabel will only have performance impact if used for forward |
| 111 | // jumps. |
| 112 | class NearLabel BASE_EMBEDDED { |
| 113 | public: |
| 114 | NearLabel() { Unuse(); } |
| 115 | ~NearLabel() { ASSERT(!is_linked()); } |
| 116 | |
| 117 | void Unuse() { |
| 118 | pos_ = -1; |
| 119 | unresolved_branches_ = 0; |
| 120 | #ifdef DEBUG |
| 121 | for (int i = 0; i < kMaxUnresolvedBranches; i++) { |
| 122 | unresolved_positions_[i] = -1; |
| 123 | } |
| 124 | #endif |
| 125 | } |
| 126 | |
| 127 | int pos() { |
| 128 | ASSERT(is_bound()); |
| 129 | return pos_; |
| 130 | } |
| 131 | |
| 132 | bool is_bound() { return pos_ >= 0; } |
| 133 | bool is_linked() { return !is_bound() && unresolved_branches_ > 0; } |
| 134 | bool is_unused() { return !is_bound() && unresolved_branches_ == 0; } |
| 135 | |
| 136 | void bind_to(int position) { |
| 137 | ASSERT(!is_bound()); |
| 138 | pos_ = position; |
| 139 | } |
| 140 | |
| 141 | void link_to(int position) { |
| 142 | ASSERT(!is_bound()); |
| 143 | ASSERT(unresolved_branches_ < kMaxUnresolvedBranches); |
| 144 | unresolved_positions_[unresolved_branches_++] = position; |
| 145 | } |
| 146 | |
| 147 | private: |
| 148 | static const int kMaxUnresolvedBranches = 8; |
| 149 | int pos_; |
| 150 | int unresolved_branches_; |
| 151 | int unresolved_positions_[kMaxUnresolvedBranches]; |
| 152 | |
| 153 | friend class Assembler; |
| 154 | }; |
| 155 | |
| 156 | |
| 157 | // ----------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 158 | // Relocation information |
| 159 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 160 | |
| 161 | // Relocation information consists of the address (pc) of the datum |
| 162 | // to which the relocation information applies, the relocation mode |
| 163 | // (rmode), and an optional data field. The relocation mode may be |
| 164 | // "descriptive" and not indicate a need for relocation, but simply |
| 165 | // describe a property of the datum. Such rmodes are useful for GC |
| 166 | // and nice disassembly output. |
| 167 | |
| 168 | class RelocInfo BASE_EMBEDDED { |
| 169 | public: |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 170 | // The constant kNoPosition is used with the collecting of source positions |
| 171 | // in the relocation information. Two types of source positions are collected |
| 172 | // "position" (RelocMode position) and "statement position" (RelocMode |
| 173 | // statement_position). The "position" is collected at places in the source |
| 174 | // code which are of interest when making stack traces to pin-point the source |
| 175 | // location of a stack frame as close as possible. The "statement position" is |
| 176 | // collected at the beginning at each statement, and is used to indicate |
| 177 | // possible break locations. kNoPosition is used to indicate an |
| 178 | // invalid/uninitialized position value. |
| 179 | static const int kNoPosition = -1; |
| 180 | |
| 181 | enum Mode { |
| 182 | // Please note the order is important (see IsCodeTarget, IsGCRelocMode). |
| 183 | CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor. |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 184 | CODE_TARGET_CONTEXT, // Code target used for contextual loads. |
| 185 | DEBUG_BREAK, // Code target for the debugger statement. |
| 186 | CODE_TARGET, // Code target which is not any of the above. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 187 | EMBEDDED_OBJECT, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 188 | GLOBAL_PROPERTY_CELL, |
| 189 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 190 | // Everything after runtime_entry (inclusive) is not GC'ed. |
| 191 | RUNTIME_ENTRY, |
| 192 | JS_RETURN, // Marks start of the ExitJSFrame code. |
| 193 | COMMENT, |
| 194 | POSITION, // See comment for kNoPosition above. |
| 195 | STATEMENT_POSITION, // See comment for kNoPosition above. |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 196 | DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 197 | EXTERNAL_REFERENCE, // The address of an external C++ function. |
| 198 | INTERNAL_REFERENCE, // An address inside the same function. |
| 199 | |
| 200 | // add more as needed |
| 201 | // Pseudo-types |
| 202 | NUMBER_OF_MODES, // must be no greater than 14 - see RelocInfoWriter |
| 203 | NONE, // never recorded |
| 204 | LAST_CODE_ENUM = CODE_TARGET, |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 205 | LAST_GCED_ENUM = GLOBAL_PROPERTY_CELL |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 209 | RelocInfo() {} |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 210 | RelocInfo(byte* pc, Mode rmode, intptr_t data) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 211 | : pc_(pc), rmode_(rmode), data_(data) { |
| 212 | } |
| 213 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 214 | static inline bool IsConstructCall(Mode mode) { |
| 215 | return mode == CONSTRUCT_CALL; |
| 216 | } |
| 217 | static inline bool IsCodeTarget(Mode mode) { |
| 218 | return mode <= LAST_CODE_ENUM; |
| 219 | } |
| 220 | // Is the relocation mode affected by GC? |
| 221 | static inline bool IsGCRelocMode(Mode mode) { |
| 222 | return mode <= LAST_GCED_ENUM; |
| 223 | } |
| 224 | static inline bool IsJSReturn(Mode mode) { |
| 225 | return mode == JS_RETURN; |
| 226 | } |
| 227 | static inline bool IsComment(Mode mode) { |
| 228 | return mode == COMMENT; |
| 229 | } |
| 230 | static inline bool IsPosition(Mode mode) { |
| 231 | return mode == POSITION || mode == STATEMENT_POSITION; |
| 232 | } |
| 233 | static inline bool IsStatementPosition(Mode mode) { |
| 234 | return mode == STATEMENT_POSITION; |
| 235 | } |
| 236 | static inline bool IsExternalReference(Mode mode) { |
| 237 | return mode == EXTERNAL_REFERENCE; |
| 238 | } |
| 239 | static inline bool IsInternalReference(Mode mode) { |
| 240 | return mode == INTERNAL_REFERENCE; |
| 241 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 242 | static inline bool IsDebugBreakSlot(Mode mode) { |
| 243 | return mode == DEBUG_BREAK_SLOT; |
| 244 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 245 | static inline int ModeMask(Mode mode) { return 1 << mode; } |
| 246 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 247 | // Accessors |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 248 | byte* pc() const { return pc_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 249 | void set_pc(byte* pc) { pc_ = pc; } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 250 | Mode rmode() const { return rmode_; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 251 | intptr_t data() const { return data_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 252 | |
| 253 | // Apply a relocation by delta bytes |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 254 | INLINE(void apply(intptr_t delta)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 256 | // Is the pointer this relocation info refers to coded like a plain pointer |
| 257 | // or is it strange in some way (eg relative or patched into a series of |
| 258 | // instructions). |
| 259 | bool IsCodedSpecially(); |
| 260 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 261 | // Read/modify the code target in the branch/call instruction |
| 262 | // this relocation applies to; |
| 263 | // can only be called if IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 264 | INLINE(Address target_address()); |
| 265 | INLINE(void set_target_address(Address target)); |
| 266 | INLINE(Object* target_object()); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 267 | INLINE(Handle<Object> target_object_handle(Assembler* origin)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 268 | INLINE(Object** target_object_address()); |
| 269 | INLINE(void set_target_object(Object* target)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 270 | INLINE(JSGlobalPropertyCell* target_cell()); |
| 271 | INLINE(Handle<JSGlobalPropertyCell> target_cell_handle()); |
| 272 | INLINE(void set_target_cell(JSGlobalPropertyCell* cell)); |
| 273 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 274 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 275 | // Read the address of the word containing the target_address in an |
| 276 | // instruction stream. What this means exactly is architecture-independent. |
| 277 | // The only architecture-independent user of this function is the serializer. |
| 278 | // The serializer uses it to find out how many raw bytes of instruction to |
| 279 | // output before the next target. Architecture-independent code shouldn't |
| 280 | // dereference the pointer it gets back from this. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 281 | INLINE(Address target_address_address()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 282 | // This indicates how much space a target takes up when deserializing a code |
| 283 | // stream. For most architectures this is just the size of a pointer. For |
| 284 | // an instruction like movw/movt where the target bits are mixed into the |
| 285 | // instruction bits the size of the target will be zero, indicating that the |
| 286 | // serializer should not step forwards in memory after a target is resolved |
| 287 | // and written. In this case the target_address_address function above |
| 288 | // should return the end of the instructions to be patched, allowing the |
| 289 | // deserializer to deserialize the instructions as raw bytes and put them in |
| 290 | // place, ready to be patched with the target. |
| 291 | INLINE(int target_address_size()); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 292 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 293 | // Read/modify the reference in the instruction this relocation |
| 294 | // applies to; can only be called if rmode_ is external_reference |
| 295 | INLINE(Address* target_reference_address()); |
| 296 | |
| 297 | // Read/modify the address of a call instruction. This is used to relocate |
| 298 | // the break points where straight-line code is patched with a call |
| 299 | // instruction. |
| 300 | INLINE(Address call_address()); |
| 301 | INLINE(void set_call_address(Address target)); |
| 302 | INLINE(Object* call_object()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 303 | INLINE(void set_call_object(Object* target)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 304 | INLINE(Object** call_object_address()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 305 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 306 | template<typename StaticVisitor> inline void Visit(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 307 | inline void Visit(ObjectVisitor* v); |
| 308 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 309 | // Patch the code with some other code. |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 310 | void PatchCode(byte* instructions, int instruction_count); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 311 | |
| 312 | // Patch the code with a call. |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 313 | void PatchCodeWithCall(Address target, int guard_bytes); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 314 | |
| 315 | // Check whether this return sequence has been patched |
| 316 | // with a call to the debugger. |
| 317 | INLINE(bool IsPatchedReturnSequence()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 318 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 319 | // Check whether this debug break slot has been patched with a call to the |
| 320 | // debugger. |
| 321 | INLINE(bool IsPatchedDebugBreakSlotSequence()); |
| 322 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 323 | #ifdef ENABLE_DISASSEMBLER |
| 324 | // Printing |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 325 | static const char* RelocModeName(Mode rmode); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 326 | void Print(FILE* out); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 327 | #endif // ENABLE_DISASSEMBLER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 328 | #ifdef DEBUG |
| 329 | // Debugging |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | void Verify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 331 | #endif |
| 332 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 333 | static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1; |
| 334 | static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION; |
| 335 | static const int kDebugMask = kPositionMask | 1 << COMMENT; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 336 | static const int kApplyMask; // Modes affected by apply. Depends on arch. |
| 337 | |
| 338 | private: |
| 339 | // On ARM, note that pc_ is the address of the constant pool entry |
| 340 | // to be relocated and not the address of the instruction |
| 341 | // referencing the constant pool entry (except when rmode_ == |
| 342 | // comment). |
| 343 | byte* pc_; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 344 | Mode rmode_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 345 | intptr_t data_; |
| 346 | friend class RelocIterator; |
| 347 | }; |
| 348 | |
| 349 | |
| 350 | // RelocInfoWriter serializes a stream of relocation info. It writes towards |
| 351 | // lower addresses. |
| 352 | class RelocInfoWriter BASE_EMBEDDED { |
| 353 | public: |
| 354 | RelocInfoWriter() : pos_(NULL), last_pc_(NULL), last_data_(0) {} |
| 355 | RelocInfoWriter(byte* pos, byte* pc) : pos_(pos), last_pc_(pc), |
| 356 | last_data_(0) {} |
| 357 | |
| 358 | byte* pos() const { return pos_; } |
| 359 | byte* last_pc() const { return last_pc_; } |
| 360 | |
| 361 | void Write(const RelocInfo* rinfo); |
| 362 | |
| 363 | // Update the state of the stream after reloc info buffer |
| 364 | // and/or code is moved while the stream is active. |
| 365 | void Reposition(byte* pos, byte* pc) { |
| 366 | pos_ = pos; |
| 367 | last_pc_ = pc; |
| 368 | } |
| 369 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 370 | // Max size (bytes) of a written RelocInfo. Longest encoding is |
| 371 | // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta. |
| 372 | // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12. |
| 373 | // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16; |
| 374 | // Here we use the maximum of the two. |
| 375 | static const int kMaxSize = 16; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 376 | |
| 377 | private: |
| 378 | inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta); |
| 379 | inline void WriteTaggedPC(uint32_t pc_delta, int tag); |
| 380 | inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 381 | inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag); |
| 382 | inline void WriteTaggedData(intptr_t data_delta, int tag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 383 | inline void WriteExtraTag(int extra_tag, int top_tag); |
| 384 | |
| 385 | byte* pos_; |
| 386 | byte* last_pc_; |
| 387 | intptr_t last_data_; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 388 | DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 389 | }; |
| 390 | |
| 391 | |
| 392 | // A RelocIterator iterates over relocation information. |
| 393 | // Typical use: |
| 394 | // |
| 395 | // for (RelocIterator it(code); !it.done(); it.next()) { |
| 396 | // // do something with it.rinfo() here |
| 397 | // } |
| 398 | // |
| 399 | // A mask can be specified to skip unwanted modes. |
| 400 | class RelocIterator: public Malloced { |
| 401 | public: |
| 402 | // Create a new iterator positioned at |
| 403 | // the beginning of the reloc info. |
| 404 | // Relocation information with mode k is included in the |
| 405 | // iteration iff bit k of mode_mask is set. |
| 406 | explicit RelocIterator(Code* code, int mode_mask = -1); |
| 407 | explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1); |
| 408 | |
| 409 | // Iteration |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 410 | bool done() const { return done_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 411 | void next(); |
| 412 | |
| 413 | // Return pointer valid until next next(). |
| 414 | RelocInfo* rinfo() { |
| 415 | ASSERT(!done()); |
| 416 | return &rinfo_; |
| 417 | } |
| 418 | |
| 419 | private: |
| 420 | // Advance* moves the position before/after reading. |
| 421 | // *Read* reads from current byte(s) into rinfo_. |
| 422 | // *Get* just reads and returns info on current byte. |
| 423 | void Advance(int bytes = 1) { pos_ -= bytes; } |
| 424 | int AdvanceGetTag(); |
| 425 | int GetExtraTag(); |
| 426 | int GetTopTag(); |
| 427 | void ReadTaggedPC(); |
| 428 | void AdvanceReadPC(); |
| 429 | void AdvanceReadData(); |
| 430 | void AdvanceReadVariableLengthPCJump(); |
| 431 | int GetPositionTypeTag(); |
| 432 | void ReadTaggedData(); |
| 433 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 434 | static RelocInfo::Mode DebugInfoModeFromTag(int tag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 435 | |
| 436 | // If the given mode is wanted, set it in rinfo_ and return true. |
| 437 | // Else return false. Used for efficiently skipping unwanted modes. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 438 | bool SetMode(RelocInfo::Mode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 439 | return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | byte* pos_; |
| 443 | byte* end_; |
| 444 | RelocInfo rinfo_; |
| 445 | bool done_; |
| 446 | int mode_mask_; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 447 | DISALLOW_COPY_AND_ASSIGN(RelocIterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 448 | }; |
| 449 | |
| 450 | |
| 451 | //------------------------------------------------------------------------------ |
| 452 | // External function |
| 453 | |
| 454 | //---------------------------------------------------------------------------- |
| 455 | class IC_Utility; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 456 | class SCTableReference; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 457 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 458 | class Debug_Address; |
| 459 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 461 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 462 | // An ExternalReference represents a C++ address used in the generated |
| 463 | // code. All references to C++ functions and variables must be encapsulated in |
| 464 | // an ExternalReference instance. This is done in order to track the origin of |
| 465 | // all external references in the code so that they can be bound to the correct |
| 466 | // addresses when deserializing a heap. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 467 | class ExternalReference BASE_EMBEDDED { |
| 468 | public: |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 469 | // Used in the simulator to support different native api calls. |
| 470 | // |
| 471 | // BUILTIN_CALL - builtin call. |
| 472 | // MaybeObject* f(v8::internal::Arguments). |
| 473 | // |
| 474 | // FP_RETURN_CALL - builtin call that returns floating point. |
| 475 | // double f(double, double). |
| 476 | // |
| 477 | // DIRECT_CALL - direct call to API function native callback |
| 478 | // from generated code. |
| 479 | // Handle<Value> f(v8::Arguments&) |
| 480 | // |
| 481 | enum Type { |
| 482 | BUILTIN_CALL, // default |
| 483 | FP_RETURN_CALL, |
| 484 | DIRECT_CALL |
| 485 | }; |
| 486 | |
| 487 | typedef void* ExternalReferenceRedirector(void* original, Type type); |
| 488 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 489 | explicit ExternalReference(Builtins::CFunctionId id); |
| 490 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 491 | explicit ExternalReference(ApiFunction* ptr, Type type); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 492 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 493 | explicit ExternalReference(Builtins::Name name); |
| 494 | |
| 495 | explicit ExternalReference(Runtime::FunctionId id); |
| 496 | |
| 497 | explicit ExternalReference(Runtime::Function* f); |
| 498 | |
| 499 | explicit ExternalReference(const IC_Utility& ic_utility); |
| 500 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 501 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 502 | explicit ExternalReference(const Debug_Address& debug_address); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 503 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 504 | |
| 505 | explicit ExternalReference(StatsCounter* counter); |
| 506 | |
| 507 | explicit ExternalReference(Top::AddressId id); |
| 508 | |
| 509 | explicit ExternalReference(const SCTableReference& table_ref); |
| 510 | |
| 511 | // One-of-a-kind references. These references are not part of a general |
| 512 | // pattern. This means that they have to be added to the |
| 513 | // ExternalReferenceTable in serialize.cc manually. |
| 514 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 515 | static ExternalReference perform_gc_function(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 516 | static ExternalReference fill_heap_number_with_random_function(); |
| 517 | static ExternalReference random_uint32_function(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 518 | static ExternalReference transcendental_cache_array_address(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 519 | static ExternalReference delete_handle_scope_extensions(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 520 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 521 | // Deoptimization support. |
| 522 | static ExternalReference new_deoptimizer_function(); |
| 523 | static ExternalReference compute_output_frames_function(); |
| 524 | static ExternalReference global_contexts_list(); |
| 525 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 526 | // Static data in the keyed lookup cache. |
| 527 | static ExternalReference keyed_lookup_cache_keys(); |
| 528 | static ExternalReference keyed_lookup_cache_field_offsets(); |
| 529 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 530 | // Static variable Factory::the_hole_value.location() |
| 531 | static ExternalReference the_hole_value_location(); |
| 532 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 533 | // Static variable Factory::arguments_marker.location() |
| 534 | static ExternalReference arguments_marker_location(); |
| 535 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 536 | // Static variable Heap::roots_address() |
| 537 | static ExternalReference roots_address(); |
| 538 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 539 | // Static variable StackGuard::address_of_jslimit() |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 540 | static ExternalReference address_of_stack_limit(); |
| 541 | |
| 542 | // Static variable StackGuard::address_of_real_jslimit() |
| 543 | static ExternalReference address_of_real_stack_limit(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 544 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 545 | // Static variable RegExpStack::limit_address() |
| 546 | static ExternalReference address_of_regexp_stack_limit(); |
| 547 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 548 | // Static variables for RegExp. |
| 549 | static ExternalReference address_of_static_offsets_vector(); |
| 550 | static ExternalReference address_of_regexp_stack_memory_address(); |
| 551 | static ExternalReference address_of_regexp_stack_memory_size(); |
| 552 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 553 | // Static variable Heap::NewSpaceStart() |
| 554 | static ExternalReference new_space_start(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 555 | static ExternalReference new_space_mask(); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 556 | static ExternalReference heap_always_allocate_scope_depth(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | |
| 558 | // Used for fast allocation in generated code. |
| 559 | static ExternalReference new_space_allocation_top_address(); |
| 560 | static ExternalReference new_space_allocation_limit_address(); |
| 561 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 562 | static ExternalReference double_fp_operation(Token::Value operation); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 563 | static ExternalReference compare_doubles(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 564 | static ExternalReference power_double_double_function(); |
| 565 | static ExternalReference power_double_int_function(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 567 | static ExternalReference handle_scope_next_address(); |
| 568 | static ExternalReference handle_scope_limit_address(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 569 | static ExternalReference handle_scope_level_address(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 570 | |
| 571 | static ExternalReference scheduled_exception_address(); |
| 572 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 573 | // Static variables containing common double constants. |
| 574 | static ExternalReference address_of_min_int(); |
| 575 | static ExternalReference address_of_one_half(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 576 | static ExternalReference address_of_minus_zero(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 577 | static ExternalReference address_of_negative_infinity(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 578 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 579 | Address address() const {return reinterpret_cast<Address>(address_);} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 580 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 581 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 582 | // Function Debug::Break() |
| 583 | static ExternalReference debug_break(); |
| 584 | |
| 585 | // Used to check if single stepping is enabled in generated code. |
| 586 | static ExternalReference debug_step_in_fp_address(); |
| 587 | #endif |
| 588 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 589 | #ifndef V8_INTERPRETED_REGEXP |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 590 | // C functions called from RegExp generated code. |
| 591 | |
| 592 | // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16() |
| 593 | static ExternalReference re_case_insensitive_compare_uc16(); |
| 594 | |
| 595 | // Function RegExpMacroAssembler*::CheckStackGuardState() |
| 596 | static ExternalReference re_check_stack_guard_state(); |
| 597 | |
| 598 | // Function NativeRegExpMacroAssembler::GrowStack() |
| 599 | static ExternalReference re_grow_stack(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 600 | |
| 601 | // byte NativeRegExpMacroAssembler::word_character_bitmap |
| 602 | static ExternalReference re_word_character_map(); |
| 603 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 604 | #endif |
| 605 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 606 | // This lets you register a function that rewrites all external references. |
| 607 | // Used by the ARM simulator to catch calls to external references. |
| 608 | static void set_redirector(ExternalReferenceRedirector* redirector) { |
| 609 | ASSERT(redirector_ == NULL); // We can't stack them. |
| 610 | redirector_ = redirector; |
| 611 | } |
| 612 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 613 | private: |
| 614 | explicit ExternalReference(void* address) |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 615 | : address_(address) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 616 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 617 | static ExternalReferenceRedirector* redirector_; |
| 618 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 619 | static void* Redirect(void* address, |
| 620 | Type type = ExternalReference::BUILTIN_CALL) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 621 | if (redirector_ == NULL) return address; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 622 | void* answer = (*redirector_)(address, type); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 623 | return answer; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 624 | } |
| 625 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 626 | static void* Redirect(Address address_arg, |
| 627 | Type type = ExternalReference::BUILTIN_CALL) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 628 | void* address = reinterpret_cast<void*>(address_arg); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 629 | void* answer = (redirector_ == NULL) ? |
| 630 | address : |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 631 | (*redirector_)(address, type); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 632 | return answer; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | void* address_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | }; |
| 637 | |
| 638 | |
| 639 | // ----------------------------------------------------------------------------- |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 640 | // Position recording support |
| 641 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 642 | struct PositionState { |
| 643 | PositionState() : current_position(RelocInfo::kNoPosition), |
| 644 | written_position(RelocInfo::kNoPosition), |
| 645 | current_statement_position(RelocInfo::kNoPosition), |
| 646 | written_statement_position(RelocInfo::kNoPosition) {} |
| 647 | |
| 648 | int current_position; |
| 649 | int written_position; |
| 650 | |
| 651 | int current_statement_position; |
| 652 | int written_statement_position; |
| 653 | }; |
| 654 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 655 | |
| 656 | class PositionsRecorder BASE_EMBEDDED { |
| 657 | public: |
| 658 | explicit PositionsRecorder(Assembler* assembler) |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 659 | : assembler_(assembler) { |
| 660 | #ifdef ENABLE_GDB_JIT_INTERFACE |
| 661 | gdbjit_lineinfo_ = NULL; |
| 662 | #endif |
| 663 | } |
| 664 | |
| 665 | #ifdef ENABLE_GDB_JIT_INTERFACE |
| 666 | ~PositionsRecorder() { |
| 667 | delete gdbjit_lineinfo_; |
| 668 | } |
| 669 | |
| 670 | void StartGDBJITLineInfoRecording() { |
| 671 | if (FLAG_gdbjit) { |
| 672 | gdbjit_lineinfo_ = new GDBJITLineInfo(); |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | GDBJITLineInfo* DetachGDBJITLineInfo() { |
| 677 | GDBJITLineInfo* lineinfo = gdbjit_lineinfo_; |
| 678 | gdbjit_lineinfo_ = NULL; // To prevent deallocation in destructor. |
| 679 | return lineinfo; |
| 680 | } |
| 681 | #endif |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 682 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 683 | // Set current position to pos. |
| 684 | void RecordPosition(int pos); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 685 | |
| 686 | // Set current statement position to pos. |
| 687 | void RecordStatementPosition(int pos); |
| 688 | |
| 689 | // Write recorded positions to relocation information. |
| 690 | bool WriteRecordedPositions(); |
| 691 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 692 | int current_position() const { return state_.current_position; } |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 693 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 694 | int current_statement_position() const { |
| 695 | return state_.current_statement_position; |
| 696 | } |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 697 | |
| 698 | private: |
| 699 | Assembler* assembler_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 700 | PositionState state_; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 701 | #ifdef ENABLE_GDB_JIT_INTERFACE |
| 702 | GDBJITLineInfo* gdbjit_lineinfo_; |
| 703 | #endif |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 704 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 705 | friend class PreservePositionScope; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 706 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 707 | DISALLOW_COPY_AND_ASSIGN(PositionsRecorder); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 708 | }; |
| 709 | |
| 710 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 711 | class PreservePositionScope BASE_EMBEDDED { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 712 | public: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 713 | explicit PreservePositionScope(PositionsRecorder* positions_recorder) |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 714 | : positions_recorder_(positions_recorder), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 715 | saved_state_(positions_recorder->state_) {} |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 716 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 717 | ~PreservePositionScope() { |
| 718 | positions_recorder_->state_ = saved_state_; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | private: |
| 722 | PositionsRecorder* positions_recorder_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 723 | const PositionState saved_state_; |
| 724 | |
| 725 | DISALLOW_COPY_AND_ASSIGN(PreservePositionScope); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 726 | }; |
| 727 | |
| 728 | |
| 729 | // ----------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 730 | // Utility functions |
| 731 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 732 | static inline bool is_intn(int x, int n) { |
| 733 | return -(1 << (n-1)) <= x && x < (1 << (n-1)); |
| 734 | } |
| 735 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 736 | static inline bool is_int8(int x) { return is_intn(x, 8); } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 737 | static inline bool is_int16(int x) { return is_intn(x, 16); } |
| 738 | static inline bool is_int18(int x) { return is_intn(x, 18); } |
| 739 | static inline bool is_int24(int x) { return is_intn(x, 24); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 740 | |
| 741 | static inline bool is_uintn(int x, int n) { |
| 742 | return (x & -(1 << n)) == 0; |
| 743 | } |
| 744 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 745 | static inline bool is_uint2(int x) { return is_uintn(x, 2); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 746 | static inline bool is_uint3(int x) { return is_uintn(x, 3); } |
| 747 | static inline bool is_uint4(int x) { return is_uintn(x, 4); } |
| 748 | static inline bool is_uint5(int x) { return is_uintn(x, 5); } |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 749 | static inline bool is_uint6(int x) { return is_uintn(x, 6); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 750 | static inline bool is_uint8(int x) { return is_uintn(x, 8); } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 751 | static inline bool is_uint10(int x) { return is_uintn(x, 10); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 752 | static inline bool is_uint12(int x) { return is_uintn(x, 12); } |
| 753 | static inline bool is_uint16(int x) { return is_uintn(x, 16); } |
| 754 | static inline bool is_uint24(int x) { return is_uintn(x, 24); } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 755 | static inline bool is_uint26(int x) { return is_uintn(x, 26); } |
| 756 | static inline bool is_uint28(int x) { return is_uintn(x, 28); } |
| 757 | |
| 758 | static inline int NumberOfBitsSet(uint32_t x) { |
| 759 | unsigned int num_bits_set; |
| 760 | for (num_bits_set = 0; x; x >>= 1) { |
| 761 | num_bits_set += x & 1; |
| 762 | } |
| 763 | return num_bits_set; |
| 764 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 765 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 766 | // Computes pow(x, y) with the special cases in the spec for Math.pow. |
| 767 | double power_double_int(double x, int y); |
| 768 | double power_double_double(double x, double y); |
| 769 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 770 | } } // namespace v8::internal |
| 771 | |
| 772 | #endif // V8_ASSEMBLER_H_ |