| 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/block_scheduler.h" | 10 #include "vm/block_scheduler.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 Error& error = Error::Handle(); | 205 Error& error = Error::Handle(); |
| 206 error = isolate->object_store()->sticky_error(); | 206 error = isolate->object_store()->sticky_error(); |
| 207 isolate->object_store()->clear_sticky_error(); | 207 isolate->object_store()->clear_sticky_error(); |
| 208 return error.raw(); | 208 return error.raw(); |
| 209 } | 209 } |
| 210 UNREACHABLE(); | 210 UNREACHABLE(); |
| 211 return Error::null(); | 211 return Error::null(); |
| 212 } | 212 } |
| 213 | 213 |
| 214 | 214 |
| 215 static void AddRelatedClassesToList(const Class& cls, | 215 static void AddRelatedClassesToList( |
| 216 const GrowableObjectArray& parse_list, | 216 const Class& cls, |
| 217 const GrowableObjectArray& patch_list) { | 217 GrowableHandlePtrArray<const Class>* parse_list, |
| 218 GrowableHandlePtrArray<const Class>* patch_list) { |
| 218 Isolate* isolate = Isolate::Current(); | 219 Isolate* isolate = Isolate::Current(); |
| 219 Class& parse_class = Class::Handle(isolate); | 220 Class& parse_class = Class::Handle(isolate); |
| 220 AbstractType& interface_type = Type::Handle(isolate); | 221 AbstractType& interface_type = Type::Handle(isolate); |
| 221 Array& interfaces = Array::Handle(isolate); | 222 Array& interfaces = Array::Handle(isolate); |
| 222 | 223 |
| 223 // Add all the interfaces implemented by the class that have not been | 224 // Add all the interfaces implemented by the class that have not been |
| 224 // already parsed to the parse list. Mark the interface as parsed so that | 225 // already parsed to the parse list. Mark the interface as parsed so that |
| 225 // we don't recursively add it back into the list. | 226 // we don't recursively add it back into the list. |
| 226 interfaces ^= cls.interfaces(); | 227 interfaces ^= cls.interfaces(); |
| 227 for (intptr_t i = 0; i < interfaces.Length(); i++) { | 228 for (intptr_t i = 0; i < interfaces.Length(); i++) { |
| 228 interface_type ^= interfaces.At(i); | 229 interface_type ^= interfaces.At(i); |
| 229 parse_class ^= interface_type.type_class(); | 230 parse_class ^= interface_type.type_class(); |
| 230 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { | 231 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { |
| 231 parse_list.Add(parse_class); | 232 parse_list->Add(parse_class); |
| 232 parse_class.set_is_marked_for_parsing(); | 233 parse_class.set_is_marked_for_parsing(); |
| 233 } | 234 } |
| 234 } | 235 } |
| 235 | 236 |
| 236 // Walk up the super_class chain and add these classes to the list if they | 237 // Walk up the super_class chain and add these classes to the list if they |
| 237 // have not been already parsed to the parse list. Mark the class as parsed | 238 // have not been already parsed to the parse list. Mark the class as parsed |
| 238 // so that we don't recursively add it back into the list. | 239 // so that we don't recursively add it back into the list. |
| 239 parse_class ^= cls.SuperClass(); | 240 parse_class ^= cls.SuperClass(); |
| 240 while (!parse_class.IsNull()) { | 241 while (!parse_class.IsNull()) { |
| 241 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { | 242 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { |
| 242 parse_list.Add(parse_class); | 243 parse_list->Add(parse_class); |
| 243 parse_class.set_is_marked_for_parsing(); | 244 parse_class.set_is_marked_for_parsing(); |
| 244 } | 245 } |
| 245 parse_class ^= parse_class.SuperClass(); | 246 parse_class ^= parse_class.SuperClass(); |
| 246 } | 247 } |
| 247 | 248 |
| 248 // Add patch classes if they exist to the parse list if they have not already | 249 // Add patch classes if they exist to the parse list if they have not already |
| 249 // been parsed and patched. Mark the class as parsed so that we don't | 250 // been parsed and patched. Mark the class as parsed so that we don't |
| 250 // recursively add it back into the list. | 251 // recursively add it back into the list. |
| 251 parse_class ^= cls.patch_class(); | 252 parse_class ^= cls.patch_class(); |
| 252 if (!parse_class.IsNull()) { | 253 if (!parse_class.IsNull()) { |
| 253 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { | 254 if (!parse_class.is_finalized() && !parse_class.is_marked_for_parsing()) { |
| 254 patch_list.Add(parse_class); | 255 patch_list->Add(parse_class); |
| 255 parse_class.set_is_marked_for_parsing(); | 256 parse_class.set_is_marked_for_parsing(); |
| 256 } | 257 } |
| 257 } | 258 } |
| 258 } | 259 } |
| 259 | 260 |
| 260 | 261 |
| 261 RawError* Compiler::CompileClass(const Class& cls) { | 262 RawError* Compiler::CompileClass(const Class& cls) { |
| 262 // If class is a top level class it is already parsed. | 263 // If class is a top level class it is already parsed. |
| 263 if (cls.IsTopLevel()) { | 264 if (cls.IsTopLevel()) { |
| 264 return Error::null(); | 265 return Error::null(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 284 Isolate* isolate = Isolate::Current(); | 285 Isolate* isolate = Isolate::Current(); |
| 285 Error& error = Error::Handle(isolate); | 286 Error& error = Error::Handle(isolate); |
| 286 error = isolate->object_store()->sticky_error(); | 287 error = isolate->object_store()->sticky_error(); |
| 287 isolate->object_store()->clear_sticky_error(); | 288 isolate->object_store()->clear_sticky_error(); |
| 288 return error.raw(); | 289 return error.raw(); |
| 289 } | 290 } |
| 290 } | 291 } |
| 291 | 292 |
| 292 Thread* const thread = Thread::Current(); | 293 Thread* const thread = Thread::Current(); |
| 293 Isolate* const isolate = thread->isolate(); | 294 Isolate* const isolate = thread->isolate(); |
| 295 StackZone zone(thread); |
| 294 // We remember all the classes that are being compiled in these lists. This | 296 // We remember all the classes that are being compiled in these lists. This |
| 295 // also allows us to reset the marked_for_parsing state in case we see an | 297 // also allows us to reset the marked_for_parsing state in case we see an |
| 296 // error. | 298 // error. |
| 297 VMTagScope tagScope(thread, VMTag::kCompileClassTagId); | 299 VMTagScope tagScope(thread, VMTag::kCompileClassTagId); |
| 298 Class& parse_class = Class::Handle(isolate); | 300 GrowableHandlePtrArray<const Class> parse_list(thread->zone(), 4); |
| 299 const GrowableObjectArray& parse_list = | 301 GrowableHandlePtrArray<const Class> patch_list(thread->zone(), 4); |
| 300 GrowableObjectArray::Handle(thread->zone(), GrowableObjectArray::New(4)); | |
| 301 const GrowableObjectArray& patch_list = | |
| 302 GrowableObjectArray::Handle(thread->zone(), GrowableObjectArray::New(4)); | |
| 303 | 302 |
| 304 // Parse the class and all the interfaces it implements and super classes. | 303 // Parse the class and all the interfaces it implements and super classes. |
| 305 LongJumpScope jump; | 304 LongJumpScope jump; |
| 306 if (setjmp(*jump.Set()) == 0) { | 305 if (setjmp(*jump.Set()) == 0) { |
| 307 StackZone zone(thread); | |
| 308 if (FLAG_trace_compiler) { | 306 if (FLAG_trace_compiler) { |
| 309 ISL_Print("Compiling Class %s '%s'\n", "", cls.ToCString()); | 307 ISL_Print("Compiling Class %s '%s'\n", "", cls.ToCString()); |
| 310 } | 308 } |
| 311 | 309 |
| 312 // Add the primary class which needs to be parsed to the parse list. | 310 // Add the primary class which needs to be parsed to the parse list. |
| 313 // Mark the class as parsed so that we don't recursively add the same | 311 // Mark the class as parsed so that we don't recursively add the same |
| 314 // class back into the list. | 312 // class back into the list. |
| 315 parse_list.Add(cls); | 313 parse_list.Add(cls); |
| 316 cls.set_is_marked_for_parsing(); | 314 cls.set_is_marked_for_parsing(); |
| 317 | 315 |
| 318 // Add all super classes, interface classes and patch class if one | 316 // Add all super classes, interface classes and patch class if one |
| 319 // exists to the corresponding lists. | 317 // exists to the corresponding lists. |
| 320 // NOTE: The parse_list array keeps growing as more classes are added | 318 // NOTE: The parse_list array keeps growing as more classes are added |
| 321 // to it by AddRelatedClassesToList. It is not OK to hoist | 319 // to it by AddRelatedClassesToList. It is not OK to hoist |
| 322 // parse_list.Length() into a local variable and iterate using the local | 320 // parse_list.Length() into a local variable and iterate using the local |
| 323 // variable. | 321 // variable. |
| 324 for (intptr_t i = 0; i < parse_list.Length(); i++) { | 322 for (intptr_t i = 0; i < parse_list.length(); i++) { |
| 325 parse_class ^= parse_list.At(i); | 323 AddRelatedClassesToList(parse_list.At(i), &parse_list, &patch_list); |
| 326 AddRelatedClassesToList(parse_class, parse_list, patch_list); | |
| 327 } | 324 } |
| 328 | 325 |
| 329 // Parse all the classes that have been added above. | 326 // Parse all the classes that have been added above. |
| 330 for (intptr_t i = (parse_list.Length() - 1); i >=0 ; i--) { | 327 for (intptr_t i = (parse_list.length() - 1); i >=0 ; i--) { |
| 331 parse_class ^= parse_list.At(i); | 328 const Class& parse_class = parse_list.At(i); |
| 332 ASSERT(!parse_class.IsNull()); | 329 ASSERT(!parse_class.IsNull()); |
| 333 Parser::ParseClass(parse_class); | 330 Parser::ParseClass(parse_class); |
| 334 } | 331 } |
| 335 | 332 |
| 336 // Parse all the patch classes that have been added above. | 333 // Parse all the patch classes that have been added above. |
| 337 for (intptr_t i = 0; i < patch_list.Length(); i++) { | 334 for (intptr_t i = 0; i < patch_list.length(); i++) { |
| 338 parse_class ^= patch_list.At(i); | 335 const Class& parse_class = patch_list.At(i); |
| 339 ASSERT(!parse_class.IsNull()); | 336 ASSERT(!parse_class.IsNull()); |
| 340 Parser::ParseClass(parse_class); | 337 Parser::ParseClass(parse_class); |
| 341 } | 338 } |
| 342 | 339 |
| 343 // Finalize these classes. | 340 // Finalize these classes. |
| 344 for (intptr_t i = (parse_list.Length() - 1); i >=0 ; i--) { | 341 for (intptr_t i = (parse_list.length() - 1); i >=0 ; i--) { |
| 345 parse_class ^= parse_list.At(i); | 342 const Class& parse_class = parse_list.At(i); |
| 346 ASSERT(!parse_class.IsNull()); | 343 ASSERT(!parse_class.IsNull()); |
| 347 ClassFinalizer::FinalizeClass(parse_class); | 344 ClassFinalizer::FinalizeClass(parse_class); |
| 348 parse_class.reset_is_marked_for_parsing(); | 345 parse_class.reset_is_marked_for_parsing(); |
| 349 } | 346 } |
| 350 for (intptr_t i = (patch_list.Length() - 1); i >=0 ; i--) { | 347 for (intptr_t i = (patch_list.length() - 1); i >=0 ; i--) { |
| 351 parse_class ^= patch_list.At(i); | 348 const Class& parse_class = patch_list.At(i); |
| 352 ASSERT(!parse_class.IsNull()); | 349 ASSERT(!parse_class.IsNull()); |
| 353 ClassFinalizer::FinalizeClass(parse_class); | 350 ClassFinalizer::FinalizeClass(parse_class); |
| 354 parse_class.reset_is_marked_for_parsing(); | 351 parse_class.reset_is_marked_for_parsing(); |
| 355 } | 352 } |
| 356 | 353 |
| 357 return Error::null(); | 354 return Error::null(); |
| 358 } else { | 355 } else { |
| 359 // Reset the marked for parsing flags. | 356 // Reset the marked for parsing flags. |
| 360 for (intptr_t i = 0; i < parse_list.Length(); i++) { | 357 for (intptr_t i = 0; i < parse_list.length(); i++) { |
| 361 parse_class ^= parse_list.At(i); | 358 const Class& parse_class = parse_list.At(i); |
| 362 if (parse_class.is_marked_for_parsing()) { | 359 if (parse_class.is_marked_for_parsing()) { |
| 363 parse_class.reset_is_marked_for_parsing(); | 360 parse_class.reset_is_marked_for_parsing(); |
| 364 } | 361 } |
| 365 } | 362 } |
| 366 for (intptr_t i = 0; i < patch_list.Length(); i++) { | 363 for (intptr_t i = 0; i < patch_list.length(); i++) { |
| 367 parse_class ^= patch_list.At(i); | 364 const Class& parse_class = patch_list.At(i); |
| 368 if (parse_class.is_marked_for_parsing()) { | 365 if (parse_class.is_marked_for_parsing()) { |
| 369 parse_class.reset_is_marked_for_parsing(); | 366 parse_class.reset_is_marked_for_parsing(); |
| 370 } | 367 } |
| 371 } | 368 } |
| 372 Thread* const thread = Thread::Current(); | |
| 373 Isolate* const isolate = Isolate::Current(); | |
| 374 StackZone zone(thread); | |
| 375 Error& error = Error::Handle(isolate); | 369 Error& error = Error::Handle(isolate); |
| 376 error = isolate->object_store()->sticky_error(); | 370 error = isolate->object_store()->sticky_error(); |
| 377 isolate->object_store()->clear_sticky_error(); | 371 isolate->object_store()->clear_sticky_error(); |
| 378 return error.raw(); | 372 return error.raw(); |
| 379 } | 373 } |
| 380 UNREACHABLE(); | 374 UNREACHABLE(); |
| 381 return Error::null(); | 375 return Error::null(); |
| 382 } | 376 } |
| 383 | 377 |
| 384 | 378 |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 const Object& result = | 1421 const Object& result = |
| 1428 PassiveObject::Handle(isolate->object_store()->sticky_error()); | 1422 PassiveObject::Handle(isolate->object_store()->sticky_error()); |
| 1429 isolate->object_store()->clear_sticky_error(); | 1423 isolate->object_store()->clear_sticky_error(); |
| 1430 return result.raw(); | 1424 return result.raw(); |
| 1431 } | 1425 } |
| 1432 UNREACHABLE(); | 1426 UNREACHABLE(); |
| 1433 return Object::null(); | 1427 return Object::null(); |
| 1434 } | 1428 } |
| 1435 | 1429 |
| 1436 } // namespace dart | 1430 } // namespace dart |
| OLD | NEW |