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

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

Issue 2723643002: Properly handle instantiator when allocating or cloning closure instance. (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/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/become.h" 10 #include "vm/become.h"
(...skipping 6889 matching lines...) Expand 10 before | Expand all | Expand 10 after
6900 6900
6901 6901
6902 RawInstance* Function::ImplicitStaticClosure() const { 6902 RawInstance* Function::ImplicitStaticClosure() const {
6903 if (implicit_static_closure() == Instance::null()) { 6903 if (implicit_static_closure() == Instance::null()) {
6904 Thread* thread = Thread::Current(); 6904 Thread* thread = Thread::Current();
6905 Isolate* isolate = thread->isolate(); 6905 Isolate* isolate = thread->isolate();
6906 Zone* zone = thread->zone(); 6906 Zone* zone = thread->zone();
6907 ObjectStore* object_store = isolate->object_store(); 6907 ObjectStore* object_store = isolate->object_store();
6908 const Context& context = 6908 const Context& context =
6909 Context::Handle(zone, object_store->empty_context()); 6909 Context::Handle(zone, object_store->empty_context());
6910 Instance& closure = 6910 const TypeArguments& instantiator = TypeArguments::Handle(zone);
6911 Instance::Handle(zone, Closure::New(*this, context, Heap::kOld)); 6911 Instance& closure = Instance::Handle(
6912 zone, Closure::New(instantiator, *this, context, Heap::kOld));
6912 set_implicit_static_closure(closure); 6913 set_implicit_static_closure(closure);
6913 } 6914 }
6914 return implicit_static_closure(); 6915 return implicit_static_closure();
6915 } 6916 }
6916 6917
6917 6918
6918 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { 6919 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const {
6919 ASSERT(IsImplicitClosureFunction()); 6920 ASSERT(IsImplicitClosureFunction());
6920 const Type& signature_type = Type::Handle(SignatureType()); 6921 Zone* zone = Thread::Current()->zone();
6921 const Class& cls = Class::Handle(signature_type.type_class()); 6922 const Type& signature_type = Type::Handle(zone, SignatureType());
6922 const Context& context = Context::Handle(Context::New(1)); 6923 const Class& cls = Class::Handle(zone, signature_type.type_class());
6924 const Context& context = Context::Handle(zone, Context::New(1));
6923 context.SetAt(0, receiver); 6925 context.SetAt(0, receiver);
6924 const Instance& result = Instance::Handle(Closure::New(*this, context)); 6926 TypeArguments& instantiator = TypeArguments::Handle(zone);
6925 if (cls.IsGeneric()) { 6927 if (cls.IsGeneric()) {
6926 const TypeArguments& type_arguments = 6928 instantiator = receiver.GetTypeArguments();
6927 TypeArguments::Handle(receiver.GetTypeArguments());
6928 result.SetTypeArguments(type_arguments);
6929 } 6929 }
6930 return result.raw(); 6930 return Closure::New(instantiator, *this, context);
6931 } 6931 }
6932 6932
6933 6933
6934 RawSmi* Function::GetClosureHashCode() const { 6934 RawSmi* Function::GetClosureHashCode() const {
6935 ASSERT(IsClosureFunction()); 6935 ASSERT(IsClosureFunction());
6936 const Object& obj = Object::Handle(raw_ptr()->data_); 6936 const Object& obj = Object::Handle(raw_ptr()->data_);
6937 ASSERT(!obj.IsNull()); 6937 ASSERT(!obj.IsNull());
6938 if (ClosureData::Cast(obj).hash() != Object::null()) { 6938 if (ClosureData::Cast(obj).hash() != Object::null()) {
6939 return Smi::RawCast(ClosureData::Cast(obj).hash()); 6939 return Smi::RawCast(ClosureData::Cast(obj).hash());
6940 } 6940 }
(...skipping 15437 matching lines...) Expand 10 before | Expand all | Expand 10 after
22378 const Function& fun = Function::Handle(function()); 22378 const Function& fun = Function::Handle(function());
22379 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); 22379 const bool is_implicit_closure = fun.IsImplicitClosureFunction();
22380 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString(); 22380 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString();
22381 const char* from = is_implicit_closure ? " from " : ""; 22381 const char* from = is_implicit_closure ? " from " : "";
22382 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; 22382 const char* fun_desc = is_implicit_closure ? fun.ToCString() : "";
22383 return OS::SCreate(Thread::Current()->zone(), "Closure: %s%s%s", fun_sig, 22383 return OS::SCreate(Thread::Current()->zone(), "Closure: %s%s%s", fun_sig,
22384 from, fun_desc); 22384 from, fun_desc);
22385 } 22385 }
22386 22386
22387 22387
22388 RawClosure* Closure::New(const Function& function, 22388 RawClosure* Closure::New(const TypeArguments& instantiator,
22389 const Function& function,
22389 const Context& context, 22390 const Context& context,
22390 Heap::Space space) { 22391 Heap::Space space) {
22391 Closure& result = Closure::Handle(); 22392 Closure& result = Closure::Handle();
22392 { 22393 {
22393 RawObject* raw = 22394 RawObject* raw =
22394 Object::Allocate(Closure::kClassId, Closure::InstanceSize(), space); 22395 Object::Allocate(Closure::kClassId, Closure::InstanceSize(), space);
22395 NoSafepointScope no_safepoint; 22396 NoSafepointScope no_safepoint;
22396 result ^= raw; 22397 result ^= raw;
22398 result.StorePointer(&result.raw_ptr()->instantiator_, instantiator.raw());
22397 result.StorePointer(&result.raw_ptr()->function_, function.raw()); 22399 result.StorePointer(&result.raw_ptr()->function_, function.raw());
22398 result.StorePointer(&result.raw_ptr()->context_, context.raw()); 22400 result.StorePointer(&result.raw_ptr()->context_, context.raw());
22399 } 22401 }
22400 return result.raw(); 22402 return result.raw();
22401 } 22403 }
22402 22404
22403 22405
22404 RawClosure* Closure::New() { 22406 RawClosure* Closure::New() {
22405 RawObject* raw = 22407 RawObject* raw =
22406 Object::Allocate(Closure::kClassId, Closure::InstanceSize(), Heap::kOld); 22408 Object::Allocate(Closure::kClassId, Closure::InstanceSize(), Heap::kOld);
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
22925 return UserTag::null(); 22927 return UserTag::null();
22926 } 22928 }
22927 22929
22928 22930
22929 const char* UserTag::ToCString() const { 22931 const char* UserTag::ToCString() const {
22930 const String& tag_label = String::Handle(label()); 22932 const String& tag_label = String::Handle(label());
22931 return tag_label.ToCString(); 22933 return tag_label.ToCString();
22932 } 22934 }
22933 22935
22934 } // namespace dart 22936 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698