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

Side by Side Diff: vm/object.cc

Issue 11087070: - Get rid of RawClosure class and use RawInstance for closures. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 2 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
« vm/object.h ('K') | « vm/object.h ('k') | vm/object_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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 4950 matching lines...) Expand 10 before | Expand all | Expand 10 after
8106 !other_type_arguments.IsInstantiated()) { 8103 !other_type_arguments.IsInstantiated()) {
8107 other_type_arguments = 8104 other_type_arguments =
8108 other_type_arguments.InstantiateFrom(other_instantiator); 8105 other_type_arguments.InstantiateFrom(other_instantiator);
8109 } 8106 }
8110 } 8107 }
8111 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments, 8108 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments,
8112 malformed_error); 8109 malformed_error);
8113 } 8110 }
8114 8111
8115 8112
8113 bool Instance::IsClosure() const {
8114 const Class& cls = Class::Handle(clazz());
8115 return cls.IsSignatureClass();
8116 }
8117
8118
8116 RawInstance* Instance::New(const Class& cls, Heap::Space space) { 8119 RawInstance* Instance::New(const Class& cls, Heap::Space space) {
8117 Instance& result = Instance::Handle(); 8120 Instance& result = Instance::Handle();
8118 { 8121 {
8119 intptr_t instance_size = cls.instance_size(); 8122 intptr_t instance_size = cls.instance_size();
8120 ASSERT(instance_size > 0); 8123 ASSERT(instance_size > 0);
8121 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); 8124 RawObject* raw = Object::Allocate(cls.id(), instance_size, space);
8122 NoGCScope no_gc; 8125 NoGCScope no_gc;
8123 result ^= raw; 8126 result ^= raw;
8124 uword addr = reinterpret_cast<uword>(result.raw_ptr()); 8127 uword addr = reinterpret_cast<uword>(result.raw_ptr());
8125 // Initialize fields. 8128 // Initialize fields.
(...skipping 18 matching lines...) Expand all
8144 if (IsNull()) { 8147 if (IsNull()) {
8145 return "null"; 8148 return "null";
8146 } else if (raw() == Object::sentinel()) { 8149 } else if (raw() == Object::sentinel()) {
8147 return "sentinel"; 8150 return "sentinel";
8148 } else if (raw() == Object::transition_sentinel()) { 8151 } else if (raw() == Object::transition_sentinel()) {
8149 return "transition_sentinel"; 8152 return "transition_sentinel";
8150 } else if (Isolate::Current()->no_gc_scope_depth() > 0) { 8153 } else if (Isolate::Current()->no_gc_scope_depth() > 0) {
8151 // Can occur when running disassembler. 8154 // Can occur when running disassembler.
8152 return "Instance"; 8155 return "Instance";
8153 } else { 8156 } else {
8157 if (IsClosure()) {
8158 const Function& fun = Function::Handle(Closure::function(*this));
Ivan Posva 2012/10/11 04:04:22 Could this be abstracted out into a function in th
siva 2012/10/11 17:45:58 Done.
8159 const bool is_implicit_closure = fun.IsImplicitClosureFunction();
8160 const char* fun_sig = String::Handle(fun.Signature()).ToCString();
8161 const char* from = is_implicit_closure ? " from " : "";
8162 const char* fun_desc = is_implicit_closure ? fun.ToCString() : "";
8163 const char* format = "Closure: %s%s%s";
8164 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1;
8165 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
8166 OS::SNPrint(chars, len, format, fun_sig, from, fun_desc);
8167 return chars;
8168 }
8154 const char* kFormat = "Instance of '%s'"; 8169 const char* kFormat = "Instance of '%s'";
8155 Class& cls = Class::Handle(clazz()); 8170 const Class& cls = Class::Handle(clazz());
8156 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); 8171 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle();
8157 const intptr_t num_type_arguments = cls.NumTypeArguments(); 8172 const intptr_t num_type_arguments = cls.NumTypeArguments();
8158 if (num_type_arguments > 0) { 8173 if (num_type_arguments > 0) {
8159 type_arguments = GetTypeArguments(); 8174 type_arguments = GetTypeArguments();
8160 } 8175 }
8161 const Type& type = 8176 const Type& type =
8162 Type::Handle(Type::New(cls, type_arguments, Scanner::kDummyTokenIndex)); 8177 Type::Handle(Type::New(cls, type_arguments, Scanner::kDummyTokenIndex));
8163 const String& type_name = String::Handle(type.Name()); 8178 const String& type_name = String::Handle(type.Name());
8164 // Calculate the size of the string. 8179 // Calculate the size of the string.
8165 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; 8180 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1;
(...skipping 3715 matching lines...) Expand 10 before | Expand all | Expand 10 after
11881 cls, data, len, peer, callback, space); 11896 cls, data, len, peer, callback, space);
11882 } 11897 }
11883 11898
11884 11899
11885 const char* ExternalFloat64Array::ToCString() const { 11900 const char* ExternalFloat64Array::ToCString() const {
11886 return "_ExternalFloat64Array"; 11901 return "_ExternalFloat64Array";
11887 } 11902 }
11888 11903
11889 11904
11890 11905
11891 RawClosure* Closure::New(const Function& function, 11906 RawInstance* Closure::New(const Function& function,
11892 const Context& context, 11907 const Context& context,
11893 Heap::Space space) { 11908 Heap::Space space) {
11894 Isolate* isolate = Isolate::Current(); 11909 Isolate* isolate = Isolate::Current();
11895 ASSERT(context.isolate() == isolate); 11910 ASSERT(context.isolate() == isolate);
11896 11911
11897 const Class& cls = Class::Handle(function.signature_class()); 11912 const Class& cls = Class::Handle(function.signature_class());
11898 Closure& result = Closure::Handle(); 11913 ASSERT(cls.instance_size() == Closure::InstanceSize());
11914 Instance& result = Instance::Handle();
11899 { 11915 {
11900 RawObject* raw = Object::Allocate(cls.id(), Closure::InstanceSize(), space); 11916 RawObject* raw = Object::Allocate(cls.id(), Closure::InstanceSize(), space);
11901 NoGCScope no_gc; 11917 NoGCScope no_gc;
11902 result ^= raw; 11918 result ^= raw;
11903 } 11919 }
11904 result.set_function(function); 11920 Closure::set_function(result, function);
11905 result.set_context(context); 11921 Closure::set_context(result, context);
11906 return result.raw(); 11922 return result.raw();
11907 } 11923 }
11908 11924
11909 11925
11910 void Closure::set_context(const Context& value) const {
11911 StorePointer(&raw_ptr()->context_, value.raw());
11912 }
11913
11914
11915 void Closure::set_function(const Function& value) const {
11916 StorePointer(&raw_ptr()->function_, value.raw());
11917 }
11918
11919
11920 const char* DartFunction::ToCString() const { 11926 const char* DartFunction::ToCString() const {
11921 return "Function type class"; 11927 return "Function type class";
11922 } 11928 }
11923 11929
11924 11930
11925 const char* Closure::ToCString() const {
11926 const Function& fun = Function::Handle(function());
11927 const bool is_implicit_closure = fun.IsImplicitClosureFunction();
11928 const char* fun_sig = String::Handle(fun.Signature()).ToCString();
11929 const char* from = is_implicit_closure ? " from " : "";
11930 const char* fun_desc = is_implicit_closure ? fun.ToCString() : "";
11931 const char* format = "Closure: %s%s%s";
11932 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1;
11933 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
11934 OS::SNPrint(chars, len, format, fun_sig, from, fun_desc);
11935 return chars;
11936 }
11937
11938
11939 intptr_t Stacktrace::Length() const { 11931 intptr_t Stacktrace::Length() const {
11940 const Array& code_array = Array::Handle(raw_ptr()->code_array_); 11932 const Array& code_array = Array::Handle(raw_ptr()->code_array_);
11941 return code_array.Length(); 11933 return code_array.Length();
11942 } 11934 }
11943 11935
11944 11936
11945 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { 11937 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const {
11946 const Array& function_array = Array::Handle(raw_ptr()->function_array_); 11938 const Array& function_array = Array::Handle(raw_ptr()->function_array_);
11947 return reinterpret_cast<RawFunction*>(function_array.At(frame_index)); 11939 return reinterpret_cast<RawFunction*>(function_array.At(frame_index));
11948 } 11940 }
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
12198 } 12190 }
12199 return result.raw(); 12191 return result.raw();
12200 } 12192 }
12201 12193
12202 12194
12203 const char* WeakProperty::ToCString() const { 12195 const char* WeakProperty::ToCString() const {
12204 return "_WeakProperty"; 12196 return "_WeakProperty";
12205 } 12197 }
12206 12198
12207 } // namespace dart 12199 } // namespace dart
OLDNEW
« vm/object.h ('K') | « vm/object.h ('k') | vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698