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