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

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

Issue 269253005: Put metadata fields in their owner class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 | 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 2776 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 for (intptr_t i = 0; i < len; i++) { 2787 for (intptr_t i = 0; i < len; i++) {
2788 field ^= value.At(i); 2788 field ^= value.At(i);
2789 ASSERT(field.owner() == raw()); 2789 ASSERT(field.owner() == raw());
2790 } 2790 }
2791 #endif 2791 #endif
2792 // The value of static fields is already initialized to null. 2792 // The value of static fields is already initialized to null.
2793 StorePointer(&raw_ptr()->fields_, value.raw()); 2793 StorePointer(&raw_ptr()->fields_, value.raw());
2794 } 2794 }
2795 2795
2796 2796
2797 void Class::AddField(const Field& field) const {
2798 const Array& arr = Array::Handle(fields());
2799 const Array& new_arr = Array::Handle(Array::Grow(arr, arr.Length() + 1));
regis 2014/05/08 16:39:11 By default, Array::Grow will allocate in the new s
rmacnak 2014/05/08 18:14:54 This path will only be hit when we encounter metad
2800 new_arr.SetAt(arr.Length(), field);
2801 SetFields(new_arr);
2802 }
2803
2804
2805 void Class::AddFields(const GrowableObjectArray& new_fields) const {
2806 const intptr_t num_new_fields = new_fields.Length();
2807 if (num_new_fields == 0) return;
2808 const Array& arr = Array::Handle(fields());
2809 const intptr_t num_old_fields = arr.Length();
2810 const Array& new_arr =
2811 Array::Handle(Array::Grow(arr, num_old_fields + num_new_fields));
regis 2014/05/08 16:39:11 ditto
rmacnak 2014/05/08 18:14:54 This will happen once when we parse the class memb
2812 Field& field = Field::Handle();
2813 for (intptr_t i = 0; i < num_new_fields; i++) {
2814 field ^= new_fields.At(i);
2815 new_arr.SetAt(i + num_old_fields, field);
2816 }
2817 SetFields(new_arr);
2818 }
2819
2820
2797 intptr_t Class::FindFieldIndex(const Field& needle) const { 2821 intptr_t Class::FindFieldIndex(const Field& needle) const {
2798 Isolate* isolate = Isolate::Current(); 2822 Isolate* isolate = Isolate::Current();
2799 if (EnsureIsFinalized(isolate) != Error::null()) { 2823 if (EnsureIsFinalized(isolate) != Error::null()) {
2800 return -1; 2824 return -1;
2801 } 2825 }
2802 REUSABLE_ARRAY_HANDLESCOPE(isolate); 2826 REUSABLE_ARRAY_HANDLESCOPE(isolate);
2803 REUSABLE_FIELD_HANDLESCOPE(isolate); 2827 REUSABLE_FIELD_HANDLESCOPE(isolate);
2804 REUSABLE_STRING_HANDLESCOPE(isolate); 2828 REUSABLE_STRING_HANDLESCOPE(isolate);
2805 Array& fields_array = isolate->ArrayHandle(); 2829 Array& fields_array = isolate->ArrayHandle();
2806 Field& field = isolate->FieldHandle(); 2830 Field& field = isolate->FieldHandle();
(...skipping 5454 matching lines...) Expand 10 before | Expand all | Expand 10 after
8261 true, // is_static 8285 true, // is_static
8262 false, // is_final 8286 false, // is_final
8263 false, // is_const 8287 false, // is_const
8264 cls, 8288 cls,
8265 token_pos)); 8289 token_pos));
8266 field.set_type(Type::Handle(Type::DynamicType())); 8290 field.set_type(Type::Handle(Type::DynamicType()));
8267 field.set_value(Array::empty_array()); 8291 field.set_value(Array::empty_array());
8268 GrowableObjectArray& metadata = 8292 GrowableObjectArray& metadata =
8269 GrowableObjectArray::Handle(this->metadata()); 8293 GrowableObjectArray::Handle(this->metadata());
8270 metadata.Add(field, Heap::kOld); 8294 metadata.Add(field, Heap::kOld);
8295 cls.AddField(field);
8271 } 8296 }
8272 8297
8273 8298
8274 void Library::AddClassMetadata(const Class& cls, 8299 void Library::AddClassMetadata(const Class& cls,
8275 const Class& toplevel_class, 8300 const Class& toplevel_class,
8276 intptr_t token_pos) const { 8301 intptr_t token_pos) const {
8277 // We use the toplevel class as the owner of a class's metadata field because 8302 // We use the toplevel class as the owner of a class's metadata field because
8278 // a class's metadata is in scope of the library, not the class. 8303 // a class's metadata is in scope of the library, not the class.
8279 AddMetadata(toplevel_class, 8304 AddMetadata(toplevel_class,
8280 String::Handle(MakeClassMetaName(cls)), 8305 String::Handle(MakeClassMetaName(cls)),
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after
9634 ASSERT(Field::Handle(metadata_field()).IsNull()); 9659 ASSERT(Field::Handle(metadata_field()).IsNull());
9635 Field& field = Field::Handle(Field::New(Symbols::TopLevel(), 9660 Field& field = Field::Handle(Field::New(Symbols::TopLevel(),
9636 true, // is_static 9661 true, // is_static
9637 false, // is_final 9662 false, // is_final
9638 false, // is_const 9663 false, // is_const
9639 owner_class, 9664 owner_class,
9640 token_pos)); 9665 token_pos));
9641 field.set_type(Type::Handle(Type::DynamicType())); 9666 field.set_type(Type::Handle(Type::DynamicType()));
9642 field.set_value(Array::empty_array()); 9667 field.set_value(Array::empty_array());
9643 set_metadata_field(field); 9668 set_metadata_field(field);
9669 owner_class.AddField(field);
9644 } 9670 }
9645 9671
9646 9672
9647 RawObject* Namespace::GetMetadata() const { 9673 RawObject* Namespace::GetMetadata() const {
9648 Field& field = Field::Handle(metadata_field()); 9674 Field& field = Field::Handle(metadata_field());
9649 if (field.IsNull()) { 9675 if (field.IsNull()) {
9650 // There is no metadata for this object. 9676 // There is no metadata for this object.
9651 return Object::empty_array().raw(); 9677 return Object::empty_array().raw();
9652 } 9678 }
9653 Object& metadata = Object::Handle(); 9679 Object& metadata = Object::Handle();
(...skipping 9133 matching lines...) Expand 10 before | Expand all | Expand 10 after
18787 return tag_label.ToCString(); 18813 return tag_label.ToCString();
18788 } 18814 }
18789 18815
18790 18816
18791 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 18817 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
18792 Instance::PrintJSONImpl(stream, ref); 18818 Instance::PrintJSONImpl(stream, ref);
18793 } 18819 }
18794 18820
18795 18821
18796 } // namespace dart 18822 } // 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