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