Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 35 | #include "src/assembler.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 36 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 37 | #include <math.h> |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 38 | #include <cmath> |
| 39 | #include "src/api.h" |
| 40 | #include "src/base/cpu.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 41 | #include "src/base/functional.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 42 | #include "src/base/lazy-instance.h" |
| 43 | #include "src/base/platform/platform.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 44 | #include "src/base/utils/random-number-generator.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | #include "src/builtins.h" |
| 46 | #include "src/codegen.h" |
| 47 | #include "src/counters.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 48 | #include "src/debug/debug.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 49 | #include "src/deoptimizer.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 50 | #include "src/disassembler.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 51 | #include "src/execution.h" |
| 52 | #include "src/ic/ic.h" |
| 53 | #include "src/ic/stub-cache.h" |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 54 | #include "src/interpreter/interpreter.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 55 | #include "src/ostreams.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 56 | #include "src/profiler/cpu-profiler.h" |
| 57 | #include "src/regexp/jsregexp.h" |
| 58 | #include "src/regexp/regexp-macro-assembler.h" |
| 59 | #include "src/regexp/regexp-stack.h" |
| 60 | #include "src/register-configuration.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 61 | #include "src/runtime/runtime.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 62 | #include "src/simulator.h" // For flushing instruction cache. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 63 | #include "src/snapshot/serializer-common.h" |
| 64 | #include "src/wasm/wasm-external-refs.h" |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 65 | |
| 66 | #if V8_TARGET_ARCH_IA32 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 67 | #include "src/ia32/assembler-ia32-inl.h" // NOLINT |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 68 | #elif V8_TARGET_ARCH_X64 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 69 | #include "src/x64/assembler-x64-inl.h" // NOLINT |
| 70 | #elif V8_TARGET_ARCH_ARM64 |
| 71 | #include "src/arm64/assembler-arm64-inl.h" // NOLINT |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 72 | #elif V8_TARGET_ARCH_ARM |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 73 | #include "src/arm/assembler-arm-inl.h" // NOLINT |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 74 | #elif V8_TARGET_ARCH_PPC |
| 75 | #include "src/ppc/assembler-ppc-inl.h" // NOLINT |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 76 | #elif V8_TARGET_ARCH_MIPS |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 77 | #include "src/mips/assembler-mips-inl.h" // NOLINT |
| 78 | #elif V8_TARGET_ARCH_MIPS64 |
| 79 | #include "src/mips64/assembler-mips64-inl.h" // NOLINT |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 80 | #elif V8_TARGET_ARCH_S390 |
| 81 | #include "src/s390/assembler-s390-inl.h" // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 82 | #elif V8_TARGET_ARCH_X87 |
| 83 | #include "src/x87/assembler-x87-inl.h" // NOLINT |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 84 | #else |
| 85 | #error "Unknown architecture." |
| 86 | #endif |
| 87 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 88 | // Include native regexp-macro-assembler. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 89 | #ifndef V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 90 | #if V8_TARGET_ARCH_IA32 |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 91 | #include "src/regexp/ia32/regexp-macro-assembler-ia32.h" // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 92 | #elif V8_TARGET_ARCH_X64 |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 93 | #include "src/regexp/x64/regexp-macro-assembler-x64.h" // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 94 | #elif V8_TARGET_ARCH_ARM64 |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 95 | #include "src/regexp/arm64/regexp-macro-assembler-arm64.h" // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 96 | #elif V8_TARGET_ARCH_ARM |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 97 | #include "src/regexp/arm/regexp-macro-assembler-arm.h" // NOLINT |
| 98 | #elif V8_TARGET_ARCH_PPC |
| 99 | #include "src/regexp/ppc/regexp-macro-assembler-ppc.h" // NOLINT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 100 | #elif V8_TARGET_ARCH_MIPS |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 101 | #include "src/regexp/mips/regexp-macro-assembler-mips.h" // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 102 | #elif V8_TARGET_ARCH_MIPS64 |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 103 | #include "src/regexp/mips64/regexp-macro-assembler-mips64.h" // NOLINT |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 104 | #elif V8_TARGET_ARCH_S390 |
| 105 | #include "src/regexp/s390/regexp-macro-assembler-s390.h" // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 106 | #elif V8_TARGET_ARCH_X87 |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 107 | #include "src/regexp/x87/regexp-macro-assembler-x87.h" // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 108 | #else // Unknown architecture. |
| 109 | #error "Unknown architecture." |
| 110 | #endif // Target architecture. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 111 | #endif // V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 112 | |
| 113 | namespace v8 { |
| 114 | namespace internal { |
| 115 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 116 | // ----------------------------------------------------------------------------- |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 117 | // Common register code. |
| 118 | |
| 119 | const char* Register::ToString() { |
| 120 | // This is the mapping of allocation indices to registers. |
| 121 | DCHECK(reg_code >= 0 && reg_code < kNumRegisters); |
| 122 | return RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT) |
| 123 | ->GetGeneralRegisterName(reg_code); |
| 124 | } |
| 125 | |
| 126 | |
| 127 | bool Register::IsAllocatable() const { |
| 128 | return ((1 << reg_code) & |
| 129 | RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT) |
| 130 | ->allocatable_general_codes_mask()) != 0; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | const char* DoubleRegister::ToString() { |
| 135 | // This is the mapping of allocation indices to registers. |
| 136 | DCHECK(reg_code >= 0 && reg_code < kMaxNumRegisters); |
| 137 | return RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT) |
| 138 | ->GetDoubleRegisterName(reg_code); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | bool DoubleRegister::IsAllocatable() const { |
| 143 | return ((1 << reg_code) & |
| 144 | RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT) |
| 145 | ->allocatable_double_codes_mask()) != 0; |
| 146 | } |
| 147 | |
| 148 | |
| 149 | // ----------------------------------------------------------------------------- |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 150 | // Common double constants. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 151 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 152 | struct DoubleConstant BASE_EMBEDDED { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 153 | double min_int; |
| 154 | double one_half; |
| 155 | double minus_one_half; |
| 156 | double negative_infinity; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 157 | double the_hole_nan; |
| 158 | double uint32_bias; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 159 | }; |
| 160 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 161 | static DoubleConstant double_constants; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 162 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 163 | const char* const RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING"; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 164 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 165 | static bool math_exp_data_initialized = false; |
| 166 | static base::Mutex* math_exp_data_mutex = NULL; |
| 167 | static double* math_exp_constants_array = NULL; |
| 168 | static double* math_exp_log_table_array = NULL; |
| 169 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 170 | // ----------------------------------------------------------------------------- |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 171 | // Implementation of AssemblerBase |
| 172 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 173 | AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size) |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 174 | : isolate_(isolate), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 175 | jit_cookie_(0), |
| 176 | enabled_cpu_features_(0), |
| 177 | emit_debug_code_(FLAG_debug_code), |
| 178 | predictable_code_size_(false), |
| 179 | // We may use the assembler without an isolate. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 180 | serializer_enabled_(isolate && isolate->serializer_enabled()), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 181 | constant_pool_available_(false) { |
| 182 | DCHECK_NOT_NULL(isolate); |
| 183 | if (FLAG_mask_constants_with_cookie) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 184 | jit_cookie_ = isolate->random_number_generator()->NextInt(); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 185 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 186 | own_buffer_ = buffer == NULL; |
| 187 | if (buffer_size == 0) buffer_size = kMinimalBufferSize; |
| 188 | DCHECK(buffer_size > 0); |
| 189 | if (own_buffer_) buffer = NewArray<byte>(buffer_size); |
| 190 | buffer_ = static_cast<byte*>(buffer); |
| 191 | buffer_size_ = buffer_size; |
| 192 | |
| 193 | pc_ = buffer_; |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 197 | AssemblerBase::~AssemblerBase() { |
| 198 | if (own_buffer_) DeleteArray(buffer_); |
| 199 | } |
| 200 | |
| 201 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 202 | void AssemblerBase::FlushICache(Isolate* isolate, void* start, size_t size) { |
| 203 | if (size == 0) return; |
| 204 | if (CpuFeatures::IsSupported(COHERENT_CACHE)) return; |
| 205 | |
| 206 | #if defined(USE_SIMULATOR) |
| 207 | Simulator::FlushICache(isolate->simulator_i_cache(), start, size); |
| 208 | #else |
| 209 | CpuFeatures::FlushICache(start, size); |
| 210 | #endif // USE_SIMULATOR |
| 211 | } |
| 212 | |
| 213 | |
| 214 | void AssemblerBase::Print() { |
| 215 | OFStream os(stdout); |
| 216 | v8::internal::Disassembler::Decode(isolate(), &os, buffer_, pc_, nullptr); |
| 217 | } |
| 218 | |
| 219 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 220 | // ----------------------------------------------------------------------------- |
| 221 | // Implementation of PredictableCodeSizeScope |
| 222 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 223 | PredictableCodeSizeScope::PredictableCodeSizeScope(AssemblerBase* assembler) |
| 224 | : PredictableCodeSizeScope(assembler, -1) {} |
| 225 | |
| 226 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 227 | PredictableCodeSizeScope::PredictableCodeSizeScope(AssemblerBase* assembler, |
| 228 | int expected_size) |
| 229 | : assembler_(assembler), |
| 230 | expected_size_(expected_size), |
| 231 | start_offset_(assembler->pc_offset()), |
| 232 | old_value_(assembler->predictable_code_size()) { |
| 233 | assembler_->set_predictable_code_size(true); |
| 234 | } |
| 235 | |
| 236 | |
| 237 | PredictableCodeSizeScope::~PredictableCodeSizeScope() { |
| 238 | // TODO(svenpanne) Remove the 'if' when everything works. |
| 239 | if (expected_size_ >= 0) { |
| 240 | CHECK_EQ(expected_size_, assembler_->pc_offset() - start_offset_); |
| 241 | } |
| 242 | assembler_->set_predictable_code_size(old_value_); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | // ----------------------------------------------------------------------------- |
| 247 | // Implementation of CpuFeatureScope |
| 248 | |
| 249 | #ifdef DEBUG |
| 250 | CpuFeatureScope::CpuFeatureScope(AssemblerBase* assembler, CpuFeature f) |
| 251 | : assembler_(assembler) { |
| 252 | DCHECK(CpuFeatures::IsSupported(f)); |
| 253 | old_enabled_ = assembler_->enabled_cpu_features(); |
| 254 | uint64_t mask = static_cast<uint64_t>(1) << f; |
| 255 | // TODO(svenpanne) This special case below doesn't belong here! |
| 256 | #if V8_TARGET_ARCH_ARM |
| 257 | // ARMv7 is implied by VFP3. |
| 258 | if (f == VFP3) { |
| 259 | mask |= static_cast<uint64_t>(1) << ARMv7; |
| 260 | } |
| 261 | #endif |
| 262 | assembler_->set_enabled_cpu_features(old_enabled_ | mask); |
| 263 | } |
| 264 | |
| 265 | |
| 266 | CpuFeatureScope::~CpuFeatureScope() { |
| 267 | assembler_->set_enabled_cpu_features(old_enabled_); |
| 268 | } |
| 269 | #endif |
| 270 | |
| 271 | |
| 272 | bool CpuFeatures::initialized_ = false; |
| 273 | unsigned CpuFeatures::supported_ = 0; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 274 | unsigned CpuFeatures::icache_line_size_ = 0; |
| 275 | unsigned CpuFeatures::dcache_line_size_ = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 276 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 277 | // ----------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 278 | // Implementation of Label |
| 279 | |
| 280 | int Label::pos() const { |
| 281 | if (pos_ < 0) return -pos_ - 1; |
| 282 | if (pos_ > 0) return pos_ - 1; |
| 283 | UNREACHABLE(); |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | |
| 288 | // ----------------------------------------------------------------------------- |
| 289 | // Implementation of RelocInfoWriter and RelocIterator |
| 290 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 291 | // Relocation information is written backwards in memory, from high addresses |
| 292 | // towards low addresses, byte by byte. Therefore, in the encodings listed |
| 293 | // below, the first byte listed it at the highest address, and successive |
| 294 | // bytes in the record are at progressively lower addresses. |
| 295 | // |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 296 | // Encoding |
| 297 | // |
| 298 | // The most common modes are given single-byte encodings. Also, it is |
| 299 | // easy to identify the type of reloc info and skip unwanted modes in |
| 300 | // an iteration. |
| 301 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 302 | // The encoding relies on the fact that there are fewer than 14 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 303 | // different relocation modes using standard non-compact encoding. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 304 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 305 | // The first byte of a relocation record has a tag in its low 2 bits: |
| 306 | // Here are the record schemes, depending on the low tag and optional higher |
| 307 | // tags. |
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 | // Low tag: |
| 310 | // 00: embedded_object: [6-bit pc delta] 00 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 311 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 312 | // 01: code_target: [6-bit pc delta] 01 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 314 | // 10: short_data_record: [6-bit pc delta] 10 followed by |
| 315 | // [6-bit data delta] [2-bit data type tag] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 316 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 317 | // 11: long_record [6 bit reloc mode] 11 |
| 318 | // followed by pc delta |
| 319 | // followed by optional data depending on type. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 320 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 321 | // 2-bit data type tags, used in short_data_record and data_jump long_record: |
| 322 | // code_target_with_id: 00 |
| 323 | // position: 01 |
| 324 | // statement_position: 10 |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 325 | // deopt_reason: 11 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 326 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 327 | // If a pc delta exceeds 6 bits, it is split into a remainder that fits into |
| 328 | // 6 bits and a part that does not. The latter is encoded as a long record |
| 329 | // with PC_JUMP as pseudo reloc info mode. The former is encoded as part of |
| 330 | // the following record in the usual way. The long pc jump record has variable |
| 331 | // length: |
| 332 | // pc-jump: [PC_JUMP] 11 |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 333 | // [7 bits data] 0 |
| 334 | // ... |
| 335 | // [7 bits data] 1 |
| 336 | // (Bits 6..31 of pc delta, with leading zeroes |
| 337 | // dropped, and last non-zero chunk tagged with 1.) |
| 338 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 339 | const int kTagBits = 2; |
| 340 | const int kTagMask = (1 << kTagBits) - 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 341 | const int kLongTagBits = 6; |
| 342 | const int kShortDataTypeTagBits = 2; |
| 343 | const int kShortDataBits = kBitsPerByte - kShortDataTypeTagBits; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 344 | |
| 345 | const int kEmbeddedObjectTag = 0; |
| 346 | const int kCodeTargetTag = 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 347 | const int kLocatableTag = 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 348 | const int kDefaultTag = 3; |
| 349 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 350 | const int kSmallPCDeltaBits = kBitsPerByte - kTagBits; |
| 351 | const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 352 | const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 353 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 354 | const int kChunkBits = 7; |
| 355 | const int kChunkMask = (1 << kChunkBits) - 1; |
| 356 | const int kLastChunkTagBits = 1; |
| 357 | const int kLastChunkTagMask = 1; |
| 358 | const int kLastChunkTag = 1; |
| 359 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 360 | const int kCodeWithIdTag = 0; |
| 361 | const int kNonstatementPositionTag = 1; |
| 362 | const int kStatementPositionTag = 2; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 363 | const int kDeoptReasonTag = 3; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 364 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 365 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 366 | uint32_t RelocInfoWriter::WriteLongPCJump(uint32_t pc_delta) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 367 | // Return if the pc_delta can fit in kSmallPCDeltaBits bits. |
| 368 | // Otherwise write a variable length PC jump for the bits that do |
| 369 | // not fit in the kSmallPCDeltaBits bits. |
| 370 | if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 371 | WriteMode(RelocInfo::PC_JUMP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 372 | uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 373 | DCHECK(pc_jump > 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 374 | // Write kChunkBits size chunks of the pc_jump. |
| 375 | for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) { |
| 376 | byte b = pc_jump & kChunkMask; |
| 377 | *--pos_ = b << kLastChunkTagBits; |
| 378 | } |
| 379 | // Tag the last chunk so it can be identified. |
| 380 | *pos_ = *pos_ | kLastChunkTag; |
| 381 | // Return the remaining kSmallPCDeltaBits of the pc_delta. |
| 382 | return pc_delta & kSmallPCDeltaMask; |
| 383 | } |
| 384 | |
| 385 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 386 | void RelocInfoWriter::WriteShortTaggedPC(uint32_t pc_delta, int tag) { |
| 387 | // Write a byte of tagged pc-delta, possibly preceded by an explicit pc-jump. |
| 388 | pc_delta = WriteLongPCJump(pc_delta); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 389 | *--pos_ = pc_delta << kTagBits | tag; |
| 390 | } |
| 391 | |
| 392 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 393 | void RelocInfoWriter::WriteShortTaggedData(intptr_t data_delta, int tag) { |
| 394 | *--pos_ = static_cast<byte>(data_delta << kShortDataTypeTagBits | tag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 398 | void RelocInfoWriter::WriteMode(RelocInfo::Mode rmode) { |
| 399 | STATIC_ASSERT(RelocInfo::NUMBER_OF_MODES <= (1 << kLongTagBits)); |
| 400 | *--pos_ = static_cast<int>((rmode << kTagBits) | kDefaultTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 404 | void RelocInfoWriter::WriteModeAndPC(uint32_t pc_delta, RelocInfo::Mode rmode) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 405 | // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 406 | pc_delta = WriteLongPCJump(pc_delta); |
| 407 | WriteMode(rmode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 408 | *--pos_ = pc_delta; |
| 409 | } |
| 410 | |
| 411 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 412 | void RelocInfoWriter::WriteIntData(int number) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 413 | for (int i = 0; i < kIntSize; i++) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 414 | *--pos_ = static_cast<byte>(number); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 415 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 416 | number = number >> kBitsPerByte; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 420 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 421 | void RelocInfoWriter::WriteData(intptr_t data_delta) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 422 | for (int i = 0; i < kIntptrSize; i++) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 423 | *--pos_ = static_cast<byte>(data_delta); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 424 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 425 | data_delta = data_delta >> kBitsPerByte; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 430 | void RelocInfoWriter::WritePosition(int pc_delta, int pos_delta, |
| 431 | RelocInfo::Mode rmode) { |
| 432 | int pos_type_tag = (rmode == RelocInfo::POSITION) ? kNonstatementPositionTag |
| 433 | : kStatementPositionTag; |
| 434 | // Check if delta is small enough to fit in a tagged byte. |
| 435 | if (is_intn(pos_delta, kShortDataBits)) { |
| 436 | WriteShortTaggedPC(pc_delta, kLocatableTag); |
| 437 | WriteShortTaggedData(pos_delta, pos_type_tag); |
| 438 | } else { |
| 439 | // Otherwise, use costly encoding. |
| 440 | WriteModeAndPC(pc_delta, rmode); |
| 441 | WriteIntData(pos_delta); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | |
| 446 | void RelocInfoWriter::FlushPosition() { |
| 447 | if (!next_position_candidate_flushed_) { |
| 448 | WritePosition(next_position_candidate_pc_delta_, |
| 449 | next_position_candidate_pos_delta_, RelocInfo::POSITION); |
| 450 | next_position_candidate_pos_delta_ = 0; |
| 451 | next_position_candidate_pc_delta_ = 0; |
| 452 | next_position_candidate_flushed_ = true; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 457 | void RelocInfoWriter::Write(const RelocInfo* rinfo) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 458 | RelocInfo::Mode rmode = rinfo->rmode(); |
| 459 | if (rmode != RelocInfo::POSITION) { |
| 460 | FlushPosition(); |
| 461 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 462 | #ifdef DEBUG |
| 463 | byte* begin_pos = pos_; |
| 464 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 465 | DCHECK(rinfo->rmode() < RelocInfo::NUMBER_OF_MODES); |
| 466 | DCHECK(rinfo->pc() - last_pc_ >= 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 467 | // Use unsigned delta-encoding for pc. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 468 | uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 469 | |
| 470 | // The two most common modes are given small tags, and usually fit in a byte. |
| 471 | if (rmode == RelocInfo::EMBEDDED_OBJECT) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 472 | WriteShortTaggedPC(pc_delta, kEmbeddedObjectTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 473 | } else if (rmode == RelocInfo::CODE_TARGET) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 474 | WriteShortTaggedPC(pc_delta, kCodeTargetTag); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 475 | DCHECK(begin_pos - pos_ <= RelocInfo::kMaxCallSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 476 | } else if (rmode == RelocInfo::CODE_TARGET_WITH_ID) { |
| 477 | // Use signed delta-encoding for id. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 478 | DCHECK_EQ(static_cast<int>(rinfo->data()), rinfo->data()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 479 | int id_delta = static_cast<int>(rinfo->data()) - last_id_; |
| 480 | // Check if delta is small enough to fit in a tagged byte. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 481 | if (is_intn(id_delta, kShortDataBits)) { |
| 482 | WriteShortTaggedPC(pc_delta, kLocatableTag); |
| 483 | WriteShortTaggedData(id_delta, kCodeWithIdTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 484 | } else { |
| 485 | // Otherwise, use costly encoding. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 486 | WriteModeAndPC(pc_delta, rmode); |
| 487 | WriteIntData(id_delta); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 488 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 489 | last_id_ = static_cast<int>(rinfo->data()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 490 | } else if (rmode == RelocInfo::DEOPT_REASON) { |
| 491 | DCHECK(rinfo->data() < (1 << kShortDataBits)); |
| 492 | WriteShortTaggedPC(pc_delta, kLocatableTag); |
| 493 | WriteShortTaggedData(rinfo->data(), kDeoptReasonTag); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 494 | } else if (RelocInfo::IsPosition(rmode)) { |
| 495 | // Use signed delta-encoding for position. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 496 | DCHECK_EQ(static_cast<int>(rinfo->data()), rinfo->data()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 497 | int pos_delta = static_cast<int>(rinfo->data()) - last_position_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 498 | if (rmode == RelocInfo::STATEMENT_POSITION) { |
| 499 | WritePosition(pc_delta, pos_delta, rmode); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 500 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 501 | DCHECK_EQ(rmode, RelocInfo::POSITION); |
| 502 | if (pc_delta != 0 || last_mode_ != RelocInfo::POSITION) { |
| 503 | FlushPosition(); |
| 504 | next_position_candidate_pc_delta_ = pc_delta; |
| 505 | next_position_candidate_pos_delta_ = pos_delta; |
| 506 | } else { |
| 507 | next_position_candidate_pos_delta_ += pos_delta; |
| 508 | } |
| 509 | next_position_candidate_flushed_ = false; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 510 | } |
| 511 | last_position_ = static_cast<int>(rinfo->data()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 512 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 513 | WriteModeAndPC(pc_delta, rmode); |
| 514 | if (RelocInfo::IsComment(rmode)) { |
| 515 | WriteData(rinfo->data()); |
| 516 | } else if (RelocInfo::IsConstPool(rmode) || |
| 517 | RelocInfo::IsVeneerPool(rmode)) { |
| 518 | WriteIntData(static_cast<int>(rinfo->data())); |
| 519 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 520 | } |
| 521 | last_pc_ = rinfo->pc(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 522 | last_mode_ = rmode; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 523 | #ifdef DEBUG |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 524 | DCHECK(begin_pos - pos_ <= kMaxSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 525 | #endif |
| 526 | } |
| 527 | |
| 528 | |
| 529 | inline int RelocIterator::AdvanceGetTag() { |
| 530 | return *--pos_ & kTagMask; |
| 531 | } |
| 532 | |
| 533 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 534 | inline RelocInfo::Mode RelocIterator::GetMode() { |
| 535 | return static_cast<RelocInfo::Mode>((*pos_ >> kTagBits) & |
| 536 | ((1 << kLongTagBits) - 1)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 540 | inline void RelocIterator::ReadShortTaggedPC() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 541 | rinfo_.pc_ += *pos_ >> kTagBits; |
| 542 | } |
| 543 | |
| 544 | |
| 545 | inline void RelocIterator::AdvanceReadPC() { |
| 546 | rinfo_.pc_ += *--pos_; |
| 547 | } |
| 548 | |
| 549 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 550 | void RelocIterator::AdvanceReadId() { |
| 551 | int x = 0; |
| 552 | for (int i = 0; i < kIntSize; i++) { |
| 553 | x |= static_cast<int>(*--pos_) << i * kBitsPerByte; |
| 554 | } |
| 555 | last_id_ += x; |
| 556 | rinfo_.data_ = last_id_; |
| 557 | } |
| 558 | |
| 559 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 560 | void RelocIterator::AdvanceReadInt() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 561 | int x = 0; |
| 562 | for (int i = 0; i < kIntSize; i++) { |
| 563 | x |= static_cast<int>(*--pos_) << i * kBitsPerByte; |
| 564 | } |
| 565 | rinfo_.data_ = x; |
| 566 | } |
| 567 | |
| 568 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 569 | void RelocIterator::AdvanceReadPosition() { |
| 570 | int x = 0; |
| 571 | for (int i = 0; i < kIntSize; i++) { |
| 572 | x |= static_cast<int>(*--pos_) << i * kBitsPerByte; |
| 573 | } |
| 574 | last_position_ += x; |
| 575 | rinfo_.data_ = last_position_; |
| 576 | } |
| 577 | |
| 578 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 579 | void RelocIterator::AdvanceReadData() { |
| 580 | intptr_t x = 0; |
| 581 | for (int i = 0; i < kIntptrSize; i++) { |
| 582 | x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte; |
| 583 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 584 | rinfo_.data_ = x; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 588 | void RelocIterator::AdvanceReadLongPCJump() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 589 | // Read the 32-kSmallPCDeltaBits most significant bits of the |
| 590 | // pc jump in kChunkBits bit chunks and shift them into place. |
| 591 | // Stop when the last chunk is encountered. |
| 592 | uint32_t pc_jump = 0; |
| 593 | for (int i = 0; i < kIntSize; i++) { |
| 594 | byte pc_jump_part = *--pos_; |
| 595 | pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits; |
| 596 | if ((pc_jump_part & kLastChunkTagMask) == 1) break; |
| 597 | } |
| 598 | // The least significant kSmallPCDeltaBits bits will be added |
| 599 | // later. |
| 600 | rinfo_.pc_ += pc_jump << kSmallPCDeltaBits; |
| 601 | } |
| 602 | |
| 603 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 604 | inline int RelocIterator::GetShortDataTypeTag() { |
| 605 | return *pos_ & ((1 << kShortDataTypeTagBits) - 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 609 | inline void RelocIterator::ReadShortTaggedId() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 610 | int8_t signed_b = *pos_; |
| 611 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 612 | last_id_ += signed_b >> kShortDataTypeTagBits; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 613 | rinfo_.data_ = last_id_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 617 | inline void RelocIterator::ReadShortTaggedPosition() { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 618 | int8_t signed_b = *pos_; |
| 619 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 620 | last_position_ += signed_b >> kShortDataTypeTagBits; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 621 | rinfo_.data_ = last_position_; |
| 622 | } |
| 623 | |
| 624 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 625 | inline void RelocIterator::ReadShortTaggedData() { |
| 626 | uint8_t unsigned_b = *pos_; |
| 627 | rinfo_.data_ = unsigned_b >> kTagBits; |
| 628 | } |
| 629 | |
| 630 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 631 | static inline RelocInfo::Mode GetPositionModeFromTag(int tag) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 632 | DCHECK(tag == kNonstatementPositionTag || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 633 | tag == kStatementPositionTag); |
| 634 | return (tag == kNonstatementPositionTag) ? |
| 635 | RelocInfo::POSITION : |
| 636 | RelocInfo::STATEMENT_POSITION; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | |
| 640 | void RelocIterator::next() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 641 | DCHECK(!done()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 642 | // Basically, do the opposite of RelocInfoWriter::Write. |
| 643 | // Reading of data is as far as possible avoided for unwanted modes, |
| 644 | // but we must always update the pc. |
| 645 | // |
| 646 | // We exit this loop by returning when we find a mode we want. |
| 647 | while (pos_ > end_) { |
| 648 | int tag = AdvanceGetTag(); |
| 649 | if (tag == kEmbeddedObjectTag) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 650 | ReadShortTaggedPC(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 651 | if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return; |
| 652 | } else if (tag == kCodeTargetTag) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 653 | ReadShortTaggedPC(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 654 | if (SetMode(RelocInfo::CODE_TARGET)) return; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 655 | } else if (tag == kLocatableTag) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 656 | ReadShortTaggedPC(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 657 | Advance(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 658 | int data_type_tag = GetShortDataTypeTag(); |
| 659 | if (data_type_tag == kCodeWithIdTag) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 660 | if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 661 | ReadShortTaggedId(); |
| 662 | return; |
| 663 | } |
| 664 | } else if (data_type_tag == kDeoptReasonTag) { |
| 665 | if (SetMode(RelocInfo::DEOPT_REASON)) { |
| 666 | ReadShortTaggedData(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 667 | return; |
| 668 | } |
| 669 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 670 | DCHECK(data_type_tag == kNonstatementPositionTag || |
| 671 | data_type_tag == kStatementPositionTag); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 672 | if (mode_mask_ & RelocInfo::kPositionMask) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 673 | // Always update the position if we are interested in either |
| 674 | // statement positions or non-statement positions. |
| 675 | ReadShortTaggedPosition(); |
| 676 | if (SetMode(GetPositionModeFromTag(data_type_tag))) return; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 677 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 678 | } |
| 679 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 680 | DCHECK(tag == kDefaultTag); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 681 | RelocInfo::Mode rmode = GetMode(); |
| 682 | if (rmode == RelocInfo::PC_JUMP) { |
| 683 | AdvanceReadLongPCJump(); |
| 684 | } else { |
| 685 | AdvanceReadPC(); |
| 686 | if (rmode == RelocInfo::CODE_TARGET_WITH_ID) { |
| 687 | if (SetMode(rmode)) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 688 | AdvanceReadId(); |
| 689 | return; |
| 690 | } |
| 691 | Advance(kIntSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 692 | } else if (RelocInfo::IsComment(rmode)) { |
| 693 | if (SetMode(rmode)) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 694 | AdvanceReadData(); |
| 695 | return; |
| 696 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 697 | Advance(kIntptrSize); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 698 | } else if (RelocInfo::IsPosition(rmode)) { |
| 699 | if (mode_mask_ & RelocInfo::kPositionMask) { |
| 700 | // Always update the position if we are interested in either |
| 701 | // statement positions or non-statement positions. |
| 702 | AdvanceReadPosition(); |
| 703 | if (SetMode(rmode)) return; |
| 704 | } else { |
| 705 | Advance(kIntSize); |
| 706 | } |
| 707 | } else if (RelocInfo::IsConstPool(rmode) || |
| 708 | RelocInfo::IsVeneerPool(rmode)) { |
| 709 | if (SetMode(rmode)) { |
| 710 | AdvanceReadInt(); |
| 711 | return; |
| 712 | } |
| 713 | Advance(kIntSize); |
| 714 | } else if (SetMode(static_cast<RelocInfo::Mode>(rmode))) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 715 | return; |
| 716 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 720 | if (code_age_sequence_ != NULL) { |
| 721 | byte* old_code_age_sequence = code_age_sequence_; |
| 722 | code_age_sequence_ = NULL; |
| 723 | if (SetMode(RelocInfo::CODE_AGE_SEQUENCE)) { |
| 724 | rinfo_.data_ = 0; |
| 725 | rinfo_.pc_ = old_code_age_sequence; |
| 726 | return; |
| 727 | } |
| 728 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 729 | done_ = true; |
| 730 | } |
| 731 | |
| 732 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 733 | RelocIterator::RelocIterator(Code* code, int mode_mask) |
| 734 | : rinfo_(code->map()->GetIsolate()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 735 | rinfo_.host_ = code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 736 | rinfo_.pc_ = code->instruction_start(); |
| 737 | rinfo_.data_ = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 738 | // Relocation info is read backwards. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 739 | pos_ = code->relocation_start() + code->relocation_size(); |
| 740 | end_ = code->relocation_start(); |
| 741 | done_ = false; |
| 742 | mode_mask_ = mode_mask; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 743 | last_id_ = 0; |
| 744 | last_position_ = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 745 | byte* sequence = code->FindCodeAgeSequence(); |
| 746 | // We get the isolate from the map, because at serialization time |
| 747 | // the code pointer has been cloned and isn't really in heap space. |
| 748 | Isolate* isolate = code->map()->GetIsolate(); |
| 749 | if (sequence != NULL && !Code::IsYoungSequence(isolate, sequence)) { |
| 750 | code_age_sequence_ = sequence; |
| 751 | } else { |
| 752 | code_age_sequence_ = NULL; |
| 753 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 754 | if (mode_mask_ == 0) pos_ = end_; |
| 755 | next(); |
| 756 | } |
| 757 | |
| 758 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 759 | RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) |
| 760 | : rinfo_(desc.origin->isolate()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 761 | rinfo_.pc_ = desc.buffer; |
| 762 | rinfo_.data_ = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 763 | // Relocation info is read backwards. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 764 | pos_ = desc.buffer + desc.buffer_size; |
| 765 | end_ = pos_ - desc.reloc_size; |
| 766 | done_ = false; |
| 767 | mode_mask_ = mode_mask; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 768 | last_id_ = 0; |
| 769 | last_position_ = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 770 | code_age_sequence_ = NULL; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 771 | if (mode_mask_ == 0) pos_ = end_; |
| 772 | next(); |
| 773 | } |
| 774 | |
| 775 | |
| 776 | // ----------------------------------------------------------------------------- |
| 777 | // Implementation of RelocInfo |
| 778 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 779 | bool RelocInfo::IsPatchedDebugBreakSlotSequence() { |
| 780 | return DebugCodegen::DebugBreakSlotIsPatched(pc_); |
| 781 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 782 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 783 | #ifdef DEBUG |
| 784 | bool RelocInfo::RequiresRelocation(const CodeDesc& desc) { |
| 785 | // Ensure there are no code targets or embedded objects present in the |
| 786 | // deoptimization entries, they would require relocation after code |
| 787 | // generation. |
| 788 | int mode_mask = RelocInfo::kCodeTargetMask | |
| 789 | RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | |
| 790 | RelocInfo::ModeMask(RelocInfo::CELL) | |
| 791 | RelocInfo::kApplyMask; |
| 792 | RelocIterator it(desc, mode_mask); |
| 793 | return !it.done(); |
| 794 | } |
| 795 | #endif |
| 796 | |
| 797 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 798 | #ifdef ENABLE_DISASSEMBLER |
| 799 | const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) { |
| 800 | switch (rmode) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 801 | case NONE32: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 802 | return "no reloc 32"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 803 | case NONE64: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 804 | return "no reloc 64"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 805 | case EMBEDDED_OBJECT: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 806 | return "embedded object"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 807 | case DEBUGGER_STATEMENT: |
| 808 | return "debugger statement"; |
| 809 | case CODE_TARGET: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 810 | return "code target"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 811 | case CODE_TARGET_WITH_ID: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 812 | return "code target with id"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 813 | case CELL: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 814 | return "property cell"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 815 | case RUNTIME_ENTRY: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 816 | return "runtime entry"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 817 | case COMMENT: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 818 | return "comment"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 819 | case POSITION: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 820 | return "position"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 821 | case STATEMENT_POSITION: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 822 | return "statement position"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 823 | case EXTERNAL_REFERENCE: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 824 | return "external reference"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 825 | case INTERNAL_REFERENCE: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 826 | return "internal reference"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 827 | case INTERNAL_REFERENCE_ENCODED: |
| 828 | return "encoded internal reference"; |
| 829 | case DEOPT_REASON: |
| 830 | return "deopt reason"; |
| 831 | case CONST_POOL: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 832 | return "constant pool"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 833 | case VENEER_POOL: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 834 | return "veneer pool"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 835 | case DEBUG_BREAK_SLOT_AT_POSITION: |
| 836 | return "debug break slot at position"; |
| 837 | case DEBUG_BREAK_SLOT_AT_RETURN: |
| 838 | return "debug break slot at return"; |
| 839 | case DEBUG_BREAK_SLOT_AT_CALL: |
| 840 | return "debug break slot at call"; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 841 | case DEBUG_BREAK_SLOT_AT_TAIL_CALL: |
| 842 | return "debug break slot at tail call"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 843 | case CODE_AGE_SEQUENCE: |
| 844 | return "code age sequence"; |
| 845 | case GENERATOR_CONTINUATION: |
| 846 | return "generator continuation"; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 847 | case WASM_MEMORY_REFERENCE: |
| 848 | return "wasm memory reference"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 849 | case NUMBER_OF_MODES: |
| 850 | case PC_JUMP: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 851 | UNREACHABLE(); |
| 852 | return "number_of_modes"; |
| 853 | } |
| 854 | return "unknown relocation type"; |
| 855 | } |
| 856 | |
| 857 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 858 | void RelocInfo::Print(Isolate* isolate, std::ostream& os) { // NOLINT |
| 859 | os << static_cast<const void*>(pc_) << " " << RelocModeName(rmode_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 860 | if (IsComment(rmode_)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 861 | os << " (" << reinterpret_cast<char*>(data_) << ")"; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 862 | } else if (rmode_ == DEOPT_REASON) { |
| 863 | os << " (" << Deoptimizer::GetDeoptReason( |
| 864 | static_cast<Deoptimizer::DeoptReason>(data_)) << ")"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 865 | } else if (rmode_ == EMBEDDED_OBJECT) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 866 | os << " (" << Brief(target_object()) << ")"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 867 | } else if (rmode_ == EXTERNAL_REFERENCE) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 868 | ExternalReferenceEncoder ref_encoder(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 869 | os << " (" |
| 870 | << ref_encoder.NameOfAddress(isolate, target_external_reference()) |
| 871 | << ") (" << static_cast<const void*>(target_external_reference()) |
| 872 | << ")"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 873 | } else if (IsCodeTarget(rmode_)) { |
| 874 | Code* code = Code::GetCodeFromTargetAddress(target_address()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 875 | os << " (" << Code::Kind2String(code->kind()) << ") (" |
| 876 | << static_cast<const void*>(target_address()) << ")"; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 877 | if (rmode_ == CODE_TARGET_WITH_ID) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 878 | os << " (id=" << static_cast<int>(data_) << ")"; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 879 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 880 | } else if (IsPosition(rmode_)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 881 | os << " (" << data() << ")"; |
| 882 | } else if (IsRuntimeEntry(rmode_) && |
| 883 | isolate->deoptimizer_data() != NULL) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 884 | // Depotimization bailouts are stored as runtime entries. |
| 885 | int id = Deoptimizer::GetDeoptimizationId( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 886 | isolate, target_address(), Deoptimizer::EAGER); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 887 | if (id != Deoptimizer::kNotDeoptimizationEntry) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 888 | os << " (deoptimization bailout " << id << ")"; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 889 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 890 | } else if (IsConstPool(rmode_)) { |
| 891 | os << " (size " << static_cast<int>(data_) << ")"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 892 | } |
| 893 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 894 | os << "\n"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 895 | } |
| 896 | #endif // ENABLE_DISASSEMBLER |
| 897 | |
| 898 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 899 | #ifdef VERIFY_HEAP |
| 900 | void RelocInfo::Verify(Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 901 | switch (rmode_) { |
| 902 | case EMBEDDED_OBJECT: |
| 903 | Object::VerifyPointer(target_object()); |
| 904 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 905 | case CELL: |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 906 | Object::VerifyPointer(target_cell()); |
| 907 | break; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 908 | case DEBUGGER_STATEMENT: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 909 | case CODE_TARGET_WITH_ID: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 910 | case CODE_TARGET: { |
| 911 | // convert inline target address to code object |
| 912 | Address addr = target_address(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 913 | CHECK(addr != NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 914 | // Check that we can find the right code object. |
| 915 | Code* code = Code::GetCodeFromTargetAddress(addr); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 916 | Object* found = isolate->FindCodeObject(addr); |
| 917 | CHECK(found->IsCode()); |
| 918 | CHECK(code->address() == HeapObject::cast(found)->address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 919 | break; |
| 920 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 921 | case INTERNAL_REFERENCE: |
| 922 | case INTERNAL_REFERENCE_ENCODED: { |
| 923 | Address target = target_internal_reference(); |
| 924 | Address pc = target_internal_reference_address(); |
| 925 | Code* code = Code::cast(isolate->FindCodeObject(pc)); |
| 926 | CHECK(target >= code->instruction_start()); |
| 927 | CHECK(target <= code->instruction_end()); |
| 928 | break; |
| 929 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 930 | case RUNTIME_ENTRY: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 931 | case COMMENT: |
| 932 | case POSITION: |
| 933 | case STATEMENT_POSITION: |
| 934 | case EXTERNAL_REFERENCE: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 935 | case DEOPT_REASON: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 936 | case CONST_POOL: |
| 937 | case VENEER_POOL: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 938 | case DEBUG_BREAK_SLOT_AT_POSITION: |
| 939 | case DEBUG_BREAK_SLOT_AT_RETURN: |
| 940 | case DEBUG_BREAK_SLOT_AT_CALL: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 941 | case DEBUG_BREAK_SLOT_AT_TAIL_CALL: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 942 | case GENERATOR_CONTINUATION: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 943 | case WASM_MEMORY_REFERENCE: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 944 | case NONE32: |
| 945 | case NONE64: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 946 | break; |
| 947 | case NUMBER_OF_MODES: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 948 | case PC_JUMP: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 949 | UNREACHABLE(); |
| 950 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 951 | case CODE_AGE_SEQUENCE: |
| 952 | DCHECK(Code::IsYoungSequence(isolate, pc_) || code_age_stub()->IsCode()); |
| 953 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 954 | } |
| 955 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 956 | #endif // VERIFY_HEAP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 957 | |
| 958 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 959 | // Implementation of ExternalReference |
| 960 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 961 | static ExternalReference::Type BuiltinCallTypeForResultSize(int result_size) { |
| 962 | switch (result_size) { |
| 963 | case 1: |
| 964 | return ExternalReference::BUILTIN_CALL; |
| 965 | case 2: |
| 966 | return ExternalReference::BUILTIN_CALL_PAIR; |
| 967 | case 3: |
| 968 | return ExternalReference::BUILTIN_CALL_TRIPLE; |
| 969 | } |
| 970 | UNREACHABLE(); |
| 971 | return ExternalReference::BUILTIN_CALL; |
| 972 | } |
| 973 | |
| 974 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 975 | void ExternalReference::SetUp() { |
| 976 | double_constants.min_int = kMinInt; |
| 977 | double_constants.one_half = 0.5; |
| 978 | double_constants.minus_one_half = -0.5; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 979 | double_constants.the_hole_nan = bit_cast<double>(kHoleNanInt64); |
| 980 | double_constants.negative_infinity = -V8_INFINITY; |
| 981 | double_constants.uint32_bias = |
| 982 | static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1; |
| 983 | |
| 984 | math_exp_data_mutex = new base::Mutex(); |
| 985 | } |
| 986 | |
| 987 | |
| 988 | void ExternalReference::InitializeMathExpData() { |
| 989 | // Early return? |
| 990 | if (math_exp_data_initialized) return; |
| 991 | |
| 992 | base::LockGuard<base::Mutex> lock_guard(math_exp_data_mutex); |
| 993 | if (!math_exp_data_initialized) { |
| 994 | // If this is changed, generated code must be adapted too. |
| 995 | const int kTableSizeBits = 11; |
| 996 | const int kTableSize = 1 << kTableSizeBits; |
| 997 | const double kTableSizeDouble = static_cast<double>(kTableSize); |
| 998 | |
| 999 | math_exp_constants_array = new double[9]; |
| 1000 | // Input values smaller than this always return 0. |
| 1001 | math_exp_constants_array[0] = -708.39641853226408; |
| 1002 | // Input values larger than this always return +Infinity. |
| 1003 | math_exp_constants_array[1] = 709.78271289338397; |
| 1004 | math_exp_constants_array[2] = V8_INFINITY; |
| 1005 | // The rest is black magic. Do not attempt to understand it. It is |
| 1006 | // loosely based on the "expd" function published at: |
| 1007 | // http://herumi.blogspot.com/2011/08/fast-double-precision-exponential.html |
| 1008 | const double constant3 = (1 << kTableSizeBits) / std::log(2.0); |
| 1009 | math_exp_constants_array[3] = constant3; |
| 1010 | math_exp_constants_array[4] = |
| 1011 | static_cast<double>(static_cast<int64_t>(3) << 51); |
| 1012 | math_exp_constants_array[5] = 1 / constant3; |
| 1013 | math_exp_constants_array[6] = 3.0000000027955394; |
| 1014 | math_exp_constants_array[7] = 0.16666666685227835; |
| 1015 | math_exp_constants_array[8] = 1; |
| 1016 | |
| 1017 | math_exp_log_table_array = new double[kTableSize]; |
| 1018 | for (int i = 0; i < kTableSize; i++) { |
| 1019 | double value = std::pow(2, i / kTableSizeDouble); |
| 1020 | uint64_t bits = bit_cast<uint64_t, double>(value); |
| 1021 | bits &= (static_cast<uint64_t>(1) << 52) - 1; |
| 1022 | double mantissa = bit_cast<double, uint64_t>(bits); |
| 1023 | math_exp_log_table_array[i] = mantissa; |
| 1024 | } |
| 1025 | |
| 1026 | math_exp_data_initialized = true; |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | |
| 1031 | void ExternalReference::TearDownMathExpData() { |
| 1032 | delete[] math_exp_constants_array; |
| 1033 | math_exp_constants_array = NULL; |
| 1034 | delete[] math_exp_log_table_array; |
| 1035 | math_exp_log_table_array = NULL; |
| 1036 | delete math_exp_data_mutex; |
| 1037 | math_exp_data_mutex = NULL; |
| 1038 | } |
| 1039 | |
| 1040 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1041 | ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate) |
| 1042 | : address_(Redirect(isolate, Builtins::c_function_address(id))) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1043 | |
| 1044 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1045 | ExternalReference::ExternalReference( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1046 | ApiFunction* fun, |
| 1047 | Type type = ExternalReference::BUILTIN_CALL, |
| 1048 | Isolate* isolate = NULL) |
| 1049 | : address_(Redirect(isolate, fun->address(), type)) {} |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1050 | |
| 1051 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1052 | ExternalReference::ExternalReference(Builtins::Name name, Isolate* isolate) |
| 1053 | : address_(isolate->builtins()->builtin_address(name)) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1054 | |
| 1055 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1056 | ExternalReference::ExternalReference(Runtime::FunctionId id, Isolate* isolate) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1057 | : ExternalReference(Runtime::FunctionForId(id), isolate) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1058 | |
| 1059 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1060 | ExternalReference::ExternalReference(const Runtime::Function* f, |
| 1061 | Isolate* isolate) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1062 | : address_(Redirect(isolate, f->entry, |
| 1063 | BuiltinCallTypeForResultSize(f->result_size))) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1064 | |
| 1065 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1066 | ExternalReference ExternalReference::isolate_address(Isolate* isolate) { |
| 1067 | return ExternalReference(isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1070 | ExternalReference ExternalReference::interpreter_dispatch_table_address( |
| 1071 | Isolate* isolate) { |
| 1072 | return ExternalReference(isolate->interpreter()->dispatch_table_address()); |
| 1073 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1074 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1075 | ExternalReference::ExternalReference(StatsCounter* counter) |
| 1076 | : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {} |
| 1077 | |
| 1078 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1079 | ExternalReference::ExternalReference(Isolate::AddressId id, Isolate* isolate) |
| 1080 | : address_(isolate->get_address_from_id(id)) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1081 | |
| 1082 | |
| 1083 | ExternalReference::ExternalReference(const SCTableReference& table_ref) |
| 1084 | : address_(table_ref.address()) {} |
| 1085 | |
| 1086 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1087 | ExternalReference ExternalReference:: |
| 1088 | incremental_marking_record_write_function(Isolate* isolate) { |
| 1089 | return ExternalReference(Redirect( |
| 1090 | isolate, |
| 1091 | FUNCTION_ADDR(IncrementalMarking::RecordWriteFromCode))); |
| 1092 | } |
| 1093 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1094 | ExternalReference |
| 1095 | ExternalReference::incremental_marking_record_write_code_entry_function( |
| 1096 | Isolate* isolate) { |
| 1097 | return ExternalReference(Redirect( |
| 1098 | isolate, |
| 1099 | FUNCTION_ADDR(IncrementalMarking::RecordWriteOfCodeEntryFromCode))); |
| 1100 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1101 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1102 | ExternalReference ExternalReference::store_buffer_overflow_function( |
| 1103 | Isolate* isolate) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1104 | return ExternalReference(Redirect( |
| 1105 | isolate, |
| 1106 | FUNCTION_ADDR(StoreBuffer::StoreBufferOverflow))); |
| 1107 | } |
| 1108 | |
| 1109 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1110 | ExternalReference ExternalReference::delete_handle_scope_extensions( |
| 1111 | Isolate* isolate) { |
| 1112 | return ExternalReference(Redirect( |
| 1113 | isolate, |
| 1114 | FUNCTION_ADDR(HandleScope::DeleteExtensions))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1118 | ExternalReference ExternalReference::get_date_field_function( |
| 1119 | Isolate* isolate) { |
| 1120 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(JSDate::GetField))); |
| 1121 | } |
| 1122 | |
| 1123 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1124 | ExternalReference ExternalReference::get_make_code_young_function( |
| 1125 | Isolate* isolate) { |
| 1126 | return ExternalReference(Redirect( |
| 1127 | isolate, FUNCTION_ADDR(Code::MakeCodeAgeSequenceYoung))); |
| 1128 | } |
| 1129 | |
| 1130 | |
| 1131 | ExternalReference ExternalReference::get_mark_code_as_executed_function( |
| 1132 | Isolate* isolate) { |
| 1133 | return ExternalReference(Redirect( |
| 1134 | isolate, FUNCTION_ADDR(Code::MarkCodeAsExecuted))); |
| 1135 | } |
| 1136 | |
| 1137 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1138 | ExternalReference ExternalReference::date_cache_stamp(Isolate* isolate) { |
| 1139 | return ExternalReference(isolate->date_cache()->stamp_address()); |
| 1140 | } |
| 1141 | |
| 1142 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1143 | ExternalReference ExternalReference::stress_deopt_count(Isolate* isolate) { |
| 1144 | return ExternalReference(isolate->stress_deopt_count_address()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1148 | ExternalReference ExternalReference::new_deoptimizer_function( |
| 1149 | Isolate* isolate) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1150 | return ExternalReference( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1151 | Redirect(isolate, FUNCTION_ADDR(Deoptimizer::New))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1155 | ExternalReference ExternalReference::compute_output_frames_function( |
| 1156 | Isolate* isolate) { |
| 1157 | return ExternalReference( |
| 1158 | Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1159 | } |
| 1160 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1161 | ExternalReference ExternalReference::wasm_f32_trunc(Isolate* isolate) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1162 | return ExternalReference( |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1163 | Redirect(isolate, FUNCTION_ADDR(wasm::f32_trunc_wrapper))); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1164 | } |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1165 | ExternalReference ExternalReference::wasm_f32_floor(Isolate* isolate) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1166 | return ExternalReference( |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1167 | Redirect(isolate, FUNCTION_ADDR(wasm::f32_floor_wrapper))); |
| 1168 | } |
| 1169 | ExternalReference ExternalReference::wasm_f32_ceil(Isolate* isolate) { |
| 1170 | return ExternalReference( |
| 1171 | Redirect(isolate, FUNCTION_ADDR(wasm::f32_ceil_wrapper))); |
| 1172 | } |
| 1173 | ExternalReference ExternalReference::wasm_f32_nearest_int(Isolate* isolate) { |
| 1174 | return ExternalReference( |
| 1175 | Redirect(isolate, FUNCTION_ADDR(wasm::f32_nearest_int_wrapper))); |
| 1176 | } |
| 1177 | |
| 1178 | ExternalReference ExternalReference::wasm_f64_trunc(Isolate* isolate) { |
| 1179 | return ExternalReference( |
| 1180 | Redirect(isolate, FUNCTION_ADDR(wasm::f64_trunc_wrapper))); |
| 1181 | } |
| 1182 | |
| 1183 | ExternalReference ExternalReference::wasm_f64_floor(Isolate* isolate) { |
| 1184 | return ExternalReference( |
| 1185 | Redirect(isolate, FUNCTION_ADDR(wasm::f64_floor_wrapper))); |
| 1186 | } |
| 1187 | |
| 1188 | ExternalReference ExternalReference::wasm_f64_ceil(Isolate* isolate) { |
| 1189 | return ExternalReference( |
| 1190 | Redirect(isolate, FUNCTION_ADDR(wasm::f64_ceil_wrapper))); |
| 1191 | } |
| 1192 | |
| 1193 | ExternalReference ExternalReference::wasm_f64_nearest_int(Isolate* isolate) { |
| 1194 | return ExternalReference( |
| 1195 | Redirect(isolate, FUNCTION_ADDR(wasm::f64_nearest_int_wrapper))); |
| 1196 | } |
| 1197 | |
| 1198 | ExternalReference ExternalReference::wasm_int64_to_float32(Isolate* isolate) { |
| 1199 | return ExternalReference( |
| 1200 | Redirect(isolate, FUNCTION_ADDR(wasm::int64_to_float32_wrapper))); |
| 1201 | } |
| 1202 | |
| 1203 | ExternalReference ExternalReference::wasm_uint64_to_float32(Isolate* isolate) { |
| 1204 | return ExternalReference( |
| 1205 | Redirect(isolate, FUNCTION_ADDR(wasm::uint64_to_float32_wrapper))); |
| 1206 | } |
| 1207 | |
| 1208 | ExternalReference ExternalReference::wasm_int64_to_float64(Isolate* isolate) { |
| 1209 | return ExternalReference( |
| 1210 | Redirect(isolate, FUNCTION_ADDR(wasm::int64_to_float64_wrapper))); |
| 1211 | } |
| 1212 | |
| 1213 | ExternalReference ExternalReference::wasm_uint64_to_float64(Isolate* isolate) { |
| 1214 | return ExternalReference( |
| 1215 | Redirect(isolate, FUNCTION_ADDR(wasm::uint64_to_float64_wrapper))); |
| 1216 | } |
| 1217 | |
| 1218 | ExternalReference ExternalReference::wasm_float32_to_int64(Isolate* isolate) { |
| 1219 | return ExternalReference( |
| 1220 | Redirect(isolate, FUNCTION_ADDR(wasm::float32_to_int64_wrapper))); |
| 1221 | } |
| 1222 | |
| 1223 | ExternalReference ExternalReference::wasm_float32_to_uint64(Isolate* isolate) { |
| 1224 | return ExternalReference( |
| 1225 | Redirect(isolate, FUNCTION_ADDR(wasm::float32_to_uint64_wrapper))); |
| 1226 | } |
| 1227 | |
| 1228 | ExternalReference ExternalReference::wasm_float64_to_int64(Isolate* isolate) { |
| 1229 | return ExternalReference( |
| 1230 | Redirect(isolate, FUNCTION_ADDR(wasm::float64_to_int64_wrapper))); |
| 1231 | } |
| 1232 | |
| 1233 | ExternalReference ExternalReference::wasm_float64_to_uint64(Isolate* isolate) { |
| 1234 | return ExternalReference( |
| 1235 | Redirect(isolate, FUNCTION_ADDR(wasm::float64_to_uint64_wrapper))); |
| 1236 | } |
| 1237 | |
| 1238 | ExternalReference ExternalReference::wasm_int64_div(Isolate* isolate) { |
| 1239 | return ExternalReference( |
| 1240 | Redirect(isolate, FUNCTION_ADDR(wasm::int64_div_wrapper))); |
| 1241 | } |
| 1242 | |
| 1243 | ExternalReference ExternalReference::wasm_int64_mod(Isolate* isolate) { |
| 1244 | return ExternalReference( |
| 1245 | Redirect(isolate, FUNCTION_ADDR(wasm::int64_mod_wrapper))); |
| 1246 | } |
| 1247 | |
| 1248 | ExternalReference ExternalReference::wasm_uint64_div(Isolate* isolate) { |
| 1249 | return ExternalReference( |
| 1250 | Redirect(isolate, FUNCTION_ADDR(wasm::uint64_div_wrapper))); |
| 1251 | } |
| 1252 | |
| 1253 | ExternalReference ExternalReference::wasm_uint64_mod(Isolate* isolate) { |
| 1254 | return ExternalReference( |
| 1255 | Redirect(isolate, FUNCTION_ADDR(wasm::uint64_mod_wrapper))); |
| 1256 | } |
| 1257 | |
| 1258 | static void f64_acos_wrapper(double* param) { *param = std::acos(*param); } |
| 1259 | |
| 1260 | ExternalReference ExternalReference::f64_acos_wrapper_function( |
| 1261 | Isolate* isolate) { |
| 1262 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_acos_wrapper))); |
| 1263 | } |
| 1264 | |
| 1265 | static void f64_asin_wrapper(double* param) { *param = std::asin(*param); } |
| 1266 | |
| 1267 | ExternalReference ExternalReference::f64_asin_wrapper_function( |
| 1268 | Isolate* isolate) { |
| 1269 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_asin_wrapper))); |
| 1270 | } |
| 1271 | |
| 1272 | static void f64_atan_wrapper(double* param) { *param = std::atan(*param); } |
| 1273 | |
| 1274 | ExternalReference ExternalReference::f64_atan_wrapper_function( |
| 1275 | Isolate* isolate) { |
| 1276 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_atan_wrapper))); |
| 1277 | } |
| 1278 | |
| 1279 | static void f64_cos_wrapper(double* param) { *param = std::cos(*param); } |
| 1280 | |
| 1281 | ExternalReference ExternalReference::f64_cos_wrapper_function( |
| 1282 | Isolate* isolate) { |
| 1283 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_cos_wrapper))); |
| 1284 | } |
| 1285 | |
| 1286 | static void f64_sin_wrapper(double* param) { *param = std::sin(*param); } |
| 1287 | |
| 1288 | ExternalReference ExternalReference::f64_sin_wrapper_function( |
| 1289 | Isolate* isolate) { |
| 1290 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_sin_wrapper))); |
| 1291 | } |
| 1292 | |
| 1293 | static void f64_tan_wrapper(double* param) { *param = std::tan(*param); } |
| 1294 | |
| 1295 | ExternalReference ExternalReference::f64_tan_wrapper_function( |
| 1296 | Isolate* isolate) { |
| 1297 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_tan_wrapper))); |
| 1298 | } |
| 1299 | |
| 1300 | static void f64_exp_wrapper(double* param) { *param = std::exp(*param); } |
| 1301 | |
| 1302 | ExternalReference ExternalReference::f64_exp_wrapper_function( |
| 1303 | Isolate* isolate) { |
| 1304 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_exp_wrapper))); |
| 1305 | } |
| 1306 | |
| 1307 | static void f64_log_wrapper(double* param) { *param = std::log(*param); } |
| 1308 | |
| 1309 | ExternalReference ExternalReference::f64_log_wrapper_function( |
| 1310 | Isolate* isolate) { |
| 1311 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_log_wrapper))); |
| 1312 | } |
| 1313 | |
| 1314 | static void f64_pow_wrapper(double* param0, double* param1) { |
| 1315 | *param0 = power_double_double(*param0, *param1); |
| 1316 | } |
| 1317 | |
| 1318 | ExternalReference ExternalReference::f64_pow_wrapper_function( |
| 1319 | Isolate* isolate) { |
| 1320 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_pow_wrapper))); |
| 1321 | } |
| 1322 | |
| 1323 | static void f64_atan2_wrapper(double* param0, double* param1) { |
| 1324 | double x = *param0; |
| 1325 | double y = *param1; |
| 1326 | // TODO(bradnelson): Find a good place to put this to share |
| 1327 | // with the same code in src/runtime/runtime-math.cc |
| 1328 | static const double kPiDividedBy4 = 0.78539816339744830962; |
| 1329 | if (std::isinf(x) && std::isinf(y)) { |
| 1330 | // Make sure that the result in case of two infinite arguments |
| 1331 | // is a multiple of Pi / 4. The sign of the result is determined |
| 1332 | // by the first argument (x) and the sign of the second argument |
| 1333 | // determines the multiplier: one or three. |
| 1334 | int multiplier = (x < 0) ? -1 : 1; |
| 1335 | if (y < 0) multiplier *= 3; |
| 1336 | *param0 = multiplier * kPiDividedBy4; |
| 1337 | } else { |
| 1338 | *param0 = std::atan2(x, y); |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | ExternalReference ExternalReference::f64_atan2_wrapper_function( |
| 1343 | Isolate* isolate) { |
| 1344 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_atan2_wrapper))); |
| 1345 | } |
| 1346 | |
| 1347 | static void f64_mod_wrapper(double* param0, double* param1) { |
| 1348 | *param0 = modulo(*param0, *param1); |
| 1349 | } |
| 1350 | |
| 1351 | ExternalReference ExternalReference::f64_mod_wrapper_function( |
| 1352 | Isolate* isolate) { |
| 1353 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_mod_wrapper))); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1354 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1355 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1356 | ExternalReference ExternalReference::log_enter_external_function( |
| 1357 | Isolate* isolate) { |
| 1358 | return ExternalReference( |
| 1359 | Redirect(isolate, FUNCTION_ADDR(Logger::EnterExternal))); |
| 1360 | } |
| 1361 | |
| 1362 | |
| 1363 | ExternalReference ExternalReference::log_leave_external_function( |
| 1364 | Isolate* isolate) { |
| 1365 | return ExternalReference( |
| 1366 | Redirect(isolate, FUNCTION_ADDR(Logger::LeaveExternal))); |
| 1367 | } |
| 1368 | |
| 1369 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1370 | ExternalReference ExternalReference::keyed_lookup_cache_keys(Isolate* isolate) { |
| 1371 | return ExternalReference(isolate->keyed_lookup_cache()->keys_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1375 | ExternalReference ExternalReference::keyed_lookup_cache_field_offsets( |
| 1376 | Isolate* isolate) { |
| 1377 | return ExternalReference( |
| 1378 | isolate->keyed_lookup_cache()->field_offsets_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1382 | ExternalReference ExternalReference::roots_array_start(Isolate* isolate) { |
| 1383 | return ExternalReference(isolate->heap()->roots_array_start()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1387 | ExternalReference ExternalReference::allocation_sites_list_address( |
| 1388 | Isolate* isolate) { |
| 1389 | return ExternalReference(isolate->heap()->allocation_sites_list_address()); |
| 1390 | } |
| 1391 | |
| 1392 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1393 | ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) { |
| 1394 | return ExternalReference(isolate->stack_guard()->address_of_jslimit()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1398 | ExternalReference ExternalReference::address_of_real_stack_limit( |
| 1399 | Isolate* isolate) { |
| 1400 | return ExternalReference(isolate->stack_guard()->address_of_real_jslimit()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1404 | ExternalReference ExternalReference::address_of_regexp_stack_limit( |
| 1405 | Isolate* isolate) { |
| 1406 | return ExternalReference(isolate->regexp_stack()->limit_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1409 | ExternalReference ExternalReference::store_buffer_top(Isolate* isolate) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1410 | return ExternalReference(isolate->heap()->store_buffer_top_address()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1414 | ExternalReference ExternalReference::new_space_allocation_top_address( |
| 1415 | Isolate* isolate) { |
| 1416 | return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1420 | ExternalReference ExternalReference::new_space_allocation_limit_address( |
| 1421 | Isolate* isolate) { |
| 1422 | return ExternalReference(isolate->heap()->NewSpaceAllocationLimitAddress()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1425 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1426 | ExternalReference ExternalReference::old_space_allocation_top_address( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1427 | Isolate* isolate) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1428 | return ExternalReference(isolate->heap()->OldSpaceAllocationTopAddress()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1432 | ExternalReference ExternalReference::old_space_allocation_limit_address( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1433 | Isolate* isolate) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1434 | return ExternalReference(isolate->heap()->OldSpaceAllocationLimitAddress()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | |
| 1438 | ExternalReference ExternalReference::handle_scope_level_address( |
| 1439 | Isolate* isolate) { |
| 1440 | return ExternalReference(HandleScope::current_level_address(isolate)); |
| 1441 | } |
| 1442 | |
| 1443 | |
| 1444 | ExternalReference ExternalReference::handle_scope_next_address( |
| 1445 | Isolate* isolate) { |
| 1446 | return ExternalReference(HandleScope::current_next_address(isolate)); |
| 1447 | } |
| 1448 | |
| 1449 | |
| 1450 | ExternalReference ExternalReference::handle_scope_limit_address( |
| 1451 | Isolate* isolate) { |
| 1452 | return ExternalReference(HandleScope::current_limit_address(isolate)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1456 | ExternalReference ExternalReference::scheduled_exception_address( |
| 1457 | Isolate* isolate) { |
| 1458 | return ExternalReference(isolate->scheduled_exception_address()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1462 | ExternalReference ExternalReference::address_of_pending_message_obj( |
| 1463 | Isolate* isolate) { |
| 1464 | return ExternalReference(isolate->pending_message_obj_address()); |
| 1465 | } |
| 1466 | |
| 1467 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1468 | ExternalReference ExternalReference::address_of_min_int() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1469 | return ExternalReference(reinterpret_cast<void*>(&double_constants.min_int)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | |
| 1473 | ExternalReference ExternalReference::address_of_one_half() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1474 | return ExternalReference(reinterpret_cast<void*>(&double_constants.one_half)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1478 | ExternalReference ExternalReference::address_of_minus_one_half() { |
| 1479 | return ExternalReference( |
| 1480 | reinterpret_cast<void*>(&double_constants.minus_one_half)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1484 | ExternalReference ExternalReference::address_of_negative_infinity() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1485 | return ExternalReference( |
| 1486 | reinterpret_cast<void*>(&double_constants.negative_infinity)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1490 | ExternalReference ExternalReference::address_of_the_hole_nan() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1491 | return ExternalReference( |
| 1492 | reinterpret_cast<void*>(&double_constants.the_hole_nan)); |
| 1493 | } |
| 1494 | |
| 1495 | |
| 1496 | ExternalReference ExternalReference::address_of_uint32_bias() { |
| 1497 | return ExternalReference( |
| 1498 | reinterpret_cast<void*>(&double_constants.uint32_bias)); |
| 1499 | } |
| 1500 | |
| 1501 | |
| 1502 | ExternalReference ExternalReference::is_profiling_address(Isolate* isolate) { |
| 1503 | return ExternalReference(isolate->cpu_profiler()->is_profiling_address()); |
| 1504 | } |
| 1505 | |
| 1506 | |
| 1507 | ExternalReference ExternalReference::invoke_function_callback( |
| 1508 | Isolate* isolate) { |
| 1509 | Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback); |
| 1510 | ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL; |
| 1511 | ApiFunction thunk_fun(thunk_address); |
| 1512 | return ExternalReference(&thunk_fun, thunk_type, isolate); |
| 1513 | } |
| 1514 | |
| 1515 | |
| 1516 | ExternalReference ExternalReference::invoke_accessor_getter_callback( |
| 1517 | Isolate* isolate) { |
| 1518 | Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback); |
| 1519 | ExternalReference::Type thunk_type = |
| 1520 | ExternalReference::PROFILING_GETTER_CALL; |
| 1521 | ApiFunction thunk_fun(thunk_address); |
| 1522 | return ExternalReference(&thunk_fun, thunk_type, isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1526 | #ifndef V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1527 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1528 | ExternalReference ExternalReference::re_check_stack_guard_state( |
| 1529 | Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1530 | Address function; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1531 | #if V8_TARGET_ARCH_X64 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1532 | function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState); |
| 1533 | #elif V8_TARGET_ARCH_IA32 |
| 1534 | function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1535 | #elif V8_TARGET_ARCH_ARM64 |
| 1536 | function = FUNCTION_ADDR(RegExpMacroAssemblerARM64::CheckStackGuardState); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1537 | #elif V8_TARGET_ARCH_ARM |
| 1538 | function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1539 | #elif V8_TARGET_ARCH_PPC |
| 1540 | function = FUNCTION_ADDR(RegExpMacroAssemblerPPC::CheckStackGuardState); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1541 | #elif V8_TARGET_ARCH_MIPS |
| 1542 | function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1543 | #elif V8_TARGET_ARCH_MIPS64 |
| 1544 | function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1545 | #elif V8_TARGET_ARCH_S390 |
| 1546 | function = FUNCTION_ADDR(RegExpMacroAssemblerS390::CheckStackGuardState); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1547 | #elif V8_TARGET_ARCH_X87 |
| 1548 | function = FUNCTION_ADDR(RegExpMacroAssemblerX87::CheckStackGuardState); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1549 | #else |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1550 | UNREACHABLE(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1551 | #endif |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1552 | return ExternalReference(Redirect(isolate, function)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1553 | } |
| 1554 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1555 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1556 | ExternalReference ExternalReference::re_grow_stack(Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1557 | return ExternalReference( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1558 | Redirect(isolate, FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1561 | ExternalReference ExternalReference::re_case_insensitive_compare_uc16( |
| 1562 | Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1563 | return ExternalReference(Redirect( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1564 | isolate, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1565 | FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16))); |
| 1566 | } |
| 1567 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1568 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1569 | ExternalReference ExternalReference::re_word_character_map() { |
| 1570 | return ExternalReference( |
| 1571 | NativeRegExpMacroAssembler::word_character_map_address()); |
| 1572 | } |
| 1573 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1574 | ExternalReference ExternalReference::address_of_static_offsets_vector( |
| 1575 | Isolate* isolate) { |
| 1576 | return ExternalReference( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1577 | reinterpret_cast<Address>(isolate->jsregexp_static_offsets_vector())); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1580 | ExternalReference ExternalReference::address_of_regexp_stack_memory_address( |
| 1581 | Isolate* isolate) { |
| 1582 | return ExternalReference( |
| 1583 | isolate->regexp_stack()->memory_address()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1586 | ExternalReference ExternalReference::address_of_regexp_stack_memory_size( |
| 1587 | Isolate* isolate) { |
| 1588 | return ExternalReference(isolate->regexp_stack()->memory_size_address()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1591 | #endif // V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1592 | |
| 1593 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1594 | ExternalReference ExternalReference::math_log_double_function( |
| 1595 | Isolate* isolate) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1596 | typedef double (*d2d)(double x); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1597 | return ExternalReference(Redirect(isolate, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1598 | FUNCTION_ADDR(static_cast<d2d>(std::log)), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1599 | BUILTIN_FP_CALL)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1603 | ExternalReference ExternalReference::math_exp_constants(int constant_index) { |
| 1604 | DCHECK(math_exp_data_initialized); |
| 1605 | return ExternalReference( |
| 1606 | reinterpret_cast<void*>(math_exp_constants_array + constant_index)); |
| 1607 | } |
| 1608 | |
| 1609 | |
| 1610 | ExternalReference ExternalReference::math_exp_log_table() { |
| 1611 | DCHECK(math_exp_data_initialized); |
| 1612 | return ExternalReference(reinterpret_cast<void*>(math_exp_log_table_array)); |
| 1613 | } |
| 1614 | |
| 1615 | |
| 1616 | ExternalReference ExternalReference::page_flags(Page* page) { |
| 1617 | return ExternalReference(reinterpret_cast<Address>(page) + |
| 1618 | MemoryChunk::kFlagsOffset); |
| 1619 | } |
| 1620 | |
| 1621 | |
| 1622 | ExternalReference ExternalReference::ForDeoptEntry(Address entry) { |
| 1623 | return ExternalReference(entry); |
| 1624 | } |
| 1625 | |
| 1626 | |
| 1627 | ExternalReference ExternalReference::cpu_features() { |
| 1628 | DCHECK(CpuFeatures::initialized_); |
| 1629 | return ExternalReference(&CpuFeatures::supported_); |
| 1630 | } |
| 1631 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1632 | ExternalReference ExternalReference::is_tail_call_elimination_enabled_address( |
| 1633 | Isolate* isolate) { |
| 1634 | return ExternalReference(isolate->is_tail_call_elimination_enabled_address()); |
| 1635 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1636 | |
| 1637 | ExternalReference ExternalReference::debug_is_active_address( |
| 1638 | Isolate* isolate) { |
| 1639 | return ExternalReference(isolate->debug()->is_active_address()); |
| 1640 | } |
| 1641 | |
| 1642 | |
| 1643 | ExternalReference ExternalReference::debug_after_break_target_address( |
| 1644 | Isolate* isolate) { |
| 1645 | return ExternalReference(isolate->debug()->after_break_target_address()); |
| 1646 | } |
| 1647 | |
| 1648 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1649 | ExternalReference ExternalReference::virtual_handler_register( |
| 1650 | Isolate* isolate) { |
| 1651 | return ExternalReference(isolate->virtual_handler_register_address()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1655 | ExternalReference ExternalReference::virtual_slot_register(Isolate* isolate) { |
| 1656 | return ExternalReference(isolate->virtual_slot_register_address()); |
| 1657 | } |
| 1658 | |
| 1659 | |
| 1660 | ExternalReference ExternalReference::runtime_function_table_address( |
| 1661 | Isolate* isolate) { |
| 1662 | return ExternalReference( |
| 1663 | const_cast<Runtime::Function*>(Runtime::RuntimeFunctionTable(isolate))); |
| 1664 | } |
| 1665 | |
| 1666 | |
| 1667 | double power_helper(Isolate* isolate, double x, double y) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1668 | int y_int = static_cast<int>(y); |
| 1669 | if (y == y_int) { |
| 1670 | return power_double_int(x, y_int); // Returns 1 if exponent is 0. |
| 1671 | } |
| 1672 | if (y == 0.5) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1673 | lazily_initialize_fast_sqrt(isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1674 | return (std::isinf(x)) ? V8_INFINITY |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1675 | : fast_sqrt(x + 0.0, isolate); // Convert -0 to +0. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1676 | } |
| 1677 | if (y == -0.5) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1678 | lazily_initialize_fast_sqrt(isolate); |
| 1679 | return (std::isinf(x)) ? 0 : 1.0 / fast_sqrt(x + 0.0, |
| 1680 | isolate); // Convert -0 to +0. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1681 | } |
| 1682 | return power_double_double(x, y); |
| 1683 | } |
| 1684 | |
| 1685 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1686 | // Helper function to compute x^y, where y is known to be an |
| 1687 | // integer. Uses binary decomposition to limit the number of |
| 1688 | // multiplications; see the discussion in "Hacker's Delight" by Henry |
| 1689 | // S. Warren, Jr., figure 11-6, page 213. |
| 1690 | double power_double_int(double x, int y) { |
| 1691 | double m = (y < 0) ? 1 / x : x; |
| 1692 | unsigned n = (y < 0) ? -y : y; |
| 1693 | double p = 1; |
| 1694 | while (n != 0) { |
| 1695 | if ((n & 1) != 0) p *= m; |
| 1696 | m *= m; |
| 1697 | if ((n & 2) != 0) p *= m; |
| 1698 | m *= m; |
| 1699 | n >>= 2; |
| 1700 | } |
| 1701 | return p; |
| 1702 | } |
| 1703 | |
| 1704 | |
| 1705 | double power_double_double(double x, double y) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1706 | // The checks for special cases can be dropped in ia32 because it has already |
| 1707 | // been done in generated code before bailing out here. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1708 | if (std::isnan(y) || ((x == 1 || x == -1) && std::isinf(y))) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1709 | return std::numeric_limits<double>::quiet_NaN(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1710 | } |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1711 | return Pow(x, y); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1715 | ExternalReference ExternalReference::power_double_double_function( |
| 1716 | Isolate* isolate) { |
| 1717 | return ExternalReference(Redirect(isolate, |
| 1718 | FUNCTION_ADDR(power_double_double), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1719 | BUILTIN_FP_FP_CALL)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1723 | ExternalReference ExternalReference::power_double_int_function( |
| 1724 | Isolate* isolate) { |
| 1725 | return ExternalReference(Redirect(isolate, |
| 1726 | FUNCTION_ADDR(power_double_int), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1727 | BUILTIN_FP_INT_CALL)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1731 | ExternalReference ExternalReference::mod_two_doubles_operation( |
| 1732 | Isolate* isolate) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1733 | return ExternalReference(Redirect(isolate, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1734 | FUNCTION_ADDR(modulo), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1735 | BUILTIN_FP_FP_CALL)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1739 | ExternalReference ExternalReference::debug_step_in_enabled_address( |
| 1740 | Isolate* isolate) { |
| 1741 | return ExternalReference(isolate->debug()->step_in_enabled_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1745 | ExternalReference ExternalReference::fixed_typed_array_base_data_offset() { |
| 1746 | return ExternalReference(reinterpret_cast<void*>( |
| 1747 | FixedTypedArrayBase::kDataOffset - kHeapObjectTag)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1748 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1749 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1750 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1751 | bool operator==(ExternalReference lhs, ExternalReference rhs) { |
| 1752 | return lhs.address() == rhs.address(); |
| 1753 | } |
| 1754 | |
| 1755 | |
| 1756 | bool operator!=(ExternalReference lhs, ExternalReference rhs) { |
| 1757 | return !(lhs == rhs); |
| 1758 | } |
| 1759 | |
| 1760 | |
| 1761 | size_t hash_value(ExternalReference reference) { |
| 1762 | return base::hash<Address>()(reference.address()); |
| 1763 | } |
| 1764 | |
| 1765 | |
| 1766 | std::ostream& operator<<(std::ostream& os, ExternalReference reference) { |
| 1767 | os << static_cast<const void*>(reference.address()); |
| 1768 | const Runtime::Function* fn = Runtime::FunctionForEntry(reference.address()); |
| 1769 | if (fn) os << "<" << fn->name << ".entry>"; |
| 1770 | return os; |
| 1771 | } |
| 1772 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1773 | void AssemblerPositionsRecorder::RecordPosition(int pos) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1774 | DCHECK(pos != RelocInfo::kNoPosition); |
| 1775 | DCHECK(pos >= 0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1776 | state_.current_position = pos; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1777 | LOG_CODE_EVENT(assembler_->isolate(), |
| 1778 | CodeLinePosInfoAddPositionEvent(jit_handler_data_, |
| 1779 | assembler_->pc_offset(), |
| 1780 | pos)); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1781 | } |
| 1782 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1783 | void AssemblerPositionsRecorder::RecordStatementPosition(int pos) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1784 | DCHECK(pos != RelocInfo::kNoPosition); |
| 1785 | DCHECK(pos >= 0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1786 | state_.current_statement_position = pos; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1787 | LOG_CODE_EVENT(assembler_->isolate(), |
| 1788 | CodeLinePosInfoAddStatementPositionEvent( |
| 1789 | jit_handler_data_, |
| 1790 | assembler_->pc_offset(), |
| 1791 | pos)); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1792 | } |
| 1793 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1794 | bool AssemblerPositionsRecorder::WriteRecordedPositions() { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1795 | bool written = false; |
| 1796 | |
| 1797 | // Write the statement position if it is different from what was written last |
| 1798 | // time. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1799 | if (state_.current_statement_position != state_.written_statement_position) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1800 | EnsureSpace ensure_space(assembler_); |
| 1801 | assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1802 | state_.current_statement_position); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1803 | state_.written_position = state_.current_statement_position; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1804 | state_.written_statement_position = state_.current_statement_position; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1805 | written = true; |
| 1806 | } |
| 1807 | |
| 1808 | // Write the position if it is different from what was written last time and |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1809 | // also different from the statement position that was just written. |
| 1810 | if (state_.current_position != state_.written_position) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1811 | EnsureSpace ensure_space(assembler_); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1812 | assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position); |
| 1813 | state_.written_position = state_.current_position; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1814 | written = true; |
| 1815 | } |
| 1816 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1817 | // Return whether something was written. |
| 1818 | return written; |
| 1819 | } |
| 1820 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1821 | |
| 1822 | ConstantPoolBuilder::ConstantPoolBuilder(int ptr_reach_bits, |
| 1823 | int double_reach_bits) { |
| 1824 | info_[ConstantPoolEntry::INTPTR].entries.reserve(64); |
| 1825 | info_[ConstantPoolEntry::INTPTR].regular_reach_bits = ptr_reach_bits; |
| 1826 | info_[ConstantPoolEntry::DOUBLE].regular_reach_bits = double_reach_bits; |
| 1827 | } |
| 1828 | |
| 1829 | |
| 1830 | ConstantPoolEntry::Access ConstantPoolBuilder::NextAccess( |
| 1831 | ConstantPoolEntry::Type type) const { |
| 1832 | const PerTypeEntryInfo& info = info_[type]; |
| 1833 | |
| 1834 | if (info.overflow()) return ConstantPoolEntry::OVERFLOWED; |
| 1835 | |
| 1836 | int dbl_count = info_[ConstantPoolEntry::DOUBLE].regular_count; |
| 1837 | int dbl_offset = dbl_count * kDoubleSize; |
| 1838 | int ptr_count = info_[ConstantPoolEntry::INTPTR].regular_count; |
| 1839 | int ptr_offset = ptr_count * kPointerSize + dbl_offset; |
| 1840 | |
| 1841 | if (type == ConstantPoolEntry::DOUBLE) { |
| 1842 | // Double overflow detection must take into account the reach for both types |
| 1843 | int ptr_reach_bits = info_[ConstantPoolEntry::INTPTR].regular_reach_bits; |
| 1844 | if (!is_uintn(dbl_offset, info.regular_reach_bits) || |
| 1845 | (ptr_count > 0 && |
| 1846 | !is_uintn(ptr_offset + kDoubleSize - kPointerSize, ptr_reach_bits))) { |
| 1847 | return ConstantPoolEntry::OVERFLOWED; |
| 1848 | } |
| 1849 | } else { |
| 1850 | DCHECK(type == ConstantPoolEntry::INTPTR); |
| 1851 | if (!is_uintn(ptr_offset, info.regular_reach_bits)) { |
| 1852 | return ConstantPoolEntry::OVERFLOWED; |
| 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | return ConstantPoolEntry::REGULAR; |
| 1857 | } |
| 1858 | |
| 1859 | |
| 1860 | ConstantPoolEntry::Access ConstantPoolBuilder::AddEntry( |
| 1861 | ConstantPoolEntry& entry, ConstantPoolEntry::Type type) { |
| 1862 | DCHECK(!emitted_label_.is_bound()); |
| 1863 | PerTypeEntryInfo& info = info_[type]; |
| 1864 | const int entry_size = ConstantPoolEntry::size(type); |
| 1865 | bool merged = false; |
| 1866 | |
| 1867 | if (entry.sharing_ok()) { |
| 1868 | // Try to merge entries |
| 1869 | std::vector<ConstantPoolEntry>::iterator it = info.shared_entries.begin(); |
| 1870 | int end = static_cast<int>(info.shared_entries.size()); |
| 1871 | for (int i = 0; i < end; i++, it++) { |
| 1872 | if ((entry_size == kPointerSize) ? entry.value() == it->value() |
| 1873 | : entry.value64() == it->value64()) { |
| 1874 | // Merge with found entry. |
| 1875 | entry.set_merged_index(i); |
| 1876 | merged = true; |
| 1877 | break; |
| 1878 | } |
| 1879 | } |
| 1880 | } |
| 1881 | |
| 1882 | // By definition, merged entries have regular access. |
| 1883 | DCHECK(!merged || entry.merged_index() < info.regular_count); |
| 1884 | ConstantPoolEntry::Access access = |
| 1885 | (merged ? ConstantPoolEntry::REGULAR : NextAccess(type)); |
| 1886 | |
| 1887 | // Enforce an upper bound on search time by limiting the search to |
| 1888 | // unique sharable entries which fit in the regular section. |
| 1889 | if (entry.sharing_ok() && !merged && access == ConstantPoolEntry::REGULAR) { |
| 1890 | info.shared_entries.push_back(entry); |
| 1891 | } else { |
| 1892 | info.entries.push_back(entry); |
| 1893 | } |
| 1894 | |
| 1895 | // We're done if we found a match or have already triggered the |
| 1896 | // overflow state. |
| 1897 | if (merged || info.overflow()) return access; |
| 1898 | |
| 1899 | if (access == ConstantPoolEntry::REGULAR) { |
| 1900 | info.regular_count++; |
| 1901 | } else { |
| 1902 | info.overflow_start = static_cast<int>(info.entries.size()) - 1; |
| 1903 | } |
| 1904 | |
| 1905 | return access; |
| 1906 | } |
| 1907 | |
| 1908 | |
| 1909 | void ConstantPoolBuilder::EmitSharedEntries(Assembler* assm, |
| 1910 | ConstantPoolEntry::Type type) { |
| 1911 | PerTypeEntryInfo& info = info_[type]; |
| 1912 | std::vector<ConstantPoolEntry>& shared_entries = info.shared_entries; |
| 1913 | const int entry_size = ConstantPoolEntry::size(type); |
| 1914 | int base = emitted_label_.pos(); |
| 1915 | DCHECK(base > 0); |
| 1916 | int shared_end = static_cast<int>(shared_entries.size()); |
| 1917 | std::vector<ConstantPoolEntry>::iterator shared_it = shared_entries.begin(); |
| 1918 | for (int i = 0; i < shared_end; i++, shared_it++) { |
| 1919 | int offset = assm->pc_offset() - base; |
| 1920 | shared_it->set_offset(offset); // Save offset for merged entries. |
| 1921 | if (entry_size == kPointerSize) { |
| 1922 | assm->dp(shared_it->value()); |
| 1923 | } else { |
| 1924 | assm->dq(shared_it->value64()); |
| 1925 | } |
| 1926 | DCHECK(is_uintn(offset, info.regular_reach_bits)); |
| 1927 | |
| 1928 | // Patch load sequence with correct offset. |
| 1929 | assm->PatchConstantPoolAccessInstruction(shared_it->position(), offset, |
| 1930 | ConstantPoolEntry::REGULAR, type); |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | |
| 1935 | void ConstantPoolBuilder::EmitGroup(Assembler* assm, |
| 1936 | ConstantPoolEntry::Access access, |
| 1937 | ConstantPoolEntry::Type type) { |
| 1938 | PerTypeEntryInfo& info = info_[type]; |
| 1939 | const bool overflow = info.overflow(); |
| 1940 | std::vector<ConstantPoolEntry>& entries = info.entries; |
| 1941 | std::vector<ConstantPoolEntry>& shared_entries = info.shared_entries; |
| 1942 | const int entry_size = ConstantPoolEntry::size(type); |
| 1943 | int base = emitted_label_.pos(); |
| 1944 | DCHECK(base > 0); |
| 1945 | int begin; |
| 1946 | int end; |
| 1947 | |
| 1948 | if (access == ConstantPoolEntry::REGULAR) { |
| 1949 | // Emit any shared entries first |
| 1950 | EmitSharedEntries(assm, type); |
| 1951 | } |
| 1952 | |
| 1953 | if (access == ConstantPoolEntry::REGULAR) { |
| 1954 | begin = 0; |
| 1955 | end = overflow ? info.overflow_start : static_cast<int>(entries.size()); |
| 1956 | } else { |
| 1957 | DCHECK(access == ConstantPoolEntry::OVERFLOWED); |
| 1958 | if (!overflow) return; |
| 1959 | begin = info.overflow_start; |
| 1960 | end = static_cast<int>(entries.size()); |
| 1961 | } |
| 1962 | |
| 1963 | std::vector<ConstantPoolEntry>::iterator it = entries.begin(); |
| 1964 | if (begin > 0) std::advance(it, begin); |
| 1965 | for (int i = begin; i < end; i++, it++) { |
| 1966 | // Update constant pool if necessary and get the entry's offset. |
| 1967 | int offset; |
| 1968 | ConstantPoolEntry::Access entry_access; |
| 1969 | if (!it->is_merged()) { |
| 1970 | // Emit new entry |
| 1971 | offset = assm->pc_offset() - base; |
| 1972 | entry_access = access; |
| 1973 | if (entry_size == kPointerSize) { |
| 1974 | assm->dp(it->value()); |
| 1975 | } else { |
| 1976 | assm->dq(it->value64()); |
| 1977 | } |
| 1978 | } else { |
| 1979 | // Retrieve offset from shared entry. |
| 1980 | offset = shared_entries[it->merged_index()].offset(); |
| 1981 | entry_access = ConstantPoolEntry::REGULAR; |
| 1982 | } |
| 1983 | |
| 1984 | DCHECK(entry_access == ConstantPoolEntry::OVERFLOWED || |
| 1985 | is_uintn(offset, info.regular_reach_bits)); |
| 1986 | |
| 1987 | // Patch load sequence with correct offset. |
| 1988 | assm->PatchConstantPoolAccessInstruction(it->position(), offset, |
| 1989 | entry_access, type); |
| 1990 | } |
| 1991 | } |
| 1992 | |
| 1993 | |
| 1994 | // Emit and return position of pool. Zero implies no constant pool. |
| 1995 | int ConstantPoolBuilder::Emit(Assembler* assm) { |
| 1996 | bool emitted = emitted_label_.is_bound(); |
| 1997 | bool empty = IsEmpty(); |
| 1998 | |
| 1999 | if (!emitted) { |
| 2000 | // Mark start of constant pool. Align if necessary. |
| 2001 | if (!empty) assm->DataAlign(kDoubleSize); |
| 2002 | assm->bind(&emitted_label_); |
| 2003 | if (!empty) { |
| 2004 | // Emit in groups based on access and type. |
| 2005 | // Emit doubles first for alignment purposes. |
| 2006 | EmitGroup(assm, ConstantPoolEntry::REGULAR, ConstantPoolEntry::DOUBLE); |
| 2007 | EmitGroup(assm, ConstantPoolEntry::REGULAR, ConstantPoolEntry::INTPTR); |
| 2008 | if (info_[ConstantPoolEntry::DOUBLE].overflow()) { |
| 2009 | assm->DataAlign(kDoubleSize); |
| 2010 | EmitGroup(assm, ConstantPoolEntry::OVERFLOWED, |
| 2011 | ConstantPoolEntry::DOUBLE); |
| 2012 | } |
| 2013 | if (info_[ConstantPoolEntry::INTPTR].overflow()) { |
| 2014 | EmitGroup(assm, ConstantPoolEntry::OVERFLOWED, |
| 2015 | ConstantPoolEntry::INTPTR); |
| 2016 | } |
| 2017 | } |
| 2018 | } |
| 2019 | |
| 2020 | return !empty ? emitted_label_.pos() : 0; |
| 2021 | } |
| 2022 | |
| 2023 | |
| 2024 | // Platform specific but identical code for all the platforms. |
| 2025 | |
| 2026 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2027 | void Assembler::RecordDeoptReason(const int reason, int raw_position) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2028 | if (FLAG_trace_deopt || isolate()->cpu_profiler()->is_profiling()) { |
| 2029 | EnsureSpace ensure_space(this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2030 | RecordRelocInfo(RelocInfo::POSITION, raw_position); |
| 2031 | RecordRelocInfo(RelocInfo::DEOPT_REASON, reason); |
| 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | |
| 2036 | void Assembler::RecordComment(const char* msg) { |
| 2037 | if (FLAG_code_comments) { |
| 2038 | EnsureSpace ensure_space(this); |
| 2039 | RecordRelocInfo(RelocInfo::COMMENT, reinterpret_cast<intptr_t>(msg)); |
| 2040 | } |
| 2041 | } |
| 2042 | |
| 2043 | |
| 2044 | void Assembler::RecordGeneratorContinuation() { |
| 2045 | EnsureSpace ensure_space(this); |
| 2046 | RecordRelocInfo(RelocInfo::GENERATOR_CONTINUATION); |
| 2047 | } |
| 2048 | |
| 2049 | |
| 2050 | void Assembler::RecordDebugBreakSlot(RelocInfo::Mode mode) { |
| 2051 | EnsureSpace ensure_space(this); |
| 2052 | DCHECK(RelocInfo::IsDebugBreakSlot(mode)); |
| 2053 | RecordRelocInfo(mode); |
| 2054 | } |
| 2055 | |
| 2056 | |
| 2057 | void Assembler::DataAlign(int m) { |
| 2058 | DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m)); |
| 2059 | while ((pc_offset() & (m - 1)) != 0) { |
| 2060 | db(0); |
| 2061 | } |
| 2062 | } |
| 2063 | } // namespace internal |
| 2064 | } // namespace v8 |