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

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

Issue 1406943006: Pass type argument to Field construction, thus freezing that field, denoting it cannot be changed l… (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: c Created 5 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
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 1548 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 Field& field = Field::Handle(zone); 1559 Field& field = Field::Handle(zone);
1560 Smi& value = Smi::Handle(zone); 1560 Smi& value = Smi::Handle(zone);
1561 String& field_name = String::Handle(zone); 1561 String& field_name = String::Handle(zone);
1562 1562
1563 #define CLASS_LIST_WITH_NULL(V) \ 1563 #define CLASS_LIST_WITH_NULL(V) \
1564 V(Null) \ 1564 V(Null) \
1565 CLASS_LIST_NO_OBJECT(V) 1565 CLASS_LIST_NO_OBJECT(V)
1566 1566
1567 #define ADD_SET_FIELD(clazz) \ 1567 #define ADD_SET_FIELD(clazz) \
1568 field_name = Symbols::New("cid"#clazz); \ 1568 field_name = Symbols::New("cid"#clazz); \
1569 field = Field::New(field_name, true, false, true, false, cls, 0); \ 1569 field = Field::New(field_name, true, false, true, false, cls, \
1570 Type::Handle(Type::IntType()), 0); \
1570 value = Smi::New(k##clazz##Cid); \ 1571 value = Smi::New(k##clazz##Cid); \
1571 field.SetStaticValue(value, true); \ 1572 field.SetStaticValue(value, true); \
1572 field.set_type(Type::Handle(Type::IntType())); \
1573 cls.AddField(field); \ 1573 cls.AddField(field); \
1574 1574
1575 CLASS_LIST_WITH_NULL(ADD_SET_FIELD) 1575 CLASS_LIST_WITH_NULL(ADD_SET_FIELD)
1576 #undef ADD_SET_FIELD 1576 #undef ADD_SET_FIELD
1577 1577
1578 isolate->object_store()->InitKnownObjects(); 1578 isolate->object_store()->InitKnownObjects();
1579 1579
1580 return Error::null(); 1580 return Error::null();
1581 #else // defined(DART_NO_SNAPSHOT). 1581 #else // defined(DART_NO_SNAPSHOT).
1582 // Object::Init version when we are running in a version of dart that has 1582 // Object::Init version when we are running in a version of dart that has
(...skipping 5883 matching lines...) Expand 10 before | Expand all | Expand 10 after
7466 RawClass* Field::origin() const { 7466 RawClass* Field::origin() const {
7467 const Object& obj = Object::Handle(raw_ptr()->owner_); 7467 const Object& obj = Object::Handle(raw_ptr()->owner_);
7468 if (obj.IsClass()) { 7468 if (obj.IsClass()) {
7469 return Class::Cast(obj).raw(); 7469 return Class::Cast(obj).raw();
7470 } 7470 }
7471 ASSERT(obj.IsPatchClass()); 7471 ASSERT(obj.IsPatchClass());
7472 return PatchClass::Cast(obj).source_class(); 7472 return PatchClass::Cast(obj).source_class();
7473 } 7473 }
7474 7474
7475 7475
7476 void Field::set_type(const AbstractType& value) const { 7476 // Called at finalization time
7477 void Field::SetFieldType(const AbstractType& value) const {
7478 ASSERT(Thread::Current()->IsMutatorThread());
7477 ASSERT(!value.IsNull()); 7479 ASSERT(!value.IsNull());
7478 StorePointer(&raw_ptr()->type_, value.raw()); 7480 if (value.raw() != type()) {
7481 StorePointer(&raw_ptr()->type_, value.raw());
7482 }
7479 } 7483 }
7480 7484
7481 7485
7482 RawField* Field::New() { 7486 RawField* Field::New() {
7483 ASSERT(Object::field_class() != Class::null()); 7487 ASSERT(Object::field_class() != Class::null());
7484 RawObject* raw = Object::Allocate(Field::kClassId, 7488 RawObject* raw = Object::Allocate(Field::kClassId,
7485 Field::InstanceSize(), 7489 Field::InstanceSize(),
7486 Heap::kOld); 7490 Heap::kOld);
7487 return reinterpret_cast<RawField*>(raw); 7491 return reinterpret_cast<RawField*>(raw);
7488 } 7492 }
7489 7493
7490 7494
7491 RawField* Field::New(const String& name, 7495 RawField* Field::New(const String& name,
7492 bool is_static, 7496 bool is_static,
7493 bool is_final, 7497 bool is_final,
7494 bool is_const, 7498 bool is_const,
7495 bool is_reflectable, 7499 bool is_reflectable,
7496 const Class& owner, 7500 const Class& owner,
7501 const AbstractType& type,
7497 intptr_t token_pos) { 7502 intptr_t token_pos) {
7498 ASSERT(!owner.IsNull()); 7503 ASSERT(!owner.IsNull());
7499 const Field& result = Field::Handle(Field::New()); 7504 const Field& result = Field::Handle(Field::New());
7500 result.set_name(name); 7505 result.set_name(name);
7501 result.set_is_static(is_static); 7506 result.set_is_static(is_static);
7502 if (!is_static) { 7507 if (!is_static) {
7503 result.SetOffset(0); 7508 result.SetOffset(0);
7504 } 7509 }
7505 result.set_is_final(is_final); 7510 result.set_is_final(is_final);
7506 result.set_is_const(is_const); 7511 result.set_is_const(is_const);
7507 result.set_is_reflectable(is_reflectable); 7512 result.set_is_reflectable(is_reflectable);
7508 result.set_is_double_initialized(false); 7513 result.set_is_double_initialized(false);
7509 result.set_owner(owner); 7514 result.set_owner(owner);
7515 result.SetFieldType(type);
7510 result.set_token_pos(token_pos); 7516 result.set_token_pos(token_pos);
7511 result.set_has_initializer(false); 7517 result.set_has_initializer(false);
7512 result.set_is_unboxing_candidate(true); 7518 result.set_is_unboxing_candidate(true);
7513 result.set_guarded_cid(FLAG_use_field_guards ? kIllegalCid : kDynamicCid); 7519 result.set_guarded_cid(FLAG_use_field_guards ? kIllegalCid : kDynamicCid);
7514 result.set_is_nullable(FLAG_use_field_guards ? false : true); 7520 result.set_is_nullable(FLAG_use_field_guards ? false : true);
7515 result.set_guarded_list_length_in_object_offset(Field::kUnknownLengthOffset); 7521 result.set_guarded_list_length_in_object_offset(Field::kUnknownLengthOffset);
7516 // Presently, we only attempt to remember the list length for final fields. 7522 // Presently, we only attempt to remember the list length for final fields.
7517 if (is_final && FLAG_use_field_guards) { 7523 if (is_final && FLAG_use_field_guards) {
7518 result.set_guarded_list_length(Field::kUnknownFixedLength); 7524 result.set_guarded_list_length(Field::kUnknownFixedLength);
7519 } else { 7525 } else {
(...skipping 11 matching lines...) Expand all
7531 const PatchClass& clone_owner = 7537 const PatchClass& clone_owner =
7532 PatchClass::Handle(PatchClass::New(new_owner, owner)); 7538 PatchClass::Handle(PatchClass::New(new_owner, owner));
7533 clone.set_owner(clone_owner); 7539 clone.set_owner(clone_owner);
7534 if (!clone.is_static()) { 7540 if (!clone.is_static()) {
7535 clone.SetOffset(0); 7541 clone.SetOffset(0);
7536 } 7542 }
7537 if (new_owner.NumTypeParameters() > 0) { 7543 if (new_owner.NumTypeParameters() > 0) {
7538 // Adjust the field type to refer to type parameters of the new owner. 7544 // Adjust the field type to refer to type parameters of the new owner.
7539 AbstractType& type = AbstractType::Handle(clone.type()); 7545 AbstractType& type = AbstractType::Handle(clone.type());
7540 type ^= type.CloneUninstantiated(new_owner); 7546 type ^= type.CloneUninstantiated(new_owner);
7541 clone.set_type(type); 7547 clone.SetFieldType(type);
7542 } 7548 }
7543 return clone.raw(); 7549 return clone.raw();
7544 } 7550 }
7545 7551
7546 7552
7547 RawString* Field::PrettyName() const { 7553 RawString* Field::PrettyName() const {
7548 const String& str = String::Handle(name()); 7554 const String& str = String::Handle(name());
7549 return String::IdentifierPrettyName(str); 7555 return String::IdentifierPrettyName(str);
7550 } 7556 }
7551 7557
7552 7558
7553 RawString* Field::UserVisibleName() const { 7559 RawString* Field::UserVisibleName() const {
7554 return PrettyName(); 7560 return PrettyName();
7555 } 7561 }
7556 7562
7557 7563
7558 intptr_t Field::guarded_list_length() const { 7564 intptr_t Field::guarded_list_length() const {
7559 return Smi::Value(raw_ptr()->guarded_list_length_); 7565 return Smi::Value(raw_ptr()->guarded_list_length_);
7560 } 7566 }
7561 7567
7562 7568
7563 void Field::set_guarded_list_length(intptr_t list_length) const { 7569 void Field::set_guarded_list_length(intptr_t list_length) const {
7570 ASSERT(Thread::Current()->IsMutatorThread());
7564 StoreSmi(&raw_ptr()->guarded_list_length_, Smi::New(list_length)); 7571 StoreSmi(&raw_ptr()->guarded_list_length_, Smi::New(list_length));
7565 } 7572 }
7566 7573
7567 7574
7568 intptr_t Field::guarded_list_length_in_object_offset() const { 7575 intptr_t Field::guarded_list_length_in_object_offset() const {
7569 return raw_ptr()->guarded_list_length_in_object_offset_ + kHeapObjectTag; 7576 return raw_ptr()->guarded_list_length_in_object_offset_ + kHeapObjectTag;
7570 } 7577 }
7571 7578
7572 7579
7573 void Field::set_guarded_list_length_in_object_offset( 7580 void Field::set_guarded_list_length_in_object_offset(
7574 intptr_t list_length_offset) const { 7581 intptr_t list_length_offset) const {
7582 ASSERT(Thread::Current()->IsMutatorThread());
7575 StoreNonPointer(&raw_ptr()->guarded_list_length_in_object_offset_, 7583 StoreNonPointer(&raw_ptr()->guarded_list_length_in_object_offset_,
7576 static_cast<int8_t>(list_length_offset - kHeapObjectTag)); 7584 static_cast<int8_t>(list_length_offset - kHeapObjectTag));
7577 ASSERT(guarded_list_length_in_object_offset() == list_length_offset); 7585 ASSERT(guarded_list_length_in_object_offset() == list_length_offset);
7578 } 7586 }
7579 7587
7580 7588
7581 const char* Field::ToCString() const { 7589 const char* Field::ToCString() const {
7582 if (IsNull()) { 7590 if (IsNull()) {
7583 return "Field::null"; 7591 return "Field::null";
7584 } 7592 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
7692 // The caller may expect the closure to be allocated in old space. Copy 7700 // The caller may expect the closure to be allocated in old space. Copy
7693 // the result here, since Object::Clone() is a private method. 7701 // the result here, since Object::Clone() is a private method.
7694 result = Object::Clone(result, Heap::kOld); 7702 result = Object::Clone(result, Heap::kOld);
7695 7703
7696 closure_field = Field::New(closure_name, 7704 closure_field = Field::New(closure_name,
7697 true, // is_static 7705 true, // is_static
7698 true, // is_final 7706 true, // is_final
7699 true, // is_const 7707 true, // is_const
7700 false, // is_reflectable 7708 false, // is_reflectable
7701 field_owner, 7709 field_owner,
7710 Object::dynamic_type(),
7702 this->token_pos()); 7711 this->token_pos());
7703 closure_field.SetStaticValue(Instance::Cast(result), true); 7712 closure_field.SetStaticValue(Instance::Cast(result), true);
7704 closure_field.set_type(Object::dynamic_type());
7705 field_owner.AddField(closure_field); 7713 field_owner.AddField(closure_field);
7706 7714
7707 return Instance::RawCast(result.raw()); 7715 return Instance::RawCast(result.raw());
7708 } 7716 }
7709 7717
7710 7718
7711 RawInstance* Field::GetterClosure() const { 7719 RawInstance* Field::GetterClosure() const {
7712 return AccessorClosure(false); 7720 return AccessorClosure(false);
7713 } 7721 }
7714 7722
(...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after
9375 void Library::AddMetadata(const Class& cls, 9383 void Library::AddMetadata(const Class& cls,
9376 const String& name, 9384 const String& name,
9377 intptr_t token_pos) const { 9385 intptr_t token_pos) const {
9378 const String& metaname = String::Handle(Symbols::New(name)); 9386 const String& metaname = String::Handle(Symbols::New(name));
9379 Field& field = Field::Handle(Field::New(metaname, 9387 Field& field = Field::Handle(Field::New(metaname,
9380 true, // is_static 9388 true, // is_static
9381 false, // is_final 9389 false, // is_final
9382 false, // is_const 9390 false, // is_const
9383 false, // is_reflectable 9391 false, // is_reflectable
9384 cls, 9392 cls,
9393 Object::dynamic_type(),
9385 token_pos)); 9394 token_pos));
9386 field.set_type(Object::dynamic_type());
9387 field.SetStaticValue(Array::empty_array(), true); 9395 field.SetStaticValue(Array::empty_array(), true);
9388 GrowableObjectArray& metadata = 9396 GrowableObjectArray& metadata =
9389 GrowableObjectArray::Handle(this->metadata()); 9397 GrowableObjectArray::Handle(this->metadata());
9390 metadata.Add(field, Heap::kOld); 9398 metadata.Add(field, Heap::kOld);
9391 cls.AddField(field); 9399 cls.AddField(field);
9392 } 9400 }
9393 9401
9394 9402
9395 void Library::AddClassMetadata(const Class& cls, 9403 void Library::AddClassMetadata(const Class& cls,
9396 const Class& toplevel_class, 9404 const Class& toplevel_class,
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after
10897 10905
10898 10906
10899 void Namespace::AddMetadata(intptr_t token_pos, const Class& owner_class) { 10907 void Namespace::AddMetadata(intptr_t token_pos, const Class& owner_class) {
10900 ASSERT(Field::Handle(metadata_field()).IsNull()); 10908 ASSERT(Field::Handle(metadata_field()).IsNull());
10901 Field& field = Field::Handle(Field::New(Symbols::TopLevel(), 10909 Field& field = Field::Handle(Field::New(Symbols::TopLevel(),
10902 true, // is_static 10910 true, // is_static
10903 false, // is_final 10911 false, // is_final
10904 false, // is_const 10912 false, // is_const
10905 false, // is_reflectable 10913 false, // is_reflectable
10906 owner_class, 10914 owner_class,
10915 Object::dynamic_type(),
10907 token_pos)); 10916 token_pos));
10908 field.set_type(Object::dynamic_type());
10909 field.SetStaticValue(Array::empty_array(), true); 10917 field.SetStaticValue(Array::empty_array(), true);
10910 set_metadata_field(field); 10918 set_metadata_field(field);
10911 owner_class.AddField(field); 10919 owner_class.AddField(field);
10912 } 10920 }
10913 10921
10914 10922
10915 RawObject* Namespace::GetMetadata() const { 10923 RawObject* Namespace::GetMetadata() const {
10916 Field& field = Field::Handle(metadata_field()); 10924 Field& field = Field::Handle(metadata_field());
10917 if (field.IsNull()) { 10925 if (field.IsNull()) {
10918 // There is no metadata for this object. 10926 // There is no metadata for this object.
(...skipping 11006 matching lines...) Expand 10 before | Expand all | Expand 10 after
21925 return tag_label.ToCString(); 21933 return tag_label.ToCString();
21926 } 21934 }
21927 21935
21928 21936
21929 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21937 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21930 Instance::PrintJSONImpl(stream, ref); 21938 Instance::PrintJSONImpl(stream, ref);
21931 } 21939 }
21932 21940
21933 21941
21934 } // namespace dart 21942 } // namespace dart
OLDNEW
« runtime/vm/object.h ('K') | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698