OLD | NEW |
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 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 str = lib.PrivateName(public_class_name); | 884 str = lib.PrivateName(public_class_name); |
885 cls.set_name(str); | 885 cls.set_name(str); |
886 lib.AddClass(cls); | 886 lib.AddClass(cls); |
887 } | 887 } |
888 | 888 |
889 | 889 |
890 RawError* Object::Init(Isolate* isolate) { | 890 RawError* Object::Init(Isolate* isolate) { |
891 TIMERSCOPE(isolate, time_bootstrap); | 891 TIMERSCOPE(isolate, time_bootstrap); |
892 ObjectStore* object_store = isolate->object_store(); | 892 ObjectStore* object_store = isolate->object_store(); |
893 | 893 |
894 Class& cls = Class::Handle(); | 894 Class& cls = Class::Handle(isolate); |
895 Type& type = Type::Handle(); | 895 Type& type = Type::Handle(isolate); |
896 Array& array = Array::Handle(); | 896 Array& array = Array::Handle(isolate); |
897 Library& lib = Library::Handle(); | 897 Library& lib = Library::Handle(isolate); |
898 | 898 |
899 // All RawArray fields will be initialized to an empty array, therefore | 899 // All RawArray fields will be initialized to an empty array, therefore |
900 // initialize array class first. | 900 // initialize array class first. |
901 cls = Class::New<Array>(); | 901 cls = Class::New<Array>(); |
902 object_store->set_array_class(cls); | 902 object_store->set_array_class(cls); |
903 | 903 |
904 // Array and ImmutableArray are the only VM classes that are parameterized. | 904 // Array and ImmutableArray are the only VM classes that are parameterized. |
905 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we | 905 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we |
906 // need to set the offset of their type_arguments_ field, which is explicitly | 906 // need to set the offset of their type_arguments_ field, which is explicitly |
907 // declared in RawArray. | 907 // declared in RawArray. |
908 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); | 908 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); |
909 cls.set_num_type_arguments(1); | 909 cls.set_num_type_arguments(1); |
910 cls.set_num_own_type_arguments(1); | 910 cls.set_num_own_type_arguments(1); |
911 | 911 |
912 // Set up the growable object array class (Has to be done after the array | 912 // Set up the growable object array class (Has to be done after the array |
913 // class is setup as one of its field is an array object). | 913 // class is setup as one of its field is an array object). |
914 cls = Class::New<GrowableObjectArray>(); | 914 cls = Class::New<GrowableObjectArray>(); |
915 object_store->set_growable_object_array_class(cls); | 915 object_store->set_growable_object_array_class(cls); |
916 cls.set_type_arguments_field_offset( | 916 cls.set_type_arguments_field_offset( |
917 GrowableObjectArray::type_arguments_offset()); | 917 GrowableObjectArray::type_arguments_offset()); |
918 cls.set_num_type_arguments(1); | 918 cls.set_num_type_arguments(1); |
919 cls.set_num_own_type_arguments(1); | 919 cls.set_num_own_type_arguments(1); |
920 | 920 |
921 // canonical_type_arguments_ are Smi terminated. | 921 // canonical_type_arguments_ are Smi terminated. |
922 // Last element contains the count of used slots. | 922 // Last element contains the count of used slots. |
923 const intptr_t kInitialCanonicalTypeArgumentsSize = 4; | 923 const intptr_t kInitialCanonicalTypeArgumentsSize = 4; |
924 array = Array::New(kInitialCanonicalTypeArgumentsSize + 1); | 924 array = Array::New(kInitialCanonicalTypeArgumentsSize + 1); |
925 array.SetAt(kInitialCanonicalTypeArgumentsSize, Smi::Handle(Smi::New(0))); | 925 array.SetAt(kInitialCanonicalTypeArgumentsSize, |
| 926 Smi::Handle(isolate, Smi::New(0))); |
926 object_store->set_canonical_type_arguments(array); | 927 object_store->set_canonical_type_arguments(array); |
927 | 928 |
928 // Setup type class early in the process. | 929 // Setup type class early in the process. |
929 cls = Class::New<Type>(); | 930 cls = Class::New<Type>(); |
930 object_store->set_type_class(cls); | 931 object_store->set_type_class(cls); |
931 | 932 |
932 cls = Class::New<TypeRef>(); | 933 cls = Class::New<TypeRef>(); |
933 object_store->set_type_ref_class(cls); | 934 object_store->set_type_ref_class(cls); |
934 | 935 |
935 cls = Class::New<TypeParameter>(); | 936 cls = Class::New<TypeParameter>(); |
(...skipping 13 matching lines...) Expand all Loading... |
949 object_store->set_one_byte_string_class(cls); | 950 object_store->set_one_byte_string_class(cls); |
950 | 951 |
951 // Pre-allocate the TwoByteString class needed by the symbol table. | 952 // Pre-allocate the TwoByteString class needed by the symbol table. |
952 cls = Class::NewStringClass(kTwoByteStringCid); | 953 cls = Class::NewStringClass(kTwoByteStringCid); |
953 object_store->set_two_byte_string_class(cls); | 954 object_store->set_two_byte_string_class(cls); |
954 | 955 |
955 // Setup the symbol table for the symbols created in the isolate. | 956 // Setup the symbol table for the symbols created in the isolate. |
956 Symbols::SetupSymbolTable(isolate); | 957 Symbols::SetupSymbolTable(isolate); |
957 | 958 |
958 // Set up the libraries array before initializing the core library. | 959 // Set up the libraries array before initializing the core library. |
959 const GrowableObjectArray& libraries = | 960 const GrowableObjectArray& libraries = GrowableObjectArray::Handle( |
960 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); | 961 isolate, GrowableObjectArray::New(Heap::kOld)); |
961 object_store->set_libraries(libraries); | 962 object_store->set_libraries(libraries); |
962 | 963 |
963 // Pre-register the core library. | 964 // Pre-register the core library. |
964 Library::InitCoreLibrary(isolate); | 965 Library::InitCoreLibrary(isolate); |
965 | 966 |
966 // Basic infrastructure has been setup, initialize the class dictionary. | 967 // Basic infrastructure has been setup, initialize the class dictionary. |
967 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 968 const Library& core_lib = Library::Handle(isolate, Library::CoreLibrary()); |
968 ASSERT(!core_lib.IsNull()); | 969 ASSERT(!core_lib.IsNull()); |
969 | 970 |
970 const GrowableObjectArray& pending_classes = | 971 const GrowableObjectArray& pending_classes = |
971 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 972 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); |
972 object_store->set_pending_classes(pending_classes); | 973 object_store->set_pending_classes(pending_classes); |
973 | 974 |
974 Context& context = Context::Handle(Context::New(0, Heap::kOld)); | 975 Context& context = Context::Handle(isolate, Context::New(0, Heap::kOld)); |
975 object_store->set_empty_context(context); | 976 object_store->set_empty_context(context); |
976 | 977 |
977 // Now that the symbol table is initialized and that the core dictionary as | 978 // Now that the symbol table is initialized and that the core dictionary as |
978 // well as the core implementation dictionary have been setup, preallocate | 979 // well as the core implementation dictionary have been setup, preallocate |
979 // remaining classes and register them by name in the dictionaries. | 980 // remaining classes and register them by name in the dictionaries. |
980 String& name = String::Handle(); | 981 String& name = String::Handle(isolate); |
981 cls = object_store->array_class(); // Was allocated above. | 982 cls = object_store->array_class(); // Was allocated above. |
982 RegisterPrivateClass(cls, Symbols::_List(), core_lib); | 983 RegisterPrivateClass(cls, Symbols::_List(), core_lib); |
983 pending_classes.Add(cls); | 984 pending_classes.Add(cls); |
984 // We cannot use NewNonParameterizedType(cls), because Array is parameterized. | 985 // We cannot use NewNonParameterizedType(cls), because Array is parameterized. |
985 type ^= Type::New(Object::Handle(cls.raw()), | 986 type ^= Type::New(Object::Handle(isolate, cls.raw()), |
986 TypeArguments::Handle(), | 987 TypeArguments::Handle(isolate), |
987 Scanner::kNoSourcePos); | 988 Scanner::kNoSourcePos); |
988 type.SetIsFinalized(); | 989 type.SetIsFinalized(); |
989 type ^= type.Canonicalize(); | 990 type ^= type.Canonicalize(); |
990 object_store->set_array_type(type); | 991 object_store->set_array_type(type); |
991 | 992 |
992 cls = object_store->growable_object_array_class(); // Was allocated above. | 993 cls = object_store->growable_object_array_class(); // Was allocated above. |
993 RegisterPrivateClass(cls, Symbols::_GrowableList(), core_lib); | 994 RegisterPrivateClass(cls, Symbols::_GrowableList(), core_lib); |
994 pending_classes.Add(cls); | 995 pending_classes.Add(cls); |
995 | 996 |
996 cls = Class::New<Array>(kImmutableArrayCid); | 997 cls = Class::New<Array>(kImmutableArrayCid); |
(...skipping 17 matching lines...) Expand all Loading... |
1014 cls = Class::NewStringClass(kExternalOneByteStringCid); | 1015 cls = Class::NewStringClass(kExternalOneByteStringCid); |
1015 object_store->set_external_one_byte_string_class(cls); | 1016 object_store->set_external_one_byte_string_class(cls); |
1016 RegisterPrivateClass(cls, Symbols::ExternalOneByteString(), core_lib); | 1017 RegisterPrivateClass(cls, Symbols::ExternalOneByteString(), core_lib); |
1017 pending_classes.Add(cls); | 1018 pending_classes.Add(cls); |
1018 | 1019 |
1019 cls = Class::NewStringClass(kExternalTwoByteStringCid); | 1020 cls = Class::NewStringClass(kExternalTwoByteStringCid); |
1020 object_store->set_external_two_byte_string_class(cls); | 1021 object_store->set_external_two_byte_string_class(cls); |
1021 RegisterPrivateClass(cls, Symbols::ExternalTwoByteString(), core_lib); | 1022 RegisterPrivateClass(cls, Symbols::ExternalTwoByteString(), core_lib); |
1022 pending_classes.Add(cls); | 1023 pending_classes.Add(cls); |
1023 | 1024 |
| 1025 // Pre-register the isolate library so the native class implementations |
| 1026 // can be hooked up before compiling it. |
| 1027 Library& isolate_lib = |
| 1028 Library::Handle(isolate, Library::LookupLibrary(Symbols::DartIsolate())); |
| 1029 if (isolate_lib.IsNull()) { |
| 1030 isolate_lib = Library::NewLibraryHelper(Symbols::DartIsolate(), true); |
| 1031 isolate_lib.Register(); |
| 1032 isolate->object_store()->set_bootstrap_library(ObjectStore::kIsolate, |
| 1033 isolate_lib); |
| 1034 } |
| 1035 ASSERT(!isolate_lib.IsNull()); |
| 1036 ASSERT(isolate_lib.raw() == Library::IsolateLibrary()); |
| 1037 |
| 1038 cls = Class::New<Capability>(); |
| 1039 RegisterPrivateClass(cls, Symbols::_CapabilityImpl(), isolate_lib); |
| 1040 pending_classes.Add(cls); |
| 1041 |
| 1042 cls = Class::New<ReceivePort>(); |
| 1043 RegisterPrivateClass(cls, Symbols::_RawReceivePortImpl(), isolate_lib); |
| 1044 pending_classes.Add(cls); |
| 1045 |
| 1046 cls = Class::New<SendPort>(); |
| 1047 RegisterPrivateClass(cls, Symbols::_SendPortImpl(), isolate_lib); |
| 1048 pending_classes.Add(cls); |
| 1049 |
1024 cls = Class::New<Stacktrace>(); | 1050 cls = Class::New<Stacktrace>(); |
1025 object_store->set_stacktrace_class(cls); | 1051 object_store->set_stacktrace_class(cls); |
1026 RegisterClass(cls, Symbols::StackTrace(), core_lib); | 1052 RegisterClass(cls, Symbols::StackTrace(), core_lib); |
1027 pending_classes.Add(cls); | 1053 pending_classes.Add(cls); |
1028 // Super type set below, after Object is allocated. | 1054 // Super type set below, after Object is allocated. |
1029 | 1055 |
1030 cls = Class::New<JSRegExp>(); | 1056 cls = Class::New<JSRegExp>(); |
1031 object_store->set_jsregexp_class(cls); | 1057 object_store->set_jsregexp_class(cls); |
1032 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib); | 1058 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib); |
1033 pending_classes.Add(cls); | 1059 pending_classes.Add(cls); |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 | 1462 |
1437 cls = Class::NewStringClass(kExternalTwoByteStringCid); | 1463 cls = Class::NewStringClass(kExternalTwoByteStringCid); |
1438 object_store->set_external_two_byte_string_class(cls); | 1464 object_store->set_external_two_byte_string_class(cls); |
1439 | 1465 |
1440 cls = Class::New<Bool>(); | 1466 cls = Class::New<Bool>(); |
1441 object_store->set_bool_class(cls); | 1467 object_store->set_bool_class(cls); |
1442 | 1468 |
1443 cls = Class::New<Instance>(kNullCid); | 1469 cls = Class::New<Instance>(kNullCid); |
1444 object_store->set_null_class(cls); | 1470 object_store->set_null_class(cls); |
1445 | 1471 |
| 1472 cls = Class::New<Capability>(); |
| 1473 cls = Class::New<ReceivePort>(); |
| 1474 cls = Class::New<SendPort>(); |
| 1475 |
1446 cls = Class::New<Stacktrace>(); | 1476 cls = Class::New<Stacktrace>(); |
1447 object_store->set_stacktrace_class(cls); | 1477 object_store->set_stacktrace_class(cls); |
1448 | 1478 |
1449 cls = Class::New<JSRegExp>(); | 1479 cls = Class::New<JSRegExp>(); |
1450 object_store->set_jsregexp_class(cls); | 1480 object_store->set_jsregexp_class(cls); |
1451 | 1481 |
1452 // Some classes are not stored in the object store. Yet we still need to | 1482 // Some classes are not stored in the object store. Yet we still need to |
1453 // create their Class object so that they get put into the class_table | 1483 // create their Class object so that they get put into the class_table |
1454 // (as a side effect of Class::New()). | 1484 // (as a side effect of Class::New()). |
1455 cls = Class::New<Number>(); | 1485 cls = Class::New<Number>(); |
(...skipping 13238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14694 } | 14724 } |
14695 | 14725 |
14696 | 14726 |
14697 RawInteger* Integer::New(int64_t value, Heap::Space space, const bool silent) { | 14727 RawInteger* Integer::New(int64_t value, Heap::Space space, const bool silent) { |
14698 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { | 14728 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { |
14699 return Smi::New(value); | 14729 return Smi::New(value); |
14700 } | 14730 } |
14701 if (!silent && | 14731 if (!silent && |
14702 FLAG_throw_on_javascript_int_overflow && | 14732 FLAG_throw_on_javascript_int_overflow && |
14703 !IsJavascriptInt(value)) { | 14733 !IsJavascriptInt(value)) { |
14704 const Integer &i = Integer::Handle(Mint::New(value)); | 14734 const Integer& i = Integer::Handle(Mint::New(value)); |
14705 ThrowJavascriptIntegerOverflow(i); | 14735 ThrowJavascriptIntegerOverflow(i); |
14706 } | 14736 } |
14707 return Mint::New(value, space); | 14737 return Mint::New(value, space); |
14708 } | 14738 } |
14709 | 14739 |
14710 | 14740 |
14711 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { | 14741 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { |
14712 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { | 14742 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { |
14713 if (FLAG_throw_on_javascript_int_overflow) { | 14743 if (FLAG_throw_on_javascript_int_overflow) { |
14714 const Integer &i = | 14744 const Integer &i = |
(...skipping 3142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17857 return "ExternalTypedData"; | 17887 return "ExternalTypedData"; |
17858 } | 17888 } |
17859 | 17889 |
17860 | 17890 |
17861 void ExternalTypedData::PrintToJSONStream(JSONStream* stream, | 17891 void ExternalTypedData::PrintToJSONStream(JSONStream* stream, |
17862 bool ref) const { | 17892 bool ref) const { |
17863 Instance::PrintToJSONStream(stream, ref); | 17893 Instance::PrintToJSONStream(stream, ref); |
17864 } | 17894 } |
17865 | 17895 |
17866 | 17896 |
| 17897 RawCapability* Capability::New(uint64_t id, Heap::Space space) { |
| 17898 Capability& result = Capability::Handle(); |
| 17899 { |
| 17900 RawObject* raw = Object::Allocate(Capability::kClassId, |
| 17901 Capability::InstanceSize(), |
| 17902 space); |
| 17903 NoGCScope no_gc; |
| 17904 result ^= raw; |
| 17905 } |
| 17906 result.raw_ptr()->id_ = id; |
| 17907 return result.raw(); |
| 17908 } |
| 17909 |
| 17910 |
| 17911 const char* Capability::ToCString() const { |
| 17912 return "Capability"; |
| 17913 } |
| 17914 |
| 17915 |
| 17916 void Capability::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17917 Instance::PrintToJSONStream(stream, ref); |
| 17918 } |
| 17919 |
| 17920 |
| 17921 RawReceivePort* ReceivePort::New(Dart_Port id, Heap::Space space) { |
| 17922 Isolate* isolate = Isolate::Current(); |
| 17923 const SendPort& send_port = SendPort::Handle(isolate, SendPort::New(id)); |
| 17924 |
| 17925 ReceivePort& result = ReceivePort::Handle(isolate); |
| 17926 { |
| 17927 RawObject* raw = Object::Allocate(ReceivePort::kClassId, |
| 17928 ReceivePort::InstanceSize(), |
| 17929 space); |
| 17930 NoGCScope no_gc; |
| 17931 result ^= raw; |
| 17932 } |
| 17933 result.raw_ptr()->send_port_ = send_port.raw(); |
| 17934 PortMap::SetLive(id); |
| 17935 return result.raw(); |
| 17936 } |
| 17937 |
| 17938 |
| 17939 const char* ReceivePort::ToCString() const { |
| 17940 return "ReceivePort"; |
| 17941 } |
| 17942 |
| 17943 |
| 17944 void ReceivePort::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17945 Instance::PrintToJSONStream(stream, ref); |
| 17946 } |
| 17947 |
| 17948 |
| 17949 RawSendPort* SendPort::New(Dart_Port id, Heap::Space space) { |
| 17950 SendPort& result = SendPort::Handle(); |
| 17951 { |
| 17952 RawObject* raw = Object::Allocate(SendPort::kClassId, |
| 17953 SendPort::InstanceSize(), |
| 17954 space); |
| 17955 NoGCScope no_gc; |
| 17956 result ^= raw; |
| 17957 } |
| 17958 result.raw_ptr()->id_ = id; |
| 17959 return result.raw(); |
| 17960 } |
| 17961 |
| 17962 |
| 17963 const char* SendPort::ToCString() const { |
| 17964 return "SendPort"; |
| 17965 } |
| 17966 |
| 17967 |
| 17968 void SendPort::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17969 Instance::PrintToJSONStream(stream, ref); |
| 17970 } |
| 17971 |
17867 | 17972 |
17868 const char* Closure::ToCString(const Instance& closure) { | 17973 const char* Closure::ToCString(const Instance& closure) { |
17869 const Function& fun = Function::Handle(Closure::function(closure)); | 17974 const Function& fun = Function::Handle(Closure::function(closure)); |
17870 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); | 17975 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); |
17871 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString(); | 17976 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString(); |
17872 const char* from = is_implicit_closure ? " from " : ""; | 17977 const char* from = is_implicit_closure ? " from " : ""; |
17873 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; | 17978 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; |
17874 const char* format = "Closure: %s%s%s"; | 17979 const char* format = "Closure: %s%s%s"; |
17875 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1; | 17980 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1; |
17876 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 17981 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18464 return tag_label.ToCString(); | 18569 return tag_label.ToCString(); |
18465 } | 18570 } |
18466 | 18571 |
18467 | 18572 |
18468 void UserTag::PrintToJSONStream(JSONStream* stream, bool ref) const { | 18573 void UserTag::PrintToJSONStream(JSONStream* stream, bool ref) const { |
18469 Instance::PrintToJSONStream(stream, ref); | 18574 Instance::PrintToJSONStream(stream, ref); |
18470 } | 18575 } |
18471 | 18576 |
18472 | 18577 |
18473 } // namespace dart | 18578 } // namespace dart |
OLD | NEW |