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