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 Class; | 16 class Class; |
17 class Code; | 17 class Code; |
| 18 class CompilationWorkQueue; |
18 class Function; | 19 class Function; |
19 class Library; | 20 class Library; |
20 class ParsedFunction; | 21 class ParsedFunction; |
21 class RawInstance; | 22 class RawInstance; |
22 class Script; | 23 class Script; |
23 class SequenceNode; | 24 class SequenceNode; |
24 | 25 |
| 26 // Carries result from background compilation: code and generation counters |
| 27 // that help check if the code may have become invalid during background |
| 28 // compilation. |
| 29 class BackgroundCompilationResult : public ValueObject { |
| 30 public: |
| 31 BackgroundCompilationResult(); |
| 32 |
| 33 // Initializes with current isolate-stored generations |
| 34 void Init(); |
| 35 |
| 36 void set_result_code(const Code& value) { result_code_ = value.raw(); } |
| 37 const Code& result_code() const { return result_code_; } |
| 38 |
| 39 // Returns true if all relevant gen-counts are current and code is valid. |
| 40 bool IsValid() const; |
| 41 |
| 42 // Remove gen-counts from validation check. |
| 43 void ClearCHAInvalidationGen() { |
| 44 cha_invalidation_gen_ = Integer::null(); |
| 45 } |
| 46 void ClearFieldInnvalidationGen() { |
| 47 field_invalidation_gen_ = Integer::null(); |
| 48 } |
| 49 void ClearPrefixInnvalidationGen() { |
| 50 prefix_invalidation_gen_ = Integer::null(); |
| 51 } |
| 52 |
| 53 void PushOnQueue(CompilationWorkQueue* queue) const; |
| 54 void PopFromQueue(CompilationWorkQueue* queue); |
| 55 |
| 56 void PrintValidity() const; |
| 57 |
| 58 private: |
| 59 Code& result_code_; |
| 60 Integer& cha_invalidation_gen_; |
| 61 Integer& field_invalidation_gen_; |
| 62 Integer& prefix_invalidation_gen_; |
| 63 }; |
| 64 |
| 65 |
25 class Compiler : public AllStatic { | 66 class Compiler : public AllStatic { |
26 public: | 67 public: |
27 static const intptr_t kNoOSRDeoptId = Thread::kNoDeoptId; | 68 static const intptr_t kNoOSRDeoptId = Thread::kNoDeoptId; |
28 | 69 |
29 static bool IsBackgroundCompilation(); | 70 static bool IsBackgroundCompilation(); |
30 | 71 |
31 // Extracts top level entities from the script and populates | 72 // Extracts top level entities from the script and populates |
32 // the class dictionary of the library. | 73 // the class dictionary of the library. |
33 // | 74 // |
34 // Returns Error::null() if there is no compilation error. | 75 // Returns Error::null() if there is no compilation error. |
(...skipping 16 matching lines...) Expand all Loading... |
51 | 92 |
52 // Generates optimized code for function. | 93 // Generates optimized code for function. |
53 // | 94 // |
54 // Returns Error::null() if there is no compilation error. | 95 // Returns Error::null() if there is no compilation error. |
55 // If 'result_code' is not NULL, then the generated code is returned but | 96 // If 'result_code' is not NULL, then the generated code is returned but |
56 // not installed. | 97 // not installed. |
57 static RawError* CompileOptimizedFunction( | 98 static RawError* CompileOptimizedFunction( |
58 Thread* thread, | 99 Thread* thread, |
59 const Function& function, | 100 const Function& function, |
60 intptr_t osr_id = kNoOSRDeoptId, | 101 intptr_t osr_id = kNoOSRDeoptId, |
61 Code* result_code = NULL); | 102 BackgroundCompilationResult* res = NULL); |
62 | 103 |
63 // Generates code for given parsed function (without parsing it again) and | 104 // Generates code for given parsed function (without parsing it again) and |
64 // sets its code field. | 105 // sets its code field. |
65 // | 106 // |
66 // Returns Error::null() if there is no compilation error. | 107 // Returns Error::null() if there is no compilation error. |
67 static RawError* CompileParsedFunction(ParsedFunction* parsed_function); | 108 static RawError* CompileParsedFunction(ParsedFunction* parsed_function); |
68 | 109 |
69 // Generates and executes code for a given code fragment, e.g. a | 110 // Generates and executes code for a given code fragment, e.g. a |
70 // compile time constant expression. Returns the result returned | 111 // compile time constant expression. Returns the result returned |
71 // by the fragment. | 112 // by the fragment. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 // Access to queue length is guarded with queue_monitor_; | 170 // Access to queue length is guarded with queue_monitor_; |
130 intptr_t function_queue_length() const { return function_queue_length_; } | 171 intptr_t function_queue_length() const { return function_queue_length_; } |
131 void set_function_queue_length(intptr_t value) { | 172 void set_function_queue_length(intptr_t value) { |
132 function_queue_length_ = value; | 173 function_queue_length_ = value; |
133 } | 174 } |
134 | 175 |
135 private: | 176 private: |
136 explicit BackgroundCompiler(Isolate* isolate); | 177 explicit BackgroundCompiler(Isolate* isolate); |
137 | 178 |
138 GrowableObjectArray* FunctionsQueue() const; | 179 GrowableObjectArray* FunctionsQueue() const; |
139 GrowableObjectArray* CodesQueue() const; | 180 GrowableObjectArray* ResultQueue() const; |
140 | 181 |
141 virtual void Run(); | 182 virtual void Run(); |
142 | 183 |
143 void AddFunction(const Function& f); | 184 void AddFunction(const Function& f); |
144 RawFunction* RemoveFunctionOrNull(); | 185 RawFunction* RemoveFunctionOrNull(); |
145 RawFunction* LastFunctionOrNull() const; | 186 RawFunction* LastFunctionOrNull() const; |
146 | 187 |
147 void AddCode(const Code& c); | 188 void AddResult(const BackgroundCompilationResult& value); |
148 | 189 |
149 Isolate* isolate_; | 190 Isolate* isolate_; |
150 bool running_; // While true, will try to read queue and compile. | 191 bool running_; // While true, will try to read queue and compile. |
151 bool* done_; // True if the thread is done. | 192 bool* done_; // True if the thread is done. |
152 Monitor* queue_monitor_; // Controls access to the queue. | 193 Monitor* queue_monitor_; // Controls access to the queue. |
153 Monitor* done_monitor_; // Notify/wait that the thread is done. | 194 Monitor* done_monitor_; // Notify/wait that the thread is done. |
154 | 195 |
155 // Lightweight access to length of compiler queue. | 196 // Lightweight access to length of compiler queue. |
156 intptr_t function_queue_length_; | 197 intptr_t function_queue_length_; |
157 | 198 |
158 DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundCompiler); | 199 DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundCompiler); |
159 }; | 200 }; |
160 | 201 |
161 } // namespace dart | 202 } // namespace dart |
162 | 203 |
163 #endif // VM_COMPILER_H_ | 204 #endif // VM_COMPILER_H_ |
OLD | NEW |