forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.h
More file actions
1845 lines (1548 loc) · 55.3 KB
/
Copy pathclass.h
File metadata and controls
1845 lines (1548 loc) · 55.3 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
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef incl_HPHP_VM_CLASS_H_
#define incl_HPHP_VM_CLASS_H_
#include "hphp/runtime/base/attr.h"
#include "hphp/runtime/base/datatype.h"
#include "hphp/runtime/base/rds-util.h"
#include "hphp/runtime/base/repo-auth-type.h"
#include "hphp/runtime/base/tv-layout.h"
#include "hphp/runtime/base/type-array.h"
#include "hphp/runtime/base/type-string.h"
#include "hphp/runtime/base/typed-value.h"
#include "hphp/runtime/base/atomic-countable.h"
#include "hphp/runtime/vm/containers.h"
#include "hphp/runtime/vm/fixed-string-map.h"
#include "hphp/runtime/vm/indexed-string-map.h"
#include "hphp/runtime/vm/instance-bits.h"
#include "hphp/runtime/vm/preclass.h"
#include "hphp/runtime/vm/reified-generics-info.h"
#include "hphp/util/bitset-view.h"
#include "hphp/util/compact-vector.h"
#include "hphp/util/compilation-flags.h"
#include "hphp/util/default-ptr.h"
#include "hphp/util/hash-map.h"
#include <folly/Hash.h>
#include <folly/Range.h>
#include <boost/container/flat_map.hpp>
#include <list>
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
extern const StaticString s_86cinit;
extern const StaticString s_86pinit;
extern const StaticString s_86sinit;
extern const StaticString s_86linit;
extern const StaticString s_86ctor;
extern const StaticString s_86metadata;
extern const StaticString s_86reified_prop;
extern const StaticString s_86reifiedinit;
extern const StaticString s___MockClass;
extern const StaticString s___Reified;
struct Class;
struct ClassInfo;
struct EnumValues;
struct Func;
struct StringData;
struct c_Awaitable;
namespace collections {
struct CollectionsExtension;
}
namespace Native {
struct NativeDataInfo;
struct NativePropHandler;
}
///////////////////////////////////////////////////////////////////////////////
/*
* Utility wrapper for static properties. Allows distinguishing them
* via type_scan::Index.
*/
struct StaticPropData {
TypedValue val;
};
enum class ClsCnsLookup {
NoTypes,
IncludeTypes,
IncludeTypesPartial
};
using ClassPtr = AtomicSharedLowPtr<Class>;
// Since native instance dtors can be release functions, they have to have
// compatible signatures.
using ObjReleaseFunc = BuiltinDtorFunction;
using ObjectProps = std::conditional_t<
wide_tv_val,
tv_layout::Tv7Up,
tv_layout::TvArray
>;
/*
* Class represents the full definition of a user class in a given request
* context.
*
* See PreClass for more on the distinction.
*
* The method table is allocated at negative offset from the start of the Class
* object, and the method slot is used as the negative offset from the object
* to index into the method table.
*
* +------------+
* Func Slot n (offset -(n+1)) --> | |
* ....
* | |
* +------------+
* Func Slot 1 (offset -2) ------> | |
* +------------+
* Func Slot 0 (offset -1) ------> | |
* Class* -----------------------> +------------+
* | |
* ....
* | |
* +------------+
*/
struct Class : AtomicCountable {
/////////////////////////////////////////////////////////////////////////////
// Types.
/*
* Class availability.
*
* @see: Class::avail()
*/
enum class Avail {
False,
True,
Fail
};
/*
* Attributes computed at runtime class init time, used to short
* circuit more expensive checks. Not to be confused with enum Attr,
* which are a-priori attributes computed by the compiler.
*/
enum RuntimeAttribute : uint8_t {
CallToImpl = 0x01, // call to{Boolean,Int64,Double}Impl
HasSleep = 0x02, // __sleep()
HasClone = 0x04, // defines __clone PHP method; only valid
// when !isCppBuiltin()
HasNativePropHandler = 0x08, // class has native magic props handler
};
/*
* Instance property information.
*/
using UpperBoundVec = PreClass::UpperBoundVec;
struct Prop {
const PreClass::Prop* preProp;
/*
* When built in RepoAuthoritative mode, this is a control-flow insensitive,
* always-true type assertion for this property. (It may be Gen if there
* was nothing interesting known.)
*/
RepoAuthType repoAuthType;
TypeConstraint typeConstraint;
UpperBoundVec ubs;
LowStringPtr name;
LowStringPtr mangledName;
/* Most derived class that declared this property. */
LowPtr<Class> cls;
/* Least derived class that declared this property. */
LowPtr<Class> baseCls;
Attr attrs;
/*
* Slot number that is only valid for reflection and serialization.
*/
Slot serializationIdx;
};
/*
* Static property information.
*/
struct SProp {
const PreClass::Prop* preProp;
RepoAuthType repoAuthType;
TypeConstraint typeConstraint;
UpperBoundVec ubs;
LowStringPtr name;
/* Most derived class that declared this property. */
LowPtr<Class> cls;
Attr attrs;
Slot serializationIdx;
/* Used if (cls == this). */
TypedValue val;
};
/*
* Class constant information.
*/
struct Const {
/* Most derived class that declared this constant. */
LowPtr<const Class> cls;
LowStringPtr name;
TypedValueAux val;
#ifndef USE_LOWPTR
StringData* pointedClsName;
#endif
bool isAbstract() const { return val.constModifiers().isAbstract(); }
bool isType() const { return val.constModifiers().isType(); }
StringData* getPointedClsName() const {
#ifndef USE_LOWPTR
return pointedClsName;
#else
return val.constModifiers().getPointedClsName();
#endif
}
void setPointedClsName(StringData* pClsName) {
#ifndef USE_LOWPTR
pointedClsName = pClsName;
#else
val.constModifiers().setPointedClsName(pClsName);
#endif
}
};
/*
* Initialization vector for declared properties.
*
* This is a vector which contains default values for all of a Class's
* declared instance properties. It is used when instantiating new objects
* from a Class.
*
* This vector is indexed by the physical index of the property within the
* objects (and not by its logical slot).
*/
struct PropInitVec {
PropInitVec();
~PropInitVec();
const PropInitVec& operator=(const PropInitVec&);
template <bool is_const>
struct Entry {
template <typename Dummy = void,
typename = std::enable_if_t<!is_const, Dummy>>
Entry& operator=(TypedValueAux);
operator TypedValueAux() const;
tv_val<is_const> val;
typename BitsetView<is_const>::bit_reference deepInit;
};
template <bool is_const>
struct iterator_impl {
using char_t = typename std::conditional_t<is_const,
const unsigned char,
unsigned char>;
using tv_iter_t = typename std::conditional_t<is_const,
ObjectProps::const_iterator,
ObjectProps::iterator>;
using bit_iter_t = typename BitsetView<is_const>::iterator;
iterator_impl(tv_iter_t tv, bit_iter_t bit);
bool operator==(const iterator_impl& o) const;
bool operator!=(const iterator_impl& o) const;
iterator_impl& operator++();
iterator_impl operator++(int);
Entry<is_const> operator*() const;
Entry<is_const> operator->() const;
using value_type = Entry<is_const>;
using reference = Entry<is_const>&;
using pointer = void;
using difference_type = void;
using iterator_category = std::forward_iterator_tag;
tv_iter_t m_val;
bit_iter_t m_bit;
};
using iterator = iterator_impl<false>;
using const_iterator = iterator_impl<true>;
size_t size() const;
template <typename T>
Entry<false> operator[](T i);
template <typename T>
Entry<true> operator[](T i) const;
iterator begin();
iterator end();
const_iterator cbegin() const;
const_iterator cend() const;
void push_back(const TypedValue& v);
const ObjectProps* data() const;
static constexpr size_t dataOff() {
return offsetof(PropInitVec, m_data);
}
size_t dataSize() const {
auto const cap = m_capacity < 0 ? ~m_capacity : m_capacity;
return ObjectProps::sizeFor(cap) +
BitsetView<true>::sizeFor(cap);
}
/*
* Make a request-allocated copy of `src'.
*/
static PropInitVec* allocWithReqAllocator(const PropInitVec& src);
TYPE_SCAN_CUSTOM() {
// We don't need to worry about scanning the pointer m_data itself because
// when we're heap-allocated, it always points inside of this allocation.
//
// The only time that's not the case is when we're allocated in general
// heap and we shouldn't be type-scanned under those circumstances
assertx(reqAllocated());
assertx(m_data == static_cast<const void*>(this + 1));
m_data->scan(ObjectProps::quickIndex(m_size), scanner);
}
private:
PropInitVec(const PropInitVec&);
bool reqAllocated() const;
BitsetView<false> deepInitBits();
BitsetView<true> deepInitBits() const;
ObjectProps* m_data;
uint32_t m_size;
// m_capacity > 0, allocated on global huge heap
// m_capacity = 0, not request allocated, m_data is nullptr
// m_capacity < 0, request allocated, with '~m_capacity' slots
int32_t m_capacity;
};
static_assert(sizeof(PropInitVec) <= 16, "");
/*
* A slot in a Class vtable vector, pointing to the vtable for an interface
* and the interface itself. Used for efficient interface method dispatch and
* instance checks.
*/
struct VtableVecSlot {
LowPtr<LowPtr<Func>> vtable;
LowPtr<Class> iface;
};
/*
* Container types.
*/
using MethodMap = FixedStringMap<Slot, false, Slot>;
using MethodMapBuilder = FixedStringMapBuilder<Func*, Slot, false, Slot>;
using InterfaceMap = IndexedStringMap<LowPtr<Class>, true, int>;
using RequirementMap = IndexedStringMap<
const PreClass::ClassRequirement*, true, int>;
using TraitAliasVec = vm_vector<PreClass::TraitAliasRule::NamePair>;
/*
* Map from a Closure subclass C's scope context to the appropriately scoped
* clone of C.
*
* @see: Class::ExtraData::m_scopedClones
*/
using ScopedClonesMap =
hphp_hash_map<LowPtr<Class>, ClassPtr, smart_pointer_hash<LowPtr<Class>>>;
/*
* We store the length of vectors of methods, parent classes and interfaces.
*
* In lowptr builds, we limit all of these quantities to 2^16-1 to save
* memory.
*/
using veclen_t = std::conditional<use_lowptr, uint16_t, uint32_t>::type;
/////////////////////////////////////////////////////////////////////////////
// Creation and destruction.
/*
* Allocate a new Class object.
*
* Eventually deallocated using atomicRelease(), but can go through some
* phase changes before that (see destroy()).
*/
static Class* newClass(PreClass* preClass, Class* parent);
/*
* Make a clone of this Closure subclass, with `ctx' as the closure scope.
*
* If the scoping already exists in m_extra->m_scopedClones, or if this class
* is already scoped correctly, just return it. Otherwise, we scope our own
* m_invoke if it's not already scoped, or clone ourselves and scope the
* clone's m_invoke, then add the mapping to m_scopedClones. It is required
* for correctness that all clones be added to the cache, because the cache
* participates in synchronization with instance bits initialization.
*
* Note that all scoping events via CreateCl opcodes clone from the
* "template" Closure subclass that is generated by the emitter.
*
* @requires: parent() == SystemLib::s_ClosureClass
*/
Class* rescope(Class* ctx);
/*
* Called when a Class becomes unreachable.
*
* This may happen before its refcount hits zero if it is still referred to
* by any of:
* - its NamedEntity;
* - any derived Class;
* - any Class that implements it (for interfaces); or
* - any Class that uses it (for traits)
*
* Such referring classes must also be logically dead at the time destroy()
* is called. However, since we don't have back pointers to find them,
* instead we leave the Class in a zombie state. When we try to instantiate
* one of its referrers, we will notice that it depends on a zombie and
* destroy *that*, releasing its reference to this Class.
*/
void destroy();
/*
* Called when the (atomic) refcount hits zero.
*
* The Class is completely dead at this point, and its memory is freed
* immediately.
*/
void atomicRelease();
private:
/*
* Free any references to child classes, interfaces, and traits.
*
* releaseRefs() is called when a Class is put into the zombie state. It's
* safe to call multiple times, so it is also called from the destructor (in
* case we bypassed the zombie state).
*/
void releaseRefs();
public:
/*
* Whether this class has been logically destroyed, but needed to be
* preserved due to outstanding references.
*/
bool isZombie() const;
/*
* Check whether a Class from a previous request is available to be defined.
* The caller should check that it has the same PreClass that is being
* defined. Being available means that the parent, the interfaces, and the
* traits are already defined (or become defined via autoload, if tryAutoload
* is true).
*
* @returns: Avail::True: if it's available
* Avail::Fail: if at least one of the parent, interfaces, and
* traits is not defined at all at this point
* Avail::False: if at least one of the parent, interfaces, and
* traits is defined but does not correspond to this
* particular Class*
*
* The parent parameter is used for two purposes: first, it lets us avoid
* looking up the active parent class for each potential Class*; and second,
* it is used on Fail to return the problem class so the caller can report
* the error correctly.
*/
Avail avail(Class*& parent, bool tryAutoload = false) const;
/////////////////////////////////////////////////////////////////////////////
// Pre- and post-allocations. [const]
/*
* Pointer to this Class's FuncVec, which is allocated before this.
*/
LowPtr<Func>* funcVec() const;
/*
* The start of malloc'd memory for `this' (i.e., including anything
* allocated before the object itself.).
*/
void* mallocPtr() const;
/*
* Address of the end of the Class's variable-length memory allocation.
*/
const void* mallocEnd() const;
/*
* Pointer to the array of Class pointers, allocated immediately after
* `this', which contain this class's inheritance hierarchy (including `this'
* as the last element).
*/
const LowPtr<Class>* classVec() const;
/*
* The size of the classVec.
*/
veclen_t classVecLen() const;
/////////////////////////////////////////////////////////////////////////////
// Ancestry. [const]
/*
* Determine if this represents a non-strict subtype of `cls'. The nonIFace
* variant is faster, but has the additional precondition that `cls' is not
* an interface.
*/
bool classof(const Class*) const;
bool classofNonIFace(const Class*) const;
bool subtypeOf(const Class*) const;
/*
* Whether this class implements an interface called `name'.
*/
bool ifaceofDirect(const StringData* name) const;
/*
* Assuming this and cls are both regular classes (not interfaces or traits),
* return their lowest common ancestor, or nullptr if they're unrelated.
*/
const Class* commonAncestor(const Class* cls) const;
/*
* Given that this class exists, return a class named "name" that is
* also guaranteed to exist, or nullptr if there is none.
*/
const Class* getClassDependency(const StringData* name) const;
/////////////////////////////////////////////////////////////////////////////
// Basic info. [const]
/*
* The name, PreClass, and parent class of this class.
*/
const StringData* name() const;
const PreClass* preClass() const;
Class* parent() const;
/*
* Uncounted String names of this class and of its parent.
*/
StrNR nameStr() const;
StrNR parentStr() const;
/*
* The attributes on this class.
*/
Attr attrs() const;
/*
* Runtime class attributes, computed during class initialization.
*/
bool rtAttribute(RuntimeAttribute) const;
void initRTAttributes(uint8_t);
/*
* Whether this class is uniquely named across the codebase.
*
* It's legal in PHP to define multiple classes in different pseudomains
* with the same name, so long as both are not required in the same request.
*/
bool isUnique() const;
/*
* Whether we can load this class once and persist it across requests.
*
* Persistence is possible when a Class is uniquely named and is defined in a
* pseudomain that has no side-effects (except other persistent definitions).
*
* A class which satisfies isPersistent() may not actually /be/ persistent,
* if we had to allocate its RDS handle before we loaded the class.
*
* @see: classHasPersistentRDS()
* @implies: isUnique()
*/
bool isPersistent() const;
/*
* Is this class allowed to be constructed dynamically?
*/
bool isDynamicallyConstructible() const;
/*
* If the class is called dynamically should we sample the calls?
*/
folly::Optional<int64_t> dynConstructSampleRate() const;
/////////////////////////////////////////////////////////////////////////////
// Magic methods. [const]
/*
* Get the constructor, destructor, or __toString() method on this class, or
* nullptr if no such method exists.
*
* DeclaredCtor refers to a user-declared __construct(), as opposed to the
* (shared) empty method generated by the compiler.
*/
const Func* getCtor() const;
const Func* getDeclaredCtor() const;
const Func* getToString() const;
const Func* get86pinit() const;
const Func* get86sinit() const;
const Func* get86linit() const;
/*
* Look up a class' cached __invoke function. We only cache __invoke methods
* if they are instance methods or if the class is a static closure.
*/
const Func* getCachedInvoke() const;
/////////////////////////////////////////////////////////////////////////////
// Builtin classes. [const]
/*
* Is the class a builtin, whether PHP or C++?
*/
bool isBuiltin() const;
/*
* Custom initialization and destruction routines for C++ extension classes.
*
* instanceCtor() returns true iff the class is a C++ extension class.
*/
template <bool Unlocked = false>
BuiltinCtorFunction instanceCtor() const;
BuiltinDtorFunction instanceDtor() const;
/*
* Whether this C++ extension class has opted into serialization.
*
* @requires: instanceCtor()
*/
bool isCppSerializable() const;
/*
* Whether this is a class for a Hack collection.
*/
bool isCollectionClass() const;
/////////////////////////////////////////////////////////////////////////////
// Methods.
/*
* Number of methods on this class.
*
* Note that this may differ from m_funcVecLen, since numMethods() is the
* exact number of methods, and m_funcVecLen is only required to be an upper
* bound.
*
* In particular, outside of RepoAuth mode, trait methods are not transcluded
* into the Classes which use them, and we are conservative when initially
* counting methods since we do not resolve trait precedence first.
*/
size_t numMethods() const;
/*
* Get or set a method by its index in the funcVec, which is allocated
* contiguously before `this' in memory.
*/
Func* getMethod(Slot idx) const;
void setMethod(Slot idx, Func* func);
/*
* Look up a method by name.
*
* Return null if no such method exists.
*/
Func* lookupMethod(const StringData* methName) const;
/*
* public because its used by importTraitMethod.
*/
void methodOverrideCheck(const Func* parentMethod, const Func* method);
/*
* Return an Array (via `out') of all the methods of `cls' visible in the
* context of `ctx' (which may be nullptr).
*
* The Array has the form [lowercase name => declared name], ordered with
* methods implemented by `cls' first, followed by its parents' methods, and
* so on, in declaration order for each Class in the hierarchy. Any
* unimplemented interface methods come last.
*/
static void getMethodNames(const Class* cls, const Class* ctx, Array& out);
/////////////////////////////////////////////////////////////////////////////
// Object release.
//
// Every class has a static release function responsible for destroying and
// freeing object instances of this class. This might be ObjectData::release,
// or a custom native instance dtor.
ObjReleaseFunc releaseFunc() const;
/////////////////////////////////////////////////////////////////////////////
// Property metadata. [const]
//
// Unless otherwise specified, the terms "declared instance properties" and
// "static properties" both refer to properties declared on this class as
// well as those declared on its ancestors. Note that this includes private
// properties in both cases.
/*
* Number of declared instance properties or static properties.
*/
size_t numDeclProperties() const;
size_t numStaticProperties() const;
/*
* An exclusive upper limit on the post-sort indices of properties of this
* class that may be countable. See m_countablePropsEnd for more details.
*/
ObjectProps::quick_index countablePropsEnd() const {
return m_countablePropsEnd;
}
/*
* Number of declared instance properties that are actually accessible from
* this class's context.
*
* Only really used when iterating over an object's properties.
*/
uint32_t declPropNumAccessible() const;
/*
* The info vector for declared instance properties or static properties.
*/
folly::Range<const Prop*> declProperties() const;
folly::Range<const SProp*> staticProperties() const;
/*
* Look up the index of a declared instance property or static property.
*
* Return kInvalidSlot if no such property exists.
*/
Slot lookupDeclProp(const StringData* propName) const;
Slot lookupSProp(const StringData* sPropName) const;
/*
* Returns the 86reified_init property's slot
*/
Slot lookupReifiedInitProp() const;
/*
* The RepoAuthType of the declared instance property or static property at
* `index' in the corresponding table.
*/
RepoAuthType declPropRepoAuthType(Slot index) const;
RepoAuthType staticPropRepoAuthType(Slot index) const;
const TypeConstraint& declPropTypeConstraint(Slot index) const;
const TypeConstraint& staticPropTypeConstraint(Slot index) const;
/*
* Whether this class has any properties that require deep initialization.
*
* Deep initialization means that the property cannot simply be memcpy'd when
* creating new objects.
*/
bool hasDeepInitProps() const;
/*
* Whether this class forbids the use of dynamic (non-declared) properties.
*/
bool forbidsDynamicProps() const;
/*
* Return true, and set the m_serialized flag, iff this Class hasn't
* been serialized yet (see prof-data-serialize.cpp).
*
* Not thread safe - caller is responsible for any necessary locking.
*/
bool serialize() const;
/*
* Return true if this class was already serialized.
*/
bool wasSerialized() const;
/////////////////////////////////////////////////////////////////////////////
// Property initialization. [const]
/*
* Whether this Class requires initialization, either because of nonscalar
* instance property initializers, simply due to having static properties, or
* possible property type invariance violations.
*/
bool needInitialization() const;
/*
* Whether this Class potentially has properties which redefine properties in
* a parent class, and the properties might have inequivalent type-hints. If
* so, a runtime check is needed during class initialization to possibly raise
* an error.
*/
bool maybeRedefinesPropTypes() const;
/*
* Whether this Class has properties that require a runtime initial value
* check.
*/
bool needsPropInitialValueCheck() const;
/*
* Perform request-local initialization.
*
* For declared instance properties, this means creating a request-local copy
* of this Class's PropInitVec. This is necessary in order to accommodate
* non-scalar defaults (e.g., class constants), which may not be consistent
* across requests.
*
* For static properties, this means setting up request-local memory for the
* actual static properties, if necessary, and initializing them to their
* default values.
*/
void initialize() const;
void initProps() const;
void initSProps() const;
/*
* Perform a property type-hint redefinition check for the property at a
* particular slot.
*/
void checkPropTypeRedefinition(Slot) const;
/*
* Check if class has been initialized.
*/
bool initialized() const;
/*
* PropInitVec for this class's declared properties, with default values for
* scalars only.
*
* This is the base from which the request-local copy is made.
*/
const PropInitVec& declPropInit() const;
/*
* Vector of 86pinit non-scalar instance property initializer functions.
*
* These are invoked during initProps() to populate the copied PropInitVec.
*
* This vector is indexed by the properties' logical slot number.
*/
const VMFixedVector<const Func*>& pinitVec() const;
/*
* RDS handle which marks whether a property type-hint redefinition check has
* been performed for this class in this request yet.
*/
rds::Handle checkedPropTypeRedefinesHandle() const;
/*
* RDS handle which marks whether the initial value check has been performed
* for this class in this request yet.
*/
rds::Handle checkedPropInitialValuesHandle() const;
/////////////////////////////////////////////////////////////////////////////
// Property storage. [const]
/*
* Initialize the RDS handles for the request-local PropInitVec and for the
* static properties.
*/
void initPropHandle() const;
void initSPropHandles() const;
/*
* RDS handle of the request-local PropInitVec.
*/
rds::Handle propHandle() const;
/*
* RDS handle for the static properties' is-initialized flag.
*/
rds::Handle sPropInitHandle() const;
/*
* RDS handle for the static property at `index'.
*/
rds::Handle sPropHandle(Slot index) const;
rds::Link<StaticPropData, rds::Mode::NonNormal> sPropLink(Slot index) const;
rds::Link<bool, rds::Mode::NonLocal> sPropInitLink() const;
/*
* Get the PropInitVec for the current request.
*/
PropInitVec* getPropData() const;
/*
* Get the value of the static variable at `index' for the current request.
*/
TypedValue* getSPropData(Slot index) const;
/*
* Map the logical slot of a property to its physical index within the object
* in memory.
*/
ObjectProps::quick_index propSlotToIndex(Slot slot) const {
return m_slotIndex[slot];
}
/*
* Map the physical index of a property within the object to its logical slot.
*/
Slot propIndexToSlot(uint16_t index) const;
/////////////////////////////////////////////////////////////////////////////
// Property lookup and accessibility. [const]
struct PropValLookup {
TypedValue* val;
Slot slot;
bool accessible;
bool constant;
};
struct PropSlotLookup {
Slot slot;
bool accessible;
bool constant;
};
/*
* Get the slot and accessibility of a declared instance property on a class
* from the given context.
*
* Accessibility refers to the public/protected/private attribute of the
* property.
*
* Return kInvalidInd for the property iff the property was not declared on
* this class or any ancestor. Note that if the return is marked as
* accessible, then the property must exist.
*/
PropSlotLookup getDeclPropSlot(const Class*, const StringData*) const;
/*
* The equivalent of getDeclPropSlot(), but for static properties.
*/
PropSlotLookup findSProp(const Class*, const StringData*) const;
/*
* Get the request-local value of the static property `sPropName', as well as
* its accessibility, from the given context.
*
* The behavior is identical to that of findSProp(), except substituting
* nullptr for kInvalidInd.
*
* getSProp() will throw if the property is AttrLateInit and the value is
* Uninit. getSPropIgnoreLateInit() will not.
*
* May perform initialization.
*/
PropValLookup getSProp(const Class*, const StringData*) const;
PropValLookup getSPropIgnoreLateInit(const Class*, const StringData*) const;
/*
* Return whether or not a declared instance property is accessible from the
* given context.
*/