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

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

Issue 1410363005: Make ICData changes thread safe (first compute array, then set it). Install code in the main thread… (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 5 years, 1 month 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/code_generator.cc ('k') | runtime/vm/compiler.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_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 Function; 18 class Function;
18 class Library; 19 class Library;
19 class ParsedFunction; 20 class ParsedFunction;
20 class RawInstance; 21 class RawInstance;
21 class Script; 22 class Script;
22 class SequenceNode; 23 class SequenceNode;
23 24
24 class Compiler : public AllStatic { 25 class Compiler : public AllStatic {
25 public: 26 public:
27 static const intptr_t kNoOSRDeoptId = Thread::kNoDeoptId;
28
26 // Extracts top level entities from the script and populates 29 // Extracts top level entities from the script and populates
27 // the class dictionary of the library. 30 // the class dictionary of the library.
28 // 31 //
29 // Returns Error::null() if there is no compilation error. 32 // Returns Error::null() if there is no compilation error.
30 static RawError* Compile(const Library& library, const Script& script); 33 static RawError* Compile(const Library& library, const Script& script);
31 34
32 // Extracts function and field symbols from the class and populates 35 // Extracts function and field symbols from the class and populates
33 // the class. 36 // the class.
34 // 37 //
35 // Returns Error::null() if there is no compilation error. 38 // Returns Error::null() if there is no compilation error.
36 static RawError* CompileClass(const Class& cls); 39 static RawError* CompileClass(const Class& cls);
37 40
38 // Generates code for given function and sets its code field. 41 // Generates code for given function and sets its code field.
39 // 42 //
40 // Returns Error::null() if there is no compilation error. 43 // Returns Error::null() if there is no compilation error.
41 static RawError* CompileFunction(Thread* thread, const Function& function); 44 static RawError* CompileFunction(Thread* thread, const Function& function);
42 45
43 // Generates unoptimized code if not present, current code is unchanged. 46 // Generates unoptimized code if not present, current code is unchanged.
44 static RawError* EnsureUnoptimizedCode(Thread* thread, 47 static RawError* EnsureUnoptimizedCode(Thread* thread,
45 const Function& function); 48 const Function& function);
46 49
47 // Generates optimized code for function. 50 // Generates optimized code for function.
48 // 51 //
49 // Returns Error::null() if there is no compilation error. 52 // Returns Error::null() if there is no compilation error.
53 // If 'result_code' is not NULL, then the generated code is returned but
54 // not installed.
50 static RawError* CompileOptimizedFunction( 55 static RawError* CompileOptimizedFunction(
51 Thread* thread, 56 Thread* thread,
52 const Function& function, 57 const Function& function,
53 intptr_t osr_id = Thread::kNoDeoptId); 58 intptr_t osr_id = kNoOSRDeoptId,
59 Code* result_code = NULL);
54 60
55 // Generates code for given parsed function (without parsing it again) and 61 // Generates code for given parsed function (without parsing it again) and
56 // sets its code field. 62 // sets its code field.
57 // 63 //
58 // Returns Error::null() if there is no compilation error. 64 // Returns Error::null() if there is no compilation error.
59 static RawError* CompileParsedFunction(ParsedFunction* parsed_function); 65 static RawError* CompileParsedFunction(ParsedFunction* parsed_function);
60 66
61 // Generates and executes code for a given code fragment, e.g. a 67 // Generates and executes code for a given code fragment, e.g. a
62 // compile time constant expression. Returns the result returned 68 // compile time constant expression. Returns the result returned
63 // by the fragment. 69 // by the fragment.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 103
98 private: 104 private:
99 static bool always_optimize_; 105 static bool always_optimize_;
100 static bool allow_recompilation_; 106 static bool allow_recompilation_;
101 }; 107 };
102 108
103 109
104 // Class to run optimizing compilation in a background thread. 110 // Class to run optimizing compilation in a background thread.
105 // Current implementation: one task per isolate, it dies with the owning 111 // Current implementation: one task per isolate, it dies with the owning
106 // isolate. 112 // isolate.
113 // No OSR compilation in the background compiler.
107 class BackgroundCompiler : public ThreadPool::Task { 114 class BackgroundCompiler : public ThreadPool::Task {
108 public: 115 public:
109 static void EnsureInit(Thread* thread); 116 static void EnsureInit(Thread* thread);
110 117
111 static void Stop(BackgroundCompiler* task); 118 static void Stop(BackgroundCompiler* task);
112 119
120 // Call to optimize a function in the background, enters the function in the
121 // compilation queue.
113 void CompileOptimized(const Function& function); 122 void CompileOptimized(const Function& function);
114 123
124 // Call to activate/install optimized code (must occur in the mutator thread).
125 void InstallGeneratedCode();
126
115 // Access to queue length is guarded with queue_monitor_; 127 // Access to queue length is guarded with queue_monitor_;
116 intptr_t queue_length() const { return queue_length_; } 128 intptr_t function_queue_length() const { return function_queue_length_; }
117 void set_queue_length(intptr_t value) { queue_length_ = value; } 129 void set_function_queue_length(intptr_t value) {
130 function_queue_length_ = value;
131 }
118 132
119 private: 133 private:
120 explicit BackgroundCompiler(Isolate* isolate); 134 explicit BackgroundCompiler(Isolate* isolate);
121 135
136 GrowableObjectArray* FunctionsQueue() const;
137 GrowableObjectArray* CodesQueue() const;
138
122 virtual void Run(); 139 virtual void Run();
123 140
124 void Add(const Function& f); 141 void AddFunction(const Function& f);
125 RawFunction* RemoveOrNull(); 142 RawFunction* RemoveFunctionOrNull();
126 RawFunction* LastOrNull() const; 143 RawFunction* LastFunctionOrNull() const;
144
145 void AddCode(const Code& c);
127 146
128 Isolate* isolate_; 147 Isolate* isolate_;
129 bool running_; // While true, will try to read queue and compile. 148 bool running_; // While true, will try to read queue and compile.
130 bool* done_; // True if the thread is done. 149 bool* done_; // True if the thread is done.
131 Monitor* queue_monitor_; // Controls access to the queue. 150 Monitor* queue_monitor_; // Controls access to the queue.
132 Monitor* done_monitor_; // Notify/wait that the thread is done. 151 Monitor* done_monitor_; // Notify/wait that the thread is done.
133 152
134 intptr_t queue_length_; // Lightweight access to length of compiler queue. 153 // Lightweight access to length of compiler queue.
154 intptr_t function_queue_length_;
135 155
136 DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundCompiler); 156 DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundCompiler);
137 }; 157 };
138 158
139 } // namespace dart 159 } // namespace dart
140 160
141 #endif // VM_COMPILER_H_ 161 #endif // VM_COMPILER_H_
OLDNEW
« no previous file with comments | « runtime/vm/code_generator.cc ('k') | runtime/vm/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698