Chromium Code Reviews| 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 #include "vm/compiler.h" | 5 #include "vm/compiler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 | 8 |
| 9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
| 10 #include "vm/code_generator.h" | 10 #include "vm/code_generator.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 error = isolate->object_store()->sticky_error(); | 92 error = isolate->object_store()->sticky_error(); |
| 93 isolate->object_store()->clear_sticky_error(); | 93 isolate->object_store()->clear_sticky_error(); |
| 94 isolate->set_long_jump_base(base); | 94 isolate->set_long_jump_base(base); |
| 95 return error.raw(); | 95 return error.raw(); |
| 96 } | 96 } |
| 97 UNREACHABLE(); | 97 UNREACHABLE(); |
| 98 return Error::null(); | 98 return Error::null(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 static void AddRelatedClassesToList(const Class& cls, | |
| 103 const GrowableObjectArray& parse_list, | |
| 104 const GrowableObjectArray& patch_list) { | |
| 105 Isolate* isolate = Isolate::Current(); | |
| 106 Class& parse_class = Class::Handle(isolate); | |
| 107 Type& interface_type = Type::Handle(isolate); | |
| 108 Array& interfaces = Array::Handle(isolate); | |
| 109 | |
| 110 // Add all the interfaces implemented by the class that have not been | |
| 111 // already parsed to the parse list. Mark the interface as parsed so that | |
| 112 // we don't recursively add it back into the list. | |
| 113 interfaces ^= cls.interfaces(); | |
| 114 for (intptr_t i = 0; i < interfaces.Length(); i++) { | |
| 115 interface_type ^= interfaces.At(i); | |
| 116 parse_class ^= interface_type.type_class(); | |
| 117 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { | |
| 118 parse_list.Add(parse_class); | |
| 119 parse_class.set_is_marked_for_parsing(); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 // Walk up the super_class chain and add these classes to the list if they | |
| 124 // have not been already parsed to the parse list. Mark the class as parsed | |
| 125 // so that we don't recursively add it back into the list. | |
| 126 parse_class ^= cls.SuperClass(); | |
| 127 while (!parse_class.IsNull()) { | |
| 128 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { | |
| 129 parse_list.Add(parse_class); | |
| 130 parse_class.set_is_marked_for_parsing(); | |
| 131 } | |
| 132 parse_class ^= parse_class.SuperClass(); | |
| 133 } | |
| 134 | |
| 135 // Add patch classes if they exist to the parse list if they have not already | |
| 136 // been parsed and patched. Mark the class as parsed so that we don't | |
| 137 // recursively add it back into the list. | |
| 138 const GrowableObjectArray& patch_class_array = | |
| 139 GrowableObjectArray::Handle(cls.patch_classes()); | |
| 140 if (!patch_class_array.IsNull()) { | |
| 141 for (intptr_t i = 0; i < patch_class_array.Length(); i++) { | |
| 142 parse_class ^= patch_class_array.At(i); | |
| 143 ASSERT(!parse_class.IsNull()); | |
| 144 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { | |
| 145 patch_list.Add(parse_class); | |
| 146 parse_class.set_is_marked_for_parsing(); | |
| 147 } | |
| 148 } | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 | |
| 153 RawError* Compiler::CompileClass(const Class& cls) { | |
| 154 // If class is a top level class it is already parsed. | |
| 155 if (cls.IsTopLevel()) { | |
| 156 return Error::null(); | |
| 157 } | |
| 158 // If the class is already marked for parsing return immediately. | |
| 159 if (cls.is_marked_for_parsing()) { | |
| 160 return Error::null(); | |
| 161 } | |
| 162 // Parse the class and all the interfaces it implements and super classes. | |
| 163 Isolate* isolate = Isolate::Current(); | |
| 164 StackZone zone(isolate); | |
| 165 LongJump* base = isolate->long_jump_base(); | |
| 166 LongJump jump; | |
| 167 isolate->set_long_jump_base(&jump); | |
| 168 if (setjmp(*jump.Set()) == 0) { | |
| 169 if (FLAG_trace_compiler) { | |
| 170 OS::Print("Compiling Class %s '%s'\n", "", cls.ToCString()); | |
| 171 } | |
| 172 | |
| 173 Class& parse_class = Class::Handle(); | |
| 174 const GrowableObjectArray& parse_list = | |
| 175 GrowableObjectArray::Handle(GrowableObjectArray::New(4)); | |
| 176 const GrowableObjectArray& patch_list = | |
| 177 GrowableObjectArray::Handle(GrowableObjectArray::New(4)); | |
| 178 | |
| 179 // Add the primary class which needs to be parsed to the parse list. | |
| 180 // Mark the class as parsed so that we don't recursively add the same | |
| 181 // class back into the list. | |
| 182 parse_list.Add(cls); | |
| 183 cls.set_is_marked_for_parsing(); | |
| 184 | |
| 185 // Add all super classes, interface classes and patch class if one | |
| 186 // exists to the corresponding lists. | |
| 187 for (intptr_t i = 0; i < parse_list.Length(); i++) { | |
|
Ivan Posva
2013/05/23 05:10:37
This is a very unusual way to do fix-point iterati
siva
2013/05/23 20:19:46
Added a comment with an uppercase NOTE to make sur
| |
| 188 parse_class ^= parse_list.At(i); | |
| 189 AddRelatedClassesToList(parse_class, parse_list, patch_list); | |
| 190 } | |
| 191 | |
| 192 // Parse all the classes that have been added above. | |
| 193 for (intptr_t i = (parse_list.Length() - 1); i >=0 ; i--) { | |
| 194 parse_class ^= parse_list.At(i); | |
| 195 ASSERT(!parse_class.IsNull()); | |
| 196 Parser::ParseClass(parse_class); | |
| 197 } | |
| 198 | |
| 199 // Parse all the patch classes that have been added above. | |
| 200 for (intptr_t i = 0; i < patch_list.Length(); i++) { | |
| 201 parse_class ^= patch_list.At(i); | |
| 202 ASSERT(!parse_class.IsNull()); | |
| 203 Parser::ParseClass(parse_class); | |
| 204 } | |
| 205 | |
| 206 // Finalize these classes. | |
| 207 for (intptr_t i = (parse_list.Length() - 1); i >=0 ; i--) { | |
| 208 parse_class ^= parse_list.At(i); | |
| 209 ASSERT(!parse_class.IsNull()); | |
| 210 ClassFinalizer::FinalizeClass(parse_class); | |
| 211 parse_class.reset_is_marked_for_parsing(); | |
| 212 } | |
| 213 | |
| 214 isolate->set_long_jump_base(base); | |
| 215 return Error::null(); | |
| 216 } else { | |
| 217 Error& error = Error::Handle(); | |
| 218 error = isolate->object_store()->sticky_error(); | |
| 219 isolate->object_store()->clear_sticky_error(); | |
| 220 isolate->set_long_jump_base(base); | |
| 221 return error.raw(); | |
| 222 } | |
| 223 UNREACHABLE(); | |
| 224 return Error::null(); | |
| 225 } | |
| 226 | |
| 227 | |
| 102 static void InstallUnoptimizedCode(const Function& function) { | 228 static void InstallUnoptimizedCode(const Function& function) { |
| 103 // Disable optimized code. | 229 // Disable optimized code. |
| 104 ASSERT(function.HasOptimizedCode()); | 230 ASSERT(function.HasOptimizedCode()); |
| 105 if (FLAG_trace_compiler) { | 231 if (FLAG_trace_compiler) { |
| 106 OS::Print("--> patching entry %#"Px"\n", | 232 OS::Print("--> patching entry %#"Px"\n", |
| 107 Code::Handle(function.CurrentCode()).EntryPoint()); | 233 Code::Handle(function.CurrentCode()).EntryPoint()); |
| 108 } | 234 } |
| 109 function.SwitchToUnoptimizedCode(); | 235 function.SwitchToUnoptimizedCode(); |
| 110 if (FLAG_trace_compiler) { | 236 if (FLAG_trace_compiler) { |
| 111 OS::Print("--> restoring entry at %#"Px"\n", | 237 OS::Print("--> restoring entry at %#"Px"\n", |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 Object::Handle(isolate->object_store()->sticky_error()); | 862 Object::Handle(isolate->object_store()->sticky_error()); |
| 737 isolate->object_store()->clear_sticky_error(); | 863 isolate->object_store()->clear_sticky_error(); |
| 738 isolate->set_long_jump_base(base); | 864 isolate->set_long_jump_base(base); |
| 739 return result.raw(); | 865 return result.raw(); |
| 740 } | 866 } |
| 741 UNREACHABLE(); | 867 UNREACHABLE(); |
| 742 return Object::null(); | 868 return Object::null(); |
| 743 } | 869 } |
| 744 | 870 |
| 745 } // namespace dart | 871 } // namespace dart |
| OLD | NEW |