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