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

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

Issue 16780008: Reified metadata in the VM (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5973 matching lines...) Expand 10 before | Expand all | Expand 10 after
5984 } 5984 }
5985 5985
5986 5986
5987 void Library::SetLoadError() const { 5987 void Library::SetLoadError() const {
5988 // Should not be already loaded or just allocated. 5988 // Should not be already loaded or just allocated.
5989 ASSERT(LoadInProgress()); 5989 ASSERT(LoadInProgress());
5990 raw_ptr()->load_state_ = RawLibrary::kLoadError; 5990 raw_ptr()->load_state_ = RawLibrary::kLoadError;
5991 } 5991 }
5992 5992
5993 5993
5994 static RawString* MakeClassMetaName(const Class& cls) {
5995 String& cname = String::Handle(cls.Name());
5996 return String::Concat(Symbols::At(), cname);
5997 }
5998
5999
6000 static RawString* MakeFieldMetaName(const Field& field) {
6001 const String& cname =
6002 String::Handle(MakeClassMetaName(Class::Handle(field.origin())));
6003 String& fname = String::Handle(field.name());
6004 fname = String::Concat(Symbols::At(), fname);
6005 return String::Concat(cname, fname);
6006 }
6007
6008
6009 static RawString* MakeFunctionMetaName(const Function& func) {
6010 const String& cname =
6011 String::Handle(MakeClassMetaName(Class::Handle(func.origin())));
6012 String& fname = String::Handle(func.name());
6013 fname = String::Concat(Symbols::At(), fname);
6014 return String::Concat(cname, fname);
6015 }
6016
6017
6018 void Library::AddMetadata(const Class& cls,
6019 const String& name,
6020 intptr_t token_pos) const {
6021 const String& metaname = String::Handle(Symbols::New(name));
6022 Field& field = Field::Handle(Field::New(metaname,
6023 true, // is_static
6024 false, // is_final
6025 false, // is_const
6026 cls,
6027 token_pos));
6028 field.set_type(Type::Handle(Type::DynamicType()));
6029 field.set_value(Array::empty_array());
6030 GrowableObjectArray& metadata =
6031 GrowableObjectArray::Handle(this->metadata());
6032 metadata.Add(field, Heap::kOld);
6033 }
6034
6035
6036 void Library::AddClassMetadata(const Class& cls, intptr_t token_pos) const {
6037 AddMetadata(cls, String::Handle(MakeClassMetaName(cls)), token_pos);
6038 }
6039
6040
6041 void Library::AddFieldMetadata(const Field& field,
6042 intptr_t token_pos) const {
6043 AddMetadata(Class::Handle(field.origin()),
6044 String::Handle(MakeFieldMetaName(field)),
6045 token_pos);
6046 }
6047
6048
6049 void Library::AddFunctionMetadata(const Function& func,
6050 intptr_t token_pos) const {
6051 AddMetadata(Class::Handle(func.origin()),
6052 String::Handle(MakeFunctionMetaName(func)),
6053 token_pos);
6054 }
6055
6056
6057 RawString* Library::MakeMetadataName(const Object& obj) const {
6058 if (obj.IsClass()) {
6059 return MakeClassMetaName(Class::Cast(obj));
6060 } else if (obj.IsField()) {
6061 return MakeFieldMetaName(Field::Cast(obj));
6062 } else if (obj.IsFunction()) {
6063 return MakeFunctionMetaName(Function::Cast(obj));
6064 }
6065 UNIMPLEMENTED();
6066 return String::null();
6067 }
6068
6069
6070 RawField* Library::GetMetadataField(const String& metaname) const {
6071 const GrowableObjectArray& metadata =
6072 GrowableObjectArray::Handle(this->metadata());
6073 Field& entry = Field::Handle();
6074 String& entryname = String::Handle();
6075 intptr_t num_entries = metadata.Length();
6076 for (intptr_t i = 0; i < num_entries; i++) {
6077 entry ^= metadata.At(i);
6078 entryname = entry.name();
6079 if (entryname.Equals(metaname)) {
6080 return entry.raw();
6081 }
6082 }
6083 return Field::null();
6084 }
6085
6086
6087 RawObject* Library::GetMetadata(const Object& obj) const {
6088 if (!obj.IsClass() && !obj.IsField() && !obj.IsFunction()) {
6089 return Object::null();
6090 }
6091 const String& metaname = String::Handle(MakeMetadataName(obj));
6092 Field& field = Field::Handle(GetMetadataField(metaname));
6093 if (field.IsNull()) {
6094 // There is no metadata for this object.
6095 return Object::empty_array().raw();;
6096 }
6097 Object& metadata = Object::Handle();
6098 metadata = field.value();
6099 if (field.value() == Object::empty_array().raw()) {
6100 metadata = Parser::ParseMetadata(Class::Handle(field.owner()),
6101 field.token_pos());
6102 if (metadata.IsArray()) {
6103 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw());
6104 field.set_value(Array::Cast(metadata));
6105 }
6106 }
6107 return metadata.raw();
6108 }
6109
6110
5994 void Library::GrowDictionary(const Array& dict, intptr_t dict_size) const { 6111 void Library::GrowDictionary(const Array& dict, intptr_t dict_size) const {
5995 // TODO(iposva): Avoid exponential growth. 6112 // TODO(iposva): Avoid exponential growth.
5996 intptr_t new_dict_size = dict_size * 2; 6113 intptr_t new_dict_size = dict_size * 2;
5997 const Array& new_dict = 6114 const Array& new_dict =
5998 Array::Handle(Array::New(new_dict_size + 1, Heap::kOld)); 6115 Array::Handle(Array::New(new_dict_size + 1, Heap::kOld));
5999 // Rehash all elements from the original dictionary 6116 // Rehash all elements from the original dictionary
6000 // to the newly allocated array. 6117 // to the newly allocated array.
6001 Object& entry = Class::Handle(); 6118 Object& entry = Class::Handle();
6002 String& entry_name = String::Handle(); 6119 String& entry_name = String::Handle();
6003 Object& new_entry = Object::Handle(); 6120 Object& new_entry = Object::Handle();
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
6522 } 6639 }
6523 6640
6524 6641
6525 RawLibrary* Library::NewLibraryHelper(const String& url, 6642 RawLibrary* Library::NewLibraryHelper(const String& url,
6526 bool import_core_lib) { 6643 bool import_core_lib) {
6527 const Library& result = Library::Handle(Library::New()); 6644 const Library& result = Library::Handle(Library::New());
6528 result.StorePointer(&result.raw_ptr()->name_, url.raw()); 6645 result.StorePointer(&result.raw_ptr()->name_, url.raw());
6529 result.StorePointer(&result.raw_ptr()->url_, url.raw()); 6646 result.StorePointer(&result.raw_ptr()->url_, url.raw());
6530 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); 6647 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result);
6531 result.raw_ptr()->dictionary_ = Object::empty_array().raw(); 6648 result.raw_ptr()->dictionary_ = Object::empty_array().raw();
6649 result.StorePointer(&result.raw_ptr()->metadata_,
6650 GrowableObjectArray::New(4, Heap::kOld));
6532 result.raw_ptr()->anonymous_classes_ = Object::empty_array().raw(); 6651 result.raw_ptr()->anonymous_classes_ = Object::empty_array().raw();
6533 result.raw_ptr()->num_anonymous_ = 0; 6652 result.raw_ptr()->num_anonymous_ = 0;
6534 result.raw_ptr()->imports_ = Object::empty_array().raw(); 6653 result.raw_ptr()->imports_ = Object::empty_array().raw();
6535 result.raw_ptr()->exports_ = Object::empty_array().raw(); 6654 result.raw_ptr()->exports_ = Object::empty_array().raw();
6536 result.raw_ptr()->loaded_scripts_ = Array::null(); 6655 result.raw_ptr()->loaded_scripts_ = Array::null();
6537 result.set_native_entry_resolver(NULL); 6656 result.set_native_entry_resolver(NULL);
6538 result.raw_ptr()->corelib_imported_ = true; 6657 result.raw_ptr()->corelib_imported_ = true;
6539 result.set_debuggable(false); 6658 result.set_debuggable(false);
6540 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; 6659 result.raw_ptr()->load_state_ = RawLibrary::kAllocated;
6541 result.raw_ptr()->index_ = -1; 6660 result.raw_ptr()->index_ = -1;
(...skipping 6855 matching lines...) Expand 10 before | Expand all | Expand 10 after
13397 space); 13516 space);
13398 return reinterpret_cast<RawWeakProperty*>(raw); 13517 return reinterpret_cast<RawWeakProperty*>(raw);
13399 } 13518 }
13400 13519
13401 13520
13402 const char* WeakProperty::ToCString() const { 13521 const char* WeakProperty::ToCString() const {
13403 return "_WeakProperty"; 13522 return "_WeakProperty";
13404 } 13523 }
13405 13524
13406 } // namespace dart 13525 } // namespace dart
OLDNEW
« no previous file with comments | « 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