blob: ca30e19cb4d2d1544cb2d1778a80af7d1e997e14 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// 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.
33// Copyright 2006-2009 the V8 project authors. All rights reserved.
34
35#include "v8.h"
36
37#include "arguments.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +010038#include "deoptimizer.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000039#include "execution.h"
40#include "ic-inl.h"
41#include "factory.h"
42#include "runtime.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +010043#include "runtime-profiler.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000044#include "serialize.h"
45#include "stub-cache.h"
46#include "regexp-stack.h"
47#include "ast.h"
48#include "regexp-macro-assembler.h"
Leon Clarkee46be812010-01-19 14:06:41 +000049#include "platform.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000050// Include native regexp-macro-assembler.
Steve Block6ded16b2010-05-10 14:33:55 +010051#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +000052#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 Block44f0eee2011-05-26 01:26:41 +010058#elif V8_TARGET_ARCH_MIPS
59#include "mips/regexp-macro-assembler-mips.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000060#else // Unknown architecture.
61#error "Unknown architecture."
62#endif // Target architecture.
Steve Block6ded16b2010-05-10 14:33:55 +010063#endif // V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +000064
65namespace v8 {
66namespace internal {
67
68
Ben Murdochb0fe1622011-05-05 13:52:32 +010069const double DoubleConstant::min_int = kMinInt;
70const double DoubleConstant::one_half = 0.5;
Ben Murdochb8e0da22011-05-16 14:20:40 +010071const double DoubleConstant::minus_zero = -0.0;
Steve Block44f0eee2011-05-26 01:26:41 +010072const double DoubleConstant::nan = OS::nan_value();
Ben Murdochb0fe1622011-05-05 13:52:32 +010073const double DoubleConstant::negative_infinity = -V8_INFINITY;
Ben Murdoche0cee9b2011-05-25 10:26:03 +010074const char* RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING";
Ben Murdochb0fe1622011-05-05 13:52:32 +010075
Steve Blocka7e24c12009-10-30 11:49:00 +000076// -----------------------------------------------------------------------------
77// Implementation of Label
78
79int Label::pos() const {
80 if (pos_ < 0) return -pos_ - 1;
81 if (pos_ > 0) return pos_ - 1;
82 UNREACHABLE();
83 return 0;
84}
85
86
87// -----------------------------------------------------------------------------
88// Implementation of RelocInfoWriter and RelocIterator
89//
90// Encoding
91//
92// The most common modes are given single-byte encodings. Also, it is
93// easy to identify the type of reloc info and skip unwanted modes in
94// an iteration.
95//
96// The encoding relies on the fact that there are less than 14
97// different relocation modes.
98//
99// embedded_object: [6 bits pc delta] 00
100//
101// code_taget: [6 bits pc delta] 01
102//
103// position: [6 bits pc delta] 10,
104// [7 bits signed data delta] 0
105//
106// statement_position: [6 bits pc delta] 10,
107// [7 bits signed data delta] 1
108//
109// any nondata mode: 00 [4 bits rmode] 11, // rmode: 0..13 only
110// 00 [6 bits pc delta]
111//
112// pc-jump: 00 1111 11,
113// 00 [6 bits pc delta]
114//
115// pc-jump: 01 1111 11,
116// (variable length) 7 - 26 bit pc delta, written in chunks of 7
117// bits, the lowest 7 bits written first.
118//
119// data-jump + pos: 00 1110 11,
120// signed intptr_t, lowest byte written first
121//
122// data-jump + st.pos: 01 1110 11,
123// signed intptr_t, lowest byte written first
124//
125// data-jump + comm.: 10 1110 11,
126// signed intptr_t, lowest byte written first
127//
128const int kMaxRelocModes = 14;
129
130const int kTagBits = 2;
131const int kTagMask = (1 << kTagBits) - 1;
132const int kExtraTagBits = 4;
133const int kPositionTypeTagBits = 1;
134const int kSmallDataBits = kBitsPerByte - kPositionTypeTagBits;
135
136const int kEmbeddedObjectTag = 0;
137const int kCodeTargetTag = 1;
138const int kPositionTag = 2;
139const int kDefaultTag = 3;
140
141const int kPCJumpTag = (1 << kExtraTagBits) - 1;
142
143const int kSmallPCDeltaBits = kBitsPerByte - kTagBits;
144const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1;
Steve Block44f0eee2011-05-26 01:26:41 +0100145const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask;
Steve Blocka7e24c12009-10-30 11:49:00 +0000146
147const int kVariableLengthPCJumpTopTag = 1;
148const int kChunkBits = 7;
149const int kChunkMask = (1 << kChunkBits) - 1;
150const int kLastChunkTagBits = 1;
151const int kLastChunkTagMask = 1;
152const int kLastChunkTag = 1;
153
154
155const int kDataJumpTag = kPCJumpTag - 1;
156
157const int kNonstatementPositionTag = 0;
158const int kStatementPositionTag = 1;
159const int kCommentTag = 2;
160
161
162uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) {
163 // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
164 // Otherwise write a variable length PC jump for the bits that do
165 // not fit in the kSmallPCDeltaBits bits.
166 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
167 WriteExtraTag(kPCJumpTag, kVariableLengthPCJumpTopTag);
168 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
169 ASSERT(pc_jump > 0);
170 // Write kChunkBits size chunks of the pc_jump.
171 for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) {
172 byte b = pc_jump & kChunkMask;
173 *--pos_ = b << kLastChunkTagBits;
174 }
175 // Tag the last chunk so it can be identified.
176 *pos_ = *pos_ | kLastChunkTag;
177 // Return the remaining kSmallPCDeltaBits of the pc_delta.
178 return pc_delta & kSmallPCDeltaMask;
179}
180
181
182void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) {
183 // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump.
184 pc_delta = WriteVariableLengthPCJump(pc_delta);
185 *--pos_ = pc_delta << kTagBits | tag;
186}
187
188
189void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) {
Steve Blockd0582a62009-12-15 09:54:21 +0000190 *--pos_ = static_cast<byte>(data_delta << kPositionTypeTagBits | tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000191}
192
193
194void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) {
Steve Blockd0582a62009-12-15 09:54:21 +0000195 *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) |
196 extra_tag << kTagBits |
197 kDefaultTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000198}
199
200
201void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) {
202 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump.
203 pc_delta = WriteVariableLengthPCJump(pc_delta);
204 WriteExtraTag(extra_tag, 0);
205 *--pos_ = pc_delta;
206}
207
208
209void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) {
210 WriteExtraTag(kDataJumpTag, top_tag);
211 for (int i = 0; i < kIntptrSize; i++) {
Steve Blockd0582a62009-12-15 09:54:21 +0000212 *--pos_ = static_cast<byte>(data_delta);
Steve Blocka7e24c12009-10-30 11:49:00 +0000213 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
214 data_delta = data_delta >> kBitsPerByte;
215 }
216}
217
218
219void RelocInfoWriter::Write(const RelocInfo* rinfo) {
220#ifdef DEBUG
221 byte* begin_pos = pos_;
222#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000223 ASSERT(rinfo->pc() - last_pc_ >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100224 ASSERT(RelocInfo::NUMBER_OF_MODES <= kMaxRelocModes);
Steve Blocka7e24c12009-10-30 11:49:00 +0000225 // Use unsigned delta-encoding for pc.
Steve Blockd0582a62009-12-15 09:54:21 +0000226 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000227 RelocInfo::Mode rmode = rinfo->rmode();
228
229 // The two most common modes are given small tags, and usually fit in a byte.
230 if (rmode == RelocInfo::EMBEDDED_OBJECT) {
231 WriteTaggedPC(pc_delta, kEmbeddedObjectTag);
232 } else if (rmode == RelocInfo::CODE_TARGET) {
233 WriteTaggedPC(pc_delta, kCodeTargetTag);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100234 ASSERT(begin_pos - pos_ <= RelocInfo::kMaxCallSize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000235 } else if (RelocInfo::IsPosition(rmode)) {
236 // Use signed delta-encoding for data.
237 intptr_t data_delta = rinfo->data() - last_data_;
238 int pos_type_tag = rmode == RelocInfo::POSITION ? kNonstatementPositionTag
239 : kStatementPositionTag;
240 // Check if data is small enough to fit in a tagged byte.
241 // We cannot use is_intn because data_delta is not an int32_t.
242 if (data_delta >= -(1 << (kSmallDataBits-1)) &&
243 data_delta < 1 << (kSmallDataBits-1)) {
244 WriteTaggedPC(pc_delta, kPositionTag);
245 WriteTaggedData(data_delta, pos_type_tag);
246 last_data_ = rinfo->data();
247 } else {
248 // Otherwise, use costly encoding.
249 WriteExtraTaggedPC(pc_delta, kPCJumpTag);
250 WriteExtraTaggedData(data_delta, pos_type_tag);
251 last_data_ = rinfo->data();
252 }
253 } else if (RelocInfo::IsComment(rmode)) {
254 // Comments are normally not generated, so we use the costly encoding.
255 WriteExtraTaggedPC(pc_delta, kPCJumpTag);
256 WriteExtraTaggedData(rinfo->data() - last_data_, kCommentTag);
257 last_data_ = rinfo->data();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100258 ASSERT(begin_pos - pos_ >= RelocInfo::kMinRelocCommentSize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000259 } else {
260 // For all other modes we simply use the mode as the extra tag.
261 // None of these modes need a data component.
262 ASSERT(rmode < kPCJumpTag && rmode < kDataJumpTag);
263 WriteExtraTaggedPC(pc_delta, rmode);
264 }
265 last_pc_ = rinfo->pc();
266#ifdef DEBUG
267 ASSERT(begin_pos - pos_ <= kMaxSize);
268#endif
269}
270
271
272inline int RelocIterator::AdvanceGetTag() {
273 return *--pos_ & kTagMask;
274}
275
276
277inline int RelocIterator::GetExtraTag() {
278 return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1);
279}
280
281
282inline int RelocIterator::GetTopTag() {
283 return *pos_ >> (kTagBits + kExtraTagBits);
284}
285
286
287inline void RelocIterator::ReadTaggedPC() {
288 rinfo_.pc_ += *pos_ >> kTagBits;
289}
290
291
292inline void RelocIterator::AdvanceReadPC() {
293 rinfo_.pc_ += *--pos_;
294}
295
296
297void RelocIterator::AdvanceReadData() {
298 intptr_t x = 0;
299 for (int i = 0; i < kIntptrSize; i++) {
300 x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte;
301 }
302 rinfo_.data_ += x;
303}
304
305
306void RelocIterator::AdvanceReadVariableLengthPCJump() {
307 // Read the 32-kSmallPCDeltaBits most significant bits of the
308 // pc jump in kChunkBits bit chunks and shift them into place.
309 // Stop when the last chunk is encountered.
310 uint32_t pc_jump = 0;
311 for (int i = 0; i < kIntSize; i++) {
312 byte pc_jump_part = *--pos_;
313 pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits;
314 if ((pc_jump_part & kLastChunkTagMask) == 1) break;
315 }
316 // The least significant kSmallPCDeltaBits bits will be added
317 // later.
318 rinfo_.pc_ += pc_jump << kSmallPCDeltaBits;
319}
320
321
322inline int RelocIterator::GetPositionTypeTag() {
323 return *pos_ & ((1 << kPositionTypeTagBits) - 1);
324}
325
326
327inline void RelocIterator::ReadTaggedData() {
328 int8_t signed_b = *pos_;
329 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
330 rinfo_.data_ += signed_b >> kPositionTypeTagBits;
331}
332
333
334inline RelocInfo::Mode RelocIterator::DebugInfoModeFromTag(int tag) {
335 if (tag == kStatementPositionTag) {
336 return RelocInfo::STATEMENT_POSITION;
337 } else if (tag == kNonstatementPositionTag) {
338 return RelocInfo::POSITION;
339 } else {
340 ASSERT(tag == kCommentTag);
341 return RelocInfo::COMMENT;
342 }
343}
344
345
346void RelocIterator::next() {
347 ASSERT(!done());
348 // Basically, do the opposite of RelocInfoWriter::Write.
349 // Reading of data is as far as possible avoided for unwanted modes,
350 // but we must always update the pc.
351 //
352 // We exit this loop by returning when we find a mode we want.
353 while (pos_ > end_) {
354 int tag = AdvanceGetTag();
355 if (tag == kEmbeddedObjectTag) {
356 ReadTaggedPC();
357 if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return;
358 } else if (tag == kCodeTargetTag) {
359 ReadTaggedPC();
Steve Blocka7e24c12009-10-30 11:49:00 +0000360 if (SetMode(RelocInfo::CODE_TARGET)) return;
361 } else if (tag == kPositionTag) {
362 ReadTaggedPC();
363 Advance();
364 // Check if we want source positions.
365 if (mode_mask_ & RelocInfo::kPositionMask) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100366 ReadTaggedData();
367 if (SetMode(DebugInfoModeFromTag(GetPositionTypeTag()))) return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000368 }
369 } else {
370 ASSERT(tag == kDefaultTag);
371 int extra_tag = GetExtraTag();
372 if (extra_tag == kPCJumpTag) {
373 int top_tag = GetTopTag();
374 if (top_tag == kVariableLengthPCJumpTopTag) {
375 AdvanceReadVariableLengthPCJump();
376 } else {
377 AdvanceReadPC();
378 }
379 } else if (extra_tag == kDataJumpTag) {
380 // Check if we want debug modes (the only ones with data).
381 if (mode_mask_ & RelocInfo::kDebugMask) {
382 int top_tag = GetTopTag();
383 AdvanceReadData();
384 if (SetMode(DebugInfoModeFromTag(top_tag))) return;
385 } else {
386 // Otherwise, just skip over the data.
387 Advance(kIntptrSize);
388 }
389 } else {
390 AdvanceReadPC();
391 if (SetMode(static_cast<RelocInfo::Mode>(extra_tag))) return;
392 }
393 }
394 }
395 done_ = true;
396}
397
398
399RelocIterator::RelocIterator(Code* code, int mode_mask) {
400 rinfo_.pc_ = code->instruction_start();
401 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100402 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000403 pos_ = code->relocation_start() + code->relocation_size();
404 end_ = code->relocation_start();
405 done_ = false;
406 mode_mask_ = mode_mask;
407 if (mode_mask_ == 0) pos_ = end_;
408 next();
409}
410
411
412RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) {
413 rinfo_.pc_ = desc.buffer;
414 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100415 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000416 pos_ = desc.buffer + desc.buffer_size;
417 end_ = pos_ - desc.reloc_size;
418 done_ = false;
419 mode_mask_ = mode_mask;
420 if (mode_mask_ == 0) pos_ = end_;
421 next();
422}
423
424
425// -----------------------------------------------------------------------------
426// Implementation of RelocInfo
427
428
429#ifdef ENABLE_DISASSEMBLER
430const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
431 switch (rmode) {
432 case RelocInfo::NONE:
433 return "no reloc";
434 case RelocInfo::EMBEDDED_OBJECT:
435 return "embedded object";
Steve Blocka7e24c12009-10-30 11:49:00 +0000436 case RelocInfo::CONSTRUCT_CALL:
437 return "code target (js construct call)";
438 case RelocInfo::CODE_TARGET_CONTEXT:
439 return "code target (context)";
Andrei Popescu402d9372010-02-26 13:31:12 +0000440 case RelocInfo::DEBUG_BREAK:
441#ifndef ENABLE_DEBUGGER_SUPPORT
442 UNREACHABLE();
443#endif
444 return "debug break";
Steve Blocka7e24c12009-10-30 11:49:00 +0000445 case RelocInfo::CODE_TARGET:
446 return "code target";
Ben Murdochb0fe1622011-05-05 13:52:32 +0100447 case RelocInfo::GLOBAL_PROPERTY_CELL:
448 return "global property cell";
Steve Blocka7e24c12009-10-30 11:49:00 +0000449 case RelocInfo::RUNTIME_ENTRY:
450 return "runtime entry";
451 case RelocInfo::JS_RETURN:
452 return "js return";
453 case RelocInfo::COMMENT:
454 return "comment";
455 case RelocInfo::POSITION:
456 return "position";
457 case RelocInfo::STATEMENT_POSITION:
458 return "statement position";
459 case RelocInfo::EXTERNAL_REFERENCE:
460 return "external reference";
461 case RelocInfo::INTERNAL_REFERENCE:
462 return "internal reference";
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100463 case RelocInfo::DEBUG_BREAK_SLOT:
464#ifndef ENABLE_DEBUGGER_SUPPORT
465 UNREACHABLE();
466#endif
467 return "debug break slot";
Steve Blocka7e24c12009-10-30 11:49:00 +0000468 case RelocInfo::NUMBER_OF_MODES:
469 UNREACHABLE();
470 return "number_of_modes";
471 }
472 return "unknown relocation type";
473}
474
475
Ben Murdochb0fe1622011-05-05 13:52:32 +0100476void RelocInfo::Print(FILE* out) {
477 PrintF(out, "%p %s", pc_, RelocModeName(rmode_));
Steve Blocka7e24c12009-10-30 11:49:00 +0000478 if (IsComment(rmode_)) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100479 PrintF(out, " (%s)", reinterpret_cast<char*>(data_));
Steve Blocka7e24c12009-10-30 11:49:00 +0000480 } else if (rmode_ == EMBEDDED_OBJECT) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100481 PrintF(out, " (");
482 target_object()->ShortPrint(out);
483 PrintF(out, ")");
Steve Blocka7e24c12009-10-30 11:49:00 +0000484 } else if (rmode_ == EXTERNAL_REFERENCE) {
485 ExternalReferenceEncoder ref_encoder;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100486 PrintF(out, " (%s) (%p)",
Steve Blocka7e24c12009-10-30 11:49:00 +0000487 ref_encoder.NameOfAddress(*target_reference_address()),
488 *target_reference_address());
489 } else if (IsCodeTarget(rmode_)) {
490 Code* code = Code::GetCodeFromTargetAddress(target_address());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100491 PrintF(out, " (%s) (%p)", Code::Kind2String(code->kind()),
492 target_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000493 } else if (IsPosition(rmode_)) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100494 PrintF(out, " (%" V8_PTR_PREFIX "d)", data());
Ben Murdoch8b112d22011-06-08 16:22:53 +0100495 } else if (rmode_ == RelocInfo::RUNTIME_ENTRY &&
496 Isolate::Current()->deoptimizer_data() != NULL) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100497 // Depotimization bailouts are stored as runtime entries.
498 int id = Deoptimizer::GetDeoptimizationId(
499 target_address(), Deoptimizer::EAGER);
500 if (id != Deoptimizer::kNotDeoptimizationEntry) {
501 PrintF(out, " (deoptimization bailout %d)", id);
502 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000503 }
504
Ben Murdochb0fe1622011-05-05 13:52:32 +0100505 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000506}
507#endif // ENABLE_DISASSEMBLER
508
509
510#ifdef DEBUG
511void RelocInfo::Verify() {
512 switch (rmode_) {
513 case EMBEDDED_OBJECT:
514 Object::VerifyPointer(target_object());
515 break;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100516 case GLOBAL_PROPERTY_CELL:
517 Object::VerifyPointer(target_cell());
518 break;
Andrei Popescu402d9372010-02-26 13:31:12 +0000519 case DEBUG_BREAK:
520#ifndef ENABLE_DEBUGGER_SUPPORT
521 UNREACHABLE();
522 break;
523#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000524 case CONSTRUCT_CALL:
525 case CODE_TARGET_CONTEXT:
526 case CODE_TARGET: {
527 // convert inline target address to code object
528 Address addr = target_address();
529 ASSERT(addr != NULL);
530 // Check that we can find the right code object.
531 Code* code = Code::GetCodeFromTargetAddress(addr);
Steve Block44f0eee2011-05-26 01:26:41 +0100532 Object* found = HEAP->FindCodeObject(addr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000533 ASSERT(found->IsCode());
534 ASSERT(code->address() == HeapObject::cast(found)->address());
535 break;
536 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000537 case RUNTIME_ENTRY:
538 case JS_RETURN:
539 case COMMENT:
540 case POSITION:
541 case STATEMENT_POSITION:
542 case EXTERNAL_REFERENCE:
543 case INTERNAL_REFERENCE:
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100544 case DEBUG_BREAK_SLOT:
Steve Blocka7e24c12009-10-30 11:49:00 +0000545 case NONE:
546 break;
547 case NUMBER_OF_MODES:
548 UNREACHABLE();
549 break;
550 }
551}
552#endif // DEBUG
553
554
555// -----------------------------------------------------------------------------
556// Implementation of ExternalReference
557
Steve Block44f0eee2011-05-26 01:26:41 +0100558ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate)
559 : address_(Redirect(isolate, Builtins::c_function_address(id))) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000560
561
Steve Block1e0659c2011-05-24 12:43:12 +0100562ExternalReference::ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100563 ApiFunction* fun,
564 Type type = ExternalReference::BUILTIN_CALL,
565 Isolate* isolate = NULL)
566 : address_(Redirect(isolate, fun->address(), type)) {}
Steve Blockd0582a62009-12-15 09:54:21 +0000567
568
Steve Block44f0eee2011-05-26 01:26:41 +0100569ExternalReference::ExternalReference(Builtins::Name name, Isolate* isolate)
570 : address_(isolate->builtins()->builtin_address(name)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000571
572
Steve Block44f0eee2011-05-26 01:26:41 +0100573ExternalReference::ExternalReference(Runtime::FunctionId id,
574 Isolate* isolate)
575 : address_(Redirect(isolate, Runtime::FunctionForId(id)->entry)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000576
577
Steve Block44f0eee2011-05-26 01:26:41 +0100578ExternalReference::ExternalReference(const Runtime::Function* f,
579 Isolate* isolate)
580 : address_(Redirect(isolate, f->entry)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000581
582
Steve Block44f0eee2011-05-26 01:26:41 +0100583ExternalReference ExternalReference::isolate_address() {
584 return ExternalReference(Isolate::Current());
585}
586
587
588ExternalReference::ExternalReference(const IC_Utility& ic_utility,
589 Isolate* isolate)
590 : address_(Redirect(isolate, ic_utility.address())) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000591
592#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100593ExternalReference::ExternalReference(const Debug_Address& debug_address,
594 Isolate* isolate)
595 : address_(debug_address.address(isolate)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000596#endif
597
598ExternalReference::ExternalReference(StatsCounter* counter)
599 : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {}
600
601
Steve Block44f0eee2011-05-26 01:26:41 +0100602ExternalReference::ExternalReference(Isolate::AddressId id, Isolate* isolate)
603 : address_(isolate->get_address_from_id(id)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000604
605
606ExternalReference::ExternalReference(const SCTableReference& table_ref)
607 : address_(table_ref.address()) {}
608
609
Steve Block44f0eee2011-05-26 01:26:41 +0100610ExternalReference ExternalReference::perform_gc_function(Isolate* isolate) {
611 return ExternalReference(Redirect(isolate,
612 FUNCTION_ADDR(Runtime::PerformGC)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000613}
614
615
Steve Block44f0eee2011-05-26 01:26:41 +0100616ExternalReference ExternalReference::fill_heap_number_with_random_function(
617 Isolate* isolate) {
618 return ExternalReference(Redirect(
619 isolate,
620 FUNCTION_ADDR(V8::FillHeapNumberWithRandom)));
Steve Block6ded16b2010-05-10 14:33:55 +0100621}
622
623
Steve Block44f0eee2011-05-26 01:26:41 +0100624ExternalReference ExternalReference::delete_handle_scope_extensions(
625 Isolate* isolate) {
626 return ExternalReference(Redirect(
627 isolate,
628 FUNCTION_ADDR(HandleScope::DeleteExtensions)));
John Reck59135872010-11-02 12:39:01 -0700629}
630
631
Steve Block44f0eee2011-05-26 01:26:41 +0100632ExternalReference ExternalReference::random_uint32_function(
633 Isolate* isolate) {
634 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(V8::Random)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000635}
636
637
Steve Block44f0eee2011-05-26 01:26:41 +0100638ExternalReference ExternalReference::transcendental_cache_array_address(
639 Isolate* isolate) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100640 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100641 isolate->transcendental_cache()->cache_array_address());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100642}
643
644
Steve Block44f0eee2011-05-26 01:26:41 +0100645ExternalReference ExternalReference::new_deoptimizer_function(
646 Isolate* isolate) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100647 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100648 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::New)));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100649}
650
651
Steve Block44f0eee2011-05-26 01:26:41 +0100652ExternalReference ExternalReference::compute_output_frames_function(
653 Isolate* isolate) {
654 return ExternalReference(
655 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames)));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100656}
657
658
Steve Block44f0eee2011-05-26 01:26:41 +0100659ExternalReference ExternalReference::global_contexts_list(Isolate* isolate) {
660 return ExternalReference(isolate->heap()->global_contexts_list_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000661}
662
663
Steve Block44f0eee2011-05-26 01:26:41 +0100664ExternalReference ExternalReference::keyed_lookup_cache_keys(Isolate* isolate) {
665 return ExternalReference(isolate->keyed_lookup_cache()->keys_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000666}
667
668
Steve Block44f0eee2011-05-26 01:26:41 +0100669ExternalReference ExternalReference::keyed_lookup_cache_field_offsets(
670 Isolate* isolate) {
671 return ExternalReference(
672 isolate->keyed_lookup_cache()->field_offsets_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000673}
674
675
Steve Block44f0eee2011-05-26 01:26:41 +0100676ExternalReference ExternalReference::the_hole_value_location(Isolate* isolate) {
677 return ExternalReference(isolate->factory()->the_hole_value().location());
Ben Murdoch086aeea2011-05-13 15:57:08 +0100678}
679
680
Steve Block44f0eee2011-05-26 01:26:41 +0100681ExternalReference ExternalReference::arguments_marker_location(
682 Isolate* isolate) {
683 return ExternalReference(isolate->factory()->arguments_marker().location());
Steve Blocka7e24c12009-10-30 11:49:00 +0000684}
685
686
Steve Block44f0eee2011-05-26 01:26:41 +0100687ExternalReference ExternalReference::roots_address(Isolate* isolate) {
688 return ExternalReference(isolate->heap()->roots_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000689}
690
691
Steve Block44f0eee2011-05-26 01:26:41 +0100692ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) {
693 return ExternalReference(isolate->stack_guard()->address_of_jslimit());
Steve Blockd0582a62009-12-15 09:54:21 +0000694}
695
696
Steve Block44f0eee2011-05-26 01:26:41 +0100697ExternalReference ExternalReference::address_of_real_stack_limit(
698 Isolate* isolate) {
699 return ExternalReference(isolate->stack_guard()->address_of_real_jslimit());
Steve Blocka7e24c12009-10-30 11:49:00 +0000700}
701
702
Steve Block44f0eee2011-05-26 01:26:41 +0100703ExternalReference ExternalReference::address_of_regexp_stack_limit(
704 Isolate* isolate) {
705 return ExternalReference(isolate->regexp_stack()->limit_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000706}
707
708
Steve Block44f0eee2011-05-26 01:26:41 +0100709ExternalReference ExternalReference::new_space_start(Isolate* isolate) {
710 return ExternalReference(isolate->heap()->NewSpaceStart());
Andrei Popescu402d9372010-02-26 13:31:12 +0000711}
712
713
Steve Block44f0eee2011-05-26 01:26:41 +0100714ExternalReference ExternalReference::new_space_mask(Isolate* isolate) {
715 Address mask = reinterpret_cast<Address>(isolate->heap()->NewSpaceMask());
716 return ExternalReference(mask);
Steve Blocka7e24c12009-10-30 11:49:00 +0000717}
718
719
Steve Block44f0eee2011-05-26 01:26:41 +0100720ExternalReference ExternalReference::new_space_allocation_top_address(
721 Isolate* isolate) {
722 return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +0000723}
724
725
Steve Block44f0eee2011-05-26 01:26:41 +0100726ExternalReference ExternalReference::heap_always_allocate_scope_depth(
727 Isolate* isolate) {
728 Heap* heap = isolate->heap();
729 return ExternalReference(heap->always_allocate_scope_depth_address());
730}
731
732
733ExternalReference ExternalReference::new_space_allocation_limit_address(
734 Isolate* isolate) {
735 return ExternalReference(isolate->heap()->NewSpaceAllocationLimitAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +0000736}
737
Steve Blockd0582a62009-12-15 09:54:21 +0000738
John Reck59135872010-11-02 12:39:01 -0700739ExternalReference ExternalReference::handle_scope_level_address() {
740 return ExternalReference(HandleScope::current_level_address());
Steve Blockd0582a62009-12-15 09:54:21 +0000741}
742
743
744ExternalReference ExternalReference::handle_scope_next_address() {
745 return ExternalReference(HandleScope::current_next_address());
746}
747
748
749ExternalReference ExternalReference::handle_scope_limit_address() {
750 return ExternalReference(HandleScope::current_limit_address());
751}
752
753
Steve Block44f0eee2011-05-26 01:26:41 +0100754ExternalReference ExternalReference::scheduled_exception_address(
755 Isolate* isolate) {
756 return ExternalReference(isolate->scheduled_exception_address());
Steve Blockd0582a62009-12-15 09:54:21 +0000757}
758
759
Ben Murdochb0fe1622011-05-05 13:52:32 +0100760ExternalReference ExternalReference::address_of_min_int() {
761 return ExternalReference(reinterpret_cast<void*>(
762 const_cast<double*>(&DoubleConstant::min_int)));
763}
764
765
766ExternalReference ExternalReference::address_of_one_half() {
767 return ExternalReference(reinterpret_cast<void*>(
768 const_cast<double*>(&DoubleConstant::one_half)));
769}
770
771
Ben Murdochb8e0da22011-05-16 14:20:40 +0100772ExternalReference ExternalReference::address_of_minus_zero() {
773 return ExternalReference(reinterpret_cast<void*>(
774 const_cast<double*>(&DoubleConstant::minus_zero)));
775}
776
777
Ben Murdochb0fe1622011-05-05 13:52:32 +0100778ExternalReference ExternalReference::address_of_negative_infinity() {
779 return ExternalReference(reinterpret_cast<void*>(
780 const_cast<double*>(&DoubleConstant::negative_infinity)));
781}
782
783
Steve Block44f0eee2011-05-26 01:26:41 +0100784ExternalReference ExternalReference::address_of_nan() {
785 return ExternalReference(reinterpret_cast<void*>(
786 const_cast<double*>(&DoubleConstant::nan)));
787}
788
789
Steve Block6ded16b2010-05-10 14:33:55 +0100790#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000791
Steve Block44f0eee2011-05-26 01:26:41 +0100792ExternalReference ExternalReference::re_check_stack_guard_state(
793 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000794 Address function;
795#ifdef V8_TARGET_ARCH_X64
796 function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState);
797#elif V8_TARGET_ARCH_IA32
798 function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState);
799#elif V8_TARGET_ARCH_ARM
800 function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState);
Steve Block44f0eee2011-05-26 01:26:41 +0100801#elif V8_TARGET_ARCH_MIPS
802 function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState);
Steve Blocka7e24c12009-10-30 11:49:00 +0000803#else
Leon Clarke4515c472010-02-03 11:58:03 +0000804 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +0000805#endif
Steve Block44f0eee2011-05-26 01:26:41 +0100806 return ExternalReference(Redirect(isolate, function));
Steve Blocka7e24c12009-10-30 11:49:00 +0000807}
808
Steve Block44f0eee2011-05-26 01:26:41 +0100809ExternalReference ExternalReference::re_grow_stack(Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000810 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100811 Redirect(isolate, FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000812}
813
Steve Block44f0eee2011-05-26 01:26:41 +0100814ExternalReference ExternalReference::re_case_insensitive_compare_uc16(
815 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000816 return ExternalReference(Redirect(
Steve Block44f0eee2011-05-26 01:26:41 +0100817 isolate,
Steve Blocka7e24c12009-10-30 11:49:00 +0000818 FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16)));
819}
820
Leon Clarkee46be812010-01-19 14:06:41 +0000821ExternalReference ExternalReference::re_word_character_map() {
822 return ExternalReference(
823 NativeRegExpMacroAssembler::word_character_map_address());
824}
825
Steve Block44f0eee2011-05-26 01:26:41 +0100826ExternalReference ExternalReference::address_of_static_offsets_vector(
827 Isolate* isolate) {
828 return ExternalReference(
829 OffsetsVector::static_offsets_vector_address(isolate));
Leon Clarkee46be812010-01-19 14:06:41 +0000830}
831
Steve Block44f0eee2011-05-26 01:26:41 +0100832ExternalReference ExternalReference::address_of_regexp_stack_memory_address(
833 Isolate* isolate) {
834 return ExternalReference(
835 isolate->regexp_stack()->memory_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000836}
837
Steve Block44f0eee2011-05-26 01:26:41 +0100838ExternalReference ExternalReference::address_of_regexp_stack_memory_size(
839 Isolate* isolate) {
840 return ExternalReference(isolate->regexp_stack()->memory_size_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000841}
842
Steve Block6ded16b2010-05-10 14:33:55 +0100843#endif // V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000844
845
846static double add_two_doubles(double x, double y) {
847 return x + y;
848}
849
850
851static double sub_two_doubles(double x, double y) {
852 return x - y;
853}
854
855
856static double mul_two_doubles(double x, double y) {
857 return x * y;
858}
859
860
861static double div_two_doubles(double x, double y) {
862 return x / y;
863}
864
865
866static double mod_two_doubles(double x, double y) {
Leon Clarkee46be812010-01-19 14:06:41 +0000867 return modulo(x, y);
Steve Blocka7e24c12009-10-30 11:49:00 +0000868}
869
870
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100871static double math_sin_double(double x) {
872 return sin(x);
873}
874
875
876static double math_cos_double(double x) {
877 return cos(x);
878}
879
880
881static double math_log_double(double x) {
882 return log(x);
883}
884
885
Steve Block44f0eee2011-05-26 01:26:41 +0100886ExternalReference ExternalReference::math_sin_double_function(
887 Isolate* isolate) {
888 return ExternalReference(Redirect(isolate,
889 FUNCTION_ADDR(math_sin_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100890 FP_RETURN_CALL));
891}
892
893
Steve Block44f0eee2011-05-26 01:26:41 +0100894ExternalReference ExternalReference::math_cos_double_function(
895 Isolate* isolate) {
896 return ExternalReference(Redirect(isolate,
897 FUNCTION_ADDR(math_cos_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100898 FP_RETURN_CALL));
899}
900
901
Steve Block44f0eee2011-05-26 01:26:41 +0100902ExternalReference ExternalReference::math_log_double_function(
903 Isolate* isolate) {
904 return ExternalReference(Redirect(isolate,
905 FUNCTION_ADDR(math_log_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100906 FP_RETURN_CALL));
907}
908
909
Ben Murdochb0fe1622011-05-05 13:52:32 +0100910// Helper function to compute x^y, where y is known to be an
911// integer. Uses binary decomposition to limit the number of
912// multiplications; see the discussion in "Hacker's Delight" by Henry
913// S. Warren, Jr., figure 11-6, page 213.
914double power_double_int(double x, int y) {
915 double m = (y < 0) ? 1 / x : x;
916 unsigned n = (y < 0) ? -y : y;
917 double p = 1;
918 while (n != 0) {
919 if ((n & 1) != 0) p *= m;
920 m *= m;
921 if ((n & 2) != 0) p *= m;
922 m *= m;
923 n >>= 2;
924 }
925 return p;
926}
927
928
929double power_double_double(double x, double y) {
930 int y_int = static_cast<int>(y);
931 if (y == y_int) {
932 return power_double_int(x, y_int); // Returns 1.0 for exponent 0.
933 }
934 if (!isinf(x)) {
Steve Block1e0659c2011-05-24 12:43:12 +0100935 if (y == 0.5) return sqrt(x + 0.0); // -0 must be converted to +0.
936 if (y == -0.5) return 1.0 / sqrt(x + 0.0);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100937 }
938 if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) {
939 return OS::nan_value();
940 }
941 return pow(x, y);
942}
943
944
Steve Block44f0eee2011-05-26 01:26:41 +0100945ExternalReference ExternalReference::power_double_double_function(
946 Isolate* isolate) {
947 return ExternalReference(Redirect(isolate,
948 FUNCTION_ADDR(power_double_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100949 FP_RETURN_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100950}
951
952
Steve Block44f0eee2011-05-26 01:26:41 +0100953ExternalReference ExternalReference::power_double_int_function(
954 Isolate* isolate) {
955 return ExternalReference(Redirect(isolate,
956 FUNCTION_ADDR(power_double_int),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100957 FP_RETURN_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100958}
959
960
Leon Clarkee46be812010-01-19 14:06:41 +0000961static int native_compare_doubles(double y, double x) {
962 if (x == y) return EQUAL;
963 return x < y ? LESS : GREATER;
Steve Blocka7e24c12009-10-30 11:49:00 +0000964}
965
966
967ExternalReference ExternalReference::double_fp_operation(
Steve Block44f0eee2011-05-26 01:26:41 +0100968 Token::Value operation, Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000969 typedef double BinaryFPOperation(double x, double y);
970 BinaryFPOperation* function = NULL;
971 switch (operation) {
972 case Token::ADD:
973 function = &add_two_doubles;
974 break;
975 case Token::SUB:
976 function = &sub_two_doubles;
977 break;
978 case Token::MUL:
979 function = &mul_two_doubles;
980 break;
981 case Token::DIV:
982 function = &div_two_doubles;
983 break;
984 case Token::MOD:
985 function = &mod_two_doubles;
986 break;
987 default:
988 UNREACHABLE();
989 }
990 // Passing true as 2nd parameter indicates that they return an fp value.
Steve Block44f0eee2011-05-26 01:26:41 +0100991 return ExternalReference(Redirect(isolate,
992 FUNCTION_ADDR(function),
993 FP_RETURN_CALL));
Steve Blocka7e24c12009-10-30 11:49:00 +0000994}
995
996
Steve Block44f0eee2011-05-26 01:26:41 +0100997ExternalReference ExternalReference::compare_doubles(Isolate* isolate) {
998 return ExternalReference(Redirect(isolate,
999 FUNCTION_ADDR(native_compare_doubles),
Steve Block1e0659c2011-05-24 12:43:12 +01001000 BUILTIN_CALL));
Steve Blocka7e24c12009-10-30 11:49:00 +00001001}
1002
1003
Steve Blocka7e24c12009-10-30 11:49:00 +00001004#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +01001005ExternalReference ExternalReference::debug_break(Isolate* isolate) {
Ben Murdoch8b112d22011-06-08 16:22:53 +01001006 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(Debug_Break)));
Steve Blocka7e24c12009-10-30 11:49:00 +00001007}
1008
1009
Steve Block44f0eee2011-05-26 01:26:41 +01001010ExternalReference ExternalReference::debug_step_in_fp_address(
1011 Isolate* isolate) {
1012 return ExternalReference(isolate->debug()->step_in_fp_addr());
Steve Blocka7e24c12009-10-30 11:49:00 +00001013}
1014#endif
1015
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001016
Ben Murdochb0fe1622011-05-05 13:52:32 +01001017void PositionsRecorder::RecordPosition(int pos) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001018 ASSERT(pos != RelocInfo::kNoPosition);
1019 ASSERT(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001020 state_.current_position = pos;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001021#ifdef ENABLE_GDB_JIT_INTERFACE
1022 if (gdbjit_lineinfo_ != NULL) {
1023 gdbjit_lineinfo_->SetPosition(assembler_->pc_offset(), pos, false);
1024 }
1025#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001026}
1027
1028
1029void PositionsRecorder::RecordStatementPosition(int pos) {
1030 ASSERT(pos != RelocInfo::kNoPosition);
1031 ASSERT(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001032 state_.current_statement_position = pos;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001033#ifdef ENABLE_GDB_JIT_INTERFACE
1034 if (gdbjit_lineinfo_ != NULL) {
1035 gdbjit_lineinfo_->SetPosition(assembler_->pc_offset(), pos, true);
1036 }
1037#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001038}
1039
1040
1041bool PositionsRecorder::WriteRecordedPositions() {
1042 bool written = false;
1043
1044 // Write the statement position if it is different from what was written last
1045 // time.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001046 if (state_.current_statement_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001047 EnsureSpace ensure_space(assembler_);
1048 assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION,
Ben Murdochb0fe1622011-05-05 13:52:32 +01001049 state_.current_statement_position);
1050 state_.written_statement_position = state_.current_statement_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001051 written = true;
1052 }
1053
1054 // Write the position if it is different from what was written last time and
Ben Murdochb0fe1622011-05-05 13:52:32 +01001055 // also different from the written statement position.
1056 if (state_.current_position != state_.written_position &&
1057 state_.current_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001058 EnsureSpace ensure_space(assembler_);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001059 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position);
1060 state_.written_position = state_.current_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001061 written = true;
1062 }
1063
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001064 // Return whether something was written.
1065 return written;
1066}
1067
Steve Blocka7e24c12009-10-30 11:49:00 +00001068} } // namespace v8::internal