Flutter Engine
The Flutter Engine
cha.h
Go to the documentation of this file.
1// Copyright (c) 2012, 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_CHA_H_
6#define RUNTIME_VM_COMPILER_CHA_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
12#include "vm/allocation.h"
13#include "vm/growable_array.h"
14#include "vm/thread.h"
15
16namespace dart {
17
18class Class;
19class CompileType;
20class Function;
21template <typename T>
22class ZoneGrowableArray;
23class String;
24
25class CHA : public ValueObject {
26 public:
27 explicit CHA(Thread* thread)
28 : thread_(thread), guarded_classes_(thread->zone(), 1) {}
29
30 // Returns true if the class has subclasses.
31 static bool HasSubclasses(const Class& cls);
32 bool HasSubclasses(intptr_t cid) const;
33
34 // Collect the concrete subclasses of 'cls' into 'class_ids'. Return true if
35 // the result is valid (may be invalid because we don't track the subclasses
36 // of classes allocated in the VM isolate or class Object).
37 static bool ConcreteSubclasses(const Class& cls,
38 GrowableArray<intptr_t>* class_ids);
39
40 // Return true if the class is implemented by some other class that is not a
41 // subclass.
42 static bool IsImplemented(const Class& cls);
43
44 // Return true if there is only one concrete class that implements
45 // 'interface'.
46 static bool HasSingleConcreteImplementation(const Class& interface,
47 intptr_t* implementation_cid);
48
49 // Return true if variable of static type based on [cls] may hold
50 // a Future instance.
51 static bool ClassCanBeFuture(const Class& cls);
52
53 // Returns true if any subclass of 'cls' contains the function.
54 // If no override was found subclass_count would contain total count of
55 // finalized subclasses that CHA looked at.
56 // This count will be used to validate CHA decision before installing
57 // optimized code compiled in background.
58 bool HasOverride(const Class& cls,
59 const String& function_name,
60 intptr_t* subclass_count);
61
62 // Adds class 'cls' to the list of guarded classes.
63 // Deoptimization occurs if any of those classes gets subclassed or
64 // implemented through later loaded/finalized libraries. Only classes that
65 // were used for CHA optimizations are added.
67 intptr_t subclass_count);
69 intptr_t implementor_cid);
71
72 // When compiling in background we need to check that no new finalized
73 // subclasses were added to guarded classes.
75
76 void RegisterDependencies(const Code& code) const;
77
78 // Used for testing.
79 bool IsGuardedClass(intptr_t cid) const;
80
81 private:
82 void AddToGuardedClasses(const Class& cls,
83 intptr_t subclass_count,
84 intptr_t implementor_cid,
85 bool track_future);
86
87 Thread* thread_;
88
89 struct GuardedClassInfo {
90 Class* cls;
91
92 // Number of finalized subclasses that this class had at the moment
93 // when CHA made the first decision based on this class.
94 // Used to validate correctness of background compilation: if
95 // any subclasses were added we will discard compiled code.
96 intptr_t subclass_count;
97
98 // Value of implementor_cid that this class had at the moment
99 // when CHA made the first decision based on this class.
100 // Used to validate correctness of background compilation: if
101 // any implementors were added we will discard compiled code.
102 intptr_t implementor_cid;
103
104 // Whether we should track that this class cannot be future.
105 bool track_future;
106 };
107
108 GrowableArray<GuardedClassInfo> guarded_classes_;
109};
110
111} // namespace dart
112
113#endif // RUNTIME_VM_COMPILER_CHA_H_
Definition: cha.h:25
CHA(Thread *thread)
Definition: cha.h:27
bool HasOverride(const Class &cls, const String &function_name, intptr_t *subclass_count)
Definition: cha.cc:227
void AddToGuardedClassesForImplementorCid(const Class &cls, intptr_t implementor_cid)
Definition: cha.cc:46
void RegisterDependencies(const Code &code) const
Definition: cha.cc:272
static bool IsImplemented(const Class &cls)
Definition: cha.cc:121
bool IsGuardedClass(intptr_t cid) const
Definition: cha.cc:57
static bool HasSubclasses(const Class &cls)
Definition: cha.cc:64
void AddToGuardedClassesForSubclassCount(const Class &cls, intptr_t subclass_count)
Definition: cha.cc:40
static bool ConcreteSubclasses(const Class &cls, GrowableArray< intptr_t > *class_ids)
Definition: cha.cc:93
void AddToGuardedClassesToTrackFuture(const Class &cls)
Definition: cha.cc:53
static bool ClassCanBeFuture(const Class &cls)
Definition: cha.cc:160
bool IsConsistentWithCurrentHierarchy() const
Definition: cha.cc:202
static bool HasSingleConcreteImplementation(const Class &interface, intptr_t *implementation_cid)
Definition: cha.cc:132
Definition: dart_vm.cc:33
const intptr_t cid
const char *const function_name