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

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_user_tag_class(cls);
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 7731 matching lines...) Expand 10 before | Expand all | Expand 10 after
9183 RawLibrary* Library::NativeWrappersLibrary() { 9206 RawLibrary* Library::NativeWrappersLibrary() {
9184 return Isolate::Current()->object_store()->native_wrappers_library(); 9207 return Isolate::Current()->object_store()->native_wrappers_library();
9185 } 9208 }
9186 9209
9187 9210
9188 RawLibrary* Library::TypedDataLibrary() { 9211 RawLibrary* Library::TypedDataLibrary() {
9189 return Isolate::Current()->object_store()->typed_data_library(); 9212 return Isolate::Current()->object_store()->typed_data_library();
9190 } 9213 }
9191 9214
9192 9215
9216 RawLibrary* Library::ProfilerLibrary() {
9217 return Isolate::Current()->object_store()->profiler_library();
9218 }
9219
9220
9193 const char* Library::ToCString() const { 9221 const char* Library::ToCString() const {
9194 const char* kFormat = "Library:'%s'"; 9222 const char* kFormat = "Library:'%s'";
9195 const String& name = String::Handle(url()); 9223 const String& name = String::Handle(url());
9196 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; 9224 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1;
9197 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 9225 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
9198 OS::SNPrint(chars, len, kFormat, name.ToCString()); 9226 OS::SNPrint(chars, len, kFormat, name.ToCString());
9199 return chars; 9227 return chars;
9200 } 9228 }
9201 9229
9202 9230
(...skipping 9059 matching lines...) Expand 10 before | Expand all | Expand 10 after
18262 const char* MirrorReference::ToCString() const { 18290 const char* MirrorReference::ToCString() const {
18263 return "_MirrorReference"; 18291 return "_MirrorReference";
18264 } 18292 }
18265 18293
18266 18294
18267 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 18295 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
18268 Instance::PrintToJSONStream(stream, ref); 18296 Instance::PrintToJSONStream(stream, ref);
18269 } 18297 }
18270 18298
18271 18299
18300 void UserTag::MakeActive() const {
18301 Isolate* isolate = Isolate::Current();
18302 ASSERT(isolate != NULL);
18303 isolate->set_current_tag(*this);
18304 }
18305
18306
18307 void UserTag::ClearActive() {
18308 Isolate* isolate = Isolate::Current();
18309 ASSERT(isolate != NULL);
18310 isolate->clear_current_tag();
18311 }
18312
18313
18314 RawUserTag* UserTag::New(const String& label, Heap::Space space) {
18315 Isolate* isolate = Isolate::Current();
18316 ASSERT(isolate->object_store()->user_tag_class() != Class::null());
18317 ASSERT(isolate->tag_table() != GrowableObjectArray::null());
18318 // Canonicalize by name.
18319 UserTag& result = UserTag::Handle(FindTagInIsolate(isolate, label));
18320 if (!result.IsNull()) {
18321 // Tag already exists, return existing instance.
18322 return result.raw();
18323 }
18324 if (TagTableIsFull(isolate)) {
18325 const String& error = String::Handle(
18326 String::NewFormatted("UserTag instance limit (%" Pd ") reached.",
18327 UserTags::kMaxUserTags));
18328 const Array& args = Array::Handle(Array::New(1));
18329 args.SetAt(0, error);
18330 Exceptions::ThrowByType(Exceptions::kUnsupported, args);
18331 }
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 AddTagToIsolate(isolate, result);
18342 return result.raw();
18343 }
18344
18345
18346 RawUserTag* UserTag::FindTagInIsolate(Isolate* isolate, const String& label) {
18347 ASSERT(isolate->tag_table() != GrowableObjectArray::null());
18348 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18349 isolate, isolate->tag_table());
18350 UserTag& other = UserTag::Handle(isolate);
18351 String& tag_label = String::Handle(isolate);
18352 for (intptr_t i = 0; i < tag_table.Length(); i++) {
18353 other ^= tag_table.At(i);
18354 ASSERT(!other.IsNull());
18355 tag_label ^= other.label();
18356 ASSERT(!tag_label.IsNull());
18357 if (tag_label.Equals(label)) {
18358 return other.raw();
18359 }
18360 }
18361 return UserTag::null();
18362 }
18363
18364
18365 void UserTag::AddTagToIsolate(Isolate* isolate, const UserTag& tag) {
18366 ASSERT(isolate->tag_table() != GrowableObjectArray::null());
18367 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18368 isolate, isolate->tag_table());
18369 ASSERT(!TagTableIsFull(isolate));
18370 #if defined(DEBUG)
18371 // Verify that no existing tag has the same tag id.
18372 UserTag& other = UserTag::Handle(isolate);
18373 for (intptr_t i = 0; i < tag_table.Length(); i++) {
18374 other ^= tag_table.At(i);
18375 ASSERT(!other.IsNull());
18376 ASSERT(tag.tag() != other.tag());
18377 }
18378 #endif
18379 // Generate the UserTag tag id by taking the length of the isolate's
18380 // tag table + kUserTagIdOffset.
18381 uword tag_id = tag_table.Length() + UserTags::kUserTagIdOffset;
18382 ASSERT(tag_id >= UserTags::kUserTagIdOffset);
18383 ASSERT(tag_id < (UserTags::kUserTagIdOffset + UserTags::kMaxUserTags));
18384 tag.set_tag(tag_id);
18385 tag_table.Add(tag);
18386 }
18387
18388
18389 bool UserTag::TagTableIsFull(Isolate* isolate) {
18390 ASSERT(isolate->tag_table() != GrowableObjectArray::null());
18391 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18392 isolate, isolate->tag_table());
18393 ASSERT(tag_table.Length() <= UserTags::kMaxUserTags);
18394 return tag_table.Length() == UserTags::kMaxUserTags;
18395 }
18396
18397
18398 RawUserTag* UserTag::FindTagById(uword tag_id) {
18399 Isolate* isolate = Isolate::Current();
18400 ASSERT(isolate->tag_table() != GrowableObjectArray::null());
18401 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18402 isolate, isolate->tag_table());
18403 UserTag& tag = UserTag::Handle(isolate);
18404 for (intptr_t i = 0; i < tag_table.Length(); i++) {
18405 tag ^= tag_table.At(i);
18406 if (tag.tag() == tag_id) {
18407 return tag.raw();
18408 }
18409 }
18410 return UserTag::null();
18411 }
18412
18413
18414 const char* UserTag::ToCString() const {
18415 const String& tag_label = String::Handle(label());
18416 return tag_label.ToCString();
18417 }
18418
18419
18420 void UserTag::PrintToJSONStream(JSONStream* stream, bool ref) const {
18421 Instance::PrintToJSONStream(stream, ref);
18422 }
18423
18424
18272 } // namespace dart 18425 } // 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