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

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

Issue 230863005: Initial UserTag and dart:profiler library (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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_store.h » ('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"
11 #include "vm/bigint_operations.h" 11 #include "vm/bigint_operations.h"
12 #include "vm/bit_vector.h"
12 #include "vm/bootstrap.h" 13 #include "vm/bootstrap.h"
13 #include "vm/class_finalizer.h" 14 #include "vm/class_finalizer.h"
14 #include "vm/code_generator.h" 15 #include "vm/code_generator.h"
15 #include "vm/code_observers.h" 16 #include "vm/code_observers.h"
16 #include "vm/code_patcher.h" 17 #include "vm/code_patcher.h"
17 #include "vm/compiler.h" 18 #include "vm/compiler.h"
18 #include "vm/compiler_stats.h" 19 #include "vm/compiler_stats.h"
19 #include "vm/dart.h" 20 #include "vm/dart.h"
20 #include "vm/dart_api_state.h" 21 #include "vm/dart_api_state.h"
21 #include "vm/dart_entry.h" 22 #include "vm/dart_entry.h"
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 isolate->object_store()->set_bootstrap_library(ObjectStore::kMirrors, 1135 isolate->object_store()->set_bootstrap_library(ObjectStore::kMirrors,
1135 lib); 1136 lib);
1136 } 1137 }
1137 ASSERT(!lib.IsNull()); 1138 ASSERT(!lib.IsNull());
1138 ASSERT(lib.raw() == Library::MirrorsLibrary()); 1139 ASSERT(lib.raw() == Library::MirrorsLibrary());
1139 1140
1140 cls = Class::New<MirrorReference>(); 1141 cls = Class::New<MirrorReference>();
1141 object_store->set_mirror_reference_class(cls); 1142 object_store->set_mirror_reference_class(cls);
1142 RegisterPrivateClass(cls, Symbols::_MirrorReference(), lib); 1143 RegisterPrivateClass(cls, Symbols::_MirrorReference(), lib);
1143 1144
1145 // Pre-register the profiler library so we can place the vm class
1146 // UserTag there rather than the core library.
1147 lib = Library::LookupLibrary(Symbols::DartProfiler());
1148 if (lib.IsNull()) {
1149 lib = Library::NewLibraryHelper(Symbols::DartProfiler(), true);
1150 lib.Register();
1151 isolate->object_store()->set_bootstrap_library(ObjectStore::kProfiler,
1152 lib);
1153 }
1154 ASSERT(!lib.IsNull());
1155 ASSERT(lib.raw() == Library::ProfilerLibrary());
1156
1157 lib = Library::LookupLibrary(Symbols::DartProfiler());
1158 ASSERT(!lib.IsNull());
1159 cls = Class::New<UserTag>();
1160 object_store->set_user_tag_class(cls);
1161 RegisterPrivateClass(cls, Symbols::_UserTag(), lib);
1162 pending_classes.Add(cls);
1163
1144 // Setup some default native field classes which can be extended for 1164 // Setup some default native field classes which can be extended for
1145 // specifying native fields in dart classes. 1165 // specifying native fields in dart classes.
1146 Library::InitNativeWrappersLibrary(isolate); 1166 Library::InitNativeWrappersLibrary(isolate);
1147 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null()); 1167 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null());
1148 1168
1149 // Pre-register the typed_data library so the native class implementations 1169 // Pre-register the typed_data library so the native class implementations
1150 // can be hooked up before compiling it. 1170 // can be hooked up before compiling it.
1151 lib = Library::LookupLibrary(Symbols::DartTypedData()); 1171 lib = Library::LookupLibrary(Symbols::DartTypedData());
1152 if (lib.IsNull()) { 1172 if (lib.IsNull()) {
1153 lib = Library::NewLibraryHelper(Symbols::DartTypedData(), true); 1173 lib = Library::NewLibraryHelper(Symbols::DartTypedData(), true);
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 // Some classes are not stored in the object store. Yet we still need to 1452 // Some classes are not stored in the object store. Yet we still need to
1433 // create their Class object so that they get put into the class_table 1453 // create their Class object so that they get put into the class_table
1434 // (as a side effect of Class::New()). 1454 // (as a side effect of Class::New()).
1435 cls = Class::New<Number>(); 1455 cls = Class::New<Number>();
1436 1456
1437 cls = Class::New<WeakProperty>(); 1457 cls = Class::New<WeakProperty>();
1438 object_store->set_weak_property_class(cls); 1458 object_store->set_weak_property_class(cls);
1439 1459
1440 cls = Class::New<MirrorReference>(); 1460 cls = Class::New<MirrorReference>();
1441 object_store->set_mirror_reference_class(cls); 1461 object_store->set_mirror_reference_class(cls);
1462
1463 cls = Class::New<UserTag>();
1464 object_store->set_object_class(cls);
siva 2014/04/10 21:35:24 object_store->set_user_tag_class(cls);
Cutch 2014/04/10 22:18:30 Done.
1442 } 1465 }
1443 1466
1444 1467
1445 void Object::Print() const { 1468 void Object::Print() const {
1446 OS::Print("%s\n", ToCString()); 1469 OS::Print("%s\n", ToCString());
1447 } 1470 }
1448 1471
1449 1472
1450 RawString* Object::DictionaryName() const { 1473 RawString* Object::DictionaryName() const {
1451 return String::null(); 1474 return String::null();
(...skipping 7730 matching lines...) Expand 10 before | Expand all | Expand 10 after
9182 RawLibrary* Library::NativeWrappersLibrary() { 9205 RawLibrary* Library::NativeWrappersLibrary() {
9183 return Isolate::Current()->object_store()->native_wrappers_library(); 9206 return Isolate::Current()->object_store()->native_wrappers_library();
9184 } 9207 }
9185 9208
9186 9209
9187 RawLibrary* Library::TypedDataLibrary() { 9210 RawLibrary* Library::TypedDataLibrary() {
9188 return Isolate::Current()->object_store()->typed_data_library(); 9211 return Isolate::Current()->object_store()->typed_data_library();
9189 } 9212 }
9190 9213
9191 9214
9215 RawLibrary* Library::ProfilerLibrary() {
9216 return Isolate::Current()->object_store()->profiler_library();
9217 }
9218
9219
9192 const char* Library::ToCString() const { 9220 const char* Library::ToCString() const {
9193 const char* kFormat = "Library:'%s'"; 9221 const char* kFormat = "Library:'%s'";
9194 const String& name = String::Handle(url()); 9222 const String& name = String::Handle(url());
9195 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; 9223 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1;
9196 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 9224 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
9197 OS::SNPrint(chars, len, kFormat, name.ToCString()); 9225 OS::SNPrint(chars, len, kFormat, name.ToCString());
9198 return chars; 9226 return chars;
9199 } 9227 }
9200 9228
9201 9229
(...skipping 9059 matching lines...) Expand 10 before | Expand all | Expand 10 after
18261 const char* MirrorReference::ToCString() const { 18289 const char* MirrorReference::ToCString() const {
18262 return "_MirrorReference"; 18290 return "_MirrorReference";
18263 } 18291 }
18264 18292
18265 18293
18266 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 18294 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
18267 Instance::PrintToJSONStream(stream, ref); 18295 Instance::PrintToJSONStream(stream, ref);
18268 } 18296 }
18269 18297
18270 18298
18299 void UserTag::MakeActive() const {
18300 Isolate* isolate = Isolate::Current();
18301 ASSERT(isolate != NULL);
18302 isolate->set_current_tag(*this);
18303 }
18304
18305
18306 void UserTag::ClearActive() {
18307 Isolate* isolate = Isolate::Current();
18308 ASSERT(isolate != NULL);
18309 isolate->clear_current_tag();
18310 }
18311
18312
18313 RawUserTag* UserTag::New(const String& label, Heap::Space space) {
18314 Isolate* isolate = Isolate::Current();
18315 ASSERT(isolate->object_store()->user_tag_class() != Class::null());
18316 ASSERT(isolate->tag_table() != GrowableObjectArray::null());
18317 // Canonicalize by name.
18318 UserTag& result = UserTag::Handle(FindTagInIsolate(isolate, label));
18319 if (!result.IsNull()) {
18320 // Tag already exists, return existing instance.
18321 return result.raw();
18322 }
18323 if (TagTableIsFull(isolate)) {
18324 const String& error = String::Handle(
18325 String::NewFormatted("UserTag instance limit (%" Pd ") reached.",
18326 UserTags::kMaxUserTags));
18327 const Array& args = Array::Handle(Array::New(1));
18328 args.SetAt(0, error);
18329 Exceptions::ThrowByType(Exceptions::kUnsupported, args);
18330 }
18331 ASSERT(!TagTableIsFull(isolate));
siva 2014/04/10 21:35:24 why is this ASSERT needed here, you have already c
Cutch 2014/04/10 22:18:30 Done.
18332 // No tag with label exists, create and register with isolate tag table.
18333 {
18334 RawObject* raw = Object::Allocate(UserTag::kClassId,
18335 UserTag::InstanceSize(),
18336 space);
18337 NoGCScope no_gc;
18338 result ^= raw;
18339 }
18340 result.set_label(label);
18341 // Generate the UserTag tag id by taking the length of the isolate's
18342 // tag table + kUserTagIdOffset.
18343 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18344 isolate, isolate->tag_table());
18345 uword tag_id = tag_table.Length() + UserTags::kUserTagIdOffset;
18346 ASSERT(tag_id >= UserTags::kUserTagIdOffset);
18347 ASSERT(tag_id < (UserTags::kUserTagIdOffset + UserTags::kMaxUserTags));
18348 result.set_tag(tag_id);
siva 2014/04/10 21:35:24 Maybe it makes sense to move this code which compu
Cutch 2014/04/10 22:18:30 Done.
18349 AddTagToIsolate(isolate, result);
18350 return result.raw();
18351 }
18352
18353
18354 RawUserTag* UserTag::FindTagInIsolate(Isolate* isolate, const String& label) {
18355 ASSERT(isolate->tag_table() != GrowableObjectArray::null());
18356 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18357 isolate, isolate->tag_table());
18358 UserTag& other = UserTag::Handle(isolate);
18359 String& tag_label = String::Handle(isolate);
18360 for (intptr_t i = 0; i < tag_table.Length(); i++) {
18361 other ^= tag_table.At(i);
18362 ASSERT(!other.IsNull());
18363 tag_label ^= other.label();
18364 ASSERT(!tag_label.IsNull());
18365 if (tag_label.Equals(label)) {
18366 return other.raw();
18367 }
18368 }
18369 return UserTag::null();
18370 }
18371
18372
18373 void UserTag::AddTagToIsolate(Isolate* isolate, const UserTag& tag) {
18374 ASSERT(isolate->tag_table() != GrowableObjectArray::null());
18375 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18376 isolate, isolate->tag_table());
18377 ASSERT(!TagTableIsFull(isolate));
18378 #if defined(DEBUG)
18379 // Verify that no existing tag has the same tag id.
18380 UserTag& other = UserTag::Handle(isolate);
18381 for (intptr_t i = 0; i < tag_table.Length(); i++) {
18382 other ^= tag_table.At(i);
18383 ASSERT(!other.IsNull());
18384 ASSERT(tag.tag() != other.tag());
18385 }
18386 #endif
18387 tag_table.Add(tag);
18388 }
18389
18390
18391 bool UserTag::TagTableIsFull(Isolate* isolate) {
18392 ASSERT(isolate->tag_table() != GrowableObjectArray::null());
18393 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18394 isolate, isolate->tag_table());
18395 ASSERT(tag_table.Length() <= UserTags::kMaxUserTags);
18396 return tag_table.Length() == UserTags::kMaxUserTags;
18397 }
18398
18399
18400 RawUserTag* UserTag::FindTagById(uword tag_id) {
siva 2014/04/10 21:35:24 I don't think this function is used anymore, can b
Cutch 2014/04/10 22:18:30 It is used by UserTags::TagName in tags.cc
18401 Isolate* isolate = Isolate::Current();
18402 ASSERT(isolate->tag_table() != GrowableObjectArray::null());
18403 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18404 isolate, isolate->tag_table());
18405 UserTag& tag = UserTag::Handle(isolate);
18406 for (intptr_t i = 0; i < tag_table.Length(); i++) {
18407 tag ^= tag_table.At(i);
18408 if (tag.tag() == tag_id) {
18409 return tag.raw();
18410 }
18411 }
18412 return UserTag::null();
18413 }
18414
18415
18416 const char* UserTag::ToCString() const {
18417 const String& tag_label = String::Handle(label());
18418 return tag_label.ToCString();
18419 }
18420
18421
18422 void UserTag::PrintToJSONStream(JSONStream* stream, bool ref) const {
18423 Instance::PrintToJSONStream(stream, ref);
18424 }
18425
18426
18271 } // namespace dart 18427 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698