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