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