Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 | // All Rights Reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // - Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // |
| 11 | // - Redistribution in binary form must reproduce the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer in the |
| 13 | // documentation and/or other materials provided with the distribution. |
| 14 | // |
| 15 | // - Neither the name of Sun Microsystems or the names of contributors may |
| 16 | // be used to endorse or promote products derived from this software without |
| 17 | // specific prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 20 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 21 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 23 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | // The original source code covered by the above license above has been |
| 32 | // modified significantly by Google Inc. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 33 | // Copyright 2012 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | |
| 35 | #ifndef V8_ASSEMBLER_H_ |
| 36 | #define V8_ASSEMBLER_H_ |
| 37 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 38 | #include "src/v8.h" |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 39 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 40 | #include "src/allocation.h" |
| 41 | #include "src/builtins.h" |
| 42 | #include "src/gdb-jit.h" |
| 43 | #include "src/isolate.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 44 | #include "src/runtime/runtime.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | #include "src/token.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 46 | |
| 47 | namespace v8 { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 48 | |
| 49 | class ApiFunction; |
| 50 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 51 | namespace internal { |
| 52 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 53 | class StatsCounter; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 54 | // ----------------------------------------------------------------------------- |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 55 | // Platform independent assembler base class. |
| 56 | |
| 57 | class AssemblerBase: public Malloced { |
| 58 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 59 | AssemblerBase(Isolate* isolate, void* buffer, int buffer_size); |
| 60 | virtual ~AssemblerBase(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 61 | |
| 62 | Isolate* isolate() const { return isolate_; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +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 serializer_enabled() const { return serializer_enabled_; } |
| 69 | void enable_serializer() { serializer_enabled_ = true; } |
| 70 | |
| 71 | bool predictable_code_size() const { return predictable_code_size_; } |
| 72 | void set_predictable_code_size(bool value) { predictable_code_size_ = value; } |
| 73 | |
| 74 | uint64_t enabled_cpu_features() const { return enabled_cpu_features_; } |
| 75 | void set_enabled_cpu_features(uint64_t features) { |
| 76 | enabled_cpu_features_ = features; |
| 77 | } |
| 78 | bool IsEnabled(CpuFeature f) { |
| 79 | return (enabled_cpu_features_ & (static_cast<uint64_t>(1) << f)) != 0; |
| 80 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 81 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 82 | bool is_ool_constant_pool_available() const { |
| 83 | if (FLAG_enable_ool_constant_pool) { |
| 84 | return ool_constant_pool_available_; |
| 85 | } else { |
| 86 | // Out-of-line constant pool not supported on this architecture. |
| 87 | UNREACHABLE(); |
| 88 | return false; |
| 89 | } |
| 90 | } |
| 91 | |
Ben Murdoch | db1b438 | 2012-04-26 19:03:50 +0100 | [diff] [blame] | 92 | // Overwrite a host NaN with a quiet target NaN. Used by mksnapshot for |
| 93 | // cross-snapshotting. |
| 94 | static void QuietNaN(HeapObject* nan) { } |
| 95 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 96 | int pc_offset() const { return static_cast<int>(pc_ - buffer_); } |
| 97 | |
| 98 | // This function is called when code generation is aborted, so that |
| 99 | // the assembler could clean up internal data structures. |
| 100 | virtual void AbortedCodeGeneration() { } |
| 101 | |
| 102 | static const int kMinimalBufferSize = 4*KB; |
| 103 | |
| 104 | protected: |
| 105 | // The buffer into which code and relocation info are generated. It could |
| 106 | // either be owned by the assembler or be provided externally. |
| 107 | byte* buffer_; |
| 108 | int buffer_size_; |
| 109 | bool own_buffer_; |
| 110 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 111 | void set_ool_constant_pool_available(bool available) { |
| 112 | if (FLAG_enable_ool_constant_pool) { |
| 113 | ool_constant_pool_available_ = available; |
| 114 | } else { |
| 115 | // Out-of-line constant pool not supported on this architecture. |
| 116 | UNREACHABLE(); |
| 117 | } |
| 118 | } |
| 119 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 120 | // The program counter, which points into the buffer above and moves forward. |
| 121 | byte* pc_; |
| 122 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 123 | private: |
| 124 | Isolate* isolate_; |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 125 | int jit_cookie_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 126 | uint64_t enabled_cpu_features_; |
| 127 | bool emit_debug_code_; |
| 128 | bool predictable_code_size_; |
| 129 | bool serializer_enabled_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 130 | |
| 131 | // Indicates whether the constant pool can be accessed, which is only possible |
| 132 | // if the pp register points to the current code object's constant pool. |
| 133 | bool ool_constant_pool_available_; |
| 134 | |
| 135 | // Constant pool. |
| 136 | friend class FrameAndConstantPoolScope; |
| 137 | friend class ConstantPoolUnavailableScope; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | |
| 141 | // Avoids emitting debug code during the lifetime of this scope object. |
| 142 | class DontEmitDebugCodeScope BASE_EMBEDDED { |
| 143 | public: |
| 144 | explicit DontEmitDebugCodeScope(AssemblerBase* assembler) |
| 145 | : assembler_(assembler), old_value_(assembler->emit_debug_code()) { |
| 146 | assembler_->set_emit_debug_code(false); |
| 147 | } |
| 148 | ~DontEmitDebugCodeScope() { |
| 149 | assembler_->set_emit_debug_code(old_value_); |
| 150 | } |
| 151 | private: |
| 152 | AssemblerBase* assembler_; |
| 153 | bool old_value_; |
| 154 | }; |
| 155 | |
| 156 | |
| 157 | // Avoids using instructions that vary in size in unpredictable ways between the |
| 158 | // snapshot and the running VM. |
| 159 | class PredictableCodeSizeScope { |
| 160 | public: |
| 161 | PredictableCodeSizeScope(AssemblerBase* assembler, int expected_size); |
| 162 | ~PredictableCodeSizeScope(); |
| 163 | |
| 164 | private: |
| 165 | AssemblerBase* assembler_; |
| 166 | int expected_size_; |
| 167 | int start_offset_; |
| 168 | bool old_value_; |
| 169 | }; |
| 170 | |
| 171 | |
| 172 | // Enable a specified feature within a scope. |
| 173 | class CpuFeatureScope BASE_EMBEDDED { |
| 174 | public: |
| 175 | #ifdef DEBUG |
| 176 | CpuFeatureScope(AssemblerBase* assembler, CpuFeature f); |
| 177 | ~CpuFeatureScope(); |
| 178 | |
| 179 | private: |
| 180 | AssemblerBase* assembler_; |
| 181 | uint64_t old_enabled_; |
| 182 | #else |
| 183 | CpuFeatureScope(AssemblerBase* assembler, CpuFeature f) {} |
| 184 | #endif |
| 185 | }; |
| 186 | |
| 187 | |
| 188 | // CpuFeatures keeps track of which features are supported by the target CPU. |
| 189 | // Supported features must be enabled by a CpuFeatureScope before use. |
| 190 | // Example: |
| 191 | // if (assembler->IsSupported(SSE3)) { |
| 192 | // CpuFeatureScope fscope(assembler, SSE3); |
| 193 | // // Generate code containing SSE3 instructions. |
| 194 | // } else { |
| 195 | // // Generate alternative code. |
| 196 | // } |
| 197 | class CpuFeatures : public AllStatic { |
| 198 | public: |
| 199 | static void Probe(bool cross_compile) { |
| 200 | STATIC_ASSERT(NUMBER_OF_CPU_FEATURES <= kBitsPerInt); |
| 201 | if (initialized_) return; |
| 202 | initialized_ = true; |
| 203 | ProbeImpl(cross_compile); |
| 204 | } |
| 205 | |
| 206 | static unsigned SupportedFeatures() { |
| 207 | Probe(false); |
| 208 | return supported_; |
| 209 | } |
| 210 | |
| 211 | static bool IsSupported(CpuFeature f) { |
| 212 | return (supported_ & (1u << f)) != 0; |
| 213 | } |
| 214 | |
| 215 | static inline bool SupportsCrankshaft(); |
| 216 | |
| 217 | static inline unsigned cache_line_size() { |
| 218 | DCHECK(cache_line_size_ != 0); |
| 219 | return cache_line_size_; |
| 220 | } |
| 221 | |
| 222 | static void PrintTarget(); |
| 223 | static void PrintFeatures(); |
| 224 | |
| 225 | // Flush instruction cache. |
| 226 | static void FlushICache(void* start, size_t size); |
| 227 | |
| 228 | private: |
| 229 | // Platform-dependent implementation. |
| 230 | static void ProbeImpl(bool cross_compile); |
| 231 | |
| 232 | static unsigned supported_; |
| 233 | static unsigned cache_line_size_; |
| 234 | static bool initialized_; |
| 235 | friend class ExternalReference; |
| 236 | DISALLOW_COPY_AND_ASSIGN(CpuFeatures); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 237 | }; |
| 238 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 239 | |
| 240 | // ----------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 241 | // Labels represent pc locations; they are typically jump or call targets. |
| 242 | // After declaration, a label can be freely used to denote known or (yet) |
| 243 | // unknown pc location. Assembler::bind() is used to bind a label to the |
| 244 | // current pc. A label can be bound only once. |
| 245 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 246 | class Label { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 247 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 248 | enum Distance { |
| 249 | kNear, kFar |
| 250 | }; |
| 251 | |
| 252 | INLINE(Label()) { |
| 253 | Unuse(); |
| 254 | UnuseNear(); |
| 255 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 256 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 257 | INLINE(~Label()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 258 | DCHECK(!is_linked()); |
| 259 | DCHECK(!is_near_linked()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 260 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 261 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 262 | INLINE(void Unuse()) { pos_ = 0; } |
| 263 | INLINE(void UnuseNear()) { near_link_pos_ = 0; } |
| 264 | |
| 265 | INLINE(bool is_bound() const) { return pos_ < 0; } |
| 266 | INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; } |
| 267 | INLINE(bool is_linked() const) { return pos_ > 0; } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 268 | INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 269 | |
| 270 | // Returns the position of bound or linked labels. Cannot be used |
| 271 | // for unused labels. |
| 272 | int pos() const; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 273 | int near_link_pos() const { return near_link_pos_ - 1; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 274 | |
| 275 | private: |
| 276 | // pos_ encodes both the binding state (via its sign) |
| 277 | // and the binding position (via its value) of a label. |
| 278 | // |
| 279 | // pos_ < 0 bound label, pos() returns the jump target position |
| 280 | // pos_ == 0 unused label |
| 281 | // pos_ > 0 linked label, pos() returns the last reference position |
| 282 | int pos_; |
| 283 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 284 | // Behaves like |pos_| in the "> 0" case, but for near jumps to this label. |
| 285 | int near_link_pos_; |
| 286 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 287 | void bind_to(int pos) { |
| 288 | pos_ = -pos - 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 289 | DCHECK(is_bound()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 290 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 291 | void link_to(int pos, Distance distance = kFar) { |
| 292 | if (distance == kNear) { |
| 293 | near_link_pos_ = pos + 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 294 | DCHECK(is_near_linked()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 295 | } else { |
| 296 | pos_ = pos + 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 297 | DCHECK(is_linked()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 298 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | friend class Assembler; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 302 | friend class Displacement; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 303 | friend class RegExpMacroAssemblerIrregexp; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 304 | |
| 305 | #if V8_TARGET_ARCH_ARM64 |
| 306 | // On ARM64, the Assembler keeps track of pointers to Labels to resolve |
| 307 | // branches to distant targets. Copying labels would confuse the Assembler. |
| 308 | DISALLOW_COPY_AND_ASSIGN(Label); // NOLINT |
| 309 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 310 | }; |
| 311 | |
| 312 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 313 | enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs }; |
| 314 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 315 | // Specifies whether to perform icache flush operations on RelocInfo updates. |
| 316 | // If FLUSH_ICACHE_IF_NEEDED, the icache will always be flushed if an |
| 317 | // instruction was modified. If SKIP_ICACHE_FLUSH the flush will always be |
| 318 | // skipped (only use this if you will flush the icache manually before it is |
| 319 | // executed). |
| 320 | enum ICacheFlushMode { FLUSH_ICACHE_IF_NEEDED, SKIP_ICACHE_FLUSH }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 321 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 322 | // ----------------------------------------------------------------------------- |
| 323 | // Relocation information |
| 324 | |
| 325 | |
| 326 | // Relocation information consists of the address (pc) of the datum |
| 327 | // to which the relocation information applies, the relocation mode |
| 328 | // (rmode), and an optional data field. The relocation mode may be |
| 329 | // "descriptive" and not indicate a need for relocation, but simply |
| 330 | // describe a property of the datum. Such rmodes are useful for GC |
| 331 | // and nice disassembly output. |
| 332 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 333 | class RelocInfo { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 334 | public: |
| 335 | // The constant kNoPosition is used with the collecting of source positions |
| 336 | // in the relocation information. Two types of source positions are collected |
| 337 | // "position" (RelocMode position) and "statement position" (RelocMode |
| 338 | // statement_position). The "position" is collected at places in the source |
| 339 | // code which are of interest when making stack traces to pin-point the source |
| 340 | // location of a stack frame as close as possible. The "statement position" is |
| 341 | // collected at the beginning at each statement, and is used to indicate |
| 342 | // possible break locations. kNoPosition is used to indicate an |
| 343 | // invalid/uninitialized position value. |
| 344 | static const int kNoPosition = -1; |
| 345 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 346 | // This string is used to add padding comments to the reloc info in cases |
| 347 | // where we are not sure to have enough space for patching in during |
| 348 | // lazy deoptimization. This is the case if we have indirect calls for which |
| 349 | // we do not normally record relocation info. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 350 | static const char* const kFillerCommentString; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 351 | |
| 352 | // The minimum size of a comment is equal to three bytes for the extra tagged |
| 353 | // pc + the tag for the data, and kPointerSize for the actual pointer to the |
| 354 | // comment. |
| 355 | static const int kMinRelocCommentSize = 3 + kPointerSize; |
| 356 | |
| 357 | // The maximum size for a call instruction including pc-jump. |
| 358 | static const int kMaxCallSize = 6; |
| 359 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 360 | // The maximum pc delta that will use the short encoding. |
| 361 | static const int kMaxSmallPCDelta; |
| 362 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 363 | enum Mode { |
| 364 | // Please note the order is important (see IsCodeTarget, IsGCRelocMode). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 365 | CODE_TARGET, // Code target which is not any of the above. |
| 366 | CODE_TARGET_WITH_ID, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 367 | CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 368 | DEBUG_BREAK, // Code target for the debugger statement. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 369 | EMBEDDED_OBJECT, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 370 | CELL, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 371 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 372 | // Everything after runtime_entry (inclusive) is not GC'ed. |
| 373 | RUNTIME_ENTRY, |
| 374 | JS_RETURN, // Marks start of the ExitJSFrame code. |
| 375 | COMMENT, |
| 376 | POSITION, // See comment for kNoPosition above. |
| 377 | STATEMENT_POSITION, // See comment for kNoPosition above. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 378 | DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 379 | EXTERNAL_REFERENCE, // The address of an external C++ function. |
| 380 | INTERNAL_REFERENCE, // An address inside the same function. |
| 381 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 382 | // Marks constant and veneer pools. Only used on ARM and ARM64. |
| 383 | // They use a custom noncompact encoding. |
| 384 | CONST_POOL, |
| 385 | VENEER_POOL, |
| 386 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 387 | // add more as needed |
| 388 | // Pseudo-types |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 389 | NUMBER_OF_MODES, // There are at most 15 modes with noncompact encoding. |
| 390 | NONE32, // never recorded 32-bit value |
| 391 | NONE64, // never recorded 64-bit value |
| 392 | CODE_AGE_SEQUENCE, // Not stored in RelocInfo array, used explictly by |
| 393 | // code aging. |
| 394 | FIRST_REAL_RELOC_MODE = CODE_TARGET, |
| 395 | LAST_REAL_RELOC_MODE = VENEER_POOL, |
| 396 | FIRST_PSEUDO_RELOC_MODE = CODE_AGE_SEQUENCE, |
| 397 | LAST_PSEUDO_RELOC_MODE = CODE_AGE_SEQUENCE, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 398 | LAST_CODE_ENUM = DEBUG_BREAK, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 399 | LAST_GCED_ENUM = CELL, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 400 | // Modes <= LAST_COMPACT_ENUM are guaranteed to have compact encoding. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 401 | LAST_COMPACT_ENUM = CODE_TARGET_WITH_ID, |
| 402 | LAST_STANDARD_NONCOMPACT_ENUM = INTERNAL_REFERENCE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 403 | }; |
| 404 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 405 | RelocInfo() {} |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 406 | |
| 407 | RelocInfo(byte* pc, Mode rmode, intptr_t data, Code* host) |
| 408 | : pc_(pc), rmode_(rmode), data_(data), host_(host) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 409 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 410 | RelocInfo(byte* pc, double data64) |
| 411 | : pc_(pc), rmode_(NONE64), data64_(data64), host_(NULL) { |
| 412 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 413 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 414 | static inline bool IsRealRelocMode(Mode mode) { |
| 415 | return mode >= FIRST_REAL_RELOC_MODE && |
| 416 | mode <= LAST_REAL_RELOC_MODE; |
| 417 | } |
| 418 | static inline bool IsPseudoRelocMode(Mode mode) { |
| 419 | DCHECK(!IsRealRelocMode(mode)); |
| 420 | return mode >= FIRST_PSEUDO_RELOC_MODE && |
| 421 | mode <= LAST_PSEUDO_RELOC_MODE; |
| 422 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 423 | static inline bool IsConstructCall(Mode mode) { |
| 424 | return mode == CONSTRUCT_CALL; |
| 425 | } |
| 426 | static inline bool IsCodeTarget(Mode mode) { |
| 427 | return mode <= LAST_CODE_ENUM; |
| 428 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 429 | static inline bool IsEmbeddedObject(Mode mode) { |
| 430 | return mode == EMBEDDED_OBJECT; |
| 431 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 432 | static inline bool IsRuntimeEntry(Mode mode) { |
| 433 | return mode == RUNTIME_ENTRY; |
| 434 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 435 | // Is the relocation mode affected by GC? |
| 436 | static inline bool IsGCRelocMode(Mode mode) { |
| 437 | return mode <= LAST_GCED_ENUM; |
| 438 | } |
| 439 | static inline bool IsJSReturn(Mode mode) { |
| 440 | return mode == JS_RETURN; |
| 441 | } |
| 442 | static inline bool IsComment(Mode mode) { |
| 443 | return mode == COMMENT; |
| 444 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 445 | static inline bool IsConstPool(Mode mode) { |
| 446 | return mode == CONST_POOL; |
| 447 | } |
| 448 | static inline bool IsVeneerPool(Mode mode) { |
| 449 | return mode == VENEER_POOL; |
| 450 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 451 | static inline bool IsPosition(Mode mode) { |
| 452 | return mode == POSITION || mode == STATEMENT_POSITION; |
| 453 | } |
| 454 | static inline bool IsStatementPosition(Mode mode) { |
| 455 | return mode == STATEMENT_POSITION; |
| 456 | } |
| 457 | static inline bool IsExternalReference(Mode mode) { |
| 458 | return mode == EXTERNAL_REFERENCE; |
| 459 | } |
| 460 | static inline bool IsInternalReference(Mode mode) { |
| 461 | return mode == INTERNAL_REFERENCE; |
| 462 | } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 463 | static inline bool IsDebugBreakSlot(Mode mode) { |
| 464 | return mode == DEBUG_BREAK_SLOT; |
| 465 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 466 | static inline bool IsNone(Mode mode) { |
| 467 | return mode == NONE32 || mode == NONE64; |
| 468 | } |
| 469 | static inline bool IsCodeAgeSequence(Mode mode) { |
| 470 | return mode == CODE_AGE_SEQUENCE; |
| 471 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 472 | static inline int ModeMask(Mode mode) { return 1 << mode; } |
| 473 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 474 | // Returns true if the first RelocInfo has the same mode and raw data as the |
| 475 | // second one. |
| 476 | static inline bool IsEqual(RelocInfo first, RelocInfo second) { |
| 477 | return first.rmode() == second.rmode() && |
| 478 | (first.rmode() == RelocInfo::NONE64 ? |
| 479 | first.raw_data64() == second.raw_data64() : |
| 480 | first.data() == second.data()); |
| 481 | } |
| 482 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 483 | // Accessors |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 484 | byte* pc() const { return pc_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 485 | void set_pc(byte* pc) { pc_ = pc; } |
| 486 | Mode rmode() const { return rmode_; } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 487 | intptr_t data() const { return data_; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 488 | double data64() const { return data64_; } |
| 489 | uint64_t raw_data64() { return bit_cast<uint64_t>(data64_); } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 490 | Code* host() const { return host_; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 491 | void set_host(Code* host) { host_ = host; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 492 | |
| 493 | // Apply a relocation by delta bytes |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 494 | INLINE(void apply(intptr_t delta, |
| 495 | ICacheFlushMode icache_flush_mode = |
| 496 | FLUSH_ICACHE_IF_NEEDED)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 497 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 498 | // Is the pointer this relocation info refers to coded like a plain pointer |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 499 | // or is it strange in some way (e.g. relative or patched into a series of |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 500 | // instructions). |
| 501 | bool IsCodedSpecially(); |
| 502 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 503 | // If true, the pointer this relocation info refers to is an entry in the |
| 504 | // constant pool, otherwise the pointer is embedded in the instruction stream. |
| 505 | bool IsInConstantPool(); |
| 506 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 507 | // Read/modify the code target in the branch/call instruction |
| 508 | // this relocation applies to; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 509 | // can only be called if IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 510 | INLINE(Address target_address()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 511 | INLINE(void set_target_address(Address target, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 512 | WriteBarrierMode write_barrier_mode = |
| 513 | UPDATE_WRITE_BARRIER, |
| 514 | ICacheFlushMode icache_flush_mode = |
| 515 | FLUSH_ICACHE_IF_NEEDED)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 516 | INLINE(Object* target_object()); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 517 | INLINE(Handle<Object> target_object_handle(Assembler* origin)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 518 | INLINE(void set_target_object(Object* target, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 519 | WriteBarrierMode write_barrier_mode = |
| 520 | UPDATE_WRITE_BARRIER, |
| 521 | ICacheFlushMode icache_flush_mode = |
| 522 | FLUSH_ICACHE_IF_NEEDED)); |
| 523 | INLINE(Address target_runtime_entry(Assembler* origin)); |
| 524 | INLINE(void set_target_runtime_entry(Address target, |
| 525 | WriteBarrierMode write_barrier_mode = |
| 526 | UPDATE_WRITE_BARRIER, |
| 527 | ICacheFlushMode icache_flush_mode = |
| 528 | FLUSH_ICACHE_IF_NEEDED)); |
| 529 | INLINE(Cell* target_cell()); |
| 530 | INLINE(Handle<Cell> target_cell_handle()); |
| 531 | INLINE(void set_target_cell(Cell* cell, |
| 532 | WriteBarrierMode write_barrier_mode = |
| 533 | UPDATE_WRITE_BARRIER, |
| 534 | ICacheFlushMode icache_flush_mode = |
| 535 | FLUSH_ICACHE_IF_NEEDED)); |
| 536 | INLINE(Handle<Object> code_age_stub_handle(Assembler* origin)); |
| 537 | INLINE(Code* code_age_stub()); |
| 538 | INLINE(void set_code_age_stub(Code* stub, |
| 539 | ICacheFlushMode icache_flush_mode = |
| 540 | FLUSH_ICACHE_IF_NEEDED)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 541 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 542 | // Returns the address of the constant pool entry where the target address |
| 543 | // is held. This should only be called if IsInConstantPool returns true. |
| 544 | INLINE(Address constant_pool_entry_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 545 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 546 | // Read the address of the word containing the target_address in an |
| 547 | // instruction stream. What this means exactly is architecture-independent. |
| 548 | // The only architecture-independent user of this function is the serializer. |
| 549 | // The serializer uses it to find out how many raw bytes of instruction to |
| 550 | // output before the next target. Architecture-independent code shouldn't |
| 551 | // dereference the pointer it gets back from this. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 552 | INLINE(Address target_address_address()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 553 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 554 | // This indicates how much space a target takes up when deserializing a code |
| 555 | // stream. For most architectures this is just the size of a pointer. For |
| 556 | // an instruction like movw/movt where the target bits are mixed into the |
| 557 | // instruction bits the size of the target will be zero, indicating that the |
| 558 | // serializer should not step forwards in memory after a target is resolved |
| 559 | // and written. In this case the target_address_address function above |
| 560 | // should return the end of the instructions to be patched, allowing the |
| 561 | // deserializer to deserialize the instructions as raw bytes and put them in |
| 562 | // place, ready to be patched with the target. |
| 563 | INLINE(int target_address_size()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 564 | |
| 565 | // Read/modify the reference in the instruction this relocation |
| 566 | // applies to; can only be called if rmode_ is external_reference |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 567 | INLINE(Address target_reference()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 568 | |
| 569 | // Read/modify the address of a call instruction. This is used to relocate |
| 570 | // the break points where straight-line code is patched with a call |
| 571 | // instruction. |
| 572 | INLINE(Address call_address()); |
| 573 | INLINE(void set_call_address(Address target)); |
| 574 | INLINE(Object* call_object()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 575 | INLINE(void set_call_object(Object* target)); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 576 | INLINE(Object** call_object_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 577 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 578 | // Wipe out a relocation to a fixed value, used for making snapshots |
| 579 | // reproducible. |
| 580 | INLINE(void WipeOut()); |
| 581 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 582 | template<typename StaticVisitor> inline void Visit(Heap* heap); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 583 | inline void Visit(Isolate* isolate, ObjectVisitor* v); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 584 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 585 | // Patch the code with some other code. |
| 586 | void PatchCode(byte* instructions, int instruction_count); |
| 587 | |
| 588 | // Patch the code with a call. |
| 589 | void PatchCodeWithCall(Address target, int guard_bytes); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 590 | |
| 591 | // Check whether this return sequence has been patched |
| 592 | // with a call to the debugger. |
| 593 | INLINE(bool IsPatchedReturnSequence()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 594 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 595 | // Check whether this debug break slot has been patched with a call to the |
| 596 | // debugger. |
| 597 | INLINE(bool IsPatchedDebugBreakSlotSequence()); |
| 598 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 599 | #ifdef DEBUG |
| 600 | // Check whether the given code contains relocation information that |
| 601 | // either is position-relative or movable by the garbage collector. |
| 602 | static bool RequiresRelocation(const CodeDesc& desc); |
| 603 | #endif |
| 604 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 605 | #ifdef ENABLE_DISASSEMBLER |
| 606 | // Printing |
| 607 | static const char* RelocModeName(Mode rmode); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 608 | void Print(Isolate* isolate, std::ostream& os); // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 609 | #endif // ENABLE_DISASSEMBLER |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 610 | #ifdef VERIFY_HEAP |
| 611 | void Verify(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 612 | #endif |
| 613 | |
| 614 | static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1; |
| 615 | static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 616 | static const int kDataMask = |
| 617 | (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 618 | static const int kApplyMask; // Modes affected by apply. Depends on arch. |
| 619 | |
| 620 | private: |
| 621 | // On ARM, note that pc_ is the address of the constant pool entry |
| 622 | // to be relocated and not the address of the instruction |
| 623 | // referencing the constant pool entry (except when rmode_ == |
| 624 | // comment). |
| 625 | byte* pc_; |
| 626 | Mode rmode_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 627 | union { |
| 628 | intptr_t data_; |
| 629 | double data64_; |
| 630 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 631 | Code* host_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 632 | // External-reference pointers are also split across instruction-pairs |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 633 | // on some platforms, but are accessed via indirect pointers. This location |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 634 | // provides a place for that pointer to exist naturally. Its address |
| 635 | // is returned by RelocInfo::target_reference_address(). |
| 636 | Address reconstructed_adr_ptr_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 637 | friend class RelocIterator; |
| 638 | }; |
| 639 | |
| 640 | |
| 641 | // RelocInfoWriter serializes a stream of relocation info. It writes towards |
| 642 | // lower addresses. |
| 643 | class RelocInfoWriter BASE_EMBEDDED { |
| 644 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 645 | RelocInfoWriter() : pos_(NULL), |
| 646 | last_pc_(NULL), |
| 647 | last_id_(0), |
| 648 | last_position_(0) {} |
| 649 | RelocInfoWriter(byte* pos, byte* pc) : pos_(pos), |
| 650 | last_pc_(pc), |
| 651 | last_id_(0), |
| 652 | last_position_(0) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 653 | |
| 654 | byte* pos() const { return pos_; } |
| 655 | byte* last_pc() const { return last_pc_; } |
| 656 | |
| 657 | void Write(const RelocInfo* rinfo); |
| 658 | |
| 659 | // Update the state of the stream after reloc info buffer |
| 660 | // and/or code is moved while the stream is active. |
| 661 | void Reposition(byte* pos, byte* pc) { |
| 662 | pos_ = pos; |
| 663 | last_pc_ = pc; |
| 664 | } |
| 665 | |
| 666 | // Max size (bytes) of a written RelocInfo. Longest encoding is |
| 667 | // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta. |
| 668 | // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12. |
| 669 | // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16; |
| 670 | // Here we use the maximum of the two. |
| 671 | static const int kMaxSize = 16; |
| 672 | |
| 673 | private: |
| 674 | inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta); |
| 675 | inline void WriteTaggedPC(uint32_t pc_delta, int tag); |
| 676 | inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 677 | inline void WriteExtraTaggedIntData(int data_delta, int top_tag); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 678 | inline void WriteExtraTaggedPoolData(int data, int pool_type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 679 | inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag); |
| 680 | inline void WriteTaggedData(intptr_t data_delta, int tag); |
| 681 | inline void WriteExtraTag(int extra_tag, int top_tag); |
| 682 | |
| 683 | byte* pos_; |
| 684 | byte* last_pc_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 685 | int last_id_; |
| 686 | int last_position_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 687 | DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter); |
| 688 | }; |
| 689 | |
| 690 | |
| 691 | // A RelocIterator iterates over relocation information. |
| 692 | // Typical use: |
| 693 | // |
| 694 | // for (RelocIterator it(code); !it.done(); it.next()) { |
| 695 | // // do something with it.rinfo() here |
| 696 | // } |
| 697 | // |
| 698 | // A mask can be specified to skip unwanted modes. |
| 699 | class RelocIterator: public Malloced { |
| 700 | public: |
| 701 | // Create a new iterator positioned at |
| 702 | // the beginning of the reloc info. |
| 703 | // Relocation information with mode k is included in the |
| 704 | // iteration iff bit k of mode_mask is set. |
| 705 | explicit RelocIterator(Code* code, int mode_mask = -1); |
| 706 | explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1); |
| 707 | |
| 708 | // Iteration |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 709 | bool done() const { return done_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 710 | void next(); |
| 711 | |
| 712 | // Return pointer valid until next next(). |
| 713 | RelocInfo* rinfo() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 714 | DCHECK(!done()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 715 | return &rinfo_; |
| 716 | } |
| 717 | |
| 718 | private: |
| 719 | // Advance* moves the position before/after reading. |
| 720 | // *Read* reads from current byte(s) into rinfo_. |
| 721 | // *Get* just reads and returns info on current byte. |
| 722 | void Advance(int bytes = 1) { pos_ -= bytes; } |
| 723 | int AdvanceGetTag(); |
| 724 | int GetExtraTag(); |
| 725 | int GetTopTag(); |
| 726 | void ReadTaggedPC(); |
| 727 | void AdvanceReadPC(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 728 | void AdvanceReadId(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 729 | void AdvanceReadPoolData(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 730 | void AdvanceReadPosition(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 731 | void AdvanceReadData(); |
| 732 | void AdvanceReadVariableLengthPCJump(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 733 | int GetLocatableTypeTag(); |
| 734 | void ReadTaggedId(); |
| 735 | void ReadTaggedPosition(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 736 | |
| 737 | // If the given mode is wanted, set it in rinfo_ and return true. |
| 738 | // Else return false. Used for efficiently skipping unwanted modes. |
| 739 | bool SetMode(RelocInfo::Mode mode) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 740 | return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | byte* pos_; |
| 744 | byte* end_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 745 | byte* code_age_sequence_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 746 | RelocInfo rinfo_; |
| 747 | bool done_; |
| 748 | int mode_mask_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 749 | int last_id_; |
| 750 | int last_position_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 751 | DISALLOW_COPY_AND_ASSIGN(RelocIterator); |
| 752 | }; |
| 753 | |
| 754 | |
| 755 | //------------------------------------------------------------------------------ |
| 756 | // External function |
| 757 | |
| 758 | //---------------------------------------------------------------------------- |
| 759 | class IC_Utility; |
| 760 | class SCTableReference; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 761 | class Debug_Address; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 762 | |
| 763 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 764 | // An ExternalReference represents a C++ address used in the generated |
| 765 | // code. All references to C++ functions and variables must be encapsulated in |
| 766 | // an ExternalReference instance. This is done in order to track the origin of |
| 767 | // all external references in the code so that they can be bound to the correct |
| 768 | // addresses when deserializing a heap. |
| 769 | class ExternalReference BASE_EMBEDDED { |
| 770 | public: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 771 | // Used in the simulator to support different native api calls. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 772 | enum Type { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 773 | // Builtin call. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 774 | // Object* f(v8::internal::Arguments). |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 775 | BUILTIN_CALL, // default |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 776 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 777 | // Builtin that takes float arguments and returns an int. |
| 778 | // int f(double, double). |
| 779 | BUILTIN_COMPARE_CALL, |
| 780 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 781 | // Builtin call that returns floating point. |
| 782 | // double f(double, double). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 783 | BUILTIN_FP_FP_CALL, |
| 784 | |
| 785 | // Builtin call that returns floating point. |
| 786 | // double f(double). |
| 787 | BUILTIN_FP_CALL, |
| 788 | |
| 789 | // Builtin call that returns floating point. |
| 790 | // double f(double, int). |
| 791 | BUILTIN_FP_INT_CALL, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 792 | |
| 793 | // Direct call to API function callback. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 794 | // void f(v8::FunctionCallbackInfo&) |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 795 | DIRECT_API_CALL, |
| 796 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 797 | // Call to function callback via InvokeFunctionCallback. |
| 798 | // void f(v8::FunctionCallbackInfo&, v8::FunctionCallback) |
| 799 | PROFILING_API_CALL, |
| 800 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 801 | // Direct call to accessor getter callback. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 802 | // void f(Local<Name> property, PropertyCallbackInfo& info) |
| 803 | DIRECT_GETTER_CALL, |
| 804 | |
| 805 | // Call to accessor getter callback via InvokeAccessorGetterCallback. |
| 806 | // void f(Local<Name> property, PropertyCallbackInfo& info, |
| 807 | // AccessorNameGetterCallback callback) |
| 808 | PROFILING_GETTER_CALL |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 809 | }; |
| 810 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 811 | static void SetUp(); |
| 812 | static void InitializeMathExpData(); |
| 813 | static void TearDownMathExpData(); |
| 814 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 815 | typedef void* ExternalReferenceRedirector(void* original, Type type); |
| 816 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 817 | ExternalReference() : address_(NULL) {} |
| 818 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 819 | ExternalReference(Builtins::CFunctionId id, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 820 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 821 | ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 822 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 823 | ExternalReference(Builtins::Name name, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 824 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 825 | ExternalReference(Runtime::FunctionId id, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 826 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 827 | ExternalReference(const Runtime::Function* f, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 828 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 829 | ExternalReference(const IC_Utility& ic_utility, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 830 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 831 | explicit ExternalReference(StatsCounter* counter); |
| 832 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 833 | ExternalReference(Isolate::AddressId id, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 834 | |
| 835 | explicit ExternalReference(const SCTableReference& table_ref); |
| 836 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 837 | // Isolate as an external reference. |
| 838 | static ExternalReference isolate_address(Isolate* isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 839 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 840 | // One-of-a-kind references. These references are not part of a general |
| 841 | // pattern. This means that they have to be added to the |
| 842 | // ExternalReferenceTable in serialize.cc manually. |
| 843 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 844 | static ExternalReference incremental_marking_record_write_function( |
| 845 | Isolate* isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 846 | static ExternalReference store_buffer_overflow_function( |
| 847 | Isolate* isolate); |
| 848 | static ExternalReference flush_icache_function(Isolate* isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 849 | static ExternalReference delete_handle_scope_extensions(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 850 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 851 | static ExternalReference get_date_field_function(Isolate* isolate); |
| 852 | static ExternalReference date_cache_stamp(Isolate* isolate); |
| 853 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 854 | static ExternalReference get_make_code_young_function(Isolate* isolate); |
| 855 | static ExternalReference get_mark_code_as_executed_function(Isolate* isolate); |
| 856 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 857 | // Deoptimization support. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 858 | static ExternalReference new_deoptimizer_function(Isolate* isolate); |
| 859 | static ExternalReference compute_output_frames_function(Isolate* isolate); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 860 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 861 | // Log support. |
| 862 | static ExternalReference log_enter_external_function(Isolate* isolate); |
| 863 | static ExternalReference log_leave_external_function(Isolate* isolate); |
| 864 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 865 | // Static data in the keyed lookup cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 866 | static ExternalReference keyed_lookup_cache_keys(Isolate* isolate); |
| 867 | static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 868 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 869 | // Static variable Heap::roots_array_start() |
| 870 | static ExternalReference roots_array_start(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 871 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 872 | // Static variable Heap::allocation_sites_list_address() |
| 873 | static ExternalReference allocation_sites_list_address(Isolate* isolate); |
| 874 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 875 | // Static variable StackGuard::address_of_jslimit() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 876 | static ExternalReference address_of_stack_limit(Isolate* isolate); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 877 | |
| 878 | // Static variable StackGuard::address_of_real_jslimit() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 879 | static ExternalReference address_of_real_stack_limit(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 880 | |
| 881 | // Static variable RegExpStack::limit_address() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 882 | static ExternalReference address_of_regexp_stack_limit(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 883 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 884 | // Static variables for RegExp. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 885 | static ExternalReference address_of_static_offsets_vector(Isolate* isolate); |
| 886 | static ExternalReference address_of_regexp_stack_memory_address( |
| 887 | Isolate* isolate); |
| 888 | static ExternalReference address_of_regexp_stack_memory_size( |
| 889 | Isolate* isolate); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 890 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 891 | // Static variable Heap::NewSpaceStart() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 892 | static ExternalReference new_space_start(Isolate* isolate); |
| 893 | static ExternalReference new_space_mask(Isolate* isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 894 | |
| 895 | // Write barrier. |
| 896 | static ExternalReference store_buffer_top(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 897 | |
| 898 | // Used for fast allocation in generated code. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 899 | static ExternalReference new_space_allocation_top_address(Isolate* isolate); |
| 900 | static ExternalReference new_space_allocation_limit_address(Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 901 | static ExternalReference old_pointer_space_allocation_top_address( |
| 902 | Isolate* isolate); |
| 903 | static ExternalReference old_pointer_space_allocation_limit_address( |
| 904 | Isolate* isolate); |
| 905 | static ExternalReference old_data_space_allocation_top_address( |
| 906 | Isolate* isolate); |
| 907 | static ExternalReference old_data_space_allocation_limit_address( |
| 908 | Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 909 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 910 | static ExternalReference mod_two_doubles_operation(Isolate* isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 911 | static ExternalReference power_double_double_function(Isolate* isolate); |
| 912 | static ExternalReference power_double_int_function(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 913 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 914 | static ExternalReference handle_scope_next_address(Isolate* isolate); |
| 915 | static ExternalReference handle_scope_limit_address(Isolate* isolate); |
| 916 | static ExternalReference handle_scope_level_address(Isolate* isolate); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 917 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 918 | static ExternalReference scheduled_exception_address(Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 919 | static ExternalReference address_of_pending_message_obj(Isolate* isolate); |
| 920 | static ExternalReference address_of_has_pending_message(Isolate* isolate); |
| 921 | static ExternalReference address_of_pending_message_script(Isolate* isolate); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 922 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 923 | // Static variables containing common double constants. |
| 924 | static ExternalReference address_of_min_int(); |
| 925 | static ExternalReference address_of_one_half(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 926 | static ExternalReference address_of_minus_one_half(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 927 | static ExternalReference address_of_negative_infinity(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 928 | static ExternalReference address_of_canonical_non_hole_nan(); |
| 929 | static ExternalReference address_of_the_hole_nan(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 930 | static ExternalReference address_of_uint32_bias(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 931 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 932 | static ExternalReference math_log_double_function(Isolate* isolate); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 933 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 934 | static ExternalReference math_exp_constants(int constant_index); |
| 935 | static ExternalReference math_exp_log_table(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 936 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 937 | static ExternalReference page_flags(Page* page); |
| 938 | |
| 939 | static ExternalReference ForDeoptEntry(Address entry); |
| 940 | |
| 941 | static ExternalReference cpu_features(); |
| 942 | |
| 943 | static ExternalReference debug_is_active_address(Isolate* isolate); |
| 944 | static ExternalReference debug_after_break_target_address(Isolate* isolate); |
| 945 | static ExternalReference debug_restarter_frame_function_pointer_address( |
| 946 | Isolate* isolate); |
| 947 | |
| 948 | static ExternalReference is_profiling_address(Isolate* isolate); |
| 949 | static ExternalReference invoke_function_callback(Isolate* isolate); |
| 950 | static ExternalReference invoke_accessor_getter_callback(Isolate* isolate); |
| 951 | |
| 952 | Address address() const { return reinterpret_cast<Address>(address_); } |
| 953 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 954 | // Function Debug::Break() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 955 | static ExternalReference debug_break(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 956 | |
| 957 | // Used to check if single stepping is enabled in generated code. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 958 | static ExternalReference debug_step_in_fp_address(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 959 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 960 | #ifndef V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 961 | // C functions called from RegExp generated code. |
| 962 | |
| 963 | // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 964 | static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 965 | |
| 966 | // Function RegExpMacroAssembler*::CheckStackGuardState() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 967 | static ExternalReference re_check_stack_guard_state(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 968 | |
| 969 | // Function NativeRegExpMacroAssembler::GrowStack() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 970 | static ExternalReference re_grow_stack(Isolate* isolate); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 971 | |
| 972 | // byte NativeRegExpMacroAssembler::word_character_bitmap |
| 973 | static ExternalReference re_word_character_map(); |
| 974 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 975 | #endif |
| 976 | |
| 977 | // This lets you register a function that rewrites all external references. |
| 978 | // Used by the ARM simulator to catch calls to external references. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 979 | static void set_redirector(Isolate* isolate, |
| 980 | ExternalReferenceRedirector* redirector) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 981 | // We can't stack them. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 982 | DCHECK(isolate->external_reference_redirector() == NULL); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 983 | isolate->set_external_reference_redirector( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 984 | reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 987 | static ExternalReference stress_deopt_count(Isolate* isolate); |
| 988 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 989 | private: |
| 990 | explicit ExternalReference(void* address) |
| 991 | : address_(address) {} |
| 992 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 993 | static void* Redirect(Isolate* isolate, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 994 | Address address_arg, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 995 | Type type = ExternalReference::BUILTIN_CALL) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 996 | ExternalReferenceRedirector* redirector = |
| 997 | reinterpret_cast<ExternalReferenceRedirector*>( |
| 998 | isolate->external_reference_redirector()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 999 | void* address = reinterpret_cast<void*>(address_arg); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1000 | void* answer = (redirector == NULL) ? |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1001 | address : |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1002 | (*redirector)(address, type); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1003 | return answer; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | void* address_; |
| 1007 | }; |
| 1008 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1009 | bool operator==(ExternalReference, ExternalReference); |
| 1010 | bool operator!=(ExternalReference, ExternalReference); |
| 1011 | |
| 1012 | size_t hash_value(ExternalReference); |
| 1013 | |
| 1014 | std::ostream& operator<<(std::ostream&, ExternalReference); |
| 1015 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1016 | |
| 1017 | // ----------------------------------------------------------------------------- |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1018 | // Position recording support |
| 1019 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1020 | struct PositionState { |
| 1021 | PositionState() : current_position(RelocInfo::kNoPosition), |
| 1022 | written_position(RelocInfo::kNoPosition), |
| 1023 | current_statement_position(RelocInfo::kNoPosition), |
| 1024 | written_statement_position(RelocInfo::kNoPosition) {} |
| 1025 | |
| 1026 | int current_position; |
| 1027 | int written_position; |
| 1028 | |
| 1029 | int current_statement_position; |
| 1030 | int written_statement_position; |
| 1031 | }; |
| 1032 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1033 | |
| 1034 | class PositionsRecorder BASE_EMBEDDED { |
| 1035 | public: |
| 1036 | explicit PositionsRecorder(Assembler* assembler) |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1037 | : assembler_(assembler) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1038 | jit_handler_data_ = NULL; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1041 | void AttachJITHandlerData(void* user_data) { |
| 1042 | jit_handler_data_ = user_data; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1043 | } |
| 1044 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1045 | void* DetachJITHandlerData() { |
| 1046 | void* old_data = jit_handler_data_; |
| 1047 | jit_handler_data_ = NULL; |
| 1048 | return old_data; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1049 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1050 | // Set current position to pos. |
| 1051 | void RecordPosition(int pos); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1052 | |
| 1053 | // Set current statement position to pos. |
| 1054 | void RecordStatementPosition(int pos); |
| 1055 | |
| 1056 | // Write recorded positions to relocation information. |
| 1057 | bool WriteRecordedPositions(); |
| 1058 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1059 | int current_position() const { return state_.current_position; } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1060 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1061 | int current_statement_position() const { |
| 1062 | return state_.current_statement_position; |
| 1063 | } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1064 | |
| 1065 | private: |
| 1066 | Assembler* assembler_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1067 | PositionState state_; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1068 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1069 | // Currently jit_handler_data_ is used to store JITHandler-specific data |
| 1070 | // over the lifetime of a PositionsRecorder |
| 1071 | void* jit_handler_data_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1072 | friend class PreservePositionScope; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1073 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1074 | DISALLOW_COPY_AND_ASSIGN(PositionsRecorder); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1075 | }; |
| 1076 | |
| 1077 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1078 | class PreservePositionScope BASE_EMBEDDED { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1079 | public: |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1080 | explicit PreservePositionScope(PositionsRecorder* positions_recorder) |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1081 | : positions_recorder_(positions_recorder), |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1082 | saved_state_(positions_recorder->state_) {} |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1083 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1084 | ~PreservePositionScope() { |
| 1085 | positions_recorder_->state_ = saved_state_; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | private: |
| 1089 | PositionsRecorder* positions_recorder_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1090 | const PositionState saved_state_; |
| 1091 | |
| 1092 | DISALLOW_COPY_AND_ASSIGN(PreservePositionScope); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1093 | }; |
| 1094 | |
| 1095 | |
| 1096 | // ----------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1097 | // Utility functions |
| 1098 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1099 | inline int NumberOfBitsSet(uint32_t x) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1100 | unsigned int num_bits_set; |
| 1101 | for (num_bits_set = 0; x; x >>= 1) { |
| 1102 | num_bits_set += x & 1; |
| 1103 | } |
| 1104 | return num_bits_set; |
| 1105 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1106 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1107 | bool EvalComparison(Token::Value op, double op1, double op2); |
| 1108 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1109 | // Computes pow(x, y) with the special cases in the spec for Math.pow. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1110 | double power_helper(double x, double y); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1111 | double power_double_int(double x, int y); |
| 1112 | double power_double_double(double x, double y); |
| 1113 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1114 | // Helper class for generating code or data associated with the code |
| 1115 | // right after a call instruction. As an example this can be used to |
| 1116 | // generate safepoint data after calls for crankshaft. |
| 1117 | class CallWrapper { |
| 1118 | public: |
| 1119 | CallWrapper() { } |
| 1120 | virtual ~CallWrapper() { } |
| 1121 | // Called just before emitting a call. Argument is the size of the generated |
| 1122 | // call code. |
| 1123 | virtual void BeforeCall(int call_size) const = 0; |
| 1124 | // Called just after emitting a call, i.e., at the return site for the call. |
| 1125 | virtual void AfterCall() const = 0; |
| 1126 | }; |
| 1127 | |
| 1128 | class NullCallWrapper : public CallWrapper { |
| 1129 | public: |
| 1130 | NullCallWrapper() { } |
| 1131 | virtual ~NullCallWrapper() { } |
| 1132 | virtual void BeforeCall(int call_size) const { } |
| 1133 | virtual void AfterCall() const { } |
| 1134 | }; |
| 1135 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1136 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1137 | } } // namespace v8::internal |
| 1138 | |
| 1139 | #endif // V8_ASSEMBLER_H_ |