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