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