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 | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 37 | #include <cmath> |
| 38 | #include "src/api.h" |
| 39 | #include "src/base/cpu.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 40 | #include "src/base/functional.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 41 | #include "src/base/lazy-instance.h" |
| 42 | #include "src/base/platform/platform.h" |
| 43 | #include "src/builtins.h" |
| 44 | #include "src/codegen.h" |
| 45 | #include "src/counters.h" |
| 46 | #include "src/cpu-profiler.h" |
| 47 | #include "src/debug.h" |
| 48 | #include "src/deoptimizer.h" |
| 49 | #include "src/execution.h" |
| 50 | #include "src/ic/ic.h" |
| 51 | #include "src/ic/stub-cache.h" |
| 52 | #include "src/isolate-inl.h" |
| 53 | #include "src/jsregexp.h" |
| 54 | #include "src/regexp-macro-assembler.h" |
| 55 | #include "src/regexp-stack.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 56 | #include "src/runtime/runtime.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 57 | #include "src/serialize.h" |
| 58 | #include "src/token.h" |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 59 | |
| 60 | #if V8_TARGET_ARCH_IA32 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 61 | #include "src/ia32/assembler-ia32-inl.h" // NOLINT |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 62 | #elif V8_TARGET_ARCH_X64 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 63 | #include "src/x64/assembler-x64-inl.h" // NOLINT |
| 64 | #elif V8_TARGET_ARCH_ARM64 |
| 65 | #include "src/arm64/assembler-arm64-inl.h" // NOLINT |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 66 | #elif V8_TARGET_ARCH_ARM |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 67 | #include "src/arm/assembler-arm-inl.h" // NOLINT |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 68 | #elif V8_TARGET_ARCH_MIPS |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 69 | #include "src/mips/assembler-mips-inl.h" // NOLINT |
| 70 | #elif V8_TARGET_ARCH_MIPS64 |
| 71 | #include "src/mips64/assembler-mips64-inl.h" // NOLINT |
| 72 | #elif V8_TARGET_ARCH_X87 |
| 73 | #include "src/x87/assembler-x87-inl.h" // NOLINT |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 74 | #else |
| 75 | #error "Unknown architecture." |
| 76 | #endif |
| 77 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 78 | // Include native regexp-macro-assembler. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 79 | #ifndef V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 80 | #if V8_TARGET_ARCH_IA32 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 81 | #include "src/ia32/regexp-macro-assembler-ia32.h" // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 82 | #elif V8_TARGET_ARCH_X64 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 83 | #include "src/x64/regexp-macro-assembler-x64.h" // NOLINT |
| 84 | #elif V8_TARGET_ARCH_ARM64 |
| 85 | #include "src/arm64/regexp-macro-assembler-arm64.h" // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 86 | #elif V8_TARGET_ARCH_ARM |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 87 | #include "src/arm/regexp-macro-assembler-arm.h" // NOLINT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 88 | #elif V8_TARGET_ARCH_MIPS |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 89 | #include "src/mips/regexp-macro-assembler-mips.h" // NOLINT |
| 90 | #elif V8_TARGET_ARCH_MIPS64 |
| 91 | #include "src/mips64/regexp-macro-assembler-mips64.h" // NOLINT |
| 92 | #elif V8_TARGET_ARCH_X87 |
| 93 | #include "src/x87/regexp-macro-assembler-x87.h" // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 94 | #else // Unknown architecture. |
| 95 | #error "Unknown architecture." |
| 96 | #endif // Target architecture. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 97 | #endif // V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 98 | |
| 99 | namespace v8 { |
| 100 | namespace internal { |
| 101 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 102 | // ----------------------------------------------------------------------------- |
| 103 | // Common double constants. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 104 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 105 | struct DoubleConstant BASE_EMBEDDED { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 106 | double min_int; |
| 107 | double one_half; |
| 108 | double minus_one_half; |
| 109 | double negative_infinity; |
| 110 | double canonical_non_hole_nan; |
| 111 | double the_hole_nan; |
| 112 | double uint32_bias; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 115 | static DoubleConstant double_constants; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 116 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 117 | const char* const RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING"; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 118 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 119 | static bool math_exp_data_initialized = false; |
| 120 | static base::Mutex* math_exp_data_mutex = NULL; |
| 121 | static double* math_exp_constants_array = NULL; |
| 122 | static double* math_exp_log_table_array = NULL; |
| 123 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 124 | // ----------------------------------------------------------------------------- |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 125 | // Implementation of AssemblerBase |
| 126 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 127 | AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size) |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 128 | : isolate_(isolate), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 129 | jit_cookie_(0), |
| 130 | enabled_cpu_features_(0), |
| 131 | emit_debug_code_(FLAG_debug_code), |
| 132 | predictable_code_size_(false), |
| 133 | // We may use the assembler without an isolate. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 134 | serializer_enabled_(isolate && isolate->serializer_enabled()), |
| 135 | ool_constant_pool_available_(false) { |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 136 | if (FLAG_mask_constants_with_cookie && isolate != NULL) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 137 | jit_cookie_ = isolate->random_number_generator()->NextInt(); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 138 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 139 | own_buffer_ = buffer == NULL; |
| 140 | if (buffer_size == 0) buffer_size = kMinimalBufferSize; |
| 141 | DCHECK(buffer_size > 0); |
| 142 | if (own_buffer_) buffer = NewArray<byte>(buffer_size); |
| 143 | buffer_ = static_cast<byte*>(buffer); |
| 144 | buffer_size_ = buffer_size; |
| 145 | |
| 146 | pc_ = buffer_; |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | AssemblerBase::~AssemblerBase() { |
| 151 | if (own_buffer_) DeleteArray(buffer_); |
| 152 | } |
| 153 | |
| 154 | |
| 155 | // ----------------------------------------------------------------------------- |
| 156 | // Implementation of PredictableCodeSizeScope |
| 157 | |
| 158 | PredictableCodeSizeScope::PredictableCodeSizeScope(AssemblerBase* assembler, |
| 159 | int expected_size) |
| 160 | : assembler_(assembler), |
| 161 | expected_size_(expected_size), |
| 162 | start_offset_(assembler->pc_offset()), |
| 163 | old_value_(assembler->predictable_code_size()) { |
| 164 | assembler_->set_predictable_code_size(true); |
| 165 | } |
| 166 | |
| 167 | |
| 168 | PredictableCodeSizeScope::~PredictableCodeSizeScope() { |
| 169 | // TODO(svenpanne) Remove the 'if' when everything works. |
| 170 | if (expected_size_ >= 0) { |
| 171 | CHECK_EQ(expected_size_, assembler_->pc_offset() - start_offset_); |
| 172 | } |
| 173 | assembler_->set_predictable_code_size(old_value_); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | // ----------------------------------------------------------------------------- |
| 178 | // Implementation of CpuFeatureScope |
| 179 | |
| 180 | #ifdef DEBUG |
| 181 | CpuFeatureScope::CpuFeatureScope(AssemblerBase* assembler, CpuFeature f) |
| 182 | : assembler_(assembler) { |
| 183 | DCHECK(CpuFeatures::IsSupported(f)); |
| 184 | old_enabled_ = assembler_->enabled_cpu_features(); |
| 185 | uint64_t mask = static_cast<uint64_t>(1) << f; |
| 186 | // TODO(svenpanne) This special case below doesn't belong here! |
| 187 | #if V8_TARGET_ARCH_ARM |
| 188 | // ARMv7 is implied by VFP3. |
| 189 | if (f == VFP3) { |
| 190 | mask |= static_cast<uint64_t>(1) << ARMv7; |
| 191 | } |
| 192 | #endif |
| 193 | assembler_->set_enabled_cpu_features(old_enabled_ | mask); |
| 194 | } |
| 195 | |
| 196 | |
| 197 | CpuFeatureScope::~CpuFeatureScope() { |
| 198 | assembler_->set_enabled_cpu_features(old_enabled_); |
| 199 | } |
| 200 | #endif |
| 201 | |
| 202 | |
| 203 | bool CpuFeatures::initialized_ = false; |
| 204 | unsigned CpuFeatures::supported_ = 0; |
| 205 | unsigned CpuFeatures::cache_line_size_ = 0; |
| 206 | |
| 207 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 208 | // ----------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 209 | // Implementation of Label |
| 210 | |
| 211 | int Label::pos() const { |
| 212 | if (pos_ < 0) return -pos_ - 1; |
| 213 | if (pos_ > 0) return pos_ - 1; |
| 214 | UNREACHABLE(); |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | |
| 219 | // ----------------------------------------------------------------------------- |
| 220 | // Implementation of RelocInfoWriter and RelocIterator |
| 221 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 222 | // Relocation information is written backwards in memory, from high addresses |
| 223 | // towards low addresses, byte by byte. Therefore, in the encodings listed |
| 224 | // below, the first byte listed it at the highest address, and successive |
| 225 | // bytes in the record are at progressively lower addresses. |
| 226 | // |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 227 | // Encoding |
| 228 | // |
| 229 | // The most common modes are given single-byte encodings. Also, it is |
| 230 | // easy to identify the type of reloc info and skip unwanted modes in |
| 231 | // an iteration. |
| 232 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 233 | // The encoding relies on the fact that there are fewer than 14 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 234 | // different relocation modes using standard non-compact encoding. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 235 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 236 | // The first byte of a relocation record has a tag in its low 2 bits: |
| 237 | // Here are the record schemes, depending on the low tag and optional higher |
| 238 | // tags. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 239 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 240 | // Low tag: |
| 241 | // 00: embedded_object: [6-bit pc delta] 00 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 242 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 243 | // 01: code_target: [6-bit pc delta] 01 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 244 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 245 | // 10: short_data_record: [6-bit pc delta] 10 followed by |
| 246 | // [6-bit data delta] [2-bit data type tag] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 247 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 248 | // 11: long_record [2-bit high tag][4 bit middle_tag] 11 |
| 249 | // followed by variable data depending on type. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 250 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 251 | // 2-bit data type tags, used in short_data_record and data_jump long_record: |
| 252 | // code_target_with_id: 00 |
| 253 | // position: 01 |
| 254 | // statement_position: 10 |
| 255 | // comment: 11 (not used in short_data_record) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 256 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 257 | // Long record format: |
| 258 | // 4-bit middle_tag: |
| 259 | // 0000 - 1100 : Short record for RelocInfo::Mode middle_tag + 2 |
| 260 | // (The middle_tag encodes rmode - RelocInfo::LAST_COMPACT_ENUM, |
| 261 | // and is between 0000 and 1100) |
| 262 | // The format is: |
| 263 | // 00 [4 bit middle_tag] 11 followed by |
| 264 | // 00 [6 bit pc delta] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 265 | // |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 266 | // 1101: constant or veneer pool. Used only on ARM and ARM64 for now. |
| 267 | // The format is: [2-bit sub-type] 1101 11 |
| 268 | // signed int (size of the pool). |
| 269 | // The 2-bit sub-types are: |
| 270 | // 00: constant pool |
| 271 | // 01: veneer pool |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 272 | // 1110: long_data_record |
| 273 | // The format is: [2-bit data_type_tag] 1110 11 |
| 274 | // signed intptr_t, lowest byte written first |
| 275 | // (except data_type code_target_with_id, which |
| 276 | // is followed by a signed int, not intptr_t.) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 277 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 278 | // 1111: long_pc_jump |
| 279 | // The format is: |
| 280 | // pc-jump: 00 1111 11, |
| 281 | // 00 [6 bits pc delta] |
| 282 | // or |
| 283 | // pc-jump (variable length): |
| 284 | // 01 1111 11, |
| 285 | // [7 bits data] 0 |
| 286 | // ... |
| 287 | // [7 bits data] 1 |
| 288 | // (Bits 6..31 of pc delta, with leading zeroes |
| 289 | // dropped, and last non-zero chunk tagged with 1.) |
| 290 | |
| 291 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 292 | #ifdef DEBUG |
| 293 | const int kMaxStandardNonCompactModes = 14; |
| 294 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 295 | |
| 296 | const int kTagBits = 2; |
| 297 | const int kTagMask = (1 << kTagBits) - 1; |
| 298 | const int kExtraTagBits = 4; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 299 | const int kLocatableTypeTagBits = 2; |
| 300 | const int kSmallDataBits = kBitsPerByte - kLocatableTypeTagBits; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 301 | |
| 302 | const int kEmbeddedObjectTag = 0; |
| 303 | const int kCodeTargetTag = 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 304 | const int kLocatableTag = 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 305 | const int kDefaultTag = 3; |
| 306 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 307 | const int kPCJumpExtraTag = (1 << kExtraTagBits) - 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 308 | |
| 309 | const int kSmallPCDeltaBits = kBitsPerByte - kTagBits; |
| 310 | const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 311 | const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 312 | |
| 313 | const int kVariableLengthPCJumpTopTag = 1; |
| 314 | const int kChunkBits = 7; |
| 315 | const int kChunkMask = (1 << kChunkBits) - 1; |
| 316 | const int kLastChunkTagBits = 1; |
| 317 | const int kLastChunkTagMask = 1; |
| 318 | const int kLastChunkTag = 1; |
| 319 | |
| 320 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 321 | const int kDataJumpExtraTag = kPCJumpExtraTag - 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 322 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 323 | const int kCodeWithIdTag = 0; |
| 324 | const int kNonstatementPositionTag = 1; |
| 325 | const int kStatementPositionTag = 2; |
| 326 | const int kCommentTag = 3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 327 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 328 | const int kPoolExtraTag = kPCJumpExtraTag - 2; |
| 329 | const int kConstPoolTag = 0; |
| 330 | const int kVeneerPoolTag = 1; |
| 331 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 332 | |
| 333 | uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) { |
| 334 | // Return if the pc_delta can fit in kSmallPCDeltaBits bits. |
| 335 | // Otherwise write a variable length PC jump for the bits that do |
| 336 | // not fit in the kSmallPCDeltaBits bits. |
| 337 | if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 338 | WriteExtraTag(kPCJumpExtraTag, kVariableLengthPCJumpTopTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 339 | uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 340 | DCHECK(pc_jump > 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 341 | // Write kChunkBits size chunks of the pc_jump. |
| 342 | for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) { |
| 343 | byte b = pc_jump & kChunkMask; |
| 344 | *--pos_ = b << kLastChunkTagBits; |
| 345 | } |
| 346 | // Tag the last chunk so it can be identified. |
| 347 | *pos_ = *pos_ | kLastChunkTag; |
| 348 | // Return the remaining kSmallPCDeltaBits of the pc_delta. |
| 349 | return pc_delta & kSmallPCDeltaMask; |
| 350 | } |
| 351 | |
| 352 | |
| 353 | void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) { |
| 354 | // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump. |
| 355 | pc_delta = WriteVariableLengthPCJump(pc_delta); |
| 356 | *--pos_ = pc_delta << kTagBits | tag; |
| 357 | } |
| 358 | |
| 359 | |
| 360 | void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 361 | *--pos_ = static_cast<byte>(data_delta << kLocatableTypeTagBits | tag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | |
| 365 | void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 366 | *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) | |
| 367 | extra_tag << kTagBits | |
| 368 | kDefaultTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | |
| 372 | void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) { |
| 373 | // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump. |
| 374 | pc_delta = WriteVariableLengthPCJump(pc_delta); |
| 375 | WriteExtraTag(extra_tag, 0); |
| 376 | *--pos_ = pc_delta; |
| 377 | } |
| 378 | |
| 379 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 380 | void RelocInfoWriter::WriteExtraTaggedIntData(int data_delta, int top_tag) { |
| 381 | WriteExtraTag(kDataJumpExtraTag, top_tag); |
| 382 | for (int i = 0; i < kIntSize; i++) { |
| 383 | *--pos_ = static_cast<byte>(data_delta); |
| 384 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
| 385 | data_delta = data_delta >> kBitsPerByte; |
| 386 | } |
| 387 | } |
| 388 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 389 | |
| 390 | void RelocInfoWriter::WriteExtraTaggedPoolData(int data, int pool_type) { |
| 391 | WriteExtraTag(kPoolExtraTag, pool_type); |
| 392 | for (int i = 0; i < kIntSize; i++) { |
| 393 | *--pos_ = static_cast<byte>(data); |
| 394 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
| 395 | data = data >> kBitsPerByte; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 400 | void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 401 | WriteExtraTag(kDataJumpExtraTag, top_tag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 402 | for (int i = 0; i < kIntptrSize; i++) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 403 | *--pos_ = static_cast<byte>(data_delta); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 404 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 405 | data_delta = data_delta >> kBitsPerByte; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | |
| 410 | void RelocInfoWriter::Write(const RelocInfo* rinfo) { |
| 411 | #ifdef DEBUG |
| 412 | byte* begin_pos = pos_; |
| 413 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 414 | DCHECK(rinfo->rmode() < RelocInfo::NUMBER_OF_MODES); |
| 415 | DCHECK(rinfo->pc() - last_pc_ >= 0); |
| 416 | DCHECK(RelocInfo::LAST_STANDARD_NONCOMPACT_ENUM - RelocInfo::LAST_COMPACT_ENUM |
| 417 | <= kMaxStandardNonCompactModes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 418 | // Use unsigned delta-encoding for pc. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 419 | uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 420 | RelocInfo::Mode rmode = rinfo->rmode(); |
| 421 | |
| 422 | // The two most common modes are given small tags, and usually fit in a byte. |
| 423 | if (rmode == RelocInfo::EMBEDDED_OBJECT) { |
| 424 | WriteTaggedPC(pc_delta, kEmbeddedObjectTag); |
| 425 | } else if (rmode == RelocInfo::CODE_TARGET) { |
| 426 | WriteTaggedPC(pc_delta, kCodeTargetTag); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 427 | DCHECK(begin_pos - pos_ <= RelocInfo::kMaxCallSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 428 | } else if (rmode == RelocInfo::CODE_TARGET_WITH_ID) { |
| 429 | // Use signed delta-encoding for id. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 430 | DCHECK(static_cast<int>(rinfo->data()) == rinfo->data()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 431 | int id_delta = static_cast<int>(rinfo->data()) - last_id_; |
| 432 | // Check if delta is small enough to fit in a tagged byte. |
| 433 | if (is_intn(id_delta, kSmallDataBits)) { |
| 434 | WriteTaggedPC(pc_delta, kLocatableTag); |
| 435 | WriteTaggedData(id_delta, kCodeWithIdTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 436 | } else { |
| 437 | // Otherwise, use costly encoding. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 438 | WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag); |
| 439 | WriteExtraTaggedIntData(id_delta, kCodeWithIdTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 440 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 441 | last_id_ = static_cast<int>(rinfo->data()); |
| 442 | } else if (RelocInfo::IsPosition(rmode)) { |
| 443 | // Use signed delta-encoding for position. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 444 | DCHECK(static_cast<int>(rinfo->data()) == rinfo->data()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 445 | int pos_delta = static_cast<int>(rinfo->data()) - last_position_; |
| 446 | int pos_type_tag = (rmode == RelocInfo::POSITION) ? kNonstatementPositionTag |
| 447 | : kStatementPositionTag; |
| 448 | // Check if delta is small enough to fit in a tagged byte. |
| 449 | if (is_intn(pos_delta, kSmallDataBits)) { |
| 450 | WriteTaggedPC(pc_delta, kLocatableTag); |
| 451 | WriteTaggedData(pos_delta, pos_type_tag); |
| 452 | } else { |
| 453 | // Otherwise, use costly encoding. |
| 454 | WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag); |
| 455 | WriteExtraTaggedIntData(pos_delta, pos_type_tag); |
| 456 | } |
| 457 | last_position_ = static_cast<int>(rinfo->data()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 458 | } else if (RelocInfo::IsComment(rmode)) { |
| 459 | // Comments are normally not generated, so we use the costly encoding. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 460 | WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag); |
| 461 | WriteExtraTaggedData(rinfo->data(), kCommentTag); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 462 | DCHECK(begin_pos - pos_ >= RelocInfo::kMinRelocCommentSize); |
| 463 | } else if (RelocInfo::IsConstPool(rmode) || RelocInfo::IsVeneerPool(rmode)) { |
| 464 | WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag); |
| 465 | WriteExtraTaggedPoolData(static_cast<int>(rinfo->data()), |
| 466 | RelocInfo::IsConstPool(rmode) ? kConstPoolTag |
| 467 | : kVeneerPoolTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 468 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 469 | DCHECK(rmode > RelocInfo::LAST_COMPACT_ENUM); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 470 | int saved_mode = rmode - RelocInfo::LAST_COMPACT_ENUM; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 471 | // For all other modes we simply use the mode as the extra tag. |
| 472 | // None of these modes need a data component. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 473 | DCHECK(saved_mode < kPCJumpExtraTag && saved_mode < kDataJumpExtraTag); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 474 | WriteExtraTaggedPC(pc_delta, saved_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 475 | } |
| 476 | last_pc_ = rinfo->pc(); |
| 477 | #ifdef DEBUG |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 478 | DCHECK(begin_pos - pos_ <= kMaxSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 479 | #endif |
| 480 | } |
| 481 | |
| 482 | |
| 483 | inline int RelocIterator::AdvanceGetTag() { |
| 484 | return *--pos_ & kTagMask; |
| 485 | } |
| 486 | |
| 487 | |
| 488 | inline int RelocIterator::GetExtraTag() { |
| 489 | return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1); |
| 490 | } |
| 491 | |
| 492 | |
| 493 | inline int RelocIterator::GetTopTag() { |
| 494 | return *pos_ >> (kTagBits + kExtraTagBits); |
| 495 | } |
| 496 | |
| 497 | |
| 498 | inline void RelocIterator::ReadTaggedPC() { |
| 499 | rinfo_.pc_ += *pos_ >> kTagBits; |
| 500 | } |
| 501 | |
| 502 | |
| 503 | inline void RelocIterator::AdvanceReadPC() { |
| 504 | rinfo_.pc_ += *--pos_; |
| 505 | } |
| 506 | |
| 507 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 508 | void RelocIterator::AdvanceReadId() { |
| 509 | int x = 0; |
| 510 | for (int i = 0; i < kIntSize; i++) { |
| 511 | x |= static_cast<int>(*--pos_) << i * kBitsPerByte; |
| 512 | } |
| 513 | last_id_ += x; |
| 514 | rinfo_.data_ = last_id_; |
| 515 | } |
| 516 | |
| 517 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 518 | void RelocIterator::AdvanceReadPoolData() { |
| 519 | int x = 0; |
| 520 | for (int i = 0; i < kIntSize; i++) { |
| 521 | x |= static_cast<int>(*--pos_) << i * kBitsPerByte; |
| 522 | } |
| 523 | rinfo_.data_ = x; |
| 524 | } |
| 525 | |
| 526 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 527 | void RelocIterator::AdvanceReadPosition() { |
| 528 | int x = 0; |
| 529 | for (int i = 0; i < kIntSize; i++) { |
| 530 | x |= static_cast<int>(*--pos_) << i * kBitsPerByte; |
| 531 | } |
| 532 | last_position_ += x; |
| 533 | rinfo_.data_ = last_position_; |
| 534 | } |
| 535 | |
| 536 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 537 | void RelocIterator::AdvanceReadData() { |
| 538 | intptr_t x = 0; |
| 539 | for (int i = 0; i < kIntptrSize; i++) { |
| 540 | x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte; |
| 541 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 542 | rinfo_.data_ = x; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | |
| 546 | void RelocIterator::AdvanceReadVariableLengthPCJump() { |
| 547 | // Read the 32-kSmallPCDeltaBits most significant bits of the |
| 548 | // pc jump in kChunkBits bit chunks and shift them into place. |
| 549 | // Stop when the last chunk is encountered. |
| 550 | uint32_t pc_jump = 0; |
| 551 | for (int i = 0; i < kIntSize; i++) { |
| 552 | byte pc_jump_part = *--pos_; |
| 553 | pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits; |
| 554 | if ((pc_jump_part & kLastChunkTagMask) == 1) break; |
| 555 | } |
| 556 | // The least significant kSmallPCDeltaBits bits will be added |
| 557 | // later. |
| 558 | rinfo_.pc_ += pc_jump << kSmallPCDeltaBits; |
| 559 | } |
| 560 | |
| 561 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 562 | inline int RelocIterator::GetLocatableTypeTag() { |
| 563 | return *pos_ & ((1 << kLocatableTypeTagBits) - 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 567 | inline void RelocIterator::ReadTaggedId() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 568 | int8_t signed_b = *pos_; |
| 569 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 570 | last_id_ += signed_b >> kLocatableTypeTagBits; |
| 571 | rinfo_.data_ = last_id_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 575 | inline void RelocIterator::ReadTaggedPosition() { |
| 576 | int8_t signed_b = *pos_; |
| 577 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
| 578 | last_position_ += signed_b >> kLocatableTypeTagBits; |
| 579 | rinfo_.data_ = last_position_; |
| 580 | } |
| 581 | |
| 582 | |
| 583 | static inline RelocInfo::Mode GetPositionModeFromTag(int tag) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 584 | DCHECK(tag == kNonstatementPositionTag || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 585 | tag == kStatementPositionTag); |
| 586 | return (tag == kNonstatementPositionTag) ? |
| 587 | RelocInfo::POSITION : |
| 588 | RelocInfo::STATEMENT_POSITION; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | |
| 592 | void RelocIterator::next() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 593 | DCHECK(!done()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 594 | // Basically, do the opposite of RelocInfoWriter::Write. |
| 595 | // Reading of data is as far as possible avoided for unwanted modes, |
| 596 | // but we must always update the pc. |
| 597 | // |
| 598 | // We exit this loop by returning when we find a mode we want. |
| 599 | while (pos_ > end_) { |
| 600 | int tag = AdvanceGetTag(); |
| 601 | if (tag == kEmbeddedObjectTag) { |
| 602 | ReadTaggedPC(); |
| 603 | if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return; |
| 604 | } else if (tag == kCodeTargetTag) { |
| 605 | ReadTaggedPC(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 606 | if (SetMode(RelocInfo::CODE_TARGET)) return; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 607 | } else if (tag == kLocatableTag) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 608 | ReadTaggedPC(); |
| 609 | Advance(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 610 | int locatable_tag = GetLocatableTypeTag(); |
| 611 | if (locatable_tag == kCodeWithIdTag) { |
| 612 | if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) { |
| 613 | ReadTaggedId(); |
| 614 | return; |
| 615 | } |
| 616 | } else { |
| 617 | // Compact encoding is never used for comments, |
| 618 | // so it must be a position. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 619 | DCHECK(locatable_tag == kNonstatementPositionTag || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 620 | locatable_tag == kStatementPositionTag); |
| 621 | if (mode_mask_ & RelocInfo::kPositionMask) { |
| 622 | ReadTaggedPosition(); |
| 623 | if (SetMode(GetPositionModeFromTag(locatable_tag))) return; |
| 624 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 625 | } |
| 626 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 627 | DCHECK(tag == kDefaultTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 628 | int extra_tag = GetExtraTag(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 629 | if (extra_tag == kPCJumpExtraTag) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 630 | if (GetTopTag() == kVariableLengthPCJumpTopTag) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 631 | AdvanceReadVariableLengthPCJump(); |
| 632 | } else { |
| 633 | AdvanceReadPC(); |
| 634 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 635 | } else if (extra_tag == kDataJumpExtraTag) { |
| 636 | int locatable_tag = GetTopTag(); |
| 637 | if (locatable_tag == kCodeWithIdTag) { |
| 638 | if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) { |
| 639 | AdvanceReadId(); |
| 640 | return; |
| 641 | } |
| 642 | Advance(kIntSize); |
| 643 | } else if (locatable_tag != kCommentTag) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 644 | DCHECK(locatable_tag == kNonstatementPositionTag || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 645 | locatable_tag == kStatementPositionTag); |
| 646 | if (mode_mask_ & RelocInfo::kPositionMask) { |
| 647 | AdvanceReadPosition(); |
| 648 | if (SetMode(GetPositionModeFromTag(locatable_tag))) return; |
| 649 | } else { |
| 650 | Advance(kIntSize); |
| 651 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 652 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 653 | DCHECK(locatable_tag == kCommentTag); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 654 | if (SetMode(RelocInfo::COMMENT)) { |
| 655 | AdvanceReadData(); |
| 656 | return; |
| 657 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 658 | Advance(kIntptrSize); |
| 659 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 660 | } else if (extra_tag == kPoolExtraTag) { |
| 661 | int pool_type = GetTopTag(); |
| 662 | DCHECK(pool_type == kConstPoolTag || pool_type == kVeneerPoolTag); |
| 663 | RelocInfo::Mode rmode = (pool_type == kConstPoolTag) ? |
| 664 | RelocInfo::CONST_POOL : RelocInfo::VENEER_POOL; |
| 665 | if (SetMode(rmode)) { |
| 666 | AdvanceReadPoolData(); |
| 667 | return; |
| 668 | } |
| 669 | Advance(kIntSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 670 | } else { |
| 671 | AdvanceReadPC(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 672 | int rmode = extra_tag + RelocInfo::LAST_COMPACT_ENUM; |
| 673 | if (SetMode(static_cast<RelocInfo::Mode>(rmode))) return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 677 | if (code_age_sequence_ != NULL) { |
| 678 | byte* old_code_age_sequence = code_age_sequence_; |
| 679 | code_age_sequence_ = NULL; |
| 680 | if (SetMode(RelocInfo::CODE_AGE_SEQUENCE)) { |
| 681 | rinfo_.data_ = 0; |
| 682 | rinfo_.pc_ = old_code_age_sequence; |
| 683 | return; |
| 684 | } |
| 685 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 686 | done_ = true; |
| 687 | } |
| 688 | |
| 689 | |
| 690 | RelocIterator::RelocIterator(Code* code, int mode_mask) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 691 | rinfo_.host_ = code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 692 | rinfo_.pc_ = code->instruction_start(); |
| 693 | rinfo_.data_ = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 694 | // Relocation info is read backwards. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 695 | pos_ = code->relocation_start() + code->relocation_size(); |
| 696 | end_ = code->relocation_start(); |
| 697 | done_ = false; |
| 698 | mode_mask_ = mode_mask; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 699 | last_id_ = 0; |
| 700 | last_position_ = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 701 | byte* sequence = code->FindCodeAgeSequence(); |
| 702 | // We get the isolate from the map, because at serialization time |
| 703 | // the code pointer has been cloned and isn't really in heap space. |
| 704 | Isolate* isolate = code->map()->GetIsolate(); |
| 705 | if (sequence != NULL && !Code::IsYoungSequence(isolate, sequence)) { |
| 706 | code_age_sequence_ = sequence; |
| 707 | } else { |
| 708 | code_age_sequence_ = NULL; |
| 709 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 710 | if (mode_mask_ == 0) pos_ = end_; |
| 711 | next(); |
| 712 | } |
| 713 | |
| 714 | |
| 715 | RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) { |
| 716 | rinfo_.pc_ = desc.buffer; |
| 717 | rinfo_.data_ = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 718 | // Relocation info is read backwards. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 719 | pos_ = desc.buffer + desc.buffer_size; |
| 720 | end_ = pos_ - desc.reloc_size; |
| 721 | done_ = false; |
| 722 | mode_mask_ = mode_mask; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 723 | last_id_ = 0; |
| 724 | last_position_ = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 725 | code_age_sequence_ = NULL; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 726 | if (mode_mask_ == 0) pos_ = end_; |
| 727 | next(); |
| 728 | } |
| 729 | |
| 730 | |
| 731 | // ----------------------------------------------------------------------------- |
| 732 | // Implementation of RelocInfo |
| 733 | |
| 734 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 735 | #ifdef DEBUG |
| 736 | bool RelocInfo::RequiresRelocation(const CodeDesc& desc) { |
| 737 | // Ensure there are no code targets or embedded objects present in the |
| 738 | // deoptimization entries, they would require relocation after code |
| 739 | // generation. |
| 740 | int mode_mask = RelocInfo::kCodeTargetMask | |
| 741 | RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | |
| 742 | RelocInfo::ModeMask(RelocInfo::CELL) | |
| 743 | RelocInfo::kApplyMask; |
| 744 | RelocIterator it(desc, mode_mask); |
| 745 | return !it.done(); |
| 746 | } |
| 747 | #endif |
| 748 | |
| 749 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 750 | #ifdef ENABLE_DISASSEMBLER |
| 751 | const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) { |
| 752 | switch (rmode) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 753 | case RelocInfo::NONE32: |
| 754 | return "no reloc 32"; |
| 755 | case RelocInfo::NONE64: |
| 756 | return "no reloc 64"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 757 | case RelocInfo::EMBEDDED_OBJECT: |
| 758 | return "embedded object"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 759 | case RelocInfo::CONSTRUCT_CALL: |
| 760 | return "code target (js construct call)"; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 761 | case RelocInfo::DEBUG_BREAK: |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 762 | return "debug break"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 763 | case RelocInfo::CODE_TARGET: |
| 764 | return "code target"; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 765 | case RelocInfo::CODE_TARGET_WITH_ID: |
| 766 | return "code target with id"; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 767 | case RelocInfo::CELL: |
| 768 | return "property cell"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 769 | case RelocInfo::RUNTIME_ENTRY: |
| 770 | return "runtime entry"; |
| 771 | case RelocInfo::JS_RETURN: |
| 772 | return "js return"; |
| 773 | case RelocInfo::COMMENT: |
| 774 | return "comment"; |
| 775 | case RelocInfo::POSITION: |
| 776 | return "position"; |
| 777 | case RelocInfo::STATEMENT_POSITION: |
| 778 | return "statement position"; |
| 779 | case RelocInfo::EXTERNAL_REFERENCE: |
| 780 | return "external reference"; |
| 781 | case RelocInfo::INTERNAL_REFERENCE: |
| 782 | return "internal reference"; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 783 | case RelocInfo::CONST_POOL: |
| 784 | return "constant pool"; |
| 785 | case RelocInfo::VENEER_POOL: |
| 786 | return "veneer pool"; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 787 | case RelocInfo::DEBUG_BREAK_SLOT: |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 788 | return "debug break slot"; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 789 | case RelocInfo::CODE_AGE_SEQUENCE: |
| 790 | return "code_age_sequence"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 791 | case RelocInfo::NUMBER_OF_MODES: |
| 792 | UNREACHABLE(); |
| 793 | return "number_of_modes"; |
| 794 | } |
| 795 | return "unknown relocation type"; |
| 796 | } |
| 797 | |
| 798 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 799 | void RelocInfo::Print(Isolate* isolate, std::ostream& os) { // NOLINT |
| 800 | os << static_cast<const void*>(pc_) << " " << RelocModeName(rmode_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 801 | if (IsComment(rmode_)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 802 | os << " (" << reinterpret_cast<char*>(data_) << ")"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 803 | } else if (rmode_ == EMBEDDED_OBJECT) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 804 | os << " (" << Brief(target_object()) << ")"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 805 | } else if (rmode_ == EXTERNAL_REFERENCE) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 806 | ExternalReferenceEncoder ref_encoder(isolate); |
| 807 | os << " (" << ref_encoder.NameOfAddress(target_reference()) << ") (" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 808 | << static_cast<const void*>(target_reference()) << ")"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 809 | } else if (IsCodeTarget(rmode_)) { |
| 810 | Code* code = Code::GetCodeFromTargetAddress(target_address()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 811 | os << " (" << Code::Kind2String(code->kind()) << ") (" |
| 812 | << static_cast<const void*>(target_address()) << ")"; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 813 | if (rmode_ == CODE_TARGET_WITH_ID) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 814 | os << " (id=" << static_cast<int>(data_) << ")"; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 815 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 816 | } else if (IsPosition(rmode_)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 817 | os << " (" << data() << ")"; |
| 818 | } else if (IsRuntimeEntry(rmode_) && |
| 819 | isolate->deoptimizer_data() != NULL) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 820 | // Depotimization bailouts are stored as runtime entries. |
| 821 | int id = Deoptimizer::GetDeoptimizationId( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 822 | isolate, target_address(), Deoptimizer::EAGER); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 823 | if (id != Deoptimizer::kNotDeoptimizationEntry) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 824 | os << " (deoptimization bailout " << id << ")"; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 825 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 828 | os << "\n"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 829 | } |
| 830 | #endif // ENABLE_DISASSEMBLER |
| 831 | |
| 832 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 833 | #ifdef VERIFY_HEAP |
| 834 | void RelocInfo::Verify(Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 835 | switch (rmode_) { |
| 836 | case EMBEDDED_OBJECT: |
| 837 | Object::VerifyPointer(target_object()); |
| 838 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 839 | case CELL: |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 840 | Object::VerifyPointer(target_cell()); |
| 841 | break; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 842 | case DEBUG_BREAK: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 843 | case CONSTRUCT_CALL: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 844 | case CODE_TARGET_WITH_ID: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 845 | case CODE_TARGET: { |
| 846 | // convert inline target address to code object |
| 847 | Address addr = target_address(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 848 | CHECK(addr != NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 849 | // Check that we can find the right code object. |
| 850 | Code* code = Code::GetCodeFromTargetAddress(addr); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 851 | Object* found = isolate->FindCodeObject(addr); |
| 852 | CHECK(found->IsCode()); |
| 853 | CHECK(code->address() == HeapObject::cast(found)->address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 854 | break; |
| 855 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 856 | case RUNTIME_ENTRY: |
| 857 | case JS_RETURN: |
| 858 | case COMMENT: |
| 859 | case POSITION: |
| 860 | case STATEMENT_POSITION: |
| 861 | case EXTERNAL_REFERENCE: |
| 862 | case INTERNAL_REFERENCE: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 863 | case CONST_POOL: |
| 864 | case VENEER_POOL: |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 865 | case DEBUG_BREAK_SLOT: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 866 | case NONE32: |
| 867 | case NONE64: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 868 | break; |
| 869 | case NUMBER_OF_MODES: |
| 870 | UNREACHABLE(); |
| 871 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 872 | case CODE_AGE_SEQUENCE: |
| 873 | DCHECK(Code::IsYoungSequence(isolate, pc_) || code_age_stub()->IsCode()); |
| 874 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 875 | } |
| 876 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 877 | #endif // VERIFY_HEAP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 878 | |
| 879 | |
| 880 | // ----------------------------------------------------------------------------- |
| 881 | // Implementation of ExternalReference |
| 882 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 883 | void ExternalReference::SetUp() { |
| 884 | double_constants.min_int = kMinInt; |
| 885 | double_constants.one_half = 0.5; |
| 886 | double_constants.minus_one_half = -0.5; |
| 887 | double_constants.canonical_non_hole_nan = base::OS::nan_value(); |
| 888 | double_constants.the_hole_nan = bit_cast<double>(kHoleNanInt64); |
| 889 | double_constants.negative_infinity = -V8_INFINITY; |
| 890 | double_constants.uint32_bias = |
| 891 | static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1; |
| 892 | |
| 893 | math_exp_data_mutex = new base::Mutex(); |
| 894 | } |
| 895 | |
| 896 | |
| 897 | void ExternalReference::InitializeMathExpData() { |
| 898 | // Early return? |
| 899 | if (math_exp_data_initialized) return; |
| 900 | |
| 901 | base::LockGuard<base::Mutex> lock_guard(math_exp_data_mutex); |
| 902 | if (!math_exp_data_initialized) { |
| 903 | // If this is changed, generated code must be adapted too. |
| 904 | const int kTableSizeBits = 11; |
| 905 | const int kTableSize = 1 << kTableSizeBits; |
| 906 | const double kTableSizeDouble = static_cast<double>(kTableSize); |
| 907 | |
| 908 | math_exp_constants_array = new double[9]; |
| 909 | // Input values smaller than this always return 0. |
| 910 | math_exp_constants_array[0] = -708.39641853226408; |
| 911 | // Input values larger than this always return +Infinity. |
| 912 | math_exp_constants_array[1] = 709.78271289338397; |
| 913 | math_exp_constants_array[2] = V8_INFINITY; |
| 914 | // The rest is black magic. Do not attempt to understand it. It is |
| 915 | // loosely based on the "expd" function published at: |
| 916 | // http://herumi.blogspot.com/2011/08/fast-double-precision-exponential.html |
| 917 | const double constant3 = (1 << kTableSizeBits) / std::log(2.0); |
| 918 | math_exp_constants_array[3] = constant3; |
| 919 | math_exp_constants_array[4] = |
| 920 | static_cast<double>(static_cast<int64_t>(3) << 51); |
| 921 | math_exp_constants_array[5] = 1 / constant3; |
| 922 | math_exp_constants_array[6] = 3.0000000027955394; |
| 923 | math_exp_constants_array[7] = 0.16666666685227835; |
| 924 | math_exp_constants_array[8] = 1; |
| 925 | |
| 926 | math_exp_log_table_array = new double[kTableSize]; |
| 927 | for (int i = 0; i < kTableSize; i++) { |
| 928 | double value = std::pow(2, i / kTableSizeDouble); |
| 929 | uint64_t bits = bit_cast<uint64_t, double>(value); |
| 930 | bits &= (static_cast<uint64_t>(1) << 52) - 1; |
| 931 | double mantissa = bit_cast<double, uint64_t>(bits); |
| 932 | math_exp_log_table_array[i] = mantissa; |
| 933 | } |
| 934 | |
| 935 | math_exp_data_initialized = true; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | |
| 940 | void ExternalReference::TearDownMathExpData() { |
| 941 | delete[] math_exp_constants_array; |
| 942 | math_exp_constants_array = NULL; |
| 943 | delete[] math_exp_log_table_array; |
| 944 | math_exp_log_table_array = NULL; |
| 945 | delete math_exp_data_mutex; |
| 946 | math_exp_data_mutex = NULL; |
| 947 | } |
| 948 | |
| 949 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 950 | ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate) |
| 951 | : address_(Redirect(isolate, Builtins::c_function_address(id))) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 952 | |
| 953 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 954 | ExternalReference::ExternalReference( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 955 | ApiFunction* fun, |
| 956 | Type type = ExternalReference::BUILTIN_CALL, |
| 957 | Isolate* isolate = NULL) |
| 958 | : address_(Redirect(isolate, fun->address(), type)) {} |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 959 | |
| 960 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 961 | ExternalReference::ExternalReference(Builtins::Name name, Isolate* isolate) |
| 962 | : address_(isolate->builtins()->builtin_address(name)) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 963 | |
| 964 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 965 | ExternalReference::ExternalReference(Runtime::FunctionId id, |
| 966 | Isolate* isolate) |
| 967 | : address_(Redirect(isolate, Runtime::FunctionForId(id)->entry)) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 968 | |
| 969 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 970 | ExternalReference::ExternalReference(const Runtime::Function* f, |
| 971 | Isolate* isolate) |
| 972 | : address_(Redirect(isolate, f->entry)) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 973 | |
| 974 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 975 | ExternalReference ExternalReference::isolate_address(Isolate* isolate) { |
| 976 | return ExternalReference(isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | |
| 980 | ExternalReference::ExternalReference(const IC_Utility& ic_utility, |
| 981 | Isolate* isolate) |
| 982 | : address_(Redirect(isolate, ic_utility.address())) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 983 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 984 | |
| 985 | ExternalReference::ExternalReference(StatsCounter* counter) |
| 986 | : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {} |
| 987 | |
| 988 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 989 | ExternalReference::ExternalReference(Isolate::AddressId id, Isolate* isolate) |
| 990 | : address_(isolate->get_address_from_id(id)) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 991 | |
| 992 | |
| 993 | ExternalReference::ExternalReference(const SCTableReference& table_ref) |
| 994 | : address_(table_ref.address()) {} |
| 995 | |
| 996 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 997 | ExternalReference ExternalReference:: |
| 998 | incremental_marking_record_write_function(Isolate* isolate) { |
| 999 | return ExternalReference(Redirect( |
| 1000 | isolate, |
| 1001 | FUNCTION_ADDR(IncrementalMarking::RecordWriteFromCode))); |
| 1002 | } |
| 1003 | |
| 1004 | |
| 1005 | ExternalReference ExternalReference:: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1006 | store_buffer_overflow_function(Isolate* isolate) { |
| 1007 | return ExternalReference(Redirect( |
| 1008 | isolate, |
| 1009 | FUNCTION_ADDR(StoreBuffer::StoreBufferOverflow))); |
| 1010 | } |
| 1011 | |
| 1012 | |
| 1013 | ExternalReference ExternalReference::flush_icache_function(Isolate* isolate) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1014 | return ExternalReference( |
| 1015 | Redirect(isolate, FUNCTION_ADDR(CpuFeatures::FlushICache))); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1019 | ExternalReference ExternalReference::delete_handle_scope_extensions( |
| 1020 | Isolate* isolate) { |
| 1021 | return ExternalReference(Redirect( |
| 1022 | isolate, |
| 1023 | FUNCTION_ADDR(HandleScope::DeleteExtensions))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1027 | ExternalReference ExternalReference::get_date_field_function( |
| 1028 | Isolate* isolate) { |
| 1029 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(JSDate::GetField))); |
| 1030 | } |
| 1031 | |
| 1032 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1033 | ExternalReference ExternalReference::get_make_code_young_function( |
| 1034 | Isolate* isolate) { |
| 1035 | return ExternalReference(Redirect( |
| 1036 | isolate, FUNCTION_ADDR(Code::MakeCodeAgeSequenceYoung))); |
| 1037 | } |
| 1038 | |
| 1039 | |
| 1040 | ExternalReference ExternalReference::get_mark_code_as_executed_function( |
| 1041 | Isolate* isolate) { |
| 1042 | return ExternalReference(Redirect( |
| 1043 | isolate, FUNCTION_ADDR(Code::MarkCodeAsExecuted))); |
| 1044 | } |
| 1045 | |
| 1046 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1047 | ExternalReference ExternalReference::date_cache_stamp(Isolate* isolate) { |
| 1048 | return ExternalReference(isolate->date_cache()->stamp_address()); |
| 1049 | } |
| 1050 | |
| 1051 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1052 | ExternalReference ExternalReference::stress_deopt_count(Isolate* isolate) { |
| 1053 | return ExternalReference(isolate->stress_deopt_count_address()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1057 | ExternalReference ExternalReference::new_deoptimizer_function( |
| 1058 | Isolate* isolate) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1059 | return ExternalReference( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1060 | Redirect(isolate, FUNCTION_ADDR(Deoptimizer::New))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1064 | ExternalReference ExternalReference::compute_output_frames_function( |
| 1065 | Isolate* isolate) { |
| 1066 | return ExternalReference( |
| 1067 | Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1071 | ExternalReference ExternalReference::log_enter_external_function( |
| 1072 | Isolate* isolate) { |
| 1073 | return ExternalReference( |
| 1074 | Redirect(isolate, FUNCTION_ADDR(Logger::EnterExternal))); |
| 1075 | } |
| 1076 | |
| 1077 | |
| 1078 | ExternalReference ExternalReference::log_leave_external_function( |
| 1079 | Isolate* isolate) { |
| 1080 | return ExternalReference( |
| 1081 | Redirect(isolate, FUNCTION_ADDR(Logger::LeaveExternal))); |
| 1082 | } |
| 1083 | |
| 1084 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1085 | ExternalReference ExternalReference::keyed_lookup_cache_keys(Isolate* isolate) { |
| 1086 | return ExternalReference(isolate->keyed_lookup_cache()->keys_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1090 | ExternalReference ExternalReference::keyed_lookup_cache_field_offsets( |
| 1091 | Isolate* isolate) { |
| 1092 | return ExternalReference( |
| 1093 | isolate->keyed_lookup_cache()->field_offsets_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1097 | ExternalReference ExternalReference::roots_array_start(Isolate* isolate) { |
| 1098 | return ExternalReference(isolate->heap()->roots_array_start()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1102 | ExternalReference ExternalReference::allocation_sites_list_address( |
| 1103 | Isolate* isolate) { |
| 1104 | return ExternalReference(isolate->heap()->allocation_sites_list_address()); |
| 1105 | } |
| 1106 | |
| 1107 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1108 | ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) { |
| 1109 | return ExternalReference(isolate->stack_guard()->address_of_jslimit()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1113 | ExternalReference ExternalReference::address_of_real_stack_limit( |
| 1114 | Isolate* isolate) { |
| 1115 | return ExternalReference(isolate->stack_guard()->address_of_real_jslimit()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1119 | ExternalReference ExternalReference::address_of_regexp_stack_limit( |
| 1120 | Isolate* isolate) { |
| 1121 | return ExternalReference(isolate->regexp_stack()->limit_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1125 | ExternalReference ExternalReference::new_space_start(Isolate* isolate) { |
| 1126 | return ExternalReference(isolate->heap()->NewSpaceStart()); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1130 | ExternalReference ExternalReference::store_buffer_top(Isolate* isolate) { |
| 1131 | return ExternalReference(isolate->heap()->store_buffer()->TopAddress()); |
| 1132 | } |
| 1133 | |
| 1134 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1135 | ExternalReference ExternalReference::new_space_mask(Isolate* isolate) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1136 | return ExternalReference(reinterpret_cast<Address>( |
| 1137 | isolate->heap()->NewSpaceMask())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1141 | ExternalReference ExternalReference::new_space_allocation_top_address( |
| 1142 | Isolate* isolate) { |
| 1143 | return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1147 | ExternalReference ExternalReference::new_space_allocation_limit_address( |
| 1148 | Isolate* isolate) { |
| 1149 | return ExternalReference(isolate->heap()->NewSpaceAllocationLimitAddress()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1152 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1153 | ExternalReference ExternalReference::old_pointer_space_allocation_top_address( |
| 1154 | Isolate* isolate) { |
| 1155 | return ExternalReference( |
| 1156 | isolate->heap()->OldPointerSpaceAllocationTopAddress()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1160 | ExternalReference ExternalReference::old_pointer_space_allocation_limit_address( |
| 1161 | Isolate* isolate) { |
| 1162 | return ExternalReference( |
| 1163 | isolate->heap()->OldPointerSpaceAllocationLimitAddress()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1167 | ExternalReference ExternalReference::old_data_space_allocation_top_address( |
| 1168 | Isolate* isolate) { |
| 1169 | return ExternalReference( |
| 1170 | isolate->heap()->OldDataSpaceAllocationTopAddress()); |
| 1171 | } |
| 1172 | |
| 1173 | |
| 1174 | ExternalReference ExternalReference::old_data_space_allocation_limit_address( |
| 1175 | Isolate* isolate) { |
| 1176 | return ExternalReference( |
| 1177 | isolate->heap()->OldDataSpaceAllocationLimitAddress()); |
| 1178 | } |
| 1179 | |
| 1180 | |
| 1181 | ExternalReference ExternalReference::handle_scope_level_address( |
| 1182 | Isolate* isolate) { |
| 1183 | return ExternalReference(HandleScope::current_level_address(isolate)); |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | ExternalReference ExternalReference::handle_scope_next_address( |
| 1188 | Isolate* isolate) { |
| 1189 | return ExternalReference(HandleScope::current_next_address(isolate)); |
| 1190 | } |
| 1191 | |
| 1192 | |
| 1193 | ExternalReference ExternalReference::handle_scope_limit_address( |
| 1194 | Isolate* isolate) { |
| 1195 | return ExternalReference(HandleScope::current_limit_address(isolate)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1199 | ExternalReference ExternalReference::scheduled_exception_address( |
| 1200 | Isolate* isolate) { |
| 1201 | return ExternalReference(isolate->scheduled_exception_address()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1205 | ExternalReference ExternalReference::address_of_pending_message_obj( |
| 1206 | Isolate* isolate) { |
| 1207 | return ExternalReference(isolate->pending_message_obj_address()); |
| 1208 | } |
| 1209 | |
| 1210 | |
| 1211 | ExternalReference ExternalReference::address_of_has_pending_message( |
| 1212 | Isolate* isolate) { |
| 1213 | return ExternalReference(isolate->has_pending_message_address()); |
| 1214 | } |
| 1215 | |
| 1216 | |
| 1217 | ExternalReference ExternalReference::address_of_pending_message_script( |
| 1218 | Isolate* isolate) { |
| 1219 | return ExternalReference(isolate->pending_message_script_address()); |
| 1220 | } |
| 1221 | |
| 1222 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1223 | ExternalReference ExternalReference::address_of_min_int() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1224 | return ExternalReference(reinterpret_cast<void*>(&double_constants.min_int)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | |
| 1228 | ExternalReference ExternalReference::address_of_one_half() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1229 | return ExternalReference(reinterpret_cast<void*>(&double_constants.one_half)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1233 | ExternalReference ExternalReference::address_of_minus_one_half() { |
| 1234 | return ExternalReference( |
| 1235 | reinterpret_cast<void*>(&double_constants.minus_one_half)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1239 | ExternalReference ExternalReference::address_of_negative_infinity() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1240 | return ExternalReference( |
| 1241 | reinterpret_cast<void*>(&double_constants.negative_infinity)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1245 | ExternalReference ExternalReference::address_of_canonical_non_hole_nan() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1246 | return ExternalReference( |
| 1247 | reinterpret_cast<void*>(&double_constants.canonical_non_hole_nan)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | ExternalReference ExternalReference::address_of_the_hole_nan() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1252 | return ExternalReference( |
| 1253 | reinterpret_cast<void*>(&double_constants.the_hole_nan)); |
| 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | ExternalReference ExternalReference::address_of_uint32_bias() { |
| 1258 | return ExternalReference( |
| 1259 | reinterpret_cast<void*>(&double_constants.uint32_bias)); |
| 1260 | } |
| 1261 | |
| 1262 | |
| 1263 | ExternalReference ExternalReference::is_profiling_address(Isolate* isolate) { |
| 1264 | return ExternalReference(isolate->cpu_profiler()->is_profiling_address()); |
| 1265 | } |
| 1266 | |
| 1267 | |
| 1268 | ExternalReference ExternalReference::invoke_function_callback( |
| 1269 | Isolate* isolate) { |
| 1270 | Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback); |
| 1271 | ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL; |
| 1272 | ApiFunction thunk_fun(thunk_address); |
| 1273 | return ExternalReference(&thunk_fun, thunk_type, isolate); |
| 1274 | } |
| 1275 | |
| 1276 | |
| 1277 | ExternalReference ExternalReference::invoke_accessor_getter_callback( |
| 1278 | Isolate* isolate) { |
| 1279 | Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback); |
| 1280 | ExternalReference::Type thunk_type = |
| 1281 | ExternalReference::PROFILING_GETTER_CALL; |
| 1282 | ApiFunction thunk_fun(thunk_address); |
| 1283 | return ExternalReference(&thunk_fun, thunk_type, isolate); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1287 | #ifndef V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1288 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1289 | ExternalReference ExternalReference::re_check_stack_guard_state( |
| 1290 | Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1291 | Address function; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1292 | #if V8_TARGET_ARCH_X64 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1293 | function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState); |
| 1294 | #elif V8_TARGET_ARCH_IA32 |
| 1295 | function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1296 | #elif V8_TARGET_ARCH_ARM64 |
| 1297 | function = FUNCTION_ADDR(RegExpMacroAssemblerARM64::CheckStackGuardState); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1298 | #elif V8_TARGET_ARCH_ARM |
| 1299 | function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1300 | #elif V8_TARGET_ARCH_MIPS |
| 1301 | function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1302 | #elif V8_TARGET_ARCH_MIPS64 |
| 1303 | function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState); |
| 1304 | #elif V8_TARGET_ARCH_X87 |
| 1305 | function = FUNCTION_ADDR(RegExpMacroAssemblerX87::CheckStackGuardState); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1306 | #else |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1307 | UNREACHABLE(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1308 | #endif |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1309 | return ExternalReference(Redirect(isolate, function)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1312 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1313 | ExternalReference ExternalReference::re_grow_stack(Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1314 | return ExternalReference( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1315 | Redirect(isolate, FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1318 | ExternalReference ExternalReference::re_case_insensitive_compare_uc16( |
| 1319 | Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1320 | return ExternalReference(Redirect( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1321 | isolate, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1322 | FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16))); |
| 1323 | } |
| 1324 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1325 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1326 | ExternalReference ExternalReference::re_word_character_map() { |
| 1327 | return ExternalReference( |
| 1328 | NativeRegExpMacroAssembler::word_character_map_address()); |
| 1329 | } |
| 1330 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1331 | ExternalReference ExternalReference::address_of_static_offsets_vector( |
| 1332 | Isolate* isolate) { |
| 1333 | return ExternalReference( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1334 | reinterpret_cast<Address>(isolate->jsregexp_static_offsets_vector())); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1337 | ExternalReference ExternalReference::address_of_regexp_stack_memory_address( |
| 1338 | Isolate* isolate) { |
| 1339 | return ExternalReference( |
| 1340 | isolate->regexp_stack()->memory_address()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1343 | ExternalReference ExternalReference::address_of_regexp_stack_memory_size( |
| 1344 | Isolate* isolate) { |
| 1345 | return ExternalReference(isolate->regexp_stack()->memory_size_address()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1348 | #endif // V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1349 | |
| 1350 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1351 | ExternalReference ExternalReference::math_log_double_function( |
| 1352 | Isolate* isolate) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1353 | typedef double (*d2d)(double x); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1354 | return ExternalReference(Redirect(isolate, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1355 | FUNCTION_ADDR(static_cast<d2d>(std::log)), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1356 | BUILTIN_FP_CALL)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1360 | ExternalReference ExternalReference::math_exp_constants(int constant_index) { |
| 1361 | DCHECK(math_exp_data_initialized); |
| 1362 | return ExternalReference( |
| 1363 | reinterpret_cast<void*>(math_exp_constants_array + constant_index)); |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | ExternalReference ExternalReference::math_exp_log_table() { |
| 1368 | DCHECK(math_exp_data_initialized); |
| 1369 | return ExternalReference(reinterpret_cast<void*>(math_exp_log_table_array)); |
| 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | ExternalReference ExternalReference::page_flags(Page* page) { |
| 1374 | return ExternalReference(reinterpret_cast<Address>(page) + |
| 1375 | MemoryChunk::kFlagsOffset); |
| 1376 | } |
| 1377 | |
| 1378 | |
| 1379 | ExternalReference ExternalReference::ForDeoptEntry(Address entry) { |
| 1380 | return ExternalReference(entry); |
| 1381 | } |
| 1382 | |
| 1383 | |
| 1384 | ExternalReference ExternalReference::cpu_features() { |
| 1385 | DCHECK(CpuFeatures::initialized_); |
| 1386 | return ExternalReference(&CpuFeatures::supported_); |
| 1387 | } |
| 1388 | |
| 1389 | |
| 1390 | ExternalReference ExternalReference::debug_is_active_address( |
| 1391 | Isolate* isolate) { |
| 1392 | return ExternalReference(isolate->debug()->is_active_address()); |
| 1393 | } |
| 1394 | |
| 1395 | |
| 1396 | ExternalReference ExternalReference::debug_after_break_target_address( |
| 1397 | Isolate* isolate) { |
| 1398 | return ExternalReference(isolate->debug()->after_break_target_address()); |
| 1399 | } |
| 1400 | |
| 1401 | |
| 1402 | ExternalReference |
| 1403 | ExternalReference::debug_restarter_frame_function_pointer_address( |
| 1404 | Isolate* isolate) { |
| 1405 | return ExternalReference( |
| 1406 | isolate->debug()->restarter_frame_function_pointer_address()); |
| 1407 | } |
| 1408 | |
| 1409 | |
| 1410 | double power_helper(double x, double y) { |
| 1411 | int y_int = static_cast<int>(y); |
| 1412 | if (y == y_int) { |
| 1413 | return power_double_int(x, y_int); // Returns 1 if exponent is 0. |
| 1414 | } |
| 1415 | if (y == 0.5) { |
| 1416 | return (std::isinf(x)) ? V8_INFINITY |
| 1417 | : fast_sqrt(x + 0.0); // Convert -0 to +0. |
| 1418 | } |
| 1419 | if (y == -0.5) { |
| 1420 | return (std::isinf(x)) ? 0 : 1.0 / fast_sqrt(x + 0.0); // Convert -0 to +0. |
| 1421 | } |
| 1422 | return power_double_double(x, y); |
| 1423 | } |
| 1424 | |
| 1425 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1426 | // Helper function to compute x^y, where y is known to be an |
| 1427 | // integer. Uses binary decomposition to limit the number of |
| 1428 | // multiplications; see the discussion in "Hacker's Delight" by Henry |
| 1429 | // S. Warren, Jr., figure 11-6, page 213. |
| 1430 | double power_double_int(double x, int y) { |
| 1431 | double m = (y < 0) ? 1 / x : x; |
| 1432 | unsigned n = (y < 0) ? -y : y; |
| 1433 | double p = 1; |
| 1434 | while (n != 0) { |
| 1435 | if ((n & 1) != 0) p *= m; |
| 1436 | m *= m; |
| 1437 | if ((n & 2) != 0) p *= m; |
| 1438 | m *= m; |
| 1439 | n >>= 2; |
| 1440 | } |
| 1441 | return p; |
| 1442 | } |
| 1443 | |
| 1444 | |
| 1445 | double power_double_double(double x, double y) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1446 | #if defined(__MINGW64_VERSION_MAJOR) && \ |
| 1447 | (!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1) |
| 1448 | // MinGW64 has a custom implementation for pow. This handles certain |
| 1449 | // special cases that are different. |
| 1450 | if ((x == 0.0 || std::isinf(x)) && std::isfinite(y)) { |
| 1451 | double f; |
| 1452 | if (std::modf(y, &f) != 0.0) { |
| 1453 | return ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0; |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | if (x == 2.0) { |
| 1458 | int y_int = static_cast<int>(y); |
| 1459 | if (y == y_int) { |
| 1460 | return std::ldexp(1.0, y_int); |
| 1461 | } |
| 1462 | } |
| 1463 | #endif |
| 1464 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1465 | // The checks for special cases can be dropped in ia32 because it has already |
| 1466 | // been done in generated code before bailing out here. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1467 | if (std::isnan(y) || ((x == 1 || x == -1) && std::isinf(y))) { |
| 1468 | return base::OS::nan_value(); |
| 1469 | } |
| 1470 | return std::pow(x, y); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1474 | ExternalReference ExternalReference::power_double_double_function( |
| 1475 | Isolate* isolate) { |
| 1476 | return ExternalReference(Redirect(isolate, |
| 1477 | FUNCTION_ADDR(power_double_double), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1478 | BUILTIN_FP_FP_CALL)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1482 | ExternalReference ExternalReference::power_double_int_function( |
| 1483 | Isolate* isolate) { |
| 1484 | return ExternalReference(Redirect(isolate, |
| 1485 | FUNCTION_ADDR(power_double_int), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1486 | BUILTIN_FP_INT_CALL)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1490 | bool EvalComparison(Token::Value op, double op1, double op2) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1491 | DCHECK(Token::IsCompareOp(op)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1492 | switch (op) { |
| 1493 | case Token::EQ: |
| 1494 | case Token::EQ_STRICT: return (op1 == op2); |
| 1495 | case Token::NE: return (op1 != op2); |
| 1496 | case Token::LT: return (op1 < op2); |
| 1497 | case Token::GT: return (op1 > op2); |
| 1498 | case Token::LTE: return (op1 <= op2); |
| 1499 | case Token::GTE: return (op1 >= op2); |
| 1500 | default: |
| 1501 | UNREACHABLE(); |
| 1502 | return false; |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1507 | ExternalReference ExternalReference::mod_two_doubles_operation( |
| 1508 | Isolate* isolate) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1509 | return ExternalReference(Redirect(isolate, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1510 | FUNCTION_ADDR(modulo), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1511 | BUILTIN_FP_FP_CALL)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1515 | ExternalReference ExternalReference::debug_break(Isolate* isolate) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1516 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(Debug_Break))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1520 | ExternalReference ExternalReference::debug_step_in_fp_address( |
| 1521 | Isolate* isolate) { |
| 1522 | return ExternalReference(isolate->debug()->step_in_fp_addr()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1523 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1524 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1525 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1526 | bool operator==(ExternalReference lhs, ExternalReference rhs) { |
| 1527 | return lhs.address() == rhs.address(); |
| 1528 | } |
| 1529 | |
| 1530 | |
| 1531 | bool operator!=(ExternalReference lhs, ExternalReference rhs) { |
| 1532 | return !(lhs == rhs); |
| 1533 | } |
| 1534 | |
| 1535 | |
| 1536 | size_t hash_value(ExternalReference reference) { |
| 1537 | return base::hash<Address>()(reference.address()); |
| 1538 | } |
| 1539 | |
| 1540 | |
| 1541 | std::ostream& operator<<(std::ostream& os, ExternalReference reference) { |
| 1542 | os << static_cast<const void*>(reference.address()); |
| 1543 | const Runtime::Function* fn = Runtime::FunctionForEntry(reference.address()); |
| 1544 | if (fn) os << "<" << fn->name << ".entry>"; |
| 1545 | return os; |
| 1546 | } |
| 1547 | |
| 1548 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1549 | void PositionsRecorder::RecordPosition(int pos) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1550 | DCHECK(pos != RelocInfo::kNoPosition); |
| 1551 | DCHECK(pos >= 0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1552 | state_.current_position = pos; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1553 | LOG_CODE_EVENT(assembler_->isolate(), |
| 1554 | CodeLinePosInfoAddPositionEvent(jit_handler_data_, |
| 1555 | assembler_->pc_offset(), |
| 1556 | pos)); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | |
| 1560 | void PositionsRecorder::RecordStatementPosition(int pos) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1561 | DCHECK(pos != RelocInfo::kNoPosition); |
| 1562 | DCHECK(pos >= 0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1563 | state_.current_statement_position = pos; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1564 | LOG_CODE_EVENT(assembler_->isolate(), |
| 1565 | CodeLinePosInfoAddStatementPositionEvent( |
| 1566 | jit_handler_data_, |
| 1567 | assembler_->pc_offset(), |
| 1568 | pos)); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | |
| 1572 | bool PositionsRecorder::WriteRecordedPositions() { |
| 1573 | bool written = false; |
| 1574 | |
| 1575 | // Write the statement position if it is different from what was written last |
| 1576 | // time. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1577 | if (state_.current_statement_position != state_.written_statement_position) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1578 | EnsureSpace ensure_space(assembler_); |
| 1579 | assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1580 | state_.current_statement_position); |
| 1581 | state_.written_statement_position = state_.current_statement_position; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1582 | written = true; |
| 1583 | } |
| 1584 | |
| 1585 | // Write the position if it is different from what was written last time and |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1586 | // also different from the written statement position. |
| 1587 | if (state_.current_position != state_.written_position && |
| 1588 | state_.current_position != state_.written_statement_position) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1589 | EnsureSpace ensure_space(assembler_); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1590 | assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position); |
| 1591 | state_.written_position = state_.current_position; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1592 | written = true; |
| 1593 | } |
| 1594 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1595 | // Return whether something was written. |
| 1596 | return written; |
| 1597 | } |
| 1598 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1599 | } } // namespace v8::internal |