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