 Chromium Code Reviews
 Chromium Code Reviews Issue 2891053003:
  Add support for converted closures with explicit contexts to VM  (Closed)
    
  
    Issue 2891053003:
  Add support for converted closures with explicit contexts to VM  (Closed) 
  | 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 #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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 | 
| 2404 // Returns true iff a converted closure function has been created | |
| 2405 // for this function. | |
| 2406 bool HasConvertedClosureFunction() const { | |
| 2407 return converted_closure_function() != null(); | |
| 2408 } | |
| 2409 | |
| 2398 // Return the closure function implicitly created for this function. | 2410 // Return the closure function implicitly created for this function. | 
| 2399 // If none exists yet, create one and remember it. | 2411 // If none exists yet, create one and remember it. | 
| 2400 RawFunction* ImplicitClosureFunction() const; | 2412 RawFunction* ImplicitClosureFunction() const; | 
| 2401 void DropUncompiledImplicitClosureFunction() const; | 2413 void DropUncompiledImplicitClosureFunction() const; | 
| 2402 | 2414 | 
| 2415 // Return the converted closure function created for this function. | |
| 
kustermann
2017/06/20 12:13:14
s/Return/Returns/
also above in the old code.
 
Dmitry Stefantsov
2017/06/22 14:12:52
Thanks!  Fixed.
 | |
| 2416 // If none exists yet, create one and remember it. | |
| 2417 RawFunction* ConvertedClosureFunction() const; | |
| 2418 void DropUncompiledConvertedClosureFunction() const; | |
| 
kustermann
2017/06/20 12:13:14
A reader of this could would be very curious what
 
