Line data Source code
1 : // Copyright 2018 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.
4 :
5 : #ifndef V8_OBJECTS_INSTANCE_TYPE_INL_H_
6 : #define V8_OBJECTS_INSTANCE_TYPE_INL_H_
7 :
8 : #include "src/objects/map-inl.h"
9 : #include "src/utils.h"
10 :
11 : // Has to be the last include (doesn't have include guards):
12 : #include "src/objects/object-macros.h"
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 : namespace InstanceTypeChecker {
18 :
19 : // Define type checkers for classes with single instance type.
20 186705456 : INSTANCE_TYPE_CHECKERS_SINGLE(INSTANCE_TYPE_CHECKER)
21 :
22 : #define TYPED_ARRAY_INSTANCE_TYPE_CHECKER(Type, type, TYPE, ctype) \
23 : INSTANCE_TYPE_CHECKER(Fixed##Type##Array, FIXED_##TYPE##_ARRAY_TYPE)
24 : TYPED_ARRAYS(TYPED_ARRAY_INSTANCE_TYPE_CHECKER)
25 : #undef TYPED_ARRAY_INSTANCE_TYPE_CHECKER
26 :
27 : #define STRUCT_INSTANCE_TYPE_CHECKER(TYPE, Name, name) \
28 : INSTANCE_TYPE_CHECKER(Name, TYPE)
29 9032065 : STRUCT_LIST(STRUCT_INSTANCE_TYPE_CHECKER)
30 : #undef STRUCT_INSTANCE_TYPE_CHECKER
31 :
32 : // Define type checkers for classes with ranges of instance types.
33 : #define INSTANCE_TYPE_CHECKER_RANGE(type, first_instance_type, \
34 : last_instance_type) \
35 : V8_INLINE bool Is##type(InstanceType instance_type) { \
36 : return IsInRange(instance_type, first_instance_type, last_instance_type); \
37 : }
38 : INSTANCE_TYPE_CHECKERS_RANGE(INSTANCE_TYPE_CHECKER_RANGE)
39 : #undef INSTANCE_TYPE_CHECKER_RANGE
40 :
41 : V8_INLINE bool IsFixedArrayBase(InstanceType instance_type) {
42 131848763 : return IsFixedArray(instance_type) || IsFixedDoubleArray(instance_type) ||
43 131866848 : IsFixedTypedArrayBase(instance_type) || IsByteArray(instance_type) ||
44 : IsBytecodeArray(instance_type);
45 : }
46 :
47 : V8_INLINE bool IsHeapObject(InstanceType instance_type) { return true; }
48 :
49 : V8_INLINE bool IsInternalizedString(InstanceType instance_type) {
50 : STATIC_ASSERT(kNotInternalizedTag != 0);
51 188261076 : return (instance_type & (kIsNotStringMask | kIsNotInternalizedMask)) ==
52 368531 : (kStringTag | kInternalizedTag);
53 : }
54 :
55 : V8_INLINE bool IsJSObject(InstanceType instance_type) {
56 : STATIC_ASSERT(LAST_TYPE == LAST_JS_OBJECT_TYPE);
57 56336565 : return instance_type >= FIRST_JS_OBJECT_TYPE;
58 : }
59 :
60 : V8_INLINE bool IsJSReceiver(InstanceType instance_type) {
61 : STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE);
62 4808 : return instance_type >= FIRST_JS_RECEIVER_TYPE;
63 : }
64 :
65 : } // namespace InstanceTypeChecker
66 :
67 : // TODO(v8:7786): For instance types that have a single map instance on the
68 : // roots, and when that map is a embedded in the binary, compare against the map
69 : // pointer rather than looking up the instance type.
70 5088953271 : INSTANCE_TYPE_CHECKERS(TYPE_CHECKER)
71 :
72 : #define TYPED_ARRAY_TYPE_CHECKER(Type, type, TYPE, ctype) \
73 : TYPE_CHECKER(Fixed##Type##Array)
74 : TYPED_ARRAYS(TYPED_ARRAY_TYPE_CHECKER)
75 : #undef TYPED_ARRAY_TYPE_CHECKER
76 :
77 : } // namespace internal
78 : } // namespace v8
79 :
80 : #include "src/objects/object-macros-undef.h"
81 :
82 : #endif // V8_OBJECTS_INSTANCE_TYPE_INL_H_
|