forked from v8/v8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-stubs.h
More file actions
3089 lines (2347 loc) · 98 KB
/
code-stubs.h
File metadata and controls
3089 lines (2347 loc) · 98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_CODE_STUBS_H_
#define V8_CODE_STUBS_H_
#include "src/allocation.h"
#include "src/assembler.h"
#include "src/codegen.h"
#include "src/globals.h"
#include "src/ic/ic-state.h"
#include "src/interface-descriptors.h"
#include "src/macro-assembler.h"
#include "src/ostreams.h"
namespace v8 {
namespace internal {
// List of code stubs used on all platforms.
#define CODE_STUB_LIST_ALL_PLATFORMS(V) \
/* PlatformCodeStubs */ \
V(ArgumentsAccess) \
V(ArrayConstructor) \
V(BinaryOpICWithAllocationSite) \
V(CallApiFunction) \
V(CallApiAccessor) \
V(CallApiGetter) \
V(CallConstruct) \
V(CallFunction) \
V(CallIC) \
V(CEntry) \
V(CompareIC) \
V(DoubleToI) \
V(FunctionPrototype) \
V(InstanceOf) \
V(InternalArrayConstructor) \
V(JSEntry) \
V(KeyedLoadICTrampoline) \
V(LoadICTrampoline) \
V(CallICTrampoline) \
V(LoadIndexedInterceptor) \
V(LoadIndexedString) \
V(MathPow) \
V(ProfileEntryHook) \
V(RecordWrite) \
V(RegExpExec) \
V(StoreArrayLiteralElement) \
V(StoreBufferOverflow) \
V(StoreElement) \
V(StringCompare) \
V(StubFailureTrampoline) \
V(SubString) \
V(ToNumber) \
V(ToString) \
V(ToObject) \
V(VectorStoreICTrampoline) \
V(VectorKeyedStoreICTrampoline) \
V(VectorStoreIC) \
V(VectorKeyedStoreIC) \
/* HydrogenCodeStubs */ \
V(AllocateHeapNumber) \
V(ArrayNArgumentsConstructor) \
V(ArrayNoArgumentConstructor) \
V(ArraySingleArgumentConstructor) \
V(BinaryOpIC) \
V(BinaryOpWithAllocationSite) \
V(CompareNilIC) \
V(CreateAllocationSite) \
V(CreateWeakCell) \
V(ElementsTransitionAndStore) \
V(FastCloneShallowArray) \
V(FastCloneShallowObject) \
V(FastNewClosure) \
V(FastNewContext) \
V(GrowArrayElements) \
V(InternalArrayNArgumentsConstructor) \
V(InternalArrayNoArgumentConstructor) \
V(InternalArraySingleArgumentConstructor) \
V(KeyedLoadGeneric) \
V(LoadGlobalViaContext) \
V(LoadScriptContextField) \
V(LoadDictionaryElement) \
V(NameDictionaryLookup) \
V(NumberToString) \
V(Typeof) \
V(RegExpConstructResult) \
V(StoreFastElement) \
V(StoreGlobalViaContext) \
V(StoreScriptContextField) \
V(StringAdd) \
V(ToBoolean) \
V(TransitionElementsKind) \
V(KeyedLoadIC) \
V(LoadIC) \
/* TurboFanCodeStubs */ \
V(StringLengthTF) \
V(StringAddTF) \
/* TurboFanICs */ \
V(MathFloor) \
/* IC Handler stubs */ \
V(ArrayBufferViewLoadField) \
V(LoadConstant) \
V(LoadFastElement) \
V(LoadField) \
V(KeyedLoadSloppyArguments) \
V(KeyedStoreSloppyArguments) \
V(StoreField) \
V(StoreGlobal) \
V(StoreTransition) \
V(StringLength)
// List of code stubs only used on ARM 32 bits platforms.
#if V8_TARGET_ARCH_ARM
#define CODE_STUB_LIST_ARM(V) V(DirectCEntry)
#else
#define CODE_STUB_LIST_ARM(V)
#endif
// List of code stubs only used on ARM 64 bits platforms.
#if V8_TARGET_ARCH_ARM64
#define CODE_STUB_LIST_ARM64(V) \
V(DirectCEntry) \
V(RestoreRegistersState) \
V(StoreRegistersState)
#else
#define CODE_STUB_LIST_ARM64(V)
#endif
// List of code stubs only used on PPC platforms.
#ifdef V8_TARGET_ARCH_PPC
#define CODE_STUB_LIST_PPC(V) \
V(DirectCEntry) \
V(StoreRegistersState) \
V(RestoreRegistersState)
#else
#define CODE_STUB_LIST_PPC(V)
#endif
// List of code stubs only used on MIPS platforms.
#if V8_TARGET_ARCH_MIPS
#define CODE_STUB_LIST_MIPS(V) \
V(DirectCEntry) \
V(RestoreRegistersState) \
V(StoreRegistersState)
#elif V8_TARGET_ARCH_MIPS64
#define CODE_STUB_LIST_MIPS(V) \
V(DirectCEntry) \
V(RestoreRegistersState) \
V(StoreRegistersState)
#else
#define CODE_STUB_LIST_MIPS(V)
#endif
// Combined list of code stubs.
#define CODE_STUB_LIST(V) \
CODE_STUB_LIST_ALL_PLATFORMS(V) \
CODE_STUB_LIST_ARM(V) \
CODE_STUB_LIST_ARM64(V) \
CODE_STUB_LIST_PPC(V) \
CODE_STUB_LIST_MIPS(V)
static const int kHasReturnedMinusZeroSentinel = 1;
// Stub is base classes of all stubs.
class CodeStub BASE_EMBEDDED {
public:
enum Major {
// TODO(mvstanton): eliminate the NoCache key by getting rid
// of the non-monomorphic-cache.
NoCache = 0, // marker for stubs that do custom caching]
#define DEF_ENUM(name) name,
CODE_STUB_LIST(DEF_ENUM)
#undef DEF_ENUM
NUMBER_OF_IDS
};
// Retrieve the code for the stub. Generate the code if needed.
Handle<Code> GetCode();
// Retrieve the code for the stub, make and return a copy of the code.
Handle<Code> GetCodeCopy(const Code::FindAndReplacePattern& pattern);
static Major MajorKeyFromKey(uint32_t key) {
return static_cast<Major>(MajorKeyBits::decode(key));
}
static uint32_t MinorKeyFromKey(uint32_t key) {
return MinorKeyBits::decode(key);
}
// Gets the major key from a code object that is a code stub or binary op IC.
static Major GetMajorKey(Code* code_stub) {
return MajorKeyFromKey(code_stub->stub_key());
}
static uint32_t NoCacheKey() { return MajorKeyBits::encode(NoCache); }
static const char* MajorName(Major major_key);
explicit CodeStub(Isolate* isolate) : minor_key_(0), isolate_(isolate) {}
virtual ~CodeStub() {}
static void GenerateStubsAheadOfTime(Isolate* isolate);
static void GenerateFPStubs(Isolate* isolate);
// Some stubs put untagged junk on the stack that cannot be scanned by the
// GC. This means that we must be statically sure that no GC can occur while
// they are running. If that is the case they should override this to return
// true, which will cause an assertion if we try to call something that can
// GC or if we try to put a stack frame on top of the junk, which would not
// result in a traversable stack.
virtual bool SometimesSetsUpAFrame() { return true; }
// Lookup the code in the (possibly custom) cache.
bool FindCodeInCache(Code** code_out);
virtual CallInterfaceDescriptor GetCallInterfaceDescriptor() const = 0;
virtual int GetStackParameterCount() const {
return GetCallInterfaceDescriptor().GetStackParameterCount();
}
virtual void InitializeDescriptor(CodeStubDescriptor* descriptor) {}
static void InitializeDescriptor(Isolate* isolate, uint32_t key,
CodeStubDescriptor* desc);
static MaybeHandle<Code> GetCode(Isolate* isolate, uint32_t key);
// Returns information for computing the number key.
virtual Major MajorKey() const = 0;
uint32_t MinorKey() const { return minor_key_; }
// BinaryOpStub needs to override this.
virtual Code::Kind GetCodeKind() const;
virtual InlineCacheState GetICState() const { return UNINITIALIZED; }
virtual ExtraICState GetExtraICState() const { return kNoExtraICState; }
virtual Code::StubType GetStubType() const { return Code::NORMAL; }
friend std::ostream& operator<<(std::ostream& os, const CodeStub& s) {
s.PrintName(os);
return os;
}
Isolate* isolate() const { return isolate_; }
protected:
CodeStub(uint32_t key, Isolate* isolate)
: minor_key_(MinorKeyFromKey(key)), isolate_(isolate) {}
// Generates the assembler code for the stub.
virtual Handle<Code> GenerateCode() = 0;
// Returns whether the code generated for this stub needs to be allocated as
// a fixed (non-moveable) code object.
virtual bool NeedsImmovableCode() { return false; }
virtual void PrintName(std::ostream& os) const; // NOLINT
virtual void PrintBaseName(std::ostream& os) const; // NOLINT
virtual void PrintState(std::ostream& os) const { ; } // NOLINT
// Computes the key based on major and minor.
uint32_t GetKey() {
DCHECK(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
return MinorKeyBits::encode(MinorKey()) | MajorKeyBits::encode(MajorKey());
}
uint32_t minor_key_;
private:
// Perform bookkeeping required after code generation when stub code is
// initially generated.
void RecordCodeGeneration(Handle<Code> code);
// Finish the code object after it has been generated.
virtual void FinishCode(Handle<Code> code) { }
// Activate newly generated stub. Is called after
// registering stub in the stub cache.
virtual void Activate(Code* code) { }
// Add the code to a specialized cache, specific to an individual
// stub type. Please note, this method must add the code object to a
// roots object, otherwise we will remove the code during GC.
virtual void AddToSpecialCache(Handle<Code> new_object) { }
// Find code in a specialized cache, work is delegated to the specific stub.
virtual bool FindCodeInSpecialCache(Code** code_out) {
return false;
}
// If a stub uses a special cache override this.
virtual bool UseSpecialCache() { return false; }
// We use this dispatch to statically instantiate the correct code stub for
// the given stub key and call the passed function with that code stub.
typedef void (*DispatchedCall)(CodeStub* stub, void** value_out);
static void Dispatch(Isolate* isolate, uint32_t key, void** value_out,
DispatchedCall call);
static void GetCodeDispatchCall(CodeStub* stub, void** value_out);
STATIC_ASSERT(NUMBER_OF_IDS < (1 << kStubMajorKeyBits));
class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {};
class MinorKeyBits: public BitField<uint32_t,
kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT
friend class BreakPointIterator;
Isolate* isolate_;
};
#define DEFINE_CODE_STUB_BASE(NAME, SUPER) \
public: \
NAME(uint32_t key, Isolate* isolate) : SUPER(key, isolate) {} \
\
private: \
DISALLOW_COPY_AND_ASSIGN(NAME)
#define DEFINE_CODE_STUB(NAME, SUPER) \
protected: \
inline Major MajorKey() const override { return NAME; }; \
DEFINE_CODE_STUB_BASE(NAME##Stub, SUPER)
#define DEFINE_PLATFORM_CODE_STUB(NAME, SUPER) \
private: \
void Generate(MacroAssembler* masm) override; \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_HYDROGEN_CODE_STUB(NAME, SUPER) \
public: \
void InitializeDescriptor(CodeStubDescriptor* descriptor) override; \
Handle<Code> GenerateCode() override; \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_TURBOFAN_CODE_STUB(NAME, SUPER) \
public: \
CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
return DESC##Descriptor(isolate()); \
}; \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_TURBOFAN_IC(NAME, SUPER, DESC) \
public: \
CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
if (GetCallMode() == CALL_FROM_OPTIMIZED_CODE) { \
return DESC##CallFromOptimizedCodeDescriptor(isolate()); \
} else { \
return DESC##CallFromUnoptimizedCodeDescriptor(isolate()); \
} \
}; \
\
protected: \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \
public: \
Handle<Code> GenerateCode() override; \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_CALL_INTERFACE_DESCRIPTOR(NAME) \
public: \
CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
return NAME##Descriptor(isolate()); \
}
// There are some code stubs we just can't describe right now with a
// CallInterfaceDescriptor. Isolate behavior for those cases with this macro.
// An attempt to retrieve a descriptor will fail.
#define DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR() \
public: \
CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
UNREACHABLE(); \
return CallInterfaceDescriptor(); \
}
class PlatformCodeStub : public CodeStub {
public:
// Retrieve the code for the stub. Generate the code if needed.
Handle<Code> GenerateCode() override;
protected:
explicit PlatformCodeStub(Isolate* isolate) : CodeStub(isolate) {}
// Generates the assembler code for the stub.
virtual void Generate(MacroAssembler* masm) = 0;
DEFINE_CODE_STUB_BASE(PlatformCodeStub, CodeStub);
};
enum StubFunctionMode { NOT_JS_FUNCTION_STUB_MODE, JS_FUNCTION_STUB_MODE };
class CodeStubDescriptor {
public:
explicit CodeStubDescriptor(CodeStub* stub);
CodeStubDescriptor(Isolate* isolate, uint32_t stub_key);
void Initialize(Address deoptimization_handler = NULL,
int hint_stack_parameter_count = -1,
StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
void Initialize(Register stack_parameter_count,
Address deoptimization_handler = NULL,
int hint_stack_parameter_count = -1,
StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
void SetMissHandler(ExternalReference handler) {
miss_handler_ = handler;
has_miss_handler_ = true;
// Our miss handler infrastructure doesn't currently support
// variable stack parameter counts.
DCHECK(!stack_parameter_count_.is_valid());
}
void set_call_descriptor(CallInterfaceDescriptor d) { call_descriptor_ = d; }
CallInterfaceDescriptor call_descriptor() const { return call_descriptor_; }
int GetRegisterParameterCount() const {
return call_descriptor().GetRegisterParameterCount();
}
int GetStackParameterCount() const {
return call_descriptor().GetStackParameterCount();
}
int GetParameterCount() const {
return call_descriptor().GetParameterCount();
}
Register GetRegisterParameter(int index) const {
return call_descriptor().GetRegisterParameter(index);
}
Type* GetParameterType(int index) const {
return call_descriptor().GetParameterType(index);
}
ExternalReference miss_handler() const {
DCHECK(has_miss_handler_);
return miss_handler_;
}
bool has_miss_handler() const {
return has_miss_handler_;
}
int GetHandlerParameterCount() const {
int params = GetParameterCount();
if (PassesArgumentsToDeoptimizationHandler()) {
params += 1;
}
return params;
}
int hint_stack_parameter_count() const { return hint_stack_parameter_count_; }
Register stack_parameter_count() const { return stack_parameter_count_; }
StubFunctionMode function_mode() const { return function_mode_; }
Address deoptimization_handler() const { return deoptimization_handler_; }
private:
bool PassesArgumentsToDeoptimizationHandler() const {
return stack_parameter_count_.is_valid();
}
CallInterfaceDescriptor call_descriptor_;
Register stack_parameter_count_;
// If hint_stack_parameter_count_ > 0, the code stub can optimize the
// return sequence. Default value is -1, which means it is ignored.
int hint_stack_parameter_count_;
StubFunctionMode function_mode_;
Address deoptimization_handler_;
ExternalReference miss_handler_;
bool has_miss_handler_;
};
class HydrogenCodeStub : public CodeStub {
public:
enum InitializationState {
UNINITIALIZED,
INITIALIZED
};
template<class SubClass>
static Handle<Code> GetUninitialized(Isolate* isolate) {
SubClass::GenerateAheadOfTime(isolate);
return SubClass().GetCode(isolate);
}
// Retrieve the code for the stub. Generate the code if needed.
Handle<Code> GenerateCode() override = 0;
bool IsUninitialized() const { return IsMissBits::decode(minor_key_); }
Handle<Code> GenerateLightweightMissCode(ExternalReference miss);
template<class StateType>
void TraceTransition(StateType from, StateType to);
protected:
explicit HydrogenCodeStub(Isolate* isolate,
InitializationState state = INITIALIZED)
: CodeStub(isolate) {
minor_key_ = IsMissBits::encode(state == UNINITIALIZED);
}
void set_sub_minor_key(uint32_t key) {
minor_key_ = SubMinorKeyBits::update(minor_key_, key);
}
uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
private:
class IsMissBits : public BitField<bool, kSubMinorKeyBits, 1> {};
class SubMinorKeyBits : public BitField<int, 0, kSubMinorKeyBits> {};
void GenerateLightweightMiss(MacroAssembler* masm, ExternalReference miss);
DEFINE_CODE_STUB_BASE(HydrogenCodeStub, CodeStub);
};
class TurboFanCodeStub : public CodeStub {
public:
// Retrieve the code for the stub. Generate the code if needed.
Handle<Code> GenerateCode() override;
virtual int GetStackParameterCount() const override {
return GetCallInterfaceDescriptor().GetStackParameterCount();
}
Code::StubType GetStubType() const override { return Code::FAST; }
protected:
explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {}
private:
DEFINE_CODE_STUB_BASE(TurboFanCodeStub, CodeStub);
};
class TurboFanIC : public TurboFanCodeStub {
public:
enum CallMode { CALL_FROM_UNOPTIMIZED_CODE, CALL_FROM_OPTIMIZED_CODE };
protected:
explicit TurboFanIC(Isolate* isolate, CallMode mode)
: TurboFanCodeStub(isolate) {
minor_key_ = CallModeBits::encode(mode);
}
CallMode GetCallMode() const { return CallModeBits::decode(minor_key_); }
void set_sub_minor_key(uint32_t key) {
minor_key_ = SubMinorKeyBits::update(minor_key_, key);
}
uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
private:
class CallModeBits : public BitField<CallMode, 0, 1> {};
class SubMinorKeyBits : public BitField<int, 1, kSubMinorKeyBits> {};
DEFINE_CODE_STUB_BASE(TurboFanIC, TurboFanCodeStub);
};
// Helper interface to prepare to/restore after making runtime calls.
class RuntimeCallHelper {
public:
virtual ~RuntimeCallHelper() {}
virtual void BeforeCall(MacroAssembler* masm) const = 0;
virtual void AfterCall(MacroAssembler* masm) const = 0;
protected:
RuntimeCallHelper() {}
private:
DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper);
};
} } // namespace v8::internal
#if V8_TARGET_ARCH_IA32
#include "src/ia32/code-stubs-ia32.h"
#elif V8_TARGET_ARCH_X64
#include "src/x64/code-stubs-x64.h"
#elif V8_TARGET_ARCH_ARM64
#include "src/arm64/code-stubs-arm64.h"
#elif V8_TARGET_ARCH_ARM
#include "src/arm/code-stubs-arm.h"
#elif V8_TARGET_ARCH_PPC
#include "src/ppc/code-stubs-ppc.h"
#elif V8_TARGET_ARCH_MIPS
#include "src/mips/code-stubs-mips.h"
#elif V8_TARGET_ARCH_MIPS64
#include "src/mips64/code-stubs-mips64.h"
#elif V8_TARGET_ARCH_X87
#include "src/x87/code-stubs-x87.h"
#else
#error Unsupported target architecture.
#endif
namespace v8 {
namespace internal {
// RuntimeCallHelper implementation used in stubs: enters/leaves a
// newly created internal frame before/after the runtime call.
class StubRuntimeCallHelper : public RuntimeCallHelper {
public:
StubRuntimeCallHelper() {}
virtual void BeforeCall(MacroAssembler* masm) const;
virtual void AfterCall(MacroAssembler* masm) const;
};
// Trivial RuntimeCallHelper implementation.
class NopRuntimeCallHelper : public RuntimeCallHelper {
public:
NopRuntimeCallHelper() {}
virtual void BeforeCall(MacroAssembler* masm) const {}
virtual void AfterCall(MacroAssembler* masm) const {}
};
class MathFloorStub : public TurboFanIC {
public:
explicit MathFloorStub(Isolate* isolate, TurboFanIC::CallMode mode)
: TurboFanIC(isolate, mode) {}
Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
DEFINE_TURBOFAN_IC(MathFloor, TurboFanIC, MathRoundVariant);
};
class StringLengthTFStub : public TurboFanCodeStub {
public:
explicit StringLengthTFStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
Code::Kind GetCodeKind() const override { return Code::HANDLER; }
InlineCacheState GetICState() const override { return MONOMORPHIC; }
ExtraICState GetExtraICState() const override { return Code::LOAD_IC; }
DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
DEFINE_CODE_STUB(StringLengthTF, TurboFanCodeStub);
};
enum StringAddFlags {
// Omit both parameter checks.
STRING_ADD_CHECK_NONE = 0,
// Check left parameter.
STRING_ADD_CHECK_LEFT = 1 << 0,
// Check right parameter.
STRING_ADD_CHECK_RIGHT = 1 << 1,
// Check both parameters.
STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT,
// Convert parameters when check fails (instead of throwing an exception).
STRING_ADD_CONVERT = 1 << 2,
STRING_ADD_CONVERT_LEFT = STRING_ADD_CHECK_LEFT | STRING_ADD_CONVERT,
STRING_ADD_CONVERT_RIGHT = STRING_ADD_CHECK_RIGHT | STRING_ADD_CONVERT
};
std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags);
class StringAddTFStub : public TurboFanCodeStub {
public:
StringAddTFStub(Isolate* isolate, StringAddFlags flags,
PretenureFlag pretenure_flag)
: TurboFanCodeStub(isolate) {
minor_key_ = StringAddFlagsBits::encode(flags) |
PretenureFlagBits::encode(pretenure_flag);
}
StringAddFlags flags() const {
return StringAddFlagsBits::decode(MinorKey());
}
PretenureFlag pretenure_flag() const {
return PretenureFlagBits::decode(MinorKey());
}
private:
class StringAddFlagsBits : public BitField<StringAddFlags, 0, 3> {};
class PretenureFlagBits : public BitField<PretenureFlag, 3, 1> {};
void PrintBaseName(std::ostream& os) const override; // NOLINT
DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
DEFINE_CODE_STUB(StringAddTF, TurboFanCodeStub);
};
class NumberToStringStub final : public HydrogenCodeStub {
public:
explicit NumberToStringStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
// Parameters accessed via CodeStubGraphBuilder::GetParameter()
static const int kNumber = 0;
DEFINE_CALL_INTERFACE_DESCRIPTOR(NumberToString);
DEFINE_HYDROGEN_CODE_STUB(NumberToString, HydrogenCodeStub);
};
class TypeofStub final : public HydrogenCodeStub {
public:
explicit TypeofStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
// Parameters accessed via CodeStubGraphBuilder::GetParameter()
static const int kObject = 0;
static void GenerateAheadOfTime(Isolate* isolate);
DEFINE_CALL_INTERFACE_DESCRIPTOR(Typeof);
DEFINE_HYDROGEN_CODE_STUB(Typeof, HydrogenCodeStub);
};
class FastNewClosureStub : public HydrogenCodeStub {
public:
FastNewClosureStub(Isolate* isolate, LanguageMode language_mode,
FunctionKind kind)
: HydrogenCodeStub(isolate) {
DCHECK(IsValidFunctionKind(kind));
set_sub_minor_key(LanguageModeBits::encode(language_mode) |
FunctionKindBits::encode(kind));
}
LanguageMode language_mode() const {
return LanguageModeBits::decode(sub_minor_key());
}
FunctionKind kind() const {
return FunctionKindBits::decode(sub_minor_key());
}
private:
STATIC_ASSERT(LANGUAGE_END == 3);
class LanguageModeBits : public BitField<LanguageMode, 0, 2> {};
class FunctionKindBits : public BitField<FunctionKind, 2, 8> {};
DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewClosure);
DEFINE_HYDROGEN_CODE_STUB(FastNewClosure, HydrogenCodeStub);
};
class FastNewContextStub final : public HydrogenCodeStub {
public:
static const int kMaximumSlots = 64;
FastNewContextStub(Isolate* isolate, int slots) : HydrogenCodeStub(isolate) {
DCHECK(slots >= 0 && slots <= kMaximumSlots);
set_sub_minor_key(SlotsBits::encode(slots));
}
int slots() const { return SlotsBits::decode(sub_minor_key()); }
// Parameters accessed via CodeStubGraphBuilder::GetParameter()
static const int kFunction = 0;
private:
class SlotsBits : public BitField<int, 0, 8> {};
DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewContext);
DEFINE_HYDROGEN_CODE_STUB(FastNewContext, HydrogenCodeStub);
};
class FastCloneShallowArrayStub : public HydrogenCodeStub {
public:
FastCloneShallowArrayStub(Isolate* isolate,
AllocationSiteMode allocation_site_mode)
: HydrogenCodeStub(isolate) {
set_sub_minor_key(AllocationSiteModeBits::encode(allocation_site_mode));
}
AllocationSiteMode allocation_site_mode() const {
return AllocationSiteModeBits::decode(sub_minor_key());
}
private:
class AllocationSiteModeBits: public BitField<AllocationSiteMode, 0, 1> {};
DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowArray);
DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowArray, HydrogenCodeStub);
};
class FastCloneShallowObjectStub : public HydrogenCodeStub {
public:
// Maximum number of properties in copied object.
static const int kMaximumClonedProperties = 6;
FastCloneShallowObjectStub(Isolate* isolate, int length)
: HydrogenCodeStub(isolate) {
DCHECK_GE(length, 0);
DCHECK_LE(length, kMaximumClonedProperties);
set_sub_minor_key(LengthBits::encode(length));
}
int length() const { return LengthBits::decode(sub_minor_key()); }
private:
class LengthBits : public BitField<int, 0, 4> {};
DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowObject);
DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowObject, HydrogenCodeStub);
};
class CreateAllocationSiteStub : public HydrogenCodeStub {
public:
explicit CreateAllocationSiteStub(Isolate* isolate)
: HydrogenCodeStub(isolate) { }
static void GenerateAheadOfTime(Isolate* isolate);
DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateAllocationSite);
DEFINE_HYDROGEN_CODE_STUB(CreateAllocationSite, HydrogenCodeStub);
};
class CreateWeakCellStub : public HydrogenCodeStub {
public:
explicit CreateWeakCellStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
static void GenerateAheadOfTime(Isolate* isolate);
DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateWeakCell);
DEFINE_HYDROGEN_CODE_STUB(CreateWeakCell, HydrogenCodeStub);
};
class GrowArrayElementsStub : public HydrogenCodeStub {
public:
GrowArrayElementsStub(Isolate* isolate, bool is_js_array, ElementsKind kind)
: HydrogenCodeStub(isolate) {
set_sub_minor_key(ElementsKindBits::encode(kind) |
IsJsArrayBits::encode(is_js_array));
}
ElementsKind elements_kind() const {
return ElementsKindBits::decode(sub_minor_key());
}
bool is_js_array() const { return IsJsArrayBits::decode(sub_minor_key()); }
private:
class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
class IsJsArrayBits : public BitField<bool, ElementsKindBits::kNext, 1> {};
DEFINE_CALL_INTERFACE_DESCRIPTOR(GrowArrayElements);
DEFINE_HYDROGEN_CODE_STUB(GrowArrayElements, HydrogenCodeStub);
};
class InstanceOfStub final : public PlatformCodeStub {
public:
explicit InstanceOfStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
private:
DEFINE_CALL_INTERFACE_DESCRIPTOR(InstanceOf);
DEFINE_PLATFORM_CODE_STUB(InstanceOf, PlatformCodeStub);
};
enum AllocationSiteOverrideMode {
DONT_OVERRIDE,
DISABLE_ALLOCATION_SITES,
LAST_ALLOCATION_SITE_OVERRIDE_MODE = DISABLE_ALLOCATION_SITES
};
class ArrayConstructorStub: public PlatformCodeStub {
public:
enum ArgumentCountKey { ANY, NONE, ONE, MORE_THAN_ONE };
ArrayConstructorStub(Isolate* isolate, int argument_count);
explicit ArrayConstructorStub(Isolate* isolate);
private:
ArgumentCountKey argument_count() const {
return ArgumentCountBits::decode(minor_key_);
}
void GenerateDispatchToArrayStub(MacroAssembler* masm,
AllocationSiteOverrideMode mode);
void PrintName(std::ostream& os) const override; // NOLINT
class ArgumentCountBits : public BitField<ArgumentCountKey, 0, 2> {};
DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
DEFINE_PLATFORM_CODE_STUB(ArrayConstructor, PlatformCodeStub);
};
class InternalArrayConstructorStub: public PlatformCodeStub {
public:
explicit InternalArrayConstructorStub(Isolate* isolate);
private:
void GenerateCase(MacroAssembler* masm, ElementsKind kind);
DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
DEFINE_PLATFORM_CODE_STUB(InternalArrayConstructor, PlatformCodeStub);
};
class MathPowStub: public PlatformCodeStub {
public:
enum ExponentType { INTEGER, DOUBLE, TAGGED, ON_STACK };
MathPowStub(Isolate* isolate, ExponentType exponent_type)
: PlatformCodeStub(isolate) {
minor_key_ = ExponentTypeBits::encode(exponent_type);
}
CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
if (exponent_type() == TAGGED) {
return MathPowTaggedDescriptor(isolate());
} else if (exponent_type() == INTEGER) {
return MathPowIntegerDescriptor(isolate());
}
// A CallInterfaceDescriptor doesn't specify double registers (yet).
return ContextOnlyDescriptor(isolate());
}
private:
ExponentType exponent_type() const {
return ExponentTypeBits::decode(minor_key_);
}
class ExponentTypeBits : public BitField<ExponentType, 0, 2> {};
DEFINE_PLATFORM_CODE_STUB(MathPow, PlatformCodeStub);
};
class CallICStub: public PlatformCodeStub {
public:
CallICStub(Isolate* isolate, const CallICState& state)
: PlatformCodeStub(isolate) {
minor_key_ = state.GetExtraICState();
}
Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
InlineCacheState GetICState() const override { return DEFAULT; }
ExtraICState GetExtraICState() const final {
return static_cast<ExtraICState>(minor_key_);
}
protected:
bool CallAsMethod() const {
return state().call_type() == CallICState::METHOD;
}
int arg_count() const { return state().arg_count(); }
CallICState state() const {
return CallICState(static_cast<ExtraICState>(minor_key_));
}
// Code generation helpers.
void GenerateMiss(MacroAssembler* masm);
void HandleArrayCase(MacroAssembler* masm, Label* miss);
private:
void PrintState(std::ostream& os) const override; // NOLINT
DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedbackAndVector);
DEFINE_PLATFORM_CODE_STUB(CallIC, PlatformCodeStub);