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) \
58 V(VectorStoreICTrampoline) \
59 V(VectorKeyedStoreICTrampoline) \
61 V(VectorKeyedStoreIC) \
62 /* HydrogenCodeStubs */ \
63 V(AllocateHeapNumber) \
64 V(ArrayNArgumentsConstructor) \
65 V(ArrayNoArgumentConstructor) \
66 V(ArraySingleArgumentConstructor) \
68 V(BinaryOpWithAllocationSite) \
70 V(CreateAllocationSite) \
72 V(ElementsTransitionAndStore) \
73 V(FastCloneShallowArray) \
74 V(FastCloneShallowObject) \
77 V(GrowArrayElements) \
78 V(InternalArrayNArgumentsConstructor) \
79 V(InternalArrayNoArgumentConstructor) \
80 V(InternalArraySingleArgumentConstructor) \
82 V(LoadGlobalViaContext) \
83 V(LoadScriptContextField) \
84 V(LoadDictionaryElement) \
85 V(NameDictionaryLookup) \
88 V(RegExpConstructResult) \
90 V(StoreGlobalViaContext) \
91 V(StoreScriptContextField) \
94 V(TransitionElementsKind) \
97 /* TurboFanCodeStubs */ \
102 /* IC Handler stubs */ \
103 V(ArrayBufferViewLoadField) \
107 V(KeyedLoadSloppyArguments) \
108 V(KeyedStoreSloppyArguments) \
115 // List of code stubs only used on ARM 32 bits platforms.
116 #if V8_TARGET_ARCH_ARM
117 #define CODE_STUB_LIST_ARM(V) V(DirectCEntry)
120 #define CODE_STUB_LIST_ARM(V)
123 // List of code stubs only used on ARM 64 bits platforms.
124 #if V8_TARGET_ARCH_ARM64
125 #define CODE_STUB_LIST_ARM64(V) \
127 V(RestoreRegistersState) \
128 V(StoreRegistersState)
131 #define CODE_STUB_LIST_ARM64(V)
134 // List of code stubs only used on PPC platforms.
135 #ifdef V8_TARGET_ARCH_PPC
136 #define CODE_STUB_LIST_PPC(V) \
138 V(StoreRegistersState) \
139 V(RestoreRegistersState)
141 #define CODE_STUB_LIST_PPC(V)
144 // List of code stubs only used on MIPS platforms.
145 #if V8_TARGET_ARCH_MIPS
146 #define CODE_STUB_LIST_MIPS(V) \
148 V(RestoreRegistersState) \
149 V(StoreRegistersState)
150 #elif V8_TARGET_ARCH_MIPS64
151 #define CODE_STUB_LIST_MIPS(V) \
153 V(RestoreRegistersState) \
154 V(StoreRegistersState)
156 #define CODE_STUB_LIST_MIPS(V)
159 // Combined list of code stubs.
160 #define CODE_STUB_LIST(V) \
161 CODE_STUB_LIST_ALL_PLATFORMS(V) \
162 CODE_STUB_LIST_ARM(V) \
163 CODE_STUB_LIST_ARM64(V) \
164 CODE_STUB_LIST_PPC(V) \
165 CODE_STUB_LIST_MIPS(V)
167 static const int kHasReturnedMinusZeroSentinel = 1;
169 // Stub is base classes of all stubs.
170 class CodeStub BASE_EMBEDDED {
173 // TODO(mvstanton): eliminate the NoCache key by getting rid
174 // of the non-monomorphic-cache.
175 NoCache = 0, // marker for stubs that do custom caching]
176 #define DEF_ENUM(name) name,
177 CODE_STUB_LIST(DEF_ENUM)
182 // Retrieve the code for the stub. Generate the code if needed.
183 Handle<Code> GetCode();
185 // Retrieve the code for the stub, make and return a copy of the code.
186 Handle<Code> GetCodeCopy(const Code::FindAndReplacePattern& pattern);
188 static Major MajorKeyFromKey(uint32_t key) {
189 return static_cast<Major>(MajorKeyBits::decode(key));
191 static uint32_t MinorKeyFromKey(uint32_t key) {
192 return MinorKeyBits::decode(key);
195 // Gets the major key from a code object that is a code stub or binary op IC.
196 static Major GetMajorKey(Code* code_stub) {
197 return MajorKeyFromKey(code_stub->stub_key());
200 static uint32_t NoCacheKey() { return MajorKeyBits::encode(NoCache); }
202 static const char* MajorName(Major major_key, bool allow_unknown_keys);
204 explicit CodeStub(Isolate* isolate) : minor_key_(0), isolate_(isolate) {}
205 virtual ~CodeStub() {}
207 static void GenerateStubsAheadOfTime(Isolate* isolate);
208 static void GenerateFPStubs(Isolate* isolate);
210 // Some stubs put untagged junk on the stack that cannot be scanned by the
211 // GC. This means that we must be statically sure that no GC can occur while
212 // they are running. If that is the case they should override this to return
213 // true, which will cause an assertion if we try to call something that can
214 // GC or if we try to put a stack frame on top of the junk, which would not
215 // result in a traversable stack.
216 virtual bool SometimesSetsUpAFrame() { return true; }
218 // Lookup the code in the (possibly custom) cache.
219 bool FindCodeInCache(Code** code_out);
221 virtual CallInterfaceDescriptor GetCallInterfaceDescriptor() const = 0;
223 virtual int GetStackParameterCount() const {
224 return GetCallInterfaceDescriptor().GetStackParameterCount();
227 virtual void InitializeDescriptor(CodeStubDescriptor* descriptor) {}
229 static void InitializeDescriptor(Isolate* isolate, uint32_t key,
230 CodeStubDescriptor* desc);
232 static MaybeHandle<Code> GetCode(Isolate* isolate, uint32_t key);
234 // Returns information for computing the number key.
235 virtual Major MajorKey() const = 0;
236 uint32_t MinorKey() const { return minor_key_; }
238 // BinaryOpStub needs to override this.
239 virtual Code::Kind GetCodeKind() const;
241 virtual InlineCacheState GetICState() const { return UNINITIALIZED; }
242 virtual ExtraICState GetExtraICState() const { return kNoExtraICState; }
243 virtual Code::StubType GetStubType() const { return Code::NORMAL; }
245 friend std::ostream& operator<<(std::ostream& os, const CodeStub& s) {
250 Isolate* isolate() const { return isolate_; }
253 CodeStub(uint32_t key, Isolate* isolate)
254 : minor_key_(MinorKeyFromKey(key)), isolate_(isolate) {}
256 // Generates the assembler code for the stub.
257 virtual Handle<Code> GenerateCode() = 0;
259 // Returns whether the code generated for this stub needs to be allocated as
260 // a fixed (non-moveable) code object.
261 virtual bool NeedsImmovableCode() { return false; }
263 virtual void PrintName(std::ostream& os) const; // NOLINT
264 virtual void PrintBaseName(std::ostream& os) const; // NOLINT
265 virtual void PrintState(std::ostream& os) const { ; } // NOLINT
267 // Computes the key based on major and minor.
269 DCHECK(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
270 return MinorKeyBits::encode(MinorKey()) | MajorKeyBits::encode(MajorKey());
276 // Perform bookkeeping required after code generation when stub code is
277 // initially generated.
278 void RecordCodeGeneration(Handle<Code> code);
280 // Finish the code object after it has been generated.
281 virtual void FinishCode(Handle<Code> code) { }
283 // Activate newly generated stub. Is called after
284 // registering stub in the stub cache.
285 virtual void Activate(Code* code) { }
287 // Add the code to a specialized cache, specific to an individual
288 // stub type. Please note, this method must add the code object to a
289 // roots object, otherwise we will remove the code during GC.
290 virtual void AddToSpecialCache(Handle<Code> new_object) { }
292 // Find code in a specialized cache, work is delegated to the specific stub.
293 virtual bool FindCodeInSpecialCache(Code** code_out) {
297 // If a stub uses a special cache override this.
298 virtual bool UseSpecialCache() { return false; }
300 // We use this dispatch to statically instantiate the correct code stub for
301 // the given stub key and call the passed function with that code stub.
302 typedef void (*DispatchedCall)(CodeStub* stub, void** value_out);
303 static void Dispatch(Isolate* isolate, uint32_t key, void** value_out,
304 DispatchedCall call);
306 static void GetCodeDispatchCall(CodeStub* stub, void** value_out);
308 STATIC_ASSERT(NUMBER_OF_IDS < (1 << kStubMajorKeyBits));
309 class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {};
310 class MinorKeyBits: public BitField<uint32_t,
311 kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT
313 friend class BreakPointIterator;
319 // TODO(svenpanne) This class is only used to construct a more or less sensible
320 // CompilationInfo for testing purposes, basically pretending that we are
321 // currently compiling some kind of code stub. Remove this when the pipeline and
322 // testing machinery is restructured in such a way that we don't have to come up
323 // with a CompilationInfo out of thin air, although we only need a few parts of
325 struct FakeStubForTesting : public CodeStub {
326 explicit FakeStubForTesting(Isolate* isolate) : CodeStub(isolate) {}
328 // Only used by pipeline.cc's GetDebugName in DEBUG mode.
329 Major MajorKey() const override { return CodeStub::NoCache; }
331 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
333 return CallInterfaceDescriptor();
336 Handle<Code> GenerateCode() override {
338 return Handle<Code>();
343 #define DEFINE_CODE_STUB_BASE(NAME, SUPER) \
345 NAME(uint32_t key, Isolate* isolate) : SUPER(key, isolate) {} \
348 DISALLOW_COPY_AND_ASSIGN(NAME)
351 #define DEFINE_CODE_STUB(NAME, SUPER) \
353 inline Major MajorKey() const override { return NAME; }; \
354 DEFINE_CODE_STUB_BASE(NAME##Stub, SUPER)
357 #define DEFINE_PLATFORM_CODE_STUB(NAME, SUPER) \
359 void Generate(MacroAssembler* masm) override; \
360 DEFINE_CODE_STUB(NAME, SUPER)
363 #define DEFINE_HYDROGEN_CODE_STUB(NAME, SUPER) \
365 void InitializeDescriptor(CodeStubDescriptor* descriptor) override; \
366 Handle<Code> GenerateCode() override; \
367 DEFINE_CODE_STUB(NAME, SUPER)
369 #define DEFINE_TURBOFAN_CODE_STUB(NAME, SUPER) \
371 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
372 return DESC##Descriptor(isolate()); \
374 DEFINE_CODE_STUB(NAME, SUPER)
376 #define DEFINE_TURBOFAN_IC(NAME, SUPER, DESC) \
378 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
379 if (GetCallMode() == CALL_FROM_OPTIMIZED_CODE) { \
380 return DESC##CallFromOptimizedCodeDescriptor(isolate()); \
382 return DESC##CallFromUnoptimizedCodeDescriptor(isolate()); \
387 DEFINE_CODE_STUB(NAME, SUPER)
389 #define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \
391 Handle<Code> GenerateCode() override; \
392 DEFINE_CODE_STUB(NAME, SUPER)
394 #define DEFINE_CALL_INTERFACE_DESCRIPTOR(NAME) \
396 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
397 return NAME##Descriptor(isolate()); \
400 // There are some code stubs we just can't describe right now with a
401 // CallInterfaceDescriptor. Isolate behavior for those cases with this macro.
402 // An attempt to retrieve a descriptor will fail.
403 #define DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR() \
405 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
407 return CallInterfaceDescriptor(); \
411 class PlatformCodeStub : public CodeStub {
413 // Retrieve the code for the stub. Generate the code if needed.
414 Handle<Code> GenerateCode() override;
417 explicit PlatformCodeStub(Isolate* isolate) : CodeStub(isolate) {}
419 // Generates the assembler code for the stub.
420 virtual void Generate(MacroAssembler* masm) = 0;
422 DEFINE_CODE_STUB_BASE(PlatformCodeStub, CodeStub);
426 enum StubFunctionMode { NOT_JS_FUNCTION_STUB_MODE, JS_FUNCTION_STUB_MODE };
429 class CodeStubDescriptor {
431 explicit CodeStubDescriptor(CodeStub* stub);
433 CodeStubDescriptor(Isolate* isolate, uint32_t stub_key);
435 void Initialize(Address deoptimization_handler = NULL,
436 int hint_stack_parameter_count = -1,
437 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
438 void Initialize(Register stack_parameter_count,
439 Address deoptimization_handler = NULL,
440 int hint_stack_parameter_count = -1,
441 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
443 void SetMissHandler(ExternalReference handler) {
444 miss_handler_ = handler;
445 has_miss_handler_ = true;
446 // Our miss handler infrastructure doesn't currently support
447 // variable stack parameter counts.
448 DCHECK(!stack_parameter_count_.is_valid());
451 void set_call_descriptor(CallInterfaceDescriptor d) { call_descriptor_ = d; }
452 CallInterfaceDescriptor call_descriptor() const { return call_descriptor_; }
454 int GetRegisterParameterCount() const {
455 return call_descriptor().GetRegisterParameterCount();
458 int GetStackParameterCount() const {
459 return call_descriptor().GetStackParameterCount();
462 int GetParameterCount() const {
463 return call_descriptor().GetParameterCount();
466 Register GetRegisterParameter(int index) const {
467 return call_descriptor().GetRegisterParameter(index);
470 Type* GetParameterType(int index) const {
471 return call_descriptor().GetParameterType(index);
474 ExternalReference miss_handler() const {
475 DCHECK(has_miss_handler_);
476 return miss_handler_;
479 bool has_miss_handler() const {
480 return has_miss_handler_;
483 int GetHandlerParameterCount() const {
484 int params = GetParameterCount();
485 if (PassesArgumentsToDeoptimizationHandler()) {
491 int hint_stack_parameter_count() const { return hint_stack_parameter_count_; }
492 Register stack_parameter_count() const { return stack_parameter_count_; }
493 StubFunctionMode function_mode() const { return function_mode_; }
494 Address deoptimization_handler() const { return deoptimization_handler_; }
497 bool PassesArgumentsToDeoptimizationHandler() const {
498 return stack_parameter_count_.is_valid();
501 CallInterfaceDescriptor call_descriptor_;
502 Register stack_parameter_count_;
503 // If hint_stack_parameter_count_ > 0, the code stub can optimize the
504 // return sequence. Default value is -1, which means it is ignored.
505 int hint_stack_parameter_count_;
506 StubFunctionMode function_mode_;
508 Address deoptimization_handler_;
510 ExternalReference miss_handler_;
511 bool has_miss_handler_;
515 class HydrogenCodeStub : public CodeStub {
517 enum InitializationState {
522 template<class SubClass>
523 static Handle<Code> GetUninitialized(Isolate* isolate) {
524 SubClass::GenerateAheadOfTime(isolate);
525 return SubClass().GetCode(isolate);
528 // Retrieve the code for the stub. Generate the code if needed.
529 Handle<Code> GenerateCode() override = 0;
531 bool IsUninitialized() const { return IsMissBits::decode(minor_key_); }
533 Handle<Code> GenerateLightweightMissCode(ExternalReference miss);
535 template<class StateType>
536 void TraceTransition(StateType from, StateType to);
539 explicit HydrogenCodeStub(Isolate* isolate,
540 InitializationState state = INITIALIZED)
541 : CodeStub(isolate) {
542 minor_key_ = IsMissBits::encode(state == UNINITIALIZED);
545 void set_sub_minor_key(uint32_t key) {
546 minor_key_ = SubMinorKeyBits::update(minor_key_, key);
549 uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
551 static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
554 class IsMissBits : public BitField<bool, kSubMinorKeyBits, 1> {};
555 class SubMinorKeyBits : public BitField<int, 0, kSubMinorKeyBits> {};
557 void GenerateLightweightMiss(MacroAssembler* masm, ExternalReference miss);
559 DEFINE_CODE_STUB_BASE(HydrogenCodeStub, CodeStub);
563 class TurboFanCodeStub : public CodeStub {
565 // Retrieve the code for the stub. Generate the code if needed.
566 Handle<Code> GenerateCode() override;
568 virtual int GetStackParameterCount() const override {
569 return GetCallInterfaceDescriptor().GetStackParameterCount();
572 Code::StubType GetStubType() const override { return Code::FAST; }
575 explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {}
578 DEFINE_CODE_STUB_BASE(TurboFanCodeStub, CodeStub);
582 class TurboFanIC : public TurboFanCodeStub {
584 enum CallMode { CALL_FROM_UNOPTIMIZED_CODE, CALL_FROM_OPTIMIZED_CODE };
587 explicit TurboFanIC(Isolate* isolate, CallMode mode)
588 : TurboFanCodeStub(isolate) {
589 minor_key_ = CallModeBits::encode(mode);
592 CallMode GetCallMode() const { return CallModeBits::decode(minor_key_); }
594 void set_sub_minor_key(uint32_t key) {
595 minor_key_ = SubMinorKeyBits::update(minor_key_, key);
598 uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
600 static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
603 class CallModeBits : public BitField<CallMode, 0, 1> {};
604 class SubMinorKeyBits : public BitField<int, 1, kSubMinorKeyBits> {};
605 DEFINE_CODE_STUB_BASE(TurboFanIC, TurboFanCodeStub);
609 // Helper interface to prepare to/restore after making runtime calls.
610 class RuntimeCallHelper {
612 virtual ~RuntimeCallHelper() {}
614 virtual void BeforeCall(MacroAssembler* masm) const = 0;
616 virtual void AfterCall(MacroAssembler* masm) const = 0;
619 RuntimeCallHelper() {}
622 DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper);
626 } } // namespace v8::internal
628 #if V8_TARGET_ARCH_IA32
629 #include "src/ia32/code-stubs-ia32.h"
630 #elif V8_TARGET_ARCH_X64
631 #include "src/x64/code-stubs-x64.h"
632 #elif V8_TARGET_ARCH_ARM64
633 #include "src/arm64/code-stubs-arm64.h"
634 #elif V8_TARGET_ARCH_ARM
635 #include "src/arm/code-stubs-arm.h"
636 #elif V8_TARGET_ARCH_PPC
637 #include "src/ppc/code-stubs-ppc.h"
638 #elif V8_TARGET_ARCH_MIPS
639 #include "src/mips/code-stubs-mips.h"
640 #elif V8_TARGET_ARCH_MIPS64
641 #include "src/mips64/code-stubs-mips64.h"
642 #elif V8_TARGET_ARCH_X87
643 #include "src/x87/code-stubs-x87.h"
645 #error Unsupported target architecture.
652 // RuntimeCallHelper implementation used in stubs: enters/leaves a
653 // newly created internal frame before/after the runtime call.
654 class StubRuntimeCallHelper : public RuntimeCallHelper {
656 StubRuntimeCallHelper() {}
658 virtual void BeforeCall(MacroAssembler* masm) const;
660 virtual void AfterCall(MacroAssembler* masm) const;
664 // Trivial RuntimeCallHelper implementation.
665 class NopRuntimeCallHelper : public RuntimeCallHelper {
667 NopRuntimeCallHelper() {}
669 virtual void BeforeCall(MacroAssembler* masm) const {}
671 virtual void AfterCall(MacroAssembler* masm) const {}
675 class MathFloorStub : public TurboFanIC {
677 explicit MathFloorStub(Isolate* isolate, TurboFanIC::CallMode mode)
678 : TurboFanIC(isolate, mode) {}
679 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
680 DEFINE_TURBOFAN_IC(MathFloor, TurboFanIC, MathRoundVariant);
684 class StringLengthTFStub : public TurboFanCodeStub {
686 explicit StringLengthTFStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
688 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
689 InlineCacheState GetICState() const override { return MONOMORPHIC; }
690 ExtraICState GetExtraICState() const override { return Code::LOAD_IC; }
692 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
693 DEFINE_CODE_STUB(StringLengthTF, TurboFanCodeStub);
697 enum StringAddFlags {
698 // Omit both parameter checks.
699 STRING_ADD_CHECK_NONE = 0,
700 // Check left parameter.
701 STRING_ADD_CHECK_LEFT = 1 << 0,
702 // Check right parameter.
703 STRING_ADD_CHECK_RIGHT = 1 << 1,
704 // Check both parameters.
705 STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT
709 std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags);
712 class StringAddTFStub : public TurboFanCodeStub {
714 StringAddTFStub(Isolate* isolate, StringAddFlags flags,
715 PretenureFlag pretenure_flag)
716 : TurboFanCodeStub(isolate) {
717 minor_key_ = StringAddFlagsBits::encode(flags) |
718 PretenureFlagBits::encode(pretenure_flag);
721 StringAddFlags flags() const {
722 return StringAddFlagsBits::decode(MinorKey());
725 PretenureFlag pretenure_flag() const {
726 return PretenureFlagBits::decode(MinorKey());
730 class StringAddFlagsBits : public BitField<StringAddFlags, 0, 2> {};
731 class PretenureFlagBits : public BitField<PretenureFlag, 2, 1> {};
733 void PrintBaseName(std::ostream& os) const override; // NOLINT
735 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
736 DEFINE_CODE_STUB(StringAddTF, TurboFanCodeStub);
740 class NumberToStringStub final : public HydrogenCodeStub {
742 explicit NumberToStringStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
744 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
745 static const int kNumber = 0;
747 DEFINE_CALL_INTERFACE_DESCRIPTOR(NumberToString);
748 DEFINE_HYDROGEN_CODE_STUB(NumberToString, HydrogenCodeStub);
752 class TypeofStub final : public HydrogenCodeStub {
754 explicit TypeofStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
756 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
757 static const int kObject = 0;
759 static void GenerateAheadOfTime(Isolate* isolate);
761 DEFINE_CALL_INTERFACE_DESCRIPTOR(Typeof);
762 DEFINE_HYDROGEN_CODE_STUB(Typeof, HydrogenCodeStub);
766 class FastNewClosureStub : public HydrogenCodeStub {
768 FastNewClosureStub(Isolate* isolate, LanguageMode language_mode,
770 : HydrogenCodeStub(isolate) {
771 DCHECK(IsValidFunctionKind(kind));
772 set_sub_minor_key(LanguageModeBits::encode(language_mode) |
773 FunctionKindBits::encode(kind));
776 LanguageMode language_mode() const {
777 return LanguageModeBits::decode(sub_minor_key());
780 FunctionKind kind() const {
781 return FunctionKindBits::decode(sub_minor_key());
785 STATIC_ASSERT(LANGUAGE_END == 3);
786 class LanguageModeBits : public BitField<LanguageMode, 0, 2> {};
787 class FunctionKindBits : public BitField<FunctionKind, 2, 8> {};
789 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewClosure);
790 DEFINE_HYDROGEN_CODE_STUB(FastNewClosure, HydrogenCodeStub);
794 class FastNewContextStub final : public HydrogenCodeStub {
796 static const int kMaximumSlots = 64;
798 FastNewContextStub(Isolate* isolate, int slots) : HydrogenCodeStub(isolate) {
799 DCHECK(slots >= 0 && slots <= kMaximumSlots);
800 set_sub_minor_key(SlotsBits::encode(slots));
803 int slots() const { return SlotsBits::decode(sub_minor_key()); }
805 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
806 static const int kFunction = 0;
809 class SlotsBits : public BitField<int, 0, 8> {};
811 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewContext);
812 DEFINE_HYDROGEN_CODE_STUB(FastNewContext, HydrogenCodeStub);
816 class FastCloneShallowArrayStub : public HydrogenCodeStub {
818 FastCloneShallowArrayStub(Isolate* isolate,
819 AllocationSiteMode allocation_site_mode)
820 : HydrogenCodeStub(isolate) {
821 set_sub_minor_key(AllocationSiteModeBits::encode(allocation_site_mode));
824 AllocationSiteMode allocation_site_mode() const {
825 return AllocationSiteModeBits::decode(sub_minor_key());
829 class AllocationSiteModeBits: public BitField<AllocationSiteMode, 0, 1> {};
831 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowArray);
832 DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowArray, HydrogenCodeStub);
836 class FastCloneShallowObjectStub : public HydrogenCodeStub {
838 // Maximum number of properties in copied object.
839 static const int kMaximumClonedProperties = 6;
841 FastCloneShallowObjectStub(Isolate* isolate, int length)
842 : HydrogenCodeStub(isolate) {
843 DCHECK_GE(length, 0);
844 DCHECK_LE(length, kMaximumClonedProperties);
845 set_sub_minor_key(LengthBits::encode(length));
848 int length() const { return LengthBits::decode(sub_minor_key()); }
851 class LengthBits : public BitField<int, 0, 4> {};
853 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowObject);
854 DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowObject, HydrogenCodeStub);
858 class CreateAllocationSiteStub : public HydrogenCodeStub {
860 explicit CreateAllocationSiteStub(Isolate* isolate)
861 : HydrogenCodeStub(isolate) { }
863 static void GenerateAheadOfTime(Isolate* isolate);
865 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateAllocationSite);
866 DEFINE_HYDROGEN_CODE_STUB(CreateAllocationSite, HydrogenCodeStub);
870 class CreateWeakCellStub : public HydrogenCodeStub {
872 explicit CreateWeakCellStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
874 static void GenerateAheadOfTime(Isolate* isolate);
876 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateWeakCell);
877 DEFINE_HYDROGEN_CODE_STUB(CreateWeakCell, HydrogenCodeStub);
881 class GrowArrayElementsStub : public HydrogenCodeStub {
883 GrowArrayElementsStub(Isolate* isolate, bool is_js_array, ElementsKind kind)
884 : HydrogenCodeStub(isolate) {
885 set_sub_minor_key(ElementsKindBits::encode(kind) |
886 IsJsArrayBits::encode(is_js_array));
889 ElementsKind elements_kind() const {
890 return ElementsKindBits::decode(sub_minor_key());
893 bool is_js_array() const { return IsJsArrayBits::decode(sub_minor_key()); }
896 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
897 class IsJsArrayBits : public BitField<bool, ElementsKindBits::kNext, 1> {};
899 DEFINE_CALL_INTERFACE_DESCRIPTOR(GrowArrayElements);
900 DEFINE_HYDROGEN_CODE_STUB(GrowArrayElements, HydrogenCodeStub);
903 class InstanceofStub: public PlatformCodeStub {
907 kArgsInRegisters = 1 << 0,
908 kCallSiteInlineCheck = 1 << 1,
909 kReturnTrueFalseObject = 1 << 2
912 InstanceofStub(Isolate* isolate, Flags flags) : PlatformCodeStub(isolate) {
913 minor_key_ = FlagBits::encode(flags);
916 static Register left() { return InstanceofDescriptor::left(); }
917 static Register right() { return InstanceofDescriptor::right(); }
919 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
920 if (HasArgsInRegisters()) {
921 return InstanceofDescriptor(isolate());
923 return ContextOnlyDescriptor(isolate());
927 Flags flags() const { return FlagBits::decode(minor_key_); }
929 bool HasArgsInRegisters() const { return (flags() & kArgsInRegisters) != 0; }
931 bool HasCallSiteInlineCheck() const {
932 return (flags() & kCallSiteInlineCheck) != 0;
935 bool ReturnTrueFalseObject() const {
936 return (flags() & kReturnTrueFalseObject) != 0;
939 void PrintName(std::ostream& os) const override; // NOLINT
941 class FlagBits : public BitField<Flags, 0, 3> {};
943 DEFINE_PLATFORM_CODE_STUB(Instanceof, PlatformCodeStub);
947 enum AllocationSiteOverrideMode {
949 DISABLE_ALLOCATION_SITES,
950 LAST_ALLOCATION_SITE_OVERRIDE_MODE = DISABLE_ALLOCATION_SITES
954 class ArrayConstructorStub: public PlatformCodeStub {
956 enum ArgumentCountKey { ANY, NONE, ONE, MORE_THAN_ONE };
958 ArrayConstructorStub(Isolate* isolate, int argument_count);
960 explicit ArrayConstructorStub(Isolate* isolate);
963 ArgumentCountKey argument_count() const {
964 return ArgumentCountBits::decode(minor_key_);
967 void GenerateDispatchToArrayStub(MacroAssembler* masm,
968 AllocationSiteOverrideMode mode);
970 void PrintName(std::ostream& os) const override; // NOLINT
972 class ArgumentCountBits : public BitField<ArgumentCountKey, 0, 2> {};
974 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
975 DEFINE_PLATFORM_CODE_STUB(ArrayConstructor, PlatformCodeStub);
979 class InternalArrayConstructorStub: public PlatformCodeStub {
981 explicit InternalArrayConstructorStub(Isolate* isolate);
984 void GenerateCase(MacroAssembler* masm, ElementsKind kind);
986 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
987 DEFINE_PLATFORM_CODE_STUB(InternalArrayConstructor, PlatformCodeStub);
991 class MathPowStub: public PlatformCodeStub {
993 enum ExponentType { INTEGER, DOUBLE, TAGGED, ON_STACK };
995 MathPowStub(Isolate* isolate, ExponentType exponent_type)
996 : PlatformCodeStub(isolate) {
997 minor_key_ = ExponentTypeBits::encode(exponent_type);
1000 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1001 if (exponent_type() == TAGGED) {
1002 return MathPowTaggedDescriptor(isolate());
1003 } else if (exponent_type() == INTEGER) {
1004 return MathPowIntegerDescriptor(isolate());
1006 // A CallInterfaceDescriptor doesn't specify double registers (yet).
1007 return ContextOnlyDescriptor(isolate());
1011 ExponentType exponent_type() const {
1012 return ExponentTypeBits::decode(minor_key_);
1015 class ExponentTypeBits : public BitField<ExponentType, 0, 2> {};
1017 DEFINE_PLATFORM_CODE_STUB(MathPow, PlatformCodeStub);
1021 class CallICStub: public PlatformCodeStub {
1023 CallICStub(Isolate* isolate, const CallICState& state)
1024 : PlatformCodeStub(isolate) {
1025 minor_key_ = state.GetExtraICState();
1028 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
1030 InlineCacheState GetICState() const override { return DEFAULT; }
1032 ExtraICState GetExtraICState() const final {
1033 return static_cast<ExtraICState>(minor_key_);
1037 bool CallAsMethod() const {
1038 return state().call_type() == CallICState::METHOD;
1041 int arg_count() const { return state().arg_count(); }
1043 CallICState state() const {
1044 return CallICState(static_cast<ExtraICState>(minor_key_));
1047 // Code generation helpers.
1048 void GenerateMiss(MacroAssembler* masm);
1051 void PrintState(std::ostream& os) const override; // NOLINT
1053 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedbackAndVector);
1054 DEFINE_PLATFORM_CODE_STUB(CallIC, PlatformCodeStub);
1058 class CallIC_ArrayStub: public CallICStub {
1060 CallIC_ArrayStub(Isolate* isolate, const CallICState& state_in)
1061 : CallICStub(isolate, state_in) {}
1063 InlineCacheState GetICState() const final { return MONOMORPHIC; }
1066 void PrintState(std::ostream& os) const override; // NOLINT
1068 DEFINE_PLATFORM_CODE_STUB(CallIC_Array, CallICStub);
1072 // TODO(verwaest): Translate to hydrogen code stub.
1073 class FunctionPrototypeStub : public PlatformCodeStub {
1075 explicit FunctionPrototypeStub(Isolate* isolate)
1076 : PlatformCodeStub(isolate) {}
1078 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1080 // TODO(mvstanton): only the receiver register is accessed. When this is
1081 // translated to a hydrogen code stub, a new CallInterfaceDescriptor
1082 // should be created that just uses that register for more efficient code.
1083 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1084 return LoadWithVectorDescriptor(isolate());
1087 DEFINE_PLATFORM_CODE_STUB(FunctionPrototype, PlatformCodeStub);
1091 // TODO(mvstanton): Translate to hydrogen code stub.
1092 class LoadIndexedInterceptorStub : public PlatformCodeStub {
1094 explicit LoadIndexedInterceptorStub(Isolate* isolate)
1095 : PlatformCodeStub(isolate) {}
1097 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1098 Code::StubType GetStubType() const override { return Code::FAST; }
1100 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
1101 DEFINE_PLATFORM_CODE_STUB(LoadIndexedInterceptor, PlatformCodeStub);
1105 class LoadIndexedStringStub : public PlatformCodeStub {
1107 explicit LoadIndexedStringStub(Isolate* isolate)
1108 : PlatformCodeStub(isolate) {}
1110 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1111 Code::StubType GetStubType() const override { return Code::FAST; }
1113 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
1114 DEFINE_PLATFORM_CODE_STUB(LoadIndexedString, PlatformCodeStub);
1118 class HandlerStub : public HydrogenCodeStub {
1120 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1121 ExtraICState GetExtraICState() const override { return kind(); }
1122 InlineCacheState GetICState() const override { return MONOMORPHIC; }
1124 void InitializeDescriptor(CodeStubDescriptor* descriptor) override;
1126 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override;
1129 explicit HandlerStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
1131 virtual Code::Kind kind() const = 0;
1133 DEFINE_CODE_STUB_BASE(HandlerStub, HydrogenCodeStub);
1137 class LoadFieldStub: public HandlerStub {
1139 LoadFieldStub(Isolate* isolate, FieldIndex index) : HandlerStub(isolate) {
1140 int property_index_key = index.GetFieldAccessStubKey();
1141 set_sub_minor_key(LoadFieldByIndexBits::encode(property_index_key));
1144 FieldIndex index() const {
1145 int property_index_key = LoadFieldByIndexBits::decode(sub_minor_key());
1146 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1150 Code::Kind kind() const override { return Code::LOAD_IC; }
1151 Code::StubType GetStubType() const override { return Code::FAST; }
1154 class LoadFieldByIndexBits : public BitField<int, 0, 13> {};
1156 DEFINE_HANDLER_CODE_STUB(LoadField, HandlerStub);
1160 class ArrayBufferViewLoadFieldStub : public HandlerStub {
1162 ArrayBufferViewLoadFieldStub(Isolate* isolate, FieldIndex index)
1163 : HandlerStub(isolate) {
1164 int property_index_key = index.GetFieldAccessStubKey();
1166 ArrayBufferViewLoadFieldByIndexBits::encode(property_index_key));
1169 FieldIndex index() const {
1170 int property_index_key =
1171 ArrayBufferViewLoadFieldByIndexBits::decode(sub_minor_key());
1172 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1176 Code::Kind kind() const override { return Code::LOAD_IC; }
1177 Code::StubType GetStubType() const override { return Code::FAST; }
1180 class ArrayBufferViewLoadFieldByIndexBits : public BitField<int, 0, 13> {};
1182 DEFINE_HANDLER_CODE_STUB(ArrayBufferViewLoadField, HandlerStub);
1186 class KeyedLoadSloppyArgumentsStub : public HandlerStub {
1188 explicit KeyedLoadSloppyArgumentsStub(Isolate* isolate)
1189 : HandlerStub(isolate) {}
1192 Code::Kind kind() const override { return Code::KEYED_LOAD_IC; }
1193 Code::StubType GetStubType() const override { return Code::FAST; }
1196 DEFINE_HANDLER_CODE_STUB(KeyedLoadSloppyArguments, HandlerStub);
1200 class KeyedStoreSloppyArgumentsStub : public HandlerStub {
1202 explicit KeyedStoreSloppyArgumentsStub(Isolate* isolate)
1203 : HandlerStub(isolate) {}
1206 Code::Kind kind() const override { return Code::KEYED_STORE_IC; }
1207 Code::StubType GetStubType() const override { return Code::FAST; }
1210 DEFINE_HANDLER_CODE_STUB(KeyedStoreSloppyArguments, HandlerStub);
1214 class LoadConstantStub : public HandlerStub {
1216 LoadConstantStub(Isolate* isolate, int constant_index)
1217 : HandlerStub(isolate) {
1218 set_sub_minor_key(ConstantIndexBits::encode(constant_index));
1221 int constant_index() const {
1222 return ConstantIndexBits::decode(sub_minor_key());
1226 Code::Kind kind() const override { return Code::LOAD_IC; }
1227 Code::StubType GetStubType() const override { return Code::FAST; }
1230 class ConstantIndexBits : public BitField<int, 0, kSubMinorKeyBits> {};
1232 DEFINE_HANDLER_CODE_STUB(LoadConstant, HandlerStub);
1236 class StringLengthStub: public HandlerStub {
1238 explicit StringLengthStub(Isolate* isolate) : HandlerStub(isolate) {}
1241 Code::Kind kind() const override { return Code::LOAD_IC; }
1242 Code::StubType GetStubType() const override { return Code::FAST; }
1244 DEFINE_HANDLER_CODE_STUB(StringLength, HandlerStub);
1248 class StoreFieldStub : public HandlerStub {
1250 StoreFieldStub(Isolate* isolate, FieldIndex index,
1251 Representation representation)
1252 : HandlerStub(isolate) {
1253 int property_index_key = index.GetFieldAccessStubKey();
1254 uint8_t repr = PropertyDetails::EncodeRepresentation(representation);
1255 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) |
1256 RepresentationBits::encode(repr));
1259 FieldIndex index() const {
1260 int property_index_key = StoreFieldByIndexBits::decode(sub_minor_key());
1261 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1264 Representation representation() {
1265 uint8_t repr = RepresentationBits::decode(sub_minor_key());
1266 return PropertyDetails::DecodeRepresentation(repr);
1270 Code::Kind kind() const override { return Code::STORE_IC; }
1271 Code::StubType GetStubType() const override { return Code::FAST; }
1274 class StoreFieldByIndexBits : public BitField<int, 0, 13> {};
1275 class RepresentationBits : public BitField<uint8_t, 13, 4> {};
1277 DEFINE_HANDLER_CODE_STUB(StoreField, HandlerStub);
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, 2> {};
1655 class PretenureFlagBits: public BitField<PretenureFlag, 2, 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 GenerateSmis(MacroAssembler* masm);
1701 void GenerateNumbers(MacroAssembler* masm);
1702 void GenerateInternalizedStrings(MacroAssembler* masm);
1703 void GenerateStrings(MacroAssembler* masm);
1704 void GenerateUniqueNames(MacroAssembler* masm);
1705 void GenerateObjects(MacroAssembler* masm);
1706 void GenerateMiss(MacroAssembler* masm);
1707 void GenerateKnownObjects(MacroAssembler* masm);
1708 void GenerateGeneric(MacroAssembler* masm);
1710 bool strict() const { return op() == Token::EQ_STRICT; }
1711 Condition GetCondition() const;
1713 void AddToSpecialCache(Handle<Code> new_object) override;
1714 bool FindCodeInSpecialCache(Code** code_out) override;
1715 bool UseSpecialCache() override {
1716 return state() == CompareICState::KNOWN_OBJECT;
1719 class OpBits : public BitField<int, 0, 3> {};
1720 class StrengthBits : public BitField<bool, 3, 1> {};
1721 class LeftStateBits : public BitField<CompareICState::State, 4, 4> {};
1722 class RightStateBits : public BitField<CompareICState::State, 8, 4> {};
1723 class StateBits : public BitField<CompareICState::State, 12, 4> {};
1725 Handle<Map> known_map_;
1727 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1728 DEFINE_PLATFORM_CODE_STUB(CompareIC, PlatformCodeStub);
1732 class CompareNilICStub : public HydrogenCodeStub {
1734 Type* GetType(Zone* zone, Handle<Map> map = Handle<Map>());
1735 Type* GetInputType(Zone* zone, Handle<Map> map);
1737 CompareNilICStub(Isolate* isolate, NilValue nil) : HydrogenCodeStub(isolate) {
1738 set_sub_minor_key(NilValueBits::encode(nil));
1741 CompareNilICStub(Isolate* isolate, ExtraICState ic_state,
1742 InitializationState init_state = INITIALIZED)
1743 : HydrogenCodeStub(isolate, init_state) {
1744 set_sub_minor_key(ic_state);
1747 static Handle<Code> GetUninitialized(Isolate* isolate,
1749 return CompareNilICStub(isolate, nil, UNINITIALIZED).GetCode();
1752 InlineCacheState GetICState() const override {
1753 State state = this->state();
1754 if (state.Contains(GENERIC)) {
1756 } else if (state.Contains(MONOMORPHIC_MAP)) {
1759 return PREMONOMORPHIC;
1763 Code::Kind GetCodeKind() const override { return Code::COMPARE_NIL_IC; }
1765 ExtraICState GetExtraICState() const override { return sub_minor_key(); }
1767 void UpdateStatus(Handle<Object> object);
1769 bool IsMonomorphic() const { return state().Contains(MONOMORPHIC_MAP); }
1771 NilValue nil_value() const { return NilValueBits::decode(sub_minor_key()); }
1774 set_sub_minor_key(TypesBits::update(sub_minor_key(), 0));
1777 void PrintState(std::ostream& os) const override; // NOLINT
1778 void PrintBaseName(std::ostream& os) const override; // NOLINT
1781 CompareNilICStub(Isolate* isolate, NilValue nil,
1782 InitializationState init_state)
1783 : HydrogenCodeStub(isolate, init_state) {
1784 set_sub_minor_key(NilValueBits::encode(nil));
1787 enum CompareNilType {
1795 // At most 6 different types can be distinguished, because the Code object
1796 // only has room for a single byte to hold a set and there are two more
1797 // boolean flags we need to store. :-P
1798 STATIC_ASSERT(NUMBER_OF_TYPES <= 6);
1800 class State : public EnumSet<CompareNilType, byte> {
1802 State() : EnumSet<CompareNilType, byte>(0) { }
1803 explicit State(byte bits) : EnumSet<CompareNilType, byte>(bits) { }
1805 friend std::ostream& operator<<(std::ostream& os, const State& s);
1807 State state() const { return State(TypesBits::decode(sub_minor_key())); }
1809 class NilValueBits : public BitField<NilValue, 0, 1> {};
1810 class TypesBits : public BitField<byte, 1, NUMBER_OF_TYPES> {};
1812 friend class CompareNilIC;
1814 DEFINE_CALL_INTERFACE_DESCRIPTOR(CompareNil);
1815 DEFINE_HYDROGEN_CODE_STUB(CompareNilIC, HydrogenCodeStub);
1819 std::ostream& operator<<(std::ostream& os, const CompareNilICStub::State& s);
1822 class CEntryStub : public PlatformCodeStub {
1824 CEntryStub(Isolate* isolate, int result_size,
1825 SaveFPRegsMode save_doubles = kDontSaveFPRegs)
1826 : PlatformCodeStub(isolate) {
1827 minor_key_ = SaveDoublesBits::encode(save_doubles == kSaveFPRegs);
1828 DCHECK(result_size == 1 || result_size == 2);
1829 #if _WIN64 || V8_TARGET_ARCH_PPC
1830 minor_key_ = ResultSizeBits::update(minor_key_, result_size);
1834 // The version of this stub that doesn't save doubles is generated ahead of
1835 // time, so it's OK to call it from other stubs that can't cope with GC during
1836 // their code generation. On machines that always have gp registers (x64) we
1837 // can generate both variants ahead of time.
1838 static void GenerateAheadOfTime(Isolate* isolate);
1841 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
1842 #if _WIN64 || V8_TARGET_ARCH_PPC
1843 int result_size() const { return ResultSizeBits::decode(minor_key_); }
1846 bool NeedsImmovableCode() override;
1848 class SaveDoublesBits : public BitField<bool, 0, 1> {};
1849 class ResultSizeBits : public BitField<int, 1, 3> {};
1851 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1852 DEFINE_PLATFORM_CODE_STUB(CEntry, PlatformCodeStub);
1856 class JSEntryStub : public PlatformCodeStub {
1858 JSEntryStub(Isolate* isolate, StackFrame::Type type)
1859 : PlatformCodeStub(isolate) {
1860 DCHECK(type == StackFrame::ENTRY || type == StackFrame::ENTRY_CONSTRUCT);
1861 minor_key_ = StackFrameTypeBits::encode(type);
1865 void FinishCode(Handle<Code> code) override;
1867 void PrintName(std::ostream& os) const override { // NOLINT
1868 os << (type() == StackFrame::ENTRY ? "JSEntryStub"
1869 : "JSConstructEntryStub");
1872 StackFrame::Type type() const {
1873 return StackFrameTypeBits::decode(minor_key_);
1876 class StackFrameTypeBits : public BitField<StackFrame::Type, 0, 5> {};
1878 int handler_offset_;
1880 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1881 DEFINE_PLATFORM_CODE_STUB(JSEntry, PlatformCodeStub);
1885 class ArgumentsAccessStub: public PlatformCodeStub {
1894 ArgumentsAccessStub(Isolate* isolate, Type type) : PlatformCodeStub(isolate) {
1895 minor_key_ = TypeBits::encode(type);
1898 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1899 if (type() == READ_ELEMENT) {
1900 return ArgumentsAccessReadDescriptor(isolate());
1902 return ContextOnlyDescriptor(isolate());
1906 Type type() const { return TypeBits::decode(minor_key_); }
1908 void GenerateReadElement(MacroAssembler* masm);
1909 void GenerateNewStrict(MacroAssembler* masm);
1910 void GenerateNewSloppyFast(MacroAssembler* masm);
1911 void GenerateNewSloppySlow(MacroAssembler* masm);
1913 void PrintName(std::ostream& os) const override; // NOLINT
1915 class TypeBits : public BitField<Type, 0, 2> {};
1917 DEFINE_PLATFORM_CODE_STUB(ArgumentsAccess, PlatformCodeStub);
1921 class RestParamAccessStub: public PlatformCodeStub {
1923 explicit RestParamAccessStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
1925 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1926 return ContextOnlyDescriptor(isolate());
1930 void GenerateNew(MacroAssembler* masm);
1932 void PrintName(std::ostream& os) const override; // NOLINT
1934 DEFINE_PLATFORM_CODE_STUB(RestParamAccess, PlatformCodeStub);
1938 class RegExpExecStub: public PlatformCodeStub {
1940 explicit RegExpExecStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
1942 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
1943 DEFINE_PLATFORM_CODE_STUB(RegExpExec, PlatformCodeStub);
1947 class RegExpConstructResultStub final : public HydrogenCodeStub {
1949 explicit RegExpConstructResultStub(Isolate* isolate)
1950 : HydrogenCodeStub(isolate) { }
1952 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1953 static const int kLength = 0;
1954 static const int kIndex = 1;
1955 static const int kInput = 2;
1957 DEFINE_CALL_INTERFACE_DESCRIPTOR(RegExpConstructResult);
1958 DEFINE_HYDROGEN_CODE_STUB(RegExpConstructResult, HydrogenCodeStub);
1962 class CallFunctionStub: public PlatformCodeStub {
1964 CallFunctionStub(Isolate* isolate, int argc, CallFunctionFlags flags)
1965 : PlatformCodeStub(isolate) {
1966 DCHECK(argc >= 0 && argc <= Code::kMaxArguments);
1967 minor_key_ = ArgcBits::encode(argc) | FlagBits::encode(flags);
1971 int argc() const { return ArgcBits::decode(minor_key_); }
1972 int flags() const { return FlagBits::decode(minor_key_); }
1974 bool CallAsMethod() const {
1975 return flags() == CALL_AS_METHOD || flags() == WRAP_AND_CALL;
1978 bool NeedsChecks() const { return flags() != WRAP_AND_CALL; }
1980 void PrintName(std::ostream& os) const override; // NOLINT
1982 // Minor key encoding in 32 bits with Bitfield <Type, shift, size>.
1983 class FlagBits : public BitField<CallFunctionFlags, 0, 2> {};
1984 class ArgcBits : public BitField<unsigned, 2, Code::kArgumentsBits> {};
1985 STATIC_ASSERT(Code::kArgumentsBits + 2 <= kStubMinorKeyBits);
1987 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction);
1988 DEFINE_PLATFORM_CODE_STUB(CallFunction, PlatformCodeStub);
1992 class CallConstructStub: public PlatformCodeStub {
1994 CallConstructStub(Isolate* isolate, CallConstructorFlags flags)
1995 : PlatformCodeStub(isolate) {
1996 minor_key_ = FlagBits::encode(flags);
1999 void FinishCode(Handle<Code> code) override {
2000 code->set_has_function_cache(RecordCallTarget());
2004 CallConstructorFlags flags() const { return FlagBits::decode(minor_key_); }
2006 bool RecordCallTarget() const {
2007 return (flags() & RECORD_CONSTRUCTOR_TARGET) != 0;
2010 bool IsSuperConstructorCall() const {
2011 return (flags() & SUPER_CONSTRUCTOR_CALL) != 0;
2014 void PrintName(std::ostream& os) const override; // NOLINT
2016 class FlagBits : public BitField<CallConstructorFlags, 0, 2> {};
2018 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallConstruct);
2019 DEFINE_PLATFORM_CODE_STUB(CallConstruct, PlatformCodeStub);
2023 enum StringIndexFlags {
2024 // Accepts smis or heap numbers.
2025 STRING_INDEX_IS_NUMBER,
2027 // Accepts smis or heap numbers that are valid array indices
2028 // (ECMA-262 15.4). Invalid indices are reported as being out of
2030 STRING_INDEX_IS_ARRAY_INDEX
2034 enum ReceiverCheckMode {
2035 // We don't know anything about the receiver.
2036 RECEIVER_IS_UNKNOWN,
2038 // We know the receiver is a string.
2044 // The code being generated is part of an IC handler, which may MISS
2045 // to an IC in failure cases.
2048 NOT_PART_OF_IC_HANDLER
2052 // Generates code implementing String.prototype.charCodeAt.
2054 // Only supports the case when the receiver is a string and the index
2055 // is a number (smi or heap number) that is a valid index into the
2056 // string. Additional index constraints are specified by the
2057 // flags. Otherwise, bails out to the provided labels.
2059 // Register usage: |object| may be changed to another string in a way
2060 // that doesn't affect charCodeAt/charAt semantics, |index| is
2061 // preserved, |scratch| and |result| are clobbered.
2062 class StringCharCodeAtGenerator {
2064 StringCharCodeAtGenerator(Register object, Register index, Register result,
2065 Label* receiver_not_string, Label* index_not_number,
2066 Label* index_out_of_range,
2067 StringIndexFlags index_flags,
2068 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
2072 receiver_not_string_(receiver_not_string),
2073 index_not_number_(index_not_number),
2074 index_out_of_range_(index_out_of_range),
2075 index_flags_(index_flags),
2076 check_mode_(check_mode) {
2077 DCHECK(!result_.is(object_));
2078 DCHECK(!result_.is(index_));
2081 // Generates the fast case code. On the fallthrough path |result|
2082 // register contains the result.
2083 void GenerateFast(MacroAssembler* masm);
2085 // Generates the slow case code. Must not be naturally
2086 // reachable. Expected to be put after a ret instruction (e.g., in
2087 // deferred code). Always jumps back to the fast case.
2088 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
2089 const RuntimeCallHelper& call_helper);
2091 // Skip handling slow case and directly jump to bailout.
2092 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2093 masm->bind(&index_not_smi_);
2094 masm->bind(&call_runtime_);
2103 Label* receiver_not_string_;
2104 Label* index_not_number_;
2105 Label* index_out_of_range_;
2107 StringIndexFlags index_flags_;
2108 ReceiverCheckMode check_mode_;
2110 Label call_runtime_;
2111 Label index_not_smi_;
2112 Label got_smi_index_;
2115 DISALLOW_COPY_AND_ASSIGN(StringCharCodeAtGenerator);
2119 // Generates code for creating a one-char string from a char code.
2120 class StringCharFromCodeGenerator {
2122 StringCharFromCodeGenerator(Register code,
2126 DCHECK(!code_.is(result_));
2129 // Generates the fast case code. On the fallthrough path |result|
2130 // register contains the result.
2131 void GenerateFast(MacroAssembler* masm);
2133 // Generates the slow case code. Must not be naturally
2134 // reachable. Expected to be put after a ret instruction (e.g., in
2135 // deferred code). Always jumps back to the fast case.
2136 void GenerateSlow(MacroAssembler* masm,
2137 const RuntimeCallHelper& call_helper);
2139 // Skip handling slow case and directly jump to bailout.
2140 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2141 masm->bind(&slow_case_);
2152 DISALLOW_COPY_AND_ASSIGN(StringCharFromCodeGenerator);
2156 // Generates code implementing String.prototype.charAt.
2158 // Only supports the case when the receiver is a string and the index
2159 // is a number (smi or heap number) that is a valid index into the
2160 // string. Additional index constraints are specified by the
2161 // flags. Otherwise, bails out to the provided labels.
2163 // Register usage: |object| may be changed to another string in a way
2164 // that doesn't affect charCodeAt/charAt semantics, |index| is
2165 // preserved, |scratch1|, |scratch2|, and |result| are clobbered.
2166 class StringCharAtGenerator {
2168 StringCharAtGenerator(Register object, Register index, Register scratch,
2169 Register result, Label* receiver_not_string,
2170 Label* index_not_number, Label* index_out_of_range,
2171 StringIndexFlags index_flags,
2172 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
2173 : char_code_at_generator_(object, index, scratch, receiver_not_string,
2174 index_not_number, index_out_of_range,
2175 index_flags, check_mode),
2176 char_from_code_generator_(scratch, result) {}
2178 // Generates the fast case code. On the fallthrough path |result|
2179 // register contains the result.
2180 void GenerateFast(MacroAssembler* masm) {
2181 char_code_at_generator_.GenerateFast(masm);
2182 char_from_code_generator_.GenerateFast(masm);
2185 // Generates the slow case code. Must not be naturally
2186 // reachable. Expected to be put after a ret instruction (e.g., in
2187 // deferred code). Always jumps back to the fast case.
2188 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
2189 const RuntimeCallHelper& call_helper) {
2190 char_code_at_generator_.GenerateSlow(masm, embed_mode, call_helper);
2191 char_from_code_generator_.GenerateSlow(masm, call_helper);
2194 // Skip handling slow case and directly jump to bailout.
2195 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2196 char_code_at_generator_.SkipSlow(masm, bailout);
2197 char_from_code_generator_.SkipSlow(masm, bailout);
2201 StringCharCodeAtGenerator char_code_at_generator_;
2202 StringCharFromCodeGenerator char_from_code_generator_;
2204 DISALLOW_COPY_AND_ASSIGN(StringCharAtGenerator);
2208 class LoadDictionaryElementStub : public HydrogenCodeStub {
2210 explicit LoadDictionaryElementStub(Isolate* isolate, const LoadICState& state)
2211 : HydrogenCodeStub(isolate) {
2212 minor_key_ = state.GetExtraICState();
2215 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
2216 return LoadWithVectorDescriptor(isolate());
2219 LanguageMode language_mode() const {
2220 return LoadICState::GetLanguageMode(MinorKey());
2223 DEFINE_HYDROGEN_CODE_STUB(LoadDictionaryElement, HydrogenCodeStub);
2227 class KeyedLoadGenericStub : public HydrogenCodeStub {
2229 explicit KeyedLoadGenericStub(Isolate* isolate, const LoadICState& state)
2230 : HydrogenCodeStub(isolate) {
2231 minor_key_ = state.GetExtraICState();
2234 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2235 InlineCacheState GetICState() const override { return GENERIC; }
2237 LanguageMode language_mode() const {
2238 return LoadICState::GetLanguageMode(MinorKey());
2241 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2243 DEFINE_HYDROGEN_CODE_STUB(KeyedLoadGeneric, HydrogenCodeStub);
2247 class LoadICTrampolineStub : public PlatformCodeStub {
2249 LoadICTrampolineStub(Isolate* isolate, const LoadICState& state)
2250 : PlatformCodeStub(isolate) {
2251 minor_key_ = state.GetExtraICState();
2254 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2256 InlineCacheState GetICState() const final { return DEFAULT; }
2258 ExtraICState GetExtraICState() const final {
2259 return static_cast<ExtraICState>(minor_key_);
2263 LoadICState state() const {
2264 return LoadICState(static_cast<ExtraICState>(minor_key_));
2267 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2268 DEFINE_PLATFORM_CODE_STUB(LoadICTrampoline, PlatformCodeStub);
2272 class KeyedLoadICTrampolineStub : public LoadICTrampolineStub {
2274 explicit KeyedLoadICTrampolineStub(Isolate* isolate, const LoadICState& state)
2275 : LoadICTrampolineStub(isolate, state) {}
2277 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2279 DEFINE_PLATFORM_CODE_STUB(KeyedLoadICTrampoline, LoadICTrampolineStub);
2283 class VectorStoreICTrampolineStub : public PlatformCodeStub {
2285 VectorStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2286 : PlatformCodeStub(isolate) {
2287 minor_key_ = state.GetExtraICState();
2290 Code::Kind GetCodeKind() const override { return Code::STORE_IC; }
2292 InlineCacheState GetICState() const final { return DEFAULT; }
2294 ExtraICState GetExtraICState() const final {
2295 return static_cast<ExtraICState>(minor_key_);
2299 StoreICState state() const {
2300 return StoreICState(static_cast<ExtraICState>(minor_key_));
2304 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreICTrampoline);
2305 DEFINE_PLATFORM_CODE_STUB(VectorStoreICTrampoline, PlatformCodeStub);
2309 class VectorKeyedStoreICTrampolineStub : public VectorStoreICTrampolineStub {
2311 VectorKeyedStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2312 : VectorStoreICTrampolineStub(isolate, state) {}
2314 Code::Kind GetCodeKind() const override { return Code::KEYED_STORE_IC; }
2316 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreICTrampoline,
2317 VectorStoreICTrampolineStub);
2321 class CallICTrampolineStub : public PlatformCodeStub {
2323 CallICTrampolineStub(Isolate* isolate, const CallICState& state)
2324 : PlatformCodeStub(isolate) {
2325 minor_key_ = state.GetExtraICState();
2328 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
2330 InlineCacheState GetICState() const final { return DEFAULT; }
2332 ExtraICState GetExtraICState() const final {
2333 return static_cast<ExtraICState>(minor_key_);
2337 CallICState state() const {
2338 return CallICState(static_cast<ExtraICState>(minor_key_));
2341 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedback);
2342 DEFINE_PLATFORM_CODE_STUB(CallICTrampoline, PlatformCodeStub);
2346 class CallIC_ArrayTrampolineStub : public CallICTrampolineStub {
2348 CallIC_ArrayTrampolineStub(Isolate* isolate, const CallICState& state)
2349 : CallICTrampolineStub(isolate, state) {}
2352 DEFINE_PLATFORM_CODE_STUB(CallIC_ArrayTrampoline, CallICTrampolineStub);
2356 class LoadICStub : public PlatformCodeStub {
2358 explicit LoadICStub(Isolate* isolate, const LoadICState& state)
2359 : PlatformCodeStub(isolate) {
2360 minor_key_ = state.GetExtraICState();
2363 void GenerateForTrampoline(MacroAssembler* masm);
2365 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2366 InlineCacheState GetICState() const final { return DEFAULT; }
2367 ExtraICState GetExtraICState() const final {
2368 return static_cast<ExtraICState>(minor_key_);
2371 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2372 DEFINE_PLATFORM_CODE_STUB(LoadIC, PlatformCodeStub);
2375 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2379 class KeyedLoadICStub : public PlatformCodeStub {
2381 explicit KeyedLoadICStub(Isolate* isolate, const LoadICState& state)
2382 : PlatformCodeStub(isolate) {
2383 minor_key_ = state.GetExtraICState();
2386 void GenerateForTrampoline(MacroAssembler* masm);
2388 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2389 InlineCacheState GetICState() const final { return DEFAULT; }
2390 ExtraICState GetExtraICState() const final {
2391 return static_cast<ExtraICState>(minor_key_);
2394 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2395 DEFINE_PLATFORM_CODE_STUB(KeyedLoadIC, PlatformCodeStub);
2398 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2402 class VectorStoreICStub : public PlatformCodeStub {
2404 VectorStoreICStub(Isolate* isolate, const StoreICState& state)
2405 : PlatformCodeStub(isolate) {
2406 minor_key_ = state.GetExtraICState();
2409 void GenerateForTrampoline(MacroAssembler* masm);
2411 Code::Kind GetCodeKind() const final { return Code::STORE_IC; }
2412 InlineCacheState GetICState() const final { return DEFAULT; }
2413 ExtraICState GetExtraICState() const final {
2414 return static_cast<ExtraICState>(minor_key_);
2417 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2418 DEFINE_PLATFORM_CODE_STUB(VectorStoreIC, PlatformCodeStub);
2421 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2425 class VectorKeyedStoreICStub : public PlatformCodeStub {
2427 VectorKeyedStoreICStub(Isolate* isolate, const StoreICState& state)
2428 : PlatformCodeStub(isolate) {
2429 minor_key_ = state.GetExtraICState();
2432 void GenerateForTrampoline(MacroAssembler* masm);
2434 Code::Kind GetCodeKind() const final { return Code::KEYED_STORE_IC; }
2435 InlineCacheState GetICState() const final { return DEFAULT; }
2436 virtual ExtraICState GetExtraICState() const final {
2437 return static_cast<ExtraICState>(minor_key_);
2440 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2441 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreIC, PlatformCodeStub);
2444 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2448 class DoubleToIStub : public PlatformCodeStub {
2450 DoubleToIStub(Isolate* isolate, Register source, Register destination,
2451 int offset, bool is_truncating, bool skip_fastpath = false)
2452 : PlatformCodeStub(isolate) {
2453 minor_key_ = SourceRegisterBits::encode(source.code()) |
2454 DestinationRegisterBits::encode(destination.code()) |
2455 OffsetBits::encode(offset) |
2456 IsTruncatingBits::encode(is_truncating) |
2457 SkipFastPathBits::encode(skip_fastpath) |
2458 SSE3Bits::encode(CpuFeatures::IsSupported(SSE3) ? 1 : 0);
2461 bool SometimesSetsUpAFrame() override { return false; }
2464 Register source() const {
2465 return Register::from_code(SourceRegisterBits::decode(minor_key_));
2467 Register destination() const {
2468 return Register::from_code(DestinationRegisterBits::decode(minor_key_));
2470 bool is_truncating() const { return IsTruncatingBits::decode(minor_key_); }
2471 bool skip_fastpath() const { return SkipFastPathBits::decode(minor_key_); }
2472 int offset() const { return OffsetBits::decode(minor_key_); }
2474 static const int kBitsPerRegisterNumber = 6;
2475 STATIC_ASSERT((1L << kBitsPerRegisterNumber) >= Register::kNumRegisters);
2476 class SourceRegisterBits:
2477 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT
2478 class DestinationRegisterBits:
2479 public BitField<int, kBitsPerRegisterNumber,
2480 kBitsPerRegisterNumber> {}; // NOLINT
2481 class IsTruncatingBits:
2482 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT
2484 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT
2485 class SkipFastPathBits:
2486 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT
2488 public BitField<int, 2 * kBitsPerRegisterNumber + 5, 1> {}; // NOLINT
2490 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2491 DEFINE_PLATFORM_CODE_STUB(DoubleToI, PlatformCodeStub);
2495 class ScriptContextFieldStub : public HandlerStub {
2497 ScriptContextFieldStub(Isolate* isolate,
2498 const ScriptContextTable::LookupResult* lookup_result)
2499 : HandlerStub(isolate) {
2500 DCHECK(Accepted(lookup_result));
2501 set_sub_minor_key(ContextIndexBits::encode(lookup_result->context_index) |
2502 SlotIndexBits::encode(lookup_result->slot_index));
2505 int context_index() const {
2506 return ContextIndexBits::decode(sub_minor_key());
2509 int slot_index() const { return SlotIndexBits::decode(sub_minor_key()); }
2511 static bool Accepted(const ScriptContextTable::LookupResult* lookup_result) {
2512 return ContextIndexBits::is_valid(lookup_result->context_index) &&
2513 SlotIndexBits::is_valid(lookup_result->slot_index);
2517 static const int kContextIndexBits = 13;
2518 static const int kSlotIndexBits = 13;
2519 class ContextIndexBits : public BitField<int, 0, kContextIndexBits> {};
2521 : public BitField<int, kContextIndexBits, kSlotIndexBits> {};
2523 Code::StubType GetStubType() const override { return Code::FAST; }
2525 DEFINE_CODE_STUB_BASE(ScriptContextFieldStub, HandlerStub);
2529 class LoadScriptContextFieldStub : public ScriptContextFieldStub {
2531 LoadScriptContextFieldStub(
2532 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2533 : ScriptContextFieldStub(isolate, lookup_result) {}
2536 Code::Kind kind() const override { return Code::LOAD_IC; }
2538 DEFINE_HANDLER_CODE_STUB(LoadScriptContextField, ScriptContextFieldStub);
2542 class StoreScriptContextFieldStub : public ScriptContextFieldStub {
2544 StoreScriptContextFieldStub(
2545 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2546 : ScriptContextFieldStub(isolate, lookup_result) {}
2549 Code::Kind kind() const override { return Code::STORE_IC; }
2551 DEFINE_HANDLER_CODE_STUB(StoreScriptContextField, ScriptContextFieldStub);
2555 class LoadFastElementStub : public HandlerStub {
2557 LoadFastElementStub(Isolate* isolate, bool is_js_array,
2558 ElementsKind elements_kind,
2559 bool convert_hole_to_undefined = false)
2560 : HandlerStub(isolate) {
2562 ElementsKindBits::encode(elements_kind) |
2563 IsJSArrayBits::encode(is_js_array) |
2564 CanConvertHoleToUndefined::encode(convert_hole_to_undefined));
2567 Code::Kind kind() const override { return Code::KEYED_LOAD_IC; }
2569 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2570 bool convert_hole_to_undefined() const {
2571 return CanConvertHoleToUndefined::decode(sub_minor_key());
2574 ElementsKind elements_kind() const {
2575 return ElementsKindBits::decode(sub_minor_key());
2579 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2580 class IsJSArrayBits: public BitField<bool, 8, 1> {};
2581 class CanConvertHoleToUndefined : public BitField<bool, 9, 1> {};
2583 DEFINE_HANDLER_CODE_STUB(LoadFastElement, HandlerStub);
2587 class StoreFastElementStub : public HydrogenCodeStub {
2589 StoreFastElementStub(Isolate* isolate, bool is_js_array,
2590 ElementsKind elements_kind, KeyedAccessStoreMode mode)
2591 : HydrogenCodeStub(isolate) {
2592 set_sub_minor_key(ElementsKindBits::encode(elements_kind) |
2593 IsJSArrayBits::encode(is_js_array) |
2594 StoreModeBits::encode(mode));
2597 static void GenerateAheadOfTime(Isolate* isolate);
2599 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2601 ElementsKind elements_kind() const {
2602 return ElementsKindBits::decode(sub_minor_key());
2605 KeyedAccessStoreMode store_mode() const {
2606 return StoreModeBits::decode(sub_minor_key());
2610 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2611 class StoreModeBits: public BitField<KeyedAccessStoreMode, 8, 4> {};
2612 class IsJSArrayBits: public BitField<bool, 12, 1> {};
2614 DEFINE_CALL_INTERFACE_DESCRIPTOR(Store);
2615 DEFINE_HYDROGEN_CODE_STUB(StoreFastElement, HydrogenCodeStub);
2619 class TransitionElementsKindStub : public HydrogenCodeStub {
2621 TransitionElementsKindStub(Isolate* isolate,
2622 ElementsKind from_kind,
2623 ElementsKind to_kind,
2624 bool is_js_array) : HydrogenCodeStub(isolate) {
2625 set_sub_minor_key(FromKindBits::encode(from_kind) |
2626 ToKindBits::encode(to_kind) |
2627 IsJSArrayBits::encode(is_js_array));
2630 ElementsKind from_kind() const {
2631 return FromKindBits::decode(sub_minor_key());
2634 ElementsKind to_kind() const { return ToKindBits::decode(sub_minor_key()); }
2636 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2639 class FromKindBits: public BitField<ElementsKind, 8, 8> {};
2640 class ToKindBits: public BitField<ElementsKind, 0, 8> {};
2641 class IsJSArrayBits: public BitField<bool, 16, 1> {};
2643 DEFINE_CALL_INTERFACE_DESCRIPTOR(TransitionElementsKind);
2644 DEFINE_HYDROGEN_CODE_STUB(TransitionElementsKind, HydrogenCodeStub);
2648 class AllocateHeapNumberStub final : public HydrogenCodeStub {
2650 explicit AllocateHeapNumberStub(Isolate* isolate)
2651 : HydrogenCodeStub(isolate) {}
2654 DEFINE_CALL_INTERFACE_DESCRIPTOR(AllocateHeapNumber);
2655 DEFINE_HYDROGEN_CODE_STUB(AllocateHeapNumber, HydrogenCodeStub);
2659 class ArrayConstructorStubBase : public HydrogenCodeStub {
2661 ArrayConstructorStubBase(Isolate* isolate,
2663 AllocationSiteOverrideMode override_mode)
2664 : HydrogenCodeStub(isolate) {
2665 // It only makes sense to override local allocation site behavior
2666 // if there is a difference between the global allocation site policy
2667 // for an ElementsKind and the desired usage of the stub.
2668 DCHECK(override_mode != DISABLE_ALLOCATION_SITES ||
2669 AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE);
2670 set_sub_minor_key(ElementsKindBits::encode(kind) |
2671 AllocationSiteOverrideModeBits::encode(override_mode));
2674 ElementsKind elements_kind() const {
2675 return ElementsKindBits::decode(sub_minor_key());
2678 AllocationSiteOverrideMode override_mode() const {
2679 return AllocationSiteOverrideModeBits::decode(sub_minor_key());
2682 static void GenerateStubsAheadOfTime(Isolate* isolate);
2684 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2685 static const int kConstructor = 0;
2686 static const int kAllocationSite = 1;
2689 std::ostream& BasePrintName(std::ostream& os,
2690 const char* name) const; // NOLINT
2693 // Ensure data fits within available bits.
2694 STATIC_ASSERT(LAST_ALLOCATION_SITE_OVERRIDE_MODE == 1);
2696 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2697 class AllocationSiteOverrideModeBits: public
2698 BitField<AllocationSiteOverrideMode, 8, 1> {}; // NOLINT
2700 DEFINE_CODE_STUB_BASE(ArrayConstructorStubBase, HydrogenCodeStub);
2704 class ArrayNoArgumentConstructorStub : public ArrayConstructorStubBase {
2706 ArrayNoArgumentConstructorStub(
2709 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2710 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2714 void PrintName(std::ostream& os) const override { // NOLINT
2715 BasePrintName(os, "ArrayNoArgumentConstructorStub");
2718 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructorConstantArgCount);
2719 DEFINE_HYDROGEN_CODE_STUB(ArrayNoArgumentConstructor,
2720 ArrayConstructorStubBase);
2724 class ArraySingleArgumentConstructorStub : public ArrayConstructorStubBase {
2726 ArraySingleArgumentConstructorStub(
2729 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2730 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2734 void PrintName(std::ostream& os) const override { // NOLINT
2735 BasePrintName(os, "ArraySingleArgumentConstructorStub");
2738 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2739 DEFINE_HYDROGEN_CODE_STUB(ArraySingleArgumentConstructor,
2740 ArrayConstructorStubBase);
2744 class ArrayNArgumentsConstructorStub : public ArrayConstructorStubBase {
2746 ArrayNArgumentsConstructorStub(
2749 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2750 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2754 void PrintName(std::ostream& os) const override { // NOLINT
2755 BasePrintName(os, "ArrayNArgumentsConstructorStub");
2758 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2759 DEFINE_HYDROGEN_CODE_STUB(ArrayNArgumentsConstructor,
2760 ArrayConstructorStubBase);
2764 class InternalArrayConstructorStubBase : public HydrogenCodeStub {
2766 InternalArrayConstructorStubBase(Isolate* isolate, ElementsKind kind)
2767 : HydrogenCodeStub(isolate) {
2768 set_sub_minor_key(ElementsKindBits::encode(kind));
2771 static void GenerateStubsAheadOfTime(Isolate* isolate);
2773 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2774 static const int kConstructor = 0;
2776 ElementsKind elements_kind() const {
2777 return ElementsKindBits::decode(sub_minor_key());
2781 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2783 DEFINE_CODE_STUB_BASE(InternalArrayConstructorStubBase, HydrogenCodeStub);
2787 class InternalArrayNoArgumentConstructorStub : public
2788 InternalArrayConstructorStubBase {
2790 InternalArrayNoArgumentConstructorStub(Isolate* isolate,
2792 : InternalArrayConstructorStubBase(isolate, kind) { }
2794 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructorConstantArgCount);
2795 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNoArgumentConstructor,
2796 InternalArrayConstructorStubBase);
2800 class InternalArraySingleArgumentConstructorStub : public
2801 InternalArrayConstructorStubBase {
2803 InternalArraySingleArgumentConstructorStub(Isolate* isolate,
2805 : InternalArrayConstructorStubBase(isolate, kind) { }
2807 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2808 DEFINE_HYDROGEN_CODE_STUB(InternalArraySingleArgumentConstructor,
2809 InternalArrayConstructorStubBase);
2813 class InternalArrayNArgumentsConstructorStub : public
2814 InternalArrayConstructorStubBase {
2816 InternalArrayNArgumentsConstructorStub(Isolate* isolate, ElementsKind kind)
2817 : InternalArrayConstructorStubBase(isolate, kind) { }
2819 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2820 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNArgumentsConstructor,
2821 InternalArrayConstructorStubBase);
2825 class StoreElementStub : public PlatformCodeStub {
2827 StoreElementStub(Isolate* isolate, ElementsKind elements_kind)
2828 : PlatformCodeStub(isolate) {
2829 minor_key_ = ElementsKindBits::encode(elements_kind);
2833 ElementsKind elements_kind() const {
2834 return ElementsKindBits::decode(minor_key_);
2837 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2839 DEFINE_CALL_INTERFACE_DESCRIPTOR(Store);
2840 DEFINE_PLATFORM_CODE_STUB(StoreElement, PlatformCodeStub);
2844 class ToBooleanStub: public HydrogenCodeStub {
2860 RESULT_AS_SMI, // For Smi(1) on truthy value, Smi(0) otherwise.
2861 RESULT_AS_ODDBALL, // For {true} on truthy value, {false} otherwise.
2862 RESULT_AS_INVERSE_ODDBALL // For {false} on truthy value, {true} otherwise.
2865 // At most 16 different types can be distinguished, because the Code object
2866 // only has room for two bytes to hold a set of these types. :-P
2867 STATIC_ASSERT(NUMBER_OF_TYPES <= 16);
2869 class Types : public EnumSet<Type, uint16_t> {
2871 Types() : EnumSet<Type, uint16_t>(0) {}
2872 explicit Types(uint16_t bits) : EnumSet<Type, uint16_t>(bits) {}
2874 bool UpdateStatus(Handle<Object> object);
2875 bool NeedsMap() const;
2876 bool CanBeUndetectable() const;
2877 bool IsGeneric() const { return ToIntegral() == Generic().ToIntegral(); }
2879 static Types Generic() { return Types((1 << NUMBER_OF_TYPES) - 1); }
2882 ToBooleanStub(Isolate* isolate, ResultMode mode, Types types = Types())
2883 : HydrogenCodeStub(isolate) {
2884 set_sub_minor_key(TypesBits::encode(types.ToIntegral()) |
2885 ResultModeBits::encode(mode));
2888 ToBooleanStub(Isolate* isolate, ExtraICState state)
2889 : HydrogenCodeStub(isolate) {
2890 set_sub_minor_key(TypesBits::encode(static_cast<uint16_t>(state)) |
2891 ResultModeBits::encode(RESULT_AS_SMI));
2894 bool UpdateStatus(Handle<Object> object);
2895 Types types() const { return Types(TypesBits::decode(sub_minor_key())); }
2896 ResultMode mode() const { return ResultModeBits::decode(sub_minor_key()); }
2898 Code::Kind GetCodeKind() const override { return Code::TO_BOOLEAN_IC; }
2899 void PrintState(std::ostream& os) const override; // NOLINT
2901 bool SometimesSetsUpAFrame() override { return false; }
2903 static Handle<Code> GetUninitialized(Isolate* isolate) {
2904 return ToBooleanStub(isolate, UNINITIALIZED).GetCode();
2907 ExtraICState GetExtraICState() const override { return types().ToIntegral(); }
2909 InlineCacheState GetICState() const override {
2910 if (types().IsEmpty()) {
2911 return ::v8::internal::UNINITIALIZED;
2918 ToBooleanStub(Isolate* isolate, InitializationState init_state)
2919 : HydrogenCodeStub(isolate, init_state) {
2920 set_sub_minor_key(ResultModeBits::encode(RESULT_AS_SMI));
2923 class TypesBits : public BitField<uint16_t, 0, NUMBER_OF_TYPES> {};
2924 class ResultModeBits : public BitField<ResultMode, NUMBER_OF_TYPES, 2> {};
2926 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToBoolean);
2927 DEFINE_HYDROGEN_CODE_STUB(ToBoolean, HydrogenCodeStub);
2931 std::ostream& operator<<(std::ostream& os, const ToBooleanStub::Types& t);
2934 class ElementsTransitionAndStoreStub : public HydrogenCodeStub {
2936 ElementsTransitionAndStoreStub(Isolate* isolate, ElementsKind from_kind,
2937 ElementsKind to_kind, bool is_jsarray,
2938 KeyedAccessStoreMode store_mode)
2939 : HydrogenCodeStub(isolate) {
2940 set_sub_minor_key(FromBits::encode(from_kind) | ToBits::encode(to_kind) |
2941 IsJSArrayBits::encode(is_jsarray) |
2942 StoreModeBits::encode(store_mode));
2945 ElementsKind from_kind() const { return FromBits::decode(sub_minor_key()); }
2946 ElementsKind to_kind() const { return ToBits::decode(sub_minor_key()); }
2947 bool is_jsarray() const { return IsJSArrayBits::decode(sub_minor_key()); }
2948 KeyedAccessStoreMode store_mode() const {
2949 return StoreModeBits::decode(sub_minor_key());
2953 class FromBits : public BitField<ElementsKind, 0, 8> {};
2954 class ToBits : public BitField<ElementsKind, 8, 8> {};
2955 class IsJSArrayBits : public BitField<bool, 16, 1> {};
2956 class StoreModeBits : public BitField<KeyedAccessStoreMode, 17, 4> {};
2958 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreTransition);
2959 DEFINE_HYDROGEN_CODE_STUB(ElementsTransitionAndStore, HydrogenCodeStub);
2963 class StoreArrayLiteralElementStub : public PlatformCodeStub {
2965 explicit StoreArrayLiteralElementStub(Isolate* isolate)
2966 : PlatformCodeStub(isolate) { }
2968 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreArrayLiteralElement);
2969 DEFINE_PLATFORM_CODE_STUB(StoreArrayLiteralElement, PlatformCodeStub);
2973 class StubFailureTrampolineStub : public PlatformCodeStub {
2975 StubFailureTrampolineStub(Isolate* isolate, StubFunctionMode function_mode)
2976 : PlatformCodeStub(isolate) {
2977 minor_key_ = FunctionModeField::encode(function_mode);
2980 static void GenerateAheadOfTime(Isolate* isolate);
2983 StubFunctionMode function_mode() const {
2984 return FunctionModeField::decode(minor_key_);
2987 class FunctionModeField : public BitField<StubFunctionMode, 0, 1> {};
2989 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2990 DEFINE_PLATFORM_CODE_STUB(StubFailureTrampoline, PlatformCodeStub);
2994 class ProfileEntryHookStub : public PlatformCodeStub {
2996 explicit ProfileEntryHookStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
2998 // The profile entry hook function is not allowed to cause a GC.
2999 bool SometimesSetsUpAFrame() override { return false; }
3001 // Generates a call to the entry hook if it's enabled.
3002 static void MaybeCallEntryHook(MacroAssembler* masm);
3005 static void EntryHookTrampoline(intptr_t function,
3006 intptr_t stack_pointer,
3009 // ProfileEntryHookStub is called at the start of a function, so it has the
3010 // same register set.
3011 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction)
3012 DEFINE_PLATFORM_CODE_STUB(ProfileEntryHook, PlatformCodeStub);
3016 class StoreBufferOverflowStub : public PlatformCodeStub {
3018 StoreBufferOverflowStub(Isolate* isolate, SaveFPRegsMode save_fp)
3019 : PlatformCodeStub(isolate) {
3020 minor_key_ = SaveDoublesBits::encode(save_fp == kSaveFPRegs);
3023 static void GenerateFixedRegStubsAheadOfTime(Isolate* isolate);
3024 bool SometimesSetsUpAFrame() override { return false; }
3027 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
3029 class SaveDoublesBits : public BitField<bool, 0, 1> {};
3031 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
3032 DEFINE_PLATFORM_CODE_STUB(StoreBufferOverflow, PlatformCodeStub);
3036 class SubStringStub : public PlatformCodeStub {
3038 explicit SubStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3040 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
3041 DEFINE_PLATFORM_CODE_STUB(SubString, PlatformCodeStub);
3045 class ToNumberStub final : public PlatformCodeStub {
3047 explicit ToNumberStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3049 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToNumber);
3050 DEFINE_PLATFORM_CODE_STUB(ToNumber, PlatformCodeStub);
3054 class ToObjectStub final : public HydrogenCodeStub {
3056 explicit ToObjectStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
3058 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToObject);
3059 DEFINE_HYDROGEN_CODE_STUB(ToObject, HydrogenCodeStub);
3063 class StringCompareStub : public PlatformCodeStub {
3065 explicit StringCompareStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3067 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
3068 DEFINE_PLATFORM_CODE_STUB(StringCompare, PlatformCodeStub);
3072 #undef DEFINE_CALL_INTERFACE_DESCRIPTOR
3073 #undef DEFINE_PLATFORM_CODE_STUB
3074 #undef DEFINE_HANDLER_CODE_STUB
3075 #undef DEFINE_HYDROGEN_CODE_STUB
3076 #undef DEFINE_CODE_STUB
3077 #undef DEFINE_CODE_STUB_BASE
3079 extern Representation RepresentationFromType(Type* type);
3080 } } // namespace v8::internal
3082 #endif // V8_CODE_STUBS_H_