Dmitry Stefantsov
2017/06/22 14:12:52
I think the comment on `Function::ConvertedClosure
 | |
| 2419 | |
| 2403 // Return the closure implicitly created for this function. | 2420 // Return the closure implicitly created for this function. | 
| 2404 // If none exists yet, create one and remember it. | 2421 // If none exists yet, create one and remember it. | 
| 2405 RawInstance* ImplicitStaticClosure() const; | 2422 RawInstance* ImplicitStaticClosure() const; | 
| 2406 | 2423 | 
| 2407 RawInstance* ImplicitInstanceClosure(const Instance& receiver) const; | 2424 RawInstance* ImplicitInstanceClosure(const Instance& receiver) const; | 
| 2408 | 2425 | 
| 2409 RawSmi* GetClosureHashCode() const; | 2426 RawSmi* GetClosureHashCode() const; | 
| 2410 | 2427 | 
| 2411 // Redirection information for a redirecting factory. | 2428 // Redirection information for a redirecting factory. | 
| 2412 bool IsRedirectingFactory() const; | 2429 bool IsRedirectingFactory() const; | 
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2753 } | 2770 } | 
| 2754 | 2771 | 
| 2755 // Returns true if this function represents a generated irregexp function. | 2772 // Returns true if this function represents a generated irregexp function. | 
| 2756 bool IsIrregexpFunction() const { | 2773 bool IsIrregexpFunction() const { | 
| 2757 return kind() == RawFunction::kIrregexpFunction; | 2774 return kind() == RawFunction::kIrregexpFunction; | 
| 2758 } | 2775 } | 
| 2759 | 2776 | 
| 2760 // Returns true if this function represents an implicit closure function. | 2777 // Returns true if this function represents an implicit closure function. | 
| 2761 bool IsImplicitClosureFunction() const; | 2778 bool IsImplicitClosureFunction() const; | 
| 2762 | 2779 | 
| 2780 // Returns true if this function represents a converted closure function. | |
| 2781 bool IsConvertedClosureFunction() const { | |
| 2782 return kind() == RawFunction::kConvertedClosureFunction; | |
| 2783 } | |
| 2784 | |
| 2763 // Returns true if this function represents a non implicit closure function. | 2785 // Returns true if this function represents a non implicit closure function. | 
| 2764 bool IsNonImplicitClosureFunction() const { | 2786 bool IsNonImplicitClosureFunction() const { | 
| 2765 return IsClosureFunction() && !IsImplicitClosureFunction(); | 2787 return IsClosureFunction() && !IsImplicitClosureFunction(); | 
| 2766 } | 2788 } | 
| 2767 | 2789 | 
| 2768 // Returns true if this function represents an implicit static closure | 2790 // Returns true if this function represents an implicit static closure | 
| 2769 // function. | 2791 // function. | 
| 2770 bool IsImplicitStaticClosureFunction() const { | 2792 bool IsImplicitStaticClosureFunction() const { | 
| 2771 return is_static() && IsImplicitClosureFunction(); | 2793 return is_static() && IsImplicitClosureFunction(); | 
| 2772 } | 2794 } | 
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2845 bool is_native, | 2867 bool is_native, | 
| 2846 const Object& owner, | 2868 const Object& owner, | 
| 2847 TokenPosition token_pos, | 2869 TokenPosition token_pos, | 
| 2848 Heap::Space space = Heap::kOld); | 2870 Heap::Space space = Heap::kOld); | 
| 2849 | 2871 | 
| 2850 // Allocates a new Function object representing a closure function. | 2872 // Allocates a new Function object representing a closure function. | 
| 2851 static RawFunction* NewClosureFunction(const String& name, | 2873 static RawFunction* NewClosureFunction(const String& name, | 
| 2852 const Function& parent, | 2874 const Function& parent, | 
| 2853 TokenPosition token_pos); | 2875 TokenPosition token_pos); | 
| 2854 | 2876 | 
| 2877 // Allocates a new Function object representing a converted closure function. | |
| 2878 static RawFunction* NewConvertedClosureFunction(const String& name, | |
| 2879 const Function& parent, | |
| 2880 TokenPosition token_pos); | |
| 2881 | |
| 2855 // Allocates a new Function object representing a signature function. | 2882 // Allocates a new Function object representing a signature function. | 
| 2856 // The owner is the scope class of the function type. | 2883 // The owner is the scope class of the function type. | 
| 2857 static RawFunction* NewSignatureFunction(const Object& owner, | 2884 static RawFunction* NewSignatureFunction(const Object& owner, | 
| 2858 TokenPosition token_pos, | 2885 TokenPosition token_pos, | 
| 2859 Heap::Space space = Heap::kOld); | 2886 Heap::Space space = Heap::kOld); | 
| 2860 | 2887 | 
| 2861 static RawFunction* NewEvalFunction(const Class& owner, | 2888 static RawFunction* NewEvalFunction(const Class& owner, | 
| 2862 const Script& script, | 2889 const Script& script, | 
| 2863 bool is_static); | 2890 bool is_static); | 
| 2864 | 2891 | 
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3006 class name##Bit : public BitField<uint32_t, bool, k##name##Bit, 1> {}; | 3033 class name##Bit : public BitField<uint32_t, bool, k##name##Bit, 1> {}; | 
| 3007 FOR_EACH_FUNCTION_KIND_BIT(DEFINE_BIT) | 3034 FOR_EACH_FUNCTION_KIND_BIT(DEFINE_BIT) | 
| 3008 #undef DEFINE_BIT | 3035 #undef DEFINE_BIT | 
| 3009 | 3036 | 
| 3010 void set_name(const String& value) const; | 3037 void set_name(const String& value) const; | 
| 3011 void set_kind(RawFunction::Kind value) const; | 3038 void set_kind(RawFunction::Kind value) const; | 
| 3012 void set_parent_function(const Function& value) const; | 3039 void set_parent_function(const Function& value) const; | 
| 3013 void set_owner(const Object& value) const; | 3040 void set_owner(const Object& value) const; | 
| 3014 RawFunction* implicit_closure_function() const; | 3041 RawFunction* implicit_closure_function() const; | 
| 3015 void set_implicit_closure_function(const Function& value) const; | 3042 void set_implicit_closure_function(const Function& value) const; | 
| 3043 RawFunction* converted_closure_function() const; | |
| 3044 void set_converted_closure_function(const Function& value) const; | |
| 3016 RawInstance* implicit_static_closure() const; | 3045 RawInstance* implicit_static_closure() const; | 
| 3017 void set_implicit_static_closure(const Instance& closure) const; | 3046 void set_implicit_static_closure(const Instance& closure) const; | 
| 3018 RawScript* eval_script() const; | 3047 RawScript* eval_script() const; | 
| 3019 void set_eval_script(const Script& value) const; | 3048 void set_eval_script(const Script& value) const; | 
| 3020 void set_num_optional_parameters(intptr_t value) const; // Encoded value. | 3049 void set_num_optional_parameters(intptr_t value) const; // Encoded value. | 
| 3021 void set_kind_tag(uint32_t value) const; | 3050 void set_kind_tag(uint32_t value) const; | 
| 3022 void set_data(const Object& value) const; | 3051 void set_data(const Object& value) const; | 
| 3023 | 3052 | 
| 3024 static RawFunction* New(Heap::Space space = Heap::kOld); | 3053 static RawFunction* New(Heap::Space space = Heap::kOld); | 
| 3025 | 3054 | 
| (...skipping 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5099 // only be created using the Code::FinalizeCode method. This method creates | 5128 // only be created using the Code::FinalizeCode method. This method creates | 
| 5100 // the RawInstruction and RawCode objects, sets up the pointer offsets | 5129 // the RawInstruction and RawCode objects, sets up the pointer offsets | 
| 5101 // and links the two in a GC safe manner. | 5130 // and links the two in a GC safe manner. | 
| 5102 static RawCode* New(intptr_t pointer_offsets_length); | 5131 static RawCode* New(intptr_t pointer_offsets_length); | 
| 5103 | 5132 | 
| 5104 FINAL_HEAP_OBJECT_IMPLEMENTATION(Code, Object); | 5133 FINAL_HEAP_OBJECT_IMPLEMENTATION(Code, Object); | 
| 5105 friend class Class; | 5134 friend class Class; | 
| 5106 friend class SnapshotWriter; | 5135 friend class SnapshotWriter; | 
| 5107 friend class FunctionSerializationCluster; | 5136 friend class FunctionSerializationCluster; | 
| 5108 friend class CodeSerializationCluster; | 5137 friend class CodeSerializationCluster; | 
| 5109 friend class CodePatcher; // for set_instructions | 5138 friend class CodePatcher; // for set_instructions | 
| 5110 friend class ProgramVisitor; // for set_instructions | 5139 friend class ProgramVisitor; // for set_instructions | 
| 5111 // So that the RawFunction pointer visitor can determine whether code the | 5140 // So that the RawFunction pointer visitor can determine whether code the | 
| 5112 // function points to is optimized. | 5141 // function points to is optimized. | 
| 5113 friend class RawFunction; | 5142 friend class RawFunction; | 
| 5114 }; | 5143 }; | 
| 5115 | 5144 | 
| 5116 | 5145 | 
| 5117 class Context : public Object { | 5146 class Context : public Object { | 
| 5118 public: | 5147 public: | 
| 5119 RawContext* parent() const { return raw_ptr()->parent_; } | 5148 RawContext* parent() const { return raw_ptr()->parent_; } | 
| (...skipping 3947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9067 | 9096 | 
| 9068 inline void TypeArguments::SetHash(intptr_t value) const { | 9097 inline void TypeArguments::SetHash(intptr_t value) const { | 
| 9069 // This is only safe because we create a new Smi, which does not cause | 9098 // This is only safe because we create a new Smi, which does not cause | 
| 9070 // heap allocation. | 9099 // heap allocation. | 
| 9071 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); | 9100 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); | 
| 9072 } | 9101 } | 
| 9073 | 9102 | 
| 9074 } // namespace dart | 9103 } // namespace dart | 
| 9075 | 9104 | 
| 9076 #endif // RUNTIME_VM_OBJECT_H_ | 9105 #endif // RUNTIME_VM_OBJECT_H_ | 
| OLD | NEW |