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

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
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
1163 cls = Class::New<Instance>(kIllegalCid);
1164 RegisterClass(cls, Symbols::UserTag(), lib);
1165 cls.set_num_type_arguments(0);
1166 cls.set_num_own_type_arguments(0);
1167 cls.set_is_prefinalized();
1168 pending_classes.Add(cls);
1169
1170
srdjan 2014/04/09 17:08:18 Remove 2 empty lines (one is enough).
Cutch 2014/04/09 20:28:54 Done.
1171
1144 // Setup some default native field classes which can be extended for 1172 // Setup some default native field classes which can be extended for
1145 // specifying native fields in dart classes. 1173 // specifying native fields in dart classes.
1146 Library::InitNativeWrappersLibrary(isolate); 1174 Library::InitNativeWrappersLibrary(isolate);
1147 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null()); 1175 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null());
1148 1176
1149 // Pre-register the typed_data library so the native class implementations 1177 // Pre-register the typed_data library so the native class implementations
1150 // can be hooked up before compiling it. 1178 // can be hooked up before compiling it.
1151 lib = Library::LookupLibrary(Symbols::DartTypedData()); 1179 lib = Library::LookupLibrary(Symbols::DartTypedData());
1152 if (lib.IsNull()) { 1180 if (lib.IsNull()) {
1153 lib = Library::NewLibraryHelper(Symbols::DartTypedData(), true); 1181 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 1460 // 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 1461 // create their Class object so that they get put into the class_table
1434 // (as a side effect of Class::New()). 1462 // (as a side effect of Class::New()).
1435 cls = Class::New<Number>(); 1463 cls = Class::New<Number>();
1436 1464
1437 cls = Class::New<WeakProperty>(); 1465 cls = Class::New<WeakProperty>();
1438 object_store->set_weak_property_class(cls); 1466 object_store->set_weak_property_class(cls);
1439 1467
1440 cls = Class::New<MirrorReference>(); 1468 cls = Class::New<MirrorReference>();
1441 object_store->set_mirror_reference_class(cls); 1469 object_store->set_mirror_reference_class(cls);
1470
1471 cls = Class::New<UserTag>();
1472 object_store->set_object_class(cls);
1442 } 1473 }
1443 1474
1444 1475
1445 void Object::Print() const { 1476 void Object::Print() const {
1446 OS::Print("%s\n", ToCString()); 1477 OS::Print("%s\n", ToCString());
1447 } 1478 }
1448 1479
1449 1480
1450 RawString* Object::DictionaryName() const { 1481 RawString* Object::DictionaryName() const {
1451 return String::null(); 1482 return String::null();
(...skipping 7730 matching lines...) Expand 10 before | Expand all | Expand 10 after
9182 RawLibrary* Library::NativeWrappersLibrary() { 9213 RawLibrary* Library::NativeWrappersLibrary() {
9183 return Isolate::Current()->object_store()->native_wrappers_library(); 9214 return Isolate::Current()->object_store()->native_wrappers_library();
9184 } 9215 }
9185 9216
9186 9217
9187 RawLibrary* Library::TypedDataLibrary() { 9218 RawLibrary* Library::TypedDataLibrary() {
9188 return Isolate::Current()->object_store()->typed_data_library(); 9219 return Isolate::Current()->object_store()->typed_data_library();
9189 } 9220 }
9190 9221
9191 9222
9223 RawLibrary* Library::ProfilerLibrary() {
9224 return Isolate::Current()->object_store()->profiler_library();
9225 }
9226
9227
9192 const char* Library::ToCString() const { 9228 const char* Library::ToCString() const {
9193 const char* kFormat = "Library:'%s'"; 9229 const char* kFormat = "Library:'%s'";
9194 const String& name = String::Handle(url()); 9230 const String& name = String::Handle(url());
9195 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; 9231 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1;
9196 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 9232 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
9197 OS::SNPrint(chars, len, kFormat, name.ToCString()); 9233 OS::SNPrint(chars, len, kFormat, name.ToCString());
9198 return chars; 9234 return chars;
9199 } 9235 }
9200 9236
9201 9237
(...skipping 9057 matching lines...) Expand 10 before | Expand all | Expand 10 after
18259 const char* MirrorReference::ToCString() const { 18295 const char* MirrorReference::ToCString() const {
18260 return "_MirrorReference"; 18296 return "_MirrorReference";
18261 } 18297 }
18262 18298
18263 18299
18264 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 18300 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
18265 Instance::PrintToJSONStream(stream, ref); 18301 Instance::PrintToJSONStream(stream, ref);
18266 } 18302 }
18267 18303
18268 18304
18305 void UserTag::make_active() {
18306 Isolate* isolate = Isolate::Current();
18307 ASSERT(isolate != NULL);
18308 intptr_t user_tag = tag();
18309 isolate->set_user_tag(static_cast<uword>(user_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->object_store()->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 // No tag with label exists, create and register with isolate tag table.
18324 {
18325 RawObject* raw = Object::Allocate(UserTag::kClassId,
18326 UserTag::InstanceSize(),
18327 space);
18328 NoGCScope no_gc;
18329 result ^= raw;
18330 }
18331 result.set_label(label);
18332 intptr_t tag_id = FindAvailableTagId(isolate);
18333 ASSERT(tag_id >= 0);
18334 result.set_tag(tag_id);
18335 AddTagToIsolate(isolate, result);
18336 return result.raw();
18337 }
18338
18339
18340 RawUserTag* UserTag::FindTagInIsolate(Isolate* isolate, const String& label) {
18341 ASSERT(isolate->object_store()->tag_table() != GrowableObjectArray::null());
18342 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18343 isolate, isolate->object_store()->tag_table());
18344 UserTag& other = UserTag::Handle(isolate);
18345 String& tag_label = String::Handle(isolate);
18346 for (intptr_t i = 0; i < tag_table.Length(); i++) {
18347 other ^= tag_table.At(i);
18348 ASSERT(!other.IsNull());
18349 tag_label ^= other.label();
18350 ASSERT(!tag_label.IsNull());
18351 if (tag_label.Equals(label)) {
18352 return other.raw();
18353 }
18354 }
18355 return UserTag::null();
18356 }
18357
18358
18359 void UserTag::AddTagToIsolate(Isolate* isolate, const UserTag& tag) {
18360 ASSERT(isolate->object_store()->tag_table() != GrowableObjectArray::null());
18361 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18362 isolate, isolate->object_store()->tag_table());
18363 #if defined(DEBUG)
18364 // Verify that no existing tag has the same tag id.
18365 UserTag& other = UserTag::Handle(isolate);
18366 for (intptr_t i = 0; i < tag_table.Length(); i++) {
18367 other ^= tag_table.At(i);
18368 ASSERT(!other.IsNull());
18369 ASSERT(tag.tag() != other.tag());
18370 }
18371 #endif
18372 tag_table.Add(tag);
18373 }
18374
18375
18376 bool UserTag::TagTableFull(Isolate* isolate) {
18377 ASSERT(isolate->object_store()->tag_table() != GrowableObjectArray::null());
18378 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18379 isolate, isolate->object_store()->tag_table());
18380 ASSERT(tag_table.Length() <= UserTagHelper::kMaxUserTags);
18381 return tag_table.Length() == UserTagHelper::kMaxUserTags;
18382 }
18383
18384
18385 intptr_t UserTag::FindAvailableTagId(Isolate* isolate) {
18386 ASSERT(!TagTableFull(isolate));
18387 ASSERT(isolate->object_store()->tag_table() != GrowableObjectArray::null());
18388 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle(
18389 isolate, isolate->object_store()->tag_table());
18390 // Use a bit-vector to collect used tag ids.
18391 BitVector* bv = new BitVector(UserTagHelper::kMaxUserTags);
18392 UserTag& other = UserTag::Handle(isolate);
18393 for (intptr_t i = 0; i < tag_table.Length(); i++) {
18394 other ^= tag_table.At(i);
18395 ASSERT(!other.IsNull());
18396 ASSERT(other.tag() >= UserTagHelper::kUserTagIdOffset);
18397 ASSERT(other.tag() <
18398 (UserTagHelper::kUserTagIdOffset + UserTagHelper::kMaxUserTags));
18399 // Mark tag as used.
18400 bv->Add(other.tag() - UserTagHelper::kUserTagIdOffset);
18401 }
18402 // Find first available id.
18403 for (intptr_t i = 0; i < bv->length(); i++) {
18404 if (!bv->Contains(i)) {
18405 return i + UserTagHelper::kUserTagIdOffset;
18406 }
18407 }
18408 // We should always be able to find an available tag id.
18409 UNREACHABLE();
18410 return -1;
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
18269 } // namespace dart 18425 } // namespace dart
OLDNEW
« runtime/vm/object.h ('K') | « 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