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

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

Issue 2891053003: Add support for converted closures with explicit contexts to VM (Closed)
Patch Set: Update the code according to Martin's comments Created 3 years, 6 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
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 #ifndef RUNTIME_VM_OBJECT_H_ 5 #ifndef RUNTIME_VM_OBJECT_H_
6 #define RUNTIME_VM_OBJECT_H_ 6 #define RUNTIME_VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 return *vm_isolate_snapshot_object_table_; 492 return *vm_isolate_snapshot_object_table_;
493 } 493 }
494 static const Type& dynamic_type() { 494 static const Type& dynamic_type() {
495 ASSERT(dynamic_type_ != NULL); 495 ASSERT(dynamic_type_ != NULL);
496 return *dynamic_type_; 496 return *dynamic_type_;
497 } 497 }
498 static const Type& void_type() { 498 static const Type& void_type() {
499 ASSERT(void_type_ != NULL); 499 ASSERT(void_type_ != NULL);
500 return *void_type_; 500 return *void_type_;
501 } 501 }
502 static const Type& vector_type() {
503 ASSERT(vector_type_ != NULL);
504 return *vector_type_;
505 }
502 506
503 static void set_vm_isolate_snapshot_object_table(const Array& table); 507 static void set_vm_isolate_snapshot_object_table(const Array& table);
504 508
505 static RawClass* class_class() { return class_class_; } 509 static RawClass* class_class() { return class_class_; }
506 static RawClass* dynamic_class() { return dynamic_class_; } 510 static RawClass* dynamic_class() { return dynamic_class_; }
507 static RawClass* void_class() { return void_class_; } 511 static RawClass* void_class() { return void_class_; }
508 static RawClass* unresolved_class_class() { return unresolved_class_class_; } 512 static RawClass* unresolved_class_class() { return unresolved_class_class_; }
509 static RawClass* type_arguments_class() { return type_arguments_class_; } 513 static RawClass* type_arguments_class() { return type_arguments_class_; }
510 static RawClass* patch_class_class() { return patch_class_class_; } 514 static RawClass* patch_class_class() { return patch_class_class_; }
511 static RawClass* function_class() { return function_class_; } 515 static RawClass* function_class() { return function_class_; }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 static cpp_vtable handle_vtable_; 760 static cpp_vtable handle_vtable_;
757 static cpp_vtable builtin_vtables_[kNumPredefinedCids]; 761 static cpp_vtable builtin_vtables_[kNumPredefinedCids];
758 762
759 // The static values below are singletons shared between the different 763 // The static values below are singletons shared between the different
760 // isolates. They are all allocated in the non-GC'd Dart::vm_isolate_. 764 // isolates. They are all allocated in the non-GC'd Dart::vm_isolate_.
761 static RawObject* null_; 765 static RawObject* null_;
762 766
763 static RawClass* class_class_; // Class of the Class vm object. 767 static RawClass* class_class_; // Class of the Class vm object.
764 static RawClass* dynamic_class_; // Class of the 'dynamic' type. 768 static RawClass* dynamic_class_; // Class of the 'dynamic' type.
765 static RawClass* void_class_; // Class of the 'void' type. 769 static RawClass* void_class_; // Class of the 'void' type.
770 static RawClass* vector_class_; // Class of the 'vector' type.
766 static RawClass* unresolved_class_class_; // Class of UnresolvedClass. 771 static RawClass* unresolved_class_class_; // Class of UnresolvedClass.
767 static RawClass* type_arguments_class_; // Class of TypeArguments vm object. 772 static RawClass* type_arguments_class_; // Class of TypeArguments vm object.
768 static RawClass* patch_class_class_; // Class of the PatchClass vm object. 773 static RawClass* patch_class_class_; // Class of the PatchClass vm object.
769 static RawClass* function_class_; // Class of the Function vm object. 774 static RawClass* function_class_; // Class of the Function vm object.
770 static RawClass* closure_data_class_; // Class of ClosureData vm obj. 775 static RawClass* closure_data_class_; // Class of ClosureData vm obj.
771 static RawClass* signature_data_class_; // Class of SignatureData vm obj. 776 static RawClass* signature_data_class_; // Class of SignatureData vm obj.
772 static RawClass* redirection_data_class_; // Class of RedirectionData vm obj. 777 static RawClass* redirection_data_class_; // Class of RedirectionData vm obj.
773 static RawClass* field_class_; // Class of the Field vm object. 778 static RawClass* field_class_; // Class of the Field vm object.
774 static RawClass* literal_token_class_; // Class of LiteralToken vm object. 779 static RawClass* literal_token_class_; // Class of LiteralToken vm object.
775 static RawClass* token_stream_class_; // Class of the TokenStream vm object. 780 static RawClass* token_stream_class_; // Class of the TokenStream vm object.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 static Bool* bool_true_; 827 static Bool* bool_true_;
823 static Bool* bool_false_; 828 static Bool* bool_false_;
824 static Smi* smi_illegal_cid_; 829 static Smi* smi_illegal_cid_;
825 static LanguageError* snapshot_writer_error_; 830 static LanguageError* snapshot_writer_error_;
826 static LanguageError* branch_offset_error_; 831 static LanguageError* branch_offset_error_;
827 static LanguageError* speculative_inlining_error_; 832 static LanguageError* speculative_inlining_error_;
828 static LanguageError* background_compilation_error_; 833 static LanguageError* background_compilation_error_;
829 static Array* vm_isolate_snapshot_object_table_; 834 static Array* vm_isolate_snapshot_object_table_;
830 static Type* dynamic_type_; 835 static Type* dynamic_type_;
831 static Type* void_type_; 836 static Type* void_type_;
837 static Type* vector_type_;
832 838
833 friend void ClassTable::Register(const Class& cls); 839 friend void ClassTable::Register(const Class& cls);
834 friend void RawObject::Validate(Isolate* isolate) const; 840 friend void RawObject::Validate(Isolate* isolate) const;
835 friend class Closure; 841 friend class Closure;
836 friend class SnapshotReader; 842 friend class SnapshotReader;
837 friend class InstanceDeserializationCluster; 843 friend class InstanceDeserializationCluster;
838 friend class OneByteString; 844 friend class OneByteString;
839 friend class TwoByteString; 845 friend class TwoByteString;
840 friend class ExternalOneByteString; 846 friend class ExternalOneByteString;
841 friend class ExternalTwoByteString; 847 friend class ExternalTwoByteString;
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 1572
1567 static RawUnresolvedClass* New(); 1573 static RawUnresolvedClass* New();
1568 1574
1569 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); 1575 FINAL_HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object);
1570 friend class Class; 1576 friend class Class;
1571 }; 1577 };
1572 1578
1573 1579
1574 // Classification of type genericity according to type parameter owners. 1580 // Classification of type genericity according to type parameter owners.
1575 enum Genericity { 1581 enum Genericity {
1576 kAny, // Consider type params of current class and functions. 1582 kAny, // Consider type params of current class and functions.
1577 kCurrentClass, // Consider type params of current class only. 1583 kCurrentClass, // Consider type params of current class only.
1578 kFunctions, // Consider type params of current and parent functions. 1584 kFunctions, // Consider type params of current and parent functions.
1579 }; 1585 };
1580 1586
1581 1587
1582 // A TypeArguments is an array of AbstractType. 1588 // A TypeArguments is an array of AbstractType.
1583 class TypeArguments : public Object { 1589 class TypeArguments : public Object {
1584 public: 1590 public:
1585 // We use 30 bits for the hash code so hashes in a snapshot taken on a 1591 // We use 30 bits for the hash code so hashes in a snapshot taken on a
1586 // 64-bit architecture stay in Smi range when loaded on a 32-bit 1592 // 64-bit architecture stay in Smi range when loaded on a 32-bit
1587 // architecture. 1593 // architecture.
1588 static const intptr_t kHashBits = 30; 1594 static const intptr_t kHashBits = 30;
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 bool IsInvokeFieldDispatcher() const { 2394 bool IsInvokeFieldDispatcher() const {
2389 return kind() == RawFunction::kInvokeFieldDispatcher; 2395 return kind() == RawFunction::kInvokeFieldDispatcher;
2390 } 2396 }
2391 2397
2392 // Returns true iff an implicit closure function has been created 2398 // Returns true iff an implicit closure function has been created
2393 // for this function. 2399 // for this function.
2394 bool HasImplicitClosureFunction() const { 2400 bool HasImplicitClosureFunction() const {
2395 return implicit_closure_function() != null(); 2401 return implicit_closure_function() != null();
2396 } 2402 }
2397 2403
2398 // Return the closure function implicitly created for this function. 2404 // Returns true iff a converted closure function has been created
2399 // If none exists yet, create one and remember it. 2405 // for this function.
2406 bool HasConvertedClosureFunction() const {
2407 return converted_closure_function() != null();
2408 }
2409
2410 // Returns the closure function implicitly created for this function. If none
2411 // exists yet, create one and remember it. Implicit closure functions are
2412 // used in VM Closure instances that represent results of tear-off operations.
2400 RawFunction* ImplicitClosureFunction() const; 2413 RawFunction* ImplicitClosureFunction() const;
2401 void DropUncompiledImplicitClosureFunction() const; 2414 void DropUncompiledImplicitClosureFunction() const;
2402 2415
2416 // Returns the converted closure function created for this function.
2417 // If none exists yet, create one and remember it. See the comment on
2418 // ConvertedClosureFunction definition in runtime/vm/object.cc for elaborate
2419 // explanation.
2420 RawFunction* ConvertedClosureFunction() const;
2421 void DropUncompiledConvertedClosureFunction() const;
2422
2403 // Return the closure implicitly created for this function. 2423 // Return the closure implicitly created for this function.
2404 // If none exists yet, create one and remember it. 2424 // If none exists yet, create one and remember it.
2405 RawInstance* ImplicitStaticClosure() const; 2425 RawInstance* ImplicitStaticClosure() const;
2406 2426
2407 RawInstance* ImplicitInstanceClosure(const Instance& receiver) const; 2427 RawInstance* ImplicitInstanceClosure(const Instance& receiver) const;
2408 2428
2409 RawSmi* GetClosureHashCode() const; 2429 RawSmi* GetClosureHashCode() const;
2410 2430
2411 // Redirection information for a redirecting factory. 2431 // Redirection information for a redirecting factory.
2412 bool IsRedirectingFactory() const; 2432 bool IsRedirectingFactory() const;
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
2753 } 2773 }
2754 2774
2755 // Returns true if this function represents a generated irregexp function. 2775 // Returns true if this function represents a generated irregexp function.
2756 bool IsIrregexpFunction() const { 2776 bool IsIrregexpFunction() const {
2757 return kind() == RawFunction::kIrregexpFunction; 2777 return kind() == RawFunction::kIrregexpFunction;
2758 } 2778 }
2759 2779
2760 // Returns true if this function represents an implicit closure function. 2780 // Returns true if this function represents an implicit closure function.
2761 bool IsImplicitClosureFunction() const; 2781 bool IsImplicitClosureFunction() const;
2762 2782
2783 // Returns true if this function represents a converted closure function.
2784 bool IsConvertedClosureFunction() const {
2785 return kind() == RawFunction::kConvertedClosureFunction;
2786 }
2787
2763 // Returns true if this function represents a non implicit closure function. 2788 // Returns true if this function represents a non implicit closure function.
2764 bool IsNonImplicitClosureFunction() const { 2789 bool IsNonImplicitClosureFunction() const {
2765 return IsClosureFunction() && !IsImplicitClosureFunction(); 2790 return IsClosureFunction() && !IsImplicitClosureFunction();
2766 } 2791 }
2767 2792
2768 // Returns true if this function represents an implicit static closure 2793 // Returns true if this function represents an implicit static closure
2769 // function. 2794 // function.
2770 bool IsImplicitStaticClosureFunction() const { 2795 bool IsImplicitStaticClosureFunction() const {
2771 return is_static() && IsImplicitClosureFunction(); 2796 return is_static() && IsImplicitClosureFunction();
2772 } 2797 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2845 bool is_native, 2870 bool is_native,
2846 const Object& owner, 2871 const Object& owner,
2847 TokenPosition token_pos, 2872 TokenPosition token_pos,
2848 Heap::Space space = Heap::kOld); 2873 Heap::Space space = Heap::kOld);
2849 2874
2850 // Allocates a new Function object representing a closure function. 2875 // Allocates a new Function object representing a closure function.
2851 static RawFunction* NewClosureFunction(const String& name, 2876 static RawFunction* NewClosureFunction(const String& name,
2852 const Function& parent, 2877 const Function& parent,
2853 TokenPosition token_pos); 2878 TokenPosition token_pos);
2854 2879
2880 // Allocates a new Function object representing a converted closure function.
2881 static RawFunction* NewConvertedClosureFunction(const String& name,
2882 const Function& parent,
2883 TokenPosition token_pos);
2884
2855 // Allocates a new Function object representing a signature function. 2885 // Allocates a new Function object representing a signature function.
2856 // The owner is the scope class of the function type. 2886 // The owner is the scope class of the function type.
2857 static RawFunction* NewSignatureFunction(const Object& owner, 2887 static RawFunction* NewSignatureFunction(const Object& owner,
2858 TokenPosition token_pos, 2888 TokenPosition token_pos,
2859 Heap::Space space = Heap::kOld); 2889 Heap::Space space = Heap::kOld);
2860 2890
2861 static RawFunction* NewEvalFunction(const Class& owner, 2891 static RawFunction* NewEvalFunction(const Class& owner,
2862 const Script& script, 2892 const Script& script,
2863 bool is_static); 2893 bool is_static);
2864 2894
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
3006 class name##Bit : public BitField<uint32_t, bool, k##name##Bit, 1> {}; 3036 class name##Bit : public BitField<uint32_t, bool, k##name##Bit, 1> {};
3007 FOR_EACH_FUNCTION_KIND_BIT(DEFINE_BIT) 3037 FOR_EACH_FUNCTION_KIND_BIT(DEFINE_BIT)
3008 #undef DEFINE_BIT 3038 #undef DEFINE_BIT
3009 3039
3010 void set_name(const String& value) const; 3040 void set_name(const String& value) const;
3011 void set_kind(RawFunction::Kind value) const; 3041 void set_kind(RawFunction::Kind value) const;
3012 void set_parent_function(const Function& value) const; 3042 void set_parent_function(const Function& value) const;
3013 void set_owner(const Object& value) const; 3043 void set_owner(const Object& value) const;
3014 RawFunction* implicit_closure_function() const; 3044 RawFunction* implicit_closure_function() const;
3015 void set_implicit_closure_function(const Function& value) const; 3045 void set_implicit_closure_function(const Function& value) const;
3046 RawFunction* converted_closure_function() const;
3047 void set_converted_closure_function(const Function& value) const;
3016 RawInstance* implicit_static_closure() const; 3048 RawInstance* implicit_static_closure() const;
3017 void set_implicit_static_closure(const Instance& closure) const; 3049 void set_implicit_static_closure(const Instance& closure) const;
3018 RawScript* eval_script() const; 3050 RawScript* eval_script() const;
3019 void set_eval_script(const Script& value) const; 3051 void set_eval_script(const Script& value) const;
3020 void set_num_optional_parameters(intptr_t value) const; // Encoded value. 3052 void set_num_optional_parameters(intptr_t value) const; // Encoded value.
3021 void set_kind_tag(uint32_t value) const; 3053 void set_kind_tag(uint32_t value) const;
3022 void set_data(const Object& value) const; 3054 void set_data(const Object& value) const;
3023 3055
3024 static RawFunction* New(Heap::Space space = Heap::kOld); 3056 static RawFunction* New(Heap::Space space = Heap::kOld);
3025 3057
(...skipping 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after
5099 // only be created using the Code::FinalizeCode method. This method creates 5131 // only be created using the Code::FinalizeCode method. This method creates
5100 // the RawInstruction and RawCode objects, sets up the pointer offsets 5132 // the RawInstruction and RawCode objects, sets up the pointer offsets
5101 // and links the two in a GC safe manner. 5133 // and links the two in a GC safe manner.
5102 static RawCode* New(intptr_t pointer_offsets_length); 5134 static RawCode* New(intptr_t pointer_offsets_length);
5103 5135
5104 FINAL_HEAP_OBJECT_IMPLEMENTATION(Code, Object); 5136 FINAL_HEAP_OBJECT_IMPLEMENTATION(Code, Object);
5105 friend class Class; 5137 friend class Class;
5106 friend class SnapshotWriter; 5138 friend class SnapshotWriter;
5107 friend class FunctionSerializationCluster; 5139 friend class FunctionSerializationCluster;
5108 friend class CodeSerializationCluster; 5140 friend class CodeSerializationCluster;
5109 friend class CodePatcher; // for set_instructions 5141 friend class CodePatcher; // for set_instructions
5110 friend class ProgramVisitor; // for set_instructions 5142 friend class ProgramVisitor; // for set_instructions
5111 // So that the RawFunction pointer visitor can determine whether code the 5143 // So that the RawFunction pointer visitor can determine whether code the
5112 // function points to is optimized. 5144 // function points to is optimized.
5113 friend class RawFunction; 5145 friend class RawFunction;
5114 }; 5146 };
5115 5147
5116 5148
5117 class Context : public Object { 5149 class Context : public Object {
5118 public: 5150 public:
5119 RawContext* parent() const { return raw_ptr()->parent_; } 5151 RawContext* parent() const { return raw_ptr()->parent_; }
(...skipping 3947 matching lines...) Expand 10 before | Expand all | Expand 10 after
9067 9099
9068 inline void TypeArguments::SetHash(intptr_t value) const { 9100 inline void TypeArguments::SetHash(intptr_t value) const {
9069 // This is only safe because we create a new Smi, which does not cause 9101 // This is only safe because we create a new Smi, which does not cause
9070 // heap allocation. 9102 // heap allocation.
9071 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); 9103 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
9072 } 9104 }
9073 9105
9074 } // namespace dart 9106 } // namespace dart
9075 9107
9076 #endif // RUNTIME_VM_OBJECT_H_ 9108 #endif // RUNTIME_VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698