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