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