blob: a40eb7480114f2b697e5ac9d1f106f31b1794425 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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_DEPENDENCIES_H_
6#define V8_DEPENDENCIES_H_
7
8#include "src/handles.h"
9#include "src/objects.h"
10
11namespace v8 {
12namespace internal {
13
14// Collects dependencies for this compilation, e.g. assumptions about
15// stable maps, constant globals, etc.
16class CompilationDependencies {
17 public:
18 CompilationDependencies(Isolate* isolate, Zone* zone)
19 : isolate_(isolate),
20 zone_(zone),
21 object_wrapper_(Handle<Foreign>::null()),
22 aborted_(false) {
23 std::fill_n(groups_, DependentCode::kGroupCount, nullptr);
24 }
25
26 void Insert(DependentCode::DependencyGroup group, Handle<HeapObject> handle);
27
28 void AssumeInitialMapCantChange(Handle<Map> map) {
29 Insert(DependentCode::kInitialMapChangedGroup, map);
30 }
31 void AssumeFieldType(Handle<Map> map) {
32 Insert(DependentCode::kFieldTypeGroup, map);
33 }
34 void AssumeMapStable(Handle<Map> map);
35 void AssumePrototypeMapsStable(
36 Handle<Map> map,
37 MaybeHandle<JSReceiver> prototype = MaybeHandle<JSReceiver>());
38 void AssumeMapNotDeprecated(Handle<Map> map);
39 void AssumePropertyCell(Handle<PropertyCell> cell) {
40 Insert(DependentCode::kPropertyCellChangedGroup, cell);
41 }
42 void AssumeTenuringDecision(Handle<AllocationSite> site) {
43 Insert(DependentCode::kAllocationSiteTenuringChangedGroup, site);
44 }
45 void AssumeTransitionStable(Handle<AllocationSite> site);
46
47 void Commit(Handle<Code> code);
48 void Rollback();
49 void Abort() { aborted_ = true; }
50 bool HasAborted() const { return aborted_; }
51
52 bool IsEmpty() const {
53 for (int i = 0; i < DependentCode::kGroupCount; i++) {
54 if (groups_[i]) return false;
55 }
56 return true;
57 }
58
59 private:
60 Isolate* isolate_;
61 Zone* zone_;
62 Handle<Foreign> object_wrapper_;
63 bool aborted_;
64 ZoneList<Handle<HeapObject> >* groups_[DependentCode::kGroupCount];
65
66 DependentCode* Get(Handle<Object> object);
67 void Set(Handle<Object> object, Handle<DependentCode> dep);
68};
69} // namespace internal
70} // namespace v8
71
72#endif // V8_DEPENDENCIES_H_