• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
inobject_property_count()20   int inobject_property_count() const { return inobject_property_count_; }
instance_size()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 class V8_EXPORT_PRIVATE CompilationDependencies : public ZoneObject {
30  public:
31   CompilationDependencies(Isolate* isolate, 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   PretenureFlag 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   // Record the assumption that neither {cell}'s {CellType} changes, nor the
59   // {IsReadOnly()} flag of {cell}'s {PropertyDetails}.
60   void DependOnGlobalProperty(const PropertyCellRef& cell);
61 
62   // Record the assumption that the protector remains valid.
63   void DependOnProtector(const PropertyCellRef& cell);
64 
65   // Record the assumption that {site}'s {ElementsKind} doesn't change.
66   void DependOnElementsKind(const AllocationSiteRef& site);
67 
68   // Depend on the stability of (the maps of) all prototypes of every class in
69   // {receiver_type} up to (and including) the {holder}.
70   // TODO(neis): Fully brokerize!
71   void DependOnStablePrototypeChains(
72       JSHeapBroker* broker, Handle<Context> native_context,
73       std::vector<Handle<Map>> const& receiver_maps, Handle<JSObject> holder);
74 
75   // Like DependOnElementsKind but also applies to all nested allocation sites.
76   void DependOnElementsKinds(const AllocationSiteRef& site);
77 
78   // Predict the final instance size for {function}'s initial map and record
79   // the assumption that this prediction is correct. In addition, register
80   // the initial map dependency. This method returns the {function}'s the
81   // predicted minimum slack instance size count (wrapped together with
82   // the corresponding in-object property count for convenience).
83   SlackTrackingPrediction DependOnInitialMapInstanceSizePrediction(
84       const JSFunctionRef& function);
85 
86   // Exposed only for testing purposes.
87   bool AreValid() const;
88 
89   // Exposed only because C++.
90   class Dependency;
91 
92  private:
93   Zone* zone_;
94   ZoneForwardList<Dependency*> dependencies_;
95 };
96 
97 }  // namespace compiler
98 }  // namespace internal
99 }  // namespace v8
100 
101 #endif  // V8_COMPILER_COMPILATION_DEPENDENCIES_H_
102