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