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

Side by Side Diff: runtime/vm/precompiler.cc

Issue 1261673004: Non-tree-shaking --precompile. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 #include "vm/precompiler.h"
6
7 #include "vm/isolate.h"
8 #include "vm/object.h"
9 #include "vm/object_store.h"
10 #include "vm/compiler.h"
11
12 namespace dart {
13
14
15 DEFINE_FLAG(bool, trace_precompiler, false, "Trace precompiler.");
16
17
18 static RawError* CompileFunction(const Function& func) {
19 Thread* thread = Thread::Current();
20 Error& error = Error::Handle();
21 if (func.is_abstract() || func.IsRedirectingFactory()) {
22 return error.raw();
23 }
24
25 if (!func.HasCode()) {
26 if (FLAG_trace_precompiler) {
27 OS::Print(" Precompiling %s\n", func.ToQualifiedCString());
28 }
29 error = Compiler::CompileFunction(thread, func);
30 if (!error.IsNull()) {
31 return error.raw();
32 }
33 }
34
35 if (!func.IsFactory() &&
36 !func.IsGenerativeConstructor() &&
37 func.kind() != RawFunction::kImplicitStaticFinalGetter &&
38 !func.IsClosureFunction() &&
39 !func.IsImplicitClosureFunction()) {
40 const Function& closure_func =
41 Function::Handle(func.ImplicitClosureFunction());
42 if (!closure_func.IsNull()) {
43 error = CompileFunction(closure_func);
44 }
45 }
46
47 return error.raw();
48 }
49
50
51 static RawError* CompileClass(const Class& cls) {
52 if (FLAG_trace_precompiler) {
53 OS::Print(" Precompiling %s\n", cls.ToCString());
54 }
55
56 Error& error = Error::Handle();
57 error = cls.EnsureIsFinalized(Isolate::Current());
58 if (!error.IsNull()) {
59 return error.raw();
60 }
61
62 const Array& fields = Array::Handle(cls.fields());
63 Field& field = Field::Handle();
64 for (intptr_t i = 0; i < fields.Length(); i++) {
65 field ^= fields.At(i);
66 ASSERT(!field.IsNull());
67 if (field.is_static() && field.has_initializer()) {
68 if (FLAG_trace_precompiler) {
69 OS::Print(" Precompiling initializer for %s\n", field.ToCString());
70 }
71 Compiler::CompileStaticInitializer(field);
72 }
73 }
74
75 const Array& functions = Array::Handle(cls.functions());
76 Function& func = Function::Handle();
77 for (intptr_t i = 0; i < functions.Length(); i++) {
78 func ^= functions.At(i);
79 ASSERT(!func.IsNull());
80 error = CompileFunction(func);
81 if (!error.IsNull()) {
82 return error.raw();
83 }
84 }
85
86 return error.raw();
87 }
88
89
90 static RawError* CompileLibrary(const Library& lib) {
91 if (FLAG_trace_precompiler) {
92 OS::Print("Precompiling %s\n", lib.ToCString());
93 }
94 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
95 Class& cls = Class::Handle();
96 Error& error = Error::Handle();
97 while (it.HasNext()) {
98 cls = it.GetNextClass();
99 error = CompileClass(cls);
100 if (!error.IsNull()) {
101 return error.raw();
102 }
103 }
104
105 return error.raw();
106 }
107
108
109 RawError* Precompiler::CompileAll() {
110 Error& error = Error::Handle();
111 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
112 Isolate::Current()->object_store()->libraries());
113 Library& lib = Library::Handle();
114 for (int i = 0; i < libs.Length(); i++) {
115 lib ^= libs.At(i);
116 error = CompileLibrary(lib);
117 if (!error.IsNull()) {
118 return error.raw();
119 }
120 }
121
122 if (FLAG_trace_precompiler) {
123 OS::Print("** Precompiling collected closures **\n");
124 }
125
126 const GrowableObjectArray& closures =
127 GrowableObjectArray::Handle(Isolate::Current()->collected_closures());
128 Function& func = Function::Handle();
129 if (!closures.IsNull()) {
130 for (int i = 0; i < closures.Length(); i++) {
131 func ^= closures.At(i);
132 error = CompileFunction(func);
133 if (!error.IsNull()) {
134 return error.raw();
135 }
136 }
137 }
138 Isolate::Current()->set_collected_closures(GrowableObjectArray::Handle());
139
140 if (FLAG_trace_precompiler) {
141 OS::Print("*** Done precompiling ***\n");
142 }
143 Isolate::Current()->set_compilation_allowed(false);
144 return error.raw();
145 }
146
147 } // namespace dart
OLDNEW
« runtime/vm/parser.cc ('K') | « runtime/vm/precompiler.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698