• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
33 // Copyright 2006-2009 the V8 project authors. All rights reserved.
34 
35 #include "v8.h"
36 
37 #include "arguments.h"
38 #include "execution.h"
39 #include "ic-inl.h"
40 #include "factory.h"
41 #include "runtime.h"
42 #include "serialize.h"
43 #include "stub-cache.h"
44 #include "regexp-stack.h"
45 #include "ast.h"
46 #include "regexp-macro-assembler.h"
47 // Include native regexp-macro-assembler.
48 #ifdef V8_NATIVE_REGEXP
49 #if V8_TARGET_ARCH_IA32
50 #include "ia32/regexp-macro-assembler-ia32.h"
51 #elif V8_TARGET_ARCH_X64
52 #include "x64/regexp-macro-assembler-x64.h"
53 #elif V8_TARGET_ARCH_ARM
54 #include "arm/regexp-macro-assembler-arm.h"
55 #else  // Unknown architecture.
56 #error "Unknown architecture."
57 #endif  // Target architecture.
58 #endif  // V8_NATIVE_REGEXP
59 
60 namespace v8 {
61 namespace internal {
62 
63 
64 // -----------------------------------------------------------------------------
65 // Implementation of Label
66 
pos() const67 int Label::pos() const {
68   if (pos_ < 0) return -pos_ - 1;
69   if (pos_ > 0) return  pos_ - 1;
70   UNREACHABLE();
71   return 0;
72 }
73 
74 
75 // -----------------------------------------------------------------------------
76 // Implementation of RelocInfoWriter and RelocIterator
77 //
78 // Encoding
79 //
80 // The most common modes are given single-byte encodings.  Also, it is
81 // easy to identify the type of reloc info and skip unwanted modes in
82 // an iteration.
83 //
84 // The encoding relies on the fact that there are less than 14
85 // different relocation modes.
86 //
87 // embedded_object:    [6 bits pc delta] 00
88 //
89 // code_taget:         [6 bits pc delta] 01
90 //
91 // position:           [6 bits pc delta] 10,
92 //                     [7 bits signed data delta] 0
93 //
94 // statement_position: [6 bits pc delta] 10,
95 //                     [7 bits signed data delta] 1
96 //
97 // any nondata mode:   00 [4 bits rmode] 11,  // rmode: 0..13 only
98 //                     00 [6 bits pc delta]
99 //
100 // pc-jump:            00 1111 11,
101 //                     00 [6 bits pc delta]
102 //
103 // pc-jump:            01 1111 11,
104 // (variable length)   7 - 26 bit pc delta, written in chunks of 7
105 //                     bits, the lowest 7 bits written first.
106 //
107 // data-jump + pos:    00 1110 11,
108 //                     signed intptr_t, lowest byte written first
109 //
110 // data-jump + st.pos: 01 1110 11,
111 //                     signed intptr_t, lowest byte written first
112 //
113 // data-jump + comm.:  10 1110 11,
114 //                     signed intptr_t, lowest byte written first
115 //
116 const int kMaxRelocModes = 14;
117 
118 const int kTagBits = 2;
119 const int kTagMask = (1 << kTagBits) - 1;
120 const int kExtraTagBits = 4;
121 const int kPositionTypeTagBits = 1;
122 const int kSmallDataBits = kBitsPerByte - kPositionTypeTagBits;
123 
124 const int kEmbeddedObjectTag = 0;
125 const int kCodeTargetTag = 1;
126 const int kPositionTag = 2;
127 const int kDefaultTag = 3;
128 
129 const int kPCJumpTag = (1 << kExtraTagBits) - 1;
130 
131 const int kSmallPCDeltaBits = kBitsPerByte - kTagBits;
132 const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1;
133 
134 const int kVariableLengthPCJumpTopTag = 1;
135 const int kChunkBits = 7;
136 const int kChunkMask = (1 << kChunkBits) - 1;
137 const int kLastChunkTagBits = 1;
138 const int kLastChunkTagMask = 1;
139 const int kLastChunkTag = 1;
140 
141 
142 const int kDataJumpTag = kPCJumpTag - 1;
143 
144 const int kNonstatementPositionTag = 0;
145 const int kStatementPositionTag = 1;
146 const int kCommentTag = 2;
147 
148 
WriteVariableLengthPCJump(uint32_t pc_delta)149 uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) {
150   // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
151   // Otherwise write a variable length PC jump for the bits that do
152   // not fit in the kSmallPCDeltaBits bits.
153   if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
154   WriteExtraTag(kPCJumpTag, kVariableLengthPCJumpTopTag);
155   uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
156   ASSERT(pc_jump > 0);
157   // Write kChunkBits size chunks of the pc_jump.
158   for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) {
159     byte b = pc_jump & kChunkMask;
160     *--pos_ = b << kLastChunkTagBits;
161   }
162   // Tag the last chunk so it can be identified.
163   *pos_ = *pos_ | kLastChunkTag;
164   // Return the remaining kSmallPCDeltaBits of the pc_delta.
165   return pc_delta & kSmallPCDeltaMask;
166 }
167 
168 
WriteTaggedPC(uint32_t pc_delta,int tag)169 void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) {
170   // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump.
171   pc_delta = WriteVariableLengthPCJump(pc_delta);
172   *--pos_ = pc_delta << kTagBits | tag;
173 }
174 
175 
WriteTaggedData(intptr_t data_delta,int tag)176 void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) {
177   *--pos_ = data_delta << kPositionTypeTagBits | tag;
178 }
179 
180 
WriteExtraTag(int extra_tag,int top_tag)181 void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) {
182   *--pos_ = top_tag << (kTagBits + kExtraTagBits) |
183             extra_tag << kTagBits |
184             kDefaultTag;
185 }
186 
187 
WriteExtraTaggedPC(uint32_t pc_delta,int extra_tag)188 void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) {
189   // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump.
190   pc_delta = WriteVariableLengthPCJump(pc_delta);
191   WriteExtraTag(extra_tag, 0);
192   *--pos_ = pc_delta;
193 }
194 
195 
WriteExtraTaggedData(intptr_t data_delta,int top_tag)196 void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) {
197   WriteExtraTag(kDataJumpTag, top_tag);
198   for (int i = 0; i < kIntptrSize; i++) {
199     *--pos_ = data_delta;
200   // Signed right shift is arithmetic shift.  Tested in test-utils.cc.
201     data_delta = data_delta >> kBitsPerByte;
202   }
203 }
204 
205 
Write(const RelocInfo * rinfo)206 void RelocInfoWriter::Write(const RelocInfo* rinfo) {
207 #ifdef DEBUG
208   byte* begin_pos = pos_;
209 #endif
210   Counters::reloc_info_count.Increment();
211   ASSERT(rinfo->pc() - last_pc_ >= 0);
212   ASSERT(RelocInfo::NUMBER_OF_MODES < kMaxRelocModes);
213   // Use unsigned delta-encoding for pc.
214   uint32_t pc_delta = rinfo->pc() - last_pc_;
215   RelocInfo::Mode rmode = rinfo->rmode();
216 
217   // The two most common modes are given small tags, and usually fit in a byte.
218   if (rmode == RelocInfo::EMBEDDED_OBJECT) {
219     WriteTaggedPC(pc_delta, kEmbeddedObjectTag);
220   } else if (rmode == RelocInfo::CODE_TARGET) {
221     WriteTaggedPC(pc_delta, kCodeTargetTag);
222   } else if (RelocInfo::IsPosition(rmode)) {
223     // Use signed delta-encoding for data.
224     intptr_t data_delta = rinfo->data() - last_data_;
225     int pos_type_tag = rmode == RelocInfo::POSITION ? kNonstatementPositionTag
226                                                     : kStatementPositionTag;
227     // Check if data is small enough to fit in a tagged byte.
228     // We cannot use is_intn because data_delta is not an int32_t.
229     if (data_delta >= -(1 << (kSmallDataBits-1)) &&
230         data_delta < 1 << (kSmallDataBits-1)) {
231       WriteTaggedPC(pc_delta, kPositionTag);
232       WriteTaggedData(data_delta, pos_type_tag);
233       last_data_ = rinfo->data();
234     } else {
235       // Otherwise, use costly encoding.
236       WriteExtraTaggedPC(pc_delta, kPCJumpTag);
237       WriteExtraTaggedData(data_delta, pos_type_tag);
238       last_data_ = rinfo->data();
239     }
240   } else if (RelocInfo::IsComment(rmode)) {
241     // Comments are normally not generated, so we use the costly encoding.
242     WriteExtraTaggedPC(pc_delta, kPCJumpTag);
243     WriteExtraTaggedData(rinfo->data() - last_data_, kCommentTag);
244     last_data_ = rinfo->data();
245   } else {
246     // For all other modes we simply use the mode as the extra tag.
247     // None of these modes need a data component.
248     ASSERT(rmode < kPCJumpTag && rmode < kDataJumpTag);
249     WriteExtraTaggedPC(pc_delta, rmode);
250   }
251   last_pc_ = rinfo->pc();
252 #ifdef DEBUG
253   ASSERT(begin_pos - pos_ <= kMaxSize);
254 #endif
255 }
256 
257 
AdvanceGetTag()258 inline int RelocIterator::AdvanceGetTag() {
259   return *--pos_ & kTagMask;
260 }
261 
262 
GetExtraTag()263 inline int RelocIterator::GetExtraTag() {
264   return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1);
265 }
266 
267 
GetTopTag()268 inline int RelocIterator::GetTopTag() {
269   return *pos_ >> (kTagBits + kExtraTagBits);
270 }
271 
272 
ReadTaggedPC()273 inline void RelocIterator::ReadTaggedPC() {
274   rinfo_.pc_ += *pos_ >> kTagBits;
275 }
276 
277 
AdvanceReadPC()278 inline void RelocIterator::AdvanceReadPC() {
279   rinfo_.pc_ += *--pos_;
280 }
281 
282 
AdvanceReadData()283 void RelocIterator::AdvanceReadData() {
284   intptr_t x = 0;
285   for (int i = 0; i < kIntptrSize; i++) {
286     x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte;
287   }
288   rinfo_.data_ += x;
289 }
290 
291 
AdvanceReadVariableLengthPCJump()292 void RelocIterator::AdvanceReadVariableLengthPCJump() {
293   // Read the 32-kSmallPCDeltaBits most significant bits of the
294   // pc jump in kChunkBits bit chunks and shift them into place.
295   // Stop when the last chunk is encountered.
296   uint32_t pc_jump = 0;
297   for (int i = 0; i < kIntSize; i++) {
298     byte pc_jump_part = *--pos_;
299     pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits;
300     if ((pc_jump_part & kLastChunkTagMask) == 1) break;
301   }
302   // The least significant kSmallPCDeltaBits bits will be added
303   // later.
304   rinfo_.pc_ += pc_jump << kSmallPCDeltaBits;
305 }
306 
307 
GetPositionTypeTag()308 inline int RelocIterator::GetPositionTypeTag() {
309   return *pos_ & ((1 << kPositionTypeTagBits) - 1);
310 }
311 
312 
ReadTaggedData()313 inline void RelocIterator::ReadTaggedData() {
314   int8_t signed_b = *pos_;
315   // Signed right shift is arithmetic shift.  Tested in test-utils.cc.
316   rinfo_.data_ += signed_b >> kPositionTypeTagBits;
317 }
318 
319 
DebugInfoModeFromTag(int tag)320 inline RelocInfo::Mode RelocIterator::DebugInfoModeFromTag(int tag) {
321   if (tag == kStatementPositionTag) {
322     return RelocInfo::STATEMENT_POSITION;
323   } else if (tag == kNonstatementPositionTag) {
324     return RelocInfo::POSITION;
325   } else {
326     ASSERT(tag == kCommentTag);
327     return RelocInfo::COMMENT;
328   }
329 }
330 
331 
next()332 void RelocIterator::next() {
333   ASSERT(!done());
334   // Basically, do the opposite of RelocInfoWriter::Write.
335   // Reading of data is as far as possible avoided for unwanted modes,
336   // but we must always update the pc.
337   //
338   // We exit this loop by returning when we find a mode we want.
339   while (pos_ > end_) {
340     int tag = AdvanceGetTag();
341     if (tag == kEmbeddedObjectTag) {
342       ReadTaggedPC();
343       if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return;
344     } else if (tag == kCodeTargetTag) {
345       ReadTaggedPC();
346       if (*(reinterpret_cast<int*>(rinfo_.pc())) == 0x61) {
347         tag = 0;
348       }
349       if (SetMode(RelocInfo::CODE_TARGET)) return;
350     } else if (tag == kPositionTag) {
351       ReadTaggedPC();
352       Advance();
353       // Check if we want source positions.
354       if (mode_mask_ & RelocInfo::kPositionMask) {
355         // Check if we want this type of source position.
356         if (SetMode(DebugInfoModeFromTag(GetPositionTypeTag()))) {
357           // Finally read the data before returning.
358           ReadTaggedData();
359           return;
360         }
361       }
362     } else {
363       ASSERT(tag == kDefaultTag);
364       int extra_tag = GetExtraTag();
365       if (extra_tag == kPCJumpTag) {
366         int top_tag = GetTopTag();
367         if (top_tag == kVariableLengthPCJumpTopTag) {
368           AdvanceReadVariableLengthPCJump();
369         } else {
370           AdvanceReadPC();
371         }
372       } else if (extra_tag == kDataJumpTag) {
373         // Check if we want debug modes (the only ones with data).
374         if (mode_mask_ & RelocInfo::kDebugMask) {
375           int top_tag = GetTopTag();
376           AdvanceReadData();
377           if (SetMode(DebugInfoModeFromTag(top_tag))) return;
378         } else {
379           // Otherwise, just skip over the data.
380           Advance(kIntptrSize);
381         }
382       } else {
383         AdvanceReadPC();
384         if (SetMode(static_cast<RelocInfo::Mode>(extra_tag))) return;
385       }
386     }
387   }
388   done_ = true;
389 }
390 
391 
RelocIterator(Code * code,int mode_mask)392 RelocIterator::RelocIterator(Code* code, int mode_mask) {
393   rinfo_.pc_ = code->instruction_start();
394   rinfo_.data_ = 0;
395   // relocation info is read backwards
396   pos_ = code->relocation_start() + code->relocation_size();
397   end_ = code->relocation_start();
398   done_ = false;
399   mode_mask_ = mode_mask;
400   if (mode_mask_ == 0) pos_ = end_;
401   next();
402 }
403 
404 
RelocIterator(const CodeDesc & desc,int mode_mask)405 RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) {
406   rinfo_.pc_ = desc.buffer;
407   rinfo_.data_ = 0;
408   // relocation info is read backwards
409   pos_ = desc.buffer + desc.buffer_size;
410   end_ = pos_ - desc.reloc_size;
411   done_ = false;
412   mode_mask_ = mode_mask;
413   if (mode_mask_ == 0) pos_ = end_;
414   next();
415 }
416 
417 
418 // -----------------------------------------------------------------------------
419 // Implementation of RelocInfo
420 
421 
422 #ifdef ENABLE_DISASSEMBLER
RelocModeName(RelocInfo::Mode rmode)423 const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
424   switch (rmode) {
425     case RelocInfo::NONE:
426       return "no reloc";
427     case RelocInfo::EMBEDDED_OBJECT:
428       return "embedded object";
429     case RelocInfo::EMBEDDED_STRING:
430       return "embedded string";
431     case RelocInfo::CONSTRUCT_CALL:
432       return "code target (js construct call)";
433     case RelocInfo::CODE_TARGET_CONTEXT:
434       return "code target (context)";
435     case RelocInfo::CODE_TARGET:
436       return "code target";
437     case RelocInfo::RUNTIME_ENTRY:
438       return "runtime entry";
439     case RelocInfo::JS_RETURN:
440       return "js return";
441     case RelocInfo::COMMENT:
442       return "comment";
443     case RelocInfo::POSITION:
444       return "position";
445     case RelocInfo::STATEMENT_POSITION:
446       return "statement position";
447     case RelocInfo::EXTERNAL_REFERENCE:
448       return "external reference";
449     case RelocInfo::INTERNAL_REFERENCE:
450       return "internal reference";
451     case RelocInfo::NUMBER_OF_MODES:
452       UNREACHABLE();
453       return "number_of_modes";
454   }
455   return "unknown relocation type";
456 }
457 
458 
Print()459 void RelocInfo::Print() {
460   PrintF("%p  %s", pc_, RelocModeName(rmode_));
461   if (IsComment(rmode_)) {
462     PrintF("  (%s)", data_);
463   } else if (rmode_ == EMBEDDED_OBJECT) {
464     PrintF("  (");
465     target_object()->ShortPrint();
466     PrintF(")");
467   } else if (rmode_ == EXTERNAL_REFERENCE) {
468     ExternalReferenceEncoder ref_encoder;
469     PrintF(" (%s)  (%p)",
470            ref_encoder.NameOfAddress(*target_reference_address()),
471            *target_reference_address());
472   } else if (IsCodeTarget(rmode_)) {
473     Code* code = Code::GetCodeFromTargetAddress(target_address());
474     PrintF(" (%s)  (%p)", Code::Kind2String(code->kind()), target_address());
475   } else if (IsPosition(rmode_)) {
476     PrintF("  (%d)", data());
477   }
478 
479   PrintF("\n");
480 }
481 #endif  // ENABLE_DISASSEMBLER
482 
483 
484 #ifdef DEBUG
Verify()485 void RelocInfo::Verify() {
486   switch (rmode_) {
487     case EMBEDDED_OBJECT:
488       Object::VerifyPointer(target_object());
489       break;
490     case CONSTRUCT_CALL:
491     case CODE_TARGET_CONTEXT:
492     case CODE_TARGET: {
493       // convert inline target address to code object
494       Address addr = target_address();
495       ASSERT(addr != NULL);
496       // Check that we can find the right code object.
497       HeapObject* code = HeapObject::FromAddress(addr - Code::kHeaderSize);
498       Object* found = Heap::FindCodeObject(addr);
499       ASSERT(found->IsCode());
500       ASSERT(code->address() == HeapObject::cast(found)->address());
501       break;
502     }
503     case RelocInfo::EMBEDDED_STRING:
504     case RUNTIME_ENTRY:
505     case JS_RETURN:
506     case COMMENT:
507     case POSITION:
508     case STATEMENT_POSITION:
509     case EXTERNAL_REFERENCE:
510     case INTERNAL_REFERENCE:
511     case NONE:
512       break;
513     case NUMBER_OF_MODES:
514       UNREACHABLE();
515       break;
516   }
517 }
518 #endif  // DEBUG
519 
520 
521 // -----------------------------------------------------------------------------
522 // Implementation of ExternalReference
523 
ExternalReference(Builtins::CFunctionId id)524 ExternalReference::ExternalReference(Builtins::CFunctionId id)
525   : address_(Redirect(Builtins::c_function_address(id))) {}
526 
527 
ExternalReference(Builtins::Name name)528 ExternalReference::ExternalReference(Builtins::Name name)
529   : address_(Builtins::builtin_address(name)) {}
530 
531 
ExternalReference(Runtime::FunctionId id)532 ExternalReference::ExternalReference(Runtime::FunctionId id)
533   : address_(Redirect(Runtime::FunctionForId(id)->entry)) {}
534 
535 
ExternalReference(Runtime::Function * f)536 ExternalReference::ExternalReference(Runtime::Function* f)
537   : address_(Redirect(f->entry)) {}
538 
539 
ExternalReference(const IC_Utility & ic_utility)540 ExternalReference::ExternalReference(const IC_Utility& ic_utility)
541   : address_(Redirect(ic_utility.address())) {}
542 
543 #ifdef ENABLE_DEBUGGER_SUPPORT
ExternalReference(const Debug_Address & debug_address)544 ExternalReference::ExternalReference(const Debug_Address& debug_address)
545   : address_(debug_address.address()) {}
546 #endif
547 
ExternalReference(StatsCounter * counter)548 ExternalReference::ExternalReference(StatsCounter* counter)
549   : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {}
550 
551 
ExternalReference(Top::AddressId id)552 ExternalReference::ExternalReference(Top::AddressId id)
553   : address_(Top::get_address_from_id(id)) {}
554 
555 
ExternalReference(const SCTableReference & table_ref)556 ExternalReference::ExternalReference(const SCTableReference& table_ref)
557   : address_(table_ref.address()) {}
558 
559 
perform_gc_function()560 ExternalReference ExternalReference::perform_gc_function() {
561   return ExternalReference(Redirect(FUNCTION_ADDR(Runtime::PerformGC)));
562 }
563 
564 
builtin_passed_function()565 ExternalReference ExternalReference::builtin_passed_function() {
566   return ExternalReference(&Builtins::builtin_passed_function);
567 }
568 
569 
random_positive_smi_function()570 ExternalReference ExternalReference::random_positive_smi_function() {
571   return ExternalReference(Redirect(FUNCTION_ADDR(V8::RandomPositiveSmi)));
572 }
573 
574 
the_hole_value_location()575 ExternalReference ExternalReference::the_hole_value_location() {
576   return ExternalReference(Factory::the_hole_value().location());
577 }
578 
579 
roots_address()580 ExternalReference ExternalReference::roots_address() {
581   return ExternalReference(Heap::roots_address());
582 }
583 
584 
address_of_stack_guard_limit()585 ExternalReference ExternalReference::address_of_stack_guard_limit() {
586   return ExternalReference(StackGuard::address_of_jslimit());
587 }
588 
589 
address_of_regexp_stack_limit()590 ExternalReference ExternalReference::address_of_regexp_stack_limit() {
591   return ExternalReference(RegExpStack::limit_address());
592 }
593 
594 
new_space_start()595 ExternalReference ExternalReference::new_space_start() {
596   return ExternalReference(Heap::NewSpaceStart());
597 }
598 
599 
new_space_allocation_top_address()600 ExternalReference ExternalReference::new_space_allocation_top_address() {
601   return ExternalReference(Heap::NewSpaceAllocationTopAddress());
602 }
603 
604 
heap_always_allocate_scope_depth()605 ExternalReference ExternalReference::heap_always_allocate_scope_depth() {
606   return ExternalReference(Heap::always_allocate_scope_depth_address());
607 }
608 
609 
new_space_allocation_limit_address()610 ExternalReference ExternalReference::new_space_allocation_limit_address() {
611   return ExternalReference(Heap::NewSpaceAllocationLimitAddress());
612 }
613 
614 #ifdef V8_NATIVE_REGEXP
615 
re_check_stack_guard_state()616 ExternalReference ExternalReference::re_check_stack_guard_state() {
617   Address function;
618 #ifdef V8_TARGET_ARCH_X64
619   function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState);
620 #elif V8_TARGET_ARCH_IA32
621   function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState);
622 #elif V8_TARGET_ARCH_ARM
623   function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState);
624 #else
625   UNREACHABLE("Unexpected architecture");
626 #endif
627   return ExternalReference(Redirect(function));
628 }
629 
re_grow_stack()630 ExternalReference ExternalReference::re_grow_stack() {
631   return ExternalReference(
632       Redirect(FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack)));
633 }
634 
re_case_insensitive_compare_uc16()635 ExternalReference ExternalReference::re_case_insensitive_compare_uc16() {
636   return ExternalReference(Redirect(
637       FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16)));
638 }
639 
640 #endif
641 
642 
add_two_doubles(double x,double y)643 static double add_two_doubles(double x, double y) {
644   return x + y;
645 }
646 
647 
sub_two_doubles(double x,double y)648 static double sub_two_doubles(double x, double y) {
649   return x - y;
650 }
651 
652 
mul_two_doubles(double x,double y)653 static double mul_two_doubles(double x, double y) {
654   return x * y;
655 }
656 
657 
div_two_doubles(double x,double y)658 static double div_two_doubles(double x, double y) {
659   return x / y;
660 }
661 
662 
mod_two_doubles(double x,double y)663 static double mod_two_doubles(double x, double y) {
664   return fmod(x, y);
665 }
666 
667 
native_compare_doubles(double x,double y)668 static int native_compare_doubles(double x, double y) {
669   if (x == y) return 0;
670   return x < y ? 1 : -1;
671 }
672 
673 
double_fp_operation(Token::Value operation)674 ExternalReference ExternalReference::double_fp_operation(
675     Token::Value operation) {
676   typedef double BinaryFPOperation(double x, double y);
677   BinaryFPOperation* function = NULL;
678   switch (operation) {
679     case Token::ADD:
680       function = &add_two_doubles;
681       break;
682     case Token::SUB:
683       function = &sub_two_doubles;
684       break;
685     case Token::MUL:
686       function = &mul_two_doubles;
687       break;
688     case Token::DIV:
689       function = &div_two_doubles;
690       break;
691     case Token::MOD:
692       function = &mod_two_doubles;
693       break;
694     default:
695       UNREACHABLE();
696   }
697   // Passing true as 2nd parameter indicates that they return an fp value.
698   return ExternalReference(Redirect(FUNCTION_ADDR(function), true));
699 }
700 
701 
compare_doubles()702 ExternalReference ExternalReference::compare_doubles() {
703   return ExternalReference(Redirect(FUNCTION_ADDR(native_compare_doubles),
704                                     false));
705 }
706 
707 
708 ExternalReferenceRedirector* ExternalReference::redirector_ = NULL;
709 
710 
711 #ifdef ENABLE_DEBUGGER_SUPPORT
debug_break()712 ExternalReference ExternalReference::debug_break() {
713   return ExternalReference(Redirect(FUNCTION_ADDR(Debug::Break)));
714 }
715 
716 
debug_step_in_fp_address()717 ExternalReference ExternalReference::debug_step_in_fp_address() {
718   return ExternalReference(Debug::step_in_fp_addr());
719 }
720 #endif
721 
722 } }  // namespace v8::internal
723