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/allocation.h" |
| 39 | #include "src/builtins.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 40 | #include "src/isolate.h" |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 41 | #include "src/log.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 42 | #include "src/runtime/runtime.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 43 | |
| 44 | namespace v8 { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 45 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 46 | // Forward declarations. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 47 | class ApiFunction; |
| 48 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 49 | namespace internal { |
| 50 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 51 | // Forward declarations. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 52 | class StatsCounter; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 53 | |
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 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 57 | enum class CodeObjectRequired { kNo, kYes }; |
| 58 | |
| 59 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 60 | class AssemblerBase: public Malloced { |
| 61 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 62 | AssemblerBase(Isolate* isolate, void* buffer, int buffer_size); |
| 63 | virtual ~AssemblerBase(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 64 | |
| 65 | Isolate* isolate() const { return isolate_; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 66 | int jit_cookie() const { return jit_cookie_; } |
| 67 | |
| 68 | bool emit_debug_code() const { return emit_debug_code_; } |
| 69 | void set_emit_debug_code(bool value) { emit_debug_code_ = value; } |
| 70 | |
| 71 | bool serializer_enabled() const { return serializer_enabled_; } |
| 72 | void enable_serializer() { serializer_enabled_ = true; } |
| 73 | |
| 74 | bool predictable_code_size() const { return predictable_code_size_; } |
| 75 | void set_predictable_code_size(bool value) { predictable_code_size_ = value; } |
| 76 | |
| 77 | uint64_t enabled_cpu_features() const { return enabled_cpu_features_; } |
| 78 | void set_enabled_cpu_features(uint64_t features) { |
| 79 | enabled_cpu_features_ = features; |
| 80 | } |
| 81 | bool IsEnabled(CpuFeature f) { |
| 82 | return (enabled_cpu_features_ & (static_cast<uint64_t>(1) << f)) != 0; |
| 83 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 84 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 85 | bool is_constant_pool_available() const { |
| 86 | if (FLAG_enable_embedded_constant_pool) { |
| 87 | return constant_pool_available_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 88 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 89 | // Embedded constant pool not supported on this architecture. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 90 | UNREACHABLE(); |
| 91 | return false; |
| 92 | } |
| 93 | } |
| 94 | |
Ben Murdoch | db1b438 | 2012-04-26 19:03:50 +0100 | [diff] [blame] | 95 | // Overwrite a host NaN with a quiet target NaN. Used by mksnapshot for |
| 96 | // cross-snapshotting. |
| 97 | static void QuietNaN(HeapObject* nan) { } |
| 98 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 99 | int pc_offset() const { return static_cast<int>(pc_ - buffer_); } |
| 100 | |
| 101 | // This function is called when code generation is aborted, so that |
| 102 | // the assembler could clean up internal data structures. |
| 103 | virtual void AbortedCodeGeneration() { } |
| 104 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 105 | // Debugging |
| 106 | void Print(); |
| 107 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 108 | static const int kMinimalBufferSize = 4*KB; |
| 109 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 110 | static void FlushICache(Isolate* isolate, void* start, size_t size); |
| 111 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 112 | protected: |
| 113 | // The buffer into which code and relocation info are generated. It could |
| 114 | // either be owned by the assembler or be provided externally. |
| 115 | byte* buffer_; |
| 116 | int buffer_size_; |
| 117 | bool own_buffer_; |
| 118 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 119 | void set_constant_pool_available(bool available) { |
| 120 | if (FLAG_enable_embedded_constant_pool) { |
| 121 | constant_pool_available_ = available; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 122 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 123 | // Embedded constant pool not supported on this architecture. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 124 | UNREACHABLE(); |
| 125 | } |
| 126 | } |
| 127 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 128 | // The program counter, which points into the buffer above and moves forward. |
| 129 | byte* pc_; |
| 130 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 131 | private: |
| 132 | Isolate* isolate_; |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 133 | int jit_cookie_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 134 | uint64_t enabled_cpu_features_; |
| 135 | bool emit_debug_code_; |
| 136 | bool predictable_code_size_; |
| 137 | bool serializer_enabled_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 138 | |
| 139 | // Indicates whether the constant pool can be accessed, which is only possible |
| 140 | // if the pp register points to the current code object's constant pool. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 141 | bool constant_pool_available_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 142 | |
| 143 | // Constant pool. |
| 144 | friend class FrameAndConstantPoolScope; |
| 145 | friend class ConstantPoolUnavailableScope; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | |
| 149 | // Avoids emitting debug code during the lifetime of this scope object. |
| 150 | class DontEmitDebugCodeScope BASE_EMBEDDED { |
| 151 | public: |
| 152 | explicit DontEmitDebugCodeScope(AssemblerBase* assembler) |
| 153 | : assembler_(assembler), old_value_(assembler->emit_debug_code()) { |
| 154 | assembler_->set_emit_debug_code(false); |
| 155 | } |
| 156 | ~DontEmitDebugCodeScope() { |
| 157 | assembler_->set_emit_debug_code(old_value_); |
| 158 | } |
| 159 | private: |
| 160 | AssemblerBase* assembler_; |
| 161 | bool old_value_; |
| 162 | }; |
| 163 | |
| 164 | |
| 165 | // Avoids using instructions that vary in size in unpredictable ways between the |
| 166 | // snapshot and the running VM. |
| 167 | class PredictableCodeSizeScope { |
| 168 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 169 | explicit PredictableCodeSizeScope(AssemblerBase* assembler); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 170 | PredictableCodeSizeScope(AssemblerBase* assembler, int expected_size); |
| 171 | ~PredictableCodeSizeScope(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 172 | void ExpectSize(int expected_size) { expected_size_ = expected_size; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 173 | |
| 174 | private: |
| 175 | AssemblerBase* assembler_; |
| 176 | int expected_size_; |
| 177 | int start_offset_; |
| 178 | bool old_value_; |
| 179 | }; |
| 180 | |
| 181 | |
| 182 | // Enable a specified feature within a scope. |
| 183 | class CpuFeatureScope BASE_EMBEDDED { |
| 184 | public: |
| 185 | #ifdef DEBUG |
| 186 | CpuFeatureScope(AssemblerBase* assembler, CpuFeature f); |
| 187 | ~CpuFeatureScope(); |
| 188 | |
| 189 | private: |
| 190 | AssemblerBase* assembler_; |
| 191 | uint64_t old_enabled_; |
| 192 | #else |
| 193 | CpuFeatureScope(AssemblerBase* assembler, CpuFeature f) {} |
| 194 | #endif |
| 195 | }; |
| 196 | |
| 197 | |
| 198 | // CpuFeatures keeps track of which features are supported by the target CPU. |
| 199 | // Supported features must be enabled by a CpuFeatureScope before use. |
| 200 | // Example: |
| 201 | // if (assembler->IsSupported(SSE3)) { |
| 202 | // CpuFeatureScope fscope(assembler, SSE3); |
| 203 | // // Generate code containing SSE3 instructions. |
| 204 | // } else { |
| 205 | // // Generate alternative code. |
| 206 | // } |
| 207 | class CpuFeatures : public AllStatic { |
| 208 | public: |
| 209 | static void Probe(bool cross_compile) { |
| 210 | STATIC_ASSERT(NUMBER_OF_CPU_FEATURES <= kBitsPerInt); |
| 211 | if (initialized_) return; |
| 212 | initialized_ = true; |
| 213 | ProbeImpl(cross_compile); |
| 214 | } |
| 215 | |
| 216 | static unsigned SupportedFeatures() { |
| 217 | Probe(false); |
| 218 | return supported_; |
| 219 | } |
| 220 | |
| 221 | static bool IsSupported(CpuFeature f) { |
| 222 | return (supported_ & (1u << f)) != 0; |
| 223 | } |
| 224 | |
| 225 | static inline bool SupportsCrankshaft(); |
| 226 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 227 | static inline unsigned icache_line_size() { |
| 228 | DCHECK(icache_line_size_ != 0); |
| 229 | return icache_line_size_; |
| 230 | } |
| 231 | |
| 232 | static inline unsigned dcache_line_size() { |
| 233 | DCHECK(dcache_line_size_ != 0); |
| 234 | return dcache_line_size_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static void PrintTarget(); |
| 238 | static void PrintFeatures(); |
| 239 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 240 | private: |
| 241 | friend class ExternalReference; |
| 242 | friend class AssemblerBase; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 243 | // Flush instruction cache. |
| 244 | static void FlushICache(void* start, size_t size); |
| 245 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 246 | // Platform-dependent implementation. |
| 247 | static void ProbeImpl(bool cross_compile); |
| 248 | |
| 249 | static unsigned supported_; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 250 | static unsigned icache_line_size_; |
| 251 | static unsigned dcache_line_size_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 252 | static bool initialized_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 253 | DISALLOW_COPY_AND_ASSIGN(CpuFeatures); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 254 | }; |
| 255 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 256 | |
| 257 | // ----------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 258 | // Labels represent pc locations; they are typically jump or call targets. |
| 259 | // After declaration, a label can be freely used to denote known or (yet) |
| 260 | // unknown pc location. Assembler::bind() is used to bind a label to the |
| 261 | // current pc. A label can be bound only once. |
| 262 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 263 | class Label { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 264 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 265 | enum Distance { |
| 266 | kNear, kFar |
| 267 | }; |
| 268 | |
| 269 | INLINE(Label()) { |
| 270 | Unuse(); |
| 271 | UnuseNear(); |
| 272 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 273 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 274 | INLINE(~Label()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 275 | DCHECK(!is_linked()); |
| 276 | DCHECK(!is_near_linked()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 277 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 278 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 279 | INLINE(void Unuse()) { pos_ = 0; } |
| 280 | INLINE(void UnuseNear()) { near_link_pos_ = 0; } |
| 281 | |
| 282 | INLINE(bool is_bound() const) { return pos_ < 0; } |
| 283 | INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; } |
| 284 | INLINE(bool is_linked() const) { return pos_ > 0; } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 285 | INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 286 | |
| 287 | // Returns the position of bound or linked labels. Cannot be used |
| 288 | // for unused labels. |
| 289 | int pos() const; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 290 | int near_link_pos() const { return near_link_pos_ - 1; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 291 | |
| 292 | private: |
| 293 | // pos_ encodes both the binding state (via its sign) |
| 294 | // and the binding position (via its value) of a label. |
| 295 | // |
| 296 | // pos_ < 0 bound label, pos() returns the jump target position |
| 297 | // pos_ == 0 unused label |
| 298 | // pos_ > 0 linked label, pos() returns the last reference position |
| 299 | int pos_; |
| 300 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 301 | // Behaves like |pos_| in the "> 0" case, but for near jumps to this label. |
| 302 | int near_link_pos_; |
| 303 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 304 | void bind_to(int pos) { |
| 305 | pos_ = -pos - 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 306 | DCHECK(is_bound()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 307 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 308 | void link_to(int pos, Distance distance = kFar) { |
| 309 | if (distance == kNear) { |
| 310 | near_link_pos_ = pos + 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 311 | DCHECK(is_near_linked()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 312 | } else { |
| 313 | pos_ = pos + 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 314 | DCHECK(is_linked()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 315 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | friend class Assembler; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 319 | friend class Displacement; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 320 | friend class RegExpMacroAssemblerIrregexp; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 321 | |
| 322 | #if V8_TARGET_ARCH_ARM64 |
| 323 | // On ARM64, the Assembler keeps track of pointers to Labels to resolve |
| 324 | // branches to distant targets. Copying labels would confuse the Assembler. |
| 325 | DISALLOW_COPY_AND_ASSIGN(Label); // NOLINT |
| 326 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 330 | enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs }; |
| 331 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 332 | enum ArgvMode { kArgvOnStack, kArgvInRegister }; |
| 333 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 334 | // Specifies whether to perform icache flush operations on RelocInfo updates. |
| 335 | // If FLUSH_ICACHE_IF_NEEDED, the icache will always be flushed if an |
| 336 | // instruction was modified. If SKIP_ICACHE_FLUSH the flush will always be |
| 337 | // skipped (only use this if you will flush the icache manually before it is |
| 338 | // executed). |
| 339 | enum ICacheFlushMode { FLUSH_ICACHE_IF_NEEDED, SKIP_ICACHE_FLUSH }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 340 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 341 | // ----------------------------------------------------------------------------- |
| 342 | // Relocation information |
| 343 | |
| 344 | |
| 345 | // Relocation information consists of the address (pc) of the datum |
| 346 | // to which the relocation information applies, the relocation mode |
| 347 | // (rmode), and an optional data field. The relocation mode may be |
| 348 | // "descriptive" and not indicate a need for relocation, but simply |
| 349 | // describe a property of the datum. Such rmodes are useful for GC |
| 350 | // and nice disassembly output. |
| 351 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 352 | class RelocInfo { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 353 | public: |
| 354 | // The constant kNoPosition is used with the collecting of source positions |
| 355 | // in the relocation information. Two types of source positions are collected |
| 356 | // "position" (RelocMode position) and "statement position" (RelocMode |
| 357 | // statement_position). The "position" is collected at places in the source |
| 358 | // code which are of interest when making stack traces to pin-point the source |
| 359 | // location of a stack frame as close as possible. The "statement position" is |
| 360 | // collected at the beginning at each statement, and is used to indicate |
| 361 | // possible break locations. kNoPosition is used to indicate an |
| 362 | // invalid/uninitialized position value. |
| 363 | static const int kNoPosition = -1; |
| 364 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 365 | // This string is used to add padding comments to the reloc info in cases |
| 366 | // where we are not sure to have enough space for patching in during |
| 367 | // lazy deoptimization. This is the case if we have indirect calls for which |
| 368 | // we do not normally record relocation info. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 369 | static const char* const kFillerCommentString; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 370 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 371 | // The minimum size of a comment is equal to two bytes for the extra tagged |
| 372 | // pc and kPointerSize for the actual pointer to the comment. |
| 373 | static const int kMinRelocCommentSize = 2 + kPointerSize; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 374 | |
| 375 | // The maximum size for a call instruction including pc-jump. |
| 376 | static const int kMaxCallSize = 6; |
| 377 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 378 | // The maximum pc delta that will use the short encoding. |
| 379 | static const int kMaxSmallPCDelta; |
| 380 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 381 | enum Mode { |
| 382 | // Please note the order is important (see IsCodeTarget, IsGCRelocMode). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 383 | CODE_TARGET, // Code target which is not any of the above. |
| 384 | CODE_TARGET_WITH_ID, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 385 | DEBUGGER_STATEMENT, // Code target for the debugger statement. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 386 | EMBEDDED_OBJECT, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 387 | CELL, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 388 | // To relocate pointers into the wasm memory embedded in wasm code |
| 389 | WASM_MEMORY_REFERENCE, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 390 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 391 | // Everything after runtime_entry (inclusive) is not GC'ed. |
| 392 | RUNTIME_ENTRY, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 393 | COMMENT, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 394 | POSITION, // See comment for kNoPosition above. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 395 | STATEMENT_POSITION, // See comment for kNoPosition above. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 396 | |
| 397 | // Additional code inserted for debug break slot. |
| 398 | DEBUG_BREAK_SLOT_AT_POSITION, |
| 399 | DEBUG_BREAK_SLOT_AT_RETURN, |
| 400 | DEBUG_BREAK_SLOT_AT_CALL, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 401 | DEBUG_BREAK_SLOT_AT_TAIL_CALL, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 402 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 403 | EXTERNAL_REFERENCE, // The address of an external C++ function. |
| 404 | INTERNAL_REFERENCE, // An address inside the same function. |
| 405 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 406 | // Encoded internal reference, used only on MIPS, MIPS64 and PPC. |
| 407 | INTERNAL_REFERENCE_ENCODED, |
| 408 | |
| 409 | // Continuation points for a generator yield. |
| 410 | GENERATOR_CONTINUATION, |
| 411 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 412 | // Marks constant and veneer pools. Only used on ARM and ARM64. |
| 413 | // They use a custom noncompact encoding. |
| 414 | CONST_POOL, |
| 415 | VENEER_POOL, |
| 416 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 417 | DEOPT_REASON, // Deoptimization reason index. |
| 418 | |
| 419 | // This is not an actual reloc mode, but used to encode a long pc jump that |
| 420 | // cannot be encoded as part of another record. |
| 421 | PC_JUMP, |
| 422 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 423 | // Pseudo-types |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 424 | NUMBER_OF_MODES, |
| 425 | NONE32, // never recorded 32-bit value |
| 426 | NONE64, // never recorded 64-bit value |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 427 | CODE_AGE_SEQUENCE, // Not stored in RelocInfo array, used explictly by |
| 428 | // code aging. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 429 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 430 | FIRST_REAL_RELOC_MODE = CODE_TARGET, |
| 431 | LAST_REAL_RELOC_MODE = VENEER_POOL, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 432 | LAST_CODE_ENUM = DEBUGGER_STATEMENT, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 433 | LAST_GCED_ENUM = WASM_MEMORY_REFERENCE, |
| 434 | FIRST_SHAREABLE_RELOC_MODE = CELL, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 435 | }; |
| 436 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 437 | STATIC_ASSERT(NUMBER_OF_MODES <= kBitsPerInt); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 438 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 439 | explicit RelocInfo(Isolate* isolate) : isolate_(isolate) { |
| 440 | DCHECK_NOT_NULL(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 441 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 442 | |
| 443 | RelocInfo(Isolate* isolate, byte* pc, Mode rmode, intptr_t data, Code* host) |
| 444 | : isolate_(isolate), pc_(pc), rmode_(rmode), data_(data), host_(host) { |
| 445 | DCHECK_NOT_NULL(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 446 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 447 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 448 | static inline bool IsRealRelocMode(Mode mode) { |
| 449 | return mode >= FIRST_REAL_RELOC_MODE && |
| 450 | mode <= LAST_REAL_RELOC_MODE; |
| 451 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 452 | static inline bool IsCodeTarget(Mode mode) { |
| 453 | return mode <= LAST_CODE_ENUM; |
| 454 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 455 | static inline bool IsEmbeddedObject(Mode mode) { |
| 456 | return mode == EMBEDDED_OBJECT; |
| 457 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 458 | static inline bool IsCell(Mode mode) { return mode == CELL; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 459 | static inline bool IsRuntimeEntry(Mode mode) { |
| 460 | return mode == RUNTIME_ENTRY; |
| 461 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 462 | // Is the relocation mode affected by GC? |
| 463 | static inline bool IsGCRelocMode(Mode mode) { |
| 464 | return mode <= LAST_GCED_ENUM; |
| 465 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 466 | static inline bool IsComment(Mode mode) { |
| 467 | return mode == COMMENT; |
| 468 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 469 | static inline bool IsConstPool(Mode mode) { |
| 470 | return mode == CONST_POOL; |
| 471 | } |
| 472 | static inline bool IsVeneerPool(Mode mode) { |
| 473 | return mode == VENEER_POOL; |
| 474 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 475 | static inline bool IsDeoptReason(Mode mode) { |
| 476 | return mode == DEOPT_REASON; |
| 477 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 478 | static inline bool IsPosition(Mode mode) { |
| 479 | return mode == POSITION || mode == STATEMENT_POSITION; |
| 480 | } |
| 481 | static inline bool IsStatementPosition(Mode mode) { |
| 482 | return mode == STATEMENT_POSITION; |
| 483 | } |
| 484 | static inline bool IsExternalReference(Mode mode) { |
| 485 | return mode == EXTERNAL_REFERENCE; |
| 486 | } |
| 487 | static inline bool IsInternalReference(Mode mode) { |
| 488 | return mode == INTERNAL_REFERENCE; |
| 489 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 490 | static inline bool IsInternalReferenceEncoded(Mode mode) { |
| 491 | return mode == INTERNAL_REFERENCE_ENCODED; |
| 492 | } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 493 | static inline bool IsDebugBreakSlot(Mode mode) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 494 | return IsDebugBreakSlotAtPosition(mode) || IsDebugBreakSlotAtReturn(mode) || |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 495 | IsDebugBreakSlotAtCall(mode) || IsDebugBreakSlotAtTailCall(mode); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 496 | } |
| 497 | static inline bool IsDebugBreakSlotAtPosition(Mode mode) { |
| 498 | return mode == DEBUG_BREAK_SLOT_AT_POSITION; |
| 499 | } |
| 500 | static inline bool IsDebugBreakSlotAtReturn(Mode mode) { |
| 501 | return mode == DEBUG_BREAK_SLOT_AT_RETURN; |
| 502 | } |
| 503 | static inline bool IsDebugBreakSlotAtCall(Mode mode) { |
| 504 | return mode == DEBUG_BREAK_SLOT_AT_CALL; |
| 505 | } |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 506 | static inline bool IsDebugBreakSlotAtTailCall(Mode mode) { |
| 507 | return mode == DEBUG_BREAK_SLOT_AT_TAIL_CALL; |
| 508 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 509 | static inline bool IsDebuggerStatement(Mode mode) { |
| 510 | return mode == DEBUGGER_STATEMENT; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 511 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 512 | static inline bool IsNone(Mode mode) { |
| 513 | return mode == NONE32 || mode == NONE64; |
| 514 | } |
| 515 | static inline bool IsCodeAgeSequence(Mode mode) { |
| 516 | return mode == CODE_AGE_SEQUENCE; |
| 517 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 518 | static inline bool IsGeneratorContinuation(Mode mode) { |
| 519 | return mode == GENERATOR_CONTINUATION; |
| 520 | } |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 521 | static inline bool IsWasmMemoryReference(Mode mode) { |
| 522 | return mode == WASM_MEMORY_REFERENCE; |
| 523 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 524 | static inline int ModeMask(Mode mode) { return 1 << mode; } |
| 525 | |
| 526 | // Accessors |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 527 | Isolate* isolate() const { return isolate_; } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 528 | byte* pc() const { return pc_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 529 | void set_pc(byte* pc) { pc_ = pc; } |
| 530 | Mode rmode() const { return rmode_; } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 531 | intptr_t data() const { return data_; } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 532 | Code* host() const { return host_; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 533 | void set_host(Code* host) { host_ = host; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 534 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 535 | // Apply a relocation by delta bytes. When the code object is moved, PC |
| 536 | // relative addresses have to be updated as well as absolute addresses |
| 537 | // inside the code (internal references). |
| 538 | // Do not forget to flush the icache afterwards! |
| 539 | INLINE(void apply(intptr_t delta)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 540 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 541 | // 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] | 542 | // 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] | 543 | // instructions). |
| 544 | bool IsCodedSpecially(); |
| 545 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 546 | // If true, the pointer this relocation info refers to is an entry in the |
| 547 | // constant pool, otherwise the pointer is embedded in the instruction stream. |
| 548 | bool IsInConstantPool(); |
| 549 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 550 | // this relocation applies to; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 551 | // can only be called if IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 552 | INLINE(Address target_address()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 553 | INLINE(void set_target_address(Address target, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 554 | WriteBarrierMode write_barrier_mode = |
| 555 | UPDATE_WRITE_BARRIER, |
| 556 | ICacheFlushMode icache_flush_mode = |
| 557 | FLUSH_ICACHE_IF_NEEDED)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 558 | INLINE(Object* target_object()); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 559 | INLINE(Handle<Object> target_object_handle(Assembler* origin)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 560 | INLINE(void set_target_object(Object* target, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 561 | WriteBarrierMode write_barrier_mode = |
| 562 | UPDATE_WRITE_BARRIER, |
| 563 | ICacheFlushMode icache_flush_mode = |
| 564 | FLUSH_ICACHE_IF_NEEDED)); |
| 565 | INLINE(Address target_runtime_entry(Assembler* origin)); |
| 566 | INLINE(void set_target_runtime_entry(Address target, |
| 567 | WriteBarrierMode write_barrier_mode = |
| 568 | UPDATE_WRITE_BARRIER, |
| 569 | ICacheFlushMode icache_flush_mode = |
| 570 | FLUSH_ICACHE_IF_NEEDED)); |
| 571 | INLINE(Cell* target_cell()); |
| 572 | INLINE(Handle<Cell> target_cell_handle()); |
| 573 | INLINE(void set_target_cell(Cell* cell, |
| 574 | WriteBarrierMode write_barrier_mode = |
| 575 | UPDATE_WRITE_BARRIER, |
| 576 | ICacheFlushMode icache_flush_mode = |
| 577 | FLUSH_ICACHE_IF_NEEDED)); |
| 578 | INLINE(Handle<Object> code_age_stub_handle(Assembler* origin)); |
| 579 | INLINE(Code* code_age_stub()); |
| 580 | INLINE(void set_code_age_stub(Code* stub, |
| 581 | ICacheFlushMode icache_flush_mode = |
| 582 | FLUSH_ICACHE_IF_NEEDED)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 583 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 584 | INLINE(Address wasm_memory_reference()); |
| 585 | INLINE(void update_wasm_memory_reference( |
| 586 | Address old_base, Address new_base, size_t old_size, size_t new_size, |
| 587 | ICacheFlushMode icache_flush_mode = SKIP_ICACHE_FLUSH)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 588 | // Returns the address of the constant pool entry where the target address |
| 589 | // is held. This should only be called if IsInConstantPool returns true. |
| 590 | INLINE(Address constant_pool_entry_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 591 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 592 | // Read the address of the word containing the target_address in an |
| 593 | // instruction stream. What this means exactly is architecture-independent. |
| 594 | // The only architecture-independent user of this function is the serializer. |
| 595 | // The serializer uses it to find out how many raw bytes of instruction to |
| 596 | // output before the next target. Architecture-independent code shouldn't |
| 597 | // dereference the pointer it gets back from this. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 598 | INLINE(Address target_address_address()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 599 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 600 | // This indicates how much space a target takes up when deserializing a code |
| 601 | // stream. For most architectures this is just the size of a pointer. For |
| 602 | // an instruction like movw/movt where the target bits are mixed into the |
| 603 | // instruction bits the size of the target will be zero, indicating that the |
| 604 | // serializer should not step forwards in memory after a target is resolved |
| 605 | // and written. In this case the target_address_address function above |
| 606 | // should return the end of the instructions to be patched, allowing the |
| 607 | // deserializer to deserialize the instructions as raw bytes and put them in |
| 608 | // place, ready to be patched with the target. |
| 609 | INLINE(int target_address_size()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 610 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 611 | // Read the reference in the instruction this relocation |
| 612 | // applies to; can only be called if rmode_ is EXTERNAL_REFERENCE. |
| 613 | INLINE(Address target_external_reference()); |
| 614 | |
| 615 | // Read the reference in the instruction this relocation |
| 616 | // applies to; can only be called if rmode_ is INTERNAL_REFERENCE. |
| 617 | INLINE(Address target_internal_reference()); |
| 618 | |
| 619 | // Return the reference address this relocation applies to; |
| 620 | // can only be called if rmode_ is INTERNAL_REFERENCE. |
| 621 | INLINE(Address target_internal_reference_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 622 | |
| 623 | // Read/modify the address of a call instruction. This is used to relocate |
| 624 | // the break points where straight-line code is patched with a call |
| 625 | // instruction. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 626 | INLINE(Address debug_call_address()); |
| 627 | INLINE(void set_debug_call_address(Address target)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 628 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 629 | // Wipe out a relocation to a fixed value, used for making snapshots |
| 630 | // reproducible. |
| 631 | INLINE(void WipeOut()); |
| 632 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 633 | template<typename StaticVisitor> inline void Visit(Heap* heap); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 634 | inline void Visit(Isolate* isolate, ObjectVisitor* v); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 635 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 636 | // Check whether this debug break slot has been patched with a call to the |
| 637 | // debugger. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 638 | bool IsPatchedDebugBreakSlotSequence(); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 639 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 640 | #ifdef DEBUG |
| 641 | // Check whether the given code contains relocation information that |
| 642 | // either is position-relative or movable by the garbage collector. |
| 643 | static bool RequiresRelocation(const CodeDesc& desc); |
| 644 | #endif |
| 645 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 646 | #ifdef ENABLE_DISASSEMBLER |
| 647 | // Printing |
| 648 | static const char* RelocModeName(Mode rmode); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 649 | void Print(Isolate* isolate, std::ostream& os); // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 650 | #endif // ENABLE_DISASSEMBLER |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 651 | #ifdef VERIFY_HEAP |
| 652 | void Verify(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 653 | #endif |
| 654 | |
| 655 | static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1; |
| 656 | static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 657 | static const int kDataMask = |
| 658 | (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 659 | static const int kDebugBreakSlotMask = 1 << DEBUG_BREAK_SLOT_AT_POSITION | |
| 660 | 1 << DEBUG_BREAK_SLOT_AT_RETURN | |
| 661 | 1 << DEBUG_BREAK_SLOT_AT_CALL; |
| 662 | static const int kApplyMask; // Modes affected by apply. Depends on arch. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 663 | |
| 664 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 665 | Isolate* isolate_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 666 | // On ARM, note that pc_ is the address of the constant pool entry |
| 667 | // to be relocated and not the address of the instruction |
| 668 | // referencing the constant pool entry (except when rmode_ == |
| 669 | // comment). |
| 670 | byte* pc_; |
| 671 | Mode rmode_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 672 | intptr_t data_; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 673 | Code* host_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 674 | friend class RelocIterator; |
| 675 | }; |
| 676 | |
| 677 | |
| 678 | // RelocInfoWriter serializes a stream of relocation info. It writes towards |
| 679 | // lower addresses. |
| 680 | class RelocInfoWriter BASE_EMBEDDED { |
| 681 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 682 | RelocInfoWriter() |
| 683 | : pos_(NULL), |
| 684 | last_pc_(NULL), |
| 685 | last_id_(0), |
| 686 | last_position_(0), |
| 687 | last_mode_(RelocInfo::NUMBER_OF_MODES), |
| 688 | next_position_candidate_pos_delta_(0), |
| 689 | next_position_candidate_pc_delta_(0), |
| 690 | next_position_candidate_flushed_(true) {} |
| 691 | RelocInfoWriter(byte* pos, byte* pc) |
| 692 | : pos_(pos), |
| 693 | last_pc_(pc), |
| 694 | last_id_(0), |
| 695 | last_position_(0), |
| 696 | last_mode_(RelocInfo::NUMBER_OF_MODES), |
| 697 | next_position_candidate_pos_delta_(0), |
| 698 | next_position_candidate_pc_delta_(0), |
| 699 | next_position_candidate_flushed_(true) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 700 | |
| 701 | byte* pos() const { return pos_; } |
| 702 | byte* last_pc() const { return last_pc_; } |
| 703 | |
| 704 | void Write(const RelocInfo* rinfo); |
| 705 | |
| 706 | // Update the state of the stream after reloc info buffer |
| 707 | // and/or code is moved while the stream is active. |
| 708 | void Reposition(byte* pos, byte* pc) { |
| 709 | pos_ = pos; |
| 710 | last_pc_ = pc; |
| 711 | } |
| 712 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 713 | void Finish() { FlushPosition(); } |
| 714 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 715 | // Max size (bytes) of a written RelocInfo. Longest encoding is |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 716 | // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, data_delta. |
| 717 | // On ia32 and arm this is 1 + 4 + 1 + 1 + 4 = 11. |
| 718 | // On x64 this is 1 + 4 + 1 + 1 + 8 == 15; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 719 | // Here we use the maximum of the two. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 720 | static const int kMaxSize = 15; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 721 | |
| 722 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 723 | inline uint32_t WriteLongPCJump(uint32_t pc_delta); |
| 724 | |
| 725 | inline void WriteShortTaggedPC(uint32_t pc_delta, int tag); |
| 726 | inline void WriteShortTaggedData(intptr_t data_delta, int tag); |
| 727 | |
| 728 | inline void WriteMode(RelocInfo::Mode rmode); |
| 729 | inline void WriteModeAndPC(uint32_t pc_delta, RelocInfo::Mode rmode); |
| 730 | inline void WriteIntData(int data_delta); |
| 731 | inline void WriteData(intptr_t data_delta); |
| 732 | inline void WritePosition(int pc_delta, int pos_delta, RelocInfo::Mode rmode); |
| 733 | |
| 734 | void FlushPosition(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 735 | |
| 736 | byte* pos_; |
| 737 | byte* last_pc_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 738 | int last_id_; |
| 739 | int last_position_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 740 | RelocInfo::Mode last_mode_; |
| 741 | int next_position_candidate_pos_delta_; |
| 742 | uint32_t next_position_candidate_pc_delta_; |
| 743 | bool next_position_candidate_flushed_; |
| 744 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 745 | DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter); |
| 746 | }; |
| 747 | |
| 748 | |
| 749 | // A RelocIterator iterates over relocation information. |
| 750 | // Typical use: |
| 751 | // |
| 752 | // for (RelocIterator it(code); !it.done(); it.next()) { |
| 753 | // // do something with it.rinfo() here |
| 754 | // } |
| 755 | // |
| 756 | // A mask can be specified to skip unwanted modes. |
| 757 | class RelocIterator: public Malloced { |
| 758 | public: |
| 759 | // Create a new iterator positioned at |
| 760 | // the beginning of the reloc info. |
| 761 | // Relocation information with mode k is included in the |
| 762 | // iteration iff bit k of mode_mask is set. |
| 763 | explicit RelocIterator(Code* code, int mode_mask = -1); |
| 764 | explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1); |
| 765 | |
| 766 | // Iteration |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 767 | bool done() const { return done_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 768 | void next(); |
| 769 | |
| 770 | // Return pointer valid until next next(). |
| 771 | RelocInfo* rinfo() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 772 | DCHECK(!done()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 773 | return &rinfo_; |
| 774 | } |
| 775 | |
| 776 | private: |
| 777 | // Advance* moves the position before/after reading. |
| 778 | // *Read* reads from current byte(s) into rinfo_. |
| 779 | // *Get* just reads and returns info on current byte. |
| 780 | void Advance(int bytes = 1) { pos_ -= bytes; } |
| 781 | int AdvanceGetTag(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 782 | RelocInfo::Mode GetMode(); |
| 783 | |
| 784 | void AdvanceReadLongPCJump(); |
| 785 | |
| 786 | int GetShortDataTypeTag(); |
| 787 | void ReadShortTaggedPC(); |
| 788 | void ReadShortTaggedId(); |
| 789 | void ReadShortTaggedPosition(); |
| 790 | void ReadShortTaggedData(); |
| 791 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 792 | void AdvanceReadPC(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 793 | void AdvanceReadId(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 794 | void AdvanceReadInt(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 795 | void AdvanceReadPosition(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 796 | void AdvanceReadData(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 797 | |
| 798 | // If the given mode is wanted, set it in rinfo_ and return true. |
| 799 | // Else return false. Used for efficiently skipping unwanted modes. |
| 800 | bool SetMode(RelocInfo::Mode mode) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 801 | return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | byte* pos_; |
| 805 | byte* end_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 806 | byte* code_age_sequence_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 807 | RelocInfo rinfo_; |
| 808 | bool done_; |
| 809 | int mode_mask_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 810 | int last_id_; |
| 811 | int last_position_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 812 | DISALLOW_COPY_AND_ASSIGN(RelocIterator); |
| 813 | }; |
| 814 | |
| 815 | |
| 816 | //------------------------------------------------------------------------------ |
| 817 | // External function |
| 818 | |
| 819 | //---------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 820 | class SCTableReference; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 821 | class Debug_Address; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 822 | |
| 823 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 824 | // An ExternalReference represents a C++ address used in the generated |
| 825 | // code. All references to C++ functions and variables must be encapsulated in |
| 826 | // an ExternalReference instance. This is done in order to track the origin of |
| 827 | // all external references in the code so that they can be bound to the correct |
| 828 | // addresses when deserializing a heap. |
| 829 | class ExternalReference BASE_EMBEDDED { |
| 830 | public: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 831 | // Used in the simulator to support different native api calls. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 832 | enum Type { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 833 | // Builtin call. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 834 | // Object* f(v8::internal::Arguments). |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 835 | BUILTIN_CALL, // default |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 836 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 837 | // Builtin call returning object pair. |
| 838 | // ObjectPair f(v8::internal::Arguments). |
| 839 | BUILTIN_CALL_PAIR, |
| 840 | |
| 841 | // Builtin call that returns . |
| 842 | // ObjectTriple f(v8::internal::Arguments). |
| 843 | BUILTIN_CALL_TRIPLE, |
| 844 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 845 | // Builtin that takes float arguments and returns an int. |
| 846 | // int f(double, double). |
| 847 | BUILTIN_COMPARE_CALL, |
| 848 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 849 | // Builtin call that returns floating point. |
| 850 | // double f(double, double). |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 851 | BUILTIN_FP_FP_CALL, |
| 852 | |
| 853 | // Builtin call that returns floating point. |
| 854 | // double f(double). |
| 855 | BUILTIN_FP_CALL, |
| 856 | |
| 857 | // Builtin call that returns floating point. |
| 858 | // double f(double, int). |
| 859 | BUILTIN_FP_INT_CALL, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 860 | |
| 861 | // Direct call to API function callback. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 862 | // void f(v8::FunctionCallbackInfo&) |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 863 | DIRECT_API_CALL, |
| 864 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 865 | // Call to function callback via InvokeFunctionCallback. |
| 866 | // void f(v8::FunctionCallbackInfo&, v8::FunctionCallback) |
| 867 | PROFILING_API_CALL, |
| 868 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 869 | // Direct call to accessor getter callback. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 870 | // void f(Local<Name> property, PropertyCallbackInfo& info) |
| 871 | DIRECT_GETTER_CALL, |
| 872 | |
| 873 | // Call to accessor getter callback via InvokeAccessorGetterCallback. |
| 874 | // void f(Local<Name> property, PropertyCallbackInfo& info, |
| 875 | // AccessorNameGetterCallback callback) |
| 876 | PROFILING_GETTER_CALL |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 877 | }; |
| 878 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 879 | static void SetUp(); |
| 880 | static void InitializeMathExpData(); |
| 881 | static void TearDownMathExpData(); |
| 882 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 883 | typedef void* ExternalReferenceRedirector(Isolate* isolate, void* original, |
| 884 | Type type); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 885 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 886 | ExternalReference() : address_(NULL) {} |
| 887 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 888 | ExternalReference(Builtins::CFunctionId id, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 889 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 890 | ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 891 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 892 | ExternalReference(Builtins::Name name, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 893 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 894 | ExternalReference(Runtime::FunctionId id, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 895 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 896 | ExternalReference(const Runtime::Function* f, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 897 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 898 | explicit ExternalReference(StatsCounter* counter); |
| 899 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 900 | ExternalReference(Isolate::AddressId id, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 901 | |
| 902 | explicit ExternalReference(const SCTableReference& table_ref); |
| 903 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 904 | // Isolate as an external reference. |
| 905 | static ExternalReference isolate_address(Isolate* isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 906 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 907 | // One-of-a-kind references. These references are not part of a general |
| 908 | // pattern. This means that they have to be added to the |
| 909 | // ExternalReferenceTable in serialize.cc manually. |
| 910 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 911 | static ExternalReference interpreter_dispatch_table_address(Isolate* isolate); |
| 912 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 913 | static ExternalReference incremental_marking_record_write_function( |
| 914 | Isolate* isolate); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 915 | static ExternalReference incremental_marking_record_write_code_entry_function( |
| 916 | Isolate* isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 917 | static ExternalReference store_buffer_overflow_function( |
| 918 | Isolate* isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 919 | static ExternalReference delete_handle_scope_extensions(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 920 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 921 | static ExternalReference get_date_field_function(Isolate* isolate); |
| 922 | static ExternalReference date_cache_stamp(Isolate* isolate); |
| 923 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 924 | static ExternalReference get_make_code_young_function(Isolate* isolate); |
| 925 | static ExternalReference get_mark_code_as_executed_function(Isolate* isolate); |
| 926 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 927 | // Deoptimization support. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 928 | static ExternalReference new_deoptimizer_function(Isolate* isolate); |
| 929 | static ExternalReference compute_output_frames_function(Isolate* isolate); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 930 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 931 | static ExternalReference wasm_f32_trunc(Isolate* isolate); |
| 932 | static ExternalReference wasm_f32_floor(Isolate* isolate); |
| 933 | static ExternalReference wasm_f32_ceil(Isolate* isolate); |
| 934 | static ExternalReference wasm_f32_nearest_int(Isolate* isolate); |
| 935 | static ExternalReference wasm_f64_trunc(Isolate* isolate); |
| 936 | static ExternalReference wasm_f64_floor(Isolate* isolate); |
| 937 | static ExternalReference wasm_f64_ceil(Isolate* isolate); |
| 938 | static ExternalReference wasm_f64_nearest_int(Isolate* isolate); |
| 939 | static ExternalReference wasm_int64_to_float32(Isolate* isolate); |
| 940 | static ExternalReference wasm_uint64_to_float32(Isolate* isolate); |
| 941 | static ExternalReference wasm_int64_to_float64(Isolate* isolate); |
| 942 | static ExternalReference wasm_uint64_to_float64(Isolate* isolate); |
| 943 | static ExternalReference wasm_float32_to_int64(Isolate* isolate); |
| 944 | static ExternalReference wasm_float32_to_uint64(Isolate* isolate); |
| 945 | static ExternalReference wasm_float64_to_int64(Isolate* isolate); |
| 946 | static ExternalReference wasm_float64_to_uint64(Isolate* isolate); |
| 947 | static ExternalReference wasm_int64_div(Isolate* isolate); |
| 948 | static ExternalReference wasm_int64_mod(Isolate* isolate); |
| 949 | static ExternalReference wasm_uint64_div(Isolate* isolate); |
| 950 | static ExternalReference wasm_uint64_mod(Isolate* isolate); |
| 951 | |
| 952 | static ExternalReference f64_acos_wrapper_function(Isolate* isolate); |
| 953 | static ExternalReference f64_asin_wrapper_function(Isolate* isolate); |
| 954 | static ExternalReference f64_atan_wrapper_function(Isolate* isolate); |
| 955 | static ExternalReference f64_cos_wrapper_function(Isolate* isolate); |
| 956 | static ExternalReference f64_sin_wrapper_function(Isolate* isolate); |
| 957 | static ExternalReference f64_tan_wrapper_function(Isolate* isolate); |
| 958 | static ExternalReference f64_exp_wrapper_function(Isolate* isolate); |
| 959 | static ExternalReference f64_log_wrapper_function(Isolate* isolate); |
| 960 | static ExternalReference f64_atan2_wrapper_function(Isolate* isolate); |
| 961 | static ExternalReference f64_pow_wrapper_function(Isolate* isolate); |
| 962 | static ExternalReference f64_mod_wrapper_function(Isolate* isolate); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 963 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 964 | // Log support. |
| 965 | static ExternalReference log_enter_external_function(Isolate* isolate); |
| 966 | static ExternalReference log_leave_external_function(Isolate* isolate); |
| 967 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 968 | // Static data in the keyed lookup cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 969 | static ExternalReference keyed_lookup_cache_keys(Isolate* isolate); |
| 970 | static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 971 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 972 | // Static variable Heap::roots_array_start() |
| 973 | static ExternalReference roots_array_start(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 974 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 975 | // Static variable Heap::allocation_sites_list_address() |
| 976 | static ExternalReference allocation_sites_list_address(Isolate* isolate); |
| 977 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 978 | // Static variable StackGuard::address_of_jslimit() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 979 | static ExternalReference address_of_stack_limit(Isolate* isolate); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 980 | |
| 981 | // Static variable StackGuard::address_of_real_jslimit() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 982 | static ExternalReference address_of_real_stack_limit(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 983 | |
| 984 | // Static variable RegExpStack::limit_address() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 985 | static ExternalReference address_of_regexp_stack_limit(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 986 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 987 | // Static variables for RegExp. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 988 | static ExternalReference address_of_static_offsets_vector(Isolate* isolate); |
| 989 | static ExternalReference address_of_regexp_stack_memory_address( |
| 990 | Isolate* isolate); |
| 991 | static ExternalReference address_of_regexp_stack_memory_size( |
| 992 | Isolate* isolate); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 993 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 994 | // Write barrier. |
| 995 | static ExternalReference store_buffer_top(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 996 | |
| 997 | // Used for fast allocation in generated code. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 998 | static ExternalReference new_space_allocation_top_address(Isolate* isolate); |
| 999 | static ExternalReference new_space_allocation_limit_address(Isolate* isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1000 | static ExternalReference old_space_allocation_top_address(Isolate* isolate); |
| 1001 | static ExternalReference old_space_allocation_limit_address(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1002 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1003 | static ExternalReference mod_two_doubles_operation(Isolate* isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1004 | static ExternalReference power_double_double_function(Isolate* isolate); |
| 1005 | static ExternalReference power_double_int_function(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1006 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1007 | static ExternalReference handle_scope_next_address(Isolate* isolate); |
| 1008 | static ExternalReference handle_scope_limit_address(Isolate* isolate); |
| 1009 | static ExternalReference handle_scope_level_address(Isolate* isolate); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1010 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1011 | static ExternalReference scheduled_exception_address(Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1012 | static ExternalReference address_of_pending_message_obj(Isolate* isolate); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1013 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1014 | // Static variables containing common double constants. |
| 1015 | static ExternalReference address_of_min_int(); |
| 1016 | static ExternalReference address_of_one_half(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1017 | static ExternalReference address_of_minus_one_half(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1018 | static ExternalReference address_of_negative_infinity(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1019 | static ExternalReference address_of_the_hole_nan(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1020 | static ExternalReference address_of_uint32_bias(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1021 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1022 | static ExternalReference math_log_double_function(Isolate* isolate); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1023 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1024 | static ExternalReference math_exp_constants(int constant_index); |
| 1025 | static ExternalReference math_exp_log_table(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1026 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1027 | static ExternalReference page_flags(Page* page); |
| 1028 | |
| 1029 | static ExternalReference ForDeoptEntry(Address entry); |
| 1030 | |
| 1031 | static ExternalReference cpu_features(); |
| 1032 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1033 | static ExternalReference is_tail_call_elimination_enabled_address( |
| 1034 | Isolate* isolate); |
| 1035 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1036 | static ExternalReference debug_is_active_address(Isolate* isolate); |
| 1037 | static ExternalReference debug_after_break_target_address(Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1038 | |
| 1039 | static ExternalReference is_profiling_address(Isolate* isolate); |
| 1040 | static ExternalReference invoke_function_callback(Isolate* isolate); |
| 1041 | static ExternalReference invoke_accessor_getter_callback(Isolate* isolate); |
| 1042 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1043 | static ExternalReference virtual_handler_register(Isolate* isolate); |
| 1044 | static ExternalReference virtual_slot_register(Isolate* isolate); |
| 1045 | |
| 1046 | static ExternalReference runtime_function_table_address(Isolate* isolate); |
| 1047 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1048 | Address address() const { return reinterpret_cast<Address>(address_); } |
| 1049 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1050 | // Used to check if single stepping is enabled in generated code. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1051 | static ExternalReference debug_step_in_enabled_address(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1052 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1053 | #ifndef V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1054 | // C functions called from RegExp generated code. |
| 1055 | |
| 1056 | // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1057 | static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1058 | |
| 1059 | // Function RegExpMacroAssembler*::CheckStackGuardState() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1060 | static ExternalReference re_check_stack_guard_state(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1061 | |
| 1062 | // Function NativeRegExpMacroAssembler::GrowStack() |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1063 | static ExternalReference re_grow_stack(Isolate* isolate); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1064 | |
| 1065 | // byte NativeRegExpMacroAssembler::word_character_bitmap |
| 1066 | static ExternalReference re_word_character_map(); |
| 1067 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1068 | #endif |
| 1069 | |
| 1070 | // This lets you register a function that rewrites all external references. |
| 1071 | // Used by the ARM simulator to catch calls to external references. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1072 | static void set_redirector(Isolate* isolate, |
| 1073 | ExternalReferenceRedirector* redirector) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1074 | // We can't stack them. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1075 | DCHECK(isolate->external_reference_redirector() == NULL); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1076 | isolate->set_external_reference_redirector( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1077 | reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1080 | static ExternalReference stress_deopt_count(Isolate* isolate); |
| 1081 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1082 | static ExternalReference fixed_typed_array_base_data_offset(); |
| 1083 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1084 | private: |
| 1085 | explicit ExternalReference(void* address) |
| 1086 | : address_(address) {} |
| 1087 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1088 | static void* Redirect(Isolate* isolate, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1089 | Address address_arg, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1090 | Type type = ExternalReference::BUILTIN_CALL) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1091 | ExternalReferenceRedirector* redirector = |
| 1092 | reinterpret_cast<ExternalReferenceRedirector*>( |
| 1093 | isolate->external_reference_redirector()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1094 | void* address = reinterpret_cast<void*>(address_arg); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1095 | void* answer = |
| 1096 | (redirector == NULL) ? address : (*redirector)(isolate, address, type); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1097 | return answer; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | void* address_; |
| 1101 | }; |
| 1102 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1103 | bool operator==(ExternalReference, ExternalReference); |
| 1104 | bool operator!=(ExternalReference, ExternalReference); |
| 1105 | |
| 1106 | size_t hash_value(ExternalReference); |
| 1107 | |
| 1108 | std::ostream& operator<<(std::ostream&, ExternalReference); |
| 1109 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1110 | |
| 1111 | // ----------------------------------------------------------------------------- |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1112 | // Position recording support |
| 1113 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1114 | struct PositionState { |
| 1115 | PositionState() : current_position(RelocInfo::kNoPosition), |
| 1116 | written_position(RelocInfo::kNoPosition), |
| 1117 | current_statement_position(RelocInfo::kNoPosition), |
| 1118 | written_statement_position(RelocInfo::kNoPosition) {} |
| 1119 | |
| 1120 | int current_position; |
| 1121 | int written_position; |
| 1122 | |
| 1123 | int current_statement_position; |
| 1124 | int written_statement_position; |
| 1125 | }; |
| 1126 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1127 | class AssemblerPositionsRecorder : public PositionsRecorder { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1128 | public: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1129 | explicit AssemblerPositionsRecorder(Assembler* assembler) |
| 1130 | : assembler_(assembler) {} |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1131 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1132 | // Set current position to pos. |
| 1133 | void RecordPosition(int pos); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1134 | |
| 1135 | // Set current statement position to pos. |
| 1136 | void RecordStatementPosition(int pos); |
| 1137 | |
| 1138 | // Write recorded positions to relocation information. |
| 1139 | bool WriteRecordedPositions(); |
| 1140 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1141 | int current_position() const { return state_.current_position; } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1142 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1143 | int current_statement_position() const { |
| 1144 | return state_.current_statement_position; |
| 1145 | } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1146 | |
| 1147 | private: |
| 1148 | Assembler* assembler_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1149 | PositionState state_; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1150 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1151 | DISALLOW_COPY_AND_ASSIGN(AssemblerPositionsRecorder); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1152 | }; |
| 1153 | |
| 1154 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1155 | // ----------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1156 | // Utility functions |
| 1157 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1158 | inline int NumberOfBitsSet(uint32_t x) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1159 | unsigned int num_bits_set; |
| 1160 | for (num_bits_set = 0; x; x >>= 1) { |
| 1161 | num_bits_set += x & 1; |
| 1162 | } |
| 1163 | return num_bits_set; |
| 1164 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1165 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1166 | // Computes pow(x, y) with the special cases in the spec for Math.pow. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1167 | double power_helper(Isolate* isolate, double x, double y); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1168 | double power_double_int(double x, int y); |
| 1169 | double power_double_double(double x, double y); |
| 1170 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1171 | // Helper class for generating code or data associated with the code |
| 1172 | // right after a call instruction. As an example this can be used to |
| 1173 | // generate safepoint data after calls for crankshaft. |
| 1174 | class CallWrapper { |
| 1175 | public: |
| 1176 | CallWrapper() { } |
| 1177 | virtual ~CallWrapper() { } |
| 1178 | // Called just before emitting a call. Argument is the size of the generated |
| 1179 | // call code. |
| 1180 | virtual void BeforeCall(int call_size) const = 0; |
| 1181 | // Called just after emitting a call, i.e., at the return site for the call. |
| 1182 | virtual void AfterCall() const = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1183 | // Return whether call needs to check for debug stepping. |
| 1184 | virtual bool NeedsDebugStepCheck() const { return false; } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1185 | }; |
| 1186 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1187 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1188 | class NullCallWrapper : public CallWrapper { |
| 1189 | public: |
| 1190 | NullCallWrapper() { } |
| 1191 | virtual ~NullCallWrapper() { } |
| 1192 | virtual void BeforeCall(int call_size) const { } |
| 1193 | virtual void AfterCall() const { } |
| 1194 | }; |
| 1195 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1196 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1197 | class CheckDebugStepCallWrapper : public CallWrapper { |
| 1198 | public: |
| 1199 | CheckDebugStepCallWrapper() {} |
| 1200 | virtual ~CheckDebugStepCallWrapper() {} |
| 1201 | virtual void BeforeCall(int call_size) const {} |
| 1202 | virtual void AfterCall() const {} |
| 1203 | virtual bool NeedsDebugStepCheck() const { return true; } |
| 1204 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1205 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1206 | |
| 1207 | // ----------------------------------------------------------------------------- |
| 1208 | // Constant pool support |
| 1209 | |
| 1210 | class ConstantPoolEntry { |
| 1211 | public: |
| 1212 | ConstantPoolEntry() {} |
| 1213 | ConstantPoolEntry(int position, intptr_t value, bool sharing_ok) |
| 1214 | : position_(position), |
| 1215 | merged_index_(sharing_ok ? SHARING_ALLOWED : SHARING_PROHIBITED), |
| 1216 | value_(value) {} |
| 1217 | ConstantPoolEntry(int position, double value) |
| 1218 | : position_(position), merged_index_(SHARING_ALLOWED), value64_(value) {} |
| 1219 | |
| 1220 | int position() const { return position_; } |
| 1221 | bool sharing_ok() const { return merged_index_ != SHARING_PROHIBITED; } |
| 1222 | bool is_merged() const { return merged_index_ >= 0; } |
| 1223 | int merged_index(void) const { |
| 1224 | DCHECK(is_merged()); |
| 1225 | return merged_index_; |
| 1226 | } |
| 1227 | void set_merged_index(int index) { |
| 1228 | merged_index_ = index; |
| 1229 | DCHECK(is_merged()); |
| 1230 | } |
| 1231 | int offset(void) const { |
| 1232 | DCHECK(merged_index_ >= 0); |
| 1233 | return merged_index_; |
| 1234 | } |
| 1235 | void set_offset(int offset) { |
| 1236 | DCHECK(offset >= 0); |
| 1237 | merged_index_ = offset; |
| 1238 | } |
| 1239 | intptr_t value() const { return value_; } |
| 1240 | uint64_t value64() const { return bit_cast<uint64_t>(value64_); } |
| 1241 | |
| 1242 | enum Type { INTPTR, DOUBLE, NUMBER_OF_TYPES }; |
| 1243 | |
| 1244 | static int size(Type type) { |
| 1245 | return (type == INTPTR) ? kPointerSize : kDoubleSize; |
| 1246 | } |
| 1247 | |
| 1248 | enum Access { REGULAR, OVERFLOWED }; |
| 1249 | |
| 1250 | private: |
| 1251 | int position_; |
| 1252 | int merged_index_; |
| 1253 | union { |
| 1254 | intptr_t value_; |
| 1255 | double value64_; |
| 1256 | }; |
| 1257 | enum { SHARING_PROHIBITED = -2, SHARING_ALLOWED = -1 }; |
| 1258 | }; |
| 1259 | |
| 1260 | |
| 1261 | // ----------------------------------------------------------------------------- |
| 1262 | // Embedded constant pool support |
| 1263 | |
| 1264 | class ConstantPoolBuilder BASE_EMBEDDED { |
| 1265 | public: |
| 1266 | ConstantPoolBuilder(int ptr_reach_bits, int double_reach_bits); |
| 1267 | |
| 1268 | // Add pointer-sized constant to the embedded constant pool |
| 1269 | ConstantPoolEntry::Access AddEntry(int position, intptr_t value, |
| 1270 | bool sharing_ok) { |
| 1271 | ConstantPoolEntry entry(position, value, sharing_ok); |
| 1272 | return AddEntry(entry, ConstantPoolEntry::INTPTR); |
| 1273 | } |
| 1274 | |
| 1275 | // Add double constant to the embedded constant pool |
| 1276 | ConstantPoolEntry::Access AddEntry(int position, double value) { |
| 1277 | ConstantPoolEntry entry(position, value); |
| 1278 | return AddEntry(entry, ConstantPoolEntry::DOUBLE); |
| 1279 | } |
| 1280 | |
| 1281 | // Previews the access type required for the next new entry to be added. |
| 1282 | ConstantPoolEntry::Access NextAccess(ConstantPoolEntry::Type type) const; |
| 1283 | |
| 1284 | bool IsEmpty() { |
| 1285 | return info_[ConstantPoolEntry::INTPTR].entries.empty() && |
| 1286 | info_[ConstantPoolEntry::INTPTR].shared_entries.empty() && |
| 1287 | info_[ConstantPoolEntry::DOUBLE].entries.empty() && |
| 1288 | info_[ConstantPoolEntry::DOUBLE].shared_entries.empty(); |
| 1289 | } |
| 1290 | |
| 1291 | // Emit the constant pool. Invoke only after all entries have been |
| 1292 | // added and all instructions have been emitted. |
| 1293 | // Returns position of the emitted pool (zero implies no constant pool). |
| 1294 | int Emit(Assembler* assm); |
| 1295 | |
| 1296 | // Returns the label associated with the start of the constant pool. |
| 1297 | // Linking to this label in the function prologue may provide an |
| 1298 | // efficient means of constant pool pointer register initialization |
| 1299 | // on some architectures. |
| 1300 | inline Label* EmittedPosition() { return &emitted_label_; } |
| 1301 | |
| 1302 | private: |
| 1303 | ConstantPoolEntry::Access AddEntry(ConstantPoolEntry& entry, |
| 1304 | ConstantPoolEntry::Type type); |
| 1305 | void EmitSharedEntries(Assembler* assm, ConstantPoolEntry::Type type); |
| 1306 | void EmitGroup(Assembler* assm, ConstantPoolEntry::Access access, |
| 1307 | ConstantPoolEntry::Type type); |
| 1308 | |
| 1309 | struct PerTypeEntryInfo { |
| 1310 | PerTypeEntryInfo() : regular_count(0), overflow_start(-1) {} |
| 1311 | bool overflow() const { |
| 1312 | return (overflow_start >= 0 && |
| 1313 | overflow_start < static_cast<int>(entries.size())); |
| 1314 | } |
| 1315 | int regular_reach_bits; |
| 1316 | int regular_count; |
| 1317 | int overflow_start; |
| 1318 | std::vector<ConstantPoolEntry> entries; |
| 1319 | std::vector<ConstantPoolEntry> shared_entries; |
| 1320 | }; |
| 1321 | |
| 1322 | Label emitted_label_; // Records pc_offset of emitted pool |
| 1323 | PerTypeEntryInfo info_[ConstantPoolEntry::NUMBER_OF_TYPES]; |
| 1324 | }; |
| 1325 | |
| 1326 | } // namespace internal |
| 1327 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1328 | #endif // V8_ASSEMBLER_H_ |