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