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

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

Issue 2972883002: [vm] Enable mirrors in product mode. Allows building a product mode SDK. (Closed)
Patch Set: Created 3 years, 5 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
« 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/become.h" 10 #include "vm/become.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // And so forth: 261 // And so forth:
262 // 262 //
263 // get:foo@6328321 -> foo 263 // get:foo@6328321 -> foo
264 // _MyClass@6328321. -> _MyClass 264 // _MyClass@6328321. -> _MyClass
265 // _MyClass@6328321.named -> _MyClass.named 265 // _MyClass@6328321.named -> _MyClass.named
266 // 266 //
267 RawString* String::ScrubName(const String& name) { 267 RawString* String::ScrubName(const String& name) {
268 Thread* thread = Thread::Current(); 268 Thread* thread = Thread::Current();
269 Zone* zone = thread->zone(); 269 Zone* zone = thread->zone();
270 270
271 #if !defined(PRODUCT) 271 #if !defined(DART_PRECOMPILED_RUNTIME)
272 if (name.Equals(Symbols::TopLevel())) { 272 if (name.Equals(Symbols::TopLevel())) {
273 // Name of invisible top-level class. 273 // Name of invisible top-level class.
274 return Symbols::Empty().raw(); 274 return Symbols::Empty().raw();
275 } 275 }
276 #endif // !defined(PRODUCT) 276 #endif // !defined(DART_PRECOMPILED_RUNTIME)
277 277
278 const char* cname = name.ToCString(); 278 const char* cname = name.ToCString();
279 ASSERT(strlen(cname) == static_cast<size_t>(name.Length())); 279 ASSERT(strlen(cname) == static_cast<size_t>(name.Length()));
280 const intptr_t name_len = name.Length(); 280 const intptr_t name_len = name.Length();
281 // First remove all private name mangling. 281 // First remove all private name mangling.
282 intptr_t start_pos = 0; 282 intptr_t start_pos = 0;
283 GrowableArray<const char*> unmangled_segments; 283 GrowableArray<const char*> unmangled_segments;
284 intptr_t sum_segment_len = 0; 284 intptr_t sum_segment_len = 0;
285 for (intptr_t i = 0; i < name_len; i++) { 285 for (intptr_t i = 0; i < name_len; i++) {
286 if ((cname[i] == '@') && ((i + 1) < name_len) && (cname[i + 1] >= '0') && 286 if ((cname[i] == '@') && ((i + 1) < name_len) && (cname[i + 1] >= '0') &&
(...skipping 23 matching lines...) Expand all
310 // Append the last segment. 310 // Append the last segment.
311 const intptr_t segment_len = name.Length() - start_pos; 311 const intptr_t segment_len = name.Length() - start_pos;
312 sum_segment_len += segment_len; 312 sum_segment_len += segment_len;
313 AppendSubString(zone, &unmangled_segments, cname, start_pos, segment_len); 313 AppendSubString(zone, &unmangled_segments, cname, start_pos, segment_len);
314 } 314 }
315 if (unmangled_name == NULL) { 315 if (unmangled_name == NULL) {
316 // Merge unmangled_segments. 316 // Merge unmangled_segments.
317 unmangled_name = MergeSubStrings(zone, unmangled_segments, sum_segment_len); 317 unmangled_name = MergeSubStrings(zone, unmangled_segments, sum_segment_len);
318 } 318 }
319 319
320 #if !defined(PRODUCT) 320 #if !defined(DART_PRECOMPILED_RUNTIME)
321 intptr_t len = sum_segment_len; 321 intptr_t len = sum_segment_len;
322 intptr_t start = 0; 322 intptr_t start = 0;
323 intptr_t dot_pos = -1; // Position of '.' in the name, if any. 323 intptr_t dot_pos = -1; // Position of '.' in the name, if any.
324 bool is_setter = false; 324 bool is_setter = false;
325 for (intptr_t i = start; i < len; i++) { 325 for (intptr_t i = start; i < len; i++) {
326 if (unmangled_name[i] == ':') { 326 if (unmangled_name[i] == ':') {
327 if (start != 0) { 327 if (start != 0) {
328 // Reset and break. 328 // Reset and break.
329 start = 0; 329 start = 0;
330 dot_pos = -1; 330 dot_pos = -1;
(...skipping 28 matching lines...) Expand all
359 intptr_t final_len = end - start; 359 intptr_t final_len = end - start;
360 AppendSubString(zone, &unmangled_segments, unmangled_name, start, final_len); 360 AppendSubString(zone, &unmangled_segments, unmangled_name, start, final_len);
361 if (is_setter) { 361 if (is_setter) {
362 const char* equals = Symbols::Equals().ToCString(); 362 const char* equals = Symbols::Equals().ToCString();
363 const intptr_t equals_len = strlen(equals); 363 const intptr_t equals_len = strlen(equals);
364 AppendSubString(zone, &unmangled_segments, equals, 0, equals_len); 364 AppendSubString(zone, &unmangled_segments, equals, 0, equals_len);
365 final_len += equals_len; 365 final_len += equals_len;
366 } 366 }
367 367
368 unmangled_name = MergeSubStrings(zone, unmangled_segments, final_len); 368 unmangled_name = MergeSubStrings(zone, unmangled_segments, final_len);
369 #endif // !defined(PRODUCT) 369 #endif // !defined(DART_PRECOMPILED_RUNTIME)
370 370
371 return Symbols::New(thread, unmangled_name); 371 return Symbols::New(thread, unmangled_name);
372 } 372 }
373 373
374 374
375 RawString* String::ScrubNameRetainPrivate(const String& name) { 375 RawString* String::ScrubNameRetainPrivate(const String& name) {
376 #if !defined(PRODUCT) 376 #if !defined(DART_PRECOMPILED_RUNTIME)
377 intptr_t len = name.Length(); 377 intptr_t len = name.Length();
378 intptr_t start = 0; 378 intptr_t start = 0;
379 intptr_t at_pos = -1; // Position of '@' in the name, if any. 379 intptr_t at_pos = -1; // Position of '@' in the name, if any.
380 bool is_setter = false; 380 bool is_setter = false;
381 381
382 for (intptr_t i = start; i < len; i++) { 382 for (intptr_t i = start; i < len; i++) {
383 if (name.CharAt(i) == ':') { 383 if (name.CharAt(i) == ':') {
384 ASSERT(start == 0); // Only one : is possible in getters or setters. 384 ASSERT(start == 0); // Only one : is possible in getters or setters.
385 if (name.CharAt(0) == 's') { 385 if (name.CharAt(0) == 's') {
386 is_setter = true; 386 is_setter = true;
(...skipping 22 matching lines...) Expand all
409 const String& pre_at = 409 const String& pre_at =
410 String::Handle(String::SubString(result, 0, at_pos - 4)); 410 String::Handle(String::SubString(result, 0, at_pos - 4));
411 const String& post_at = 411 const String& post_at =
412 String::Handle(String::SubString(name, at_pos, len - at_pos)); 412 String::Handle(String::SubString(name, at_pos, len - at_pos));
413 result = String::Concat(pre_at, Symbols::Equals()); 413 result = String::Concat(pre_at, Symbols::Equals());
414 result = String::Concat(result, post_at); 414 result = String::Concat(result, post_at);
415 } 415 }
416 } 416 }
417 417
418 return result.raw(); 418 return result.raw();
419 #endif // !defined(PRODUCT) 419 #endif // !defined(DART_PRECOMPILED_RUNTIME)
420 return name.raw(); // In PRODUCT, return argument unchanged. 420 return name.raw(); // In AOT, return argument unchanged.
421 } 421 }
422 422
423 423
424 template <typename type> 424 template <typename type>
425 static bool IsSpecialCharacter(type value) { 425 static bool IsSpecialCharacter(type value) {
426 return ((value == '"') || (value == '\n') || (value == '\f') || 426 return ((value == '"') || (value == '\n') || (value == '\f') ||
427 (value == '\b') || (value == '\t') || (value == '\v') || 427 (value == '\b') || (value == '\t') || (value == '\v') ||
428 (value == '\r') || (value == '\\') || (value == '$')); 428 (value == '\r') || (value == '\\') || (value == '$'));
429 } 429 }
430 430
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 cls.ResetFinalization(); // To calculate field offsets from Dart source. 1504 cls.ResetFinalization(); // To calculate field offsets from Dart source.
1505 RegisterPrivateClass(cls, Symbols::_Closure(), core_lib); 1505 RegisterPrivateClass(cls, Symbols::_Closure(), core_lib);
1506 pending_classes.Add(cls); 1506 pending_classes.Add(cls);
1507 1507
1508 cls = Class::New<WeakProperty>(); 1508 cls = Class::New<WeakProperty>();
1509 object_store->set_weak_property_class(cls); 1509 object_store->set_weak_property_class(cls);
1510 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); 1510 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib);
1511 1511
1512 // Pre-register the mirrors library so we can place the vm class 1512 // Pre-register the mirrors library so we can place the vm class
1513 // MirrorReference there rather than the core library. 1513 // MirrorReference there rather than the core library.
1514 #if !defined(PRODUCT) 1514 #if !defined(DART_PRECOMPILED_RUNTIME)
1515 lib = Library::LookupLibrary(thread, Symbols::DartMirrors()); 1515 lib = Library::LookupLibrary(thread, Symbols::DartMirrors());
1516 if (lib.IsNull()) { 1516 if (lib.IsNull()) {
1517 lib = Library::NewLibraryHelper(Symbols::DartMirrors(), true); 1517 lib = Library::NewLibraryHelper(Symbols::DartMirrors(), true);
1518 lib.SetLoadRequested(); 1518 lib.SetLoadRequested();
1519 lib.Register(thread); 1519 lib.Register(thread);
1520 } 1520 }
1521 object_store->set_bootstrap_library(ObjectStore::kMirrors, lib); 1521 object_store->set_bootstrap_library(ObjectStore::kMirrors, lib);
1522 ASSERT(!lib.IsNull()); 1522 ASSERT(!lib.IsNull());
1523 ASSERT(lib.raw() == Library::MirrorsLibrary()); 1523 ASSERT(lib.raw() == Library::MirrorsLibrary());
1524 1524
(...skipping 8827 matching lines...) Expand 10 before | Expand all | Expand 10 after
10352 if (entryname.Equals(metaname)) { 10352 if (entryname.Equals(metaname)) {
10353 return entry.raw(); 10353 return entry.raw();
10354 } 10354 }
10355 } 10355 }
10356 return Field::null(); 10356 return Field::null();
10357 } 10357 }
10358 10358
10359 10359
10360 RawObject* Library::GetMetadata(const Object& obj) const { 10360 RawObject* Library::GetMetadata(const Object& obj) const {
10361 #if defined(DART_PRECOMPILED_RUNTIME) 10361 #if defined(DART_PRECOMPILED_RUNTIME)
10362 COMPILE_ASSERT(!FLAG_enable_mirrors);
10363 return Object::empty_array().raw(); 10362 return Object::empty_array().raw();
10364 #else 10363 #else
10365 if (!obj.IsClass() && !obj.IsField() && !obj.IsFunction() && 10364 if (!obj.IsClass() && !obj.IsField() && !obj.IsFunction() &&
10366 !obj.IsLibrary() && !obj.IsTypeParameter()) { 10365 !obj.IsLibrary() && !obj.IsTypeParameter()) {
10367 return Object::null(); 10366 return Object::null();
10368 } 10367 }
10369 const String& metaname = String::Handle(MakeMetadataName(obj)); 10368 const String& metaname = String::Handle(MakeMetadataName(obj));
10370 Field& field = Field::Handle(GetMetadataField(metaname)); 10369 Field& field = Field::Handle(GetMetadataField(metaname));
10371 if (field.IsNull()) { 10370 if (field.IsNull()) {
10372 // There is no metadata for this object. 10371 // There is no metadata for this object.
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
11557 RawLibrary* Library::IsolateLibrary() { 11556 RawLibrary* Library::IsolateLibrary() {
11558 return Isolate::Current()->object_store()->isolate_library(); 11557 return Isolate::Current()->object_store()->isolate_library();
11559 } 11558 }
11560 11559
11561 11560
11562 RawLibrary* Library::MathLibrary() { 11561 RawLibrary* Library::MathLibrary() {
11563 return Isolate::Current()->object_store()->math_library(); 11562 return Isolate::Current()->object_store()->math_library();
11564 } 11563 }
11565 11564
11566 11565
11567 #if !defined(PRODUCT) 11566 #if !defined(DART_PRECOMPILED_RUNTIME)
11568 RawLibrary* Library::MirrorsLibrary() { 11567 RawLibrary* Library::MirrorsLibrary() {
11569 return Isolate::Current()->object_store()->mirrors_library(); 11568 return Isolate::Current()->object_store()->mirrors_library();
11570 } 11569 }
11571 #endif 11570 #endif
11572 11571
11573 11572
11574 RawLibrary* Library::NativeWrappersLibrary() { 11573 RawLibrary* Library::NativeWrappersLibrary() {
11575 return Isolate::Current()->object_store()->native_wrappers_library(); 11574 return Isolate::Current()->object_store()->native_wrappers_library();
11576 } 11575 }
11577 11576
(...skipping 12058 matching lines...) Expand 10 before | Expand all | Expand 10 after
23636 return UserTag::null(); 23635 return UserTag::null();
23637 } 23636 }
23638 23637
23639 23638
23640 const char* UserTag::ToCString() const { 23639 const char* UserTag::ToCString() const {
23641 const String& tag_label = String::Handle(label()); 23640 const String& tag_label = String::Handle(label());
23642 return tag_label.ToCString(); 23641 return tag_label.ToCString();
23643 } 23642 }
23644 23643
23645 } // namespace dart 23644 } // 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