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