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

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

Issue 24075002: Expose field data, use class id, and merge all collections into "objects" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 2908 matching lines...) Expand 10 before | Expand all | Expand 10 after
2919 const char* library_name = lib.IsNull() ? "" : lib.ToCString(); 2919 const char* library_name = lib.IsNull() ? "" : lib.ToCString();
2920 const char* class_name = String::Handle(Name()).ToCString(); 2920 const char* class_name = String::Handle(Name()).ToCString();
2921 intptr_t len = OS::SNPrint(NULL, 0, format, library_name, class_name) + 1; 2921 intptr_t len = OS::SNPrint(NULL, 0, format, library_name, class_name) + 1;
2922 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 2922 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
2923 OS::SNPrint(chars, len, format, library_name, class_name); 2923 OS::SNPrint(chars, len, format, library_name, class_name);
2924 return chars; 2924 return chars;
2925 } 2925 }
2926 2926
2927 2927
2928 void Class::PrintToJSONStream(JSONStream* stream, bool ref) const { 2928 void Class::PrintToJSONStream(JSONStream* stream, bool ref) const {
2929 const char* class_name = String::Handle(UserVisibleName()).ToCString();
2930 ObjectIdRing* ring = Isolate::Current()->object_id_ring();
2931 intptr_t id = ring->GetIdForObject(raw());
2932 JSONObject jsobj(stream); 2929 JSONObject jsobj(stream);
2930 if ((raw() == Class::null()) || (id() == kFreeListElement)) {
2931 jsobj.AddProperty("type", "Null");
2932 return;
2933 }
2934 const char* internal_class_name = "<no name>";
2935 const char* user_visible_class_name = "<no name>";
2936 internal_class_name = String::Handle(Name()).ToCString();
2937 user_visible_class_name = String::Handle(UserVisibleName()).ToCString();
siva 2013/09/17 17:25:33 internal_class_name and user_visible_class_name ar
Cutch 2013/09/19 23:57:39 Done.
2933 jsobj.AddProperty("type", JSONType(ref)); 2938 jsobj.AddProperty("type", JSONType(ref));
2934 jsobj.AddProperty("id", id); 2939 jsobj.AddProperty("id", id());
2935 jsobj.AddProperty("name", class_name); 2940 jsobj.AddProperty("name", internal_class_name);
2941 jsobj.AddProperty("user_name", user_visible_class_name);
2936 if (!ref) { 2942 if (!ref) {
2943 jsobj.AddProperty("implemented", is_implemented());
2944 jsobj.AddProperty("abstract", is_abstract());
2945 jsobj.AddProperty("patch", is_patch());
2946 jsobj.AddProperty("finalized", is_finalized());
2947 jsobj.AddProperty("const", is_const());
2948 jsobj.AddProperty("super", Class::Handle(SuperClass()));
2937 jsobj.AddProperty("library", Object::Handle(library())); 2949 jsobj.AddProperty("library", Object::Handle(library()));
2950 {
2951 JSONArray fields_array(&jsobj, "fields");
2952 const Array& field_array = Array::Handle(fields());
2953 Field& field = Field::Handle();
2954 if (!field_array.IsNull()) {
2955 for (intptr_t i = 0; i < field_array.Length(); ++i) {
2956 field ^= field_array.At(i);
2957 fields_array.AddValue(field);
2958 }
2959 }
2960 }
2961 {
2962 JSONArray functions_array(&jsobj, "functions");
2963 const Array& function_array = Array::Handle(functions());
2964 Function& function = Function::Handle();
2965 if (!function_array.IsNull()) {
2966 for (intptr_t i = 0; i < function_array.Length(); i++) {
2967 function ^= function_array.At(i);
2968 functions_array.AddValue(function);
siva 2013/09/17 17:25:33 Do we only want to list the user defined functions
Cutch 2013/09/19 23:57:39 We should provide the complete list of functions a
2969 }
2970 }
2971 }
2938 } 2972 }
2939 } 2973 }
2940 2974
2941 2975
2942 void Class::InsertCanonicalConstant(intptr_t index, 2976 void Class::InsertCanonicalConstant(intptr_t index,
2943 const Instance& constant) const { 2977 const Instance& constant) const {
2944 // The constant needs to be added to the list. Grow the list if it is full. 2978 // The constant needs to be added to the list. Grow the list if it is full.
2945 Array& canonical_list = Array::Handle(constants()); 2979 Array& canonical_list = Array::Handle(constants());
2946 const intptr_t list_len = canonical_list.Length(); 2980 const intptr_t list_len = canonical_list.Length();
2947 if (index >= list_len) { 2981 if (index >= list_len) {
(...skipping 2135 matching lines...) Expand 10 before | Expand all | Expand 10 after
5083 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, 5117 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name,
5084 static_str, abstract_str, kind_str, const_str) + 1; 5118 static_str, abstract_str, kind_str, const_str) + 1;
5085 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 5119 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
5086 OS::SNPrint(chars, len, kFormat, function_name, 5120 OS::SNPrint(chars, len, kFormat, function_name,
5087 static_str, abstract_str, kind_str, const_str); 5121 static_str, abstract_str, kind_str, const_str);
5088 return chars; 5122 return chars;
5089 } 5123 }
5090 5124
5091 5125
5092 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { 5126 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const {
5127 const char* internal_function_name = String::Handle(name()).ToCString();
5093 const char* function_name = 5128 const char* function_name =
5094 String::Handle(QualifiedUserVisibleName()).ToCString(); 5129 String::Handle(QualifiedUserVisibleName()).ToCString();
5095 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); 5130 ObjectIdRing* ring = Isolate::Current()->object_id_ring();
5096 intptr_t id = ring->GetIdForObject(raw()); 5131 intptr_t id = ring->GetIdForObject(raw());
5097 JSONObject jsobj(stream); 5132 JSONObject jsobj(stream);
5098 jsobj.AddProperty("type", JSONType(ref)); 5133 jsobj.AddProperty("type", JSONType(ref));
5099 jsobj.AddProperty("id", id); 5134 jsobj.AddProperty("id", id);
5100 jsobj.AddProperty("name", function_name); 5135 jsobj.AddProperty("name", internal_function_name);
5136 jsobj.AddProperty("user_name", function_name);
5101 if (ref) return; 5137 if (ref) return;
5102 jsobj.AddProperty("is_static", is_static()); 5138 jsobj.AddProperty("is_static", is_static());
5103 jsobj.AddProperty("is_const", is_const()); 5139 jsobj.AddProperty("is_const", is_const());
5104 jsobj.AddProperty("is_optimizable", is_optimizable()); 5140 jsobj.AddProperty("is_optimizable", is_optimizable());
5105 jsobj.AddProperty("is_inlinable", IsInlineable()); 5141 jsobj.AddProperty("is_inlinable", IsInlineable());
5106 const char* kind_string = NULL; 5142 const char* kind_string = NULL;
5107 switch (kind()) { 5143 switch (kind()) {
5108 case RawFunction::kRegularFunction: 5144 case RawFunction::kRegularFunction:
5109 kind_string = "regular"; 5145 kind_string = "regular";
5110 break; 5146 break;
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
5405 intptr_t len = 5441 intptr_t len =
5406 OS::SNPrint(NULL, 0, kFormat, cls_name, field_name, kF0, kF1, kF2) + 1; 5442 OS::SNPrint(NULL, 0, kFormat, cls_name, field_name, kF0, kF1, kF2) + 1;
5407 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 5443 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
5408 OS::SNPrint(chars, len, kFormat, cls_name, field_name, kF0, kF1, kF2); 5444 OS::SNPrint(chars, len, kFormat, cls_name, field_name, kF0, kF1, kF2);
5409 return chars; 5445 return chars;
5410 } 5446 }
5411 5447
5412 5448
5413 void Field::PrintToJSONStream(JSONStream* stream, bool ref) const { 5449 void Field::PrintToJSONStream(JSONStream* stream, bool ref) const {
5414 JSONObject jsobj(stream); 5450 JSONObject jsobj(stream);
5451 const char* internal_field_name = String::Handle(name()).ToCString();
5452 const char* field_name = String::Handle(UserVisibleName()).ToCString();
5453 ObjectIdRing* ring = Isolate::Current()->object_id_ring();
5454 intptr_t id = ring->GetIdForObject(raw());
5455 jsobj.AddProperty("type", JSONType(ref));
5456 jsobj.AddProperty("id", id);
5457 jsobj.AddProperty("name", internal_field_name);
5458 jsobj.AddProperty("user_name", field_name);
5459 if (ref) return;
siva 2013/09/17 17:25:33 Not sure if we have used this style elsewhere. if
Cutch 2013/09/19 23:57:39 Done.
5460 Class& cls = Class::Handle(owner());
5461 jsobj.AddProperty("type", "Field");
5462 jsobj.AddProperty("id", id);
5463 jsobj.AddProperty("name", internal_field_name);
5464 jsobj.AddProperty("user_name", field_name);
5465 jsobj.AddProperty("class", cls);
5466 jsobj.AddProperty("static", is_static());
5467 jsobj.AddProperty("final", is_final());
5468 jsobj.AddProperty("const", is_const());
5469 jsobj.AddProperty("guard_nullable", is_nullable());
5470 if (guarded_cid() == kIllegalCid) {
5471 jsobj.AddProperty("guard_class", "unknown");
5472 } else if (guarded_cid() == kDynamicCid) {
5473 jsobj.AddProperty("guard_class", "dynamic");
5474 } else {
5475 ClassTable* table = Isolate::Current()->class_table();
5476 ASSERT(table->IsValidIndex(guarded_cid()));
5477 cls ^= table->At(guarded_cid());
5478 jsobj.AddProperty("guard_class", cls);
5479 }
5480 if (guarded_list_length() == kUnknownFixedLength) {
5481 jsobj.AddProperty("guard_length", "unknown");
5482 } else if (guarded_list_length() == kNoFixedLength) {
5483 jsobj.AddProperty("guard_length", "variable");
5484 } else {
5485 jsobj.AddProperty("guard_length", guarded_list_length());
5486 }
5415 } 5487 }
5416 5488
5417 5489
5418 RawArray* Field::dependent_code() const { 5490 RawArray* Field::dependent_code() const {
5419 return raw_ptr()->dependent_code_; 5491 return raw_ptr()->dependent_code_;
5420 } 5492 }
5421 5493
5422 5494
5423 void Field::set_dependent_code(const Array& array) const { 5495 void Field::set_dependent_code(const Array& array) const {
5424 raw_ptr()->dependent_code_ = array.raw(); 5496 raw_ptr()->dependent_code_ = array.raw();
(...skipping 9460 matching lines...) Expand 10 before | Expand all | Expand 10 after
14885 return "_MirrorReference"; 14957 return "_MirrorReference";
14886 } 14958 }
14887 14959
14888 14960
14889 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14961 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14890 JSONObject jsobj(stream); 14962 JSONObject jsobj(stream);
14891 } 14963 }
14892 14964
14893 14965
14894 } // namespace dart 14966 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_table.cc ('k') | runtime/vm/service.cc » ('j') | runtime/vm/service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698