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

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

Issue 14520010: First step towards loading the core library scripts directly from the sources (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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"
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 const Library& lib) { 670 const Library& lib) {
671 ASSERT(public_class_name.Length() > 0); 671 ASSERT(public_class_name.Length() > 0);
672 ASSERT(public_class_name.CharAt(0) == '_'); 672 ASSERT(public_class_name.CharAt(0) == '_');
673 String& str = String::Handle(); 673 String& str = String::Handle();
674 str = lib.PrivateName(public_class_name); 674 str = lib.PrivateName(public_class_name);
675 cls.set_name(str); 675 cls.set_name(str);
676 lib.AddClass(cls); 676 lib.AddClass(cls);
677 } 677 }
678 678
679 679
680 #define LOAD_LIBRARY(name, raw_name) \
681 url = Symbols::Dart##name().raw(); \
682 lib = Library::LookupLibrary(url); \
683 if (lib.IsNull()) { \
684 lib = Library::NewLibraryHelper(url, true); \
685 lib.Register(); \
686 } \
687 isolate->object_store()->set_##raw_name##_library(lib); \
688
689 #define INIT_LIBRARY(name, raw_name, has_patch) \
690 LOAD_LIBRARY(name, raw_name) \
691 script = Bootstrap::Load##name##Script(false); \
692 error = Bootstrap::Compile(lib, script); \
693 if (!error.IsNull()) { \
694 return error.raw(); \
695 } \
696 if (has_patch) { \
697 script = Bootstrap::Load##name##Script(true); \
698 error = lib.Patch(script); \
699 if (!error.IsNull()) { \
700 return error.raw(); \
701 } \
702 } \
703
704
705 RawError* Object::Init(Isolate* isolate) { 680 RawError* Object::Init(Isolate* isolate) {
706 TIMERSCOPE(time_bootstrap); 681 TIMERSCOPE(time_bootstrap);
707 ObjectStore* object_store = isolate->object_store(); 682 ObjectStore* object_store = isolate->object_store();
708 683
709 Class& cls = Class::Handle(); 684 Class& cls = Class::Handle();
710 Type& type = Type::Handle(); 685 Type& type = Type::Handle();
711 Array& array = Array::Handle(); 686 Array& array = Array::Handle();
712 String& url = String::Handle();
713 Library& lib = Library::Handle(); 687 Library& lib = Library::Handle();
714 Script& script = Script::Handle();
715 Error& error = Error::Handle();
716 688
717 // All RawArray fields will be initialized to an empty array, therefore 689 // All RawArray fields will be initialized to an empty array, therefore
718 // initialize array class first. 690 // initialize array class first.
719 cls = Class::New<Array>(); 691 cls = Class::New<Array>();
720 object_store->set_array_class(cls); 692 object_store->set_array_class(cls);
721 693
722 // Array and ImmutableArray are the only VM classes that are parameterized. 694 // Array and ImmutableArray are the only VM classes that are parameterized.
723 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we 695 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we
724 // need to set the offset of their type_arguments_ field, which is explicitly 696 // need to set the offset of their type_arguments_ field, which is explicitly
725 // declared in RawArray. 697 // declared in RawArray.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 RegisterClass(cls, Symbols::StackTrace(), core_lib); 808 RegisterClass(cls, Symbols::StackTrace(), core_lib);
837 pending_classes.Add(cls, Heap::kOld); 809 pending_classes.Add(cls, Heap::kOld);
838 // Super type set below, after Object is allocated. 810 // Super type set below, after Object is allocated.
839 811
840 cls = Class::New<JSRegExp>(); 812 cls = Class::New<JSRegExp>();
841 object_store->set_jsregexp_class(cls); 813 object_store->set_jsregexp_class(cls);
842 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib); 814 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib);
843 pending_classes.Add(cls, Heap::kOld); 815 pending_classes.Add(cls, Heap::kOld);
844 816
845 // Initialize the base interfaces used by the core VM classes. 817 // Initialize the base interfaces used by the core VM classes.
846 script = Bootstrap::LoadCoreScript(false);
847 818
848 // Allocate and initialize the pre-allocated classes in the core library. 819 // Allocate and initialize the pre-allocated classes in the core library.
849 cls = Class::New<Instance>(kInstanceCid); 820 cls = Class::New<Instance>(kInstanceCid);
850 object_store->set_object_class(cls); 821 object_store->set_object_class(cls);
851 cls.set_name(Symbols::Object()); 822 cls.set_name(Symbols::Object());
852 cls.set_script(script); 823 // This class has no script object associated with it, it is an internal VM
824 // class with no associated source code.
Ivan Posva 2013/04/29 21:13:47 Although the methods associated with this class wi
siva 2013/04/29 21:47:38 True. I changed the commend to reflect that. On
853 cls.set_is_prefinalized(); 825 cls.set_is_prefinalized();
854 core_lib.AddClass(cls); 826 core_lib.AddClass(cls);
855 pending_classes.Add(cls, Heap::kOld); 827 pending_classes.Add(cls, Heap::kOld);
856 type = Type::NewNonParameterizedType(cls); 828 type = Type::NewNonParameterizedType(cls);
857 object_store->set_object_type(type); 829 object_store->set_object_type(type);
858 830
859 cls = object_store->type_class(); 831 cls = object_store->type_class();
860 RegisterPrivateClass(cls, Symbols::Type(), core_lib); 832 RegisterPrivateClass(cls, Symbols::Type(), core_lib);
861 pending_classes.Add(cls, Heap::kOld); 833 pending_classes.Add(cls, Heap::kOld);
862 834
(...skipping 30 matching lines...) Expand all
893 object_store->set_weak_property_class(cls); 865 object_store->set_weak_property_class(cls);
894 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); 866 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib);
895 867
896 // Setup some default native field classes which can be extended for 868 // Setup some default native field classes which can be extended for
897 // specifying native fields in dart classes. 869 // specifying native fields in dart classes.
898 Library::InitNativeWrappersLibrary(isolate); 870 Library::InitNativeWrappersLibrary(isolate);
899 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null()); 871 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null());
900 872
901 // Pre-register the typed_data library so the native class implementations 873 // Pre-register the typed_data library so the native class implementations
902 // can be hooked up before compiling it. 874 // can be hooked up before compiling it.
903 LOAD_LIBRARY(TypedData, typed_data); 875 lib = Library::LookupLibrary(Symbols::DartTypedData());
876 if (lib.IsNull()) {
877 lib = Library::NewLibraryHelper(Symbols::DartTypedData(), true);
878 lib.Register();
879 isolate->object_store()->set_bootstrap_library(ObjectStore::kTypedData,
880 lib);
881 }
904 ASSERT(!lib.IsNull()); 882 ASSERT(!lib.IsNull());
905 ASSERT(lib.raw() == Library::TypedDataLibrary()); 883 ASSERT(lib.raw() == Library::TypedDataLibrary());
906 const intptr_t typed_data_class_array_length = 884 const intptr_t typed_data_class_array_length =
907 RawObject::NumberOfTypedDataClasses(); 885 RawObject::NumberOfTypedDataClasses();
908 Array& typed_data_classes = 886 Array& typed_data_classes =
909 Array::Handle(Array::New(typed_data_class_array_length)); 887 Array::Handle(Array::New(typed_data_class_array_length));
910 int index = 0; 888 int index = 0;
911 #define REGISTER_TYPED_DATA_CLASS(clazz) \ 889 #define REGISTER_TYPED_DATA_CLASS(clazz) \
912 cls = Class::NewTypedDataClass(kTypedData##clazz##Cid); \ 890 cls = Class::NewTypedDataClass(kTypedData##clazz##Cid); \
913 index = kTypedData##clazz##Cid - kTypedDataInt8ArrayCid; \ 891 index = kTypedData##clazz##Cid - kTypedDataInt8ArrayCid; \
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 pending_classes.Add(cls, Heap::kOld); 950 pending_classes.Add(cls, Heap::kOld);
973 type = Type::NewNonParameterizedType(cls); 951 type = Type::NewNonParameterizedType(cls);
974 object_store->set_function_type(type); 952 object_store->set_function_type(type);
975 953
976 cls = Class::New<Number>(); 954 cls = Class::New<Number>();
977 RegisterClass(cls, Symbols::Number(), core_lib); 955 RegisterClass(cls, Symbols::Number(), core_lib);
978 pending_classes.Add(cls, Heap::kOld); 956 pending_classes.Add(cls, Heap::kOld);
979 type = Type::NewNonParameterizedType(cls); 957 type = Type::NewNonParameterizedType(cls);
980 object_store->set_number_type(type); 958 object_store->set_number_type(type);
981 959
982 cls = Class::New<Instance>(Symbols::Int(), script, Scanner::kDummyTokenIndex); 960 cls = Class::New<Instance>(kIllegalCid);
983 RegisterClass(cls, Symbols::Int(), core_lib); 961 RegisterClass(cls, Symbols::Int(), core_lib);
984 pending_classes.Add(cls, Heap::kOld); 962 pending_classes.Add(cls, Heap::kOld);
985 type = Type::NewNonParameterizedType(cls); 963 type = Type::NewNonParameterizedType(cls);
986 object_store->set_int_type(type); 964 object_store->set_int_type(type);
987 965
988 cls = Class::New<Instance>(Symbols::Double(), 966 cls = Class::New<Instance>(kIllegalCid);
989 script,
990 Scanner::kDummyTokenIndex);
991 RegisterClass(cls, Symbols::Double(), core_lib); 967 RegisterClass(cls, Symbols::Double(), core_lib);
992 pending_classes.Add(cls, Heap::kOld); 968 pending_classes.Add(cls, Heap::kOld);
993 type = Type::NewNonParameterizedType(cls); 969 type = Type::NewNonParameterizedType(cls);
994 object_store->set_double_type(type); 970 object_store->set_double_type(type);
995 971
996 name = Symbols::New("String"); 972 name = Symbols::New("String");
997 cls = Class::New<Instance>(name, script, Scanner::kDummyTokenIndex); 973 cls = Class::New<Instance>(kIllegalCid);
998 RegisterClass(cls, name, core_lib); 974 RegisterClass(cls, name, core_lib);
999 pending_classes.Add(cls, Heap::kOld); 975 pending_classes.Add(cls, Heap::kOld);
1000 type = Type::NewNonParameterizedType(cls); 976 type = Type::NewNonParameterizedType(cls);
1001 object_store->set_string_type(type); 977 object_store->set_string_type(type);
1002 978
1003 cls = Class::New<Instance>(Symbols::List(), 979 cls = Class::New<Instance>(kIllegalCid);
1004 script,
1005 Scanner::kDummyTokenIndex);
1006 RegisterClass(cls, Symbols::List(), core_lib); 980 RegisterClass(cls, Symbols::List(), core_lib);
1007 pending_classes.Add(cls, Heap::kOld); 981 pending_classes.Add(cls, Heap::kOld);
1008 object_store->set_list_class(cls); 982 object_store->set_list_class(cls);
1009 983
1010 cls = object_store->bool_class(); 984 cls = object_store->bool_class();
1011 type = Type::NewNonParameterizedType(cls); 985 type = Type::NewNonParameterizedType(cls);
1012 object_store->set_bool_type(type); 986 object_store->set_bool_type(type);
1013 987
1014 cls = object_store->smi_class(); 988 cls = object_store->smi_class();
1015 type = Type::NewNonParameterizedType(cls); 989 type = Type::NewNonParameterizedType(cls);
(...skipping 18 matching lines...) Expand all
1034 // The class 'dynamic' is registered in the class dictionary because its name 1008 // The class 'dynamic' is registered in the class dictionary because its name
1035 // is a built-in identifier, rather than a reserved keyword. Its name is not 1009 // is a built-in identifier, rather than a reserved keyword. Its name is not
1036 // heap allocated, because the class resides in the VM isolate. 1010 // heap allocated, because the class resides in the VM isolate.
1037 // The corresponding type, the "unknown type", is stored in the object store. 1011 // The corresponding type, the "unknown type", is stored in the object store.
1038 cls = dynamic_class(); 1012 cls = dynamic_class();
1039 type = Type::NewNonParameterizedType(cls); 1013 type = Type::NewNonParameterizedType(cls);
1040 object_store->set_dynamic_type(type); 1014 object_store->set_dynamic_type(type);
1041 1015
1042 // Finish the initialization by compiling the bootstrap scripts containing the 1016 // Finish the initialization by compiling the bootstrap scripts containing the
1043 // base interfaces and the implementation of the internal classes. 1017 // base interfaces and the implementation of the internal classes.
1044 INIT_LIBRARY(Core, core, true); 1018 const Error& error = Error::Handle(Bootstrap::LoadandCompileScripts());
1045 1019 if (!error.IsNull()) {
1046 INIT_LIBRARY(Async, async, true); 1020 return error.raw();
1047 INIT_LIBRARY(Collection, collection, true); 1021 }
1048 INIT_LIBRARY(CollectionDev, collection_dev, true);
1049 INIT_LIBRARY(Crypto, crypto, false);
1050 INIT_LIBRARY(Isolate, isolate, true);
1051 INIT_LIBRARY(Json, json, true);
1052 INIT_LIBRARY(Math, math, true);
1053 INIT_LIBRARY(Mirrors, mirrors, true);
1054 INIT_LIBRARY(TypedData, typed_data, true);
1055 INIT_LIBRARY(Utf, utf, false);
1056 INIT_LIBRARY(Uri, uri, false);
1057
1058 Bootstrap::SetupNativeResolver();
1059 1022
1060 // Remove the Object superclass cycle by setting the super type to null (not 1023 // Remove the Object superclass cycle by setting the super type to null (not
1061 // to the type of null). 1024 // to the type of null).
1062 cls = object_store->object_class(); 1025 cls = object_store->object_class();
1063 cls.set_super_type(Type::Handle()); 1026 cls.set_super_type(Type::Handle());
1064 1027
1065 ClassFinalizer::VerifyBootstrapClasses(); 1028 ClassFinalizer::VerifyBootstrapClasses();
1066 MarkInvisibleFunctions(); 1029 MarkInvisibleFunctions();
1067 1030
1068 // Set up the intrinsic state of all functions (core, math and scalar list). 1031 // Set up the intrinsic state of all functions (core, math and scalar list).
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 result.raw_ptr()->state_bits_ = 0; 1796 result.raw_ptr()->state_bits_ = 0;
1834 result.raw_ptr()->type_arguments_field_offset_in_words_ = kNoTypeArguments; 1797 result.raw_ptr()->type_arguments_field_offset_in_words_ = kNoTypeArguments;
1835 result.raw_ptr()->num_native_fields_ = 0; 1798 result.raw_ptr()->num_native_fields_ = 0;
1836 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; 1799 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex;
1837 result.InitEmptyFields(); 1800 result.InitEmptyFields();
1838 Isolate::Current()->class_table()->Register(result); 1801 Isolate::Current()->class_table()->Register(result);
1839 return result.raw(); 1802 return result.raw();
1840 } 1803 }
1841 1804
1842 1805
1843 template <class FakeInstance>
1844 RawClass* Class::New(const String& name, 1806 RawClass* Class::New(const String& name,
1845 const Script& script, 1807 const Script& script,
1846 intptr_t token_pos) { 1808 intptr_t token_pos) {
1847 Class& result = Class::Handle(New<FakeInstance>(kIllegalCid)); 1809 Class& result = Class::Handle(New<Instance>(kIllegalCid));
1848 result.set_name(name); 1810 result.set_name(name);
1849 result.set_script(script); 1811 result.set_script(script);
1850 result.set_token_pos(token_pos); 1812 result.set_token_pos(token_pos);
1851 return result.raw(); 1813 return result.raw();
1852 } 1814 }
1853 1815
1854 1816
1855 RawClass* Class::New(const String& name,
1856 const Script& script,
1857 intptr_t token_pos) {
1858 Class& result = Class::Handle(New<Instance>(name, script, token_pos));
1859 return result.raw();
1860 }
1861
1862
1863 RawClass* Class::NewSignatureClass(const String& name, 1817 RawClass* Class::NewSignatureClass(const String& name,
1864 const Function& signature_function, 1818 const Function& signature_function,
1865 const Script& script, 1819 const Script& script,
1866 intptr_t token_pos) { 1820 intptr_t token_pos) {
1867 const Class& result = Class::Handle(New<Instance>(name, script, token_pos)); 1821 const Class& result = Class::Handle(New(name, script, token_pos));
1868 const Type& super_type = Type::Handle(Type::ObjectType()); 1822 const Type& super_type = Type::Handle(Type::ObjectType());
1869 ASSERT(!super_type.IsNull()); 1823 ASSERT(!super_type.IsNull());
1870 // Instances of a signature class can only be closures. 1824 // Instances of a signature class can only be closures.
1871 result.set_instance_size(Closure::InstanceSize()); 1825 result.set_instance_size(Closure::InstanceSize());
1872 result.set_next_field_offset(Closure::InstanceSize()); 1826 result.set_next_field_offset(Closure::InstanceSize());
1873 result.set_super_type(super_type); 1827 result.set_super_type(super_type);
1874 result.set_type_arguments_field_offset(Closure::type_arguments_offset()); 1828 result.set_type_arguments_field_offset(Closure::type_arguments_offset());
1875 // Implements interface "Function". 1829 // Implements interface "Function".
1876 const Type& function_type = Type::Handle(Type::Function()); 1830 const Type& function_type = Type::Handle(Type::Function());
1877 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); 1831 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 } 1866 }
1913 set_is_prefinalized(); 1867 set_is_prefinalized();
1914 } 1868 }
1915 1869
1916 1870
1917 RawClass* Class::NewNativeWrapper(const Library& library, 1871 RawClass* Class::NewNativeWrapper(const Library& library,
1918 const String& name, 1872 const String& name,
1919 int field_count) { 1873 int field_count) {
1920 Class& cls = Class::Handle(library.LookupClass(name)); 1874 Class& cls = Class::Handle(library.LookupClass(name));
1921 if (cls.IsNull()) { 1875 if (cls.IsNull()) {
1922 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex); 1876 cls = New(name, Script::Handle(), Scanner::kDummyTokenIndex);
1923 cls.SetFields(Object::empty_array()); 1877 cls.SetFields(Object::empty_array());
1924 cls.SetFunctions(Object::empty_array()); 1878 cls.SetFunctions(Object::empty_array());
1925 // Set super class to Object. 1879 // Set super class to Object.
1926 cls.set_super_type(Type::Handle(Type::ObjectType())); 1880 cls.set_super_type(Type::Handle(Type::ObjectType()));
1927 // Compute instance size. First word contains a pointer to a properly 1881 // Compute instance size. First word contains a pointer to a properly
1928 // sized typed array once the first native field has been set. 1882 // sized typed array once the first native field has been set.
1929 intptr_t instance_size = sizeof(RawObject) + kWordSize; 1883 intptr_t instance_size = sizeof(RawObject) + kWordSize;
1930 cls.set_instance_size(RoundedAllocationSize(instance_size)); 1884 cls.set_instance_size(RoundedAllocationSize(instance_size));
1931 cls.set_next_field_offset(instance_size); 1885 cls.set_next_field_offset(instance_size);
1932 cls.set_num_native_fields(field_count); 1886 cls.set_num_native_fields(field_count);
(...skipping 4505 matching lines...) Expand 10 before | Expand all | Expand 10 after
6438 RawLibrary* Library::New(const String& url) { 6392 RawLibrary* Library::New(const String& url) {
6439 return NewLibraryHelper(url, false); 6393 return NewLibraryHelper(url, false);
6440 } 6394 }
6441 6395
6442 6396
6443 void Library::InitCoreLibrary(Isolate* isolate) { 6397 void Library::InitCoreLibrary(Isolate* isolate) {
6444 const String& core_lib_url = Symbols::DartCore(); 6398 const String& core_lib_url = Symbols::DartCore();
6445 const Library& core_lib = 6399 const Library& core_lib =
6446 Library::Handle(Library::NewLibraryHelper(core_lib_url, false)); 6400 Library::Handle(Library::NewLibraryHelper(core_lib_url, false));
6447 core_lib.Register(); 6401 core_lib.Register();
6448 isolate->object_store()->set_core_library(core_lib); 6402 isolate->object_store()->set_bootstrap_library(ObjectStore::kCore, core_lib);
6449 isolate->object_store()->set_root_library(Library::Handle()); 6403 isolate->object_store()->set_root_library(Library::Handle());
6450 6404
6451 // Hook up predefined classes without setting their library pointers. These 6405 // Hook up predefined classes without setting their library pointers. These
6452 // classes are coming from the VM isolate, and are shared between multiple 6406 // classes are coming from the VM isolate, and are shared between multiple
6453 // isolates so setting their library pointers would be wrong. 6407 // isolates so setting their library pointers would be wrong.
6454 const Class& cls = Class::Handle(Object::dynamic_class()); 6408 const Class& cls = Class::Handle(Object::dynamic_class());
6455 core_lib.AddObject(cls, String::Handle(cls.Name())); 6409 core_lib.AddObject(cls, String::Handle(cls.Name()));
6456 } 6410 }
6457 6411
6458 6412
(...skipping 6726 matching lines...) Expand 10 before | Expand all | Expand 10 after
13185 } 13139 }
13186 return result.raw(); 13140 return result.raw();
13187 } 13141 }
13188 13142
13189 13143
13190 const char* WeakProperty::ToCString() const { 13144 const char* WeakProperty::ToCString() const {
13191 return "_WeakProperty"; 13145 return "_WeakProperty";
13192 } 13146 }
13193 13147
13194 } // namespace dart 13148 } // namespace dart
OLDNEW
« runtime/vm/bootstrap.cc ('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