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 object_store->set_capability_class(cls); | |
1040 RegisterPrivateClass(cls, Symbols::_CapabilityImpl(), isolate_lib); | |
1041 pending_classes.Add(cls); | |
1042 | |
1043 cls = Class::New<ReceivePort>(); | |
1044 object_store->set_receive_port_class(cls); | |
1045 RegisterPrivateClass(cls, Symbols::_RawReceivePortImpl(), isolate_lib); | |
1046 pending_classes.Add(cls); | |
1047 | |
1048 cls = Class::New<SendPort>(); | |
1049 object_store->set_send_port_class(cls); | |
1050 RegisterPrivateClass(cls, Symbols::_SendPortImpl(), isolate_lib); | |
1051 pending_classes.Add(cls); | |
1052 | |
1024 cls = Class::New<Stacktrace>(); | 1053 cls = Class::New<Stacktrace>(); |
1025 object_store->set_stacktrace_class(cls); | 1054 object_store->set_stacktrace_class(cls); |
1026 RegisterClass(cls, Symbols::StackTrace(), core_lib); | 1055 RegisterClass(cls, Symbols::StackTrace(), core_lib); |
1027 pending_classes.Add(cls); | 1056 pending_classes.Add(cls); |
1028 // Super type set below, after Object is allocated. | 1057 // Super type set below, after Object is allocated. |
1029 | 1058 |
1030 cls = Class::New<JSRegExp>(); | 1059 cls = Class::New<JSRegExp>(); |
1031 object_store->set_jsregexp_class(cls); | 1060 object_store->set_jsregexp_class(cls); |
1032 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib); | 1061 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib); |
1033 pending_classes.Add(cls); | 1062 pending_classes.Add(cls); |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1436 | 1465 |
1437 cls = Class::NewStringClass(kExternalTwoByteStringCid); | 1466 cls = Class::NewStringClass(kExternalTwoByteStringCid); |
1438 object_store->set_external_two_byte_string_class(cls); | 1467 object_store->set_external_two_byte_string_class(cls); |
1439 | 1468 |
1440 cls = Class::New<Bool>(); | 1469 cls = Class::New<Bool>(); |
1441 object_store->set_bool_class(cls); | 1470 object_store->set_bool_class(cls); |
1442 | 1471 |
1443 cls = Class::New<Instance>(kNullCid); | 1472 cls = Class::New<Instance>(kNullCid); |
1444 object_store->set_null_class(cls); | 1473 object_store->set_null_class(cls); |
1445 | 1474 |
1475 cls = Class::New<Capability>(); | |
1476 object_store->set_capability_class(cls); | |
1477 | |
1478 cls = Class::New<ReceivePort>(); | |
1479 object_store->set_receive_port_class(cls); | |
1480 | |
1481 cls = Class::New<SendPort>(); | |
1482 object_store->set_send_port_class(cls); | |
1483 | |
1446 cls = Class::New<Stacktrace>(); | 1484 cls = Class::New<Stacktrace>(); |
1447 object_store->set_stacktrace_class(cls); | 1485 object_store->set_stacktrace_class(cls); |
1448 | 1486 |
1449 cls = Class::New<JSRegExp>(); | 1487 cls = Class::New<JSRegExp>(); |
1450 object_store->set_jsregexp_class(cls); | 1488 object_store->set_jsregexp_class(cls); |
1451 | 1489 |
1452 // Some classes are not stored in the object store. Yet we still need to | 1490 // 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 | 1491 // create their Class object so that they get put into the class_table |
1454 // (as a side effect of Class::New()). | 1492 // (as a side effect of Class::New()). |
1455 cls = Class::New<Number>(); | 1493 cls = Class::New<Number>(); |
(...skipping 13234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14690 } | 14728 } |
14691 | 14729 |
14692 | 14730 |
14693 RawInteger* Integer::New(int64_t value, Heap::Space space, const bool silent) { | 14731 RawInteger* Integer::New(int64_t value, Heap::Space space, const bool silent) { |
14694 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { | 14732 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { |
14695 return Smi::New(value); | 14733 return Smi::New(value); |
14696 } | 14734 } |
14697 if (!silent && | 14735 if (!silent && |
14698 FLAG_throw_on_javascript_int_overflow && | 14736 FLAG_throw_on_javascript_int_overflow && |
14699 !IsJavascriptInt(value)) { | 14737 !IsJavascriptInt(value)) { |
14700 const Integer &i = Integer::Handle(Mint::New(value)); | 14738 const Integer& i = Integer::Handle(Mint::New(value)); |
14701 ThrowJavascriptIntegerOverflow(i); | 14739 ThrowJavascriptIntegerOverflow(i); |
14702 } | 14740 } |
14703 return Mint::New(value, space); | 14741 return Mint::New(value, space); |
14704 } | 14742 } |
14705 | 14743 |
14706 | 14744 |
14707 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { | 14745 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { |
14708 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { | 14746 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { |
14709 if (FLAG_throw_on_javascript_int_overflow) { | 14747 if (FLAG_throw_on_javascript_int_overflow) { |
14710 const Integer &i = | 14748 const Integer &i = |
(...skipping 3142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17853 return "ExternalTypedData"; | 17891 return "ExternalTypedData"; |
17854 } | 17892 } |
17855 | 17893 |
17856 | 17894 |
17857 void ExternalTypedData::PrintToJSONStream(JSONStream* stream, | 17895 void ExternalTypedData::PrintToJSONStream(JSONStream* stream, |
17858 bool ref) const { | 17896 bool ref) const { |
17859 Instance::PrintToJSONStream(stream, ref); | 17897 Instance::PrintToJSONStream(stream, ref); |
17860 } | 17898 } |
17861 | 17899 |
17862 | 17900 |
17901 RawCapability* Capability::New(uint64_t id, Heap::Space space) { | |
17902 Capability& result = Capability::Handle(); | |
17903 { | |
17904 RawObject* raw = Object::Allocate(Capability::kClassId, | |
17905 Capability::InstanceSize(), | |
17906 space); | |
17907 NoGCScope no_gc; | |
17908 result ^= raw; | |
17909 } | |
17910 result.raw_ptr()->id_ = id; | |
17911 return result.raw(); | |
17912 } | |
17913 | |
17914 | |
17915 const char* Capability::ToCString() const { | |
17916 return "Capability"; | |
turnidge
2014/04/22 18:40:45
Consider adding Id() to the ToCString, here and be
Ivan Posva
2014/04/22 21:28:30
Not printing it on purpose.
| |
17917 } | |
17918 | |
17919 | |
17920 void Capability::PrintToJSONStream(JSONStream* stream, bool ref) const { | |
17921 Instance::PrintToJSONStream(stream, ref); | |
17922 } | |
17923 | |
17924 | |
17925 RawReceivePort* ReceivePort::New(Dart_Port id, Heap::Space space) { | |
17926 Isolate* isolate = Isolate::Current(); | |
17927 const SendPort& send_port = SendPort::Handle(isolate, SendPort::New(id)); | |
17928 | |
17929 ReceivePort& result = ReceivePort::Handle(isolate); | |
17930 { | |
17931 RawObject* raw = Object::Allocate(ReceivePort::kClassId, | |
17932 ReceivePort::InstanceSize(), | |
17933 space); | |
17934 NoGCScope no_gc; | |
17935 result ^= raw; | |
17936 } | |
17937 result.raw_ptr()->send_port_ = send_port.raw(); | |
siva
2014/04/23 00:20:31
I think this line should also move inside the NoGC
Ivan Posva
2014/04/23 19:43:35
Done.
| |
17938 PortMap::SetLive(id); | |
17939 return result.raw(); | |
17940 } | |
17941 | |
17942 | |
17943 const char* ReceivePort::ToCString() const { | |
17944 return "ReceivePort"; | |
Cutch
2014/04/22 20:15:22
Include the port id here and in SendPort::ToCStrin
Ivan Posva
2014/04/22 21:28:30
Not printing it on purpose.
| |
17945 } | |
17946 | |
17947 | |
17948 void ReceivePort::PrintToJSONStream(JSONStream* stream, bool ref) const { | |
17949 Instance::PrintToJSONStream(stream, ref); | |
17950 } | |
17951 | |
17952 | |
17953 RawSendPort* SendPort::New(Dart_Port id, Heap::Space space) { | |
17954 SendPort& result = SendPort::Handle(); | |
17955 { | |
17956 RawObject* raw = Object::Allocate(SendPort::kClassId, | |
17957 SendPort::InstanceSize(), | |
17958 space); | |
17959 NoGCScope no_gc; | |
17960 result ^= raw; | |
17961 } | |
17962 result.raw_ptr()->id_ = id; | |
siva
2014/04/23 00:20:31
Ditto comment about this line moving into the scop
| |
17963 return result.raw(); | |
17964 } | |
17965 | |
17966 | |
17967 const char* SendPort::ToCString() const { | |
17968 return "SendPort"; | |
17969 } | |
17970 | |
17971 | |
17972 void SendPort::PrintToJSONStream(JSONStream* stream, bool ref) const { | |
17973 Instance::PrintToJSONStream(stream, ref); | |
17974 } | |
17975 | |
17863 | 17976 |
17864 const char* Closure::ToCString(const Instance& closure) { | 17977 const char* Closure::ToCString(const Instance& closure) { |
17865 const Function& fun = Function::Handle(Closure::function(closure)); | 17978 const Function& fun = Function::Handle(Closure::function(closure)); |
17866 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); | 17979 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); |
17867 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString(); | 17980 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString(); |
17868 const char* from = is_implicit_closure ? " from " : ""; | 17981 const char* from = is_implicit_closure ? " from " : ""; |
17869 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; | 17982 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; |
17870 const char* format = "Closure: %s%s%s"; | 17983 const char* format = "Closure: %s%s%s"; |
17871 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1; | 17984 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1; |
17872 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 17985 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18460 return tag_label.ToCString(); | 18573 return tag_label.ToCString(); |
18461 } | 18574 } |
18462 | 18575 |
18463 | 18576 |
18464 void UserTag::PrintToJSONStream(JSONStream* stream, bool ref) const { | 18577 void UserTag::PrintToJSONStream(JSONStream* stream, bool ref) const { |
18465 Instance::PrintToJSONStream(stream, ref); | 18578 Instance::PrintToJSONStream(stream, ref); |
18466 } | 18579 } |
18467 | 18580 |
18468 | 18581 |
18469 } // namespace dart | 18582 } // namespace dart |
OLD | NEW |