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

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
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,
Ivan Posva 2013/02/22 00:39:38 Why are you not using INIT_LIBRARY to initialize t
siva 2013/02/22 01:01:19 Will make that change in a new CL as I did not wan
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 5269 matching lines...) Expand 10 before | Expand all | Expand 10 after
6366 6389
6367 6390
6368 void Library::InitCollectionDevLibrary(Isolate* isolate) { 6391 void Library::InitCollectionDevLibrary(Isolate* isolate) {
6369 const String& url = Symbols::DartCollectionDev(); 6392 const String& url = Symbols::DartCollectionDev();
6370 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); 6393 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6371 lib.Register(); 6394 lib.Register();
6372 isolate->object_store()->set_collection_dev_library(lib); 6395 isolate->object_store()->set_collection_dev_library(lib);
6373 } 6396 }
6374 6397
6375 6398
6376 void Library::InitMathLibrary(Isolate* isolate) { 6399 void Library::InitCryptoLibrary(Isolate* isolate) {
6377 const String& url = Symbols::DartMath(); 6400 const String& url = Symbols::DartCrypto();
6378 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); 6401 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6379 lib.Register(); 6402 lib.Register();
6380 isolate->object_store()->set_math_library(lib); 6403 const Library& math_lib = Library::Handle(Library::MathLibrary());
6404 const Namespace& math_ns = Namespace::Handle(
6405 Namespace::New(math_lib, Array::Handle(), Array::Handle()));
6406 lib.AddImport(math_ns);
6407 isolate->object_store()->set_crypto_library(lib);
6381 } 6408 }
6382 6409
6383 6410
6384 void Library::InitIsolateLibrary(Isolate* isolate) { 6411 void Library::InitIsolateLibrary(Isolate* isolate) {
6385 const String& url = Symbols::DartIsolate(); 6412 const String& url = Symbols::DartIsolate();
6386 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); 6413 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6387 lib.Register(); 6414 lib.Register();
6388 const Library& async_lib = Library::Handle(Library::ASyncLibrary()); 6415 const Library& async_lib = Library::Handle(Library::ASyncLibrary());
6389 const Namespace& async_ns = Namespace::Handle( 6416 const Namespace& async_ns = Namespace::Handle(
6390 Namespace::New(async_lib, Array::Handle(), Array::Handle())); 6417 Namespace::New(async_lib, Array::Handle(), Array::Handle()));
6391 lib.AddImport(async_ns); 6418 lib.AddImport(async_ns);
6392 isolate->object_store()->set_isolate_library(lib); 6419 isolate->object_store()->set_isolate_library(lib);
6393 } 6420 }
6394 6421
6395 6422
6423 void Library::InitJsonLibrary(Isolate* isolate) {
6424 const String& url = Symbols::DartJson();
6425 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6426 lib.Register();
6427 isolate->object_store()->set_json_library(lib);
6428 }
6429
6430
6431 void Library::InitMathLibrary(Isolate* isolate) {
6432 const String& url = Symbols::DartMath();
6433 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6434 lib.Register();
6435 isolate->object_store()->set_math_library(lib);
6436 }
6437
6438
6396 void Library::InitMirrorsLibrary(Isolate* isolate) { 6439 void Library::InitMirrorsLibrary(Isolate* isolate) {
6397 const String& url = Symbols::DartMirrors(); 6440 const String& url = Symbols::DartMirrors();
6398 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); 6441 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6399 lib.Register(); 6442 lib.Register();
6400 const Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); 6443 const Library& isolate_lib = Library::Handle(Library::IsolateLibrary());
6401 const Namespace& isolate_ns = Namespace::Handle( 6444 const Namespace& isolate_ns = Namespace::Handle(
6402 Namespace::New(isolate_lib, Array::Handle(), Array::Handle())); 6445 Namespace::New(isolate_lib, Array::Handle(), Array::Handle()));
6403 lib.AddImport(isolate_ns); 6446 lib.AddImport(isolate_ns);
6404 const Library& async_lib = Library::Handle(Library::ASyncLibrary()); 6447 const Library& async_lib = Library::Handle(Library::ASyncLibrary());
6405 const Namespace& async_ns = Namespace::Handle( 6448 const Namespace& async_ns = Namespace::Handle(
6406 Namespace::New(async_lib, Array::Handle(), Array::Handle())); 6449 Namespace::New(async_lib, Array::Handle(), Array::Handle()));
6407 lib.AddImport(async_ns); 6450 lib.AddImport(async_ns);
6408 const Library& wrappers_lib = 6451 const Library& wrappers_lib =
6409 Library::Handle(Library::NativeWrappersLibrary()); 6452 Library::Handle(Library::NativeWrappersLibrary());
6410 const Namespace& wrappers_ns = Namespace::Handle( 6453 const Namespace& wrappers_ns = Namespace::Handle(
6411 Namespace::New(wrappers_lib, Array::Handle(), Array::Handle())); 6454 Namespace::New(wrappers_lib, Array::Handle(), Array::Handle()));
6412 lib.AddImport(wrappers_ns); 6455 lib.AddImport(wrappers_ns);
6413 isolate->object_store()->set_mirrors_library(lib); 6456 isolate->object_store()->set_mirrors_library(lib);
6414 } 6457 }
6415 6458
6416 6459
6417 void Library::InitScalarlistLibrary(Isolate* isolate) {
6418 const String& url = Symbols::DartScalarlist();
6419 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6420 lib.Register();
6421 const Library& collection_lib =
6422 Library::Handle(Library::CollectionLibrary());
6423 const Namespace& collection_ns = Namespace::Handle(
6424 Namespace::New(collection_lib, Array::Handle(), Array::Handle()));
6425 lib.AddImport(collection_ns);
6426 isolate->object_store()->set_scalarlist_library(lib);
6427 }
6428
6429
6430 void Library::InitNativeWrappersLibrary(Isolate* isolate) { 6460 void Library::InitNativeWrappersLibrary(Isolate* isolate) {
6431 static const int kNumNativeWrappersClasses = 4; 6461 static const int kNumNativeWrappersClasses = 4;
6432 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); 6462 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10);
6433 const String& native_flds_lib_url = Symbols::DartNativeWrappers(); 6463 const String& native_flds_lib_url = Symbols::DartNativeWrappers();
6434 const Library& native_flds_lib = Library::Handle( 6464 const Library& native_flds_lib = Library::Handle(
6435 Library::NewLibraryHelper(native_flds_lib_url, false)); 6465 Library::NewLibraryHelper(native_flds_lib_url, false));
6436 native_flds_lib.Register(); 6466 native_flds_lib.Register();
6437 isolate->object_store()->set_native_wrappers_library(native_flds_lib); 6467 isolate->object_store()->set_native_wrappers_library(native_flds_lib);
6438 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; 6468 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass";
6439 static const int kNameLength = 25; 6469 static const int kNameLength = 25;
6440 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1)); 6470 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1));
6441 char name_buffer[kNameLength]; 6471 char name_buffer[kNameLength];
6442 String& cls_name = String::Handle(); 6472 String& cls_name = String::Handle();
6443 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) { 6473 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) {
6444 OS::SNPrint(name_buffer, 6474 OS::SNPrint(name_buffer,
6445 kNameLength, 6475 kNameLength,
6446 "%s%d", 6476 "%s%d",
6447 kNativeWrappersClass, 6477 kNativeWrappersClass,
6448 fld_cnt); 6478 fld_cnt);
6449 cls_name = Symbols::New(name_buffer); 6479 cls_name = Symbols::New(name_buffer);
6450 Class::NewNativeWrapper(native_flds_lib, cls_name, fld_cnt); 6480 Class::NewNativeWrapper(native_flds_lib, cls_name, fld_cnt);
6451 } 6481 }
6452 } 6482 }
6453 6483
6454 6484
6485 void Library::InitScalarlistLibrary(Isolate* isolate) {
6486 const String& url = Symbols::DartScalarlist();
6487 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6488 lib.Register();
6489 const Library& collection_lib =
6490 Library::Handle(Library::CollectionLibrary());
6491 const Namespace& collection_ns = Namespace::Handle(
6492 Namespace::New(collection_lib, Array::Handle(), Array::Handle()));
6493 lib.AddImport(collection_ns);
6494 isolate->object_store()->set_scalarlist_library(lib);
6495 }
6496
6497
6498 void Library::InitUriLibrary(Isolate* isolate) {
6499 const String& url = Symbols::DartUri();
6500 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6501 lib.Register();
6502 const Library& math_lib = Library::Handle(Library::MathLibrary());
6503 const Namespace& math_ns = Namespace::Handle(
6504 Namespace::New(math_lib, Array::Handle(), Array::Handle()));
6505 const Library& utf_lib = Library::Handle(Library::UtfLibrary());
6506 const Namespace& utf_ns = Namespace::Handle(
6507 Namespace::New(utf_lib, Array::Handle(), Array::Handle()));
6508 lib.AddImport(math_ns);
6509 lib.AddImport(utf_ns);
6510 isolate->object_store()->set_uri_library(lib);
6511 }
6512
6513
6514 void Library::InitUtfLibrary(Isolate* isolate) {
6515 const String& url = Symbols::DartUtf();
6516 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true));
6517 lib.Register();
6518 const Library& async_lib = Library::Handle(Library::ASyncLibrary());
6519 const Namespace& async_ns = Namespace::Handle(
6520 Namespace::New(async_lib, Array::Handle(), Array::Handle()));
6521 lib.AddImport(async_ns);
6522 isolate->object_store()->set_utf_library(lib);
6523 }
6524
6525
6455 RawLibrary* Library::LookupLibrary(const String &url) { 6526 RawLibrary* Library::LookupLibrary(const String &url) {
6456 Isolate* isolate = Isolate::Current(); 6527 Isolate* isolate = Isolate::Current();
6457 Library& lib = Library::Handle(isolate, Library::null()); 6528 Library& lib = Library::Handle(isolate, Library::null());
6458 String& lib_url = String::Handle(isolate, String::null()); 6529 String& lib_url = String::Handle(isolate, String::null());
6459 GrowableObjectArray& libs = GrowableObjectArray::Handle( 6530 GrowableObjectArray& libs = GrowableObjectArray::Handle(
6460 isolate, isolate->object_store()->libraries()); 6531 isolate, isolate->object_store()->libraries());
6461 for (int i = 0; i < libs.Length(); i++) { 6532 for (int i = 0; i < libs.Length(); i++) {
6462 lib ^= libs.At(i); 6533 lib ^= libs.At(i);
6463 lib_url ^= lib.url(); 6534 lib_url ^= lib.url();
6464 if (lib_url.Equals(url)) { 6535 if (lib_url.Equals(url)) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
6558 RawLibrary* Library::CollectionLibrary() { 6629 RawLibrary* Library::CollectionLibrary() {
6559 return Isolate::Current()->object_store()->collection_library(); 6630 return Isolate::Current()->object_store()->collection_library();
6560 } 6631 }
6561 6632
6562 6633
6563 RawLibrary* Library::CollectionDevLibrary() { 6634 RawLibrary* Library::CollectionDevLibrary() {
6564 return Isolate::Current()->object_store()->collection_dev_library(); 6635 return Isolate::Current()->object_store()->collection_dev_library();
6565 } 6636 }
6566 6637
6567 6638
6568 RawLibrary* Library::MathLibrary() { 6639 RawLibrary* Library::CryptoLibrary() {
6569 return Isolate::Current()->object_store()->math_library(); 6640 return Isolate::Current()->object_store()->crypto_library();
6570 } 6641 }
6571 6642
6572 6643
6573 RawLibrary* Library::IsolateLibrary() { 6644 RawLibrary* Library::IsolateLibrary() {
6574 return Isolate::Current()->object_store()->isolate_library(); 6645 return Isolate::Current()->object_store()->isolate_library();
6575 } 6646 }
6576 6647
6577 6648
6649 RawLibrary* Library::JsonLibrary() {
6650 return Isolate::Current()->object_store()->json_library();
6651 }
6652
6653
6654 RawLibrary* Library::MathLibrary() {
6655 return Isolate::Current()->object_store()->math_library();
6656 }
6657
6658
6578 RawLibrary* Library::MirrorsLibrary() { 6659 RawLibrary* Library::MirrorsLibrary() {
6579 return Isolate::Current()->object_store()->mirrors_library(); 6660 return Isolate::Current()->object_store()->mirrors_library();
6580 } 6661 }
6581 6662
6582 6663
6664 RawLibrary* Library::NativeWrappersLibrary() {
6665 return Isolate::Current()->object_store()->native_wrappers_library();
6666 }
6667
6668
6583 RawLibrary* Library::ScalarlistLibrary() { 6669 RawLibrary* Library::ScalarlistLibrary() {
6584 return Isolate::Current()->object_store()->scalarlist_library(); 6670 return Isolate::Current()->object_store()->scalarlist_library();
6585 } 6671 }
6586 6672
6587 6673
6588 RawLibrary* Library::NativeWrappersLibrary() { 6674 RawLibrary* Library::UriLibrary() {
6589 return Isolate::Current()->object_store()->native_wrappers_library(); 6675 return Isolate::Current()->object_store()->uri_library();
6676 }
6677
6678
6679 RawLibrary* Library::UtfLibrary() {
6680 return Isolate::Current()->object_store()->utf_library();
6590 } 6681 }
6591 6682
6592 6683
6593 const char* Library::ToCString() const { 6684 const char* Library::ToCString() const {
6594 const char* kFormat = "Library:'%s'"; 6685 const char* kFormat = "Library:'%s'";
6595 const String& name = String::Handle(url()); 6686 const String& name = String::Handle(url());
6596 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; 6687 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1;
6597 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 6688 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
6598 OS::SNPrint(chars, len, kFormat, name.ToCString()); 6689 OS::SNPrint(chars, len, kFormat, name.ToCString());
6599 return chars; 6690 return chars;
(...skipping 6291 matching lines...) Expand 10 before | Expand all | Expand 10 after
12891 } 12982 }
12892 return result.raw(); 12983 return result.raw();
12893 } 12984 }
12894 12985
12895 12986
12896 const char* WeakProperty::ToCString() const { 12987 const char* WeakProperty::ToCString() const {
12897 return "_WeakProperty"; 12988 return "_WeakProperty";
12898 } 12989 }
12899 12990
12900 } // namespace dart 12991 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698