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

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

Issue 12318031: Move json, uri, utf and crypto libraries into the VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 const String& public_class_name, 624 const String& public_class_name,
625 const Library& lib) { 625 const Library& lib) {
626 ASSERT(public_class_name.Length() > 0); 626 ASSERT(public_class_name.Length() > 0);
627 ASSERT(public_class_name.CharAt(0) == '_'); 627 ASSERT(public_class_name.CharAt(0) == '_');
628 String& str = String::Handle(); 628 String& str = String::Handle();
629 str = lib.PrivateName(public_class_name); 629 str = lib.PrivateName(public_class_name);
630 cls.set_name(str); 630 cls.set_name(str);
631 lib.AddClass(cls); 631 lib.AddClass(cls);
632 } 632 }
633 633
634 #define INIT_LIBRARY(name, raw_script, raw_lib) \
635 script ^= raw_script; \
636 Library::Init##name##Library(isolate); \
637 lib ^= raw_lib; \
638 ASSERT(!lib.IsNull()); \
639 error = Bootstrap::Compile(lib, script); \
640 if (!error.IsNull()) { \
641 return error.raw(); \
642 } \
643
634 644
635 RawError* Object::Init(Isolate* isolate) { 645 RawError* Object::Init(Isolate* isolate) {
636 TIMERSCOPE(time_bootstrap); 646 TIMERSCOPE(time_bootstrap);
637 ObjectStore* object_store = isolate->object_store(); 647 ObjectStore* object_store = isolate->object_store();
638 648
639 Class& cls = Class::Handle(); 649 Class& cls = Class::Handle();
640 Type& type = Type::Handle(); 650 Type& type = Type::Handle();
641 Array& array = Array::Handle(); 651 Array& array = Array::Handle();
642 652
643 // All RawArray fields will be initialized to an empty array, therefore 653 // All RawArray fields will be initialized to an empty array, therefore
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 RegisterClass(cls, Symbols::Stacktrace(), core_lib); 764 RegisterClass(cls, Symbols::Stacktrace(), core_lib);
755 pending_classes.Add(cls, Heap::kOld); 765 pending_classes.Add(cls, Heap::kOld);
756 // Super type set below, after Object is allocated. 766 // Super type set below, after Object is allocated.
757 767
758 cls = Class::New<JSRegExp>(); 768 cls = Class::New<JSRegExp>();
759 object_store->set_jsregexp_class(cls); 769 object_store->set_jsregexp_class(cls);
760 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib); 770 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib);
761 pending_classes.Add(cls, Heap::kOld); 771 pending_classes.Add(cls, Heap::kOld);
762 772
763 // Initialize the base interfaces used by the core VM classes. 773 // Initialize the base interfaces used by the core VM classes.
764 const Script& script = Script::Handle(Bootstrap::LoadCoreScript(false)); 774 Script& script = Script::Handle(Bootstrap::LoadCoreScript(false));
765 775
766 // Allocate and initialize the pre-allocated classes in the core library. 776 // Allocate and initialize the pre-allocated classes in the core library.
767 cls = Class::New<Instance>(kInstanceCid); 777 cls = Class::New<Instance>(kInstanceCid);
768 object_store->set_object_class(cls); 778 object_store->set_object_class(cls);
769 cls.set_name(Symbols::Object()); 779 cls.set_name(Symbols::Object());
770 cls.set_script(script); 780 cls.set_script(script);
771 cls.set_is_prefinalized(); 781 cls.set_is_prefinalized();
772 core_lib.AddClass(cls); 782 core_lib.AddClass(cls);
773 pending_classes.Add(cls, Heap::kOld); 783 pending_classes.Add(cls, Heap::kOld);
774 type = Type::NewNonParameterizedType(cls); 784 type = Type::NewNonParameterizedType(cls);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 ASSERT(!scalarlist_lib.IsNull()); 1087 ASSERT(!scalarlist_lib.IsNull());
1078 error = Bootstrap::Compile(scalarlist_lib, scalarlist_script); 1088 error = Bootstrap::Compile(scalarlist_lib, scalarlist_script);
1079 if (!error.IsNull()) { 1089 if (!error.IsNull()) {
1080 return error.raw(); 1090 return error.raw();
1081 } 1091 }
1082 patch_script = Bootstrap::LoadScalarlistScript(true); 1092 patch_script = Bootstrap::LoadScalarlistScript(true);
1083 error = scalarlist_lib.Patch(patch_script); 1093 error = scalarlist_lib.Patch(patch_script);
1084 if (!error.IsNull()) { 1094 if (!error.IsNull()) {
1085 return error.raw(); 1095 return error.raw();
1086 } 1096 }
1097 Library& lib = Library::Handle();
1098 INIT_LIBRARY(Crypto,
1099 Bootstrap::LoadCryptoScript(false),
1100 Library::CryptoLibrary());
1101 INIT_LIBRARY(Json,
1102 Bootstrap::LoadJsonScript(false),
1103 Library::JsonLibrary());
1104 INIT_LIBRARY(Utf,
1105 Bootstrap::LoadUtfScript(false),
1106 Library::UtfLibrary());
1107 INIT_LIBRARY(Uri,
1108 Bootstrap::LoadUriScript(false),
1109 Library::UriLibrary());
1087 Bootstrap::SetupNativeResolver(); 1110 Bootstrap::SetupNativeResolver();
1088 1111
1089 // Remove the Object superclass cycle by setting the super type to null (not 1112 // Remove the Object superclass cycle by setting the super type to null (not
1090 // to the type of null). 1113 // to the type of null).
1091 cls = object_store->object_class(); 1114 cls = object_store->object_class();
1092 cls.set_super_type(Type::Handle()); 1115 cls.set_super_type(Type::Handle());
1093 1116
1094 ClassFinalizer::VerifyBootstrapClasses(); 1117 ClassFinalizer::VerifyBootstrapClasses();
1095 MarkInvisibleFunctions(); 1118 MarkInvisibleFunctions();
1096 1119
(...skipping 5279 matching lines...) Expand 10 before | Expand all | Expand 10 after
6376 6399
6377 6400
6378 void Library::InitCollectionDevLibrary(Isolate* isolate) { 6401 void Library::InitCollectionDevLibrary(Isolate* isolate) {
6379 const String& url = Symbols::DartCollectionDev(); 6402 const String& url = Symbols::DartCollectionDev();
6380 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); 6403 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6381 lib.Register(); 6404 lib.Register();
6382 isolate->object_store()->set_collection_dev_library(lib); 6405 isolate->object_store()->set_collection_dev_library(lib);
6383 } 6406 }
6384 6407
6385 6408
6386 void Library::InitMathLibrary(Isolate* isolate) { 6409 void Library::InitCryptoLibrary(Isolate* isolate) {
6387 const String& url = Symbols::DartMath(); 6410 const String& url = Symbols::DartCrypto();
6388 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); 6411 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6389 lib.Register(); 6412 lib.Register();
6390 isolate->object_store()->set_math_library(lib); 6413 const Library& math_lib = Library::Handle(Library::MathLibrary());
6414 const Namespace& math_ns = Namespace::Handle(
6415 Namespace::New(math_lib, Array::Handle(), Array::Handle()));
6416 lib.AddImport(math_ns);
6417 isolate->object_store()->set_crypto_library(lib);
6391 } 6418 }
6392 6419
6393 6420
6394 void Library::InitIsolateLibrary(Isolate* isolate) { 6421 void Library::InitIsolateLibrary(Isolate* isolate) {
6395 const String& url = Symbols::DartIsolate(); 6422 const String& url = Symbols::DartIsolate();
6396 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); 6423 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6397 lib.Register(); 6424 lib.Register();
6398 const Library& async_lib = Library::Handle(Library::ASyncLibrary()); 6425 const Library& async_lib = Library::Handle(Library::ASyncLibrary());
6399 const Namespace& async_ns = Namespace::Handle( 6426 const Namespace& async_ns = Namespace::Handle(
6400 Namespace::New(async_lib, Array::Handle(), Array::Handle())); 6427 Namespace::New(async_lib, Array::Handle(), Array::Handle()));
6401 lib.AddImport(async_ns); 6428 lib.AddImport(async_ns);
6402 isolate->object_store()->set_isolate_library(lib); 6429 isolate->object_store()->set_isolate_library(lib);
6403 } 6430 }
6404 6431
6405 6432
6433 void Library::InitJsonLibrary(Isolate* isolate) {
6434 const String& url = Symbols::DartJson();
6435 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6436 lib.Register();
6437 isolate->object_store()->set_json_library(lib);
6438 }
6439
6440
6441 void Library::InitMathLibrary(Isolate* isolate) {
6442 const String& url = Symbols::DartMath();
6443 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6444 lib.Register();
6445 isolate->object_store()->set_math_library(lib);
6446 }
6447
6448
6406 void Library::InitMirrorsLibrary(Isolate* isolate) { 6449 void Library::InitMirrorsLibrary(Isolate* isolate) {
6407 const String& url = Symbols::DartMirrors(); 6450 const String& url = Symbols::DartMirrors();
6408 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); 6451 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6409 lib.Register(); 6452 lib.Register();
6410 const Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); 6453 const Library& isolate_lib = Library::Handle(Library::IsolateLibrary());
6411 const Namespace& isolate_ns = Namespace::Handle( 6454 const Namespace& isolate_ns = Namespace::Handle(
6412 Namespace::New(isolate_lib, Array::Handle(), Array::Handle())); 6455 Namespace::New(isolate_lib, Array::Handle(), Array::Handle()));
6413 lib.AddImport(isolate_ns); 6456 lib.AddImport(isolate_ns);
6414 const Library& async_lib = Library::Handle(Library::ASyncLibrary()); 6457 const Library& async_lib = Library::Handle(Library::ASyncLibrary());
6415 const Namespace& async_ns = Namespace::Handle( 6458 const Namespace& async_ns = Namespace::Handle(
6416 Namespace::New(async_lib, Array::Handle(), Array::Handle())); 6459 Namespace::New(async_lib, Array::Handle(), Array::Handle()));
6417 lib.AddImport(async_ns); 6460 lib.AddImport(async_ns);
6418 const Library& wrappers_lib = 6461 const Library& wrappers_lib =
6419 Library::Handle(Library::NativeWrappersLibrary()); 6462 Library::Handle(Library::NativeWrappersLibrary());
6420 const Namespace& wrappers_ns = Namespace::Handle( 6463 const Namespace& wrappers_ns = Namespace::Handle(
6421 Namespace::New(wrappers_lib, Array::Handle(), Array::Handle())); 6464 Namespace::New(wrappers_lib, Array::Handle(), Array::Handle()));
6422 lib.AddImport(wrappers_ns); 6465 lib.AddImport(wrappers_ns);
6423 isolate->object_store()->set_mirrors_library(lib); 6466 isolate->object_store()->set_mirrors_library(lib);
6424 } 6467 }
6425 6468
6426 6469
6427 void Library::InitScalarlistLibrary(Isolate* isolate) {
6428 const String& url = Symbols::DartScalarlist();
6429 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6430 lib.Register();
6431 const Library& collection_lib =
6432 Library::Handle(Library::CollectionLibrary());
6433 const Namespace& collection_ns = Namespace::Handle(
6434 Namespace::New(collection_lib, Array::Handle(), Array::Handle()));
6435 lib.AddImport(collection_ns);
6436 isolate->object_store()->set_scalarlist_library(lib);
6437 }
6438
6439
6440 void Library::InitNativeWrappersLibrary(Isolate* isolate) { 6470 void Library::InitNativeWrappersLibrary(Isolate* isolate) {
6441 static const int kNumNativeWrappersClasses = 4; 6471 static const int kNumNativeWrappersClasses = 4;
6442 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); 6472 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10);
6443 const String& native_flds_lib_url = Symbols::DartNativeWrappers(); 6473 const String& native_flds_lib_url = Symbols::DartNativeWrappers();
6444 const Library& native_flds_lib = Library::Handle( 6474 const Library& native_flds_lib = Library::Handle(
6445 Library::NewLibraryHelper(native_flds_lib_url, false)); 6475 Library::NewLibraryHelper(native_flds_lib_url, false));
6446 native_flds_lib.Register(); 6476 native_flds_lib.Register();
6447 isolate->object_store()->set_native_wrappers_library(native_flds_lib); 6477 isolate->object_store()->set_native_wrappers_library(native_flds_lib);
6448 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; 6478 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass";
6449 static const int kNameLength = 25; 6479 static const int kNameLength = 25;
6450 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1)); 6480 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1));
6451 char name_buffer[kNameLength]; 6481 char name_buffer[kNameLength];
6452 String& cls_name = String::Handle(); 6482 String& cls_name = String::Handle();
6453 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) { 6483 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) {
6454 OS::SNPrint(name_buffer, 6484 OS::SNPrint(name_buffer,
6455 kNameLength, 6485 kNameLength,
6456 "%s%d", 6486 "%s%d",
6457 kNativeWrappersClass, 6487 kNativeWrappersClass,
6458 fld_cnt); 6488 fld_cnt);
6459 cls_name = Symbols::New(name_buffer); 6489 cls_name = Symbols::New(name_buffer);
6460 Class::NewNativeWrapper(native_flds_lib, cls_name, fld_cnt); 6490 Class::NewNativeWrapper(native_flds_lib, cls_name, fld_cnt);
6461 } 6491 }
6462 } 6492 }
6463 6493
6464 6494
6495 void Library::InitScalarlistLibrary(Isolate* isolate) {
6496 const String& url = Symbols::DartScalarlist();
6497 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6498 lib.Register();
6499 const Library& collection_lib =
6500 Library::Handle(Library::CollectionLibrary());
6501 const Namespace& collection_ns = Namespace::Handle(
6502 Namespace::New(collection_lib, Array::Handle(), Array::Handle()));
6503 lib.AddImport(collection_ns);
6504 isolate->object_store()->set_scalarlist_library(lib);
6505 }
6506
6507
6508 void Library::InitUriLibrary(Isolate* isolate) {
6509 const String& url = Symbols::DartUri();
6510 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6511 lib.Register();
6512 const Library& math_lib = Library::Handle(Library::MathLibrary());
6513 const Namespace& math_ns = Namespace::Handle(
6514 Namespace::New(math_lib, Array::Handle(), Array::Handle()));
6515 const Library& utf_lib = Library::Handle(Library::UtfLibrary());
6516 const Namespace& utf_ns = Namespace::Handle(
6517 Namespace::New(utf_lib, Array::Handle(), Array::Handle()));
6518 lib.AddImport(math_ns);
6519 lib.AddImport(utf_ns);
6520 isolate->object_store()->set_uri_library(lib);
6521 }
6522
6523
6524 void Library::InitUtfLibrary(Isolate* isolate) {
6525 const String& url = Symbols::DartUtf();
6526 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6527 lib.Register();
6528 const Library& async_lib = Library::Handle(Library::ASyncLibrary());
6529 const Namespace& async_ns = Namespace::Handle(
6530 Namespace::New(async_lib, Array::Handle(), Array::Handle()));
6531 lib.AddImport(async_ns);
6532 isolate->object_store()->set_utf_library(lib);
6533 }
6534
6535
6465 RawLibrary* Library::LookupLibrary(const String &url) { 6536 RawLibrary* Library::LookupLibrary(const String &url) {
6466 Isolate* isolate = Isolate::Current(); 6537 Isolate* isolate = Isolate::Current();
6467 Library& lib = Library::Handle(isolate, Library::null()); 6538 Library& lib = Library::Handle(isolate, Library::null());
6468 String& lib_url = String::Handle(isolate, String::null()); 6539 String& lib_url = String::Handle(isolate, String::null());
6469 GrowableObjectArray& libs = GrowableObjectArray::Handle( 6540 GrowableObjectArray& libs = GrowableObjectArray::Handle(
6470 isolate, isolate->object_store()->libraries()); 6541 isolate, isolate->object_store()->libraries());
6471 for (int i = 0; i < libs.Length(); i++) { 6542 for (int i = 0; i < libs.Length(); i++) {
6472 lib ^= libs.At(i); 6543 lib ^= libs.At(i);
6473 lib_url ^= lib.url(); 6544 lib_url ^= lib.url();
6474 if (lib_url.Equals(url)) { 6545 if (lib_url.Equals(url)) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
6568 RawLibrary* Library::CollectionLibrary() { 6639 RawLibrary* Library::CollectionLibrary() {
6569 return Isolate::Current()->object_store()->collection_library(); 6640 return Isolate::Current()->object_store()->collection_library();
6570 } 6641 }
6571 6642
6572 6643
6573 RawLibrary* Library::CollectionDevLibrary() { 6644 RawLibrary* Library::CollectionDevLibrary() {
6574 return Isolate::Current()->object_store()->collection_dev_library(); 6645 return Isolate::Current()->object_store()->collection_dev_library();
6575 } 6646 }
6576 6647
6577 6648
6578 RawLibrary* Library::MathLibrary() { 6649 RawLibrary* Library::CryptoLibrary() {
6579 return Isolate::Current()->object_store()->math_library(); 6650 return Isolate::Current()->object_store()->crypto_library();
6580 } 6651 }
6581 6652
6582 6653
6583 RawLibrary* Library::IsolateLibrary() { 6654 RawLibrary* Library::IsolateLibrary() {
6584 return Isolate::Current()->object_store()->isolate_library(); 6655 return Isolate::Current()->object_store()->isolate_library();
6585 } 6656 }
6586 6657
6587 6658
6659 RawLibrary* Library::JsonLibrary() {
6660 return Isolate::Current()->object_store()->json_library();
6661 }
6662
6663
6664 RawLibrary* Library::MathLibrary() {
6665 return Isolate::Current()->object_store()->math_library();
6666 }
6667
6668
6588 RawLibrary* Library::MirrorsLibrary() { 6669 RawLibrary* Library::MirrorsLibrary() {
6589 return Isolate::Current()->object_store()->mirrors_library(); 6670 return Isolate::Current()->object_store()->mirrors_library();
6590 } 6671 }
6591 6672
6592 6673
6674 RawLibrary* Library::NativeWrappersLibrary() {
6675 return Isolate::Current()->object_store()->native_wrappers_library();
6676 }
6677
6678
6593 RawLibrary* Library::ScalarlistLibrary() { 6679 RawLibrary* Library::ScalarlistLibrary() {
6594 return Isolate::Current()->object_store()->scalarlist_library(); 6680 return Isolate::Current()->object_store()->scalarlist_library();
6595 } 6681 }
6596 6682
6597 6683
6598 RawLibrary* Library::NativeWrappersLibrary() { 6684 RawLibrary* Library::UriLibrary() {
6599 return Isolate::Current()->object_store()->native_wrappers_library(); 6685 return Isolate::Current()->object_store()->uri_library();
6686 }
6687
6688
6689 RawLibrary* Library::UtfLibrary() {
6690 return Isolate::Current()->object_store()->utf_library();
6600 } 6691 }
6601 6692
6602 6693
6603 const char* Library::ToCString() const { 6694 const char* Library::ToCString() const {
6604 const char* kFormat = "Library:'%s'"; 6695 const char* kFormat = "Library:'%s'";
6605 const String& name = String::Handle(url()); 6696 const String& name = String::Handle(url());
6606 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; 6697 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1;
6607 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 6698 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
6608 OS::SNPrint(chars, len, kFormat, name.ToCString()); 6699 OS::SNPrint(chars, len, kFormat, name.ToCString());
6609 return chars; 6700 return chars;
(...skipping 6291 matching lines...) Expand 10 before | Expand all | Expand 10 after
12901 } 12992 }
12902 return result.raw(); 12993 return result.raw();
12903 } 12994 }
12904 12995
12905 12996
12906 const char* WeakProperty::ToCString() const { 12997 const char* WeakProperty::ToCString() const {
12907 return "_WeakProperty"; 12998 return "_WeakProperty";
12908 } 12999 }
12909 13000
12910 } // namespace dart 13001 } // 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