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