1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef V8_CODE_STUBS_H_
6 #define V8_CODE_STUBS_H_
8 #include "src/allocation.h"
9 #include "src/assembler.h"
10 #include "src/codegen.h"
11 #include "src/globals.h"
12 #include "src/ic/ic-state.h"
13 #include "src/interface-descriptors.h"
14 #include "src/macro-assembler.h"
15 #include "src/ostreams.h"
20 // List of code stubs used on all platforms.
21 #define CODE_STUB_LIST_ALL_PLATFORMS(V) \
22 /* PlatformCodeStubs */ \
25 V(BinaryOpICWithAllocationSite) \
36 V(FunctionPrototype) \
38 V(InternalArrayConstructor) \
40 V(KeyedLoadICTrampoline) \
43 V(CallIC_ArrayTrampoline) \
44 V(LoadIndexedInterceptor) \
45 V(LoadIndexedString) \
50 V(StoreArrayLiteralElement) \
51 V(StoreBufferOverflow) \
54 V(StubFailureTrampoline) \
57 /* HydrogenCodeStubs */ \
58 V(AllocateHeapNumber) \
59 V(ArrayNArgumentsConstructor) \
60 V(ArrayNoArgumentConstructor) \
61 V(ArraySingleArgumentConstructor) \
63 V(BinaryOpWithAllocationSite) \
65 V(CreateAllocationSite) \
67 V(ElementsTransitionAndStore) \
68 V(FastCloneShallowArray) \
69 V(FastCloneShallowObject) \
72 V(InternalArrayNArgumentsConstructor) \
73 V(InternalArrayNoArgumentConstructor) \
74 V(InternalArraySingleArgumentConstructor) \
76 V(LoadScriptContextField) \
77 V(LoadDictionaryElement) \
80 V(NameDictionaryLookup) \
82 V(RegExpConstructResult) \
84 V(StoreScriptContextField) \
87 V(TransitionElementsKind) \
90 /* IC Handler stubs */ \
93 V(KeyedLoadSloppyArguments) \
100 // List of code stubs only used on ARM 32 bits platforms.
101 #if V8_TARGET_ARCH_ARM
102 #define CODE_STUB_LIST_ARM(V) V(DirectCEntry)
105 #define CODE_STUB_LIST_ARM(V)
108 // List of code stubs only used on ARM 64 bits platforms.
109 #if V8_TARGET_ARCH_ARM64
110 #define CODE_STUB_LIST_ARM64(V) \
112 V(RestoreRegistersState) \
113 V(StoreRegistersState)
116 #define CODE_STUB_LIST_ARM64(V)
119 // List of code stubs only used on PPC platforms.
120 #ifdef V8_TARGET_ARCH_PPC
121 #define CODE_STUB_LIST_PPC(V) \
123 V(StoreRegistersState) \
124 V(RestoreRegistersState)
126 #define CODE_STUB_LIST_PPC(V)
129 // List of code stubs only used on MIPS platforms.
130 #if V8_TARGET_ARCH_MIPS
131 #define CODE_STUB_LIST_MIPS(V) \
133 V(RestoreRegistersState) \
134 V(StoreRegistersState)
135 #elif V8_TARGET_ARCH_MIPS64
136 #define CODE_STUB_LIST_MIPS(V) \
138 V(RestoreRegistersState) \
139 V(StoreRegistersState)
141 #define CODE_STUB_LIST_MIPS(V)
144 // Combined list of code stubs.
145 #define CODE_STUB_LIST(V) \
146 CODE_STUB_LIST_ALL_PLATFORMS(V) \
147 CODE_STUB_LIST_ARM(V) \
148 CODE_STUB_LIST_ARM64(V) \
149 CODE_STUB_LIST_PPC(V) \
150 CODE_STUB_LIST_MIPS(V)
152 // Stub is base classes of all stubs.
153 class CodeStub BASE_EMBEDDED {
156 // TODO(mvstanton): eliminate the NoCache key by getting rid
157 // of the non-monomorphic-cache.
158 NoCache = 0, // marker for stubs that do custom caching]
159 #define DEF_ENUM(name) name,
160 CODE_STUB_LIST(DEF_ENUM)
165 // Retrieve the code for the stub. Generate the code if needed.
166 Handle<Code> GetCode();
168 // Retrieve the code for the stub, make and return a copy of the code.
169 Handle<Code> GetCodeCopy(const Code::FindAndReplacePattern& pattern);
171 static Major MajorKeyFromKey(uint32_t key) {
172 return static_cast<Major>(MajorKeyBits::decode(key));
174 static uint32_t MinorKeyFromKey(uint32_t key) {
175 return MinorKeyBits::decode(key);
178 // Gets the major key from a code object that is a code stub or binary op IC.
179 static Major GetMajorKey(Code* code_stub) {
180 return MajorKeyFromKey(code_stub->stub_key());
183 static uint32_t NoCacheKey() { return MajorKeyBits::encode(NoCache); }
185 static const char* MajorName(Major major_key, bool allow_unknown_keys);
187 explicit CodeStub(Isolate* isolate) : minor_key_(0), isolate_(isolate) {}
188 virtual ~CodeStub() {}
190 static void GenerateStubsAheadOfTime(Isolate* isolate);
191 static void GenerateFPStubs(Isolate* isolate);
193 // Some stubs put untagged junk on the stack that cannot be scanned by the
194 // GC. This means that we must be statically sure that no GC can occur while
195 // they are running. If that is the case they should override this to return
196 // true, which will cause an assertion if we try to call something that can
197 // GC or if we try to put a stack frame on top of the junk, which would not
198 // result in a traversable stack.
199 virtual bool SometimesSetsUpAFrame() { return true; }
201 // Lookup the code in the (possibly custom) cache.
202 bool FindCodeInCache(Code** code_out);
204 virtual CallInterfaceDescriptor GetCallInterfaceDescriptor() = 0;
206 virtual void InitializeDescriptor(CodeStubDescriptor* descriptor) {}
208 static void InitializeDescriptor(Isolate* isolate, uint32_t key,
209 CodeStubDescriptor* desc);
211 static MaybeHandle<Code> GetCode(Isolate* isolate, uint32_t key);
213 // Returns information for computing the number key.
214 virtual Major MajorKey() const = 0;
215 uint32_t MinorKey() const { return minor_key_; }
217 // BinaryOpStub needs to override this.
218 virtual Code::Kind GetCodeKind() const;
220 virtual InlineCacheState GetICState() const { return UNINITIALIZED; }
221 virtual ExtraICState GetExtraICState() const { return kNoExtraICState; }
222 virtual Code::StubType GetStubType() const { return Code::NORMAL; }
224 friend std::ostream& operator<<(std::ostream& os, const CodeStub& s) {
229 Isolate* isolate() const { return isolate_; }
232 CodeStub(uint32_t key, Isolate* isolate)
233 : minor_key_(MinorKeyFromKey(key)), isolate_(isolate) {}
235 // Generates the assembler code for the stub.
236 virtual Handle<Code> GenerateCode() = 0;
238 // Returns whether the code generated for this stub needs to be allocated as
239 // a fixed (non-moveable) code object.
240 virtual bool NeedsImmovableCode() { return false; }
242 virtual void PrintName(std::ostream& os) const; // NOLINT
243 virtual void PrintBaseName(std::ostream& os) const; // NOLINT
244 virtual void PrintState(std::ostream& os) const { ; } // NOLINT
246 // Computes the key based on major and minor.
248 DCHECK(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
249 return MinorKeyBits::encode(MinorKey()) | MajorKeyBits::encode(MajorKey());
255 // Perform bookkeeping required after code generation when stub code is
256 // initially generated.
257 void RecordCodeGeneration(Handle<Code> code);
259 // Finish the code object after it has been generated.
260 virtual void FinishCode(Handle<Code> code) { }
262 // Activate newly generated stub. Is called after
263 // registering stub in the stub cache.
264 virtual void Activate(Code* code) { }
266 // Add the code to a specialized cache, specific to an individual
267 // stub type. Please note, this method must add the code object to a
268 // roots object, otherwise we will remove the code during GC.
269 virtual void AddToSpecialCache(Handle<Code> new_object) { }
271 // Find code in a specialized cache, work is delegated to the specific stub.
272 virtual bool FindCodeInSpecialCache(Code** code_out) {
276 // If a stub uses a special cache override this.
277 virtual bool UseSpecialCache() { return false; }
279 // We use this dispatch to statically instantiate the correct code stub for
280 // the given stub key and call the passed function with that code stub.
281 typedef void (*DispatchedCall)(CodeStub* stub, void** value_out);
282 static void Dispatch(Isolate* isolate, uint32_t key, void** value_out,
283 DispatchedCall call);
285 static void GetCodeDispatchCall(CodeStub* stub, void** value_out);
287 STATIC_ASSERT(NUMBER_OF_IDS < (1 << kStubMajorKeyBits));
288 class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {};
289 class MinorKeyBits: public BitField<uint32_t,
290 kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT
292 friend class BreakPointIterator;
298 // TODO(svenpanne) This class is only used to construct a more or less sensible
299 // CompilationInfo for testing purposes, basically pretending that we are
300 // currently compiling some kind of code stub. Remove this when the pipeline and
301 // testing machinery is restructured in such a way that we don't have to come up
302 // with a CompilationInfo out of thin air, although we only need a few parts of
304 struct FakeStubForTesting : public CodeStub {
305 explicit FakeStubForTesting(Isolate* isolate) : CodeStub(isolate) {}
307 // Only used by pipeline.cc's GetDebugName in DEBUG mode.
308 Major MajorKey() const OVERRIDE { return CodeStub::NoCache; }
310 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE {
312 return CallInterfaceDescriptor();
315 Handle<Code> GenerateCode() OVERRIDE {
317 return Handle<Code>();
322 #define DEFINE_CODE_STUB_BASE(NAME, SUPER) \
324 NAME(uint32_t key, Isolate* isolate) : SUPER(key, isolate) {} \
327 DISALLOW_COPY_AND_ASSIGN(NAME)
330 #define DEFINE_CODE_STUB(NAME, SUPER) \
332 inline Major MajorKey() const OVERRIDE { return NAME; }; \
333 DEFINE_CODE_STUB_BASE(NAME##Stub, SUPER)
336 #define DEFINE_PLATFORM_CODE_STUB(NAME, SUPER) \
338 void Generate(MacroAssembler* masm) OVERRIDE; \
339 DEFINE_CODE_STUB(NAME, SUPER)
342 #define DEFINE_HYDROGEN_CODE_STUB(NAME, SUPER) \
344 void InitializeDescriptor(CodeStubDescriptor* descriptor) OVERRIDE; \
345 Handle<Code> GenerateCode() OVERRIDE; \
346 DEFINE_CODE_STUB(NAME, SUPER)
348 #define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \
350 Handle<Code> GenerateCode() OVERRIDE; \
351 DEFINE_CODE_STUB(NAME, SUPER)
353 #define DEFINE_CALL_INTERFACE_DESCRIPTOR(NAME) \
355 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE { \
356 return NAME##Descriptor(isolate()); \
359 // There are some code stubs we just can't describe right now with a
360 // CallInterfaceDescriptor. Isolate behavior for those cases with this macro.
361 // An attempt to retrieve a descriptor will fail.
362 #define DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR() \
364 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE { \
366 return CallInterfaceDescriptor(); \
370 class PlatformCodeStub : public CodeStub {
372 // Retrieve the code for the stub. Generate the code if needed.
373 Handle<Code> GenerateCode() OVERRIDE;
375 Code::Kind GetCodeKind() const OVERRIDE { return Code::STUB; }
378 explicit PlatformCodeStub(Isolate* isolate) : CodeStub(isolate) {}
380 // Generates the assembler code for the stub.
381 virtual void Generate(MacroAssembler* masm) = 0;
383 DEFINE_CODE_STUB_BASE(PlatformCodeStub, CodeStub);
387 enum StubFunctionMode { NOT_JS_FUNCTION_STUB_MODE, JS_FUNCTION_STUB_MODE };
388 enum HandlerArgumentsMode { DONT_PASS_ARGUMENTS, PASS_ARGUMENTS };
391 class CodeStubDescriptor {
393 explicit CodeStubDescriptor(CodeStub* stub);
395 CodeStubDescriptor(Isolate* isolate, uint32_t stub_key);
397 void Initialize(Address deoptimization_handler = NULL,
398 int hint_stack_parameter_count = -1,
399 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
400 void Initialize(Register stack_parameter_count,
401 Address deoptimization_handler = NULL,
402 int hint_stack_parameter_count = -1,
403 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE,
404 HandlerArgumentsMode handler_mode = DONT_PASS_ARGUMENTS);
406 void SetMissHandler(ExternalReference handler) {
407 miss_handler_ = handler;
408 has_miss_handler_ = true;
409 // Our miss handler infrastructure doesn't currently support
410 // variable stack parameter counts.
411 DCHECK(!stack_parameter_count_.is_valid());
414 void set_call_descriptor(CallInterfaceDescriptor d) { call_descriptor_ = d; }
415 CallInterfaceDescriptor call_descriptor() const { return call_descriptor_; }
417 int GetEnvironmentParameterCount() const {
418 return call_descriptor().GetEnvironmentParameterCount();
421 Representation GetEnvironmentParameterRepresentation(int index) const {
422 return call_descriptor().GetEnvironmentParameterRepresentation(index);
425 ExternalReference miss_handler() const {
426 DCHECK(has_miss_handler_);
427 return miss_handler_;
430 bool has_miss_handler() const {
431 return has_miss_handler_;
434 bool IsEnvironmentParameterCountRegister(int index) const {
435 return call_descriptor().GetEnvironmentParameterRegister(index).is(
436 stack_parameter_count_);
439 int GetHandlerParameterCount() const {
440 int params = call_descriptor().GetEnvironmentParameterCount();
441 if (handler_arguments_mode_ == PASS_ARGUMENTS) {
447 int hint_stack_parameter_count() const { return hint_stack_parameter_count_; }
448 Register stack_parameter_count() const { return stack_parameter_count_; }
449 StubFunctionMode function_mode() const { return function_mode_; }
450 Address deoptimization_handler() const { return deoptimization_handler_; }
453 CallInterfaceDescriptor call_descriptor_;
454 Register stack_parameter_count_;
455 // If hint_stack_parameter_count_ > 0, the code stub can optimize the
456 // return sequence. Default value is -1, which means it is ignored.
457 int hint_stack_parameter_count_;
458 StubFunctionMode function_mode_;
460 Address deoptimization_handler_;
461 HandlerArgumentsMode handler_arguments_mode_;
463 ExternalReference miss_handler_;
464 bool has_miss_handler_;
468 class HydrogenCodeStub : public CodeStub {
470 enum InitializationState {
475 Code::Kind GetCodeKind() const OVERRIDE { return Code::STUB; }
477 template<class SubClass>
478 static Handle<Code> GetUninitialized(Isolate* isolate) {
479 SubClass::GenerateAheadOfTime(isolate);
480 return SubClass().GetCode(isolate);
483 // Retrieve the code for the stub. Generate the code if needed.
484 Handle<Code> GenerateCode() OVERRIDE = 0;
486 bool IsUninitialized() const { return IsMissBits::decode(minor_key_); }
488 Handle<Code> GenerateLightweightMissCode(ExternalReference miss);
490 template<class StateType>
491 void TraceTransition(StateType from, StateType to);
494 explicit HydrogenCodeStub(Isolate* isolate,
495 InitializationState state = INITIALIZED)
496 : CodeStub(isolate) {
497 minor_key_ = IsMissBits::encode(state == UNINITIALIZED);
500 void set_sub_minor_key(uint32_t key) {
501 minor_key_ = SubMinorKeyBits::update(minor_key_, key);
504 uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
506 static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
509 class IsMissBits : public BitField<bool, kSubMinorKeyBits, 1> {};
510 class SubMinorKeyBits : public BitField<int, 0, kSubMinorKeyBits> {};
512 void GenerateLightweightMiss(MacroAssembler* masm, ExternalReference miss);
514 DEFINE_CODE_STUB_BASE(HydrogenCodeStub, CodeStub);
518 // Helper interface to prepare to/restore after making runtime calls.
519 class RuntimeCallHelper {
521 virtual ~RuntimeCallHelper() {}
523 virtual void BeforeCall(MacroAssembler* masm) const = 0;
525 virtual void AfterCall(MacroAssembler* masm) const = 0;
528 RuntimeCallHelper() {}
531 DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper);
535 } } // namespace v8::internal
537 #if V8_TARGET_ARCH_IA32
538 #include "src/ia32/code-stubs-ia32.h"
539 #elif V8_TARGET_ARCH_X64
540 #include "src/x64/code-stubs-x64.h"
541 #elif V8_TARGET_ARCH_ARM64
542 #include "src/arm64/code-stubs-arm64.h"
543 #elif V8_TARGET_ARCH_ARM
544 #include "src/arm/code-stubs-arm.h"
545 #elif V8_TARGET_ARCH_PPC
546 #include "src/ppc/code-stubs-ppc.h"
547 #elif V8_TARGET_ARCH_MIPS
548 #include "src/mips/code-stubs-mips.h"
549 #elif V8_TARGET_ARCH_MIPS64
550 #include "src/mips64/code-stubs-mips64.h"
551 #elif V8_TARGET_ARCH_X87
552 #include "src/x87/code-stubs-x87.h"
554 #error Unsupported target architecture.
561 // RuntimeCallHelper implementation used in stubs: enters/leaves a
562 // newly created internal frame before/after the runtime call.
563 class StubRuntimeCallHelper : public RuntimeCallHelper {
565 StubRuntimeCallHelper() {}
567 virtual void BeforeCall(MacroAssembler* masm) const;
569 virtual void AfterCall(MacroAssembler* masm) const;
573 // Trivial RuntimeCallHelper implementation.
574 class NopRuntimeCallHelper : public RuntimeCallHelper {
576 NopRuntimeCallHelper() {}
578 virtual void BeforeCall(MacroAssembler* masm) const {}
580 virtual void AfterCall(MacroAssembler* masm) const {}
584 class NumberToStringStub FINAL : public HydrogenCodeStub {
586 explicit NumberToStringStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
588 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
589 static const int kNumber = 0;
591 DEFINE_CALL_INTERFACE_DESCRIPTOR(NumberToString);
592 DEFINE_HYDROGEN_CODE_STUB(NumberToString, HydrogenCodeStub);
596 class FastNewClosureStub : public HydrogenCodeStub {
598 FastNewClosureStub(Isolate* isolate, LanguageMode language_mode,
600 : HydrogenCodeStub(isolate) {
601 DCHECK(IsValidFunctionKind(kind));
602 set_sub_minor_key(LanguageModeBits::encode(language_mode) |
603 FunctionKindBits::encode(kind));
606 LanguageMode language_mode() const {
607 return LanguageModeBits::decode(sub_minor_key());
610 FunctionKind kind() const {
611 return FunctionKindBits::decode(sub_minor_key());
615 STATIC_ASSERT(LANGUAGE_END == 3);
616 class LanguageModeBits : public BitField<LanguageMode, 0, 2> {};
617 class FunctionKindBits : public BitField<FunctionKind, 2, 7> {};
619 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewClosure);
620 DEFINE_HYDROGEN_CODE_STUB(FastNewClosure, HydrogenCodeStub);
624 class FastNewContextStub FINAL : public HydrogenCodeStub {
626 static const int kMaximumSlots = 64;
628 FastNewContextStub(Isolate* isolate, int slots) : HydrogenCodeStub(isolate) {
629 DCHECK(slots > 0 && slots <= kMaximumSlots);
630 set_sub_minor_key(SlotsBits::encode(slots));
633 int slots() const { return SlotsBits::decode(sub_minor_key()); }
635 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
636 static const int kFunction = 0;
639 class SlotsBits : public BitField<int, 0, 8> {};
641 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewContext);
642 DEFINE_HYDROGEN_CODE_STUB(FastNewContext, HydrogenCodeStub);
646 class FastCloneShallowArrayStub : public HydrogenCodeStub {
648 FastCloneShallowArrayStub(Isolate* isolate,
649 AllocationSiteMode allocation_site_mode)
650 : HydrogenCodeStub(isolate) {
651 set_sub_minor_key(AllocationSiteModeBits::encode(allocation_site_mode));
654 AllocationSiteMode allocation_site_mode() const {
655 return AllocationSiteModeBits::decode(sub_minor_key());
659 class AllocationSiteModeBits: public BitField<AllocationSiteMode, 0, 1> {};
661 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowArray);
662 DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowArray, HydrogenCodeStub);
666 class FastCloneShallowObjectStub : public HydrogenCodeStub {
668 // Maximum number of properties in copied object.
669 static const int kMaximumClonedProperties = 6;
671 FastCloneShallowObjectStub(Isolate* isolate, int length)
672 : HydrogenCodeStub(isolate) {
673 DCHECK_GE(length, 0);
674 DCHECK_LE(length, kMaximumClonedProperties);
675 set_sub_minor_key(LengthBits::encode(length));
678 int length() const { return LengthBits::decode(sub_minor_key()); }
681 class LengthBits : public BitField<int, 0, 4> {};
683 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowObject);
684 DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowObject, HydrogenCodeStub);
688 class CreateAllocationSiteStub : public HydrogenCodeStub {
690 explicit CreateAllocationSiteStub(Isolate* isolate)
691 : HydrogenCodeStub(isolate) { }
693 static void GenerateAheadOfTime(Isolate* isolate);
695 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateAllocationSite);
696 DEFINE_HYDROGEN_CODE_STUB(CreateAllocationSite, HydrogenCodeStub);
700 class CreateWeakCellStub : public HydrogenCodeStub {
702 explicit CreateWeakCellStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
704 static void GenerateAheadOfTime(Isolate* isolate);
706 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateWeakCell);
707 DEFINE_HYDROGEN_CODE_STUB(CreateWeakCell, HydrogenCodeStub);
711 class InstanceofStub: public PlatformCodeStub {
715 kArgsInRegisters = 1 << 0,
716 kCallSiteInlineCheck = 1 << 1,
717 kReturnTrueFalseObject = 1 << 2
720 InstanceofStub(Isolate* isolate, Flags flags) : PlatformCodeStub(isolate) {
721 minor_key_ = FlagBits::encode(flags);
724 static Register left() { return InstanceofDescriptor::left(); }
725 static Register right() { return InstanceofDescriptor::right(); }
727 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE {
728 if (HasArgsInRegisters()) {
729 return InstanceofDescriptor(isolate());
731 return ContextOnlyDescriptor(isolate());
735 Flags flags() const { return FlagBits::decode(minor_key_); }
737 bool HasArgsInRegisters() const { return (flags() & kArgsInRegisters) != 0; }
739 bool HasCallSiteInlineCheck() const {
740 return (flags() & kCallSiteInlineCheck) != 0;
743 bool ReturnTrueFalseObject() const {
744 return (flags() & kReturnTrueFalseObject) != 0;
747 void PrintName(std::ostream& os) const OVERRIDE; // NOLINT
749 class FlagBits : public BitField<Flags, 0, 3> {};
751 DEFINE_PLATFORM_CODE_STUB(Instanceof, PlatformCodeStub);
755 enum AllocationSiteOverrideMode {
757 DISABLE_ALLOCATION_SITES,
758 LAST_ALLOCATION_SITE_OVERRIDE_MODE = DISABLE_ALLOCATION_SITES
762 class ArrayConstructorStub: public PlatformCodeStub {
764 enum ArgumentCountKey { ANY, NONE, ONE, MORE_THAN_ONE };
766 ArrayConstructorStub(Isolate* isolate, int argument_count);
768 explicit ArrayConstructorStub(Isolate* isolate);
771 ArgumentCountKey argument_count() const {
772 return ArgumentCountBits::decode(minor_key_);
775 void GenerateDispatchToArrayStub(MacroAssembler* masm,
776 AllocationSiteOverrideMode mode);
778 void PrintName(std::ostream& os) const OVERRIDE; // NOLINT
780 class ArgumentCountBits : public BitField<ArgumentCountKey, 0, 2> {};
782 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
783 DEFINE_PLATFORM_CODE_STUB(ArrayConstructor, PlatformCodeStub);
787 class InternalArrayConstructorStub: public PlatformCodeStub {
789 explicit InternalArrayConstructorStub(Isolate* isolate);
792 void GenerateCase(MacroAssembler* masm, ElementsKind kind);
794 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
795 DEFINE_PLATFORM_CODE_STUB(InternalArrayConstructor, PlatformCodeStub);
799 class MathPowStub: public PlatformCodeStub {
801 enum ExponentType { INTEGER, DOUBLE, TAGGED, ON_STACK };
803 MathPowStub(Isolate* isolate, ExponentType exponent_type)
804 : PlatformCodeStub(isolate) {
805 minor_key_ = ExponentTypeBits::encode(exponent_type);
808 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE {
809 if (exponent_type() == TAGGED) {
810 return MathPowTaggedDescriptor(isolate());
811 } else if (exponent_type() == INTEGER) {
812 return MathPowIntegerDescriptor(isolate());
814 // A CallInterfaceDescriptor doesn't specify double registers (yet).
815 return ContextOnlyDescriptor(isolate());
819 ExponentType exponent_type() const {
820 return ExponentTypeBits::decode(minor_key_);
823 class ExponentTypeBits : public BitField<ExponentType, 0, 2> {};
825 DEFINE_PLATFORM_CODE_STUB(MathPow, PlatformCodeStub);
829 class CallICStub: public PlatformCodeStub {
831 CallICStub(Isolate* isolate, const CallICState& state)
832 : PlatformCodeStub(isolate) {
833 minor_key_ = state.GetExtraICState();
836 static int ExtractArgcFromMinorKey(int minor_key) {
837 CallICState state(static_cast<ExtraICState>(minor_key));
838 return state.arg_count();
841 Code::Kind GetCodeKind() const OVERRIDE { return Code::CALL_IC; }
843 InlineCacheState GetICState() const OVERRIDE { return DEFAULT; }
845 ExtraICState GetExtraICState() const FINAL {
846 return static_cast<ExtraICState>(minor_key_);
850 bool CallAsMethod() const {
851 return state().call_type() == CallICState::METHOD;
854 int arg_count() const { return state().arg_count(); }
856 CallICState state() const {
857 return CallICState(static_cast<ExtraICState>(minor_key_));
860 // Code generation helpers.
861 void GenerateMiss(MacroAssembler* masm);
864 void PrintState(std::ostream& os) const OVERRIDE; // NOLINT
866 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedbackAndVector);
867 DEFINE_PLATFORM_CODE_STUB(CallIC, PlatformCodeStub);
871 class CallIC_ArrayStub: public CallICStub {
873 CallIC_ArrayStub(Isolate* isolate, const CallICState& state_in)
874 : CallICStub(isolate, state_in) {}
876 InlineCacheState GetICState() const FINAL { return MONOMORPHIC; }
879 void PrintState(std::ostream& os) const OVERRIDE; // NOLINT
881 DEFINE_PLATFORM_CODE_STUB(CallIC_Array, CallICStub);
885 // TODO(verwaest): Translate to hydrogen code stub.
886 class FunctionPrototypeStub : public PlatformCodeStub {
888 explicit FunctionPrototypeStub(Isolate* isolate)
889 : PlatformCodeStub(isolate) {}
891 Code::Kind GetCodeKind() const OVERRIDE { return Code::HANDLER; }
893 // TODO(mvstanton): only the receiver register is accessed. When this is
894 // translated to a hydrogen code stub, a new CallInterfaceDescriptor
895 // should be created that just uses that register for more efficient code.
896 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE {
897 if (FLAG_vector_ics) {
898 return VectorLoadICDescriptor(isolate());
900 return LoadDescriptor(isolate());
903 DEFINE_PLATFORM_CODE_STUB(FunctionPrototype, PlatformCodeStub);
907 // TODO(mvstanton): Translate to hydrogen code stub.
908 class LoadIndexedInterceptorStub : public PlatformCodeStub {
910 explicit LoadIndexedInterceptorStub(Isolate* isolate)
911 : PlatformCodeStub(isolate) {}
913 Code::Kind GetCodeKind() const OVERRIDE { return Code::HANDLER; }
914 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; }
916 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
917 DEFINE_PLATFORM_CODE_STUB(LoadIndexedInterceptor, PlatformCodeStub);
921 class LoadIndexedStringStub : public PlatformCodeStub {
923 explicit LoadIndexedStringStub(Isolate* isolate)
924 : PlatformCodeStub(isolate) {}
926 Code::Kind GetCodeKind() const OVERRIDE { return Code::HANDLER; }
927 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; }
929 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
930 DEFINE_PLATFORM_CODE_STUB(LoadIndexedString, PlatformCodeStub);
934 class HandlerStub : public HydrogenCodeStub {
936 Code::Kind GetCodeKind() const OVERRIDE { return Code::HANDLER; }
937 ExtraICState GetExtraICState() const OVERRIDE { return kind(); }
938 InlineCacheState GetICState() const OVERRIDE { return MONOMORPHIC; }
940 void InitializeDescriptor(CodeStubDescriptor* descriptor) OVERRIDE;
942 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE;
945 explicit HandlerStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
947 virtual Code::Kind kind() const = 0;
949 DEFINE_CODE_STUB_BASE(HandlerStub, HydrogenCodeStub);
953 class LoadFieldStub: public HandlerStub {
955 LoadFieldStub(Isolate* isolate, FieldIndex index) : HandlerStub(isolate) {
956 int property_index_key = index.GetFieldAccessStubKey();
957 set_sub_minor_key(LoadFieldByIndexBits::encode(property_index_key));
960 FieldIndex index() const {
961 int property_index_key = LoadFieldByIndexBits::decode(sub_minor_key());
962 return FieldIndex::FromFieldAccessStubKey(property_index_key);
966 Code::Kind kind() const OVERRIDE { return Code::LOAD_IC; }
967 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; }
970 class LoadFieldByIndexBits : public BitField<int, 0, 13> {};
972 DEFINE_HANDLER_CODE_STUB(LoadField, HandlerStub);
976 class KeyedLoadSloppyArgumentsStub : public HandlerStub {
978 explicit KeyedLoadSloppyArgumentsStub(Isolate* isolate)
979 : HandlerStub(isolate) {}
982 Code::Kind kind() const OVERRIDE { return Code::KEYED_LOAD_IC; }
983 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; }
986 DEFINE_HANDLER_CODE_STUB(KeyedLoadSloppyArguments, HandlerStub);
990 class LoadConstantStub : public HandlerStub {
992 LoadConstantStub(Isolate* isolate, int constant_index)
993 : HandlerStub(isolate) {
994 set_sub_minor_key(ConstantIndexBits::encode(constant_index));
997 int constant_index() const {
998 return ConstantIndexBits::decode(sub_minor_key());
1002 Code::Kind kind() const OVERRIDE { return Code::LOAD_IC; }
1003 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; }
1006 class ConstantIndexBits : public BitField<int, 0, kSubMinorKeyBits> {};
1008 DEFINE_HANDLER_CODE_STUB(LoadConstant, HandlerStub);
1012 class StringLengthStub: public HandlerStub {
1014 explicit StringLengthStub(Isolate* isolate) : HandlerStub(isolate) {}
1017 Code::Kind kind() const OVERRIDE { return Code::LOAD_IC; }
1018 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; }
1020 DEFINE_HANDLER_CODE_STUB(StringLength, HandlerStub);
1024 class StoreFieldStub : public HandlerStub {
1026 StoreFieldStub(Isolate* isolate, FieldIndex index,
1027 Representation representation)
1028 : HandlerStub(isolate) {
1029 int property_index_key = index.GetFieldAccessStubKey();
1030 uint8_t repr = PropertyDetails::EncodeRepresentation(representation);
1031 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) |
1032 RepresentationBits::encode(repr));
1035 FieldIndex index() const {
1036 int property_index_key = StoreFieldByIndexBits::decode(sub_minor_key());
1037 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1040 Representation representation() {
1041 uint8_t repr = RepresentationBits::decode(sub_minor_key());
1042 return PropertyDetails::DecodeRepresentation(repr);
1046 Code::Kind kind() const OVERRIDE { return Code::STORE_IC; }
1047 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; }
1050 class StoreFieldByIndexBits : public BitField<int, 0, 13> {};
1051 class RepresentationBits : public BitField<uint8_t, 13, 4> {};
1053 DEFINE_HANDLER_CODE_STUB(StoreField, HandlerStub);
1057 class StoreTransitionStub : public HandlerStub {
1062 ExtendStorageAndStoreMapAndValue
1065 explicit StoreTransitionStub(Isolate* isolate) : HandlerStub(isolate) {
1066 set_sub_minor_key(StoreModeBits::encode(StoreMapOnly));
1069 StoreTransitionStub(Isolate* isolate, FieldIndex index,
1070 Representation representation, StoreMode store_mode)
1071 : HandlerStub(isolate) {
1072 DCHECK(store_mode != StoreMapOnly);
1073 int property_index_key = index.GetFieldAccessStubKey();
1074 uint8_t repr = PropertyDetails::EncodeRepresentation(representation);
1075 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) |
1076 RepresentationBits::encode(repr) |
1077 StoreModeBits::encode(store_mode));
1080 FieldIndex index() const {
1081 DCHECK(store_mode() != StoreMapOnly);
1082 int property_index_key = StoreFieldByIndexBits::decode(sub_minor_key());
1083 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1086 Representation representation() {
1087 DCHECK(store_mode() != StoreMapOnly);
1088 uint8_t repr = RepresentationBits::decode(sub_minor_key());
1089 return PropertyDetails::DecodeRepresentation(repr);
1092 StoreMode store_mode() const {
1093 return StoreModeBits::decode(sub_minor_key());
1096 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE;
1099 Code::Kind kind() const OVERRIDE { return Code::STORE_IC; }
1100 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; }
1103 class StoreFieldByIndexBits : public BitField<int, 0, 13> {};
1104 class RepresentationBits : public BitField<uint8_t, 13, 4> {};
1105 class StoreModeBits : public BitField<StoreMode, 17, 2> {};
1107 DEFINE_HANDLER_CODE_STUB(StoreTransition, HandlerStub);
1111 class StoreGlobalStub : public HandlerStub {
1113 StoreGlobalStub(Isolate* isolate, bool is_constant, bool check_global)
1114 : HandlerStub(isolate) {
1115 set_sub_minor_key(IsConstantBits::encode(is_constant) |
1116 CheckGlobalBits::encode(check_global));
1119 static Handle<HeapObject> property_cell_placeholder(Isolate* isolate) {
1120 return isolate->factory()->uninitialized_value();
1123 Handle<Code> GetCodeCopyFromTemplate(Handle<GlobalObject> global,
1124 Handle<PropertyCell> cell) {
1125 if (check_global()) {
1126 Code::FindAndReplacePattern pattern;
1127 pattern.Add(isolate()->factory()->meta_map(),
1128 Map::WeakCellForMap(Handle<Map>(global->map())));
1129 pattern.Add(Handle<Map>(property_cell_placeholder(isolate())->map()),
1130 isolate()->factory()->NewWeakCell(cell));
1131 return CodeStub::GetCodeCopy(pattern);
1133 Code::FindAndReplacePattern pattern;
1134 pattern.Add(Handle<Map>(property_cell_placeholder(isolate())->map()),
1135 isolate()->factory()->NewWeakCell(cell));
1136 return CodeStub::GetCodeCopy(pattern);
1140 Code::Kind kind() const OVERRIDE { return Code::STORE_IC; }
1142 bool is_constant() const { return IsConstantBits::decode(sub_minor_key()); }
1144 bool check_global() const { return CheckGlobalBits::decode(sub_minor_key()); }
1146 void set_is_constant(bool value) {
1147 set_sub_minor_key(IsConstantBits::update(sub_minor_key(), value));
1150 Representation representation() {
1151 return Representation::FromKind(
1152 RepresentationBits::decode(sub_minor_key()));
1155 void set_representation(Representation r) {
1156 set_sub_minor_key(RepresentationBits::update(sub_minor_key(), r.kind()));
1160 class IsConstantBits: public BitField<bool, 0, 1> {};
1161 class RepresentationBits: public BitField<Representation::Kind, 1, 8> {};
1162 class CheckGlobalBits: public BitField<bool, 9, 1> {};
1164 DEFINE_HANDLER_CODE_STUB(StoreGlobal, HandlerStub);
1168 class CallApiFunctionStub : public PlatformCodeStub {
1170 explicit CallApiFunctionStub(Isolate* isolate, bool call_data_undefined)
1171 : PlatformCodeStub(isolate) {
1172 minor_key_ = CallDataUndefinedBits::encode(call_data_undefined);
1176 bool call_data_undefined() const {
1177 return CallDataUndefinedBits::decode(minor_key_);
1180 class CallDataUndefinedBits : public BitField<bool, 0, 1> {};
1182 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiFunction);
1183 DEFINE_PLATFORM_CODE_STUB(CallApiFunction, PlatformCodeStub);
1187 class CallApiAccessorStub : public PlatformCodeStub {
1189 CallApiAccessorStub(Isolate* isolate, bool is_store, bool call_data_undefined)
1190 : PlatformCodeStub(isolate) {
1191 minor_key_ = IsStoreBits::encode(is_store) |
1192 CallDataUndefinedBits::encode(call_data_undefined) |
1193 ArgumentBits::encode(is_store ? 1 : 0);
1197 // For CallApiFunctionWithFixedArgsStub, see below.
1198 static const int kArgBits = 3;
1199 CallApiAccessorStub(Isolate* isolate, int argc, bool call_data_undefined)
1200 : PlatformCodeStub(isolate) {
1201 minor_key_ = IsStoreBits::encode(false) |
1202 CallDataUndefinedBits::encode(call_data_undefined) |
1203 ArgumentBits::encode(argc);
1207 bool is_store() const { return IsStoreBits::decode(minor_key_); }
1208 bool call_data_undefined() const {
1209 return CallDataUndefinedBits::decode(minor_key_);
1211 int argc() const { return ArgumentBits::decode(minor_key_); }
1213 class IsStoreBits: public BitField<bool, 0, 1> {};
1214 class CallDataUndefinedBits: public BitField<bool, 1, 1> {};
1215 class ArgumentBits : public BitField<int, 2, kArgBits> {};
1217 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiAccessor);
1218 DEFINE_PLATFORM_CODE_STUB(CallApiAccessor, PlatformCodeStub);
1222 // TODO(dcarney): see if it's possible to remove this later without performance
1224 // This is not a real stub, but a way of generating the CallApiAccessorStub
1225 // (which has the same abi) which makes it clear that it is not an accessor.
1226 class CallApiFunctionWithFixedArgsStub : public CallApiAccessorStub {
1228 static const int kMaxFixedArgs = (1 << kArgBits) - 1;
1229 CallApiFunctionWithFixedArgsStub(Isolate* isolate, int argc,
1230 bool call_data_undefined)
1231 : CallApiAccessorStub(isolate, argc, call_data_undefined) {
1232 DCHECK(0 <= argc && argc <= kMaxFixedArgs);
1237 typedef ApiAccessorDescriptor ApiFunctionWithFixedArgsDescriptor;
1240 class CallApiGetterStub : public PlatformCodeStub {
1242 explicit CallApiGetterStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
1244 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiGetter);
1245 DEFINE_PLATFORM_CODE_STUB(CallApiGetter, PlatformCodeStub);
1249 class BinaryOpICStub : public HydrogenCodeStub {
1251 BinaryOpICStub(Isolate* isolate, Token::Value op)
1252 : HydrogenCodeStub(isolate, UNINITIALIZED) {
1253 BinaryOpICState state(isolate, op);
1254 set_sub_minor_key(state.GetExtraICState());
1257 BinaryOpICStub(Isolate* isolate, const BinaryOpICState& state)
1258 : HydrogenCodeStub(isolate) {
1259 set_sub_minor_key(state.GetExtraICState());
1262 static void GenerateAheadOfTime(Isolate* isolate);
1264 Code::Kind GetCodeKind() const OVERRIDE { return Code::BINARY_OP_IC; }
1266 InlineCacheState GetICState() const FINAL { return state().GetICState(); }
1268 ExtraICState GetExtraICState() const FINAL {
1269 return static_cast<ExtraICState>(sub_minor_key());
1272 BinaryOpICState state() const {
1273 return BinaryOpICState(isolate(), GetExtraICState());
1276 void PrintState(std::ostream& os) const FINAL; // NOLINT
1278 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1279 static const int kLeft = 0;
1280 static const int kRight = 1;
1283 static void GenerateAheadOfTime(Isolate* isolate,
1284 const BinaryOpICState& state);
1286 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1287 DEFINE_HYDROGEN_CODE_STUB(BinaryOpIC, HydrogenCodeStub);
1291 // TODO(bmeurer): Merge this into the BinaryOpICStub once we have proper tail
1292 // call support for stubs in Hydrogen.
1293 class BinaryOpICWithAllocationSiteStub FINAL : public PlatformCodeStub {
1295 BinaryOpICWithAllocationSiteStub(Isolate* isolate,
1296 const BinaryOpICState& state)
1297 : PlatformCodeStub(isolate) {
1298 minor_key_ = state.GetExtraICState();
1301 static void GenerateAheadOfTime(Isolate* isolate);
1303 Handle<Code> GetCodeCopyFromTemplate(Handle<AllocationSite> allocation_site) {
1304 Code::FindAndReplacePattern pattern;
1305 pattern.Add(isolate()->factory()->undefined_map(), allocation_site);
1306 return CodeStub::GetCodeCopy(pattern);
1309 Code::Kind GetCodeKind() const OVERRIDE { return Code::BINARY_OP_IC; }
1311 InlineCacheState GetICState() const OVERRIDE { return state().GetICState(); }
1313 ExtraICState GetExtraICState() const OVERRIDE {
1314 return static_cast<ExtraICState>(minor_key_);
1317 void PrintState(std::ostream& os) const OVERRIDE; // NOLINT
1320 BinaryOpICState state() const {
1321 return BinaryOpICState(isolate(), static_cast<ExtraICState>(minor_key_));
1324 static void GenerateAheadOfTime(Isolate* isolate,
1325 const BinaryOpICState& state);
1327 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1328 DEFINE_PLATFORM_CODE_STUB(BinaryOpICWithAllocationSite, PlatformCodeStub);
1332 class BinaryOpWithAllocationSiteStub FINAL : public BinaryOpICStub {
1334 BinaryOpWithAllocationSiteStub(Isolate* isolate, Token::Value op)
1335 : BinaryOpICStub(isolate, op) {}
1337 BinaryOpWithAllocationSiteStub(Isolate* isolate, const BinaryOpICState& state)
1338 : BinaryOpICStub(isolate, state) {}
1340 Code::Kind GetCodeKind() const FINAL { return Code::STUB; }
1342 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1343 static const int kAllocationSite = 0;
1344 static const int kLeft = 1;
1345 static const int kRight = 2;
1347 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1348 DEFINE_HYDROGEN_CODE_STUB(BinaryOpWithAllocationSite, BinaryOpICStub);
1352 enum StringAddFlags {
1353 // Omit both parameter checks.
1354 STRING_ADD_CHECK_NONE = 0,
1355 // Check left parameter.
1356 STRING_ADD_CHECK_LEFT = 1 << 0,
1357 // Check right parameter.
1358 STRING_ADD_CHECK_RIGHT = 1 << 1,
1359 // Check both parameters.
1360 STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT
1364 class StringAddStub FINAL : public HydrogenCodeStub {
1366 StringAddStub(Isolate* isolate, StringAddFlags flags,
1367 PretenureFlag pretenure_flag)
1368 : HydrogenCodeStub(isolate) {
1369 set_sub_minor_key(StringAddFlagsBits::encode(flags) |
1370 PretenureFlagBits::encode(pretenure_flag));
1373 StringAddFlags flags() const {
1374 return StringAddFlagsBits::decode(sub_minor_key());
1377 PretenureFlag pretenure_flag() const {
1378 return PretenureFlagBits::decode(sub_minor_key());
1381 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1382 static const int kLeft = 0;
1383 static const int kRight = 1;
1386 class StringAddFlagsBits: public BitField<StringAddFlags, 0, 2> {};
1387 class PretenureFlagBits: public BitField<PretenureFlag, 2, 1> {};
1389 void PrintBaseName(std::ostream& os) const OVERRIDE; // NOLINT
1391 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
1392 DEFINE_HYDROGEN_CODE_STUB(StringAdd, HydrogenCodeStub);
1396 class CompareICStub : public PlatformCodeStub {
1398 CompareICStub(Isolate* isolate, Token::Value op, CompareICState::State left,
1399 CompareICState::State right, CompareICState::State state)
1400 : PlatformCodeStub(isolate) {
1401 DCHECK(Token::IsCompareOp(op));
1402 minor_key_ = OpBits::encode(op - Token::EQ) | LeftStateBits::encode(left) |
1403 RightStateBits::encode(right) | StateBits::encode(state);
1406 void set_known_map(Handle<Map> map) { known_map_ = map; }
1408 InlineCacheState GetICState() const OVERRIDE;
1410 Token::Value op() const {
1411 return static_cast<Token::Value>(Token::EQ + OpBits::decode(minor_key_));
1414 CompareICState::State left() const {
1415 return LeftStateBits::decode(minor_key_);
1417 CompareICState::State right() const {
1418 return RightStateBits::decode(minor_key_);
1420 CompareICState::State state() const { return StateBits::decode(minor_key_); }
1423 Code::Kind GetCodeKind() const OVERRIDE { return Code::COMPARE_IC; }
1425 void GenerateSmis(MacroAssembler* masm);
1426 void GenerateNumbers(MacroAssembler* masm);
1427 void GenerateInternalizedStrings(MacroAssembler* masm);
1428 void GenerateStrings(MacroAssembler* masm);
1429 void GenerateUniqueNames(MacroAssembler* masm);
1430 void GenerateObjects(MacroAssembler* masm);
1431 void GenerateMiss(MacroAssembler* masm);
1432 void GenerateKnownObjects(MacroAssembler* masm);
1433 void GenerateGeneric(MacroAssembler* masm);
1435 bool strict() const { return op() == Token::EQ_STRICT; }
1436 Condition GetCondition() const;
1438 void AddToSpecialCache(Handle<Code> new_object) OVERRIDE;
1439 bool FindCodeInSpecialCache(Code** code_out) OVERRIDE;
1440 bool UseSpecialCache() OVERRIDE {
1441 return state() == CompareICState::KNOWN_OBJECT;
1444 class OpBits : public BitField<int, 0, 3> {};
1445 class LeftStateBits : public BitField<CompareICState::State, 3, 4> {};
1446 class RightStateBits : public BitField<CompareICState::State, 7, 4> {};
1447 class StateBits : public BitField<CompareICState::State, 11, 4> {};
1449 Handle<Map> known_map_;
1451 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1452 DEFINE_PLATFORM_CODE_STUB(CompareIC, PlatformCodeStub);
1456 class CompareNilICStub : public HydrogenCodeStub {
1458 Type* GetType(Zone* zone, Handle<Map> map = Handle<Map>());
1459 Type* GetInputType(Zone* zone, Handle<Map> map);
1461 CompareNilICStub(Isolate* isolate, NilValue nil) : HydrogenCodeStub(isolate) {
1462 set_sub_minor_key(NilValueBits::encode(nil));
1465 CompareNilICStub(Isolate* isolate, ExtraICState ic_state,
1466 InitializationState init_state = INITIALIZED)
1467 : HydrogenCodeStub(isolate, init_state) {
1468 set_sub_minor_key(ic_state);
1471 static Handle<Code> GetUninitialized(Isolate* isolate,
1473 return CompareNilICStub(isolate, nil, UNINITIALIZED).GetCode();
1476 InlineCacheState GetICState() const OVERRIDE {
1477 State state = this->state();
1478 if (state.Contains(GENERIC)) {
1480 } else if (state.Contains(MONOMORPHIC_MAP)) {
1483 return PREMONOMORPHIC;
1487 Code::Kind GetCodeKind() const OVERRIDE { return Code::COMPARE_NIL_IC; }
1489 ExtraICState GetExtraICState() const OVERRIDE { return sub_minor_key(); }
1491 void UpdateStatus(Handle<Object> object);
1493 bool IsMonomorphic() const { return state().Contains(MONOMORPHIC_MAP); }
1495 NilValue nil_value() const { return NilValueBits::decode(sub_minor_key()); }
1498 set_sub_minor_key(TypesBits::update(sub_minor_key(), 0));
1501 void PrintState(std::ostream& os) const OVERRIDE; // NOLINT
1502 void PrintBaseName(std::ostream& os) const OVERRIDE; // NOLINT
1505 CompareNilICStub(Isolate* isolate, NilValue nil,
1506 InitializationState init_state)
1507 : HydrogenCodeStub(isolate, init_state) {
1508 set_sub_minor_key(NilValueBits::encode(nil));
1511 enum CompareNilType {
1519 // At most 6 different types can be distinguished, because the Code object
1520 // only has room for a single byte to hold a set and there are two more
1521 // boolean flags we need to store. :-P
1522 STATIC_ASSERT(NUMBER_OF_TYPES <= 6);
1524 class State : public EnumSet<CompareNilType, byte> {
1526 State() : EnumSet<CompareNilType, byte>(0) { }
1527 explicit State(byte bits) : EnumSet<CompareNilType, byte>(bits) { }
1529 friend std::ostream& operator<<(std::ostream& os, const State& s);
1531 State state() const { return State(TypesBits::decode(sub_minor_key())); }
1533 class NilValueBits : public BitField<NilValue, 0, 1> {};
1534 class TypesBits : public BitField<byte, 1, NUMBER_OF_TYPES> {};
1536 friend class CompareNilIC;
1538 DEFINE_CALL_INTERFACE_DESCRIPTOR(CompareNil);
1539 DEFINE_HYDROGEN_CODE_STUB(CompareNilIC, HydrogenCodeStub);
1543 std::ostream& operator<<(std::ostream& os, const CompareNilICStub::State& s);
1546 class CEntryStub : public PlatformCodeStub {
1548 CEntryStub(Isolate* isolate, int result_size,
1549 SaveFPRegsMode save_doubles = kDontSaveFPRegs)
1550 : PlatformCodeStub(isolate) {
1551 minor_key_ = SaveDoublesBits::encode(save_doubles == kSaveFPRegs);
1552 DCHECK(result_size == 1 || result_size == 2);
1553 #if _WIN64 || V8_TARGET_ARCH_PPC
1554 minor_key_ = ResultSizeBits::update(minor_key_, result_size);
1558 // The version of this stub that doesn't save doubles is generated ahead of
1559 // time, so it's OK to call it from other stubs that can't cope with GC during
1560 // their code generation. On machines that always have gp registers (x64) we
1561 // can generate both variants ahead of time.
1562 static void GenerateAheadOfTime(Isolate* isolate);
1565 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
1566 #if _WIN64 || V8_TARGET_ARCH_PPC
1567 int result_size() const { return ResultSizeBits::decode(minor_key_); }
1570 bool NeedsImmovableCode() OVERRIDE;
1572 class SaveDoublesBits : public BitField<bool, 0, 1> {};
1573 class ResultSizeBits : public BitField<int, 1, 3> {};
1575 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1576 DEFINE_PLATFORM_CODE_STUB(CEntry, PlatformCodeStub);
1580 class JSEntryStub : public PlatformCodeStub {
1582 JSEntryStub(Isolate* isolate, StackFrame::Type type)
1583 : PlatformCodeStub(isolate) {
1584 DCHECK(type == StackFrame::ENTRY || type == StackFrame::ENTRY_CONSTRUCT);
1585 minor_key_ = StackFrameTypeBits::encode(type);
1589 void FinishCode(Handle<Code> code) OVERRIDE;
1591 void PrintName(std::ostream& os) const OVERRIDE { // NOLINT
1592 os << (type() == StackFrame::ENTRY ? "JSEntryStub"
1593 : "JSConstructEntryStub");
1596 StackFrame::Type type() const {
1597 return StackFrameTypeBits::decode(minor_key_);
1600 class StackFrameTypeBits : public BitField<StackFrame::Type, 0, 5> {};
1602 int handler_offset_;
1604 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1605 DEFINE_PLATFORM_CODE_STUB(JSEntry, PlatformCodeStub);
1609 class ArgumentsAccessStub: public PlatformCodeStub {
1618 enum HasNewTarget { NO_NEW_TARGET, HAS_NEW_TARGET };
1620 ArgumentsAccessStub(Isolate* isolate, Type type,
1621 HasNewTarget has_new_target = NO_NEW_TARGET)
1622 : PlatformCodeStub(isolate) {
1624 TypeBits::encode(type) | HasNewTargetBits::encode(has_new_target);
1627 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE {
1628 if (type() == READ_ELEMENT) {
1629 return ArgumentsAccessReadDescriptor(isolate());
1631 return ContextOnlyDescriptor(isolate());
1635 Type type() const { return TypeBits::decode(minor_key_); }
1636 bool has_new_target() const {
1637 return HasNewTargetBits::decode(minor_key_) == HAS_NEW_TARGET;
1640 void GenerateReadElement(MacroAssembler* masm);
1641 void GenerateNewStrict(MacroAssembler* masm);
1642 void GenerateNewSloppyFast(MacroAssembler* masm);
1643 void GenerateNewSloppySlow(MacroAssembler* masm);
1645 void PrintName(std::ostream& os) const OVERRIDE; // NOLINT
1647 class TypeBits : public BitField<Type, 0, 2> {};
1648 class HasNewTargetBits : public BitField<HasNewTarget, 2, 1> {};
1650 DEFINE_PLATFORM_CODE_STUB(ArgumentsAccess, PlatformCodeStub);
1654 class RestParamAccessStub: public PlatformCodeStub {
1656 explicit RestParamAccessStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
1658 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE {
1659 return ContextOnlyDescriptor(isolate());
1663 void GenerateNew(MacroAssembler* masm);
1665 virtual void PrintName(std::ostream& os) const OVERRIDE; // NOLINT
1667 DEFINE_PLATFORM_CODE_STUB(RestParamAccess, PlatformCodeStub);
1671 class RegExpExecStub: public PlatformCodeStub {
1673 explicit RegExpExecStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
1675 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
1676 DEFINE_PLATFORM_CODE_STUB(RegExpExec, PlatformCodeStub);
1680 class RegExpConstructResultStub FINAL : public HydrogenCodeStub {
1682 explicit RegExpConstructResultStub(Isolate* isolate)
1683 : HydrogenCodeStub(isolate) { }
1685 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1686 static const int kLength = 0;
1687 static const int kIndex = 1;
1688 static const int kInput = 2;
1690 DEFINE_CALL_INTERFACE_DESCRIPTOR(RegExpConstructResult);
1691 DEFINE_HYDROGEN_CODE_STUB(RegExpConstructResult, HydrogenCodeStub);
1695 class CallFunctionStub: public PlatformCodeStub {
1697 CallFunctionStub(Isolate* isolate, int argc, CallFunctionFlags flags)
1698 : PlatformCodeStub(isolate) {
1699 DCHECK(argc >= 0 && argc <= Code::kMaxArguments);
1700 minor_key_ = ArgcBits::encode(argc) | FlagBits::encode(flags);
1703 static int ExtractArgcFromMinorKey(int minor_key) {
1704 return ArgcBits::decode(minor_key);
1708 int argc() const { return ArgcBits::decode(minor_key_); }
1709 int flags() const { return FlagBits::decode(minor_key_); }
1711 bool CallAsMethod() const {
1712 return flags() == CALL_AS_METHOD || flags() == WRAP_AND_CALL;
1715 bool NeedsChecks() const { return flags() != WRAP_AND_CALL; }
1717 void PrintName(std::ostream& os) const OVERRIDE; // NOLINT
1719 // Minor key encoding in 32 bits with Bitfield <Type, shift, size>.
1720 class FlagBits : public BitField<CallFunctionFlags, 0, 2> {};
1721 class ArgcBits : public BitField<unsigned, 2, Code::kArgumentsBits> {};
1722 STATIC_ASSERT(Code::kArgumentsBits + 2 <= kStubMinorKeyBits);
1724 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction);
1725 DEFINE_PLATFORM_CODE_STUB(CallFunction, PlatformCodeStub);
1729 class CallConstructStub: public PlatformCodeStub {
1731 CallConstructStub(Isolate* isolate, CallConstructorFlags flags)
1732 : PlatformCodeStub(isolate) {
1733 minor_key_ = FlagBits::encode(flags);
1736 void FinishCode(Handle<Code> code) OVERRIDE {
1737 code->set_has_function_cache(RecordCallTarget());
1741 CallConstructorFlags flags() const { return FlagBits::decode(minor_key_); }
1743 bool RecordCallTarget() const {
1744 return (flags() & RECORD_CONSTRUCTOR_TARGET) != 0;
1747 bool IsSuperConstructorCall() const {
1748 return (flags() & SUPER_CONSTRUCTOR_CALL) != 0;
1751 void PrintName(std::ostream& os) const OVERRIDE; // NOLINT
1753 class FlagBits : public BitField<CallConstructorFlags, 0, 2> {};
1755 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallConstruct);
1756 DEFINE_PLATFORM_CODE_STUB(CallConstruct, PlatformCodeStub);
1760 enum StringIndexFlags {
1761 // Accepts smis or heap numbers.
1762 STRING_INDEX_IS_NUMBER,
1764 // Accepts smis or heap numbers that are valid array indices
1765 // (ECMA-262 15.4). Invalid indices are reported as being out of
1767 STRING_INDEX_IS_ARRAY_INDEX
1771 enum ReceiverCheckMode {
1772 // We don't know anything about the receiver.
1773 RECEIVER_IS_UNKNOWN,
1775 // We know the receiver is a string.
1780 // Generates code implementing String.prototype.charCodeAt.
1782 // Only supports the case when the receiver is a string and the index
1783 // is a number (smi or heap number) that is a valid index into the
1784 // string. Additional index constraints are specified by the
1785 // flags. Otherwise, bails out to the provided labels.
1787 // Register usage: |object| may be changed to another string in a way
1788 // that doesn't affect charCodeAt/charAt semantics, |index| is
1789 // preserved, |scratch| and |result| are clobbered.
1790 class StringCharCodeAtGenerator {
1792 StringCharCodeAtGenerator(Register object, Register index, Register result,
1793 Label* receiver_not_string, Label* index_not_number,
1794 Label* index_out_of_range,
1795 StringIndexFlags index_flags,
1796 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
1800 receiver_not_string_(receiver_not_string),
1801 index_not_number_(index_not_number),
1802 index_out_of_range_(index_out_of_range),
1803 index_flags_(index_flags),
1804 check_mode_(check_mode) {
1805 DCHECK(!result_.is(object_));
1806 DCHECK(!result_.is(index_));
1809 // Generates the fast case code. On the fallthrough path |result|
1810 // register contains the result.
1811 void GenerateFast(MacroAssembler* masm);
1813 // Generates the slow case code. Must not be naturally
1814 // reachable. Expected to be put after a ret instruction (e.g., in
1815 // deferred code). Always jumps back to the fast case.
1816 void GenerateSlow(MacroAssembler* masm,
1817 const RuntimeCallHelper& call_helper);
1819 // Skip handling slow case and directly jump to bailout.
1820 void SkipSlow(MacroAssembler* masm, Label* bailout) {
1821 masm->bind(&index_not_smi_);
1822 masm->bind(&call_runtime_);
1831 Label* receiver_not_string_;
1832 Label* index_not_number_;
1833 Label* index_out_of_range_;
1835 StringIndexFlags index_flags_;
1836 ReceiverCheckMode check_mode_;
1838 Label call_runtime_;
1839 Label index_not_smi_;
1840 Label got_smi_index_;
1843 DISALLOW_COPY_AND_ASSIGN(StringCharCodeAtGenerator);
1847 // Generates code for creating a one-char string from a char code.
1848 class StringCharFromCodeGenerator {
1850 StringCharFromCodeGenerator(Register code,
1854 DCHECK(!code_.is(result_));
1857 // Generates the fast case code. On the fallthrough path |result|
1858 // register contains the result.
1859 void GenerateFast(MacroAssembler* masm);
1861 // Generates the slow case code. Must not be naturally
1862 // reachable. Expected to be put after a ret instruction (e.g., in
1863 // deferred code). Always jumps back to the fast case.
1864 void GenerateSlow(MacroAssembler* masm,
1865 const RuntimeCallHelper& call_helper);
1867 // Skip handling slow case and directly jump to bailout.
1868 void SkipSlow(MacroAssembler* masm, Label* bailout) {
1869 masm->bind(&slow_case_);
1880 DISALLOW_COPY_AND_ASSIGN(StringCharFromCodeGenerator);
1884 // Generates code implementing String.prototype.charAt.
1886 // Only supports the case when the receiver is a string and the index
1887 // is a number (smi or heap number) that is a valid index into the
1888 // string. Additional index constraints are specified by the
1889 // flags. Otherwise, bails out to the provided labels.
1891 // Register usage: |object| may be changed to another string in a way
1892 // that doesn't affect charCodeAt/charAt semantics, |index| is
1893 // preserved, |scratch1|, |scratch2|, and |result| are clobbered.
1894 class StringCharAtGenerator {
1896 StringCharAtGenerator(Register object, Register index, Register scratch,
1897 Register result, Label* receiver_not_string,
1898 Label* index_not_number, Label* index_out_of_range,
1899 StringIndexFlags index_flags,
1900 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
1901 : char_code_at_generator_(object, index, scratch, receiver_not_string,
1902 index_not_number, index_out_of_range,
1903 index_flags, check_mode),
1904 char_from_code_generator_(scratch, result) {}
1906 // Generates the fast case code. On the fallthrough path |result|
1907 // register contains the result.
1908 void GenerateFast(MacroAssembler* masm) {
1909 char_code_at_generator_.GenerateFast(masm);
1910 char_from_code_generator_.GenerateFast(masm);
1913 // Generates the slow case code. Must not be naturally
1914 // reachable. Expected to be put after a ret instruction (e.g., in
1915 // deferred code). Always jumps back to the fast case.
1916 void GenerateSlow(MacroAssembler* masm,
1917 const RuntimeCallHelper& call_helper) {
1918 char_code_at_generator_.GenerateSlow(masm, call_helper);
1919 char_from_code_generator_.GenerateSlow(masm, call_helper);
1922 // Skip handling slow case and directly jump to bailout.
1923 void SkipSlow(MacroAssembler* masm, Label* bailout) {
1924 char_code_at_generator_.SkipSlow(masm, bailout);
1925 char_from_code_generator_.SkipSlow(masm, bailout);
1929 StringCharCodeAtGenerator char_code_at_generator_;
1930 StringCharFromCodeGenerator char_from_code_generator_;
1932 DISALLOW_COPY_AND_ASSIGN(StringCharAtGenerator);
1936 class LoadDictionaryElementStub : public HydrogenCodeStub {
1938 explicit LoadDictionaryElementStub(Isolate* isolate)
1939 : HydrogenCodeStub(isolate) {}
1941 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE {
1942 if (FLAG_vector_ics) {
1943 return VectorLoadICDescriptor(isolate());
1945 return LoadDescriptor(isolate());
1948 DEFINE_HYDROGEN_CODE_STUB(LoadDictionaryElement, HydrogenCodeStub);
1952 class KeyedLoadGenericStub : public HydrogenCodeStub {
1954 explicit KeyedLoadGenericStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
1956 Code::Kind GetCodeKind() const OVERRIDE { return Code::KEYED_LOAD_IC; }
1957 InlineCacheState GetICState() const OVERRIDE { return GENERIC; }
1959 // Since KeyedLoadGeneric stub doesn't miss (simply calls runtime), it
1960 // doesn't need to use the VectorLoadICDescriptor for the case when
1961 // flag --vector-ics is true.
1962 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
1964 DEFINE_HYDROGEN_CODE_STUB(KeyedLoadGeneric, HydrogenCodeStub);
1968 class LoadICTrampolineStub : public PlatformCodeStub {
1970 LoadICTrampolineStub(Isolate* isolate, const LoadICState& state)
1971 : PlatformCodeStub(isolate) {
1972 minor_key_ = state.GetExtraICState();
1975 Code::Kind GetCodeKind() const OVERRIDE { return Code::LOAD_IC; }
1977 InlineCacheState GetICState() const FINAL { return DEFAULT; }
1979 ExtraICState GetExtraICState() const FINAL {
1980 return static_cast<ExtraICState>(minor_key_);
1984 LoadICState state() const {
1985 return LoadICState(static_cast<ExtraICState>(minor_key_));
1988 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorLoadICTrampoline);
1989 DEFINE_PLATFORM_CODE_STUB(LoadICTrampoline, PlatformCodeStub);
1993 class KeyedLoadICTrampolineStub : public LoadICTrampolineStub {
1995 explicit KeyedLoadICTrampolineStub(Isolate* isolate)
1996 : LoadICTrampolineStub(isolate, LoadICState(0)) {}
1998 Code::Kind GetCodeKind() const OVERRIDE { return Code::KEYED_LOAD_IC; }
2000 DEFINE_PLATFORM_CODE_STUB(KeyedLoadICTrampoline, LoadICTrampolineStub);
2004 class CallICTrampolineStub : public PlatformCodeStub {
2006 CallICTrampolineStub(Isolate* isolate, const CallICState& state)
2007 : PlatformCodeStub(isolate) {
2008 minor_key_ = state.GetExtraICState();
2011 Code::Kind GetCodeKind() const OVERRIDE { return Code::CALL_IC; }
2013 InlineCacheState GetICState() const FINAL { return DEFAULT; }
2015 ExtraICState GetExtraICState() const FINAL {
2016 return static_cast<ExtraICState>(minor_key_);
2020 CallICState state() const {
2021 return CallICState(static_cast<ExtraICState>(minor_key_));
2024 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedback);
2025 DEFINE_PLATFORM_CODE_STUB(CallICTrampoline, PlatformCodeStub);
2029 class CallIC_ArrayTrampolineStub : public CallICTrampolineStub {
2031 CallIC_ArrayTrampolineStub(Isolate* isolate, const CallICState& state)
2032 : CallICTrampolineStub(isolate, state) {}
2035 DEFINE_PLATFORM_CODE_STUB(CallIC_ArrayTrampoline, CallICTrampolineStub);
2039 class MegamorphicLoadStub : public HydrogenCodeStub {
2041 MegamorphicLoadStub(Isolate* isolate, const LoadICState& state)
2042 : HydrogenCodeStub(isolate) {
2043 set_sub_minor_key(state.GetExtraICState());
2046 Code::Kind GetCodeKind() const OVERRIDE { return Code::LOAD_IC; }
2048 InlineCacheState GetICState() const FINAL { return MEGAMORPHIC; }
2050 ExtraICState GetExtraICState() const FINAL {
2051 return static_cast<ExtraICState>(sub_minor_key());
2054 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE {
2055 if (FLAG_vector_ics) {
2056 return VectorLoadICDescriptor(isolate());
2058 return LoadDescriptor(isolate());
2061 DEFINE_HYDROGEN_CODE_STUB(MegamorphicLoad, HydrogenCodeStub);
2065 class VectorLoadStub : public HydrogenCodeStub {
2067 explicit VectorLoadStub(Isolate* isolate, const LoadICState& state)
2068 : HydrogenCodeStub(isolate) {
2069 set_sub_minor_key(state.GetExtraICState());
2072 Code::Kind GetCodeKind() const OVERRIDE { return Code::LOAD_IC; }
2074 InlineCacheState GetICState() const FINAL { return DEFAULT; }
2076 ExtraICState GetExtraICState() const FINAL {
2077 return static_cast<ExtraICState>(sub_minor_key());
2081 LoadICState state() const { return LoadICState(GetExtraICState()); }
2083 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorLoadIC);
2084 DEFINE_HYDROGEN_CODE_STUB(VectorLoad, HydrogenCodeStub);
2088 class VectorKeyedLoadStub : public VectorLoadStub {
2090 explicit VectorKeyedLoadStub(Isolate* isolate)
2091 : VectorLoadStub(isolate, LoadICState(0)) {}
2093 Code::Kind GetCodeKind() const OVERRIDE { return Code::KEYED_LOAD_IC; }
2095 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorLoadIC);
2096 DEFINE_HYDROGEN_CODE_STUB(VectorKeyedLoad, VectorLoadStub);
2100 class DoubleToIStub : public PlatformCodeStub {
2102 DoubleToIStub(Isolate* isolate, Register source, Register destination,
2103 int offset, bool is_truncating, bool skip_fastpath = false)
2104 : PlatformCodeStub(isolate) {
2105 minor_key_ = SourceRegisterBits::encode(source.code()) |
2106 DestinationRegisterBits::encode(destination.code()) |
2107 OffsetBits::encode(offset) |
2108 IsTruncatingBits::encode(is_truncating) |
2109 SkipFastPathBits::encode(skip_fastpath) |
2110 SSE3Bits::encode(CpuFeatures::IsSupported(SSE3) ? 1 : 0);
2113 bool SometimesSetsUpAFrame() OVERRIDE { return false; }
2116 Register source() const {
2117 return Register::from_code(SourceRegisterBits::decode(minor_key_));
2119 Register destination() const {
2120 return Register::from_code(DestinationRegisterBits::decode(minor_key_));
2122 bool is_truncating() const { return IsTruncatingBits::decode(minor_key_); }
2123 bool skip_fastpath() const { return SkipFastPathBits::decode(minor_key_); }
2124 int offset() const { return OffsetBits::decode(minor_key_); }
2126 static const int kBitsPerRegisterNumber = 6;
2127 STATIC_ASSERT((1L << kBitsPerRegisterNumber) >= Register::kNumRegisters);
2128 class SourceRegisterBits:
2129 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT
2130 class DestinationRegisterBits:
2131 public BitField<int, kBitsPerRegisterNumber,
2132 kBitsPerRegisterNumber> {}; // NOLINT
2133 class IsTruncatingBits:
2134 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT
2136 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT
2137 class SkipFastPathBits:
2138 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT
2140 public BitField<int, 2 * kBitsPerRegisterNumber + 5, 1> {}; // NOLINT
2142 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2143 DEFINE_PLATFORM_CODE_STUB(DoubleToI, PlatformCodeStub);
2147 class ScriptContextFieldStub : public HandlerStub {
2149 ScriptContextFieldStub(Isolate* isolate,
2150 const ScriptContextTable::LookupResult* lookup_result)
2151 : HandlerStub(isolate) {
2152 DCHECK(Accepted(lookup_result));
2153 set_sub_minor_key(ContextIndexBits::encode(lookup_result->context_index) |
2154 SlotIndexBits::encode(lookup_result->slot_index));
2157 int context_index() const {
2158 return ContextIndexBits::decode(sub_minor_key());
2161 int slot_index() const { return SlotIndexBits::decode(sub_minor_key()); }
2163 static bool Accepted(const ScriptContextTable::LookupResult* lookup_result) {
2164 return ContextIndexBits::is_valid(lookup_result->context_index) &&
2165 SlotIndexBits::is_valid(lookup_result->slot_index);
2169 static const int kContextIndexBits = 13;
2170 static const int kSlotIndexBits = 13;
2171 class ContextIndexBits : public BitField<int, 0, kContextIndexBits> {};
2173 : public BitField<int, kContextIndexBits, kSlotIndexBits> {};
2175 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; }
2177 DEFINE_CODE_STUB_BASE(ScriptContextFieldStub, HandlerStub);
2181 class LoadScriptContextFieldStub : public ScriptContextFieldStub {
2183 LoadScriptContextFieldStub(
2184 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2185 : ScriptContextFieldStub(isolate, lookup_result) {}
2188 Code::Kind kind() const OVERRIDE { return Code::LOAD_IC; }
2190 DEFINE_HANDLER_CODE_STUB(LoadScriptContextField, ScriptContextFieldStub);
2194 class StoreScriptContextFieldStub : public ScriptContextFieldStub {
2196 StoreScriptContextFieldStub(
2197 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2198 : ScriptContextFieldStub(isolate, lookup_result) {}
2201 Code::Kind kind() const OVERRIDE { return Code::STORE_IC; }
2203 DEFINE_HANDLER_CODE_STUB(StoreScriptContextField, ScriptContextFieldStub);
2207 class LoadFastElementStub : public HydrogenCodeStub {
2209 LoadFastElementStub(Isolate* isolate, bool is_js_array,
2210 ElementsKind elements_kind)
2211 : HydrogenCodeStub(isolate) {
2212 set_sub_minor_key(ElementsKindBits::encode(elements_kind) |
2213 IsJSArrayBits::encode(is_js_array));
2216 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2218 ElementsKind elements_kind() const {
2219 return ElementsKindBits::decode(sub_minor_key());
2223 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2224 class IsJSArrayBits: public BitField<bool, 8, 1> {};
2226 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE {
2227 if (FLAG_vector_ics) {
2228 return VectorLoadICDescriptor(isolate());
2230 return LoadDescriptor(isolate());
2233 DEFINE_HYDROGEN_CODE_STUB(LoadFastElement, HydrogenCodeStub);
2237 class StoreFastElementStub : public HydrogenCodeStub {
2239 StoreFastElementStub(Isolate* isolate, bool is_js_array,
2240 ElementsKind elements_kind, KeyedAccessStoreMode mode)
2241 : HydrogenCodeStub(isolate) {
2242 set_sub_minor_key(ElementsKindBits::encode(elements_kind) |
2243 IsJSArrayBits::encode(is_js_array) |
2244 StoreModeBits::encode(mode));
2247 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2249 ElementsKind elements_kind() const {
2250 return ElementsKindBits::decode(sub_minor_key());
2253 KeyedAccessStoreMode store_mode() const {
2254 return StoreModeBits::decode(sub_minor_key());
2258 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2259 class StoreModeBits: public BitField<KeyedAccessStoreMode, 8, 4> {};
2260 class IsJSArrayBits: public BitField<bool, 12, 1> {};
2262 DEFINE_CALL_INTERFACE_DESCRIPTOR(Store);
2263 DEFINE_HYDROGEN_CODE_STUB(StoreFastElement, HydrogenCodeStub);
2267 class TransitionElementsKindStub : public HydrogenCodeStub {
2269 TransitionElementsKindStub(Isolate* isolate,
2270 ElementsKind from_kind,
2271 ElementsKind to_kind,
2272 bool is_js_array) : HydrogenCodeStub(isolate) {
2273 set_sub_minor_key(FromKindBits::encode(from_kind) |
2274 ToKindBits::encode(to_kind) |
2275 IsJSArrayBits::encode(is_js_array));
2278 ElementsKind from_kind() const {
2279 return FromKindBits::decode(sub_minor_key());
2282 ElementsKind to_kind() const { return ToKindBits::decode(sub_minor_key()); }
2284 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2287 class FromKindBits: public BitField<ElementsKind, 8, 8> {};
2288 class ToKindBits: public BitField<ElementsKind, 0, 8> {};
2289 class IsJSArrayBits: public BitField<bool, 16, 1> {};
2291 DEFINE_CALL_INTERFACE_DESCRIPTOR(TransitionElementsKind);
2292 DEFINE_HYDROGEN_CODE_STUB(TransitionElementsKind, HydrogenCodeStub);
2296 class AllocateHeapNumberStub FINAL : public HydrogenCodeStub {
2298 explicit AllocateHeapNumberStub(Isolate* isolate)
2299 : HydrogenCodeStub(isolate) {}
2302 DEFINE_CALL_INTERFACE_DESCRIPTOR(AllocateHeapNumber);
2303 DEFINE_HYDROGEN_CODE_STUB(AllocateHeapNumber, HydrogenCodeStub);
2307 class ArrayConstructorStubBase : public HydrogenCodeStub {
2309 ArrayConstructorStubBase(Isolate* isolate,
2311 AllocationSiteOverrideMode override_mode)
2312 : HydrogenCodeStub(isolate) {
2313 // It only makes sense to override local allocation site behavior
2314 // if there is a difference between the global allocation site policy
2315 // for an ElementsKind and the desired usage of the stub.
2316 DCHECK(override_mode != DISABLE_ALLOCATION_SITES ||
2317 AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE);
2318 set_sub_minor_key(ElementsKindBits::encode(kind) |
2319 AllocationSiteOverrideModeBits::encode(override_mode));
2322 ElementsKind elements_kind() const {
2323 return ElementsKindBits::decode(sub_minor_key());
2326 AllocationSiteOverrideMode override_mode() const {
2327 return AllocationSiteOverrideModeBits::decode(sub_minor_key());
2330 static void GenerateStubsAheadOfTime(Isolate* isolate);
2332 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2333 static const int kConstructor = 0;
2334 static const int kAllocationSite = 1;
2337 std::ostream& BasePrintName(std::ostream& os,
2338 const char* name) const; // NOLINT
2341 // Ensure data fits within available bits.
2342 STATIC_ASSERT(LAST_ALLOCATION_SITE_OVERRIDE_MODE == 1);
2344 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2345 class AllocationSiteOverrideModeBits: public
2346 BitField<AllocationSiteOverrideMode, 8, 1> {}; // NOLINT
2348 DEFINE_CODE_STUB_BASE(ArrayConstructorStubBase, HydrogenCodeStub);
2352 class ArrayNoArgumentConstructorStub : public ArrayConstructorStubBase {
2354 ArrayNoArgumentConstructorStub(
2357 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2358 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2362 void PrintName(std::ostream& os) const OVERRIDE { // NOLINT
2363 BasePrintName(os, "ArrayNoArgumentConstructorStub");
2366 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructorConstantArgCount);
2367 DEFINE_HYDROGEN_CODE_STUB(ArrayNoArgumentConstructor,
2368 ArrayConstructorStubBase);
2372 class ArraySingleArgumentConstructorStub : public ArrayConstructorStubBase {
2374 ArraySingleArgumentConstructorStub(
2377 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2378 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2382 void PrintName(std::ostream& os) const OVERRIDE { // NOLINT
2383 BasePrintName(os, "ArraySingleArgumentConstructorStub");
2386 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2387 DEFINE_HYDROGEN_CODE_STUB(ArraySingleArgumentConstructor,
2388 ArrayConstructorStubBase);
2392 class ArrayNArgumentsConstructorStub : public ArrayConstructorStubBase {
2394 ArrayNArgumentsConstructorStub(
2397 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2398 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2402 void PrintName(std::ostream& os) const OVERRIDE { // NOLINT
2403 BasePrintName(os, "ArrayNArgumentsConstructorStub");
2406 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2407 DEFINE_HYDROGEN_CODE_STUB(ArrayNArgumentsConstructor,
2408 ArrayConstructorStubBase);
2412 class InternalArrayConstructorStubBase : public HydrogenCodeStub {
2414 InternalArrayConstructorStubBase(Isolate* isolate, ElementsKind kind)
2415 : HydrogenCodeStub(isolate) {
2416 set_sub_minor_key(ElementsKindBits::encode(kind));
2419 static void GenerateStubsAheadOfTime(Isolate* isolate);
2421 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2422 static const int kConstructor = 0;
2424 ElementsKind elements_kind() const {
2425 return ElementsKindBits::decode(sub_minor_key());
2429 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2431 DEFINE_CODE_STUB_BASE(InternalArrayConstructorStubBase, HydrogenCodeStub);
2435 class InternalArrayNoArgumentConstructorStub : public
2436 InternalArrayConstructorStubBase {
2438 InternalArrayNoArgumentConstructorStub(Isolate* isolate,
2440 : InternalArrayConstructorStubBase(isolate, kind) { }
2442 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructorConstantArgCount);
2443 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNoArgumentConstructor,
2444 InternalArrayConstructorStubBase);
2448 class InternalArraySingleArgumentConstructorStub : public
2449 InternalArrayConstructorStubBase {
2451 InternalArraySingleArgumentConstructorStub(Isolate* isolate,
2453 : InternalArrayConstructorStubBase(isolate, kind) { }
2455 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2456 DEFINE_HYDROGEN_CODE_STUB(InternalArraySingleArgumentConstructor,
2457 InternalArrayConstructorStubBase);
2461 class InternalArrayNArgumentsConstructorStub : public
2462 InternalArrayConstructorStubBase {
2464 InternalArrayNArgumentsConstructorStub(Isolate* isolate, ElementsKind kind)
2465 : InternalArrayConstructorStubBase(isolate, kind) { }
2467 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2468 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNArgumentsConstructor,
2469 InternalArrayConstructorStubBase);
2473 class StoreElementStub : public PlatformCodeStub {
2475 StoreElementStub(Isolate* isolate, ElementsKind elements_kind)
2476 : PlatformCodeStub(isolate) {
2477 minor_key_ = ElementsKindBits::encode(elements_kind);
2481 ElementsKind elements_kind() const {
2482 return ElementsKindBits::decode(minor_key_);
2485 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2487 DEFINE_CALL_INTERFACE_DESCRIPTOR(Store);
2488 DEFINE_PLATFORM_CODE_STUB(StoreElement, PlatformCodeStub);
2492 class ToBooleanStub: public HydrogenCodeStub {
2507 RESULT_AS_SMI, // For Smi(1) on truthy value, Smi(0) otherwise.
2508 RESULT_AS_ODDBALL, // For {true} on truthy value, {false} otherwise.
2509 RESULT_AS_INVERSE_ODDBALL // For {false} on truthy value, {true} otherwise.
2512 // At most 8 different types can be distinguished, because the Code object
2513 // only has room for a single byte to hold a set of these types. :-P
2514 STATIC_ASSERT(NUMBER_OF_TYPES <= 8);
2516 class Types : public EnumSet<Type, byte> {
2518 Types() : EnumSet<Type, byte>(0) {}
2519 explicit Types(byte bits) : EnumSet<Type, byte>(bits) {}
2521 byte ToByte() const { return ToIntegral(); }
2522 bool UpdateStatus(Handle<Object> object);
2523 bool NeedsMap() const;
2524 bool CanBeUndetectable() const;
2525 bool IsGeneric() const { return ToIntegral() == Generic().ToIntegral(); }
2527 static Types Generic() { return Types((1 << NUMBER_OF_TYPES) - 1); }
2530 ToBooleanStub(Isolate* isolate, ResultMode mode, Types types = Types())
2531 : HydrogenCodeStub(isolate) {
2532 set_sub_minor_key(TypesBits::encode(types.ToByte()) |
2533 ResultModeBits::encode(mode));
2536 ToBooleanStub(Isolate* isolate, ExtraICState state)
2537 : HydrogenCodeStub(isolate) {
2538 set_sub_minor_key(TypesBits::encode(static_cast<byte>(state)) |
2539 ResultModeBits::encode(RESULT_AS_SMI));
2542 bool UpdateStatus(Handle<Object> object);
2543 Types types() const { return Types(TypesBits::decode(sub_minor_key())); }
2544 ResultMode mode() const { return ResultModeBits::decode(sub_minor_key()); }
2546 Code::Kind GetCodeKind() const OVERRIDE { return Code::TO_BOOLEAN_IC; }
2547 void PrintState(std::ostream& os) const OVERRIDE; // NOLINT
2549 bool SometimesSetsUpAFrame() OVERRIDE { return false; }
2551 static Handle<Code> GetUninitialized(Isolate* isolate) {
2552 return ToBooleanStub(isolate, UNINITIALIZED).GetCode();
2555 ExtraICState GetExtraICState() const OVERRIDE { return types().ToIntegral(); }
2557 InlineCacheState GetICState() const OVERRIDE {
2558 if (types().IsEmpty()) {
2559 return ::v8::internal::UNINITIALIZED;
2566 ToBooleanStub(Isolate* isolate, InitializationState init_state)
2567 : HydrogenCodeStub(isolate, init_state) {
2568 set_sub_minor_key(ResultModeBits::encode(RESULT_AS_SMI));
2571 class TypesBits : public BitField<byte, 0, NUMBER_OF_TYPES> {};
2572 class ResultModeBits : public BitField<ResultMode, NUMBER_OF_TYPES, 2> {};
2574 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToBoolean);
2575 DEFINE_HYDROGEN_CODE_STUB(ToBoolean, HydrogenCodeStub);
2579 std::ostream& operator<<(std::ostream& os, const ToBooleanStub::Types& t);
2582 class ElementsTransitionAndStoreStub : public HydrogenCodeStub {
2584 ElementsTransitionAndStoreStub(Isolate* isolate, ElementsKind from_kind,
2585 ElementsKind to_kind, bool is_jsarray,
2586 KeyedAccessStoreMode store_mode)
2587 : HydrogenCodeStub(isolate) {
2588 set_sub_minor_key(FromBits::encode(from_kind) | ToBits::encode(to_kind) |
2589 IsJSArrayBits::encode(is_jsarray) |
2590 StoreModeBits::encode(store_mode));
2593 ElementsKind from_kind() const { return FromBits::decode(sub_minor_key()); }
2594 ElementsKind to_kind() const { return ToBits::decode(sub_minor_key()); }
2595 bool is_jsarray() const { return IsJSArrayBits::decode(sub_minor_key()); }
2596 KeyedAccessStoreMode store_mode() const {
2597 return StoreModeBits::decode(sub_minor_key());
2600 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2601 enum ParameterIndices {
2609 static const Register ValueRegister() {
2610 return ElementTransitionAndStoreDescriptor::ValueRegister();
2612 static const Register MapRegister() {
2613 return ElementTransitionAndStoreDescriptor::MapRegister();
2615 static const Register KeyRegister() {
2616 return ElementTransitionAndStoreDescriptor::NameRegister();
2618 static const Register ObjectRegister() {
2619 return ElementTransitionAndStoreDescriptor::ReceiverRegister();
2623 class FromBits : public BitField<ElementsKind, 0, 8> {};
2624 class ToBits : public BitField<ElementsKind, 8, 8> {};
2625 class IsJSArrayBits : public BitField<bool, 16, 1> {};
2626 class StoreModeBits : public BitField<KeyedAccessStoreMode, 17, 4> {};
2628 DEFINE_CALL_INTERFACE_DESCRIPTOR(ElementTransitionAndStore);
2629 DEFINE_HYDROGEN_CODE_STUB(ElementsTransitionAndStore, HydrogenCodeStub);
2633 class StoreArrayLiteralElementStub : public PlatformCodeStub {
2635 explicit StoreArrayLiteralElementStub(Isolate* isolate)
2636 : PlatformCodeStub(isolate) { }
2638 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreArrayLiteralElement);
2639 DEFINE_PLATFORM_CODE_STUB(StoreArrayLiteralElement, PlatformCodeStub);
2643 class StubFailureTrampolineStub : public PlatformCodeStub {
2645 StubFailureTrampolineStub(Isolate* isolate, StubFunctionMode function_mode)
2646 : PlatformCodeStub(isolate) {
2647 minor_key_ = FunctionModeField::encode(function_mode);
2650 static void GenerateAheadOfTime(Isolate* isolate);
2653 StubFunctionMode function_mode() const {
2654 return FunctionModeField::decode(minor_key_);
2657 class FunctionModeField : public BitField<StubFunctionMode, 0, 1> {};
2659 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2660 DEFINE_PLATFORM_CODE_STUB(StubFailureTrampoline, PlatformCodeStub);
2664 class ProfileEntryHookStub : public PlatformCodeStub {
2666 explicit ProfileEntryHookStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
2668 // The profile entry hook function is not allowed to cause a GC.
2669 bool SometimesSetsUpAFrame() OVERRIDE { return false; }
2671 // Generates a call to the entry hook if it's enabled.
2672 static void MaybeCallEntryHook(MacroAssembler* masm);
2675 static void EntryHookTrampoline(intptr_t function,
2676 intptr_t stack_pointer,
2679 // ProfileEntryHookStub is called at the start of a function, so it has the
2680 // same register set.
2681 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction)
2682 DEFINE_PLATFORM_CODE_STUB(ProfileEntryHook, PlatformCodeStub);
2686 class StoreBufferOverflowStub : public PlatformCodeStub {
2688 StoreBufferOverflowStub(Isolate* isolate, SaveFPRegsMode save_fp)
2689 : PlatformCodeStub(isolate) {
2690 minor_key_ = SaveDoublesBits::encode(save_fp == kSaveFPRegs);
2693 static void GenerateFixedRegStubsAheadOfTime(Isolate* isolate);
2694 bool SometimesSetsUpAFrame() OVERRIDE { return false; }
2697 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
2699 class SaveDoublesBits : public BitField<bool, 0, 1> {};
2701 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2702 DEFINE_PLATFORM_CODE_STUB(StoreBufferOverflow, PlatformCodeStub);
2706 class SubStringStub : public PlatformCodeStub {
2708 explicit SubStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
2710 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
2711 DEFINE_PLATFORM_CODE_STUB(SubString, PlatformCodeStub);
2715 class ToNumberStub FINAL : public PlatformCodeStub {
2717 explicit ToNumberStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
2719 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToNumber);
2720 DEFINE_PLATFORM_CODE_STUB(ToNumber, PlatformCodeStub);
2724 class StringCompareStub : public PlatformCodeStub {
2726 explicit StringCompareStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
2728 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
2729 DEFINE_PLATFORM_CODE_STUB(StringCompare, PlatformCodeStub);
2733 #undef DEFINE_CALL_INTERFACE_DESCRIPTOR
2734 #undef DEFINE_PLATFORM_CODE_STUB
2735 #undef DEFINE_HANDLER_CODE_STUB
2736 #undef DEFINE_HYDROGEN_CODE_STUB
2737 #undef DEFINE_CODE_STUB
2738 #undef DEFINE_CODE_STUB_BASE
2739 } } // namespace v8::internal
2741 #endif // V8_CODE_STUBS_H_