Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 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. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 33 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | |
| 35 | #include "v8.h" |
| 36 | |
| 37 | #include "arguments.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 38 | #include "deoptimizer.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 39 | #include "execution.h" |
| 40 | #include "ic-inl.h" |
| 41 | #include "factory.h" |
| 42 | #include "runtime.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 43 | #include "runtime-profiler.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | #include "serialize.h" |
| 45 | #include "stub-cache.h" |
| 46 | #include "regexp-stack.h" |
| 47 | #include "ast.h" |
| 48 | #include "regexp-macro-assembler.h" |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 49 | #include "platform.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 50 | // Include native regexp-macro-assembler. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 51 | #ifndef V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 52 | #if V8_TARGET_ARCH_IA32 |
| 53 | #include "ia32/regexp-macro-assembler-ia32.h" |
| 54 | #elif V8_TARGET_ARCH_X64 |
| 55 | #include "x64/regexp-macro-assembler-x64.h" |
| 56 | #elif V8_TARGET_ARCH_ARM |
| 57 | #include "arm/regexp-macro-assembler-arm.h" |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 58 | #elif V8_TARGET_ARCH_MIPS |
| 59 | #include "mips/regexp-macro-assembler-mips.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 60 | #else // Unknown architecture. |
| 61 | #error "Unknown architecture." |
| 62 | #endif // Target architecture. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 63 | #endif // V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 64 | |
| 65 | namespace v8 { |
| 66 | namespace internal { |
| 67 | |
| 68 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 69 | const double DoubleConstant::min_int = kMinInt; |
| 70 | const double DoubleConstant::one_half = 0.5; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 71 | const double DoubleConstant::minus_zero = -0.0; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 72 | const double DoubleConstant::uint8_max_value = 255; |
| 73 | const double DoubleConstant::zero = 0.0; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 74 | const double DoubleConstant::nan = OS::nan_value(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 75 | const double DoubleConstant::negative_infinity = -V8_INFINITY; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 76 | const char* RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING"; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 77 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 78 | // ----------------------------------------------------------------------------- |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 79 | // Implementation of AssemblerBase |
| 80 | |
| 81 | AssemblerBase::AssemblerBase(Isolate* isolate) |
| 82 | : isolate_(isolate), |
| 83 | jit_cookie_(0) { |
| 84 | if (FLAG_mask_constants_with_cookie && isolate != NULL) { |
| 85 | jit_cookie_ = V8::RandomPrivate(isolate); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | |
| 90 | // ----------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 91 | // Implementation of Label |
| 92 | |
| 93 | int Label::pos() const { |
| 94 | if (pos_ < 0) return -pos_ - 1; |
| 95 | if (pos_ > 0) return pos_ - 1; |
| 96 | UNREACHABLE(); |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | // ----------------------------------------------------------------------------- |
| 102 | // Implementation of RelocInfoWriter and RelocIterator |
| 103 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 104 | // Relocation information is written backwards in memory, from high addresses |
| 105 | // towards low addresses, byte by byte. Therefore, in the encodings listed |
| 106 | // below, the first byte listed it at the highest address, and successive |
| 107 | // bytes in the record are at progressively lower addresses. |
| 108 | // |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 109 | // Encoding |
| 110 | // |
| 111 | // The most common modes are given single-byte encodings. Also, it is |
| 112 | // easy to identify the type of reloc info and skip unwanted modes in |
| 113 | // an iteration. |
| 114 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 115 | // The encoding relies on the fact that there are fewer than 14 |
| 116 | // different non-compactly encoded relocation modes. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 117 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 118 | // The first byte of a relocation record has a tag in its low 2 bits: |
| 119 | // Here are the record schemes, depending on the low tag and optional higher |
| 120 | // tags. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 121 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 122 | // Low tag: |
| 123 | // 00: embedded_object: [6-bit pc delta] 00 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 124 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 125 | // 01: code_target: [6-bit pc delta] 01 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 126 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 127 | // 10: short_data_record: [6-bit pc delta] 10 followed by |
| 128 | // [6-bit data delta] [2-bit data type tag] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 129 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 130 | // 11: long_record [2-bit high tag][4 bit middle_tag] 11 |
| 131 | // followed by variable data depending on type. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 132 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 133 | // 2-bit data type tags, used in short_data_record and data_jump long_record: |
| 134 | // code_target_with_id: 00 |
| 135 | // position: 01 |
| 136 | // statement_position: 10 |
| 137 | // comment: 11 (not used in short_data_record) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 138 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 139 | // Long record format: |
| 140 | // 4-bit middle_tag: |
| 141 | // 0000 - 1100 : Short record for RelocInfo::Mode middle_tag + 2 |
| 142 | // (The middle_tag encodes rmode - RelocInfo::LAST_COMPACT_ENUM, |
| 143 | // and is between 0000 and 1100) |
| 144 | // The format is: |
| 145 | // 00 [4 bit middle_tag] 11 followed by |
| 146 | // 00 [6 bit pc delta] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 147 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 148 | // 1101: not used (would allow one more relocation mode to be added) |
| 149 | // 1110: long_data_record |
| 150 | // The format is: [2-bit data_type_tag] 1110 11 |
| 151 | // signed intptr_t, lowest byte written first |
| 152 | // (except data_type code_target_with_id, which |
| 153 | // is followed by a signed int, not intptr_t.) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 154 | // |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 155 | // 1111: long_pc_jump |
| 156 | // The format is: |
| 157 | // pc-jump: 00 1111 11, |
| 158 | // 00 [6 bits pc delta] |
| 159 | // or |
| 160 | // pc-jump (variable length): |
| 161 | // 01 1111 11, |
| 162 | // [7 bits data] 0 |
| 163 | // ... |
| 164 | // [7 bits data] 1 |
| 165 | // (Bits 6..31 of pc delta, with leading zeroes |
| 166 | // dropped, and last non-zero chunk tagged with 1.) |
| 167 | |
| 168 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 169 | const int kMaxRelocModes = 14; |
| 170 | |
| 171 | const int kTagBits = 2; |
| 172 | const int kTagMask = (1 << kTagBits) - 1; |
| 173 | const int kExtraTagBits = 4; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 174 | const int kLocatableTypeTagBits = 2; |
| 175 | const int kSmallDataBits = kBitsPerByte - kLocatableTypeTagBits; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 176 | |
| 177 | const int kEmbeddedObjectTag = 0; |
| 178 | const int kCodeTargetTag = 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 179 | const int kLocatableTag = 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 180 | const int kDefaultTag = 3; |
| 181 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 182 | const int kPCJumpExtraTag = (1 << kExtraTagBits) - 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 183 | |
| 184 | const int kSmallPCDeltaBits = kBitsPerByte - kTagBits; |
| 185 | const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 186 | const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 187 | |
| 188 | const int kVariableLengthPCJumpTopTag = 1; |
| 189 | const int kChunkBits = 7; |
| 190 | const int kChunkMask = (1 << kChunkBits) - 1; |
| 191 | const int kLastChunkTagBits = 1; |
| 192 | const int kLastChunkTagMask = 1; |
| 193 | const int kLastChunkTag = 1; |
| 194 | |
| 195 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 196 | const int kDataJumpExtraTag = kPCJumpExtraTag - 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 197 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 198 | const int kCodeWithIdTag = 0; |
| 199 | const int kNonstatementPositionTag = 1; |
| 200 | const int kStatementPositionTag = 2; |
| 201 | const int kCommentTag = 3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 202 | |
| 203 | |
| 204 | uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) { |
| 205 | // Return if the pc_delta can fit in kSmallPCDeltaBits bits. |
| 206 | // Otherwise write a variable length PC jump for the bits that do |
| 207 | // not fit in the kSmallPCDeltaBits bits. |
| 208 | if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 209 | WriteExtraTag(kPCJumpExtraTag, kVariableLengthPCJumpTopTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 210 | uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits; |
| 211 | ASSERT(pc_jump > 0); |
| 212 | // Write kChunkBits size chunks of the pc_jump. |
| 213 | for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) { |
| 214 | byte b = pc_jump & kChunkMask; |
| 215 | *--pos_ = b << kLastChunkTagBits; |
| 216 | } |
| 217 | // Tag the last chunk so it can be identified. |
| 218 | *pos_ = *pos_ | kLastChunkTag; |
| 219 | // Return the remaining kSmallPCDeltaBits of the pc_delta. |
| 220 | return pc_delta & kSmallPCDeltaMask; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) { |
| 225 | // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump. |
| 226 | pc_delta = WriteVariableLengthPCJump(pc_delta); |
| 227 | *--pos_ = pc_delta << kTagBits | tag; |
| 228 | } |
| 229 | |
| 230 | |
| 231 | void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 232 | *--pos_ = static_cast<byte>(data_delta << kLocatableTypeTagBits | tag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | |
| 236 | void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 237 | *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) | |
| 238 | extra_tag << kTagBits | |
| 239 | kDefaultTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | |
| 243 | void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) { |
| 244 | // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump. |
| 245 | pc_delta = WriteVariableLengthPCJump(pc_delta); |
| 246 | WriteExtraTag(extra_tag, 0); |
| 247 | *--pos_ = pc_delta; |
| 248 | } |
| 249 | |
| 250 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 251 | void RelocInfoWriter::WriteExtraTaggedIntData(int data_delta, int top_tag) { |
| 252 | WriteExtraTag(kDataJumpExtraTag, top_tag); |
| 253 | for (int i = 0; i < kIntSize; i++) { |
| 254 | *--pos_ = static_cast<byte>(data_delta); |
| 255 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
| 256 | data_delta = data_delta >> kBitsPerByte; |
| 257 | } |
| 258 | } |
| 259 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 260 | void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 261 | WriteExtraTag(kDataJumpExtraTag, top_tag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 262 | for (int i = 0; i < kIntptrSize; i++) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 263 | *--pos_ = static_cast<byte>(data_delta); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 264 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 265 | data_delta = data_delta >> kBitsPerByte; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | |
| 270 | void RelocInfoWriter::Write(const RelocInfo* rinfo) { |
| 271 | #ifdef DEBUG |
| 272 | byte* begin_pos = pos_; |
| 273 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 274 | ASSERT(rinfo->pc() - last_pc_ >= 0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 275 | ASSERT(RelocInfo::NUMBER_OF_MODES - RelocInfo::LAST_COMPACT_ENUM <= |
| 276 | kMaxRelocModes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 277 | // Use unsigned delta-encoding for pc. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 278 | uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 279 | RelocInfo::Mode rmode = rinfo->rmode(); |
| 280 | |
| 281 | // The two most common modes are given small tags, and usually fit in a byte. |
| 282 | if (rmode == RelocInfo::EMBEDDED_OBJECT) { |
| 283 | WriteTaggedPC(pc_delta, kEmbeddedObjectTag); |
| 284 | } else if (rmode == RelocInfo::CODE_TARGET) { |
| 285 | WriteTaggedPC(pc_delta, kCodeTargetTag); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 286 | ASSERT(begin_pos - pos_ <= RelocInfo::kMaxCallSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 287 | } else if (rmode == RelocInfo::CODE_TARGET_WITH_ID) { |
| 288 | // Use signed delta-encoding for id. |
| 289 | ASSERT(static_cast<int>(rinfo->data()) == rinfo->data()); |
| 290 | int id_delta = static_cast<int>(rinfo->data()) - last_id_; |
| 291 | // Check if delta is small enough to fit in a tagged byte. |
| 292 | if (is_intn(id_delta, kSmallDataBits)) { |
| 293 | WriteTaggedPC(pc_delta, kLocatableTag); |
| 294 | WriteTaggedData(id_delta, kCodeWithIdTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 295 | } else { |
| 296 | // Otherwise, use costly encoding. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 297 | WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag); |
| 298 | WriteExtraTaggedIntData(id_delta, kCodeWithIdTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 300 | last_id_ = static_cast<int>(rinfo->data()); |
| 301 | } else if (RelocInfo::IsPosition(rmode)) { |
| 302 | // Use signed delta-encoding for position. |
| 303 | ASSERT(static_cast<int>(rinfo->data()) == rinfo->data()); |
| 304 | int pos_delta = static_cast<int>(rinfo->data()) - last_position_; |
| 305 | int pos_type_tag = (rmode == RelocInfo::POSITION) ? kNonstatementPositionTag |
| 306 | : kStatementPositionTag; |
| 307 | // Check if delta is small enough to fit in a tagged byte. |
| 308 | if (is_intn(pos_delta, kSmallDataBits)) { |
| 309 | WriteTaggedPC(pc_delta, kLocatableTag); |
| 310 | WriteTaggedData(pos_delta, pos_type_tag); |
| 311 | } else { |
| 312 | // Otherwise, use costly encoding. |
| 313 | WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag); |
| 314 | WriteExtraTaggedIntData(pos_delta, pos_type_tag); |
| 315 | } |
| 316 | last_position_ = static_cast<int>(rinfo->data()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 317 | } else if (RelocInfo::IsComment(rmode)) { |
| 318 | // Comments are normally not generated, so we use the costly encoding. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 319 | WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag); |
| 320 | WriteExtraTaggedData(rinfo->data(), kCommentTag); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 321 | ASSERT(begin_pos - pos_ >= RelocInfo::kMinRelocCommentSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 322 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 323 | ASSERT(rmode > RelocInfo::LAST_COMPACT_ENUM); |
| 324 | int saved_mode = rmode - RelocInfo::LAST_COMPACT_ENUM; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 325 | // For all other modes we simply use the mode as the extra tag. |
| 326 | // None of these modes need a data component. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 327 | ASSERT(saved_mode < kPCJumpExtraTag && saved_mode < kDataJumpExtraTag); |
| 328 | WriteExtraTaggedPC(pc_delta, saved_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 329 | } |
| 330 | last_pc_ = rinfo->pc(); |
| 331 | #ifdef DEBUG |
| 332 | ASSERT(begin_pos - pos_ <= kMaxSize); |
| 333 | #endif |
| 334 | } |
| 335 | |
| 336 | |
| 337 | inline int RelocIterator::AdvanceGetTag() { |
| 338 | return *--pos_ & kTagMask; |
| 339 | } |
| 340 | |
| 341 | |
| 342 | inline int RelocIterator::GetExtraTag() { |
| 343 | return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1); |
| 344 | } |
| 345 | |
| 346 | |
| 347 | inline int RelocIterator::GetTopTag() { |
| 348 | return *pos_ >> (kTagBits + kExtraTagBits); |
| 349 | } |
| 350 | |
| 351 | |
| 352 | inline void RelocIterator::ReadTaggedPC() { |
| 353 | rinfo_.pc_ += *pos_ >> kTagBits; |
| 354 | } |
| 355 | |
| 356 | |
| 357 | inline void RelocIterator::AdvanceReadPC() { |
| 358 | rinfo_.pc_ += *--pos_; |
| 359 | } |
| 360 | |
| 361 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 362 | void RelocIterator::AdvanceReadId() { |
| 363 | int x = 0; |
| 364 | for (int i = 0; i < kIntSize; i++) { |
| 365 | x |= static_cast<int>(*--pos_) << i * kBitsPerByte; |
| 366 | } |
| 367 | last_id_ += x; |
| 368 | rinfo_.data_ = last_id_; |
| 369 | } |
| 370 | |
| 371 | |
| 372 | void RelocIterator::AdvanceReadPosition() { |
| 373 | int x = 0; |
| 374 | for (int i = 0; i < kIntSize; i++) { |
| 375 | x |= static_cast<int>(*--pos_) << i * kBitsPerByte; |
| 376 | } |
| 377 | last_position_ += x; |
| 378 | rinfo_.data_ = last_position_; |
| 379 | } |
| 380 | |
| 381 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 382 | void RelocIterator::AdvanceReadData() { |
| 383 | intptr_t x = 0; |
| 384 | for (int i = 0; i < kIntptrSize; i++) { |
| 385 | x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte; |
| 386 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 387 | rinfo_.data_ = x; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | |
| 391 | void RelocIterator::AdvanceReadVariableLengthPCJump() { |
| 392 | // Read the 32-kSmallPCDeltaBits most significant bits of the |
| 393 | // pc jump in kChunkBits bit chunks and shift them into place. |
| 394 | // Stop when the last chunk is encountered. |
| 395 | uint32_t pc_jump = 0; |
| 396 | for (int i = 0; i < kIntSize; i++) { |
| 397 | byte pc_jump_part = *--pos_; |
| 398 | pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits; |
| 399 | if ((pc_jump_part & kLastChunkTagMask) == 1) break; |
| 400 | } |
| 401 | // The least significant kSmallPCDeltaBits bits will be added |
| 402 | // later. |
| 403 | rinfo_.pc_ += pc_jump << kSmallPCDeltaBits; |
| 404 | } |
| 405 | |
| 406 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 407 | inline int RelocIterator::GetLocatableTypeTag() { |
| 408 | return *pos_ & ((1 << kLocatableTypeTagBits) - 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 412 | inline void RelocIterator::ReadTaggedId() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 413 | int8_t signed_b = *pos_; |
| 414 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 415 | last_id_ += signed_b >> kLocatableTypeTagBits; |
| 416 | rinfo_.data_ = last_id_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 420 | inline void RelocIterator::ReadTaggedPosition() { |
| 421 | int8_t signed_b = *pos_; |
| 422 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
| 423 | last_position_ += signed_b >> kLocatableTypeTagBits; |
| 424 | rinfo_.data_ = last_position_; |
| 425 | } |
| 426 | |
| 427 | |
| 428 | static inline RelocInfo::Mode GetPositionModeFromTag(int tag) { |
| 429 | ASSERT(tag == kNonstatementPositionTag || |
| 430 | tag == kStatementPositionTag); |
| 431 | return (tag == kNonstatementPositionTag) ? |
| 432 | RelocInfo::POSITION : |
| 433 | RelocInfo::STATEMENT_POSITION; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | |
| 437 | void RelocIterator::next() { |
| 438 | ASSERT(!done()); |
| 439 | // Basically, do the opposite of RelocInfoWriter::Write. |
| 440 | // Reading of data is as far as possible avoided for unwanted modes, |
| 441 | // but we must always update the pc. |
| 442 | // |
| 443 | // We exit this loop by returning when we find a mode we want. |
| 444 | while (pos_ > end_) { |
| 445 | int tag = AdvanceGetTag(); |
| 446 | if (tag == kEmbeddedObjectTag) { |
| 447 | ReadTaggedPC(); |
| 448 | if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return; |
| 449 | } else if (tag == kCodeTargetTag) { |
| 450 | ReadTaggedPC(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 451 | if (SetMode(RelocInfo::CODE_TARGET)) return; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 452 | } else if (tag == kLocatableTag) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 453 | ReadTaggedPC(); |
| 454 | Advance(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 455 | int locatable_tag = GetLocatableTypeTag(); |
| 456 | if (locatable_tag == kCodeWithIdTag) { |
| 457 | if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) { |
| 458 | ReadTaggedId(); |
| 459 | return; |
| 460 | } |
| 461 | } else { |
| 462 | // Compact encoding is never used for comments, |
| 463 | // so it must be a position. |
| 464 | ASSERT(locatable_tag == kNonstatementPositionTag || |
| 465 | locatable_tag == kStatementPositionTag); |
| 466 | if (mode_mask_ & RelocInfo::kPositionMask) { |
| 467 | ReadTaggedPosition(); |
| 468 | if (SetMode(GetPositionModeFromTag(locatable_tag))) return; |
| 469 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 470 | } |
| 471 | } else { |
| 472 | ASSERT(tag == kDefaultTag); |
| 473 | int extra_tag = GetExtraTag(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 474 | if (extra_tag == kPCJumpExtraTag) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 475 | int top_tag = GetTopTag(); |
| 476 | if (top_tag == kVariableLengthPCJumpTopTag) { |
| 477 | AdvanceReadVariableLengthPCJump(); |
| 478 | } else { |
| 479 | AdvanceReadPC(); |
| 480 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 481 | } else if (extra_tag == kDataJumpExtraTag) { |
| 482 | int locatable_tag = GetTopTag(); |
| 483 | if (locatable_tag == kCodeWithIdTag) { |
| 484 | if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) { |
| 485 | AdvanceReadId(); |
| 486 | return; |
| 487 | } |
| 488 | Advance(kIntSize); |
| 489 | } else if (locatable_tag != kCommentTag) { |
| 490 | ASSERT(locatable_tag == kNonstatementPositionTag || |
| 491 | locatable_tag == kStatementPositionTag); |
| 492 | if (mode_mask_ & RelocInfo::kPositionMask) { |
| 493 | AdvanceReadPosition(); |
| 494 | if (SetMode(GetPositionModeFromTag(locatable_tag))) return; |
| 495 | } else { |
| 496 | Advance(kIntSize); |
| 497 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 498 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 499 | ASSERT(locatable_tag == kCommentTag); |
| 500 | if (SetMode(RelocInfo::COMMENT)) { |
| 501 | AdvanceReadData(); |
| 502 | return; |
| 503 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 504 | Advance(kIntptrSize); |
| 505 | } |
| 506 | } else { |
| 507 | AdvanceReadPC(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 508 | int rmode = extra_tag + RelocInfo::LAST_COMPACT_ENUM; |
| 509 | if (SetMode(static_cast<RelocInfo::Mode>(rmode))) return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | } |
| 513 | done_ = true; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | RelocIterator::RelocIterator(Code* code, int mode_mask) { |
| 518 | rinfo_.pc_ = code->instruction_start(); |
| 519 | rinfo_.data_ = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 520 | // Relocation info is read backwards. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 521 | pos_ = code->relocation_start() + code->relocation_size(); |
| 522 | end_ = code->relocation_start(); |
| 523 | done_ = false; |
| 524 | mode_mask_ = mode_mask; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 525 | last_id_ = 0; |
| 526 | last_position_ = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 527 | if (mode_mask_ == 0) pos_ = end_; |
| 528 | next(); |
| 529 | } |
| 530 | |
| 531 | |
| 532 | RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) { |
| 533 | rinfo_.pc_ = desc.buffer; |
| 534 | rinfo_.data_ = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 535 | // Relocation info is read backwards. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 536 | pos_ = desc.buffer + desc.buffer_size; |
| 537 | end_ = pos_ - desc.reloc_size; |
| 538 | done_ = false; |
| 539 | mode_mask_ = mode_mask; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 540 | last_id_ = 0; |
| 541 | last_position_ = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 542 | if (mode_mask_ == 0) pos_ = end_; |
| 543 | next(); |
| 544 | } |
| 545 | |
| 546 | |
| 547 | // ----------------------------------------------------------------------------- |
| 548 | // Implementation of RelocInfo |
| 549 | |
| 550 | |
| 551 | #ifdef ENABLE_DISASSEMBLER |
| 552 | const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) { |
| 553 | switch (rmode) { |
| 554 | case RelocInfo::NONE: |
| 555 | return "no reloc"; |
| 556 | case RelocInfo::EMBEDDED_OBJECT: |
| 557 | return "embedded object"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 558 | case RelocInfo::CONSTRUCT_CALL: |
| 559 | return "code target (js construct call)"; |
| 560 | case RelocInfo::CODE_TARGET_CONTEXT: |
| 561 | return "code target (context)"; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 562 | case RelocInfo::DEBUG_BREAK: |
| 563 | #ifndef ENABLE_DEBUGGER_SUPPORT |
| 564 | UNREACHABLE(); |
| 565 | #endif |
| 566 | return "debug break"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 567 | case RelocInfo::CODE_TARGET: |
| 568 | return "code target"; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 569 | case RelocInfo::CODE_TARGET_WITH_ID: |
| 570 | return "code target with id"; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 571 | case RelocInfo::GLOBAL_PROPERTY_CELL: |
| 572 | return "global property cell"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 573 | case RelocInfo::RUNTIME_ENTRY: |
| 574 | return "runtime entry"; |
| 575 | case RelocInfo::JS_RETURN: |
| 576 | return "js return"; |
| 577 | case RelocInfo::COMMENT: |
| 578 | return "comment"; |
| 579 | case RelocInfo::POSITION: |
| 580 | return "position"; |
| 581 | case RelocInfo::STATEMENT_POSITION: |
| 582 | return "statement position"; |
| 583 | case RelocInfo::EXTERNAL_REFERENCE: |
| 584 | return "external reference"; |
| 585 | case RelocInfo::INTERNAL_REFERENCE: |
| 586 | return "internal reference"; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 587 | case RelocInfo::DEBUG_BREAK_SLOT: |
| 588 | #ifndef ENABLE_DEBUGGER_SUPPORT |
| 589 | UNREACHABLE(); |
| 590 | #endif |
| 591 | return "debug break slot"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 592 | case RelocInfo::NUMBER_OF_MODES: |
| 593 | UNREACHABLE(); |
| 594 | return "number_of_modes"; |
| 595 | } |
| 596 | return "unknown relocation type"; |
| 597 | } |
| 598 | |
| 599 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 600 | void RelocInfo::Print(FILE* out) { |
| 601 | PrintF(out, "%p %s", pc_, RelocModeName(rmode_)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 602 | if (IsComment(rmode_)) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 603 | PrintF(out, " (%s)", reinterpret_cast<char*>(data_)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 604 | } else if (rmode_ == EMBEDDED_OBJECT) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 605 | PrintF(out, " ("); |
| 606 | target_object()->ShortPrint(out); |
| 607 | PrintF(out, ")"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 608 | } else if (rmode_ == EXTERNAL_REFERENCE) { |
| 609 | ExternalReferenceEncoder ref_encoder; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 610 | PrintF(out, " (%s) (%p)", |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 611 | ref_encoder.NameOfAddress(*target_reference_address()), |
| 612 | *target_reference_address()); |
| 613 | } else if (IsCodeTarget(rmode_)) { |
| 614 | Code* code = Code::GetCodeFromTargetAddress(target_address()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 615 | PrintF(out, " (%s) (%p)", Code::Kind2String(code->kind()), |
| 616 | target_address()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 617 | if (rmode_ == CODE_TARGET_WITH_ID) { |
| 618 | PrintF(" (id=%d)", static_cast<int>(data_)); |
| 619 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 620 | } else if (IsPosition(rmode_)) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 621 | PrintF(out, " (%" V8_PTR_PREFIX "d)", data()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 622 | } else if (rmode_ == RelocInfo::RUNTIME_ENTRY && |
| 623 | Isolate::Current()->deoptimizer_data() != NULL) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 624 | // Depotimization bailouts are stored as runtime entries. |
| 625 | int id = Deoptimizer::GetDeoptimizationId( |
| 626 | target_address(), Deoptimizer::EAGER); |
| 627 | if (id != Deoptimizer::kNotDeoptimizationEntry) { |
| 628 | PrintF(out, " (deoptimization bailout %d)", id); |
| 629 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 632 | PrintF(out, "\n"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 633 | } |
| 634 | #endif // ENABLE_DISASSEMBLER |
| 635 | |
| 636 | |
| 637 | #ifdef DEBUG |
| 638 | void RelocInfo::Verify() { |
| 639 | switch (rmode_) { |
| 640 | case EMBEDDED_OBJECT: |
| 641 | Object::VerifyPointer(target_object()); |
| 642 | break; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 643 | case GLOBAL_PROPERTY_CELL: |
| 644 | Object::VerifyPointer(target_cell()); |
| 645 | break; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 646 | case DEBUG_BREAK: |
| 647 | #ifndef ENABLE_DEBUGGER_SUPPORT |
| 648 | UNREACHABLE(); |
| 649 | break; |
| 650 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 651 | case CONSTRUCT_CALL: |
| 652 | case CODE_TARGET_CONTEXT: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 653 | case CODE_TARGET_WITH_ID: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 654 | case CODE_TARGET: { |
| 655 | // convert inline target address to code object |
| 656 | Address addr = target_address(); |
| 657 | ASSERT(addr != NULL); |
| 658 | // Check that we can find the right code object. |
| 659 | Code* code = Code::GetCodeFromTargetAddress(addr); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 660 | Object* found = HEAP->FindCodeObject(addr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 661 | ASSERT(found->IsCode()); |
| 662 | ASSERT(code->address() == HeapObject::cast(found)->address()); |
| 663 | break; |
| 664 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 665 | case RUNTIME_ENTRY: |
| 666 | case JS_RETURN: |
| 667 | case COMMENT: |
| 668 | case POSITION: |
| 669 | case STATEMENT_POSITION: |
| 670 | case EXTERNAL_REFERENCE: |
| 671 | case INTERNAL_REFERENCE: |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 672 | case DEBUG_BREAK_SLOT: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 673 | case NONE: |
| 674 | break; |
| 675 | case NUMBER_OF_MODES: |
| 676 | UNREACHABLE(); |
| 677 | break; |
| 678 | } |
| 679 | } |
| 680 | #endif // DEBUG |
| 681 | |
| 682 | |
| 683 | // ----------------------------------------------------------------------------- |
| 684 | // Implementation of ExternalReference |
| 685 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 686 | ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate) |
| 687 | : address_(Redirect(isolate, Builtins::c_function_address(id))) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 688 | |
| 689 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 690 | ExternalReference::ExternalReference( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 691 | ApiFunction* fun, |
| 692 | Type type = ExternalReference::BUILTIN_CALL, |
| 693 | Isolate* isolate = NULL) |
| 694 | : address_(Redirect(isolate, fun->address(), type)) {} |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 695 | |
| 696 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 697 | ExternalReference::ExternalReference(Builtins::Name name, Isolate* isolate) |
| 698 | : address_(isolate->builtins()->builtin_address(name)) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 699 | |
| 700 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 701 | ExternalReference::ExternalReference(Runtime::FunctionId id, |
| 702 | Isolate* isolate) |
| 703 | : address_(Redirect(isolate, Runtime::FunctionForId(id)->entry)) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 704 | |
| 705 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 706 | ExternalReference::ExternalReference(const Runtime::Function* f, |
| 707 | Isolate* isolate) |
| 708 | : address_(Redirect(isolate, f->entry)) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 709 | |
| 710 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 711 | ExternalReference ExternalReference::isolate_address() { |
| 712 | return ExternalReference(Isolate::Current()); |
| 713 | } |
| 714 | |
| 715 | |
| 716 | ExternalReference::ExternalReference(const IC_Utility& ic_utility, |
| 717 | Isolate* isolate) |
| 718 | : address_(Redirect(isolate, ic_utility.address())) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 719 | |
| 720 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 721 | ExternalReference::ExternalReference(const Debug_Address& debug_address, |
| 722 | Isolate* isolate) |
| 723 | : address_(debug_address.address(isolate)) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 724 | #endif |
| 725 | |
| 726 | ExternalReference::ExternalReference(StatsCounter* counter) |
| 727 | : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {} |
| 728 | |
| 729 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 730 | ExternalReference::ExternalReference(Isolate::AddressId id, Isolate* isolate) |
| 731 | : address_(isolate->get_address_from_id(id)) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 732 | |
| 733 | |
| 734 | ExternalReference::ExternalReference(const SCTableReference& table_ref) |
| 735 | : address_(table_ref.address()) {} |
| 736 | |
| 737 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 738 | ExternalReference ExternalReference::perform_gc_function(Isolate* isolate) { |
| 739 | return ExternalReference(Redirect(isolate, |
| 740 | FUNCTION_ADDR(Runtime::PerformGC))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 744 | ExternalReference ExternalReference::fill_heap_number_with_random_function( |
| 745 | Isolate* isolate) { |
| 746 | return ExternalReference(Redirect( |
| 747 | isolate, |
| 748 | FUNCTION_ADDR(V8::FillHeapNumberWithRandom))); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 752 | ExternalReference ExternalReference::delete_handle_scope_extensions( |
| 753 | Isolate* isolate) { |
| 754 | return ExternalReference(Redirect( |
| 755 | isolate, |
| 756 | FUNCTION_ADDR(HandleScope::DeleteExtensions))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 760 | ExternalReference ExternalReference::random_uint32_function( |
| 761 | Isolate* isolate) { |
| 762 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(V8::Random))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 766 | ExternalReference ExternalReference::transcendental_cache_array_address( |
| 767 | Isolate* isolate) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 768 | return ExternalReference( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 769 | isolate->transcendental_cache()->cache_array_address()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 773 | ExternalReference ExternalReference::new_deoptimizer_function( |
| 774 | Isolate* isolate) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 775 | return ExternalReference( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 776 | Redirect(isolate, FUNCTION_ADDR(Deoptimizer::New))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 780 | ExternalReference ExternalReference::compute_output_frames_function( |
| 781 | Isolate* isolate) { |
| 782 | return ExternalReference( |
| 783 | Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 787 | ExternalReference ExternalReference::global_contexts_list(Isolate* isolate) { |
| 788 | return ExternalReference(isolate->heap()->global_contexts_list_address()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 792 | ExternalReference ExternalReference::keyed_lookup_cache_keys(Isolate* isolate) { |
| 793 | return ExternalReference(isolate->keyed_lookup_cache()->keys_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 797 | ExternalReference ExternalReference::keyed_lookup_cache_field_offsets( |
| 798 | Isolate* isolate) { |
| 799 | return ExternalReference( |
| 800 | isolate->keyed_lookup_cache()->field_offsets_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 804 | ExternalReference ExternalReference::the_hole_value_location(Isolate* isolate) { |
| 805 | return ExternalReference(isolate->factory()->the_hole_value().location()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 809 | ExternalReference ExternalReference::arguments_marker_location( |
| 810 | Isolate* isolate) { |
| 811 | return ExternalReference(isolate->factory()->arguments_marker().location()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 815 | ExternalReference ExternalReference::roots_address(Isolate* isolate) { |
| 816 | return ExternalReference(isolate->heap()->roots_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 820 | ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) { |
| 821 | return ExternalReference(isolate->stack_guard()->address_of_jslimit()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 825 | ExternalReference ExternalReference::address_of_real_stack_limit( |
| 826 | Isolate* isolate) { |
| 827 | return ExternalReference(isolate->stack_guard()->address_of_real_jslimit()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 831 | ExternalReference ExternalReference::address_of_regexp_stack_limit( |
| 832 | Isolate* isolate) { |
| 833 | return ExternalReference(isolate->regexp_stack()->limit_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 837 | ExternalReference ExternalReference::new_space_start(Isolate* isolate) { |
| 838 | return ExternalReference(isolate->heap()->NewSpaceStart()); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 842 | ExternalReference ExternalReference::new_space_mask(Isolate* isolate) { |
| 843 | Address mask = reinterpret_cast<Address>(isolate->heap()->NewSpaceMask()); |
| 844 | return ExternalReference(mask); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 848 | ExternalReference ExternalReference::new_space_allocation_top_address( |
| 849 | Isolate* isolate) { |
| 850 | return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 854 | ExternalReference ExternalReference::heap_always_allocate_scope_depth( |
| 855 | Isolate* isolate) { |
| 856 | Heap* heap = isolate->heap(); |
| 857 | return ExternalReference(heap->always_allocate_scope_depth_address()); |
| 858 | } |
| 859 | |
| 860 | |
| 861 | ExternalReference ExternalReference::new_space_allocation_limit_address( |
| 862 | Isolate* isolate) { |
| 863 | return ExternalReference(isolate->heap()->NewSpaceAllocationLimitAddress()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 866 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 867 | ExternalReference ExternalReference::handle_scope_level_address() { |
| 868 | return ExternalReference(HandleScope::current_level_address()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | |
| 872 | ExternalReference ExternalReference::handle_scope_next_address() { |
| 873 | return ExternalReference(HandleScope::current_next_address()); |
| 874 | } |
| 875 | |
| 876 | |
| 877 | ExternalReference ExternalReference::handle_scope_limit_address() { |
| 878 | return ExternalReference(HandleScope::current_limit_address()); |
| 879 | } |
| 880 | |
| 881 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 882 | ExternalReference ExternalReference::scheduled_exception_address( |
| 883 | Isolate* isolate) { |
| 884 | return ExternalReference(isolate->scheduled_exception_address()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 888 | ExternalReference ExternalReference::address_of_min_int() { |
| 889 | return ExternalReference(reinterpret_cast<void*>( |
| 890 | const_cast<double*>(&DoubleConstant::min_int))); |
| 891 | } |
| 892 | |
| 893 | |
| 894 | ExternalReference ExternalReference::address_of_one_half() { |
| 895 | return ExternalReference(reinterpret_cast<void*>( |
| 896 | const_cast<double*>(&DoubleConstant::one_half))); |
| 897 | } |
| 898 | |
| 899 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 900 | ExternalReference ExternalReference::address_of_minus_zero() { |
| 901 | return ExternalReference(reinterpret_cast<void*>( |
| 902 | const_cast<double*>(&DoubleConstant::minus_zero))); |
| 903 | } |
| 904 | |
| 905 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 906 | ExternalReference ExternalReference::address_of_zero() { |
| 907 | return ExternalReference(reinterpret_cast<void*>( |
| 908 | const_cast<double*>(&DoubleConstant::zero))); |
| 909 | } |
| 910 | |
| 911 | |
| 912 | ExternalReference ExternalReference::address_of_uint8_max_value() { |
| 913 | return ExternalReference(reinterpret_cast<void*>( |
| 914 | const_cast<double*>(&DoubleConstant::uint8_max_value))); |
| 915 | } |
| 916 | |
| 917 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 918 | ExternalReference ExternalReference::address_of_negative_infinity() { |
| 919 | return ExternalReference(reinterpret_cast<void*>( |
| 920 | const_cast<double*>(&DoubleConstant::negative_infinity))); |
| 921 | } |
| 922 | |
| 923 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 924 | ExternalReference ExternalReference::address_of_nan() { |
| 925 | return ExternalReference(reinterpret_cast<void*>( |
| 926 | const_cast<double*>(&DoubleConstant::nan))); |
| 927 | } |
| 928 | |
| 929 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 930 | #ifndef V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 931 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 932 | ExternalReference ExternalReference::re_check_stack_guard_state( |
| 933 | Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 934 | Address function; |
| 935 | #ifdef V8_TARGET_ARCH_X64 |
| 936 | function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState); |
| 937 | #elif V8_TARGET_ARCH_IA32 |
| 938 | function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState); |
| 939 | #elif V8_TARGET_ARCH_ARM |
| 940 | function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 941 | #elif V8_TARGET_ARCH_MIPS |
| 942 | function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 943 | #else |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 944 | UNREACHABLE(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 945 | #endif |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 946 | return ExternalReference(Redirect(isolate, function)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 947 | } |
| 948 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 949 | ExternalReference ExternalReference::re_grow_stack(Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 950 | return ExternalReference( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 951 | Redirect(isolate, FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 954 | ExternalReference ExternalReference::re_case_insensitive_compare_uc16( |
| 955 | Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 956 | return ExternalReference(Redirect( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 957 | isolate, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 958 | FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16))); |
| 959 | } |
| 960 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 961 | ExternalReference ExternalReference::re_word_character_map() { |
| 962 | return ExternalReference( |
| 963 | NativeRegExpMacroAssembler::word_character_map_address()); |
| 964 | } |
| 965 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 966 | ExternalReference ExternalReference::address_of_static_offsets_vector( |
| 967 | Isolate* isolate) { |
| 968 | return ExternalReference( |
| 969 | OffsetsVector::static_offsets_vector_address(isolate)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 972 | ExternalReference ExternalReference::address_of_regexp_stack_memory_address( |
| 973 | Isolate* isolate) { |
| 974 | return ExternalReference( |
| 975 | isolate->regexp_stack()->memory_address()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 978 | ExternalReference ExternalReference::address_of_regexp_stack_memory_size( |
| 979 | Isolate* isolate) { |
| 980 | return ExternalReference(isolate->regexp_stack()->memory_size_address()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 983 | #endif // V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 984 | |
| 985 | |
| 986 | static double add_two_doubles(double x, double y) { |
| 987 | return x + y; |
| 988 | } |
| 989 | |
| 990 | |
| 991 | static double sub_two_doubles(double x, double y) { |
| 992 | return x - y; |
| 993 | } |
| 994 | |
| 995 | |
| 996 | static double mul_two_doubles(double x, double y) { |
| 997 | return x * y; |
| 998 | } |
| 999 | |
| 1000 | |
| 1001 | static double div_two_doubles(double x, double y) { |
| 1002 | return x / y; |
| 1003 | } |
| 1004 | |
| 1005 | |
| 1006 | static double mod_two_doubles(double x, double y) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1007 | return modulo(x, y); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1011 | static double math_sin_double(double x) { |
| 1012 | return sin(x); |
| 1013 | } |
| 1014 | |
| 1015 | |
| 1016 | static double math_cos_double(double x) { |
| 1017 | return cos(x); |
| 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | static double math_log_double(double x) { |
| 1022 | return log(x); |
| 1023 | } |
| 1024 | |
| 1025 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1026 | ExternalReference ExternalReference::math_sin_double_function( |
| 1027 | Isolate* isolate) { |
| 1028 | return ExternalReference(Redirect(isolate, |
| 1029 | FUNCTION_ADDR(math_sin_double), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1030 | BUILTIN_FP_CALL)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1034 | ExternalReference ExternalReference::math_cos_double_function( |
| 1035 | Isolate* isolate) { |
| 1036 | return ExternalReference(Redirect(isolate, |
| 1037 | FUNCTION_ADDR(math_cos_double), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1038 | BUILTIN_FP_CALL)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1042 | ExternalReference ExternalReference::math_log_double_function( |
| 1043 | Isolate* isolate) { |
| 1044 | return ExternalReference(Redirect(isolate, |
| 1045 | FUNCTION_ADDR(math_log_double), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1046 | BUILTIN_FP_CALL)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1050 | // Helper function to compute x^y, where y is known to be an |
| 1051 | // integer. Uses binary decomposition to limit the number of |
| 1052 | // multiplications; see the discussion in "Hacker's Delight" by Henry |
| 1053 | // S. Warren, Jr., figure 11-6, page 213. |
| 1054 | double power_double_int(double x, int y) { |
| 1055 | double m = (y < 0) ? 1 / x : x; |
| 1056 | unsigned n = (y < 0) ? -y : y; |
| 1057 | double p = 1; |
| 1058 | while (n != 0) { |
| 1059 | if ((n & 1) != 0) p *= m; |
| 1060 | m *= m; |
| 1061 | if ((n & 2) != 0) p *= m; |
| 1062 | m *= m; |
| 1063 | n >>= 2; |
| 1064 | } |
| 1065 | return p; |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | double power_double_double(double x, double y) { |
| 1070 | int y_int = static_cast<int>(y); |
| 1071 | if (y == y_int) { |
| 1072 | return power_double_int(x, y_int); // Returns 1.0 for exponent 0. |
| 1073 | } |
| 1074 | if (!isinf(x)) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1075 | if (y == 0.5) return sqrt(x + 0.0); // -0 must be converted to +0. |
| 1076 | if (y == -0.5) return 1.0 / sqrt(x + 0.0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1077 | } |
| 1078 | if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) { |
| 1079 | return OS::nan_value(); |
| 1080 | } |
| 1081 | return pow(x, y); |
| 1082 | } |
| 1083 | |
| 1084 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1085 | ExternalReference ExternalReference::power_double_double_function( |
| 1086 | Isolate* isolate) { |
| 1087 | return ExternalReference(Redirect(isolate, |
| 1088 | FUNCTION_ADDR(power_double_double), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1089 | BUILTIN_FP_FP_CALL)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1093 | ExternalReference ExternalReference::power_double_int_function( |
| 1094 | Isolate* isolate) { |
| 1095 | return ExternalReference(Redirect(isolate, |
| 1096 | FUNCTION_ADDR(power_double_int), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1097 | BUILTIN_FP_INT_CALL)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1101 | static int native_compare_doubles(double y, double x) { |
| 1102 | if (x == y) return EQUAL; |
| 1103 | return x < y ? LESS : GREATER; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | |
| 1107 | ExternalReference ExternalReference::double_fp_operation( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1108 | Token::Value operation, Isolate* isolate) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1109 | typedef double BinaryFPOperation(double x, double y); |
| 1110 | BinaryFPOperation* function = NULL; |
| 1111 | switch (operation) { |
| 1112 | case Token::ADD: |
| 1113 | function = &add_two_doubles; |
| 1114 | break; |
| 1115 | case Token::SUB: |
| 1116 | function = &sub_two_doubles; |
| 1117 | break; |
| 1118 | case Token::MUL: |
| 1119 | function = &mul_two_doubles; |
| 1120 | break; |
| 1121 | case Token::DIV: |
| 1122 | function = &div_two_doubles; |
| 1123 | break; |
| 1124 | case Token::MOD: |
| 1125 | function = &mod_two_doubles; |
| 1126 | break; |
| 1127 | default: |
| 1128 | UNREACHABLE(); |
| 1129 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1130 | return ExternalReference(Redirect(isolate, |
| 1131 | FUNCTION_ADDR(function), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1132 | BUILTIN_FP_FP_CALL)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1136 | ExternalReference ExternalReference::compare_doubles(Isolate* isolate) { |
| 1137 | return ExternalReference(Redirect(isolate, |
| 1138 | FUNCTION_ADDR(native_compare_doubles), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1139 | BUILTIN_COMPARE_CALL)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1143 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1144 | ExternalReference ExternalReference::debug_break(Isolate* isolate) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1145 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(Debug_Break))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1149 | ExternalReference ExternalReference::debug_step_in_fp_address( |
| 1150 | Isolate* isolate) { |
| 1151 | return ExternalReference(isolate->debug()->step_in_fp_addr()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1152 | } |
| 1153 | #endif |
| 1154 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1155 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1156 | void PositionsRecorder::RecordPosition(int pos) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1157 | ASSERT(pos != RelocInfo::kNoPosition); |
| 1158 | ASSERT(pos >= 0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1159 | state_.current_position = pos; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1160 | #ifdef ENABLE_GDB_JIT_INTERFACE |
| 1161 | if (gdbjit_lineinfo_ != NULL) { |
| 1162 | gdbjit_lineinfo_->SetPosition(assembler_->pc_offset(), pos, false); |
| 1163 | } |
| 1164 | #endif |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | |
| 1168 | void PositionsRecorder::RecordStatementPosition(int pos) { |
| 1169 | ASSERT(pos != RelocInfo::kNoPosition); |
| 1170 | ASSERT(pos >= 0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1171 | state_.current_statement_position = pos; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1172 | #ifdef ENABLE_GDB_JIT_INTERFACE |
| 1173 | if (gdbjit_lineinfo_ != NULL) { |
| 1174 | gdbjit_lineinfo_->SetPosition(assembler_->pc_offset(), pos, true); |
| 1175 | } |
| 1176 | #endif |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | |
| 1180 | bool PositionsRecorder::WriteRecordedPositions() { |
| 1181 | bool written = false; |
| 1182 | |
| 1183 | // Write the statement position if it is different from what was written last |
| 1184 | // time. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1185 | if (state_.current_statement_position != state_.written_statement_position) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1186 | EnsureSpace ensure_space(assembler_); |
| 1187 | assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1188 | state_.current_statement_position); |
| 1189 | state_.written_statement_position = state_.current_statement_position; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1190 | written = true; |
| 1191 | } |
| 1192 | |
| 1193 | // Write the position if it is different from what was written last time and |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1194 | // also different from the written statement position. |
| 1195 | if (state_.current_position != state_.written_position && |
| 1196 | state_.current_position != state_.written_statement_position) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1197 | EnsureSpace ensure_space(assembler_); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1198 | assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position); |
| 1199 | state_.written_position = state_.current_position; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1200 | written = true; |
| 1201 | } |
| 1202 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1203 | // Return whether something was written. |
| 1204 | return written; |
| 1205 | } |
| 1206 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1207 | } } // namespace v8::internal |