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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 RawObject* raw = Object::Allocate(Class::kClassId, | 1338 RawObject* raw = Object::Allocate(Class::kClassId, |
1339 Class::InstanceSize(), | 1339 Class::InstanceSize(), |
1340 Heap::kOld); | 1340 Heap::kOld); |
1341 NoGCScope no_gc; | 1341 NoGCScope no_gc; |
1342 result ^= raw; | 1342 result ^= raw; |
1343 } | 1343 } |
1344 FakeObject fake; | 1344 FakeObject fake; |
1345 result.set_handle_vtable(fake.vtable()); | 1345 result.set_handle_vtable(fake.vtable()); |
1346 result.set_instance_size(FakeObject::InstanceSize()); | 1346 result.set_instance_size(FakeObject::InstanceSize()); |
1347 result.set_next_field_offset(FakeObject::InstanceSize()); | 1347 result.set_next_field_offset(FakeObject::InstanceSize()); |
1348 ASSERT((FakeObject::kClassId != kInstanceCid) && | 1348 ASSERT((FakeObject::kClassId != kInstanceCid)); |
1349 (FakeObject::kClassId != kClosureCid)); | |
1350 result.set_id(FakeObject::kClassId); | 1349 result.set_id(FakeObject::kClassId); |
1351 result.raw_ptr()->state_bits_ = 0; | 1350 result.raw_ptr()->state_bits_ = 0; |
1352 // VM backed classes are almost ready: run checks and resolve class | 1351 // VM backed classes are almost ready: run checks and resolve class |
1353 // references, but do not recompute size. | 1352 // references, but do not recompute size. |
1354 result.set_is_prefinalized(); | 1353 result.set_is_prefinalized(); |
1355 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; | 1354 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; |
1356 result.raw_ptr()->num_native_fields_ = 0; | 1355 result.raw_ptr()->num_native_fields_ = 0; |
1357 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; | 1356 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; |
1358 result.InitEmptyFields(); | 1357 result.InitEmptyFields(); |
1359 Isolate::Current()->class_table()->Register(result); | 1358 Isolate::Current()->class_table()->Register(result); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1771 result.raw_ptr()->state_bits_ = 0; | 1770 result.raw_ptr()->state_bits_ = 0; |
1772 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; | 1771 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; |
1773 result.raw_ptr()->num_native_fields_ = 0; | 1772 result.raw_ptr()->num_native_fields_ = 0; |
1774 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; | 1773 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; |
1775 result.InitEmptyFields(); | 1774 result.InitEmptyFields(); |
1776 Isolate::Current()->class_table()->Register(result); | 1775 Isolate::Current()->class_table()->Register(result); |
1777 return result.raw(); | 1776 return result.raw(); |
1778 } | 1777 } |
1779 | 1778 |
1780 | 1779 |
1781 // Force instantiation of template version to work around ld problems. | |
1782 template RawClass* Class::New<Closure>(intptr_t index); | |
1783 | |
1784 | |
1785 template <class FakeInstance> | 1780 template <class FakeInstance> |
1786 RawClass* Class::New(const String& name, | 1781 RawClass* Class::New(const String& name, |
1787 const Script& script, | 1782 const Script& script, |
1788 intptr_t token_pos) { | 1783 intptr_t token_pos) { |
1789 Class& result = Class::Handle(New<FakeInstance>(kIllegalCid)); | 1784 Class& result = Class::Handle(New<FakeInstance>(kIllegalCid)); |
1790 result.set_name(name); | 1785 result.set_name(name); |
1791 result.set_script(script); | 1786 result.set_script(script); |
1792 result.set_token_pos(token_pos); | 1787 result.set_token_pos(token_pos); |
1793 return result.raw(); | 1788 return result.raw(); |
1794 } | 1789 } |
(...skipping 25 matching lines...) Expand all Loading... |
1820 TypeArguments& type_parameters = TypeArguments::Handle(); | 1815 TypeArguments& type_parameters = TypeArguments::Handle(); |
1821 // A signature class extends class Instance and is parameterized in the same | 1816 // A signature class extends class Instance and is parameterized in the same |
1822 // way as the owner class of its non-static signature function. | 1817 // way as the owner class of its non-static signature function. |
1823 // It is not type parameterized if its signature function is static. | 1818 // It is not type parameterized if its signature function is static. |
1824 if (!signature_function.is_static() && | 1819 if (!signature_function.is_static() && |
1825 (owner_class.NumTypeParameters() > 0) && | 1820 (owner_class.NumTypeParameters() > 0) && |
1826 !signature_function.HasInstantiatedSignature()) { | 1821 !signature_function.HasInstantiatedSignature()) { |
1827 type_parameters = owner_class.type_parameters(); | 1822 type_parameters = owner_class.type_parameters(); |
1828 } | 1823 } |
1829 const intptr_t token_pos = signature_function.token_pos(); | 1824 const intptr_t token_pos = signature_function.token_pos(); |
1830 Class& result = Class::Handle(New<Closure>(name, script, token_pos)); | 1825 Class& result = Class::Handle(New<Instance>(name, script, token_pos)); |
1831 const Type& super_type = Type::Handle(Type::ObjectType()); | 1826 const Type& super_type = Type::Handle(Type::ObjectType()); |
1832 const Array& empty_array = Array::Handle(Object::empty_array()); | 1827 const Array& empty_array = Array::Handle(Object::empty_array()); |
1833 ASSERT(!super_type.IsNull()); | 1828 ASSERT(!super_type.IsNull()); |
| 1829 result.set_instance_size(Closure::InstanceSize()); |
| 1830 result.set_next_field_offset(Closure::InstanceSize()); |
1834 result.set_super_type(super_type); | 1831 result.set_super_type(super_type); |
1835 result.set_signature_function(signature_function); | 1832 result.set_signature_function(signature_function); |
1836 result.set_type_parameters(type_parameters); | 1833 result.set_type_parameters(type_parameters); |
1837 result.SetFields(empty_array); | 1834 result.SetFields(empty_array); |
1838 result.SetFunctions(empty_array); | 1835 result.SetFunctions(empty_array); |
1839 result.set_type_arguments_instance_field_offset( | 1836 result.set_type_arguments_instance_field_offset( |
1840 Closure::type_arguments_offset()); | 1837 Closure::type_arguments_offset()); |
1841 // Implements interface "Function". | 1838 // Implements interface "Function". |
1842 const Type& function_type = Type::Handle(Type::Function()); | 1839 const Type& function_type = Type::Handle(Type::Function()); |
1843 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); | 1840 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); |
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3135 return; | 3132 return; |
3136 } | 3133 } |
3137 UNREACHABLE(); | 3134 UNREACHABLE(); |
3138 } | 3135 } |
3139 | 3136 |
3140 | 3137 |
3141 bool Function::IsRedirectingFactory() const { | 3138 bool Function::IsRedirectingFactory() const { |
3142 if (!IsFactory() || (raw_ptr()->data_ == Object::null())) { | 3139 if (!IsFactory() || (raw_ptr()->data_ == Object::null())) { |
3143 return false; | 3140 return false; |
3144 } | 3141 } |
3145 ASSERT(!IsClosure()); // A factory cannot also be a closure. | 3142 ASSERT(!IsClosureFunction()); // A factory cannot also be a closure. |
3146 return true; | 3143 return true; |
3147 } | 3144 } |
3148 | 3145 |
3149 | 3146 |
3150 RawType* Function::RedirectionType() const { | 3147 RawType* Function::RedirectionType() const { |
3151 ASSERT(IsRedirectingFactory()); | 3148 ASSERT(IsRedirectingFactory()); |
3152 const Object& obj = Object::Handle(raw_ptr()->data_); | 3149 const Object& obj = Object::Handle(raw_ptr()->data_); |
3153 ASSERT(!obj.IsNull()); | 3150 ASSERT(!obj.IsNull()); |
3154 return RedirectionData::Cast(obj).type(); | 3151 return RedirectionData::Cast(obj).type(); |
3155 } | 3152 } |
(...skipping 4957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8113 !other_type_arguments.IsInstantiated()) { | 8110 !other_type_arguments.IsInstantiated()) { |
8114 other_type_arguments = | 8111 other_type_arguments = |
8115 other_type_arguments.InstantiateFrom(other_instantiator); | 8112 other_type_arguments.InstantiateFrom(other_instantiator); |
8116 } | 8113 } |
8117 } | 8114 } |
8118 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments, | 8115 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments, |
8119 malformed_error); | 8116 malformed_error); |
8120 } | 8117 } |
8121 | 8118 |
8122 | 8119 |
| 8120 bool Instance::IsClosure() const { |
| 8121 const Class& cls = Class::Handle(clazz()); |
| 8122 return cls.IsSignatureClass(); |
| 8123 } |
| 8124 |
| 8125 |
8123 RawInstance* Instance::New(const Class& cls, Heap::Space space) { | 8126 RawInstance* Instance::New(const Class& cls, Heap::Space space) { |
8124 Instance& result = Instance::Handle(); | 8127 Instance& result = Instance::Handle(); |
8125 { | 8128 { |
8126 intptr_t instance_size = cls.instance_size(); | 8129 intptr_t instance_size = cls.instance_size(); |
8127 ASSERT(instance_size > 0); | 8130 ASSERT(instance_size > 0); |
8128 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); | 8131 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); |
8129 NoGCScope no_gc; | 8132 NoGCScope no_gc; |
8130 result ^= raw; | 8133 result ^= raw; |
8131 uword addr = reinterpret_cast<uword>(result.raw_ptr()); | 8134 uword addr = reinterpret_cast<uword>(result.raw_ptr()); |
8132 // Initialize fields. | 8135 // Initialize fields. |
(...skipping 18 matching lines...) Expand all Loading... |
8151 if (IsNull()) { | 8154 if (IsNull()) { |
8152 return "null"; | 8155 return "null"; |
8153 } else if (raw() == Object::sentinel()) { | 8156 } else if (raw() == Object::sentinel()) { |
8154 return "sentinel"; | 8157 return "sentinel"; |
8155 } else if (raw() == Object::transition_sentinel()) { | 8158 } else if (raw() == Object::transition_sentinel()) { |
8156 return "transition_sentinel"; | 8159 return "transition_sentinel"; |
8157 } else if (Isolate::Current()->no_gc_scope_depth() > 0) { | 8160 } else if (Isolate::Current()->no_gc_scope_depth() > 0) { |
8158 // Can occur when running disassembler. | 8161 // Can occur when running disassembler. |
8159 return "Instance"; | 8162 return "Instance"; |
8160 } else { | 8163 } else { |
| 8164 if (IsClosure()) { |
| 8165 return Closure::ToCString(*this); |
| 8166 } |
8161 const char* kFormat = "Instance of '%s'"; | 8167 const char* kFormat = "Instance of '%s'"; |
8162 Class& cls = Class::Handle(clazz()); | 8168 const Class& cls = Class::Handle(clazz()); |
8163 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); | 8169 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); |
8164 const intptr_t num_type_arguments = cls.NumTypeArguments(); | 8170 const intptr_t num_type_arguments = cls.NumTypeArguments(); |
8165 if (num_type_arguments > 0) { | 8171 if (num_type_arguments > 0) { |
8166 type_arguments = GetTypeArguments(); | 8172 type_arguments = GetTypeArguments(); |
8167 } | 8173 } |
8168 const Type& type = | 8174 const Type& type = |
8169 Type::Handle(Type::New(cls, type_arguments, Scanner::kDummyTokenIndex)); | 8175 Type::Handle(Type::New(cls, type_arguments, Scanner::kDummyTokenIndex)); |
8170 const String& type_name = String::Handle(type.Name()); | 8176 const String& type_name = String::Handle(type.Name()); |
8171 // Calculate the size of the string. | 8177 // Calculate the size of the string. |
8172 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; | 8178 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; |
(...skipping 3714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11887 return NewExternalImpl<ExternalFloat64Array, RawExternalFloat64Array>( | 11893 return NewExternalImpl<ExternalFloat64Array, RawExternalFloat64Array>( |
11888 cls, data, len, peer, callback, space); | 11894 cls, data, len, peer, callback, space); |
11889 } | 11895 } |
11890 | 11896 |
11891 | 11897 |
11892 const char* ExternalFloat64Array::ToCString() const { | 11898 const char* ExternalFloat64Array::ToCString() const { |
11893 return "_ExternalFloat64Array"; | 11899 return "_ExternalFloat64Array"; |
11894 } | 11900 } |
11895 | 11901 |
11896 | 11902 |
11897 | 11903 const char* Closure::ToCString(const Instance& closure) { |
11898 RawClosure* Closure::New(const Function& function, | 11904 const Function& fun = Function::Handle(Closure::function(closure)); |
11899 const Context& context, | |
11900 Heap::Space space) { | |
11901 Isolate* isolate = Isolate::Current(); | |
11902 ASSERT(context.isolate() == isolate); | |
11903 | |
11904 const Class& cls = Class::Handle(function.signature_class()); | |
11905 Closure& result = Closure::Handle(); | |
11906 { | |
11907 RawObject* raw = Object::Allocate(cls.id(), Closure::InstanceSize(), space); | |
11908 NoGCScope no_gc; | |
11909 result ^= raw; | |
11910 } | |
11911 result.set_function(function); | |
11912 result.set_context(context); | |
11913 return result.raw(); | |
11914 } | |
11915 | |
11916 | |
11917 void Closure::set_context(const Context& value) const { | |
11918 StorePointer(&raw_ptr()->context_, value.raw()); | |
11919 } | |
11920 | |
11921 | |
11922 void Closure::set_function(const Function& value) const { | |
11923 StorePointer(&raw_ptr()->function_, value.raw()); | |
11924 } | |
11925 | |
11926 | |
11927 const char* DartFunction::ToCString() const { | |
11928 return "Function type class"; | |
11929 } | |
11930 | |
11931 | |
11932 const char* Closure::ToCString() const { | |
11933 const Function& fun = Function::Handle(function()); | |
11934 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); | 11905 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); |
11935 const char* fun_sig = String::Handle(fun.Signature()).ToCString(); | 11906 const char* fun_sig = String::Handle(fun.Signature()).ToCString(); |
11936 const char* from = is_implicit_closure ? " from " : ""; | 11907 const char* from = is_implicit_closure ? " from " : ""; |
11937 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; | 11908 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; |
11938 const char* format = "Closure: %s%s%s"; | 11909 const char* format = "Closure: %s%s%s"; |
11939 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1; | 11910 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1; |
11940 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 11911 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
11941 OS::SNPrint(chars, len, format, fun_sig, from, fun_desc); | 11912 OS::SNPrint(chars, len, format, fun_sig, from, fun_desc); |
11942 return chars; | 11913 return chars; |
11943 } | 11914 } |
11944 | 11915 |
11945 | 11916 |
| 11917 RawInstance* Closure::New(const Function& function, |
| 11918 const Context& context, |
| 11919 Heap::Space space) { |
| 11920 Isolate* isolate = Isolate::Current(); |
| 11921 ASSERT(context.isolate() == isolate); |
| 11922 |
| 11923 const Class& cls = Class::Handle(function.signature_class()); |
| 11924 ASSERT(cls.instance_size() == Closure::InstanceSize()); |
| 11925 Instance& result = Instance::Handle(); |
| 11926 { |
| 11927 RawObject* raw = Object::Allocate(cls.id(), Closure::InstanceSize(), space); |
| 11928 NoGCScope no_gc; |
| 11929 result ^= raw; |
| 11930 } |
| 11931 Closure::set_function(result, function); |
| 11932 Closure::set_context(result, context); |
| 11933 return result.raw(); |
| 11934 } |
| 11935 |
| 11936 |
| 11937 const char* DartFunction::ToCString() const { |
| 11938 return "Function type class"; |
| 11939 } |
| 11940 |
| 11941 |
11946 intptr_t Stacktrace::Length() const { | 11942 intptr_t Stacktrace::Length() const { |
11947 const Array& code_array = Array::Handle(raw_ptr()->code_array_); | 11943 const Array& code_array = Array::Handle(raw_ptr()->code_array_); |
11948 return code_array.Length(); | 11944 return code_array.Length(); |
11949 } | 11945 } |
11950 | 11946 |
11951 | 11947 |
11952 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { | 11948 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { |
11953 const Array& function_array = Array::Handle(raw_ptr()->function_array_); | 11949 const Array& function_array = Array::Handle(raw_ptr()->function_array_); |
11954 return reinterpret_cast<RawFunction*>(function_array.At(frame_index)); | 11950 return reinterpret_cast<RawFunction*>(function_array.At(frame_index)); |
11955 } | 11951 } |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12205 } | 12201 } |
12206 return result.raw(); | 12202 return result.raw(); |
12207 } | 12203 } |
12208 | 12204 |
12209 | 12205 |
12210 const char* WeakProperty::ToCString() const { | 12206 const char* WeakProperty::ToCString() const { |
12211 return "_WeakProperty"; | 12207 return "_WeakProperty"; |
12212 } | 12208 } |
12213 | 12209 |
12214 } // namespace dart | 12210 } // namespace dart |
OLD | NEW |