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. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 33 | // Copyright 2012 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 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 38 | #include "v8.h" |
| 39 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 40 | #include "allocation.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 41 | #include "builtins.h" |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 42 | #include "gdb-jit.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 43 | #include "isolate.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | #include "runtime.h" |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 45 | #include "token.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 46 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 47 | namespace v8 { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 48 | |
| 49 | class ApiFunction; |
| 50 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 51 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 53 | struct StatsCounter; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 54 | // ----------------------------------------------------------------------------- |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 55 | // Platform independent assembler base class. |
| 56 | |
| 57 | class AssemblerBase: public Malloced { |
| 58 | public: |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 59 | AssemblerBase(Isolate* isolate, void* buffer, int buffer_size); |
| 60 | virtual ~AssemblerBase(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 61 | |
| 62 | Isolate* isolate() const { return isolate_; } |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 63 | int jit_cookie() const { return jit_cookie_; } |
| 64 | |
| 65 | bool emit_debug_code() const { return emit_debug_code_; } |
| 66 | void set_emit_debug_code(bool value) { emit_debug_code_ = value; } |
| 67 | |
| 68 | bool predictable_code_size() const { return predictable_code_size_; } |
| 69 | void set_predictable_code_size(bool value) { predictable_code_size_ = value; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 70 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 71 | // Overwrite a host NaN with a quiet target NaN. Used by mksnapshot for |
| 72 | // cross-snapshotting. |
| 73 | static void QuietNaN(HeapObject* nan) { } |
| 74 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 75 | int pc_offset() const { return static_cast<int>(pc_ - buffer_); } |
| 76 | |
| 77 | static const int kMinimalBufferSize = 4*KB; |
| 78 | |
| 79 | protected: |
| 80 | // The buffer into which code and relocation info are generated. It could |
| 81 | // either be owned by the assembler or be provided externally. |
| 82 | byte* buffer_; |
| 83 | int buffer_size_; |
| 84 | bool own_buffer_; |
| 85 | |
| 86 | // The program counter, which points into the buffer above and moves forward. |
| 87 | byte* pc_; |
| 88 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 89 | private: |
| 90 | Isolate* isolate_; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 91 | int jit_cookie_; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 92 | bool emit_debug_code_; |
| 93 | bool predictable_code_size_; |
| 94 | }; |
| 95 | |
| 96 | |
| 97 | // Avoids using instructions that vary in size in unpredictable ways between the |
| 98 | // snapshot and the running VM. |
| 99 | class PredictableCodeSizeScope { |
| 100 | public: |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 101 | PredictableCodeSizeScope(AssemblerBase* assembler, int expected_size); |
| 102 | ~PredictableCodeSizeScope(); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 103 | |
| 104 | private: |
| 105 | AssemblerBase* assembler_; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 106 | int expected_size_; |
| 107 | int start_offset_; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 108 | bool old_value_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 111 | |
| 112 | // ----------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | // Labels represent pc locations; they are typically jump or call targets. |
| 114 | // After declaration, a label can be freely used to denote known or (yet) |
| 115 | // unknown pc location. Assembler::bind() is used to bind a label to the |
| 116 | // current pc. A label can be bound only once. |
| 117 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 118 | class Label BASE_EMBEDDED { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | public: |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 120 | enum Distance { |
| 121 | kNear, kFar |
| 122 | }; |
| 123 | |
| 124 | INLINE(Label()) { |
| 125 | Unuse(); |
| 126 | UnuseNear(); |
| 127 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 128 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 129 | INLINE(~Label()) { |
| 130 | ASSERT(!is_linked()); |
| 131 | ASSERT(!is_near_linked()); |
| 132 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 133 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 134 | INLINE(void Unuse()) { pos_ = 0; } |
| 135 | INLINE(void UnuseNear()) { near_link_pos_ = 0; } |
| 136 | |
| 137 | INLINE(bool is_bound() const) { return pos_ < 0; } |
| 138 | INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; } |
| 139 | INLINE(bool is_linked() const) { return pos_ > 0; } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 140 | INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 141 | |
| 142 | // Returns the position of bound or linked labels. Cannot be used |
| 143 | // for unused labels. |
| 144 | int pos() const; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 145 | int near_link_pos() const { return near_link_pos_ - 1; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 146 | |
| 147 | private: |
| 148 | // pos_ encodes both the binding state (via its sign) |
| 149 | // and the binding position (via its value) of a label. |
| 150 | // |
| 151 | // pos_ < 0 bound label, pos() returns the jump target position |
| 152 | // pos_ == 0 unused label |
| 153 | // pos_ > 0 linked label, pos() returns the last reference position |
| 154 | int pos_; |
| 155 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 156 | // Behaves like |pos_| in the "> 0" case, but for near jumps to this label. |
| 157 | int near_link_pos_; |
| 158 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 159 | void bind_to(int pos) { |
| 160 | pos_ = -pos - 1; |
| 161 | ASSERT(is_bound()); |
| 162 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 163 | void link_to(int pos, Distance distance = kFar) { |
| 164 | if (distance == kNear) { |
| 165 | near_link_pos_ = pos + 1; |
| 166 | ASSERT(is_near_linked()); |
| 167 | } else { |
| 168 | pos_ = pos + 1; |
| 169 | ASSERT(is_linked()); |
| 170 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | friend class Assembler; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 174 | friend class RegexpAssembler; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 175 | friend class Displacement; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 176 | friend class RegExpMacroAssemblerIrregexp; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 180 | enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs }; |
| 181 | |
| 182 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | // ----------------------------------------------------------------------------- |
| 184 | // Relocation information |
| 185 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 186 | |
| 187 | // Relocation information consists of the address (pc) of the datum |
| 188 | // to which the relocation information applies, the relocation mode |
| 189 | // (rmode), and an optional data field. The relocation mode may be |
| 190 | // "descriptive" and not indicate a need for relocation, but simply |
| 191 | // describe a property of the datum. Such rmodes are useful for GC |
| 192 | // and nice disassembly output. |
| 193 | |
| 194 | class RelocInfo BASE_EMBEDDED { |
| 195 | public: |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 196 | // The constant kNoPosition is used with the collecting of source positions |
| 197 | // in the relocation information. Two types of source positions are collected |
| 198 | // "position" (RelocMode position) and "statement position" (RelocMode |
| 199 | // statement_position). The "position" is collected at places in the source |
| 200 | // code which are of interest when making stack traces to pin-point the source |
| 201 | // location of a stack frame as close as possible. The "statement position" is |
| 202 | // collected at the beginning at each statement, and is used to indicate |
| 203 | // possible break locations. kNoPosition is used to indicate an |
| 204 | // invalid/uninitialized position value. |
| 205 | static const int kNoPosition = -1; |
| 206 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 207 | // This string is used to add padding comments to the reloc info in cases |
| 208 | // where we are not sure to have enough space for patching in during |
| 209 | // lazy deoptimization. This is the case if we have indirect calls for which |
| 210 | // we do not normally record relocation info. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 211 | static const char* const kFillerCommentString; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 212 | |
ricow@chromium.org | 2233451 | 2011-02-25 07:28:50 +0000 | [diff] [blame] | 213 | // The minimum size of a comment is equal to three bytes for the extra tagged |
| 214 | // 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] | 215 | // comment. |
ricow@chromium.org | 2233451 | 2011-02-25 07:28:50 +0000 | [diff] [blame] | 216 | static const int kMinRelocCommentSize = 3 + kPointerSize; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 217 | |
| 218 | // The maximum size for a call instruction including pc-jump. |
| 219 | static const int kMaxCallSize = 6; |
| 220 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 221 | // The maximum pc delta that will use the short encoding. |
| 222 | static const int kMaxSmallPCDelta; |
| 223 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 224 | enum Mode { |
| 225 | // Please note the order is important (see IsCodeTarget, IsGCRelocMode). |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 226 | CODE_TARGET, // Code target which is not any of the above. |
| 227 | CODE_TARGET_WITH_ID, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 228 | 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] | 229 | CODE_TARGET_CONTEXT, // Code target used for contextual loads and stores. |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 230 | DEBUG_BREAK, // Code target for the debugger statement. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 231 | EMBEDDED_OBJECT, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 232 | GLOBAL_PROPERTY_CELL, |
| 233 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 234 | // Everything after runtime_entry (inclusive) is not GC'ed. |
| 235 | RUNTIME_ENTRY, |
| 236 | JS_RETURN, // Marks start of the ExitJSFrame code. |
| 237 | COMMENT, |
| 238 | POSITION, // See comment for kNoPosition above. |
| 239 | STATEMENT_POSITION, // See comment for kNoPosition above. |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 240 | DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 241 | EXTERNAL_REFERENCE, // The address of an external C++ function. |
| 242 | INTERNAL_REFERENCE, // An address inside the same function. |
| 243 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 244 | // Marks a constant pool. Only used on ARM. |
| 245 | // It uses a custom noncompact encoding. |
| 246 | CONST_POOL, |
| 247 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 248 | // add more as needed |
| 249 | // Pseudo-types |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 250 | NUMBER_OF_MODES, // There are at most 15 modes with noncompact encoding. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 251 | NONE32, // never recorded 32-bit value |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 252 | NONE64, // never recorded 64-bit value |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 253 | CODE_AGE_SEQUENCE, // Not stored in RelocInfo array, used explictly by |
| 254 | // code aging. |
| 255 | FIRST_REAL_RELOC_MODE = CODE_TARGET, |
| 256 | LAST_REAL_RELOC_MODE = CONST_POOL, |
| 257 | FIRST_PSEUDO_RELOC_MODE = CODE_AGE_SEQUENCE, |
| 258 | LAST_PSEUDO_RELOC_MODE = CODE_AGE_SEQUENCE, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 259 | LAST_CODE_ENUM = DEBUG_BREAK, |
| 260 | LAST_GCED_ENUM = GLOBAL_PROPERTY_CELL, |
| 261 | // Modes <= LAST_COMPACT_ENUM are guaranteed to have compact encoding. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 262 | LAST_COMPACT_ENUM = CODE_TARGET_WITH_ID, |
| 263 | LAST_STANDARD_NONCOMPACT_ENUM = INTERNAL_REFERENCE |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 267 | RelocInfo() {} |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 268 | |
| 269 | RelocInfo(byte* pc, Mode rmode, intptr_t data, Code* host) |
| 270 | : pc_(pc), rmode_(rmode), data_(data), host_(host) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 271 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 272 | RelocInfo(byte* pc, double data64) |
| 273 | : pc_(pc), rmode_(NONE64), data64_(data64), host_(NULL) { |
| 274 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 275 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 276 | static inline bool IsRealRelocMode(Mode mode) { |
| 277 | return mode >= FIRST_REAL_RELOC_MODE && |
| 278 | mode <= LAST_REAL_RELOC_MODE; |
| 279 | } |
| 280 | static inline bool IsPseudoRelocMode(Mode mode) { |
| 281 | ASSERT(!IsRealRelocMode(mode)); |
| 282 | return mode >= FIRST_PSEUDO_RELOC_MODE && |
| 283 | mode <= LAST_PSEUDO_RELOC_MODE; |
| 284 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 285 | static inline bool IsConstructCall(Mode mode) { |
| 286 | return mode == CONSTRUCT_CALL; |
| 287 | } |
| 288 | static inline bool IsCodeTarget(Mode mode) { |
| 289 | return mode <= LAST_CODE_ENUM; |
| 290 | } |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 291 | static inline bool IsEmbeddedObject(Mode mode) { |
| 292 | return mode == EMBEDDED_OBJECT; |
| 293 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 294 | // Is the relocation mode affected by GC? |
| 295 | static inline bool IsGCRelocMode(Mode mode) { |
| 296 | return mode <= LAST_GCED_ENUM; |
| 297 | } |
| 298 | static inline bool IsJSReturn(Mode mode) { |
| 299 | return mode == JS_RETURN; |
| 300 | } |
| 301 | static inline bool IsComment(Mode mode) { |
| 302 | return mode == COMMENT; |
| 303 | } |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 304 | static inline bool IsConstPool(Mode mode) { |
| 305 | return mode == CONST_POOL; |
| 306 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 307 | static inline bool IsPosition(Mode mode) { |
| 308 | return mode == POSITION || mode == STATEMENT_POSITION; |
| 309 | } |
| 310 | static inline bool IsStatementPosition(Mode mode) { |
| 311 | return mode == STATEMENT_POSITION; |
| 312 | } |
| 313 | static inline bool IsExternalReference(Mode mode) { |
| 314 | return mode == EXTERNAL_REFERENCE; |
| 315 | } |
| 316 | static inline bool IsInternalReference(Mode mode) { |
| 317 | return mode == INTERNAL_REFERENCE; |
| 318 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 319 | static inline bool IsDebugBreakSlot(Mode mode) { |
| 320 | return mode == DEBUG_BREAK_SLOT; |
| 321 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 322 | static inline bool IsNone(Mode mode) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 323 | return mode == NONE32 || mode == NONE64; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 324 | } |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 325 | static inline bool IsCodeAgeSequence(Mode mode) { |
| 326 | return mode == CODE_AGE_SEQUENCE; |
| 327 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 328 | static inline int ModeMask(Mode mode) { return 1 << mode; } |
| 329 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | // Accessors |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 331 | byte* pc() const { return pc_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 332 | void set_pc(byte* pc) { pc_ = pc; } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 333 | Mode rmode() const { return rmode_; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 334 | intptr_t data() const { return data_; } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 335 | double data64() const { return data64_; } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 336 | Code* host() const { return host_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | |
| 338 | // Apply a relocation by delta bytes |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 339 | INLINE(void apply(intptr_t delta)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 340 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 341 | // Is the pointer this relocation info refers to coded like a plain pointer |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 342 | // or is it strange in some way (e.g. relative or patched into a series of |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 343 | // instructions). |
| 344 | bool IsCodedSpecially(); |
| 345 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 346 | // Read/modify the code target in the branch/call instruction |
| 347 | // this relocation applies to; |
| 348 | // can only be called if IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 349 | INLINE(Address target_address()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 350 | INLINE(void set_target_address(Address target, |
| 351 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 352 | INLINE(Object* target_object()); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 353 | INLINE(Handle<Object> target_object_handle(Assembler* origin)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 354 | INLINE(Object** target_object_address()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 355 | INLINE(void set_target_object(Object* target, |
| 356 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 357 | INLINE(JSGlobalPropertyCell* target_cell()); |
| 358 | INLINE(Handle<JSGlobalPropertyCell> target_cell_handle()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 359 | INLINE(void set_target_cell(JSGlobalPropertyCell* cell, |
| 360 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 361 | INLINE(Code* code_age_stub()); |
| 362 | INLINE(void set_code_age_stub(Code* stub)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 363 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 364 | // Read the address of the word containing the target_address in an |
| 365 | // instruction stream. What this means exactly is architecture-independent. |
| 366 | // The only architecture-independent user of this function is the serializer. |
| 367 | // The serializer uses it to find out how many raw bytes of instruction to |
| 368 | // output before the next target. Architecture-independent code shouldn't |
| 369 | // dereference the pointer it gets back from this. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 370 | INLINE(Address target_address_address()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 371 | // This indicates how much space a target takes up when deserializing a code |
| 372 | // stream. For most architectures this is just the size of a pointer. For |
| 373 | // an instruction like movw/movt where the target bits are mixed into the |
| 374 | // instruction bits the size of the target will be zero, indicating that the |
| 375 | // serializer should not step forwards in memory after a target is resolved |
| 376 | // and written. In this case the target_address_address function above |
| 377 | // should return the end of the instructions to be patched, allowing the |
| 378 | // deserializer to deserialize the instructions as raw bytes and put them in |
| 379 | // place, ready to be patched with the target. |
| 380 | INLINE(int target_address_size()); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 381 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 382 | // Read/modify the reference in the instruction this relocation |
| 383 | // applies to; can only be called if rmode_ is external_reference |
| 384 | INLINE(Address* target_reference_address()); |
| 385 | |
| 386 | // Read/modify the address of a call instruction. This is used to relocate |
| 387 | // the break points where straight-line code is patched with a call |
| 388 | // instruction. |
| 389 | INLINE(Address call_address()); |
| 390 | INLINE(void set_call_address(Address target)); |
| 391 | INLINE(Object* call_object()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 392 | INLINE(void set_call_object(Object* target)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 393 | INLINE(Object** call_object_address()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 394 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 395 | template<typename StaticVisitor> inline void Visit(Heap* heap); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 396 | inline void Visit(ObjectVisitor* v); |
| 397 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 398 | // Patch the code with some other code. |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 399 | void PatchCode(byte* instructions, int instruction_count); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 400 | |
| 401 | // Patch the code with a call. |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 402 | void PatchCodeWithCall(Address target, int guard_bytes); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 403 | |
| 404 | // Check whether this return sequence has been patched |
| 405 | // with a call to the debugger. |
| 406 | INLINE(bool IsPatchedReturnSequence()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 407 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 408 | // Check whether this debug break slot has been patched with a call to the |
| 409 | // debugger. |
| 410 | INLINE(bool IsPatchedDebugBreakSlotSequence()); |
| 411 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame^] | 412 | #ifdef DEBUG |
| 413 | // Check whether the given code contains relocation information that |
| 414 | // either is position-relative or movable by the garbage collector. |
| 415 | static bool RequiresRelocation(const CodeDesc& desc); |
| 416 | #endif |
| 417 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 418 | #ifdef ENABLE_DISASSEMBLER |
| 419 | // Printing |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 420 | static const char* RelocModeName(Mode rmode); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 421 | void Print(FILE* out); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 422 | #endif // ENABLE_DISASSEMBLER |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 423 | #ifdef VERIFY_HEAP |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 424 | void Verify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 425 | #endif |
| 426 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 427 | static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1; |
| 428 | static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 429 | static const int kDataMask = |
| 430 | (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 431 | static const int kApplyMask; // Modes affected by apply. Depends on arch. |
| 432 | |
| 433 | private: |
| 434 | // On ARM, note that pc_ is the address of the constant pool entry |
| 435 | // to be relocated and not the address of the instruction |
| 436 | // referencing the constant pool entry (except when rmode_ == |
| 437 | // comment). |
| 438 | byte* pc_; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 439 | Mode rmode_; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 440 | union { |
| 441 | intptr_t data_; |
| 442 | double data64_; |
| 443 | }; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 444 | Code* host_; |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 445 | // Code and Embedded Object pointers on some platforms are stored split |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 446 | // across two consecutive 32-bit instructions. Heap management |
| 447 | // routines expect to access these pointers indirectly. The following |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 448 | // location provides a place for these pointers to exist naturally |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 449 | // when accessed via the Iterator. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 450 | Object* reconstructed_obj_ptr_; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 451 | // External-reference pointers are also split across instruction-pairs |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 452 | // on some platforms, but are accessed via indirect pointers. This location |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 453 | // provides a place for that pointer to exist naturally. Its address |
| 454 | // is returned by RelocInfo::target_reference_address(). |
| 455 | Address reconstructed_adr_ptr_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 456 | friend class RelocIterator; |
| 457 | }; |
| 458 | |
| 459 | |
| 460 | // RelocInfoWriter serializes a stream of relocation info. It writes towards |
| 461 | // lower addresses. |
| 462 | class RelocInfoWriter BASE_EMBEDDED { |
| 463 | public: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 464 | RelocInfoWriter() : pos_(NULL), |
| 465 | last_pc_(NULL), |
| 466 | last_id_(0), |
| 467 | last_position_(0) {} |
| 468 | RelocInfoWriter(byte* pos, byte* pc) : pos_(pos), |
| 469 | last_pc_(pc), |
| 470 | last_id_(0), |
| 471 | last_position_(0) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 472 | |
| 473 | byte* pos() const { return pos_; } |
| 474 | byte* last_pc() const { return last_pc_; } |
| 475 | |
| 476 | void Write(const RelocInfo* rinfo); |
| 477 | |
| 478 | // Update the state of the stream after reloc info buffer |
| 479 | // and/or code is moved while the stream is active. |
| 480 | void Reposition(byte* pos, byte* pc) { |
| 481 | pos_ = pos; |
| 482 | last_pc_ = pc; |
| 483 | } |
| 484 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 485 | // Max size (bytes) of a written RelocInfo. Longest encoding is |
| 486 | // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta. |
| 487 | // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12. |
| 488 | // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16; |
| 489 | // Here we use the maximum of the two. |
| 490 | static const int kMaxSize = 16; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 491 | |
| 492 | private: |
| 493 | inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta); |
| 494 | inline void WriteTaggedPC(uint32_t pc_delta, int tag); |
| 495 | inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 496 | inline void WriteExtraTaggedIntData(int data_delta, int top_tag); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 497 | inline void WriteExtraTaggedConstPoolData(int data); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 498 | inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag); |
| 499 | inline void WriteTaggedData(intptr_t data_delta, int tag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 500 | inline void WriteExtraTag(int extra_tag, int top_tag); |
| 501 | |
| 502 | byte* pos_; |
| 503 | byte* last_pc_; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 504 | int last_id_; |
| 505 | int last_position_; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 506 | DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 507 | }; |
| 508 | |
| 509 | |
| 510 | // A RelocIterator iterates over relocation information. |
| 511 | // Typical use: |
| 512 | // |
| 513 | // for (RelocIterator it(code); !it.done(); it.next()) { |
| 514 | // // do something with it.rinfo() here |
| 515 | // } |
| 516 | // |
| 517 | // A mask can be specified to skip unwanted modes. |
| 518 | class RelocIterator: public Malloced { |
| 519 | public: |
| 520 | // Create a new iterator positioned at |
| 521 | // the beginning of the reloc info. |
| 522 | // Relocation information with mode k is included in the |
| 523 | // iteration iff bit k of mode_mask is set. |
| 524 | explicit RelocIterator(Code* code, int mode_mask = -1); |
| 525 | explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1); |
| 526 | |
| 527 | // Iteration |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 528 | bool done() const { return done_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 529 | void next(); |
| 530 | |
| 531 | // Return pointer valid until next next(). |
| 532 | RelocInfo* rinfo() { |
| 533 | ASSERT(!done()); |
| 534 | return &rinfo_; |
| 535 | } |
| 536 | |
| 537 | private: |
| 538 | // Advance* moves the position before/after reading. |
| 539 | // *Read* reads from current byte(s) into rinfo_. |
| 540 | // *Get* just reads and returns info on current byte. |
| 541 | void Advance(int bytes = 1) { pos_ -= bytes; } |
| 542 | int AdvanceGetTag(); |
| 543 | int GetExtraTag(); |
| 544 | int GetTopTag(); |
| 545 | void ReadTaggedPC(); |
| 546 | void AdvanceReadPC(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 547 | void AdvanceReadId(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 548 | void AdvanceReadConstPoolData(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 549 | void AdvanceReadPosition(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 550 | void AdvanceReadData(); |
| 551 | void AdvanceReadVariableLengthPCJump(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 552 | int GetLocatableTypeTag(); |
| 553 | void ReadTaggedId(); |
| 554 | void ReadTaggedPosition(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | |
| 556 | // If the given mode is wanted, set it in rinfo_ and return true. |
| 557 | // Else return false. Used for efficiently skipping unwanted modes. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 558 | bool SetMode(RelocInfo::Mode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 559 | return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | byte* pos_; |
| 563 | byte* end_; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 564 | byte* code_age_sequence_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 565 | RelocInfo rinfo_; |
| 566 | bool done_; |
| 567 | int mode_mask_; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 568 | int last_id_; |
| 569 | int last_position_; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 570 | DISALLOW_COPY_AND_ASSIGN(RelocIterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 571 | }; |
| 572 | |
| 573 | |
| 574 | //------------------------------------------------------------------------------ |
| 575 | // External function |
| 576 | |
| 577 | //---------------------------------------------------------------------------- |
| 578 | class IC_Utility; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 579 | class SCTableReference; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 580 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 581 | class Debug_Address; |
| 582 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 583 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 584 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 585 | // An ExternalReference represents a C++ address used in the generated |
| 586 | // code. All references to C++ functions and variables must be encapsulated in |
| 587 | // an ExternalReference instance. This is done in order to track the origin of |
| 588 | // all external references in the code so that they can be bound to the correct |
| 589 | // addresses when deserializing a heap. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 590 | class ExternalReference BASE_EMBEDDED { |
| 591 | public: |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 592 | // Used in the simulator to support different native api calls. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 593 | enum Type { |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 594 | // Builtin call. |
| 595 | // MaybeObject* f(v8::internal::Arguments). |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 596 | BUILTIN_CALL, // default |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 597 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 598 | // Builtin that takes float arguments and returns an int. |
| 599 | // int f(double, double). |
| 600 | BUILTIN_COMPARE_CALL, |
| 601 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 602 | // Builtin call that returns floating point. |
| 603 | // double f(double, double). |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 604 | BUILTIN_FP_FP_CALL, |
| 605 | |
| 606 | // Builtin call that returns floating point. |
| 607 | // double f(double). |
| 608 | BUILTIN_FP_CALL, |
| 609 | |
| 610 | // Builtin call that returns floating point. |
| 611 | // double f(double, int). |
| 612 | BUILTIN_FP_INT_CALL, |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 613 | |
| 614 | // Direct call to API function callback. |
| 615 | // Handle<Value> f(v8::Arguments&) |
| 616 | DIRECT_API_CALL, |
| 617 | |
| 618 | // Direct call to accessor getter callback. |
| 619 | // Handle<value> f(Local<String> property, AccessorInfo& info) |
| 620 | DIRECT_GETTER_CALL |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 621 | }; |
| 622 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 623 | static void SetUp(); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 624 | static void InitializeMathExpData(); |
| 625 | static void TearDownMathExpData(); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 626 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 627 | typedef void* ExternalReferenceRedirector(void* original, Type type); |
| 628 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 629 | ExternalReference(Builtins::CFunctionId id, Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 630 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 631 | ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 632 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 633 | ExternalReference(Builtins::Name name, Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 634 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 635 | ExternalReference(Runtime::FunctionId id, Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 637 | ExternalReference(const Runtime::Function* f, Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 638 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 639 | ExternalReference(const IC_Utility& ic_utility, Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 640 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 641 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 642 | ExternalReference(const Debug_Address& debug_address, Isolate* isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 643 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 644 | |
| 645 | explicit ExternalReference(StatsCounter* counter); |
| 646 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 647 | ExternalReference(Isolate::AddressId id, Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 648 | |
| 649 | explicit ExternalReference(const SCTableReference& table_ref); |
| 650 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 651 | // Isolate::Current() as an external reference. |
| 652 | static ExternalReference isolate_address(); |
| 653 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 654 | // One-of-a-kind references. These references are not part of a general |
| 655 | // pattern. This means that they have to be added to the |
| 656 | // ExternalReferenceTable in serialize.cc manually. |
| 657 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 658 | static ExternalReference incremental_marking_record_write_function( |
| 659 | Isolate* isolate); |
| 660 | static ExternalReference incremental_evacuation_record_write_function( |
| 661 | Isolate* isolate); |
| 662 | static ExternalReference store_buffer_overflow_function( |
| 663 | Isolate* isolate); |
| 664 | static ExternalReference flush_icache_function(Isolate* isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 665 | static ExternalReference perform_gc_function(Isolate* isolate); |
| 666 | static ExternalReference fill_heap_number_with_random_function( |
| 667 | Isolate* isolate); |
| 668 | static ExternalReference random_uint32_function(Isolate* isolate); |
| 669 | static ExternalReference transcendental_cache_array_address(Isolate* isolate); |
| 670 | static ExternalReference delete_handle_scope_extensions(Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 671 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 672 | static ExternalReference get_date_field_function(Isolate* isolate); |
| 673 | static ExternalReference date_cache_stamp(Isolate* isolate); |
| 674 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 675 | static ExternalReference get_make_code_young_function(Isolate* isolate); |
| 676 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 677 | // Deoptimization support. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 678 | static ExternalReference new_deoptimizer_function(Isolate* isolate); |
| 679 | static ExternalReference compute_output_frames_function(Isolate* isolate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 680 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 681 | // Log support. |
| 682 | static ExternalReference log_enter_external_function(Isolate* isolate); |
| 683 | static ExternalReference log_leave_external_function(Isolate* isolate); |
| 684 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 685 | // Static data in the keyed lookup cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 686 | static ExternalReference keyed_lookup_cache_keys(Isolate* isolate); |
| 687 | static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 688 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 689 | // Static variable Heap::roots_array_start() |
| 690 | static ExternalReference roots_array_start(Isolate* isolate); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 691 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 692 | // Static variable StackGuard::address_of_jslimit() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 693 | static ExternalReference address_of_stack_limit(Isolate* isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 694 | |
| 695 | // Static variable StackGuard::address_of_real_jslimit() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 696 | static ExternalReference address_of_real_stack_limit(Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 697 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 698 | // Static variable RegExpStack::limit_address() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 699 | static ExternalReference address_of_regexp_stack_limit(Isolate* isolate); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 700 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 701 | // Static variables for RegExp. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 702 | static ExternalReference address_of_static_offsets_vector(Isolate* isolate); |
| 703 | static ExternalReference address_of_regexp_stack_memory_address( |
| 704 | Isolate* isolate); |
| 705 | static ExternalReference address_of_regexp_stack_memory_size( |
| 706 | Isolate* isolate); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 707 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 708 | // Static variable Heap::NewSpaceStart() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 709 | static ExternalReference new_space_start(Isolate* isolate); |
| 710 | static ExternalReference new_space_mask(Isolate* isolate); |
| 711 | static ExternalReference heap_always_allocate_scope_depth(Isolate* isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 712 | static ExternalReference new_space_mark_bits(Isolate* isolate); |
| 713 | |
| 714 | // Write barrier. |
| 715 | static ExternalReference store_buffer_top(Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 716 | |
| 717 | // Used for fast allocation in generated code. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 718 | static ExternalReference new_space_allocation_top_address(Isolate* isolate); |
| 719 | static ExternalReference new_space_allocation_limit_address(Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 720 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 721 | static ExternalReference double_fp_operation(Token::Value operation, |
| 722 | Isolate* isolate); |
| 723 | static ExternalReference compare_doubles(Isolate* isolate); |
| 724 | static ExternalReference power_double_double_function(Isolate* isolate); |
| 725 | static ExternalReference power_double_int_function(Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 726 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 727 | static ExternalReference handle_scope_next_address(); |
| 728 | static ExternalReference handle_scope_limit_address(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 729 | static ExternalReference handle_scope_level_address(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 730 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 731 | static ExternalReference scheduled_exception_address(Isolate* isolate); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 732 | static ExternalReference address_of_pending_message_obj(Isolate* isolate); |
| 733 | static ExternalReference address_of_has_pending_message(Isolate* isolate); |
| 734 | static ExternalReference address_of_pending_message_script(Isolate* isolate); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 735 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 736 | // Static variables containing common double constants. |
| 737 | static ExternalReference address_of_min_int(); |
| 738 | static ExternalReference address_of_one_half(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 739 | static ExternalReference address_of_minus_zero(); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 740 | static ExternalReference address_of_zero(); |
| 741 | static ExternalReference address_of_uint8_max_value(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 742 | static ExternalReference address_of_negative_infinity(); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 743 | static ExternalReference address_of_canonical_non_hole_nan(); |
| 744 | static ExternalReference address_of_the_hole_nan(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 745 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 746 | static ExternalReference math_sin_double_function(Isolate* isolate); |
| 747 | static ExternalReference math_cos_double_function(Isolate* isolate); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 748 | static ExternalReference math_tan_double_function(Isolate* isolate); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 749 | static ExternalReference math_log_double_function(Isolate* isolate); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 750 | |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 751 | static ExternalReference math_exp_constants(int constant_index); |
| 752 | static ExternalReference math_exp_log_table(); |
| 753 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 754 | static ExternalReference page_flags(Page* page); |
| 755 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 756 | static ExternalReference ForDeoptEntry(Address entry); |
| 757 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 758 | static ExternalReference cpu_features(); |
| 759 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 760 | Address address() const {return reinterpret_cast<Address>(address_);} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 761 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 762 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 763 | // Function Debug::Break() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 764 | static ExternalReference debug_break(Isolate* isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 765 | |
| 766 | // Used to check if single stepping is enabled in generated code. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 767 | static ExternalReference debug_step_in_fp_address(Isolate* isolate); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 768 | #endif |
| 769 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 770 | #ifndef V8_INTERPRETED_REGEXP |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 771 | // C functions called from RegExp generated code. |
| 772 | |
| 773 | // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 774 | static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 775 | |
| 776 | // Function RegExpMacroAssembler*::CheckStackGuardState() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 777 | static ExternalReference re_check_stack_guard_state(Isolate* isolate); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 778 | |
| 779 | // Function NativeRegExpMacroAssembler::GrowStack() |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 780 | static ExternalReference re_grow_stack(Isolate* isolate); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 781 | |
| 782 | // byte NativeRegExpMacroAssembler::word_character_bitmap |
| 783 | static ExternalReference re_word_character_map(); |
| 784 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 785 | #endif |
| 786 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 787 | // This lets you register a function that rewrites all external references. |
| 788 | // Used by the ARM simulator to catch calls to external references. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 789 | static void set_redirector(Isolate* isolate, |
| 790 | ExternalReferenceRedirector* redirector) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 791 | // We can't stack them. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 792 | ASSERT(isolate->external_reference_redirector() == NULL); |
| 793 | isolate->set_external_reference_redirector( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 794 | reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 795 | } |
| 796 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 797 | private: |
| 798 | explicit ExternalReference(void* address) |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 799 | : address_(address) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 800 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 801 | static void* Redirect(Isolate* isolate, |
| 802 | void* address, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 803 | Type type = ExternalReference::BUILTIN_CALL) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 804 | ExternalReferenceRedirector* redirector = |
| 805 | reinterpret_cast<ExternalReferenceRedirector*>( |
| 806 | isolate->external_reference_redirector()); |
| 807 | if (redirector == NULL) return address; |
| 808 | void* answer = (*redirector)(address, type); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 809 | return answer; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 810 | } |
| 811 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 812 | static void* Redirect(Isolate* isolate, |
| 813 | Address address_arg, |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 814 | Type type = ExternalReference::BUILTIN_CALL) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 815 | ExternalReferenceRedirector* redirector = |
| 816 | reinterpret_cast<ExternalReferenceRedirector*>( |
| 817 | isolate->external_reference_redirector()); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 818 | void* address = reinterpret_cast<void*>(address_arg); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 819 | void* answer = (redirector == NULL) ? |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 820 | address : |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 821 | (*redirector)(address, type); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 822 | return answer; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | void* address_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 826 | }; |
| 827 | |
| 828 | |
| 829 | // ----------------------------------------------------------------------------- |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 830 | // Position recording support |
| 831 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 832 | struct PositionState { |
| 833 | PositionState() : current_position(RelocInfo::kNoPosition), |
| 834 | written_position(RelocInfo::kNoPosition), |
| 835 | current_statement_position(RelocInfo::kNoPosition), |
| 836 | written_statement_position(RelocInfo::kNoPosition) {} |
| 837 | |
| 838 | int current_position; |
| 839 | int written_position; |
| 840 | |
| 841 | int current_statement_position; |
| 842 | int written_statement_position; |
| 843 | }; |
| 844 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 845 | |
| 846 | class PositionsRecorder BASE_EMBEDDED { |
| 847 | public: |
| 848 | explicit PositionsRecorder(Assembler* assembler) |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 849 | : assembler_(assembler) { |
| 850 | #ifdef ENABLE_GDB_JIT_INTERFACE |
| 851 | gdbjit_lineinfo_ = NULL; |
| 852 | #endif |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 853 | jit_handler_data_ = NULL; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | #ifdef ENABLE_GDB_JIT_INTERFACE |
| 857 | ~PositionsRecorder() { |
| 858 | delete gdbjit_lineinfo_; |
| 859 | } |
| 860 | |
| 861 | void StartGDBJITLineInfoRecording() { |
| 862 | if (FLAG_gdbjit) { |
| 863 | gdbjit_lineinfo_ = new GDBJITLineInfo(); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | GDBJITLineInfo* DetachGDBJITLineInfo() { |
| 868 | GDBJITLineInfo* lineinfo = gdbjit_lineinfo_; |
| 869 | gdbjit_lineinfo_ = NULL; // To prevent deallocation in destructor. |
| 870 | return lineinfo; |
| 871 | } |
| 872 | #endif |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 873 | void AttachJITHandlerData(void* user_data) { |
| 874 | jit_handler_data_ = user_data; |
| 875 | } |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 876 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 877 | void* DetachJITHandlerData() { |
| 878 | void* old_data = jit_handler_data_; |
| 879 | jit_handler_data_ = NULL; |
| 880 | return old_data; |
| 881 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 882 | // Set current position to pos. |
| 883 | void RecordPosition(int pos); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 884 | |
| 885 | // Set current statement position to pos. |
| 886 | void RecordStatementPosition(int pos); |
| 887 | |
| 888 | // Write recorded positions to relocation information. |
| 889 | bool WriteRecordedPositions(); |
| 890 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 891 | int current_position() const { return state_.current_position; } |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 892 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 893 | int current_statement_position() const { |
| 894 | return state_.current_statement_position; |
| 895 | } |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 896 | |
| 897 | private: |
| 898 | Assembler* assembler_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 899 | PositionState state_; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 900 | #ifdef ENABLE_GDB_JIT_INTERFACE |
| 901 | GDBJITLineInfo* gdbjit_lineinfo_; |
| 902 | #endif |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 903 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 904 | // Currently jit_handler_data_ is used to store JITHandler-specific data |
| 905 | // over the lifetime of a PositionsRecorder |
| 906 | void* jit_handler_data_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 907 | friend class PreservePositionScope; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 908 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 909 | DISALLOW_COPY_AND_ASSIGN(PositionsRecorder); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 910 | }; |
| 911 | |
| 912 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 913 | class PreservePositionScope BASE_EMBEDDED { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 914 | public: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 915 | explicit PreservePositionScope(PositionsRecorder* positions_recorder) |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 916 | : positions_recorder_(positions_recorder), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 917 | saved_state_(positions_recorder->state_) {} |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 918 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 919 | ~PreservePositionScope() { |
| 920 | positions_recorder_->state_ = saved_state_; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | private: |
| 924 | PositionsRecorder* positions_recorder_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 925 | const PositionState saved_state_; |
| 926 | |
| 927 | DISALLOW_COPY_AND_ASSIGN(PreservePositionScope); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 928 | }; |
| 929 | |
| 930 | |
| 931 | // ----------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 932 | // Utility functions |
| 933 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 934 | inline bool is_intn(int x, int n) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 935 | return -(1 << (n-1)) <= x && x < (1 << (n-1)); |
| 936 | } |
| 937 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 938 | inline bool is_int8(int x) { return is_intn(x, 8); } |
| 939 | inline bool is_int16(int x) { return is_intn(x, 16); } |
| 940 | inline bool is_int18(int x) { return is_intn(x, 18); } |
| 941 | inline bool is_int24(int x) { return is_intn(x, 24); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 942 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 943 | inline bool is_uintn(int x, int n) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 944 | return (x & -(1 << n)) == 0; |
| 945 | } |
| 946 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 947 | inline bool is_uint2(int x) { return is_uintn(x, 2); } |
| 948 | inline bool is_uint3(int x) { return is_uintn(x, 3); } |
| 949 | inline bool is_uint4(int x) { return is_uintn(x, 4); } |
| 950 | inline bool is_uint5(int x) { return is_uintn(x, 5); } |
| 951 | inline bool is_uint6(int x) { return is_uintn(x, 6); } |
| 952 | inline bool is_uint8(int x) { return is_uintn(x, 8); } |
| 953 | inline bool is_uint10(int x) { return is_uintn(x, 10); } |
| 954 | inline bool is_uint12(int x) { return is_uintn(x, 12); } |
| 955 | inline bool is_uint16(int x) { return is_uintn(x, 16); } |
| 956 | inline bool is_uint24(int x) { return is_uintn(x, 24); } |
| 957 | inline bool is_uint26(int x) { return is_uintn(x, 26); } |
| 958 | inline bool is_uint28(int x) { return is_uintn(x, 28); } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 959 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 960 | inline int NumberOfBitsSet(uint32_t x) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 961 | unsigned int num_bits_set; |
| 962 | for (num_bits_set = 0; x; x >>= 1) { |
| 963 | num_bits_set += x & 1; |
| 964 | } |
| 965 | return num_bits_set; |
| 966 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 967 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 968 | bool EvalComparison(Token::Value op, double op1, double op2); |
| 969 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 970 | // Computes pow(x, y) with the special cases in the spec for Math.pow. |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame^] | 971 | double power_helper(double x, double y); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 972 | double power_double_int(double x, int y); |
| 973 | double power_double_double(double x, double y); |
| 974 | |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 975 | // Helper class for generating code or data associated with the code |
| 976 | // right after a call instruction. As an example this can be used to |
| 977 | // generate safepoint data after calls for crankshaft. |
| 978 | class CallWrapper { |
| 979 | public: |
| 980 | CallWrapper() { } |
| 981 | virtual ~CallWrapper() { } |
| 982 | // Called just before emitting a call. Argument is the size of the generated |
| 983 | // call code. |
| 984 | virtual void BeforeCall(int call_size) const = 0; |
| 985 | // Called just after emitting a call, i.e., at the return site for the call. |
| 986 | virtual void AfterCall() const = 0; |
| 987 | }; |
| 988 | |
| 989 | class NullCallWrapper : public CallWrapper { |
| 990 | public: |
| 991 | NullCallWrapper() { } |
| 992 | virtual ~NullCallWrapper() { } |
| 993 | virtual void BeforeCall(int call_size) const { } |
| 994 | virtual void AfterCall() const { } |
| 995 | }; |
| 996 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 997 | } } // namespace v8::internal |
| 998 | |
| 999 | #endif // V8_ASSEMBLER_H_ |