d86bc70dcf105399d1f0ba91cb2dbc605797601c
[platform/framework/web/crosswalk.git] / src / v8 / src / code-stubs.cc
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "v8.h"
29
30 #include "bootstrapper.h"
31 #include "code-stubs.h"
32 #include "cpu-profiler.h"
33 #include "stub-cache.h"
34 #include "factory.h"
35 #include "gdb-jit.h"
36 #include "macro-assembler.h"
37
38 namespace v8 {
39 namespace internal {
40
41
42 CodeStubInterfaceDescriptor::CodeStubInterfaceDescriptor()
43     : register_param_count_(-1),
44       stack_parameter_count_(no_reg),
45       hint_stack_parameter_count_(-1),
46       function_mode_(NOT_JS_FUNCTION_STUB_MODE),
47       register_params_(NULL),
48       deoptimization_handler_(NULL),
49       handler_arguments_mode_(DONT_PASS_ARGUMENTS),
50       miss_handler_(),
51       has_miss_handler_(false) { }
52
53
54 bool CodeStub::FindCodeInCache(Code** code_out, Isolate* isolate) {
55   UnseededNumberDictionary* stubs = isolate->heap()->code_stubs();
56   int index = stubs->FindEntry(GetKey());
57   if (index != UnseededNumberDictionary::kNotFound) {
58     *code_out = Code::cast(stubs->ValueAt(index));
59     return true;
60   }
61   return false;
62 }
63
64
65 SmartArrayPointer<const char> CodeStub::GetName() {
66   char buffer[100];
67   NoAllocationStringAllocator allocator(buffer,
68                                         static_cast<unsigned>(sizeof(buffer)));
69   StringStream stream(&allocator);
70   PrintName(&stream);
71   return stream.ToCString();
72 }
73
74
75 void CodeStub::RecordCodeGeneration(Code* code, Isolate* isolate) {
76   SmartArrayPointer<const char> name = GetName();
77   PROFILE(isolate, CodeCreateEvent(Logger::STUB_TAG, code, name.get()));
78   GDBJIT(AddCode(GDBJITInterface::STUB, name.get(), code));
79   Counters* counters = isolate->counters();
80   counters->total_stubs_code_size()->Increment(code->instruction_size());
81 }
82
83
84 Code::Kind CodeStub::GetCodeKind() const {
85   return Code::STUB;
86 }
87
88
89 Handle<Code> CodeStub::GetCodeCopyFromTemplate(Isolate* isolate) {
90   Handle<Code> ic = GetCode(isolate);
91   ic = isolate->factory()->CopyCode(ic);
92   RecordCodeGeneration(*ic, isolate);
93   return ic;
94 }
95
96
97 Handle<Code> PlatformCodeStub::GenerateCode(Isolate* isolate) {
98   Factory* factory = isolate->factory();
99
100   // Generate the new code.
101   MacroAssembler masm(isolate, NULL, 256);
102
103   {
104     // Update the static counter each time a new code stub is generated.
105     isolate->counters()->code_stubs()->Increment();
106
107     // Generate the code for the stub.
108     masm.set_generating_stub(true);
109     NoCurrentFrameScope scope(&masm);
110     Generate(&masm);
111   }
112
113   // Create the code object.
114   CodeDesc desc;
115   masm.GetCode(&desc);
116
117   // Copy the generated code into a heap object.
118   Code::Flags flags = Code::ComputeFlags(
119       GetCodeKind(),
120       GetICState(),
121       GetExtraICState(),
122       GetStubType(),
123       GetStubFlags());
124   Handle<Code> new_object = factory->NewCode(
125       desc, flags, masm.CodeObject(), NeedsImmovableCode());
126   return new_object;
127 }
128
129
130 void CodeStub::VerifyPlatformFeatures(Isolate* isolate) {
131   ASSERT(CpuFeatures::VerifyCrossCompiling());
132 }
133
134
135 Handle<Code> CodeStub::GetCode(Isolate* isolate) {
136   Factory* factory = isolate->factory();
137   Heap* heap = isolate->heap();
138   Code* code;
139   if (UseSpecialCache()
140       ? FindCodeInSpecialCache(&code, isolate)
141       : FindCodeInCache(&code, isolate)) {
142     ASSERT(GetCodeKind() == code->kind());
143     return Handle<Code>(code);
144   }
145
146 #ifdef DEBUG
147   VerifyPlatformFeatures(isolate);
148 #endif
149
150   {
151     HandleScope scope(isolate);
152
153     Handle<Code> new_object = GenerateCode(isolate);
154     new_object->set_major_key(MajorKey());
155     FinishCode(new_object);
156     RecordCodeGeneration(*new_object, isolate);
157
158 #ifdef ENABLE_DISASSEMBLER
159     if (FLAG_print_code_stubs) {
160       CodeTracer::Scope trace_scope(isolate->GetCodeTracer());
161       new_object->Disassemble(GetName().get(), trace_scope.file());
162       PrintF(trace_scope.file(), "\n");
163     }
164 #endif
165
166     if (UseSpecialCache()) {
167       AddToSpecialCache(new_object);
168     } else {
169       // Update the dictionary and the root in Heap.
170       Handle<UnseededNumberDictionary> dict =
171           factory->DictionaryAtNumberPut(
172               Handle<UnseededNumberDictionary>(heap->code_stubs()),
173               GetKey(),
174               new_object);
175       heap->public_set_code_stubs(*dict);
176     }
177     code = *new_object;
178   }
179
180   Activate(code);
181   ASSERT(!NeedsImmovableCode() ||
182          heap->lo_space()->Contains(code) ||
183          heap->code_space()->FirstPage()->Contains(code->address()));
184   return Handle<Code>(code, isolate);
185 }
186
187
188 const char* CodeStub::MajorName(CodeStub::Major major_key,
189                                 bool allow_unknown_keys) {
190   switch (major_key) {
191 #define DEF_CASE(name) case name: return #name "Stub";
192     CODE_STUB_LIST(DEF_CASE)
193 #undef DEF_CASE
194     case UninitializedMajorKey: return "<UninitializedMajorKey>Stub";
195     default:
196       if (!allow_unknown_keys) {
197         UNREACHABLE();
198       }
199       return NULL;
200   }
201 }
202
203
204 void CodeStub::PrintBaseName(StringStream* stream) {
205   stream->Add("%s", MajorName(MajorKey(), false));
206 }
207
208
209 void CodeStub::PrintName(StringStream* stream) {
210   PrintBaseName(stream);
211   PrintState(stream);
212 }
213
214
215 // static
216 void BinaryOpICStub::GenerateAheadOfTime(Isolate* isolate) {
217   // Generate the uninitialized versions of the stub.
218   for (int op = Token::BIT_OR; op <= Token::MOD; ++op) {
219     for (int mode = NO_OVERWRITE; mode <= OVERWRITE_RIGHT; ++mode) {
220       BinaryOpICStub stub(static_cast<Token::Value>(op),
221                           static_cast<OverwriteMode>(mode));
222       stub.GetCode(isolate);
223     }
224   }
225
226   // Generate special versions of the stub.
227   BinaryOpIC::State::GenerateAheadOfTime(isolate, &GenerateAheadOfTime);
228 }
229
230
231 void BinaryOpICStub::PrintState(StringStream* stream) {
232   state_.Print(stream);
233 }
234
235
236 // static
237 void BinaryOpICStub::GenerateAheadOfTime(Isolate* isolate,
238                                          const BinaryOpIC::State& state) {
239   BinaryOpICStub stub(state);
240   stub.GetCode(isolate);
241 }
242
243
244 // static
245 void BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(Isolate* isolate) {
246   // Generate special versions of the stub.
247   BinaryOpIC::State::GenerateAheadOfTime(isolate, &GenerateAheadOfTime);
248 }
249
250
251 void BinaryOpICWithAllocationSiteStub::PrintState(StringStream* stream) {
252   state_.Print(stream);
253 }
254
255
256 // static
257 void BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(
258     Isolate* isolate, const BinaryOpIC::State& state) {
259   if (state.CouldCreateAllocationMementos()) {
260     BinaryOpICWithAllocationSiteStub stub(state);
261     stub.GetCode(isolate);
262   }
263 }
264
265
266 void StringAddStub::PrintBaseName(StringStream* stream) {
267   stream->Add("StringAddStub");
268   if ((flags() & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) {
269     stream->Add("_CheckBoth");
270   } else if ((flags() & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) {
271     stream->Add("_CheckLeft");
272   } else if ((flags() & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) {
273     stream->Add("_CheckRight");
274   }
275   if (pretenure_flag() == TENURED) {
276     stream->Add("_Tenured");
277   }
278 }
279
280
281 InlineCacheState ICCompareStub::GetICState() {
282   CompareIC::State state = Max(left_, right_);
283   switch (state) {
284     case CompareIC::UNINITIALIZED:
285       return ::v8::internal::UNINITIALIZED;
286     case CompareIC::SMI:
287     case CompareIC::NUMBER:
288     case CompareIC::INTERNALIZED_STRING:
289     case CompareIC::STRING:
290     case CompareIC::UNIQUE_NAME:
291     case CompareIC::OBJECT:
292     case CompareIC::KNOWN_OBJECT:
293       return MONOMORPHIC;
294     case CompareIC::GENERIC:
295       return ::v8::internal::GENERIC;
296   }
297   UNREACHABLE();
298   return ::v8::internal::UNINITIALIZED;
299 }
300
301
302 void ICCompareStub::AddToSpecialCache(Handle<Code> new_object) {
303   ASSERT(*known_map_ != NULL);
304   Isolate* isolate = new_object->GetIsolate();
305   Factory* factory = isolate->factory();
306   return Map::UpdateCodeCache(known_map_,
307                               strict() ?
308                                   factory->strict_compare_ic_string() :
309                                   factory->compare_ic_string(),
310                               new_object);
311 }
312
313
314 bool ICCompareStub::FindCodeInSpecialCache(Code** code_out, Isolate* isolate) {
315   Factory* factory = isolate->factory();
316   Code::Flags flags = Code::ComputeFlags(
317       GetCodeKind(),
318       UNINITIALIZED);
319   ASSERT(op_ == Token::EQ || op_ == Token::EQ_STRICT);
320   Handle<Object> probe(
321       known_map_->FindInCodeCache(
322         strict() ?
323             *factory->strict_compare_ic_string() :
324             *factory->compare_ic_string(),
325         flags),
326       isolate);
327   if (probe->IsCode()) {
328     *code_out = Code::cast(*probe);
329 #ifdef DEBUG
330     Token::Value cached_op;
331     ICCompareStub::DecodeMinorKey((*code_out)->stub_info(), NULL, NULL, NULL,
332                                   &cached_op);
333     ASSERT(op_ == cached_op);
334 #endif
335     return true;
336   }
337   return false;
338 }
339
340
341 int ICCompareStub::MinorKey() {
342   return OpField::encode(op_ - Token::EQ) |
343          LeftStateField::encode(left_) |
344          RightStateField::encode(right_) |
345          HandlerStateField::encode(state_);
346 }
347
348
349 void ICCompareStub::DecodeMinorKey(int minor_key,
350                                    CompareIC::State* left_state,
351                                    CompareIC::State* right_state,
352                                    CompareIC::State* handler_state,
353                                    Token::Value* op) {
354   if (left_state) {
355     *left_state =
356         static_cast<CompareIC::State>(LeftStateField::decode(minor_key));
357   }
358   if (right_state) {
359     *right_state =
360         static_cast<CompareIC::State>(RightStateField::decode(minor_key));
361   }
362   if (handler_state) {
363     *handler_state =
364         static_cast<CompareIC::State>(HandlerStateField::decode(minor_key));
365   }
366   if (op) {
367     *op = static_cast<Token::Value>(OpField::decode(minor_key) + Token::EQ);
368   }
369 }
370
371
372 void ICCompareStub::Generate(MacroAssembler* masm) {
373   switch (state_) {
374     case CompareIC::UNINITIALIZED:
375       GenerateMiss(masm);
376       break;
377     case CompareIC::SMI:
378       GenerateSmis(masm);
379       break;
380     case CompareIC::NUMBER:
381       GenerateNumbers(masm);
382       break;
383     case CompareIC::STRING:
384       GenerateStrings(masm);
385       break;
386     case CompareIC::INTERNALIZED_STRING:
387       GenerateInternalizedStrings(masm);
388       break;
389     case CompareIC::UNIQUE_NAME:
390       GenerateUniqueNames(masm);
391       break;
392     case CompareIC::OBJECT:
393       GenerateObjects(masm);
394       break;
395     case CompareIC::KNOWN_OBJECT:
396       ASSERT(*known_map_ != NULL);
397       GenerateKnownObjects(masm);
398       break;
399     case CompareIC::GENERIC:
400       GenerateGeneric(masm);
401       break;
402   }
403 }
404
405
406 void CompareNilICStub::UpdateStatus(Handle<Object> object) {
407   ASSERT(!state_.Contains(GENERIC));
408   State old_state(state_);
409   if (object->IsNull()) {
410     state_.Add(NULL_TYPE);
411   } else if (object->IsUndefined()) {
412     state_.Add(UNDEFINED);
413   } else if (object->IsUndetectableObject() ||
414              object->IsOddball() ||
415              !object->IsHeapObject()) {
416     state_.RemoveAll();
417     state_.Add(GENERIC);
418   } else if (IsMonomorphic()) {
419     state_.RemoveAll();
420     state_.Add(GENERIC);
421   } else {
422     state_.Add(MONOMORPHIC_MAP);
423   }
424   TraceTransition(old_state, state_);
425 }
426
427
428 template<class StateType>
429 void HydrogenCodeStub::TraceTransition(StateType from, StateType to) {
430   // Note: Although a no-op transition is semantically OK, it is hinting at a
431   // bug somewhere in our state transition machinery.
432   ASSERT(from != to);
433   if (!FLAG_trace_ic) return;
434   char buffer[100];
435   NoAllocationStringAllocator allocator(buffer,
436                                         static_cast<unsigned>(sizeof(buffer)));
437   StringStream stream(&allocator);
438   stream.Add("[");
439   PrintBaseName(&stream);
440   stream.Add(": ");
441   from.Print(&stream);
442   stream.Add("=>");
443   to.Print(&stream);
444   stream.Add("]\n");
445   stream.OutputToStdOut();
446 }
447
448
449 void CompareNilICStub::PrintBaseName(StringStream* stream) {
450   CodeStub::PrintBaseName(stream);
451   stream->Add((nil_value_ == kNullValue) ? "(NullValue)":
452                                            "(UndefinedValue)");
453 }
454
455
456 void CompareNilICStub::PrintState(StringStream* stream) {
457   state_.Print(stream);
458 }
459
460
461 void CompareNilICStub::State::Print(StringStream* stream) const {
462   stream->Add("(");
463   SimpleListPrinter printer(stream);
464   if (IsEmpty()) printer.Add("None");
465   if (Contains(UNDEFINED)) printer.Add("Undefined");
466   if (Contains(NULL_TYPE)) printer.Add("Null");
467   if (Contains(MONOMORPHIC_MAP)) printer.Add("MonomorphicMap");
468   if (Contains(GENERIC)) printer.Add("Generic");
469   stream->Add(")");
470 }
471
472
473 Type* CompareNilICStub::GetType(Zone* zone, Handle<Map> map) {
474   if (state_.Contains(CompareNilICStub::GENERIC)) {
475     return Type::Any(zone);
476   }
477
478   Type* result = Type::None(zone);
479   if (state_.Contains(CompareNilICStub::UNDEFINED)) {
480     result = Type::Union(result, Type::Undefined(zone), zone);
481   }
482   if (state_.Contains(CompareNilICStub::NULL_TYPE)) {
483     result = Type::Union(result, Type::Null(zone), zone);
484   }
485   if (state_.Contains(CompareNilICStub::MONOMORPHIC_MAP)) {
486     Type* type =
487         map.is_null() ? Type::Detectable(zone) : Type::Class(map, zone);
488     result = Type::Union(result, type, zone);
489   }
490
491   return result;
492 }
493
494
495 Type* CompareNilICStub::GetInputType(Zone* zone, Handle<Map> map) {
496   Type* output_type = GetType(zone, map);
497   Type* nil_type =
498       nil_value_ == kNullValue ? Type::Null(zone) : Type::Undefined(zone);
499   return Type::Union(output_type, nil_type, zone);
500 }
501
502
503 void InstanceofStub::PrintName(StringStream* stream) {
504   const char* args = "";
505   if (HasArgsInRegisters()) {
506     args = "_REGS";
507   }
508
509   const char* inline_check = "";
510   if (HasCallSiteInlineCheck()) {
511     inline_check = "_INLINE";
512   }
513
514   const char* return_true_false_object = "";
515   if (ReturnTrueFalseObject()) {
516     return_true_false_object = "_TRUEFALSE";
517   }
518
519   stream->Add("InstanceofStub%s%s%s",
520               args,
521               inline_check,
522               return_true_false_object);
523 }
524
525
526 void JSEntryStub::FinishCode(Handle<Code> code) {
527   Handle<FixedArray> handler_table =
528       code->GetIsolate()->factory()->NewFixedArray(1, TENURED);
529   handler_table->set(0, Smi::FromInt(handler_offset_));
530   code->set_handler_table(*handler_table);
531 }
532
533
534 void KeyedLoadDictionaryElementPlatformStub::Generate(
535     MacroAssembler* masm) {
536   KeyedLoadStubCompiler::GenerateLoadDictionaryElement(masm);
537 }
538
539
540 void CreateAllocationSiteStub::GenerateAheadOfTime(Isolate* isolate) {
541   CreateAllocationSiteStub stub;
542   stub.GetCode(isolate);
543 }
544
545
546 void KeyedStoreElementStub::Generate(MacroAssembler* masm) {
547   switch (elements_kind_) {
548     case FAST_ELEMENTS:
549     case FAST_HOLEY_ELEMENTS:
550     case FAST_SMI_ELEMENTS:
551     case FAST_HOLEY_SMI_ELEMENTS:
552     case FAST_DOUBLE_ELEMENTS:
553     case FAST_HOLEY_DOUBLE_ELEMENTS:
554 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
555     case EXTERNAL_##TYPE##_ELEMENTS:                    \
556     case TYPE##_ELEMENTS:
557
558     TYPED_ARRAYS(TYPED_ARRAY_CASE)
559 #undef TYPED_ARRAY_CASE
560       UNREACHABLE();
561       break;
562     case DICTIONARY_ELEMENTS:
563       KeyedStoreStubCompiler::GenerateStoreDictionaryElement(masm);
564       break;
565     case NON_STRICT_ARGUMENTS_ELEMENTS:
566       UNREACHABLE();
567       break;
568   }
569 }
570
571
572 void ArgumentsAccessStub::PrintName(StringStream* stream) {
573   stream->Add("ArgumentsAccessStub_");
574   switch (type_) {
575     case READ_ELEMENT: stream->Add("ReadElement"); break;
576     case NEW_NON_STRICT_FAST: stream->Add("NewNonStrictFast"); break;
577     case NEW_NON_STRICT_SLOW: stream->Add("NewNonStrictSlow"); break;
578     case NEW_STRICT: stream->Add("NewStrict"); break;
579   }
580 }
581
582
583 void CallFunctionStub::PrintName(StringStream* stream) {
584   stream->Add("CallFunctionStub_Args%d", argc_);
585   if (RecordCallTarget()) stream->Add("_Recording");
586 }
587
588
589 void CallConstructStub::PrintName(StringStream* stream) {
590   stream->Add("CallConstructStub");
591   if (RecordCallTarget()) stream->Add("_Recording");
592 }
593
594
595 void ArrayConstructorStub::PrintName(StringStream* stream) {
596   stream->Add("ArrayConstructorStub");
597   switch (argument_count_) {
598     case ANY: stream->Add("_Any"); break;
599     case NONE: stream->Add("_None"); break;
600     case ONE: stream->Add("_One"); break;
601     case MORE_THAN_ONE: stream->Add("_More_Than_One"); break;
602   }
603 }
604
605
606 void ArrayConstructorStubBase::BasePrintName(const char* name,
607                                              StringStream* stream) {
608   stream->Add(name);
609   stream->Add("_");
610   stream->Add(ElementsKindToString(elements_kind()));
611   if (override_mode() == DISABLE_ALLOCATION_SITES) {
612     stream->Add("_DISABLE_ALLOCATION_SITES");
613   }
614 }
615
616
617 bool ToBooleanStub::UpdateStatus(Handle<Object> object) {
618   Types old_types(types_);
619   bool to_boolean_value = types_.UpdateStatus(object);
620   TraceTransition(old_types, types_);
621   return to_boolean_value;
622 }
623
624
625 void ToBooleanStub::PrintState(StringStream* stream) {
626   types_.Print(stream);
627 }
628
629
630 void ToBooleanStub::Types::Print(StringStream* stream) const {
631   stream->Add("(");
632   SimpleListPrinter printer(stream);
633   if (IsEmpty()) printer.Add("None");
634   if (Contains(UNDEFINED)) printer.Add("Undefined");
635   if (Contains(BOOLEAN)) printer.Add("Bool");
636   if (Contains(NULL_TYPE)) printer.Add("Null");
637   if (Contains(SMI)) printer.Add("Smi");
638   if (Contains(SPEC_OBJECT)) printer.Add("SpecObject");
639   if (Contains(STRING)) printer.Add("String");
640   if (Contains(SYMBOL)) printer.Add("Symbol");
641   if (Contains(HEAP_NUMBER)) printer.Add("HeapNumber");
642   stream->Add(")");
643 }
644
645
646 bool ToBooleanStub::Types::UpdateStatus(Handle<Object> object) {
647   if (object->IsUndefined()) {
648     Add(UNDEFINED);
649     return false;
650   } else if (object->IsBoolean()) {
651     Add(BOOLEAN);
652     return object->IsTrue();
653   } else if (object->IsNull()) {
654     Add(NULL_TYPE);
655     return false;
656   } else if (object->IsSmi()) {
657     Add(SMI);
658     return Smi::cast(*object)->value() != 0;
659   } else if (object->IsSpecObject()) {
660     Add(SPEC_OBJECT);
661     return !object->IsUndetectableObject();
662   } else if (object->IsString()) {
663     Add(STRING);
664     return !object->IsUndetectableObject() &&
665         String::cast(*object)->length() != 0;
666   } else if (object->IsSymbol()) {
667     Add(SYMBOL);
668     return true;
669   } else if (object->IsHeapNumber()) {
670     ASSERT(!object->IsUndetectableObject());
671     Add(HEAP_NUMBER);
672     double value = HeapNumber::cast(*object)->value();
673     return value != 0 && !std::isnan(value);
674   } else {
675     // We should never see an internal object at runtime here!
676     UNREACHABLE();
677     return true;
678   }
679 }
680
681
682 bool ToBooleanStub::Types::NeedsMap() const {
683   return Contains(ToBooleanStub::SPEC_OBJECT)
684       || Contains(ToBooleanStub::STRING)
685       || Contains(ToBooleanStub::SYMBOL)
686       || Contains(ToBooleanStub::HEAP_NUMBER);
687 }
688
689
690 bool ToBooleanStub::Types::CanBeUndetectable() const {
691   return Contains(ToBooleanStub::SPEC_OBJECT)
692       || Contains(ToBooleanStub::STRING);
693 }
694
695
696 void StubFailureTrampolineStub::GenerateAheadOfTime(Isolate* isolate) {
697   StubFailureTrampolineStub stub1(NOT_JS_FUNCTION_STUB_MODE);
698   StubFailureTrampolineStub stub2(JS_FUNCTION_STUB_MODE);
699   stub1.GetCode(isolate);
700   stub2.GetCode(isolate);
701 }
702
703
704 void ProfileEntryHookStub::EntryHookTrampoline(intptr_t function,
705                                                intptr_t stack_pointer,
706                                                Isolate* isolate) {
707   FunctionEntryHook entry_hook = isolate->function_entry_hook();
708   ASSERT(entry_hook != NULL);
709   entry_hook(function, stack_pointer);
710 }
711
712
713 static void InstallDescriptor(Isolate* isolate, HydrogenCodeStub* stub) {
714   int major_key = stub->MajorKey();
715   CodeStubInterfaceDescriptor* descriptor =
716       isolate->code_stub_interface_descriptor(major_key);
717   if (!descriptor->initialized()) {
718     stub->InitializeInterfaceDescriptor(isolate, descriptor);
719   }
720 }
721
722
723 void ArrayConstructorStubBase::InstallDescriptors(Isolate* isolate) {
724   ArrayNoArgumentConstructorStub stub1(GetInitialFastElementsKind());
725   InstallDescriptor(isolate, &stub1);
726   ArraySingleArgumentConstructorStub stub2(GetInitialFastElementsKind());
727   InstallDescriptor(isolate, &stub2);
728   ArrayNArgumentsConstructorStub stub3(GetInitialFastElementsKind());
729   InstallDescriptor(isolate, &stub3);
730 }
731
732
733 void NumberToStringStub::InstallDescriptors(Isolate* isolate) {
734   NumberToStringStub stub;
735   InstallDescriptor(isolate, &stub);
736 }
737
738
739 void FastNewClosureStub::InstallDescriptors(Isolate* isolate) {
740   FastNewClosureStub stub(STRICT_MODE, false);
741   InstallDescriptor(isolate, &stub);
742 }
743
744
745 void FastNewContextStub::InstallDescriptors(Isolate* isolate) {
746   FastNewContextStub stub(FastNewContextStub::kMaximumSlots);
747   InstallDescriptor(isolate, &stub);
748 }
749
750
751 // static
752 void BinaryOpICStub::InstallDescriptors(Isolate* isolate) {
753   BinaryOpICStub stub(Token::ADD, NO_OVERWRITE);
754   InstallDescriptor(isolate, &stub);
755 }
756
757
758 // static
759 void BinaryOpWithAllocationSiteStub::InstallDescriptors(Isolate* isolate) {
760   BinaryOpWithAllocationSiteStub stub(Token::ADD, NO_OVERWRITE);
761   InstallDescriptor(isolate, &stub);
762 }
763
764
765 // static
766 void StringAddStub::InstallDescriptors(Isolate* isolate) {
767   StringAddStub stub(STRING_ADD_CHECK_NONE, NOT_TENURED);
768   InstallDescriptor(isolate, &stub);
769 }
770
771
772 // static
773 void RegExpConstructResultStub::InstallDescriptors(Isolate* isolate) {
774   RegExpConstructResultStub stub;
775   InstallDescriptor(isolate, &stub);
776 }
777
778
779 ArrayConstructorStub::ArrayConstructorStub(Isolate* isolate)
780     : argument_count_(ANY) {
781   ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
782 }
783
784
785 ArrayConstructorStub::ArrayConstructorStub(Isolate* isolate,
786                                            int argument_count) {
787   if (argument_count == 0) {
788     argument_count_ = NONE;
789   } else if (argument_count == 1) {
790     argument_count_ = ONE;
791   } else if (argument_count >= 2) {
792     argument_count_ = MORE_THAN_ONE;
793   } else {
794     UNREACHABLE();
795   }
796   ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
797 }
798
799
800 void InternalArrayConstructorStubBase::InstallDescriptors(Isolate* isolate) {
801   InternalArrayNoArgumentConstructorStub stub1(FAST_ELEMENTS);
802   InstallDescriptor(isolate, &stub1);
803   InternalArraySingleArgumentConstructorStub stub2(FAST_ELEMENTS);
804   InstallDescriptor(isolate, &stub2);
805   InternalArrayNArgumentsConstructorStub stub3(FAST_ELEMENTS);
806   InstallDescriptor(isolate, &stub3);
807 }
808
809 InternalArrayConstructorStub::InternalArrayConstructorStub(
810     Isolate* isolate) {
811   InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
812 }
813
814
815 } }  // namespace v8::internal