Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: runtime/vm/cha.h

Issue 2002583002: Background compiler should validate CHA decisions before committing the code. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/aot_optimizer.cc ('k') | runtime/vm/cha.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_CHA_H_ 5 #ifndef VM_CHA_H_
6 #define VM_CHA_H_ 6 #define VM_CHA_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/growable_array.h" 9 #include "vm/growable_array.h"
10 #include "vm/thread.h" 10 #include "vm/thread.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 class Class; 14 class Class;
15 class Function; 15 class Function;
16 template <typename T> class ZoneGrowableArray; 16 template <typename T> class ZoneGrowableArray;
17 class String; 17 class String;
18 18
19 class CHA : public StackResource { 19 class CHA : public StackResource {
20 public: 20 public:
21 explicit CHA(Thread* thread) 21 explicit CHA(Thread* thread)
22 : StackResource(thread), 22 : StackResource(thread),
23 thread_(thread), 23 thread_(thread),
24 leaf_classes_(thread->zone(), 1), 24 guarded_classes_(thread->zone(), 1),
25 previous_(thread->cha()) { 25 previous_(thread->cha()) {
26 thread->set_cha(this); 26 thread->set_cha(this);
27 } 27 }
28 28
29 ~CHA() { 29 ~CHA() {
30 ASSERT(thread_->cha() == this); 30 ASSERT(thread_->cha() == this);
31 thread_->set_cha(previous_); 31 thread_->set_cha(previous_);
32 } 32 }
33 33
34 // Returns true if the class has subclasses. 34 // Returns true if the class has subclasses.
35 static bool HasSubclasses(const Class& cls); 35 static bool HasSubclasses(const Class& cls);
36 bool HasSubclasses(intptr_t cid) const; 36 bool HasSubclasses(intptr_t cid) const;
37 37
38 // Collect the concrete subclasses of 'cls' into 'class_ids'. Return true if 38 // Collect the concrete subclasses of 'cls' into 'class_ids'. Return true if
39 // the result is valid (may be invalid because we don't track the subclasses 39 // the result is valid (may be invalid because we don't track the subclasses
40 // of classes allocated in the VM isolate or class Object). 40 // of classes allocated in the VM isolate or class Object).
41 bool ConcreteSubclasses(const Class& cls, GrowableArray<intptr_t> *class_ids); 41 bool ConcreteSubclasses(const Class& cls, GrowableArray<intptr_t> *class_ids);
42 42
43 // Return true if the class is implemented by some other class. 43 // Return true if the class is implemented by some other class.
44 static bool IsImplemented(const Class& cls); 44 static bool IsImplemented(const Class& cls);
45 45
46 // Returns true if any subclass of 'cls' contains the function. 46 // Returns true if any subclass of 'cls' contains the function.
47 bool HasOverride(const Class& cls, const String& function_name); 47 // If no override was found subclass_count would contain total count of
48 // finalized subclasses that CHA looked at.
49 // This count will be used to validate CHA decision before installing
50 // optimized code compiled in background.
51 bool HasOverride(const Class& cls,
52 const String& function_name,
53 intptr_t* subclass_count);
48 54
49 const GrowableArray<Class*>& leaf_classes() const { 55 // Adds class 'cls' to the list of guarded classes, deoptimization occurs
50 return leaf_classes_; 56 // if any of those classes gets subclassed through later loaded/finalized
51 } 57 // libraries. Only classes that were used for CHA optimizations are added.
58 void AddToGuardedClasses(const Class& cls, intptr_t subclass_count);
52 59
53 // Adds class 'cls' to the list of guarded leaf classes, deoptimization occurs 60 // When compiling in background we need to check that no new finalized
54 // if any of those leaf classes gets subclassed through later loaded/finalized 61 // subclasses were added to guarded classes.
55 // libraries. Only classes that were used for CHA optimizations are added. 62 bool IsConsistentWithCurrentHierarchy() const;
56 void AddToLeafClasses(const Class& cls); 63
64 void RegisterDependencies(const Code& code) const;
65
66 // Used for testing.
67 bool IsGuardedClass(intptr_t cid) const;
57 68
58 private: 69 private:
59 Thread* thread_; 70 Thread* thread_;
60 GrowableArray<Class*> leaf_classes_; 71
72 struct GuardedClassInfo {
73 Class* cls;
74
75 // Number of finalized subclasses that this class had at the moment
76 // when CHA made the first decision based on this class.
77 // Used to validate correctness of background compilation: if
78 // any subclasses were added we will discard compiled code.
79 intptr_t subclass_count;
80 };
81
82 GrowableArray<GuardedClassInfo> guarded_classes_;
61 CHA* previous_; 83 CHA* previous_;
62 }; 84 };
63 85
64 } // namespace dart 86 } // namespace dart
65 87
66 #endif // VM_CHA_H_ 88 #endif // VM_CHA_H_
OLDNEW
« no previous file with comments | « runtime/vm/aot_optimizer.cc ('k') | runtime/vm/cha.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698