Line data Source code
1 : // Copyright 2015 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_COMPILER_COMPILATION_DEPENDENCIES_H_
6 : #define V8_COMPILER_COMPILATION_DEPENDENCIES_H_
7 :
8 : #include "src/compiler/js-heap-broker.h"
9 : #include "src/objects.h"
10 : #include "src/zone/zone-containers.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 : namespace compiler {
15 :
16 : class SlackTrackingPrediction {
17 : public:
18 : SlackTrackingPrediction(MapRef initial_map, int instance_size);
19 :
20 : int inobject_property_count() const { return inobject_property_count_; }
21 : int instance_size() const { return instance_size_; }
22 :
23 : private:
24 : int instance_size_;
25 : int inobject_property_count_;
26 : };
27 :
28 : // Collects and installs dependencies of the code that is being generated.
29 418 : class V8_EXPORT_PRIVATE CompilationDependencies : public ZoneObject {
30 : public:
31 : CompilationDependencies(JSHeapBroker* broker, Zone* zone);
32 :
33 : V8_WARN_UNUSED_RESULT bool Commit(Handle<Code> code);
34 :
35 : // Return the initial map of {function} and record the assumption that it
36 : // stays the initial map.
37 : MapRef DependOnInitialMap(const JSFunctionRef& function);
38 :
39 : // Return the "prototype" property of the given function and record the
40 : // assumption that it doesn't change.
41 : ObjectRef DependOnPrototypeProperty(const JSFunctionRef& function);
42 :
43 : // Record the assumption that {map} stays stable.
44 : void DependOnStableMap(const MapRef& map);
45 :
46 : // Record the assumption that {target_map} can be transitioned to, i.e., that
47 : // it does not become deprecated.
48 : void DependOnTransition(const MapRef& target_map);
49 :
50 : // Return the pretenure mode of {site} and record the assumption that it does
51 : // not change.
52 : AllocationType DependOnPretenureMode(const AllocationSiteRef& site);
53 :
54 : // Record the assumption that the field type of a field does not change. The
55 : // field is identified by the arguments.
56 : void DependOnFieldType(const MapRef& map, int descriptor);
57 :
58 : // Return a field's constness and, if kConst, record the assumption that it
59 : // remains kConst. The field is identified by the arguments.
60 : //
61 : // For arrays, arguments objects and value wrappers, only consider the field
62 : // kConst if the map is stable (and register stability dependency in that
63 : // case). This is to ensure that fast elements kind transitions cannot be
64 : // used to mutate fields without deoptimization of the dependent code.
65 : PropertyConstness DependOnFieldConstness(const MapRef& map, int descriptor);
66 :
67 : // Record the assumption that neither {cell}'s {CellType} changes, nor the
68 : // {IsReadOnly()} flag of {cell}'s {PropertyDetails}.
69 : void DependOnGlobalProperty(const PropertyCellRef& cell);
70 :
71 : // Return the validity of the given protector and, if true, record the
72 : // assumption that the protector remains valid.
73 : bool DependOnProtector(const PropertyCellRef& cell);
74 :
75 : // Convenience wrappers around {DependOnProtector}.
76 : bool DependOnArrayBufferDetachingProtector();
77 : bool DependOnArrayIteratorProtector();
78 : bool DependOnArraySpeciesProtector();
79 : bool DependOnNoElementsProtector();
80 : bool DependOnPromiseHookProtector();
81 : bool DependOnPromiseSpeciesProtector();
82 : bool DependOnPromiseThenProtector();
83 :
84 : // Record the assumption that {site}'s {ElementsKind} doesn't change.
85 : void DependOnElementsKind(const AllocationSiteRef& site);
86 :
87 : // Depend on the stability of (the maps of) all prototypes of every class in
88 : // {receiver_type} up to (and including) the {holder}.
89 : void DependOnStablePrototypeChains(
90 : std::vector<Handle<Map>> const& receiver_maps, const JSObjectRef& holder);
91 :
92 : // Like DependOnElementsKind but also applies to all nested allocation sites.
93 : void DependOnElementsKinds(const AllocationSiteRef& site);
94 :
95 : // Predict the final instance size for {function}'s initial map and record
96 : // the assumption that this prediction is correct. In addition, register
97 : // the initial map dependency. This method returns the {function}'s the
98 : // predicted minimum slack instance size count (wrapped together with
99 : // the corresponding in-object property count for convenience).
100 : SlackTrackingPrediction DependOnInitialMapInstanceSizePrediction(
101 : const JSFunctionRef& function);
102 :
103 : // Exposed only for testing purposes.
104 : bool AreValid() const;
105 :
106 : // Exposed only because C++.
107 : class Dependency;
108 :
109 : private:
110 : Zone* const zone_;
111 : JSHeapBroker* const broker_;
112 : ZoneForwardList<Dependency*> dependencies_;
113 : };
114 :
115 : } // namespace compiler
116 : } // namespace internal
117 : } // namespace v8
118 :
119 : #endif // V8_COMPILER_COMPILATION_DEPENDENCIES_H_
|