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