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