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