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) \
35 V(FunctionPrototype) \
37 V(InternalArrayConstructor) \
39 V(KeyedLoadICTrampoline) \
42 V(LoadIndexedInterceptor) \
43 V(LoadIndexedString) \
48 V(StoreArrayLiteralElement) \
49 V(StoreBufferOverflow) \
52 V(StubFailureTrampoline) \
57 V(VectorStoreICTrampoline) \
58 V(VectorKeyedStoreICTrampoline) \
60 V(VectorKeyedStoreIC) \
61 /* HydrogenCodeStubs */ \
62 V(AllocateHeapNumber) \
63 V(ArrayNArgumentsConstructor) \
64 V(ArrayNoArgumentConstructor) \
65 V(ArraySingleArgumentConstructor) \
67 V(BinaryOpWithAllocationSite) \
69 V(CreateAllocationSite) \
71 V(ElementsTransitionAndStore) \
72 V(FastCloneShallowArray) \
73 V(FastCloneShallowObject) \
76 V(GrowArrayElements) \
77 V(InternalArrayNArgumentsConstructor) \
78 V(InternalArrayNoArgumentConstructor) \
79 V(InternalArraySingleArgumentConstructor) \
81 V(LoadGlobalViaContext) \
82 V(LoadScriptContextField) \
83 V(LoadDictionaryElement) \
84 V(NameDictionaryLookup) \
87 V(RegExpConstructResult) \
89 V(StoreGlobalViaContext) \
90 V(StoreScriptContextField) \
93 V(TransitionElementsKind) \
96 /* TurboFanCodeStubs */ \
101 /* IC Handler stubs */ \
102 V(ArrayBufferViewLoadField) \
106 V(KeyedLoadSloppyArguments) \
107 V(KeyedStoreSloppyArguments) \
113 // List of code stubs only used on ARM 32 bits platforms.
114 #if V8_TARGET_ARCH_ARM
115 #define CODE_STUB_LIST_ARM(V) V(DirectCEntry)
118 #define CODE_STUB_LIST_ARM(V)
121 // List of code stubs only used on ARM 64 bits platforms.
122 #if V8_TARGET_ARCH_ARM64
123 #define CODE_STUB_LIST_ARM64(V) \
125 V(RestoreRegistersState) \
126 V(StoreRegistersState)
129 #define CODE_STUB_LIST_ARM64(V)
132 // List of code stubs only used on PPC platforms.
133 #ifdef V8_TARGET_ARCH_PPC
134 #define CODE_STUB_LIST_PPC(V) \
136 V(StoreRegistersState) \
137 V(RestoreRegistersState)
139 #define CODE_STUB_LIST_PPC(V)
142 // List of code stubs only used on MIPS platforms.
143 #if V8_TARGET_ARCH_MIPS
144 #define CODE_STUB_LIST_MIPS(V) \
146 V(RestoreRegistersState) \
147 V(StoreRegistersState)
148 #elif V8_TARGET_ARCH_MIPS64
149 #define CODE_STUB_LIST_MIPS(V) \
151 V(RestoreRegistersState) \
152 V(StoreRegistersState)
154 #define CODE_STUB_LIST_MIPS(V)
157 // Combined list of code stubs.
158 #define CODE_STUB_LIST(V) \
159 CODE_STUB_LIST_ALL_PLATFORMS(V) \
160 CODE_STUB_LIST_ARM(V) \
161 CODE_STUB_LIST_ARM64(V) \
162 CODE_STUB_LIST_PPC(V) \
163 CODE_STUB_LIST_MIPS(V)
165 static const int kHasReturnedMinusZeroSentinel = 1;
167 // Stub is base classes of all stubs.
168 class CodeStub BASE_EMBEDDED {
171 // TODO(mvstanton): eliminate the NoCache key by getting rid
172 // of the non-monomorphic-cache.
173 NoCache = 0, // marker for stubs that do custom caching]
174 #define DEF_ENUM(name) name,
175 CODE_STUB_LIST(DEF_ENUM)
180 // Retrieve the code for the stub. Generate the code if needed.
181 Handle<Code> GetCode();
183 // Retrieve the code for the stub, make and return a copy of the code.
184 Handle<Code> GetCodeCopy(const Code::FindAndReplacePattern& pattern);
186 static Major MajorKeyFromKey(uint32_t key) {
187 return static_cast<Major>(MajorKeyBits::decode(key));
189 static uint32_t MinorKeyFromKey(uint32_t key) {
190 return MinorKeyBits::decode(key);
193 // Gets the major key from a code object that is a code stub or binary op IC.
194 static Major GetMajorKey(Code* code_stub) {
195 return MajorKeyFromKey(code_stub->stub_key());
198 static uint32_t NoCacheKey() { return MajorKeyBits::encode(NoCache); }
200 static const char* MajorName(Major major_key);
202 explicit CodeStub(Isolate* isolate) : minor_key_(0), isolate_(isolate) {}
203 virtual ~CodeStub() {}
205 static void GenerateStubsAheadOfTime(Isolate* isolate);
206 static void GenerateFPStubs(Isolate* isolate);
208 // Some stubs put untagged junk on the stack that cannot be scanned by the
209 // GC. This means that we must be statically sure that no GC can occur while
210 // they are running. If that is the case they should override this to return
211 // true, which will cause an assertion if we try to call something that can
212 // GC or if we try to put a stack frame on top of the junk, which would not
213 // result in a traversable stack.
214 virtual bool SometimesSetsUpAFrame() { return true; }
216 // Lookup the code in the (possibly custom) cache.
217 bool FindCodeInCache(Code** code_out);
219 virtual CallInterfaceDescriptor GetCallInterfaceDescriptor() const = 0;
221 virtual int GetStackParameterCount() const {
222 return GetCallInterfaceDescriptor().GetStackParameterCount();
225 virtual void InitializeDescriptor(CodeStubDescriptor* descriptor) {}
227 static void InitializeDescriptor(Isolate* isolate, uint32_t key,
228 CodeStubDescriptor* desc);
230 static MaybeHandle<Code> GetCode(Isolate* isolate, uint32_t key);
232 // Returns information for computing the number key.
233 virtual Major MajorKey() const = 0;
234 uint32_t MinorKey() const { return minor_key_; }
236 // BinaryOpStub needs to override this.
237 virtual Code::Kind GetCodeKind() const;
239 virtual InlineCacheState GetICState() const { return UNINITIALIZED; }
240 virtual ExtraICState GetExtraICState() const { return kNoExtraICState; }
241 virtual Code::StubType GetStubType() const { return Code::NORMAL; }
243 friend std::ostream& operator<<(std::ostream& os, const CodeStub& s) {
248 Isolate* isolate() const { return isolate_; }
251 CodeStub(uint32_t key, Isolate* isolate)
252 : minor_key_(MinorKeyFromKey(key)), isolate_(isolate) {}
254 // Generates the assembler code for the stub.
255 virtual Handle<Code> GenerateCode() = 0;
257 // Returns whether the code generated for this stub needs to be allocated as
258 // a fixed (non-moveable) code object.
259 virtual bool NeedsImmovableCode() { return false; }
261 virtual void PrintName(std::ostream& os) const; // NOLINT
262 virtual void PrintBaseName(std::ostream& os) const; // NOLINT
263 virtual void PrintState(std::ostream& os) const { ; } // NOLINT
265 // Computes the key based on major and minor.
267 DCHECK(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
268 return MinorKeyBits::encode(MinorKey()) | MajorKeyBits::encode(MajorKey());
274 // Perform bookkeeping required after code generation when stub code is
275 // initially generated.
276 void RecordCodeGeneration(Handle<Code> code);
278 // Finish the code object after it has been generated.
279 virtual void FinishCode(Handle<Code> code) { }
281 // Activate newly generated stub. Is called after
282 // registering stub in the stub cache.
283 virtual void Activate(Code* code) { }
285 // Add the code to a specialized cache, specific to an individual
286 // stub type. Please note, this method must add the code object to a
287 // roots object, otherwise we will remove the code during GC.
288 virtual void AddToSpecialCache(Handle<Code> new_object) { }
290 // Find code in a specialized cache, work is delegated to the specific stub.
291 virtual bool FindCodeInSpecialCache(Code** code_out) {
295 // If a stub uses a special cache override this.
296 virtual bool UseSpecialCache() { return false; }
298 // We use this dispatch to statically instantiate the correct code stub for
299 // the given stub key and call the passed function with that code stub.
300 typedef void (*DispatchedCall)(CodeStub* stub, void** value_out);
301 static void Dispatch(Isolate* isolate, uint32_t key, void** value_out,
302 DispatchedCall call);
304 static void GetCodeDispatchCall(CodeStub* stub, void** value_out);
306 STATIC_ASSERT(NUMBER_OF_IDS < (1 << kStubMajorKeyBits));
307 class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {};
308 class MinorKeyBits: public BitField<uint32_t,
309 kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT
311 friend class BreakPointIterator;
317 #define DEFINE_CODE_STUB_BASE(NAME, SUPER) \
319 NAME(uint32_t key, Isolate* isolate) : SUPER(key, isolate) {} \
322 DISALLOW_COPY_AND_ASSIGN(NAME)
325 #define DEFINE_CODE_STUB(NAME, SUPER) \
327 inline Major MajorKey() const override { return NAME; }; \
328 DEFINE_CODE_STUB_BASE(NAME##Stub, SUPER)
331 #define DEFINE_PLATFORM_CODE_STUB(NAME, SUPER) \
333 void Generate(MacroAssembler* masm) override; \
334 DEFINE_CODE_STUB(NAME, SUPER)
337 #define DEFINE_HYDROGEN_CODE_STUB(NAME, SUPER) \
339 void InitializeDescriptor(CodeStubDescriptor* descriptor) override; \
340 Handle<Code> GenerateCode() override; \
341 DEFINE_CODE_STUB(NAME, SUPER)
343 #define DEFINE_TURBOFAN_CODE_STUB(NAME, SUPER) \
345 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
346 return DESC##Descriptor(isolate()); \
348 DEFINE_CODE_STUB(NAME, SUPER)
350 #define DEFINE_TURBOFAN_IC(NAME, SUPER, DESC) \
352 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
353 if (GetCallMode() == CALL_FROM_OPTIMIZED_CODE) { \
354 return DESC##CallFromOptimizedCodeDescriptor(isolate()); \
356 return DESC##CallFromUnoptimizedCodeDescriptor(isolate()); \
361 DEFINE_CODE_STUB(NAME, SUPER)
363 #define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \
365 Handle<Code> GenerateCode() override; \
366 DEFINE_CODE_STUB(NAME, SUPER)
368 #define DEFINE_CALL_INTERFACE_DESCRIPTOR(NAME) \
370 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
371 return NAME##Descriptor(isolate()); \
374 // There are some code stubs we just can't describe right now with a
375 // CallInterfaceDescriptor. Isolate behavior for those cases with this macro.
376 // An attempt to retrieve a descriptor will fail.
377 #define DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR() \
379 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
381 return CallInterfaceDescriptor(); \
385 class PlatformCodeStub : public CodeStub {
387 // Retrieve the code for the stub. Generate the code if needed.
388 Handle<Code> GenerateCode() override;
391 explicit PlatformCodeStub(Isolate* isolate) : CodeStub(isolate) {}
393 // Generates the assembler code for the stub.
394 virtual void Generate(MacroAssembler* masm) = 0;
396 DEFINE_CODE_STUB_BASE(PlatformCodeStub, CodeStub);
400 enum StubFunctionMode { NOT_JS_FUNCTION_STUB_MODE, JS_FUNCTION_STUB_MODE };
403 class CodeStubDescriptor {
405 explicit CodeStubDescriptor(CodeStub* stub);
407 CodeStubDescriptor(Isolate* isolate, uint32_t stub_key);
409 void Initialize(Address deoptimization_handler = NULL,
410 int hint_stack_parameter_count = -1,
411 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
412 void Initialize(Register stack_parameter_count,
413 Address deoptimization_handler = NULL,
414 int hint_stack_parameter_count = -1,
415 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
417 void SetMissHandler(ExternalReference handler) {
418 miss_handler_ = handler;
419 has_miss_handler_ = true;
420 // Our miss handler infrastructure doesn't currently support
421 // variable stack parameter counts.
422 DCHECK(!stack_parameter_count_.is_valid());
425 void set_call_descriptor(CallInterfaceDescriptor d) { call_descriptor_ = d; }
426 CallInterfaceDescriptor call_descriptor() const { return call_descriptor_; }
428 int GetRegisterParameterCount() const {
429 return call_descriptor().GetRegisterParameterCount();
432 int GetStackParameterCount() const {
433 return call_descriptor().GetStackParameterCount();
436 int GetParameterCount() const {
437 return call_descriptor().GetParameterCount();
440 Register GetRegisterParameter(int index) const {
441 return call_descriptor().GetRegisterParameter(index);
444 Type* GetParameterType(int index) const {
445 return call_descriptor().GetParameterType(index);
448 ExternalReference miss_handler() const {
449 DCHECK(has_miss_handler_);
450 return miss_handler_;
453 bool has_miss_handler() const {
454 return has_miss_handler_;
457 int GetHandlerParameterCount() const {
458 int params = GetParameterCount();
459 if (PassesArgumentsToDeoptimizationHandler()) {
465 int hint_stack_parameter_count() const { return hint_stack_parameter_count_; }
466 Register stack_parameter_count() const { return stack_parameter_count_; }
467 StubFunctionMode function_mode() const { return function_mode_; }
468 Address deoptimization_handler() const { return deoptimization_handler_; }
471 bool PassesArgumentsToDeoptimizationHandler() const {
472 return stack_parameter_count_.is_valid();
475 CallInterfaceDescriptor call_descriptor_;
476 Register stack_parameter_count_;
477 // If hint_stack_parameter_count_ > 0, the code stub can optimize the
478 // return sequence. Default value is -1, which means it is ignored.
479 int hint_stack_parameter_count_;
480 StubFunctionMode function_mode_;
482 Address deoptimization_handler_;
484 ExternalReference miss_handler_;
485 bool has_miss_handler_;
489 class HydrogenCodeStub : public CodeStub {
491 enum InitializationState {
496 template<class SubClass>
497 static Handle<Code> GetUninitialized(Isolate* isolate) {
498 SubClass::GenerateAheadOfTime(isolate);
499 return SubClass().GetCode(isolate);
502 // Retrieve the code for the stub. Generate the code if needed.
503 Handle<Code> GenerateCode() override = 0;
505 bool IsUninitialized() const { return IsMissBits::decode(minor_key_); }
507 Handle<Code> GenerateLightweightMissCode(ExternalReference miss);
509 template<class StateType>
510 void TraceTransition(StateType from, StateType to);
513 explicit HydrogenCodeStub(Isolate* isolate,
514 InitializationState state = INITIALIZED)
515 : CodeStub(isolate) {
516 minor_key_ = IsMissBits::encode(state == UNINITIALIZED);
519 void set_sub_minor_key(uint32_t key) {
520 minor_key_ = SubMinorKeyBits::update(minor_key_, key);
523 uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
525 static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
528 class IsMissBits : public BitField<bool, kSubMinorKeyBits, 1> {};
529 class SubMinorKeyBits : public BitField<int, 0, kSubMinorKeyBits> {};
531 void GenerateLightweightMiss(MacroAssembler* masm, ExternalReference miss);
533 DEFINE_CODE_STUB_BASE(HydrogenCodeStub, CodeStub);
537 class TurboFanCodeStub : public CodeStub {
539 // Retrieve the code for the stub. Generate the code if needed.
540 Handle<Code> GenerateCode() override;
542 virtual int GetStackParameterCount() const override {
543 return GetCallInterfaceDescriptor().GetStackParameterCount();
546 Code::StubType GetStubType() const override { return Code::FAST; }
549 explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {}
552 DEFINE_CODE_STUB_BASE(TurboFanCodeStub, CodeStub);
556 class TurboFanIC : public TurboFanCodeStub {
558 enum CallMode { CALL_FROM_UNOPTIMIZED_CODE, CALL_FROM_OPTIMIZED_CODE };
561 explicit TurboFanIC(Isolate* isolate, CallMode mode)
562 : TurboFanCodeStub(isolate) {
563 minor_key_ = CallModeBits::encode(mode);
566 CallMode GetCallMode() const { return CallModeBits::decode(minor_key_); }
568 void set_sub_minor_key(uint32_t key) {
569 minor_key_ = SubMinorKeyBits::update(minor_key_, key);
572 uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
574 static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
577 class CallModeBits : public BitField<CallMode, 0, 1> {};
578 class SubMinorKeyBits : public BitField<int, 1, kSubMinorKeyBits> {};
579 DEFINE_CODE_STUB_BASE(TurboFanIC, TurboFanCodeStub);
583 // Helper interface to prepare to/restore after making runtime calls.
584 class RuntimeCallHelper {
586 virtual ~RuntimeCallHelper() {}
588 virtual void BeforeCall(MacroAssembler* masm) const = 0;
590 virtual void AfterCall(MacroAssembler* masm) const = 0;
593 RuntimeCallHelper() {}
596 DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper);
600 } } // namespace v8::internal
602 #if V8_TARGET_ARCH_IA32
603 #include "src/ia32/code-stubs-ia32.h"
604 #elif V8_TARGET_ARCH_X64
605 #include "src/x64/code-stubs-x64.h"
606 #elif V8_TARGET_ARCH_ARM64
607 #include "src/arm64/code-stubs-arm64.h"
608 #elif V8_TARGET_ARCH_ARM
609 #include "src/arm/code-stubs-arm.h"
610 #elif V8_TARGET_ARCH_PPC
611 #include "src/ppc/code-stubs-ppc.h"
612 #elif V8_TARGET_ARCH_MIPS
613 #include "src/mips/code-stubs-mips.h"
614 #elif V8_TARGET_ARCH_MIPS64
615 #include "src/mips64/code-stubs-mips64.h"
616 #elif V8_TARGET_ARCH_X87
617 #include "src/x87/code-stubs-x87.h"
619 #error Unsupported target architecture.
626 // RuntimeCallHelper implementation used in stubs: enters/leaves a
627 // newly created internal frame before/after the runtime call.
628 class StubRuntimeCallHelper : public RuntimeCallHelper {
630 StubRuntimeCallHelper() {}
632 virtual void BeforeCall(MacroAssembler* masm) const;
634 virtual void AfterCall(MacroAssembler* masm) const;
638 // Trivial RuntimeCallHelper implementation.
639 class NopRuntimeCallHelper : public RuntimeCallHelper {
641 NopRuntimeCallHelper() {}
643 virtual void BeforeCall(MacroAssembler* masm) const {}
645 virtual void AfterCall(MacroAssembler* masm) const {}
649 class MathFloorStub : public TurboFanIC {
651 explicit MathFloorStub(Isolate* isolate, TurboFanIC::CallMode mode)
652 : TurboFanIC(isolate, mode) {}
653 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
654 DEFINE_TURBOFAN_IC(MathFloor, TurboFanIC, MathRoundVariant);
658 class StringLengthTFStub : public TurboFanCodeStub {
660 explicit StringLengthTFStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
662 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
663 InlineCacheState GetICState() const override { return MONOMORPHIC; }
664 ExtraICState GetExtraICState() const override { return Code::LOAD_IC; }
666 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
667 DEFINE_CODE_STUB(StringLengthTF, TurboFanCodeStub);
671 enum StringAddFlags {
672 // Omit both parameter checks.
673 STRING_ADD_CHECK_NONE = 0,
674 // Check left parameter.
675 STRING_ADD_CHECK_LEFT = 1 << 0,
676 // Check right parameter.
677 STRING_ADD_CHECK_RIGHT = 1 << 1,
678 // Check both parameters.
679 STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT,
680 // Convert parameters when check fails (instead of throwing an exception).
681 STRING_ADD_CONVERT = 1 << 2,
682 STRING_ADD_CONVERT_LEFT = STRING_ADD_CHECK_LEFT | STRING_ADD_CONVERT,
683 STRING_ADD_CONVERT_RIGHT = STRING_ADD_CHECK_RIGHT | STRING_ADD_CONVERT
687 std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags);
690 class StringAddTFStub : public TurboFanCodeStub {
692 StringAddTFStub(Isolate* isolate, StringAddFlags flags,
693 PretenureFlag pretenure_flag)
694 : TurboFanCodeStub(isolate) {
695 minor_key_ = StringAddFlagsBits::encode(flags) |
696 PretenureFlagBits::encode(pretenure_flag);
699 StringAddFlags flags() const {
700 return StringAddFlagsBits::decode(MinorKey());
703 PretenureFlag pretenure_flag() const {
704 return PretenureFlagBits::decode(MinorKey());
708 class StringAddFlagsBits : public BitField<StringAddFlags, 0, 3> {};
709 class PretenureFlagBits : public BitField<PretenureFlag, 3, 1> {};
711 void PrintBaseName(std::ostream& os) const override; // NOLINT
713 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
714 DEFINE_CODE_STUB(StringAddTF, TurboFanCodeStub);
718 class NumberToStringStub final : public HydrogenCodeStub {
720 explicit NumberToStringStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
722 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
723 static const int kNumber = 0;
725 DEFINE_CALL_INTERFACE_DESCRIPTOR(NumberToString);
726 DEFINE_HYDROGEN_CODE_STUB(NumberToString, HydrogenCodeStub);
730 class TypeofStub final : public HydrogenCodeStub {
732 explicit TypeofStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
734 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
735 static const int kObject = 0;
737 static void GenerateAheadOfTime(Isolate* isolate);
739 DEFINE_CALL_INTERFACE_DESCRIPTOR(Typeof);
740 DEFINE_HYDROGEN_CODE_STUB(Typeof, HydrogenCodeStub);
744 class FastNewClosureStub : public HydrogenCodeStub {
746 FastNewClosureStub(Isolate* isolate, LanguageMode language_mode,
748 : HydrogenCodeStub(isolate) {
749 DCHECK(IsValidFunctionKind(kind));
750 set_sub_minor_key(LanguageModeBits::encode(language_mode) |
751 FunctionKindBits::encode(kind));
754 LanguageMode language_mode() const {
755 return LanguageModeBits::decode(sub_minor_key());
758 FunctionKind kind() const {
759 return FunctionKindBits::decode(sub_minor_key());
763 STATIC_ASSERT(LANGUAGE_END == 3);
764 class LanguageModeBits : public BitField<LanguageMode, 0, 2> {};
765 class FunctionKindBits : public BitField<FunctionKind, 2, 8> {};
767 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewClosure);
768 DEFINE_HYDROGEN_CODE_STUB(FastNewClosure, HydrogenCodeStub);
772 class FastNewContextStub final : public HydrogenCodeStub {
774 static const int kMaximumSlots = 64;
776 FastNewContextStub(Isolate* isolate, int slots) : HydrogenCodeStub(isolate) {
777 DCHECK(slots >= 0 && slots <= kMaximumSlots);
778 set_sub_minor_key(SlotsBits::encode(slots));
781 int slots() const { return SlotsBits::decode(sub_minor_key()); }
783 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
784 static const int kFunction = 0;
787 class SlotsBits : public BitField<int, 0, 8> {};
789 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewContext);
790 DEFINE_HYDROGEN_CODE_STUB(FastNewContext, HydrogenCodeStub);
794 class FastCloneShallowArrayStub : public HydrogenCodeStub {
796 FastCloneShallowArrayStub(Isolate* isolate,
797 AllocationSiteMode allocation_site_mode)
798 : HydrogenCodeStub(isolate) {
799 set_sub_minor_key(AllocationSiteModeBits::encode(allocation_site_mode));
802 AllocationSiteMode allocation_site_mode() const {
803 return AllocationSiteModeBits::decode(sub_minor_key());
807 class AllocationSiteModeBits: public BitField<AllocationSiteMode, 0, 1> {};
809 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowArray);
810 DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowArray, HydrogenCodeStub);
814 class FastCloneShallowObjectStub : public HydrogenCodeStub {
816 // Maximum number of properties in copied object.
817 static const int kMaximumClonedProperties = 6;
819 FastCloneShallowObjectStub(Isolate* isolate, int length)
820 : HydrogenCodeStub(isolate) {
821 DCHECK_GE(length, 0);
822 DCHECK_LE(length, kMaximumClonedProperties);
823 set_sub_minor_key(LengthBits::encode(length));
826 int length() const { return LengthBits::decode(sub_minor_key()); }
829 class LengthBits : public BitField<int, 0, 4> {};
831 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowObject);
832 DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowObject, HydrogenCodeStub);
836 class CreateAllocationSiteStub : public HydrogenCodeStub {
838 explicit CreateAllocationSiteStub(Isolate* isolate)
839 : HydrogenCodeStub(isolate) { }
841 static void GenerateAheadOfTime(Isolate* isolate);
843 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateAllocationSite);
844 DEFINE_HYDROGEN_CODE_STUB(CreateAllocationSite, HydrogenCodeStub);
848 class CreateWeakCellStub : public HydrogenCodeStub {
850 explicit CreateWeakCellStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
852 static void GenerateAheadOfTime(Isolate* isolate);
854 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateWeakCell);
855 DEFINE_HYDROGEN_CODE_STUB(CreateWeakCell, HydrogenCodeStub);
859 class GrowArrayElementsStub : public HydrogenCodeStub {
861 GrowArrayElementsStub(Isolate* isolate, bool is_js_array, ElementsKind kind)
862 : HydrogenCodeStub(isolate) {
863 set_sub_minor_key(ElementsKindBits::encode(kind) |
864 IsJsArrayBits::encode(is_js_array));
867 ElementsKind elements_kind() const {
868 return ElementsKindBits::decode(sub_minor_key());
871 bool is_js_array() const { return IsJsArrayBits::decode(sub_minor_key()); }
874 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
875 class IsJsArrayBits : public BitField<bool, ElementsKindBits::kNext, 1> {};
877 DEFINE_CALL_INTERFACE_DESCRIPTOR(GrowArrayElements);
878 DEFINE_HYDROGEN_CODE_STUB(GrowArrayElements, HydrogenCodeStub);
882 class InstanceOfStub final : public PlatformCodeStub {
884 explicit InstanceOfStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
887 DEFINE_CALL_INTERFACE_DESCRIPTOR(InstanceOf);
888 DEFINE_PLATFORM_CODE_STUB(InstanceOf, PlatformCodeStub);
892 enum AllocationSiteOverrideMode {
894 DISABLE_ALLOCATION_SITES,
895 LAST_ALLOCATION_SITE_OVERRIDE_MODE = DISABLE_ALLOCATION_SITES
899 class ArrayConstructorStub: public PlatformCodeStub {
901 enum ArgumentCountKey { ANY, NONE, ONE, MORE_THAN_ONE };
903 ArrayConstructorStub(Isolate* isolate, int argument_count);
905 explicit ArrayConstructorStub(Isolate* isolate);
908 ArgumentCountKey argument_count() const {
909 return ArgumentCountBits::decode(minor_key_);
912 void GenerateDispatchToArrayStub(MacroAssembler* masm,
913 AllocationSiteOverrideMode mode);
915 void PrintName(std::ostream& os) const override; // NOLINT
917 class ArgumentCountBits : public BitField<ArgumentCountKey, 0, 2> {};
919 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
920 DEFINE_PLATFORM_CODE_STUB(ArrayConstructor, PlatformCodeStub);
924 class InternalArrayConstructorStub: public PlatformCodeStub {
926 explicit InternalArrayConstructorStub(Isolate* isolate);
929 void GenerateCase(MacroAssembler* masm, ElementsKind kind);
931 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
932 DEFINE_PLATFORM_CODE_STUB(InternalArrayConstructor, PlatformCodeStub);
936 class MathPowStub: public PlatformCodeStub {
938 enum ExponentType { INTEGER, DOUBLE, TAGGED, ON_STACK };
940 MathPowStub(Isolate* isolate, ExponentType exponent_type)
941 : PlatformCodeStub(isolate) {
942 minor_key_ = ExponentTypeBits::encode(exponent_type);
945 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
946 if (exponent_type() == TAGGED) {
947 return MathPowTaggedDescriptor(isolate());
948 } else if (exponent_type() == INTEGER) {
949 return MathPowIntegerDescriptor(isolate());
951 // A CallInterfaceDescriptor doesn't specify double registers (yet).
952 return ContextOnlyDescriptor(isolate());
956 ExponentType exponent_type() const {
957 return ExponentTypeBits::decode(minor_key_);
960 class ExponentTypeBits : public BitField<ExponentType, 0, 2> {};
962 DEFINE_PLATFORM_CODE_STUB(MathPow, PlatformCodeStub);
966 class CallICStub: public PlatformCodeStub {
968 CallICStub(Isolate* isolate, const CallICState& state)
969 : PlatformCodeStub(isolate) {
970 minor_key_ = state.GetExtraICState();
973 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
975 InlineCacheState GetICState() const override { return DEFAULT; }
977 ExtraICState GetExtraICState() const final {
978 return static_cast<ExtraICState>(minor_key_);
982 bool CallAsMethod() const {
983 return state().call_type() == CallICState::METHOD;
986 int arg_count() const { return state().arg_count(); }
988 CallICState state() const {
989 return CallICState(static_cast<ExtraICState>(minor_key_));
992 // Code generation helpers.
993 void GenerateMiss(MacroAssembler* masm);
994 void HandleArrayCase(MacroAssembler* masm, Label* miss);
997 void PrintState(std::ostream& os) const override; // NOLINT
999 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedbackAndVector);
1000 DEFINE_PLATFORM_CODE_STUB(CallIC, PlatformCodeStub);
1004 // TODO(verwaest): Translate to hydrogen code stub.
1005 class FunctionPrototypeStub : public PlatformCodeStub {
1007 explicit FunctionPrototypeStub(Isolate* isolate)
1008 : PlatformCodeStub(isolate) {}
1010 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1012 // TODO(mvstanton): only the receiver register is accessed. When this is
1013 // translated to a hydrogen code stub, a new CallInterfaceDescriptor
1014 // should be created that just uses that register for more efficient code.
1015 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1016 return LoadWithVectorDescriptor(isolate());
1019 DEFINE_PLATFORM_CODE_STUB(FunctionPrototype, PlatformCodeStub);
1023 // TODO(mvstanton): Translate to hydrogen code stub.
1024 class LoadIndexedInterceptorStub : public PlatformCodeStub {
1026 explicit LoadIndexedInterceptorStub(Isolate* isolate)
1027 : PlatformCodeStub(isolate) {}
1029 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1030 Code::StubType GetStubType() const override { return Code::FAST; }
1032 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
1033 DEFINE_PLATFORM_CODE_STUB(LoadIndexedInterceptor, PlatformCodeStub);
1037 class LoadIndexedStringStub : public PlatformCodeStub {
1039 explicit LoadIndexedStringStub(Isolate* isolate)
1040 : PlatformCodeStub(isolate) {}
1042 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1043 Code::StubType GetStubType() const override { return Code::FAST; }
1045 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
1046 DEFINE_PLATFORM_CODE_STUB(LoadIndexedString, PlatformCodeStub);
1050 class HandlerStub : public HydrogenCodeStub {
1052 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1053 ExtraICState GetExtraICState() const override { return kind(); }
1054 InlineCacheState GetICState() const override { return MONOMORPHIC; }
1056 void InitializeDescriptor(CodeStubDescriptor* descriptor) override;
1058 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override;
1061 explicit HandlerStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
1063 virtual Code::Kind kind() const = 0;
1065 DEFINE_CODE_STUB_BASE(HandlerStub, HydrogenCodeStub);
1069 class LoadFieldStub: public HandlerStub {
1071 LoadFieldStub(Isolate* isolate, FieldIndex index) : HandlerStub(isolate) {
1072 int property_index_key = index.GetFieldAccessStubKey();
1073 set_sub_minor_key(LoadFieldByIndexBits::encode(property_index_key));
1076 FieldIndex index() const {
1077 int property_index_key = LoadFieldByIndexBits::decode(sub_minor_key());
1078 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1082 Code::Kind kind() const override { return Code::LOAD_IC; }
1083 Code::StubType GetStubType() const override { return Code::FAST; }
1086 class LoadFieldByIndexBits : public BitField<int, 0, 13> {};
1088 DEFINE_HANDLER_CODE_STUB(LoadField, HandlerStub);
1092 class ArrayBufferViewLoadFieldStub : public HandlerStub {
1094 ArrayBufferViewLoadFieldStub(Isolate* isolate, FieldIndex index)
1095 : HandlerStub(isolate) {
1096 int property_index_key = index.GetFieldAccessStubKey();
1098 ArrayBufferViewLoadFieldByIndexBits::encode(property_index_key));
1101 FieldIndex index() const {
1102 int property_index_key =
1103 ArrayBufferViewLoadFieldByIndexBits::decode(sub_minor_key());
1104 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1108 Code::Kind kind() const override { return Code::LOAD_IC; }
1109 Code::StubType GetStubType() const override { return Code::FAST; }
1112 class ArrayBufferViewLoadFieldByIndexBits : public BitField<int, 0, 13> {};
1114 DEFINE_HANDLER_CODE_STUB(ArrayBufferViewLoadField, HandlerStub);
1118 class KeyedLoadSloppyArgumentsStub : public HandlerStub {
1120 explicit KeyedLoadSloppyArgumentsStub(Isolate* isolate)
1121 : HandlerStub(isolate) {}
1124 Code::Kind kind() const override { return Code::KEYED_LOAD_IC; }
1125 Code::StubType GetStubType() const override { return Code::FAST; }
1128 DEFINE_HANDLER_CODE_STUB(KeyedLoadSloppyArguments, HandlerStub);
1132 class CommonStoreModeBits : public BitField<KeyedAccessStoreMode, 0, 3> {};
1134 class KeyedStoreSloppyArgumentsStub : public HandlerStub {
1136 explicit KeyedStoreSloppyArgumentsStub(Isolate* isolate,
1137 KeyedAccessStoreMode mode)
1138 : HandlerStub(isolate) {
1139 set_sub_minor_key(CommonStoreModeBits::encode(mode));
1143 Code::Kind kind() const override { return Code::KEYED_STORE_IC; }
1144 Code::StubType GetStubType() const override { return Code::FAST; }
1147 DEFINE_HANDLER_CODE_STUB(KeyedStoreSloppyArguments, HandlerStub);
1151 class LoadConstantStub : public HandlerStub {
1153 LoadConstantStub(Isolate* isolate, int constant_index)
1154 : HandlerStub(isolate) {
1155 set_sub_minor_key(ConstantIndexBits::encode(constant_index));
1158 int constant_index() const {
1159 return ConstantIndexBits::decode(sub_minor_key());
1163 Code::Kind kind() const override { return Code::LOAD_IC; }
1164 Code::StubType GetStubType() const override { return Code::FAST; }
1167 class ConstantIndexBits : public BitField<int, 0, kSubMinorKeyBits> {};
1169 DEFINE_HANDLER_CODE_STUB(LoadConstant, HandlerStub);
1173 class StringLengthStub: public HandlerStub {
1175 explicit StringLengthStub(Isolate* isolate) : HandlerStub(isolate) {}
1178 Code::Kind kind() const override { return Code::LOAD_IC; }
1179 Code::StubType GetStubType() const override { return Code::FAST; }
1181 DEFINE_HANDLER_CODE_STUB(StringLength, HandlerStub);
1185 class StoreFieldStub : public HandlerStub {
1187 StoreFieldStub(Isolate* isolate, FieldIndex index,
1188 Representation representation)
1189 : HandlerStub(isolate) {
1190 int property_index_key = index.GetFieldAccessStubKey();
1191 uint8_t repr = PropertyDetails::EncodeRepresentation(representation);
1192 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) |
1193 RepresentationBits::encode(repr));
1196 FieldIndex index() const {
1197 int property_index_key = StoreFieldByIndexBits::decode(sub_minor_key());
1198 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1201 Representation representation() {
1202 uint8_t repr = RepresentationBits::decode(sub_minor_key());
1203 return PropertyDetails::DecodeRepresentation(repr);
1207 Code::Kind kind() const override { return Code::STORE_IC; }
1208 Code::StubType GetStubType() const override { return Code::FAST; }
1211 class StoreFieldByIndexBits : public BitField<int, 0, 13> {};
1212 class RepresentationBits : public BitField<uint8_t, 13, 4> {};
1214 DEFINE_HANDLER_CODE_STUB(StoreField, HandlerStub);
1218 // Register and parameter access methods are specified here instead of in
1219 // the CallInterfaceDescriptor because the stub uses a different descriptor
1220 // if FLAG_vector_stores is on.
1221 class StoreTransitionHelper {
1223 static Register ReceiverRegister() {
1224 return StoreTransitionDescriptor::ReceiverRegister();
1227 static Register NameRegister() {
1228 return StoreTransitionDescriptor::NameRegister();
1231 static Register ValueRegister() {
1232 return StoreTransitionDescriptor::ValueRegister();
1235 static Register SlotRegister() {
1236 DCHECK(FLAG_vector_stores);
1237 return VectorStoreTransitionDescriptor::SlotRegister();
1240 static Register VectorRegister() {
1241 DCHECK(FLAG_vector_stores);
1242 return VectorStoreTransitionDescriptor::VectorRegister();
1245 static Register MapRegister() {
1246 return FLAG_vector_stores ? VectorStoreTransitionDescriptor::MapRegister()
1247 : StoreTransitionDescriptor::MapRegister();
1250 static int ReceiverIndex() {
1251 return StoreTransitionDescriptor::kReceiverIndex;
1254 static int NameIndex() { return StoreTransitionDescriptor::kReceiverIndex; }
1256 static int ValueIndex() { return StoreTransitionDescriptor::kValueIndex; }
1258 static int SlotIndex() {
1259 DCHECK(FLAG_vector_stores);
1260 return VectorStoreTransitionDescriptor::kSlotIndex;
1263 static int VectorIndex() {
1264 DCHECK(FLAG_vector_stores);
1265 return VectorStoreTransitionDescriptor::kVectorIndex;
1268 static int MapIndex() {
1269 if (FLAG_vector_stores) {
1270 return VectorStoreTransitionDescriptor::kMapIndex;
1272 return StoreTransitionDescriptor::kMapIndex;
1275 // Some platforms push Slot, Vector, Map on the stack instead of in
1277 static bool UsesStackArgs() { return MapRegister().is(no_reg); }
1281 class StoreTransitionStub : public HandlerStub {
1286 ExtendStorageAndStoreMapAndValue
1289 explicit StoreTransitionStub(Isolate* isolate) : HandlerStub(isolate) {
1290 set_sub_minor_key(StoreModeBits::encode(StoreMapOnly));
1293 StoreTransitionStub(Isolate* isolate, FieldIndex index,
1294 Representation representation, StoreMode store_mode)
1295 : HandlerStub(isolate) {
1296 DCHECK(store_mode != StoreMapOnly);
1297 int property_index_key = index.GetFieldAccessStubKey();
1298 uint8_t repr = PropertyDetails::EncodeRepresentation(representation);
1299 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) |
1300 RepresentationBits::encode(repr) |
1301 StoreModeBits::encode(store_mode));
1304 FieldIndex index() const {
1305 DCHECK(store_mode() != StoreMapOnly);
1306 int property_index_key = StoreFieldByIndexBits::decode(sub_minor_key());
1307 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1310 Representation representation() {
1311 DCHECK(store_mode() != StoreMapOnly);
1312 uint8_t repr = RepresentationBits::decode(sub_minor_key());
1313 return PropertyDetails::DecodeRepresentation(repr);
1316 StoreMode store_mode() const {
1317 return StoreModeBits::decode(sub_minor_key());
1320 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override;
1323 Code::Kind kind() const override { return Code::STORE_IC; }
1324 Code::StubType GetStubType() const override { return Code::FAST; }
1327 class StoreFieldByIndexBits : public BitField<int, 0, 13> {};
1328 class RepresentationBits : public BitField<uint8_t, 13, 4> {};
1329 class StoreModeBits : public BitField<StoreMode, 17, 2> {};
1331 DEFINE_HANDLER_CODE_STUB(StoreTransition, HandlerStub);
1335 class StoreGlobalStub : public HandlerStub {
1337 StoreGlobalStub(Isolate* isolate, PropertyCellType type,
1338 Maybe<PropertyCellConstantType> constant_type,
1340 : HandlerStub(isolate) {
1341 PropertyCellConstantType encoded_constant_type =
1342 constant_type.FromMaybe(PropertyCellConstantType::kSmi);
1343 set_sub_minor_key(CellTypeBits::encode(type) |
1344 ConstantTypeBits::encode(encoded_constant_type) |
1345 CheckGlobalBits::encode(check_global));
1348 static Handle<HeapObject> property_cell_placeholder(Isolate* isolate) {
1349 return isolate->factory()->uninitialized_value();
1352 static Handle<HeapObject> global_map_placeholder(Isolate* isolate) {
1353 return isolate->factory()->termination_exception();
1356 Handle<Code> GetCodeCopyFromTemplate(Handle<GlobalObject> global,
1357 Handle<PropertyCell> cell) {
1358 Code::FindAndReplacePattern pattern;
1359 if (check_global()) {
1360 pattern.Add(handle(global_map_placeholder(isolate())->map()),
1361 Map::WeakCellForMap(Handle<Map>(global->map())));
1363 pattern.Add(handle(property_cell_placeholder(isolate())->map()),
1364 isolate()->factory()->NewWeakCell(cell));
1365 return CodeStub::GetCodeCopy(pattern);
1368 Code::Kind kind() const override { return Code::STORE_IC; }
1370 PropertyCellType cell_type() const {
1371 return CellTypeBits::decode(sub_minor_key());
1374 PropertyCellConstantType constant_type() const {
1375 DCHECK(PropertyCellType::kConstantType == cell_type());
1376 return ConstantTypeBits::decode(sub_minor_key());
1379 bool check_global() const { return CheckGlobalBits::decode(sub_minor_key()); }
1381 Representation representation() {
1382 return Representation::FromKind(
1383 RepresentationBits::decode(sub_minor_key()));
1386 void set_representation(Representation r) {
1387 set_sub_minor_key(RepresentationBits::update(sub_minor_key(), r.kind()));
1391 class CellTypeBits : public BitField<PropertyCellType, 0, 2> {};
1392 class ConstantTypeBits : public BitField<PropertyCellConstantType, 2, 2> {};
1393 class RepresentationBits : public BitField<Representation::Kind, 4, 8> {};
1394 class CheckGlobalBits : public BitField<bool, 12, 1> {};
1396 DEFINE_HANDLER_CODE_STUB(StoreGlobal, HandlerStub);
1400 class LoadGlobalViaContextStub final : public PlatformCodeStub {
1402 static const int kMaximumDepth = 15;
1404 LoadGlobalViaContextStub(Isolate* isolate, int depth)
1405 : PlatformCodeStub(isolate) {
1406 minor_key_ = DepthBits::encode(depth);
1409 int depth() const { return DepthBits::decode(minor_key_); }
1412 class DepthBits : public BitField<int, 0, 4> {};
1413 STATIC_ASSERT(DepthBits::kMax == kMaximumDepth);
1415 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadGlobalViaContext);
1416 DEFINE_PLATFORM_CODE_STUB(LoadGlobalViaContext, PlatformCodeStub);
1420 class StoreGlobalViaContextStub final : public PlatformCodeStub {
1422 static const int kMaximumDepth = 15;
1424 StoreGlobalViaContextStub(Isolate* isolate, int depth,
1425 LanguageMode language_mode)
1426 : PlatformCodeStub(isolate) {
1428 DepthBits::encode(depth) | LanguageModeBits::encode(language_mode);
1431 int depth() const { return DepthBits::decode(minor_key_); }
1432 LanguageMode language_mode() const {
1433 return LanguageModeBits::decode(minor_key_);
1437 class DepthBits : public BitField<int, 0, 4> {};
1438 STATIC_ASSERT(DepthBits::kMax == kMaximumDepth);
1439 class LanguageModeBits : public BitField<LanguageMode, 4, 2> {};
1440 STATIC_ASSERT(LANGUAGE_END == 3);
1442 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreGlobalViaContext);
1443 DEFINE_PLATFORM_CODE_STUB(StoreGlobalViaContext, PlatformCodeStub);
1447 class CallApiFunctionStub : public PlatformCodeStub {
1449 explicit CallApiFunctionStub(Isolate* isolate, bool call_data_undefined)
1450 : PlatformCodeStub(isolate) {
1451 minor_key_ = CallDataUndefinedBits::encode(call_data_undefined);
1455 bool call_data_undefined() const {
1456 return CallDataUndefinedBits::decode(minor_key_);
1459 class CallDataUndefinedBits : public BitField<bool, 0, 1> {};
1461 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiFunction);
1462 DEFINE_PLATFORM_CODE_STUB(CallApiFunction, PlatformCodeStub);
1466 class CallApiAccessorStub : public PlatformCodeStub {
1468 CallApiAccessorStub(Isolate* isolate, bool is_store, bool call_data_undefined)
1469 : PlatformCodeStub(isolate) {
1470 minor_key_ = IsStoreBits::encode(is_store) |
1471 CallDataUndefinedBits::encode(call_data_undefined) |
1472 ArgumentBits::encode(is_store ? 1 : 0);
1476 // For CallApiFunctionWithFixedArgsStub, see below.
1477 static const int kArgBits = 3;
1478 CallApiAccessorStub(Isolate* isolate, int argc, bool call_data_undefined)
1479 : PlatformCodeStub(isolate) {
1480 minor_key_ = IsStoreBits::encode(false) |
1481 CallDataUndefinedBits::encode(call_data_undefined) |
1482 ArgumentBits::encode(argc);
1486 bool is_store() const { return IsStoreBits::decode(minor_key_); }
1487 bool call_data_undefined() const {
1488 return CallDataUndefinedBits::decode(minor_key_);
1490 int argc() const { return ArgumentBits::decode(minor_key_); }
1492 class IsStoreBits: public BitField<bool, 0, 1> {};
1493 class CallDataUndefinedBits: public BitField<bool, 1, 1> {};
1494 class ArgumentBits : public BitField<int, 2, kArgBits> {};
1496 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiAccessor);
1497 DEFINE_PLATFORM_CODE_STUB(CallApiAccessor, PlatformCodeStub);
1501 // TODO(dcarney): see if it's possible to remove this later without performance
1503 // This is not a real stub, but a way of generating the CallApiAccessorStub
1504 // (which has the same abi) which makes it clear that it is not an accessor.
1505 class CallApiFunctionWithFixedArgsStub : public CallApiAccessorStub {
1507 static const int kMaxFixedArgs = (1 << kArgBits) - 1;
1508 CallApiFunctionWithFixedArgsStub(Isolate* isolate, int argc,
1509 bool call_data_undefined)
1510 : CallApiAccessorStub(isolate, argc, call_data_undefined) {
1511 DCHECK(0 <= argc && argc <= kMaxFixedArgs);
1516 typedef ApiAccessorDescriptor ApiFunctionWithFixedArgsDescriptor;
1519 class CallApiGetterStub : public PlatformCodeStub {
1521 explicit CallApiGetterStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
1523 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiGetter);
1524 DEFINE_PLATFORM_CODE_STUB(CallApiGetter, PlatformCodeStub);
1528 class BinaryOpICStub : public HydrogenCodeStub {
1530 BinaryOpICStub(Isolate* isolate, Token::Value op, Strength strength)
1531 : HydrogenCodeStub(isolate, UNINITIALIZED) {
1532 BinaryOpICState state(isolate, op, strength);
1533 set_sub_minor_key(state.GetExtraICState());
1536 BinaryOpICStub(Isolate* isolate, const BinaryOpICState& state)
1537 : HydrogenCodeStub(isolate) {
1538 set_sub_minor_key(state.GetExtraICState());
1541 static void GenerateAheadOfTime(Isolate* isolate);
1543 Code::Kind GetCodeKind() const override { return Code::BINARY_OP_IC; }
1545 InlineCacheState GetICState() const final { return state().GetICState(); }
1547 ExtraICState GetExtraICState() const final {
1548 return static_cast<ExtraICState>(sub_minor_key());
1551 BinaryOpICState state() const {
1552 return BinaryOpICState(isolate(), GetExtraICState());
1555 void PrintState(std::ostream& os) const final; // NOLINT
1557 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1558 static const int kLeft = 0;
1559 static const int kRight = 1;
1562 static void GenerateAheadOfTime(Isolate* isolate,
1563 const BinaryOpICState& state);
1565 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1566 DEFINE_HYDROGEN_CODE_STUB(BinaryOpIC, HydrogenCodeStub);
1570 // TODO(bmeurer): Merge this into the BinaryOpICStub once we have proper tail
1571 // call support for stubs in Hydrogen.
1572 class BinaryOpICWithAllocationSiteStub final : public PlatformCodeStub {
1574 BinaryOpICWithAllocationSiteStub(Isolate* isolate,
1575 const BinaryOpICState& state)
1576 : PlatformCodeStub(isolate) {
1577 minor_key_ = state.GetExtraICState();
1580 static void GenerateAheadOfTime(Isolate* isolate);
1582 Handle<Code> GetCodeCopyFromTemplate(Handle<AllocationSite> allocation_site) {
1583 Code::FindAndReplacePattern pattern;
1584 pattern.Add(isolate()->factory()->undefined_map(), allocation_site);
1585 return CodeStub::GetCodeCopy(pattern);
1588 Code::Kind GetCodeKind() const override { return Code::BINARY_OP_IC; }
1590 InlineCacheState GetICState() const override { return state().GetICState(); }
1592 ExtraICState GetExtraICState() const override {
1593 return static_cast<ExtraICState>(minor_key_);
1596 void PrintState(std::ostream& os) const override; // NOLINT
1599 BinaryOpICState state() const {
1600 return BinaryOpICState(isolate(), static_cast<ExtraICState>(minor_key_));
1603 static void GenerateAheadOfTime(Isolate* isolate,
1604 const BinaryOpICState& state);
1606 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1607 DEFINE_PLATFORM_CODE_STUB(BinaryOpICWithAllocationSite, PlatformCodeStub);
1611 class BinaryOpWithAllocationSiteStub final : public BinaryOpICStub {
1613 BinaryOpWithAllocationSiteStub(Isolate* isolate, Token::Value op,
1615 : BinaryOpICStub(isolate, op, strength) {}
1617 BinaryOpWithAllocationSiteStub(Isolate* isolate, const BinaryOpICState& state)
1618 : BinaryOpICStub(isolate, state) {}
1620 Code::Kind GetCodeKind() const final { return Code::STUB; }
1622 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1623 static const int kAllocationSite = 0;
1624 static const int kLeft = 1;
1625 static const int kRight = 2;
1627 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1628 DEFINE_HYDROGEN_CODE_STUB(BinaryOpWithAllocationSite, BinaryOpICStub);
1632 class StringAddStub final : public HydrogenCodeStub {
1634 StringAddStub(Isolate* isolate, StringAddFlags flags,
1635 PretenureFlag pretenure_flag)
1636 : HydrogenCodeStub(isolate) {
1637 set_sub_minor_key(StringAddFlagsBits::encode(flags) |
1638 PretenureFlagBits::encode(pretenure_flag));
1641 StringAddFlags flags() const {
1642 return StringAddFlagsBits::decode(sub_minor_key());
1645 PretenureFlag pretenure_flag() const {
1646 return PretenureFlagBits::decode(sub_minor_key());
1649 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1650 static const int kLeft = 0;
1651 static const int kRight = 1;
1654 class StringAddFlagsBits : public BitField<StringAddFlags, 0, 3> {};
1655 class PretenureFlagBits : public BitField<PretenureFlag, 3, 1> {};
1657 void PrintBaseName(std::ostream& os) const override; // NOLINT
1659 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
1660 DEFINE_HYDROGEN_CODE_STUB(StringAdd, HydrogenCodeStub);
1664 class CompareICStub : public PlatformCodeStub {
1666 CompareICStub(Isolate* isolate, Token::Value op, Strength strength,
1667 CompareICState::State left, CompareICState::State right,
1668 CompareICState::State state)
1669 : PlatformCodeStub(isolate) {
1670 DCHECK(Token::IsCompareOp(op));
1671 minor_key_ = OpBits::encode(op - Token::EQ) |
1672 StrengthBits::encode(is_strong(strength)) |
1673 LeftStateBits::encode(left) | RightStateBits::encode(right) |
1674 StateBits::encode(state);
1677 void set_known_map(Handle<Map> map) { known_map_ = map; }
1679 InlineCacheState GetICState() const override;
1681 Token::Value op() const {
1682 return static_cast<Token::Value>(Token::EQ + OpBits::decode(minor_key_));
1685 Strength strength() const {
1686 return StrengthBits::decode(minor_key_) ? Strength::STRONG : Strength::WEAK;
1689 CompareICState::State left() const {
1690 return LeftStateBits::decode(minor_key_);
1692 CompareICState::State right() const {
1693 return RightStateBits::decode(minor_key_);
1695 CompareICState::State state() const { return StateBits::decode(minor_key_); }
1698 Code::Kind GetCodeKind() const override { return Code::COMPARE_IC; }
1700 void GenerateBooleans(MacroAssembler* masm);
1701 void GenerateSmis(MacroAssembler* masm);
1702 void GenerateNumbers(MacroAssembler* masm);
1703 void GenerateInternalizedStrings(MacroAssembler* masm);
1704 void GenerateStrings(MacroAssembler* masm);
1705 void GenerateUniqueNames(MacroAssembler* masm);
1706 void GenerateObjects(MacroAssembler* masm);
1707 void GenerateMiss(MacroAssembler* masm);
1708 void GenerateKnownObjects(MacroAssembler* masm);
1709 void GenerateGeneric(MacroAssembler* masm);
1711 bool strict() const { return op() == Token::EQ_STRICT; }
1712 Condition GetCondition() const;
1714 void AddToSpecialCache(Handle<Code> new_object) override;
1715 bool FindCodeInSpecialCache(Code** code_out) override;
1716 bool UseSpecialCache() override {
1717 return state() == CompareICState::KNOWN_OBJECT;
1720 class OpBits : public BitField<int, 0, 3> {};
1721 class StrengthBits : public BitField<bool, 3, 1> {};
1722 class LeftStateBits : public BitField<CompareICState::State, 4, 4> {};
1723 class RightStateBits : public BitField<CompareICState::State, 8, 4> {};
1724 class StateBits : public BitField<CompareICState::State, 12, 4> {};
1726 Handle<Map> known_map_;
1728 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1729 DEFINE_PLATFORM_CODE_STUB(CompareIC, PlatformCodeStub);
1733 class CompareNilICStub : public HydrogenCodeStub {
1735 Type* GetType(Zone* zone, Handle<Map> map = Handle<Map>());
1736 Type* GetInputType(Zone* zone, Handle<Map> map);
1738 CompareNilICStub(Isolate* isolate, NilValue nil) : HydrogenCodeStub(isolate) {
1739 set_sub_minor_key(NilValueBits::encode(nil));
1742 CompareNilICStub(Isolate* isolate, ExtraICState ic_state,
1743 InitializationState init_state = INITIALIZED)
1744 : HydrogenCodeStub(isolate, init_state) {
1745 set_sub_minor_key(ic_state);
1748 static Handle<Code> GetUninitialized(Isolate* isolate,
1750 return CompareNilICStub(isolate, nil, UNINITIALIZED).GetCode();
1753 InlineCacheState GetICState() const override {
1754 State state = this->state();
1755 if (state.Contains(GENERIC)) {
1757 } else if (state.Contains(MONOMORPHIC_MAP)) {
1760 return PREMONOMORPHIC;
1764 Code::Kind GetCodeKind() const override { return Code::COMPARE_NIL_IC; }
1766 ExtraICState GetExtraICState() const override { return sub_minor_key(); }
1768 void UpdateStatus(Handle<Object> object);
1770 bool IsMonomorphic() const { return state().Contains(MONOMORPHIC_MAP); }
1772 NilValue nil_value() const { return NilValueBits::decode(sub_minor_key()); }
1775 set_sub_minor_key(TypesBits::update(sub_minor_key(), 0));
1778 void PrintState(std::ostream& os) const override; // NOLINT
1779 void PrintBaseName(std::ostream& os) const override; // NOLINT
1782 CompareNilICStub(Isolate* isolate, NilValue nil,
1783 InitializationState init_state)
1784 : HydrogenCodeStub(isolate, init_state) {
1785 set_sub_minor_key(NilValueBits::encode(nil));
1788 enum CompareNilType {
1796 // At most 6 different types can be distinguished, because the Code object
1797 // only has room for a single byte to hold a set and there are two more
1798 // boolean flags we need to store. :-P
1799 STATIC_ASSERT(NUMBER_OF_TYPES <= 6);
1801 class State : public EnumSet<CompareNilType, byte> {
1803 State() : EnumSet<CompareNilType, byte>(0) { }
1804 explicit State(byte bits) : EnumSet<CompareNilType, byte>(bits) { }
1806 friend std::ostream& operator<<(std::ostream& os, const State& s);
1808 State state() const { return State(TypesBits::decode(sub_minor_key())); }
1810 class NilValueBits : public BitField<NilValue, 0, 1> {};
1811 class TypesBits : public BitField<byte, 1, NUMBER_OF_TYPES> {};
1813 friend class CompareNilIC;
1815 DEFINE_CALL_INTERFACE_DESCRIPTOR(CompareNil);
1816 DEFINE_HYDROGEN_CODE_STUB(CompareNilIC, HydrogenCodeStub);
1820 std::ostream& operator<<(std::ostream& os, const CompareNilICStub::State& s);
1823 class CEntryStub : public PlatformCodeStub {
1825 CEntryStub(Isolate* isolate, int result_size,
1826 SaveFPRegsMode save_doubles = kDontSaveFPRegs)
1827 : PlatformCodeStub(isolate) {
1828 minor_key_ = SaveDoublesBits::encode(save_doubles == kSaveFPRegs);
1829 DCHECK(result_size == 1 || result_size == 2);
1830 #if _WIN64 || V8_TARGET_ARCH_PPC
1831 minor_key_ = ResultSizeBits::update(minor_key_, result_size);
1835 // The version of this stub that doesn't save doubles is generated ahead of
1836 // time, so it's OK to call it from other stubs that can't cope with GC during
1837 // their code generation. On machines that always have gp registers (x64) we
1838 // can generate both variants ahead of time.
1839 static void GenerateAheadOfTime(Isolate* isolate);
1842 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
1843 #if _WIN64 || V8_TARGET_ARCH_PPC
1844 int result_size() const { return ResultSizeBits::decode(minor_key_); }
1847 bool NeedsImmovableCode() override;
1849 class SaveDoublesBits : public BitField<bool, 0, 1> {};
1850 class ResultSizeBits : public BitField<int, 1, 3> {};
1852 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1853 DEFINE_PLATFORM_CODE_STUB(CEntry, PlatformCodeStub);
1857 class JSEntryStub : public PlatformCodeStub {
1859 JSEntryStub(Isolate* isolate, StackFrame::Type type)
1860 : PlatformCodeStub(isolate) {
1861 DCHECK(type == StackFrame::ENTRY || type == StackFrame::ENTRY_CONSTRUCT);
1862 minor_key_ = StackFrameTypeBits::encode(type);
1866 void FinishCode(Handle<Code> code) override;
1868 void PrintName(std::ostream& os) const override { // NOLINT
1869 os << (type() == StackFrame::ENTRY ? "JSEntryStub"
1870 : "JSConstructEntryStub");
1873 StackFrame::Type type() const {
1874 return StackFrameTypeBits::decode(minor_key_);
1877 class StackFrameTypeBits : public BitField<StackFrame::Type, 0, 5> {};
1879 int handler_offset_;
1881 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1882 DEFINE_PLATFORM_CODE_STUB(JSEntry, PlatformCodeStub);
1886 class ArgumentsAccessStub: public PlatformCodeStub {
1895 ArgumentsAccessStub(Isolate* isolate, Type type) : PlatformCodeStub(isolate) {
1896 minor_key_ = TypeBits::encode(type);
1899 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1900 if (type() == READ_ELEMENT) {
1901 return ArgumentsAccessReadDescriptor(isolate());
1903 return ArgumentsAccessNewDescriptor(isolate());
1907 static Type ComputeType(bool is_unmapped, bool has_duplicate_parameters) {
1909 return Type::NEW_STRICT;
1910 } else if (has_duplicate_parameters) {
1911 return Type::NEW_SLOPPY_SLOW;
1913 return Type::NEW_SLOPPY_FAST;
1918 Type type() const { return TypeBits::decode(minor_key_); }
1920 void GenerateReadElement(MacroAssembler* masm);
1921 void GenerateNewStrict(MacroAssembler* masm);
1922 void GenerateNewSloppyFast(MacroAssembler* masm);
1923 void GenerateNewSloppySlow(MacroAssembler* masm);
1925 void PrintName(std::ostream& os) const override; // NOLINT
1927 class TypeBits : public BitField<Type, 0, 2> {};
1929 DEFINE_PLATFORM_CODE_STUB(ArgumentsAccess, PlatformCodeStub);
1933 class RegExpExecStub: public PlatformCodeStub {
1935 explicit RegExpExecStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
1937 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
1938 DEFINE_PLATFORM_CODE_STUB(RegExpExec, PlatformCodeStub);
1942 class RegExpConstructResultStub final : public HydrogenCodeStub {
1944 explicit RegExpConstructResultStub(Isolate* isolate)
1945 : HydrogenCodeStub(isolate) { }
1947 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1948 static const int kLength = 0;
1949 static const int kIndex = 1;
1950 static const int kInput = 2;
1952 DEFINE_CALL_INTERFACE_DESCRIPTOR(RegExpConstructResult);
1953 DEFINE_HYDROGEN_CODE_STUB(RegExpConstructResult, HydrogenCodeStub);
1957 // TODO(bmeurer): Deprecate the CallFunctionStub in favor of the more general
1958 // Invoke family of builtins.
1959 class CallFunctionStub: public PlatformCodeStub {
1961 CallFunctionStub(Isolate* isolate, int argc, CallFunctionFlags flags)
1962 : PlatformCodeStub(isolate) {
1963 DCHECK(argc >= 0 && argc <= Code::kMaxArguments);
1964 minor_key_ = ArgcBits::encode(argc) | FlagBits::encode(flags);
1968 int argc() const { return ArgcBits::decode(minor_key_); }
1969 int flags() const { return FlagBits::decode(minor_key_); }
1971 bool CallAsMethod() const {
1972 return flags() == CALL_AS_METHOD || flags() == WRAP_AND_CALL;
1975 bool NeedsChecks() const { return flags() != WRAP_AND_CALL; }
1977 void PrintName(std::ostream& os) const override; // NOLINT
1979 // Minor key encoding in 32 bits with Bitfield <Type, shift, size>.
1980 class FlagBits : public BitField<CallFunctionFlags, 0, 2> {};
1981 class ArgcBits : public BitField<unsigned, 2, Code::kArgumentsBits> {};
1982 STATIC_ASSERT(Code::kArgumentsBits + 2 <= kStubMinorKeyBits);
1984 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction);
1985 DEFINE_PLATFORM_CODE_STUB(CallFunction, PlatformCodeStub);
1989 class CallConstructStub: public PlatformCodeStub {
1991 CallConstructStub(Isolate* isolate, CallConstructorFlags flags)
1992 : PlatformCodeStub(isolate) {
1993 minor_key_ = FlagBits::encode(flags);
1996 void FinishCode(Handle<Code> code) override {
1997 code->set_has_function_cache(RecordCallTarget());
2001 CallConstructorFlags flags() const { return FlagBits::decode(minor_key_); }
2003 bool RecordCallTarget() const {
2004 return (flags() & RECORD_CONSTRUCTOR_TARGET) != 0;
2007 bool IsSuperConstructorCall() const {
2008 return (flags() & SUPER_CONSTRUCTOR_CALL) != 0;
2011 void PrintName(std::ostream& os) const override; // NOLINT
2013 class FlagBits : public BitField<CallConstructorFlags, 0, 2> {};
2015 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallConstruct);
2016 DEFINE_PLATFORM_CODE_STUB(CallConstruct, PlatformCodeStub);
2020 enum StringIndexFlags {
2021 // Accepts smis or heap numbers.
2022 STRING_INDEX_IS_NUMBER,
2024 // Accepts smis or heap numbers that are valid array indices
2025 // (ECMA-262 15.4). Invalid indices are reported as being out of
2027 STRING_INDEX_IS_ARRAY_INDEX
2031 enum ReceiverCheckMode {
2032 // We don't know anything about the receiver.
2033 RECEIVER_IS_UNKNOWN,
2035 // We know the receiver is a string.
2041 // The code being generated is part of an IC handler, which may MISS
2042 // to an IC in failure cases.
2045 NOT_PART_OF_IC_HANDLER
2049 // Generates code implementing String.prototype.charCodeAt.
2051 // Only supports the case when the receiver is a string and the index
2052 // is a number (smi or heap number) that is a valid index into the
2053 // string. Additional index constraints are specified by the
2054 // flags. Otherwise, bails out to the provided labels.
2056 // Register usage: |object| may be changed to another string in a way
2057 // that doesn't affect charCodeAt/charAt semantics, |index| is
2058 // preserved, |scratch| and |result| are clobbered.
2059 class StringCharCodeAtGenerator {
2061 StringCharCodeAtGenerator(Register object, Register index, Register result,
2062 Label* receiver_not_string, Label* index_not_number,
2063 Label* index_out_of_range,
2064 StringIndexFlags index_flags,
2065 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
2069 receiver_not_string_(receiver_not_string),
2070 index_not_number_(index_not_number),
2071 index_out_of_range_(index_out_of_range),
2072 index_flags_(index_flags),
2073 check_mode_(check_mode) {
2074 DCHECK(!result_.is(object_));
2075 DCHECK(!result_.is(index_));
2078 // Generates the fast case code. On the fallthrough path |result|
2079 // register contains the result.
2080 void GenerateFast(MacroAssembler* masm);
2082 // Generates the slow case code. Must not be naturally
2083 // reachable. Expected to be put after a ret instruction (e.g., in
2084 // deferred code). Always jumps back to the fast case.
2085 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
2086 const RuntimeCallHelper& call_helper);
2088 // Skip handling slow case and directly jump to bailout.
2089 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2090 masm->bind(&index_not_smi_);
2091 masm->bind(&call_runtime_);
2100 Label* receiver_not_string_;
2101 Label* index_not_number_;
2102 Label* index_out_of_range_;
2104 StringIndexFlags index_flags_;
2105 ReceiverCheckMode check_mode_;
2107 Label call_runtime_;
2108 Label index_not_smi_;
2109 Label got_smi_index_;
2112 DISALLOW_COPY_AND_ASSIGN(StringCharCodeAtGenerator);
2116 // Generates code for creating a one-char string from a char code.
2117 class StringCharFromCodeGenerator {
2119 StringCharFromCodeGenerator(Register code,
2123 DCHECK(!code_.is(result_));
2126 // Generates the fast case code. On the fallthrough path |result|
2127 // register contains the result.
2128 void GenerateFast(MacroAssembler* masm);
2130 // Generates the slow case code. Must not be naturally
2131 // reachable. Expected to be put after a ret instruction (e.g., in
2132 // deferred code). Always jumps back to the fast case.
2133 void GenerateSlow(MacroAssembler* masm,
2134 const RuntimeCallHelper& call_helper);
2136 // Skip handling slow case and directly jump to bailout.
2137 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2138 masm->bind(&slow_case_);
2149 DISALLOW_COPY_AND_ASSIGN(StringCharFromCodeGenerator);
2153 // Generates code implementing String.prototype.charAt.
2155 // Only supports the case when the receiver is a string and the index
2156 // is a number (smi or heap number) that is a valid index into the
2157 // string. Additional index constraints are specified by the
2158 // flags. Otherwise, bails out to the provided labels.
2160 // Register usage: |object| may be changed to another string in a way
2161 // that doesn't affect charCodeAt/charAt semantics, |index| is
2162 // preserved, |scratch1|, |scratch2|, and |result| are clobbered.
2163 class StringCharAtGenerator {
2165 StringCharAtGenerator(Register object, Register index, Register scratch,
2166 Register result, Label* receiver_not_string,
2167 Label* index_not_number, Label* index_out_of_range,
2168 StringIndexFlags index_flags,
2169 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
2170 : char_code_at_generator_(object, index, scratch, receiver_not_string,
2171 index_not_number, index_out_of_range,
2172 index_flags, check_mode),
2173 char_from_code_generator_(scratch, result) {}
2175 // Generates the fast case code. On the fallthrough path |result|
2176 // register contains the result.
2177 void GenerateFast(MacroAssembler* masm) {
2178 char_code_at_generator_.GenerateFast(masm);
2179 char_from_code_generator_.GenerateFast(masm);
2182 // Generates the slow case code. Must not be naturally
2183 // reachable. Expected to be put after a ret instruction (e.g., in
2184 // deferred code). Always jumps back to the fast case.
2185 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
2186 const RuntimeCallHelper& call_helper) {
2187 char_code_at_generator_.GenerateSlow(masm, embed_mode, call_helper);
2188 char_from_code_generator_.GenerateSlow(masm, call_helper);
2191 // Skip handling slow case and directly jump to bailout.
2192 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2193 char_code_at_generator_.SkipSlow(masm, bailout);
2194 char_from_code_generator_.SkipSlow(masm, bailout);
2198 StringCharCodeAtGenerator char_code_at_generator_;
2199 StringCharFromCodeGenerator char_from_code_generator_;
2201 DISALLOW_COPY_AND_ASSIGN(StringCharAtGenerator);
2205 class LoadDictionaryElementStub : public HydrogenCodeStub {
2207 explicit LoadDictionaryElementStub(Isolate* isolate, const LoadICState& state)
2208 : HydrogenCodeStub(isolate) {
2209 minor_key_ = state.GetExtraICState();
2212 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
2213 return LoadWithVectorDescriptor(isolate());
2216 LanguageMode language_mode() const {
2217 return LoadICState::GetLanguageMode(MinorKey());
2220 DEFINE_HYDROGEN_CODE_STUB(LoadDictionaryElement, HydrogenCodeStub);
2224 class KeyedLoadGenericStub : public HydrogenCodeStub {
2226 explicit KeyedLoadGenericStub(Isolate* isolate, const LoadICState& state)
2227 : HydrogenCodeStub(isolate) {
2228 minor_key_ = state.GetExtraICState();
2231 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2232 InlineCacheState GetICState() const override { return GENERIC; }
2234 LanguageMode language_mode() const {
2235 return LoadICState::GetLanguageMode(MinorKey());
2238 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2240 DEFINE_HYDROGEN_CODE_STUB(KeyedLoadGeneric, HydrogenCodeStub);
2244 class LoadICTrampolineStub : public PlatformCodeStub {
2246 LoadICTrampolineStub(Isolate* isolate, const LoadICState& state)
2247 : PlatformCodeStub(isolate) {
2248 minor_key_ = state.GetExtraICState();
2251 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2253 InlineCacheState GetICState() const final { return DEFAULT; }
2255 ExtraICState GetExtraICState() const final {
2256 return static_cast<ExtraICState>(minor_key_);
2260 LoadICState state() const {
2261 return LoadICState(static_cast<ExtraICState>(minor_key_));
2264 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2265 DEFINE_PLATFORM_CODE_STUB(LoadICTrampoline, PlatformCodeStub);
2269 class KeyedLoadICTrampolineStub : public LoadICTrampolineStub {
2271 explicit KeyedLoadICTrampolineStub(Isolate* isolate, const LoadICState& state)
2272 : LoadICTrampolineStub(isolate, state) {}
2274 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2276 DEFINE_PLATFORM_CODE_STUB(KeyedLoadICTrampoline, LoadICTrampolineStub);
2280 class VectorStoreICTrampolineStub : public PlatformCodeStub {
2282 VectorStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2283 : PlatformCodeStub(isolate) {
2284 minor_key_ = state.GetExtraICState();
2287 Code::Kind GetCodeKind() const override { return Code::STORE_IC; }
2289 InlineCacheState GetICState() const final { return DEFAULT; }
2291 ExtraICState GetExtraICState() const final {
2292 return static_cast<ExtraICState>(minor_key_);
2296 StoreICState state() const {
2297 return StoreICState(static_cast<ExtraICState>(minor_key_));
2301 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreICTrampoline);
2302 DEFINE_PLATFORM_CODE_STUB(VectorStoreICTrampoline, PlatformCodeStub);
2306 class VectorKeyedStoreICTrampolineStub : public VectorStoreICTrampolineStub {
2308 VectorKeyedStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2309 : VectorStoreICTrampolineStub(isolate, state) {}
2311 Code::Kind GetCodeKind() const override { return Code::KEYED_STORE_IC; }
2313 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreICTrampoline,
2314 VectorStoreICTrampolineStub);
2318 class CallICTrampolineStub : public PlatformCodeStub {
2320 CallICTrampolineStub(Isolate* isolate, const CallICState& state)
2321 : PlatformCodeStub(isolate) {
2322 minor_key_ = state.GetExtraICState();
2325 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
2327 InlineCacheState GetICState() const final { return DEFAULT; }
2329 ExtraICState GetExtraICState() const final {
2330 return static_cast<ExtraICState>(minor_key_);
2334 CallICState state() const {
2335 return CallICState(static_cast<ExtraICState>(minor_key_));
2338 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedback);
2339 DEFINE_PLATFORM_CODE_STUB(CallICTrampoline, PlatformCodeStub);
2343 class LoadICStub : public PlatformCodeStub {
2345 explicit LoadICStub(Isolate* isolate, const LoadICState& state)
2346 : PlatformCodeStub(isolate) {
2347 minor_key_ = state.GetExtraICState();
2350 void GenerateForTrampoline(MacroAssembler* masm);
2352 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2353 InlineCacheState GetICState() const final { return DEFAULT; }
2354 ExtraICState GetExtraICState() const final {
2355 return static_cast<ExtraICState>(minor_key_);
2358 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2359 DEFINE_PLATFORM_CODE_STUB(LoadIC, PlatformCodeStub);
2362 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2366 class KeyedLoadICStub : public PlatformCodeStub {
2368 explicit KeyedLoadICStub(Isolate* isolate, const LoadICState& state)
2369 : PlatformCodeStub(isolate) {
2370 minor_key_ = state.GetExtraICState();
2373 void GenerateForTrampoline(MacroAssembler* masm);
2375 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2376 InlineCacheState GetICState() const final { return DEFAULT; }
2377 ExtraICState GetExtraICState() const final {
2378 return static_cast<ExtraICState>(minor_key_);
2381 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2382 DEFINE_PLATFORM_CODE_STUB(KeyedLoadIC, PlatformCodeStub);
2385 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2389 class VectorStoreICStub : public PlatformCodeStub {
2391 VectorStoreICStub(Isolate* isolate, const StoreICState& state)
2392 : PlatformCodeStub(isolate) {
2393 minor_key_ = state.GetExtraICState();
2396 void GenerateForTrampoline(MacroAssembler* masm);
2398 Code::Kind GetCodeKind() const final { return Code::STORE_IC; }
2399 InlineCacheState GetICState() const final { return DEFAULT; }
2400 ExtraICState GetExtraICState() const final {
2401 return static_cast<ExtraICState>(minor_key_);
2404 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2405 DEFINE_PLATFORM_CODE_STUB(VectorStoreIC, PlatformCodeStub);
2408 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2412 class VectorKeyedStoreICStub : public PlatformCodeStub {
2414 VectorKeyedStoreICStub(Isolate* isolate, const StoreICState& state)
2415 : PlatformCodeStub(isolate) {
2416 minor_key_ = state.GetExtraICState();
2419 void GenerateForTrampoline(MacroAssembler* masm);
2421 Code::Kind GetCodeKind() const final { return Code::KEYED_STORE_IC; }
2422 InlineCacheState GetICState() const final { return DEFAULT; }
2423 virtual ExtraICState GetExtraICState() const final {
2424 return static_cast<ExtraICState>(minor_key_);
2427 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2428 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreIC, PlatformCodeStub);
2431 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2435 class DoubleToIStub : public PlatformCodeStub {
2437 DoubleToIStub(Isolate* isolate, Register source, Register destination,
2438 int offset, bool is_truncating, bool skip_fastpath = false)
2439 : PlatformCodeStub(isolate) {
2440 minor_key_ = SourceRegisterBits::encode(source.code()) |
2441 DestinationRegisterBits::encode(destination.code()) |
2442 OffsetBits::encode(offset) |
2443 IsTruncatingBits::encode(is_truncating) |
2444 SkipFastPathBits::encode(skip_fastpath) |
2445 SSE3Bits::encode(CpuFeatures::IsSupported(SSE3) ? 1 : 0);
2448 bool SometimesSetsUpAFrame() override { return false; }
2451 Register source() const {
2452 return Register::from_code(SourceRegisterBits::decode(minor_key_));
2454 Register destination() const {
2455 return Register::from_code(DestinationRegisterBits::decode(minor_key_));
2457 bool is_truncating() const { return IsTruncatingBits::decode(minor_key_); }
2458 bool skip_fastpath() const { return SkipFastPathBits::decode(minor_key_); }
2459 int offset() const { return OffsetBits::decode(minor_key_); }
2461 static const int kBitsPerRegisterNumber = 6;
2462 STATIC_ASSERT((1L << kBitsPerRegisterNumber) >= Register::kNumRegisters);
2463 class SourceRegisterBits:
2464 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT
2465 class DestinationRegisterBits:
2466 public BitField<int, kBitsPerRegisterNumber,
2467 kBitsPerRegisterNumber> {}; // NOLINT
2468 class IsTruncatingBits:
2469 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT
2471 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT
2472 class SkipFastPathBits:
2473 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT
2475 public BitField<int, 2 * kBitsPerRegisterNumber + 5, 1> {}; // NOLINT
2477 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2478 DEFINE_PLATFORM_CODE_STUB(DoubleToI, PlatformCodeStub);
2482 class ScriptContextFieldStub : public HandlerStub {
2484 ScriptContextFieldStub(Isolate* isolate,
2485 const ScriptContextTable::LookupResult* lookup_result)
2486 : HandlerStub(isolate) {
2487 DCHECK(Accepted(lookup_result));
2488 set_sub_minor_key(ContextIndexBits::encode(lookup_result->context_index) |
2489 SlotIndexBits::encode(lookup_result->slot_index));
2492 int context_index() const {
2493 return ContextIndexBits::decode(sub_minor_key());
2496 int slot_index() const { return SlotIndexBits::decode(sub_minor_key()); }
2498 static bool Accepted(const ScriptContextTable::LookupResult* lookup_result) {
2499 return ContextIndexBits::is_valid(lookup_result->context_index) &&
2500 SlotIndexBits::is_valid(lookup_result->slot_index);
2504 static const int kContextIndexBits = 13;
2505 static const int kSlotIndexBits = 13;
2506 class ContextIndexBits : public BitField<int, 0, kContextIndexBits> {};
2508 : public BitField<int, kContextIndexBits, kSlotIndexBits> {};
2510 Code::StubType GetStubType() const override { return Code::FAST; }
2512 DEFINE_CODE_STUB_BASE(ScriptContextFieldStub, HandlerStub);
2516 class LoadScriptContextFieldStub : public ScriptContextFieldStub {
2518 LoadScriptContextFieldStub(
2519 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2520 : ScriptContextFieldStub(isolate, lookup_result) {}
2523 Code::Kind kind() const override { return Code::LOAD_IC; }
2525 DEFINE_HANDLER_CODE_STUB(LoadScriptContextField, ScriptContextFieldStub);
2529 class StoreScriptContextFieldStub : public ScriptContextFieldStub {
2531 StoreScriptContextFieldStub(
2532 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2533 : ScriptContextFieldStub(isolate, lookup_result) {}
2536 Code::Kind kind() const override { return Code::STORE_IC; }
2538 DEFINE_HANDLER_CODE_STUB(StoreScriptContextField, ScriptContextFieldStub);
2542 class LoadFastElementStub : public HandlerStub {
2544 LoadFastElementStub(Isolate* isolate, bool is_js_array,
2545 ElementsKind elements_kind,
2546 bool convert_hole_to_undefined = false)
2547 : HandlerStub(isolate) {
2549 ElementsKindBits::encode(elements_kind) |
2550 IsJSArrayBits::encode(is_js_array) |
2551 CanConvertHoleToUndefined::encode(convert_hole_to_undefined));
2554 Code::Kind kind() const override { return Code::KEYED_LOAD_IC; }
2556 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2557 bool convert_hole_to_undefined() const {
2558 return CanConvertHoleToUndefined::decode(sub_minor_key());
2561 ElementsKind elements_kind() const {
2562 return ElementsKindBits::decode(sub_minor_key());
2566 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2567 class IsJSArrayBits: public BitField<bool, 8, 1> {};
2568 class CanConvertHoleToUndefined : public BitField<bool, 9, 1> {};
2570 DEFINE_HANDLER_CODE_STUB(LoadFastElement, HandlerStub);
2574 class StoreFastElementStub : public HydrogenCodeStub {
2576 StoreFastElementStub(Isolate* isolate, bool is_js_array,
2577 ElementsKind elements_kind, KeyedAccessStoreMode mode)
2578 : HydrogenCodeStub(isolate) {
2579 set_sub_minor_key(CommonStoreModeBits::encode(mode) |
2580 ElementsKindBits::encode(elements_kind) |
2581 IsJSArrayBits::encode(is_js_array));
2584 static void GenerateAheadOfTime(Isolate* isolate);
2586 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2588 ElementsKind elements_kind() const {
2589 return ElementsKindBits::decode(sub_minor_key());
2592 KeyedAccessStoreMode store_mode() const {
2593 return CommonStoreModeBits::decode(sub_minor_key());
2596 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
2597 if (FLAG_vector_stores) {
2598 return VectorStoreICDescriptor(isolate());
2600 return StoreDescriptor(isolate());
2603 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
2606 class ElementsKindBits : public BitField<ElementsKind, 3, 8> {};
2607 class IsJSArrayBits : public BitField<bool, 11, 1> {};
2609 DEFINE_HYDROGEN_CODE_STUB(StoreFastElement, HydrogenCodeStub);
2613 class TransitionElementsKindStub : public HydrogenCodeStub {
2615 TransitionElementsKindStub(Isolate* isolate,
2616 ElementsKind from_kind,
2617 ElementsKind to_kind,
2618 bool is_js_array) : HydrogenCodeStub(isolate) {
2619 set_sub_minor_key(FromKindBits::encode(from_kind) |
2620 ToKindBits::encode(to_kind) |
2621 IsJSArrayBits::encode(is_js_array));
2624 ElementsKind from_kind() const {
2625 return FromKindBits::decode(sub_minor_key());
2628 ElementsKind to_kind() const { return ToKindBits::decode(sub_minor_key()); }
2630 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2633 class FromKindBits: public BitField<ElementsKind, 8, 8> {};
2634 class ToKindBits: public BitField<ElementsKind, 0, 8> {};
2635 class IsJSArrayBits: public BitField<bool, 16, 1> {};
2637 DEFINE_CALL_INTERFACE_DESCRIPTOR(TransitionElementsKind);
2638 DEFINE_HYDROGEN_CODE_STUB(TransitionElementsKind, HydrogenCodeStub);
2642 class AllocateHeapNumberStub final : public HydrogenCodeStub {
2644 explicit AllocateHeapNumberStub(Isolate* isolate)
2645 : HydrogenCodeStub(isolate) {}
2648 DEFINE_CALL_INTERFACE_DESCRIPTOR(AllocateHeapNumber);
2649 DEFINE_HYDROGEN_CODE_STUB(AllocateHeapNumber, HydrogenCodeStub);
2653 class ArrayConstructorStubBase : public HydrogenCodeStub {
2655 ArrayConstructorStubBase(Isolate* isolate,
2657 AllocationSiteOverrideMode override_mode)
2658 : HydrogenCodeStub(isolate) {
2659 // It only makes sense to override local allocation site behavior
2660 // if there is a difference between the global allocation site policy
2661 // for an ElementsKind and the desired usage of the stub.
2662 DCHECK(override_mode != DISABLE_ALLOCATION_SITES ||
2663 AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE);
2664 set_sub_minor_key(ElementsKindBits::encode(kind) |
2665 AllocationSiteOverrideModeBits::encode(override_mode));
2668 ElementsKind elements_kind() const {
2669 return ElementsKindBits::decode(sub_minor_key());
2672 AllocationSiteOverrideMode override_mode() const {
2673 return AllocationSiteOverrideModeBits::decode(sub_minor_key());
2676 static void GenerateStubsAheadOfTime(Isolate* isolate);
2678 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2679 static const int kConstructor = 0;
2680 static const int kAllocationSite = 1;
2683 std::ostream& BasePrintName(std::ostream& os,
2684 const char* name) const; // NOLINT
2687 // Ensure data fits within available bits.
2688 STATIC_ASSERT(LAST_ALLOCATION_SITE_OVERRIDE_MODE == 1);
2690 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2691 class AllocationSiteOverrideModeBits: public
2692 BitField<AllocationSiteOverrideMode, 8, 1> {}; // NOLINT
2694 DEFINE_CODE_STUB_BASE(ArrayConstructorStubBase, HydrogenCodeStub);
2698 class ArrayNoArgumentConstructorStub : public ArrayConstructorStubBase {
2700 ArrayNoArgumentConstructorStub(
2703 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2704 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2708 void PrintName(std::ostream& os) const override { // NOLINT
2709 BasePrintName(os, "ArrayNoArgumentConstructorStub");
2712 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructorConstantArgCount);
2713 DEFINE_HYDROGEN_CODE_STUB(ArrayNoArgumentConstructor,
2714 ArrayConstructorStubBase);
2718 class ArraySingleArgumentConstructorStub : public ArrayConstructorStubBase {
2720 ArraySingleArgumentConstructorStub(
2723 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2724 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2728 void PrintName(std::ostream& os) const override { // NOLINT
2729 BasePrintName(os, "ArraySingleArgumentConstructorStub");
2732 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2733 DEFINE_HYDROGEN_CODE_STUB(ArraySingleArgumentConstructor,
2734 ArrayConstructorStubBase);
2738 class ArrayNArgumentsConstructorStub : public ArrayConstructorStubBase {
2740 ArrayNArgumentsConstructorStub(
2743 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2744 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2748 void PrintName(std::ostream& os) const override { // NOLINT
2749 BasePrintName(os, "ArrayNArgumentsConstructorStub");
2752 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2753 DEFINE_HYDROGEN_CODE_STUB(ArrayNArgumentsConstructor,
2754 ArrayConstructorStubBase);
2758 class InternalArrayConstructorStubBase : public HydrogenCodeStub {
2760 InternalArrayConstructorStubBase(Isolate* isolate, ElementsKind kind)
2761 : HydrogenCodeStub(isolate) {
2762 set_sub_minor_key(ElementsKindBits::encode(kind));
2765 static void GenerateStubsAheadOfTime(Isolate* isolate);
2767 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2768 static const int kConstructor = 0;
2770 ElementsKind elements_kind() const {
2771 return ElementsKindBits::decode(sub_minor_key());
2775 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2777 DEFINE_CODE_STUB_BASE(InternalArrayConstructorStubBase, HydrogenCodeStub);
2781 class InternalArrayNoArgumentConstructorStub : public
2782 InternalArrayConstructorStubBase {
2784 InternalArrayNoArgumentConstructorStub(Isolate* isolate,
2786 : InternalArrayConstructorStubBase(isolate, kind) { }
2788 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructorConstantArgCount);
2789 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNoArgumentConstructor,
2790 InternalArrayConstructorStubBase);
2794 class InternalArraySingleArgumentConstructorStub : public
2795 InternalArrayConstructorStubBase {
2797 InternalArraySingleArgumentConstructorStub(Isolate* isolate,
2799 : InternalArrayConstructorStubBase(isolate, kind) { }
2801 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2802 DEFINE_HYDROGEN_CODE_STUB(InternalArraySingleArgumentConstructor,
2803 InternalArrayConstructorStubBase);
2807 class InternalArrayNArgumentsConstructorStub : public
2808 InternalArrayConstructorStubBase {
2810 InternalArrayNArgumentsConstructorStub(Isolate* isolate, ElementsKind kind)
2811 : InternalArrayConstructorStubBase(isolate, kind) { }
2813 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2814 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNArgumentsConstructor,
2815 InternalArrayConstructorStubBase);
2819 class StoreElementStub : public PlatformCodeStub {
2821 StoreElementStub(Isolate* isolate, ElementsKind elements_kind,
2822 KeyedAccessStoreMode mode)
2823 : PlatformCodeStub(isolate) {
2824 minor_key_ = ElementsKindBits::encode(elements_kind) |
2825 CommonStoreModeBits::encode(mode);
2828 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
2829 if (FLAG_vector_stores) {
2830 return VectorStoreICDescriptor(isolate());
2832 return StoreDescriptor(isolate());
2835 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
2838 ElementsKind elements_kind() const {
2839 return ElementsKindBits::decode(minor_key_);
2842 class ElementsKindBits : public BitField<ElementsKind, 3, 8> {};
2844 DEFINE_PLATFORM_CODE_STUB(StoreElement, PlatformCodeStub);
2848 class ToBooleanStub: public HydrogenCodeStub {
2864 RESULT_AS_SMI, // For Smi(1) on truthy value, Smi(0) otherwise.
2865 RESULT_AS_ODDBALL, // For {true} on truthy value, {false} otherwise.
2866 RESULT_AS_INVERSE_ODDBALL // For {false} on truthy value, {true} otherwise.
2869 // At most 16 different types can be distinguished, because the Code object
2870 // only has room for two bytes to hold a set of these types. :-P
2871 STATIC_ASSERT(NUMBER_OF_TYPES <= 16);
2873 class Types : public EnumSet<Type, uint16_t> {
2875 Types() : EnumSet<Type, uint16_t>(0) {}
2876 explicit Types(uint16_t bits) : EnumSet<Type, uint16_t>(bits) {}
2878 bool UpdateStatus(Handle<Object> object);
2879 bool NeedsMap() const;
2880 bool CanBeUndetectable() const {
2881 return Contains(ToBooleanStub::SPEC_OBJECT);
2883 bool IsGeneric() const { return ToIntegral() == Generic().ToIntegral(); }
2885 static Types Generic() { return Types((1 << NUMBER_OF_TYPES) - 1); }
2888 ToBooleanStub(Isolate* isolate, ResultMode mode, Types types = Types())
2889 : HydrogenCodeStub(isolate) {
2890 set_sub_minor_key(TypesBits::encode(types.ToIntegral()) |
2891 ResultModeBits::encode(mode));
2894 ToBooleanStub(Isolate* isolate, ExtraICState state)
2895 : HydrogenCodeStub(isolate) {
2896 set_sub_minor_key(TypesBits::encode(static_cast<uint16_t>(state)) |
2897 ResultModeBits::encode(RESULT_AS_SMI));
2900 bool UpdateStatus(Handle<Object> object);
2901 Types types() const { return Types(TypesBits::decode(sub_minor_key())); }
2902 ResultMode mode() const { return ResultModeBits::decode(sub_minor_key()); }
2904 Code::Kind GetCodeKind() const override { return Code::TO_BOOLEAN_IC; }
2905 void PrintState(std::ostream& os) const override; // NOLINT
2907 bool SometimesSetsUpAFrame() override { return false; }
2909 static Handle<Code> GetUninitialized(Isolate* isolate) {
2910 return ToBooleanStub(isolate, UNINITIALIZED).GetCode();
2913 ExtraICState GetExtraICState() const override { return types().ToIntegral(); }
2915 InlineCacheState GetICState() const override {
2916 if (types().IsEmpty()) {
2917 return ::v8::internal::UNINITIALIZED;
2924 ToBooleanStub(Isolate* isolate, InitializationState init_state)
2925 : HydrogenCodeStub(isolate, init_state) {
2926 set_sub_minor_key(ResultModeBits::encode(RESULT_AS_SMI));
2929 class TypesBits : public BitField<uint16_t, 0, NUMBER_OF_TYPES> {};
2930 class ResultModeBits : public BitField<ResultMode, NUMBER_OF_TYPES, 2> {};
2932 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToBoolean);
2933 DEFINE_HYDROGEN_CODE_STUB(ToBoolean, HydrogenCodeStub);
2937 std::ostream& operator<<(std::ostream& os, const ToBooleanStub::Types& t);
2940 class ElementsTransitionAndStoreStub : public HydrogenCodeStub {
2942 ElementsTransitionAndStoreStub(Isolate* isolate, ElementsKind from_kind,
2943 ElementsKind to_kind, bool is_jsarray,
2944 KeyedAccessStoreMode store_mode)
2945 : HydrogenCodeStub(isolate) {
2946 set_sub_minor_key(CommonStoreModeBits::encode(store_mode) |
2947 FromBits::encode(from_kind) | ToBits::encode(to_kind) |
2948 IsJSArrayBits::encode(is_jsarray));
2951 ElementsKind from_kind() const { return FromBits::decode(sub_minor_key()); }
2952 ElementsKind to_kind() const { return ToBits::decode(sub_minor_key()); }
2953 bool is_jsarray() const { return IsJSArrayBits::decode(sub_minor_key()); }
2954 KeyedAccessStoreMode store_mode() const {
2955 return CommonStoreModeBits::decode(sub_minor_key());
2958 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override;
2959 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
2962 class FromBits : public BitField<ElementsKind, 3, 8> {};
2963 class ToBits : public BitField<ElementsKind, 11, 8> {};
2964 class IsJSArrayBits : public BitField<bool, 19, 1> {};
2966 DEFINE_HYDROGEN_CODE_STUB(ElementsTransitionAndStore, HydrogenCodeStub);
2970 class StoreArrayLiteralElementStub : public PlatformCodeStub {
2972 explicit StoreArrayLiteralElementStub(Isolate* isolate)
2973 : PlatformCodeStub(isolate) { }
2975 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreArrayLiteralElement);
2976 DEFINE_PLATFORM_CODE_STUB(StoreArrayLiteralElement, PlatformCodeStub);
2980 class StubFailureTrampolineStub : public PlatformCodeStub {
2982 StubFailureTrampolineStub(Isolate* isolate, StubFunctionMode function_mode)
2983 : PlatformCodeStub(isolate) {
2984 minor_key_ = FunctionModeField::encode(function_mode);
2987 static void GenerateAheadOfTime(Isolate* isolate);
2990 StubFunctionMode function_mode() const {
2991 return FunctionModeField::decode(minor_key_);
2994 class FunctionModeField : public BitField<StubFunctionMode, 0, 1> {};
2996 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2997 DEFINE_PLATFORM_CODE_STUB(StubFailureTrampoline, PlatformCodeStub);
3001 class ProfileEntryHookStub : public PlatformCodeStub {
3003 explicit ProfileEntryHookStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3005 // The profile entry hook function is not allowed to cause a GC.
3006 bool SometimesSetsUpAFrame() override { return false; }
3008 // Generates a call to the entry hook if it's enabled.
3009 static void MaybeCallEntryHook(MacroAssembler* masm);
3012 static void EntryHookTrampoline(intptr_t function,
3013 intptr_t stack_pointer,
3016 // ProfileEntryHookStub is called at the start of a function, so it has the
3017 // same register set.
3018 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction)
3019 DEFINE_PLATFORM_CODE_STUB(ProfileEntryHook, PlatformCodeStub);
3023 class StoreBufferOverflowStub : public PlatformCodeStub {
3025 StoreBufferOverflowStub(Isolate* isolate, SaveFPRegsMode save_fp)
3026 : PlatformCodeStub(isolate) {
3027 minor_key_ = SaveDoublesBits::encode(save_fp == kSaveFPRegs);
3030 static void GenerateFixedRegStubsAheadOfTime(Isolate* isolate);
3031 bool SometimesSetsUpAFrame() override { return false; }
3034 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
3036 class SaveDoublesBits : public BitField<bool, 0, 1> {};
3038 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
3039 DEFINE_PLATFORM_CODE_STUB(StoreBufferOverflow, PlatformCodeStub);
3043 class SubStringStub : public PlatformCodeStub {
3045 explicit SubStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3047 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
3048 DEFINE_PLATFORM_CODE_STUB(SubString, PlatformCodeStub);
3052 class ToNumberStub final : public PlatformCodeStub {
3054 explicit ToNumberStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3056 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToNumber);
3057 DEFINE_PLATFORM_CODE_STUB(ToNumber, PlatformCodeStub);
3061 class ToStringStub final : public PlatformCodeStub {
3063 explicit ToStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3065 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToString);
3066 DEFINE_PLATFORM_CODE_STUB(ToString, PlatformCodeStub);
3070 class ToObjectStub final : public HydrogenCodeStub {
3072 explicit ToObjectStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
3074 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToObject);
3075 DEFINE_HYDROGEN_CODE_STUB(ToObject, HydrogenCodeStub);
3079 class StringCompareStub : public PlatformCodeStub {
3081 explicit StringCompareStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3083 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringCompare);
3084 DEFINE_PLATFORM_CODE_STUB(StringCompare, PlatformCodeStub);
3088 #undef DEFINE_CALL_INTERFACE_DESCRIPTOR
3089 #undef DEFINE_PLATFORM_CODE_STUB
3090 #undef DEFINE_HANDLER_CODE_STUB
3091 #undef DEFINE_HYDROGEN_CODE_STUB
3092 #undef DEFINE_CODE_STUB
3093 #undef DEFINE_CODE_STUB_BASE
3095 extern Representation RepresentationFromType(Type* type);
3097 } // namespace internal
3100 #endif // V8_CODE_STUBS_H_