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