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

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
« no previous file with comments | « runtime/vm/precompiler.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "vm/longjump.h"
12
13 namespace dart {
14
15
16 DEFINE_FLAG(bool, trace_precompiler, false, "Trace precompiler.");
17
18
19 static RawError* CompileFunction(const Function& func) {
20 Thread* thread = Thread::Current();
21 Error& error = Error::Handle();
22 if (func.is_abstract() || func.IsRedirectingFactory()) {
23 return error.raw();
24 }
25
26 if (!func.HasCode()) {
27 if (FLAG_trace_precompiler) {
28 OS::Print(" Precompiling %s (%" Pd ")\n",
29 func.ToQualifiedCString(),
30 func.token_pos());
31 }
32 error = Compiler::CompileFunction(thread, func);
33 if (!error.IsNull()) {
34 return error.raw();
35 }
36 }
37
38 if ((func.kind() == RawFunction::kRegularFunction) && !func.is_static()) {
39 const String& name = String::Handle(func.name());
40 if (!Field::IsGetterName(name) && !Field::IsSetterName(name)) {
41 const Function& closure_func =
42 Function::Handle(func.ImplicitClosureFunction());
43 ASSERT(!closure_func.IsNull());
44 error = CompileFunction(closure_func);
45 }
46 }
47
48 return error.raw();
49 }
50
51
52 static RawError* CompileClass(const Class& cls) {
53 if (FLAG_trace_precompiler) {
54 OS::Print(" Precompiling %s\n", cls.ToCString());
55 }
56
57 Error& error = Error::Handle();
58 error = cls.EnsureIsFinalized(Isolate::Current());
59 if (!error.IsNull()) {
60 return error.raw();
61 }
62
63 const Array& fields = Array::Handle(cls.fields());
64 Field& field = Field::Handle();
65 for (intptr_t i = 0; i < fields.Length(); i++) {
66 field ^= fields.At(i);
67 ASSERT(!field.IsNull());
68 if (field.is_static() && field.has_initializer()) {
69 if (FLAG_trace_precompiler) {
70 OS::Print(" Precompiling initializer for %s\n", field.ToCString());
71 }
72 Compiler::CompileStaticInitializer(field);
73 }
74 }
75
76 const Array& functions = Array::Handle(cls.functions());
77 Function& func = Function::Handle();
78 for (intptr_t i = 0; i < functions.Length(); i++) {
79 func ^= functions.At(i);
80 ASSERT(!func.IsNull());
81 error = CompileFunction(func);
82 if (!error.IsNull()) {
83 return error.raw();
84 }
85 }
86
87 return error.raw();
88 }
89
90
91 static RawError* CompileLibrary(const Library& lib) {
92 if (FLAG_trace_precompiler) {
93 OS::Print("Precompiling %s\n", lib.ToCString());
94 }
95 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
96 Class& cls = Class::Handle();
97 Error& error = Error::Handle();
98 while (it.HasNext()) {
99 cls = it.GetNextClass();
100 error = CompileClass(cls);
101 if (!error.IsNull()) {
102 return error.raw();
103 }
104 }
105
106 return error.raw();
107 }
108
109
110 static RawError* InnerCompileAll() {
111 Error& error = Error::Handle();
112 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
113 Isolate::Current()->object_store()->libraries());
114 Library& lib = Library::Handle();
115 for (int i = 0; i < libs.Length(); i++) {
116 lib ^= libs.At(i);
117 error = CompileLibrary(lib);
118 if (!error.IsNull()) {
119 return error.raw();
120 }
121 }
122
123 if (FLAG_trace_precompiler) {
124 OS::Print("** Precompiling collected closures **\n");
125 }
126
127 const GrowableObjectArray& closures =
128 GrowableObjectArray::Handle(Isolate::Current()->collected_closures());
129 Function& func = Function::Handle();
130 if (!closures.IsNull()) {
131 for (int i = 0; i < closures.Length(); i++) {
132 func ^= closures.At(i);
133 error = CompileFunction(func);
134 if (!error.IsNull()) {
135 return error.raw();
136 }
137 }
138 }
139 Isolate::Current()->set_collected_closures(GrowableObjectArray::Handle());
140
141 if (FLAG_trace_precompiler) {
142 OS::Print("*** Done precompiling ***\n");
143 }
144 Isolate::Current()->set_compilation_allowed(false);
145 return error.raw();
146 }
147
148
149 RawError* Precompiler::CompileAll() {
150 LongJumpScope jump;
151 if (setjmp(*jump.Set()) == 0) {
152 return InnerCompileAll();
153 } else {
154 Isolate* isolate = Isolate::Current();
155 const Error& error = Error::Handle(isolate,
156 isolate->object_store()->sticky_error());
157 isolate->object_store()->clear_sticky_error();
158 return error.raw();
159 }
160 }
161
162 } // namespace dart
OLDNEW
« no previous file with comments | « 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