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

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

Issue 54713003: VM: Fix initialization of statics in presence of exceptions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | Annotate | Revision Log
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 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 4184 matching lines...) Expand 10 before | Expand all | Expand 10 after
4195 4195
4196 4196
4197 void Function::set_saved_args_desc(const Array& value) const { 4197 void Function::set_saved_args_desc(const Array& value) const {
4198 ASSERT(kind() == RawFunction::kNoSuchMethodDispatcher || 4198 ASSERT(kind() == RawFunction::kNoSuchMethodDispatcher ||
4199 kind() == RawFunction::kInvokeFieldDispatcher); 4199 kind() == RawFunction::kInvokeFieldDispatcher);
4200 ASSERT(raw_ptr()->data_ == Object::null()); 4200 ASSERT(raw_ptr()->data_ == Object::null());
4201 set_data(value); 4201 set_data(value);
4202 } 4202 }
4203 4203
4204 4204
4205 RawField* Function::saved_static_field() const {
4206 ASSERT(kind() == RawFunction::kStaticInitializer);
4207 const Object& obj = Object::Handle(raw_ptr()->data_);
4208 ASSERT(obj.IsField());
4209 return Field::Cast(obj).raw();
4210 }
4211
4212
4213 void Function::set_saved_static_field(const Field& value) const {
4214 ASSERT(kind() == RawFunction::kStaticInitializer);
4215 ASSERT(raw_ptr()->data_ == Object::null());
4216 set_data(value);
4217 }
4218
4219
4205 RawFunction* Function::parent_function() const { 4220 RawFunction* Function::parent_function() const {
4206 if (IsClosureFunction()) { 4221 if (IsClosureFunction()) {
4207 const Object& obj = Object::Handle(raw_ptr()->data_); 4222 const Object& obj = Object::Handle(raw_ptr()->data_);
4208 ASSERT(!obj.IsNull()); 4223 ASSERT(!obj.IsNull());
4209 return ClosureData::Cast(obj).parent_function(); 4224 return ClosureData::Cast(obj).parent_function();
4210 } 4225 }
4211 return Function::null(); 4226 return Function::null();
4212 } 4227 }
4213 4228
4214 4229
(...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after
5422 ToFullyQualifiedCString(), 5437 ToFullyQualifiedCString(),
5423 fp, 5438 fp,
5424 SourceFingerprint()); 5439 SourceFingerprint());
5425 return false; 5440 return false;
5426 } 5441 }
5427 } 5442 }
5428 return true; 5443 return true;
5429 } 5444 }
5430 5445
5431 5446
5432 RawFunction* Function::NewStaticInitializer(const String& field_name, 5447 RawFunction* Function::NewStaticInitializer(const Field& field) {
5433 const AbstractType& result_type, 5448 ASSERT(field.is_static());
5434 const Class& cls, 5449 const String& field_name = String::Handle(field.name());
5435 intptr_t initializer_pos) {
5436 const String& init_name = 5450 const String& init_name =
5437 String::Handle(Symbols::New(String::Handle( 5451 String::Handle(Symbols::New(String::Handle(
5438 String::Concat(Symbols::InitPrefix(), field_name)))); 5452 String::Concat(Symbols::InitPrefix(), field_name))));
5439 const Function& init_function = Function::ZoneHandle( 5453 const Function& init_function = Function::ZoneHandle(
5440 Function::New(init_name, 5454 Function::New(init_name,
5441 RawFunction::kStaticInitializer, 5455 RawFunction::kStaticInitializer,
5442 true, // static 5456 true, // static
5443 false, // !const 5457 false, // !const
5444 false, // !abstract 5458 false, // !abstract
5445 false, // !external 5459 false, // !external
5446 cls, 5460 Class::Handle(field.owner()),
5447 initializer_pos)); 5461 field.token_pos()));
5448 init_function.set_result_type(result_type); 5462 init_function.set_result_type(AbstractType::Handle(field.type()));
5449 // Static initializer functions are generated by the VM and are therfore 5463 // Static initializer functions are generated by the VM and are therfore
5450 // hidden from the user. Since they are only executed once, we avoid 5464 // hidden from the user. Since they are only executed once, we avoid
5451 // optimizing and inlining them. After the field is initialized, the 5465 // optimizing and inlining them. After the field is initialized, the
5452 // optimizing compiler can eliminate the call to the static initializer 5466 // optimizing compiler can eliminate the call to the static initializer
5453 // via constant folding. 5467 // via constant folding.
5454 init_function.set_is_visible(false); 5468 init_function.set_is_visible(false);
5455 init_function.set_is_optimizable(false); 5469 init_function.set_is_optimizable(false);
5456 init_function.set_is_inlinable(false); 5470 init_function.set_is_inlinable(false);
5471 init_function.set_saved_static_field(field);
5457 return init_function.raw(); 5472 return init_function.raw();
5458 } 5473 }
5459 5474
5460 5475
5461 const char* Function::ToCString() const { 5476 const char* Function::ToCString() const {
5462 const char* static_str = is_static() ? " static" : ""; 5477 const char* static_str = is_static() ? " static" : "";
5463 const char* abstract_str = is_abstract() ? " abstract" : ""; 5478 const char* abstract_str = is_abstract() ? " abstract" : "";
5464 const char* kind_str = NULL; 5479 const char* kind_str = NULL;
5465 const char* const_str = is_const() ? " const" : ""; 5480 const char* const_str = is_const() ? " const" : "";
5466 switch (kind()) { 5481 switch (kind()) {
(...skipping 10167 matching lines...) Expand 10 before | Expand all | Expand 10 after
15634 return "_MirrorReference"; 15649 return "_MirrorReference";
15635 } 15650 }
15636 15651
15637 15652
15638 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 15653 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
15639 JSONObject jsobj(stream); 15654 JSONObject jsobj(stream);
15640 } 15655 }
15641 15656
15642 15657
15643 } // namespace dart 15658 } // namespace dart
OLDNEW
« runtime/vm/class_finalizer.cc ('K') | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698