| OLD | NEW |
| 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_COMPILER_H_ | 5 #ifndef VM_COMPILER_H_ |
| 6 #define VM_COMPILER_H_ | 6 #define VM_COMPILER_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/runtime_entry.h" | 10 #include "vm/runtime_entry.h" |
| 11 #include "vm/thread_pool.h" | 11 #include "vm/thread_pool.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 // Forward declarations. | 15 // Forward declarations. |
| 16 class BackgroundCompilationQueue; | 16 class BackgroundCompilationQueue; |
| 17 class Class; | 17 class Class; |
| 18 class Code; | 18 class Code; |
| 19 class CompilationWorkQueue; | 19 class CompilationWorkQueue; |
| 20 class Function; | 20 class Function; |
| 21 class Library; | 21 class Library; |
| 22 class ParsedFunction; | 22 class ParsedFunction; |
| 23 class QueueElement; | 23 class QueueElement; |
| 24 class RawInstance; | 24 class RawInstance; |
| 25 class Script; | 25 class Script; |
| 26 class SequenceNode; | 26 class SequenceNode; |
| 27 | 27 |
| 28 // Carries result from background compilation: code and generation counters | |
| 29 // that help check if the code may have become invalid during background | |
| 30 // compilation. | |
| 31 class BackgroundCompilationResult : public ValueObject { | |
| 32 public: | |
| 33 BackgroundCompilationResult(); | |
| 34 | |
| 35 // Initializes with current isolate-stored generations | |
| 36 void Init(); | |
| 37 | |
| 38 void set_result_code(const Code& value) { result_code_ = value.raw(); } | |
| 39 const Code& result_code() const { return result_code_; } | |
| 40 | |
| 41 uint32_t cha_invalidation_gen() const { return cha_invalidation_gen_; } | |
| 42 uint32_t field_invalidation_gen() const { return field_invalidation_gen_; } | |
| 43 uint32_t prefix_invalidation_gen() const { return prefix_invalidation_gen_; } | |
| 44 | |
| 45 void SetFromQElement(QueueElement* value); | |
| 46 | |
| 47 void SetLeafClasses(const GrowableArray<Class*>& leaf_classes); | |
| 48 void SetGuardedFields(const ZoneGrowableArray<const Field*>& guarded_fields); | |
| 49 void SetDeoptimizeDependentFields(const GrowableArray<const Field*>& fields); | |
| 50 | |
| 51 const Array& leaf_classes() const { return leaf_classes_; } | |
| 52 const Array& guarded_fields() const { return guarded_fields_; } | |
| 53 const Array& deoptimize_dependent_fields() const { | |
| 54 return deoptimize_dependent_fields_; | |
| 55 } | |
| 56 | |
| 57 // Returns true if all relevant gen-counts are current and code is valid. | |
| 58 bool IsValid() const; | |
| 59 | |
| 60 // Remove gen-counts from validation check. | |
| 61 void ClearCHAInvalidationGen() { | |
| 62 cha_invalidation_gen_ = Isolate::kInvalidGen; | |
| 63 } | |
| 64 void ClearFieldInvalidationGen() { | |
| 65 field_invalidation_gen_ = Isolate::kInvalidGen; | |
| 66 } | |
| 67 void ClearPrefixInvalidationGen() { | |
| 68 prefix_invalidation_gen_ = Isolate::kInvalidGen; | |
| 69 } | |
| 70 | |
| 71 void PrintValidity() const; | |
| 72 | |
| 73 private: | |
| 74 Code& result_code_; | |
| 75 Array& leaf_classes_; | |
| 76 Array& guarded_fields_; | |
| 77 Array& deoptimize_dependent_fields_; | |
| 78 uint32_t cha_invalidation_gen_; | |
| 79 uint32_t field_invalidation_gen_; | |
| 80 uint32_t prefix_invalidation_gen_; | |
| 81 }; | |
| 82 | |
| 83 | 28 |
| 84 class Compiler : public AllStatic { | 29 class Compiler : public AllStatic { |
| 85 public: | 30 public: |
| 86 static const intptr_t kNoOSRDeoptId = Thread::kNoDeoptId; | 31 static const intptr_t kNoOSRDeoptId = Thread::kNoDeoptId; |
| 87 | 32 |
| 88 static bool IsBackgroundCompilation(); | 33 static bool IsBackgroundCompilation(); |
| 89 | 34 |
| 90 // Extracts top level entities from the script and populates | 35 // Extracts top level entities from the script and populates |
| 91 // the class dictionary of the library. | 36 // the class dictionary of the library. |
| 92 // | 37 // |
| (...skipping 16 matching lines...) Expand all Loading... |
| 109 const Function& function); | 54 const Function& function); |
| 110 | 55 |
| 111 // Generates optimized code for function. | 56 // Generates optimized code for function. |
| 112 // | 57 // |
| 113 // Returns Error::null() if there is no compilation error. | 58 // Returns Error::null() if there is no compilation error. |
| 114 // If 'result_code' is not NULL, then the generated code is returned but | 59 // If 'result_code' is not NULL, then the generated code is returned but |
| 115 // not installed. | 60 // not installed. |
| 116 static RawError* CompileOptimizedFunction( | 61 static RawError* CompileOptimizedFunction( |
| 117 Thread* thread, | 62 Thread* thread, |
| 118 const Function& function, | 63 const Function& function, |
| 119 intptr_t osr_id = kNoOSRDeoptId, | 64 intptr_t osr_id = kNoOSRDeoptId); |
| 120 BackgroundCompilationResult* res = NULL); | |
| 121 | 65 |
| 122 // Generates code for given parsed function (without parsing it again) and | 66 // Generates code for given parsed function (without parsing it again) and |
| 123 // sets its code field. | 67 // sets its code field. |
| 124 // | 68 // |
| 125 // Returns Error::null() if there is no compilation error. | 69 // Returns Error::null() if there is no compilation error. |
| 126 static RawError* CompileParsedFunction(ParsedFunction* parsed_function); | 70 static RawError* CompileParsedFunction(ParsedFunction* parsed_function); |
| 127 | 71 |
| 128 // Generates and executes code for a given code fragment, e.g. a | 72 // Generates and executes code for a given code fragment, e.g. a |
| 129 // compile time constant expression. Returns the result returned | 73 // compile time constant expression. Returns the result returned |
| 130 // by the fragment. | 74 // by the fragment. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 class BackgroundCompiler : public ThreadPool::Task { | 119 class BackgroundCompiler : public ThreadPool::Task { |
| 176 public: | 120 public: |
| 177 static void EnsureInit(Thread* thread); | 121 static void EnsureInit(Thread* thread); |
| 178 | 122 |
| 179 static void Stop(BackgroundCompiler* task); | 123 static void Stop(BackgroundCompiler* task); |
| 180 | 124 |
| 181 // Call to optimize a function in the background, enters the function in the | 125 // Call to optimize a function in the background, enters the function in the |
| 182 // compilation queue. | 126 // compilation queue. |
| 183 void CompileOptimized(const Function& function); | 127 void CompileOptimized(const Function& function); |
| 184 | 128 |
| 185 // Call to activate/install optimized code (must occur in the mutator thread). | |
| 186 void InstallGeneratedCode(); | |
| 187 | |
| 188 | |
| 189 void VisitPointers(ObjectPointerVisitor* visitor); | 129 void VisitPointers(ObjectPointerVisitor* visitor); |
| 190 | 130 |
| 191 BackgroundCompilationQueue* function_queue() const { return function_queue_; } | 131 BackgroundCompilationQueue* function_queue() const { return function_queue_; } |
| 192 BackgroundCompilationQueue* result_queue() const { return result_queue_; } | |
| 193 | 132 |
| 194 private: | 133 private: |
| 195 explicit BackgroundCompiler(Isolate* isolate); | 134 explicit BackgroundCompiler(Isolate* isolate); |
| 196 | 135 |
| 197 virtual void Run(); | 136 virtual void Run(); |
| 198 | 137 |
| 199 void AddResult(const BackgroundCompilationResult& value); | |
| 200 | |
| 201 Isolate* isolate_; | 138 Isolate* isolate_; |
| 202 bool running_; // While true, will try to read queue and compile. | 139 bool running_; // While true, will try to read queue and compile. |
| 203 bool* done_; // True if the thread is done. | 140 bool* done_; // True if the thread is done. |
| 204 Monitor* queue_monitor_; // Controls access to the queue. | 141 Monitor* queue_monitor_; // Controls access to the queue. |
| 205 Monitor* done_monitor_; // Notify/wait that the thread is done. | 142 Monitor* done_monitor_; // Notify/wait that the thread is done. |
| 206 | 143 |
| 207 BackgroundCompilationQueue* function_queue_; | 144 BackgroundCompilationQueue* function_queue_; |
| 208 BackgroundCompilationQueue* result_queue_; | |
| 209 | 145 |
| 210 DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundCompiler); | 146 DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundCompiler); |
| 211 }; | 147 }; |
| 212 | 148 |
| 213 } // namespace dart | 149 } // namespace dart |
| 214 | 150 |
| 215 #endif // VM_COMPILER_H_ | 151 #endif // VM_COMPILER_H_ |
| OLD | NEW |