Flutter Engine
The Flutter Engine
dispatch_table_generator.h
Go to the documentation of this file.
1// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_COMPILER_AOT_DISPATCH_TABLE_GENERATOR_H_
6#define RUNTIME_VM_COMPILER_AOT_DISPATCH_TABLE_GENERATOR_H_
7
8#if defined(DART_PRECOMPILED_RUNTIME)
9#error "AOT runtime should not use compiler sources (including header files)"
10#endif // defined(DART_PRECOMPILED_RUNTIME)
11
13#include "vm/object.h"
14
15namespace dart {
16
17class ClassTable;
18class Precompiler;
19class PrecompilerTracer;
20
21namespace compiler {
22
23class SelectorRow;
24
26 TableSelector(int32_t _id,
27 int32_t _call_count,
28 int32_t _offset,
29 bool _called_on_null,
30 bool _torn_off)
31 : id(_id),
32 call_count(_call_count),
33 offset(_offset),
34 called_on_null(_called_on_null),
35 torn_off(_torn_off) {}
36
37 bool IsUsed() const { return call_count > 0; }
38
39 // ID assigned to the selector.
40 int32_t id;
41 // Number of dispatch table call sites with this selector (conservative:
42 // number may be bigger, but not smaller, than actual number of call sites).
43 int32_t call_count;
44 // Table offset assigned to the selector by the dispatch table generator.
45 int32_t offset;
46 // Are there any call sites with this selector where the receiver may be null?
48 // Is this method ever torn off, i.e. is its method extractor accessed?
50 // Is the selector part of the interface on Null (same as Object)?
51 bool on_null_interface = false;
52 // Do any targets of this selector assume that an args descriptor is passed?
54};
55
57 public:
58 explicit SelectorMap(Zone* zone) : zone_(zone) {}
59
60 // Get the selector for this interface target, or null if the function does
61 // not have a selector assigned.
62 const TableSelector* GetSelector(const Function& interface_target) const;
63
64 const TableSelector* GetSelector(int32_t sid) const;
65
66 private:
67 static constexpr int32_t kInvalidSelectorId =
69 static constexpr int32_t kInvalidSelectorOffset = -1;
70
71 int32_t SelectorId(const Function& interface_target) const;
72
73 void AddSelector(int32_t call_count, bool called_on_null, bool torn_off);
74 void SetSelectorProperties(int32_t sid,
75 bool on_null_interface,
76 bool requires_args_descriptor);
77
78 int32_t NumIds() const { return selectors_.length(); }
79
80 friend class dart::Precompiler;
83 friend class SelectorRow;
84
85 Zone* zone_;
87};
88
90 public:
92
93 SelectorMap* selector_map() { return &selector_map_; }
94
95 // Find suitable selectors and compute offsets for them.
97
98 // Build up an array of Code objects, used to serialize the information
99 // deserialized as a DispatchTable at runtime.
100 ArrayPtr BuildCodeArray();
101
102 private:
103 void ReadTableSelectorInfo();
104 void NumberSelectors();
105 void SetupSelectorRows();
106 void ComputeSelectorOffsets();
107
108 Zone* const zone_;
109 ClassTable* classes_;
110 int32_t num_selectors_;
111 int32_t num_classes_;
112 int32_t table_size_;
113
114 GrowableArray<SelectorRow*> table_rows_;
115
116 SelectorMap selector_map_;
117};
118
119} // namespace compiler
120} // namespace dart
121
122#endif // RUNTIME_VM_COMPILER_AOT_DISPATCH_TABLE_GENERATOR_H_
SI F table(const skcms_Curve *curve, F v)
void Initialize(ClassTable *table)
const TableSelector * GetSelector(int32_t sid) const
const TableSelector * GetSelector(const Function &interface_target) const
Definition: dart_vm.cc:33
TableSelector(int32_t _id, int32_t _call_count, int32_t _offset, bool _called_on_null, bool _torn_off)