| 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/become.h" | 10 #include "vm/become.h" |
| (...skipping 2876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2887 | 2887 |
| 2888 | 2888 |
| 2889 bool Class::ValidatePostFinalizePatch(const Class& orig_class, | 2889 bool Class::ValidatePostFinalizePatch(const Class& orig_class, |
| 2890 Error* error) const { | 2890 Error* error) const { |
| 2891 ASSERT(error != NULL); | 2891 ASSERT(error != NULL); |
| 2892 // Not allowed to add new fields in a post finalization patch. | 2892 // Not allowed to add new fields in a post finalization patch. |
| 2893 if (fields() != Object::empty_array().raw()) { | 2893 if (fields() != Object::empty_array().raw()) { |
| 2894 *error = LanguageError::NewFormatted( | 2894 *error = LanguageError::NewFormatted( |
| 2895 *error, // No previous error. | 2895 *error, // No previous error. |
| 2896 Script::Handle(script()), token_pos(), Report::AtLocation, | 2896 Script::Handle(script()), token_pos(), Report::AtLocation, |
| 2897 Report::kError, Heap::kNew, | 2897 Report::kError, Heap::kOld, |
| 2898 "new fields are not allowed for this patch"); | 2898 "new fields are not allowed for this patch"); |
| 2899 return false; | 2899 return false; |
| 2900 } | 2900 } |
| 2901 // There seem to be no functions, the patch is pointless. | 2901 // There seem to be no functions, the patch is pointless. |
| 2902 if (functions() == Object::empty_array().raw()) { | 2902 if (functions() == Object::empty_array().raw()) { |
| 2903 *error = LanguageError::NewFormatted(*error, // No previous error. | 2903 *error = LanguageError::NewFormatted(*error, // No previous error. |
| 2904 Script::Handle(script()), token_pos(), | 2904 Script::Handle(script()), token_pos(), |
| 2905 Report::AtLocation, Report::kError, | 2905 Report::AtLocation, Report::kError, |
| 2906 Heap::kNew, "no functions to patch"); | 2906 Heap::kOld, "no functions to patch"); |
| 2907 return false; | 2907 return false; |
| 2908 } | 2908 } |
| 2909 // Iterate over all functions that will be patched and make sure | 2909 // Iterate over all functions that will be patched and make sure |
| 2910 // the original function was declared 'external' and has not executed | 2910 // the original function was declared 'external' and has not executed |
| 2911 // so far i.e no code has been generated for it. | 2911 // so far i.e no code has been generated for it. |
| 2912 Thread* thread = Thread::Current(); | 2912 Thread* thread = Thread::Current(); |
| 2913 ASSERT(thread->IsMutatorThread()); | 2913 ASSERT(thread->IsMutatorThread()); |
| 2914 Zone* zone = thread->zone(); | 2914 Zone* zone = thread->zone(); |
| 2915 const Array& funcs = Array::Handle(zone, functions()); | 2915 const Array& funcs = Array::Handle(zone, functions()); |
| 2916 Function& func = Function::Handle(zone); | 2916 Function& func = Function::Handle(zone); |
| 2917 Function& orig_func = Function::Handle(zone); | 2917 Function& orig_func = Function::Handle(zone); |
| 2918 String& name = String::Handle(zone); | 2918 String& name = String::Handle(zone); |
| 2919 for (intptr_t i = 0; i < funcs.Length(); i++) { | 2919 for (intptr_t i = 0; i < funcs.Length(); i++) { |
| 2920 func ^= funcs.At(i); | 2920 func ^= funcs.At(i); |
| 2921 name ^= func.name(); | 2921 name ^= func.name(); |
| 2922 orig_func ^= orig_class.LookupFunctionAllowPrivate(name); | 2922 orig_func ^= orig_class.LookupFunctionAllowPrivate(name); |
| 2923 if (!orig_func.IsNull()) { | 2923 if (!orig_func.IsNull()) { |
| 2924 if (!orig_func.is_external() || orig_func.HasCode()) { | 2924 if (!orig_func.is_external() || orig_func.HasCode()) { |
| 2925 // We can only patch external functions in a post finalized class. | 2925 // We can only patch external functions in a post finalized class. |
| 2926 *error = LanguageError::NewFormatted( | 2926 *error = LanguageError::NewFormatted( |
| 2927 *error, // No previous error. | 2927 *error, // No previous error. |
| 2928 Script::Handle(script()), token_pos(), Report::AtLocation, | 2928 Script::Handle(script()), token_pos(), Report::AtLocation, |
| 2929 Report::kError, Heap::kNew, | 2929 Report::kError, Heap::kOld, |
| 2930 !orig_func.is_external() | 2930 !orig_func.is_external() |
| 2931 ? "'%s' is not external and therefore cannot be patched" | 2931 ? "'%s' is not external and therefore cannot be patched" |
| 2932 : "'%s' has already executed and therefore cannot be patched", | 2932 : "'%s' has already executed and therefore cannot be patched", |
| 2933 name.ToCString()); | 2933 name.ToCString()); |
| 2934 return false; | 2934 return false; |
| 2935 } | 2935 } |
| 2936 } else if (!Library::IsPrivate(name)) { | 2936 } else if (!Library::IsPrivate(name)) { |
| 2937 // We can only have new private functions that are added. | 2937 // We can only have new private functions that are added. |
| 2938 *error = LanguageError::NewFormatted( | 2938 *error = LanguageError::NewFormatted( |
| 2939 *error, // No previous error. | 2939 *error, // No previous error. |
| 2940 Script::Handle(script()), token_pos(), Report::AtLocation, | 2940 Script::Handle(script()), token_pos(), Report::AtLocation, |
| 2941 Report::kError, Heap::kNew, | 2941 Report::kError, Heap::kOld, |
| 2942 "'%s' is not private and therefore cannot be patched", | 2942 "'%s' is not private and therefore cannot be patched", |
| 2943 name.ToCString()); | 2943 name.ToCString()); |
| 2944 return false; | 2944 return false; |
| 2945 } | 2945 } |
| 2946 } | 2946 } |
| 2947 return true; | 2947 return true; |
| 2948 } | 2948 } |
| 2949 | 2949 |
| 2950 | 2950 |
| 2951 void Class::set_dependent_code(const Array& array) const { | 2951 void Class::set_dependent_code(const Array& array) const { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2967 intptr_t orig_len = orig_list.Length(); | 2967 intptr_t orig_len = orig_list.Length(); |
| 2968 Array& patch_list = Array::Handle(patch.functions()); | 2968 Array& patch_list = Array::Handle(patch.functions()); |
| 2969 intptr_t patch_len = patch_list.Length(); | 2969 intptr_t patch_len = patch_list.Length(); |
| 2970 | 2970 |
| 2971 // TODO(iposva): Verify that only patching existing methods and adding only | 2971 // TODO(iposva): Verify that only patching existing methods and adding only |
| 2972 // new private methods. | 2972 // new private methods. |
| 2973 Function& func = Function::Handle(); | 2973 Function& func = Function::Handle(); |
| 2974 Function& orig_func = Function::Handle(); | 2974 Function& orig_func = Function::Handle(); |
| 2975 // Lookup the original implicit constructor, if any. | 2975 // Lookup the original implicit constructor, if any. |
| 2976 member_name = Name(); | 2976 member_name = Name(); |
| 2977 member_name = String::Concat(member_name, Symbols::Dot()); | 2977 member_name = String::Concat(member_name, Symbols::Dot(), Heap::kOld); |
| 2978 Function& orig_implicit_ctor = Function::Handle(LookupFunction(member_name)); | 2978 Function& orig_implicit_ctor = Function::Handle(LookupFunction(member_name)); |
| 2979 if (!orig_implicit_ctor.IsNull() && | 2979 if (!orig_implicit_ctor.IsNull() && |
| 2980 !orig_implicit_ctor.IsImplicitConstructor()) { | 2980 !orig_implicit_ctor.IsImplicitConstructor()) { |
| 2981 // Not an implicit constructor, but a user declared one. | 2981 // Not an implicit constructor, but a user declared one. |
| 2982 orig_implicit_ctor = Function::null(); | 2982 orig_implicit_ctor = Function::null(); |
| 2983 } | 2983 } |
| 2984 const GrowableObjectArray& new_functions = | 2984 const GrowableObjectArray& new_functions = GrowableObjectArray::Handle( |
| 2985 GrowableObjectArray::Handle(GrowableObjectArray::New(orig_len)); | 2985 GrowableObjectArray::New(orig_len, Heap::kOld)); |
| 2986 for (intptr_t i = 0; i < orig_len; i++) { | 2986 for (intptr_t i = 0; i < orig_len; i++) { |
| 2987 orig_func ^= orig_list.At(i); | 2987 orig_func ^= orig_list.At(i); |
| 2988 member_name ^= orig_func.name(); | 2988 member_name ^= orig_func.name(); |
| 2989 func = patch.LookupFunction(member_name); | 2989 func = patch.LookupFunction(member_name); |
| 2990 if (func.IsNull()) { | 2990 if (func.IsNull()) { |
| 2991 // Non-patched function is preserved, all patched functions are added in | 2991 // Non-patched function is preserved, all patched functions are added in |
| 2992 // the loop below. | 2992 // the loop below. |
| 2993 // However, an implicitly created constructor should not be preserved if | 2993 // However, an implicitly created constructor should not be preserved if |
| 2994 // the patch provides a constructor or a factory. Wait for now. | 2994 // the patch provides a constructor or a factory. Wait for now. |
| 2995 if (orig_func.raw() != orig_implicit_ctor.raw()) { | 2995 if (orig_func.raw() != orig_implicit_ctor.raw()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3008 return false; | 3008 return false; |
| 3009 } | 3009 } |
| 3010 } | 3010 } |
| 3011 for (intptr_t i = 0; i < patch_len; i++) { | 3011 for (intptr_t i = 0; i < patch_len; i++) { |
| 3012 func ^= patch_list.At(i); | 3012 func ^= patch_list.At(i); |
| 3013 if (func.IsGenerativeConstructor() || func.IsFactory()) { | 3013 if (func.IsGenerativeConstructor() || func.IsFactory()) { |
| 3014 // Do not preserve the original implicit constructor, if any. | 3014 // Do not preserve the original implicit constructor, if any. |
| 3015 orig_implicit_ctor = Function::null(); | 3015 orig_implicit_ctor = Function::null(); |
| 3016 } | 3016 } |
| 3017 func.set_owner(patch_class); | 3017 func.set_owner(patch_class); |
| 3018 new_functions.Add(func); | 3018 new_functions.Add(func, Heap::kOld); |
| 3019 } | 3019 } |
| 3020 if (!orig_implicit_ctor.IsNull()) { | 3020 if (!orig_implicit_ctor.IsNull()) { |
| 3021 // Preserve the original implicit constructor. | 3021 // Preserve the original implicit constructor. |
| 3022 new_functions.Add(orig_implicit_ctor); | 3022 new_functions.Add(orig_implicit_ctor, Heap::kOld); |
| 3023 } | 3023 } |
| 3024 Array& new_list = Array::Handle(Array::MakeArray(new_functions)); | 3024 Array& new_list = Array::Handle(Array::MakeArray(new_functions)); |
| 3025 SetFunctions(new_list); | 3025 SetFunctions(new_list); |
| 3026 | 3026 |
| 3027 // Merge the two list of fields. Raise an error when duplicates are found or | 3027 // Merge the two list of fields. Raise an error when duplicates are found or |
| 3028 // when a public field is being added. | 3028 // when a public field is being added. |
| 3029 orig_list = fields(); | 3029 orig_list = fields(); |
| 3030 orig_len = orig_list.Length(); | 3030 orig_len = orig_list.Length(); |
| 3031 patch_list = patch.fields(); | 3031 patch_list = patch.fields(); |
| 3032 patch_len = patch_list.Length(); | 3032 patch_len = patch_list.Length(); |
| 3033 | 3033 |
| 3034 Field& field = Field::Handle(); | 3034 Field& field = Field::Handle(); |
| 3035 Field& orig_field = Field::Handle(); | 3035 Field& orig_field = Field::Handle(); |
| 3036 new_list = Array::New(patch_len + orig_len); | 3036 new_list = Array::New(patch_len + orig_len, Heap::kOld); |
| 3037 for (intptr_t i = 0; i < patch_len; i++) { | 3037 for (intptr_t i = 0; i < patch_len; i++) { |
| 3038 field ^= patch_list.At(i); | 3038 field ^= patch_list.At(i); |
| 3039 field.set_owner(patch_class); | 3039 field.set_owner(patch_class); |
| 3040 member_name = field.name(); | 3040 member_name = field.name(); |
| 3041 // TODO(iposva): Verify non-public fields only. | 3041 // TODO(iposva): Verify non-public fields only. |
| 3042 | 3042 |
| 3043 // Verify no duplicate additions. | 3043 // Verify no duplicate additions. |
| 3044 orig_field ^= LookupField(member_name); | 3044 orig_field ^= LookupField(member_name); |
| 3045 if (!orig_field.IsNull()) { | 3045 if (!orig_field.IsNull()) { |
| 3046 *error = LanguageError::NewFormatted( | 3046 *error = LanguageError::NewFormatted( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3173 ASSERT(field.Owner() == raw()); | 3173 ASSERT(field.Owner() == raw()); |
| 3174 } | 3174 } |
| 3175 #endif | 3175 #endif |
| 3176 // The value of static fields is already initialized to null. | 3176 // The value of static fields is already initialized to null. |
| 3177 StorePointer(&raw_ptr()->fields_, value.raw()); | 3177 StorePointer(&raw_ptr()->fields_, value.raw()); |
| 3178 } | 3178 } |
| 3179 | 3179 |
| 3180 | 3180 |
| 3181 void Class::AddField(const Field& field) const { | 3181 void Class::AddField(const Field& field) const { |
| 3182 const Array& arr = Array::Handle(fields()); | 3182 const Array& arr = Array::Handle(fields()); |
| 3183 const Array& new_arr = Array::Handle(Array::Grow(arr, arr.Length() + 1)); | 3183 const Array& new_arr = |
| 3184 Array::Handle(Array::Grow(arr, arr.Length() + 1, Heap::kOld)); |
| 3184 new_arr.SetAt(arr.Length(), field); | 3185 new_arr.SetAt(arr.Length(), field); |
| 3185 SetFields(new_arr); | 3186 SetFields(new_arr); |
| 3186 } | 3187 } |
| 3187 | 3188 |
| 3188 | 3189 |
| 3189 void Class::AddFields(const GrowableArray<const Field*>& new_fields) const { | 3190 void Class::AddFields(const GrowableArray<const Field*>& new_fields) const { |
| 3190 const intptr_t num_new_fields = new_fields.length(); | 3191 const intptr_t num_new_fields = new_fields.length(); |
| 3191 if (num_new_fields == 0) return; | 3192 if (num_new_fields == 0) return; |
| 3192 const Array& arr = Array::Handle(fields()); | 3193 const Array& arr = Array::Handle(fields()); |
| 3193 const intptr_t num_old_fields = arr.Length(); | 3194 const intptr_t num_old_fields = arr.Length(); |
| (...skipping 2068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5262 | 5263 |
| 5263 | 5264 |
| 5264 RawString* TypeArguments::EnumerateURIs() const { | 5265 RawString* TypeArguments::EnumerateURIs() const { |
| 5265 if (IsNull()) { | 5266 if (IsNull()) { |
| 5266 return Symbols::Empty().raw(); | 5267 return Symbols::Empty().raw(); |
| 5267 } | 5268 } |
| 5268 Thread* thread = Thread::Current(); | 5269 Thread* thread = Thread::Current(); |
| 5269 Zone* zone = thread->zone(); | 5270 Zone* zone = thread->zone(); |
| 5270 AbstractType& type = AbstractType::Handle(zone); | 5271 AbstractType& type = AbstractType::Handle(zone); |
| 5271 const intptr_t num_types = Length(); | 5272 const intptr_t num_types = Length(); |
| 5272 const Array& pieces = Array::Handle(zone, Array::New(num_types)); | 5273 const Array& pieces = Array::Handle(zone, Array::New(num_types, Heap::kOld)); |
| 5273 for (intptr_t i = 0; i < num_types; i++) { | 5274 for (intptr_t i = 0; i < num_types; i++) { |
| 5274 type = TypeAt(i); | 5275 type = TypeAt(i); |
| 5275 pieces.SetAt(i, String::Handle(zone, type.EnumerateURIs())); | 5276 pieces.SetAt(i, String::Handle(zone, type.EnumerateURIs())); |
| 5276 } | 5277 } |
| 5277 return String::ConcatAll(pieces); | 5278 return String::ConcatAll(pieces, Heap::kOld); |
| 5278 } | 5279 } |
| 5279 | 5280 |
| 5280 | 5281 |
| 5281 const char* TypeArguments::ToCString() const { | 5282 const char* TypeArguments::ToCString() const { |
| 5282 if (IsNull()) { | 5283 if (IsNull()) { |
| 5283 return "TypeArguments: null"; | 5284 return "TypeArguments: null"; |
| 5284 } | 5285 } |
| 5285 Zone* zone = Thread::Current()->zone(); | 5286 Zone* zone = Thread::Current()->zone(); |
| 5286 const char* prev_cstr = OS::SCreate(zone, "TypeArguments: (%" Pd ")", | 5287 const char* prev_cstr = OS::SCreate(zone, "TypeArguments: (%" Pd ")", |
| 5287 Smi::Value(raw_ptr()->hash_)); | 5288 Smi::Value(raw_ptr()->hash_)); |
| (...skipping 2423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7711 | 7712 |
| 7712 | 7713 |
| 7713 void Field::SetOriginal(const Field& value) const { | 7714 void Field::SetOriginal(const Field& value) const { |
| 7714 ASSERT(value.IsOriginal()); | 7715 ASSERT(value.IsOriginal()); |
| 7715 ASSERT(!value.IsNull()); | 7716 ASSERT(!value.IsNull()); |
| 7716 StorePointer(&raw_ptr()->owner_, reinterpret_cast<RawObject*>(value.raw())); | 7717 StorePointer(&raw_ptr()->owner_, reinterpret_cast<RawObject*>(value.raw())); |
| 7717 } | 7718 } |
| 7718 | 7719 |
| 7719 | 7720 |
| 7720 RawString* Field::GetterName(const String& field_name) { | 7721 RawString* Field::GetterName(const String& field_name) { |
| 7721 return String::Concat(Symbols::GetterPrefix(), field_name); | 7722 return String::Concat(Symbols::GetterPrefix(), field_name, Heap::kOld); |
| 7722 } | 7723 } |
| 7723 | 7724 |
| 7724 | 7725 |
| 7725 RawString* Field::GetterSymbol(const String& field_name) { | 7726 RawString* Field::GetterSymbol(const String& field_name) { |
| 7726 return Symbols::FromGet(Thread::Current(), field_name); | 7727 return Symbols::FromGet(Thread::Current(), field_name); |
| 7727 } | 7728 } |
| 7728 | 7729 |
| 7729 | 7730 |
| 7730 RawString* Field::LookupGetterSymbol(const String& field_name) { | 7731 RawString* Field::LookupGetterSymbol(const String& field_name) { |
| 7731 return Symbols::LookupFromGet(Thread::Current(), field_name); | 7732 return Symbols::LookupFromGet(Thread::Current(), field_name); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8056 ASSERT(!closure.IsNull()); | 8057 ASSERT(!closure.IsNull()); |
| 8057 ASSERT(closure.IsClosure()); | 8058 ASSERT(closure.IsClosure()); |
| 8058 return closure.raw(); | 8059 return closure.raw(); |
| 8059 } | 8060 } |
| 8060 | 8061 |
| 8061 // This is the first time a closure for this field is requested. | 8062 // This is the first time a closure for this field is requested. |
| 8062 // Create the closure and a new static field in which it is stored. | 8063 // Create the closure and a new static field in which it is stored. |
| 8063 const char* field_name = String::Handle(zone, name()).ToCString(); | 8064 const char* field_name = String::Handle(zone, name()).ToCString(); |
| 8064 String& expr_src = String::Handle(zone); | 8065 String& expr_src = String::Handle(zone); |
| 8065 if (make_setter) { | 8066 if (make_setter) { |
| 8066 expr_src = String::NewFormatted("(%s_) { return %s = %s_; }", field_name, | 8067 expr_src = String::NewFormatted(Heap::kOld, "(%s_) { return %s = %s_; }", |
| 8067 field_name, field_name); | 8068 field_name, field_name, field_name); |
| 8068 } else { | 8069 } else { |
| 8069 expr_src = String::NewFormatted("() { return %s; }", field_name); | 8070 expr_src = |
| 8071 String::NewFormatted(Heap::kOld, "() { return %s; }", field_name); |
| 8070 } | 8072 } |
| 8071 Object& result = | 8073 Object& result = |
| 8072 Object::Handle(zone, field_owner.Evaluate(expr_src, Object::empty_array(), | 8074 Object::Handle(zone, field_owner.Evaluate(expr_src, Object::empty_array(), |
| 8073 Object::empty_array())); | 8075 Object::empty_array())); |
| 8074 ASSERT(result.IsInstance()); | 8076 ASSERT(result.IsInstance()); |
| 8075 // The caller may expect the closure to be allocated in old space. Copy | 8077 // The caller may expect the closure to be allocated in old space. Copy |
| 8076 // the result here, since Object::Clone() is a private method. | 8078 // the result here, since Object::Clone() is a private method. |
| 8077 result = Object::Clone(result, Heap::kOld); | 8079 result = Object::Clone(result, Heap::kOld); |
| 8078 | 8080 |
| 8079 closure_field = | 8081 closure_field = |
| (...skipping 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9985 return error.raw(); | 9987 return error.raw(); |
| 9986 } | 9988 } |
| 9987 | 9989 |
| 9988 | 9990 |
| 9989 void Library::AddPatchClass(const Class& cls) const { | 9991 void Library::AddPatchClass(const Class& cls) const { |
| 9990 ASSERT(Thread::Current()->IsMutatorThread()); | 9992 ASSERT(Thread::Current()->IsMutatorThread()); |
| 9991 ASSERT(cls.is_patch()); | 9993 ASSERT(cls.is_patch()); |
| 9992 ASSERT(GetPatchClass(String::Handle(cls.Name())) == Class::null()); | 9994 ASSERT(GetPatchClass(String::Handle(cls.Name())) == Class::null()); |
| 9993 const GrowableObjectArray& patch_classes = | 9995 const GrowableObjectArray& patch_classes = |
| 9994 GrowableObjectArray::Handle(this->patch_classes()); | 9996 GrowableObjectArray::Handle(this->patch_classes()); |
| 9995 patch_classes.Add(cls); | 9997 patch_classes.Add(cls, Heap::kOld); |
| 9996 } | 9998 } |
| 9997 | 9999 |
| 9998 | 10000 |
| 9999 RawClass* Library::GetPatchClass(const String& name) const { | 10001 RawClass* Library::GetPatchClass(const String& name) const { |
| 10000 ASSERT(Thread::Current()->IsMutatorThread()); | 10002 ASSERT(Thread::Current()->IsMutatorThread()); |
| 10001 const GrowableObjectArray& patch_classes = | 10003 const GrowableObjectArray& patch_classes = |
| 10002 GrowableObjectArray::Handle(this->patch_classes()); | 10004 GrowableObjectArray::Handle(this->patch_classes()); |
| 10003 Object& obj = Object::Handle(); | 10005 Object& obj = Object::Handle(); |
| 10004 for (intptr_t i = 0; i < patch_classes.Length(); i++) { | 10006 for (intptr_t i = 0; i < patch_classes.Length(); i++) { |
| 10005 obj = patch_classes.At(i); | 10007 obj = patch_classes.At(i); |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10919 StorePointer(&raw_ptr()->exported_names_, Array::null()); | 10921 StorePointer(&raw_ptr()->exported_names_, Array::null()); |
| 10920 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); | 10922 StorePointer(&raw_ptr()->loaded_scripts_, Array::null()); |
| 10921 } | 10923 } |
| 10922 | 10924 |
| 10923 | 10925 |
| 10924 void Library::AddImport(const Namespace& ns) const { | 10926 void Library::AddImport(const Namespace& ns) const { |
| 10925 Array& imports = Array::Handle(this->imports()); | 10927 Array& imports = Array::Handle(this->imports()); |
| 10926 intptr_t capacity = imports.Length(); | 10928 intptr_t capacity = imports.Length(); |
| 10927 if (num_imports() == capacity) { | 10929 if (num_imports() == capacity) { |
| 10928 capacity = capacity + kImportsCapacityIncrement + (capacity >> 2); | 10930 capacity = capacity + kImportsCapacityIncrement + (capacity >> 2); |
| 10929 imports = Array::Grow(imports, capacity); | 10931 imports = Array::Grow(imports, capacity, Heap::kOld); |
| 10930 StorePointer(&raw_ptr()->imports_, imports.raw()); | 10932 StorePointer(&raw_ptr()->imports_, imports.raw()); |
| 10931 } | 10933 } |
| 10932 intptr_t index = num_imports(); | 10934 intptr_t index = num_imports(); |
| 10933 imports.SetAt(index, ns); | 10935 imports.SetAt(index, ns); |
| 10934 set_num_imports(index + 1); | 10936 set_num_imports(index + 1); |
| 10935 } | 10937 } |
| 10936 | 10938 |
| 10937 | 10939 |
| 10938 // Convenience function to determine whether the export list is | 10940 // Convenience function to determine whether the export list is |
| 10939 // non-empty. | 10941 // non-empty. |
| 10940 bool Library::HasExports() const { | 10942 bool Library::HasExports() const { |
| 10941 return exports() != Object::empty_array().raw(); | 10943 return exports() != Object::empty_array().raw(); |
| 10942 } | 10944 } |
| 10943 | 10945 |
| 10944 | 10946 |
| 10945 // We add one namespace at a time to the exports array and don't | 10947 // We add one namespace at a time to the exports array and don't |
| 10946 // pre-allocate any unused capacity. The assumption is that | 10948 // pre-allocate any unused capacity. The assumption is that |
| 10947 // re-exports are quite rare. | 10949 // re-exports are quite rare. |
| 10948 void Library::AddExport(const Namespace& ns) const { | 10950 void Library::AddExport(const Namespace& ns) const { |
| 10949 Array& exports = Array::Handle(this->exports()); | 10951 Array& exports = Array::Handle(this->exports()); |
| 10950 intptr_t num_exports = exports.Length(); | 10952 intptr_t num_exports = exports.Length(); |
| 10951 exports = Array::Grow(exports, num_exports + 1); | 10953 exports = Array::Grow(exports, num_exports + 1, Heap::kOld); |
| 10952 StorePointer(&raw_ptr()->exports_, exports.raw()); | 10954 StorePointer(&raw_ptr()->exports_, exports.raw()); |
| 10953 exports.SetAt(num_exports, ns); | 10955 exports.SetAt(num_exports, ns); |
| 10954 } | 10956 } |
| 10955 | 10957 |
| 10956 | 10958 |
| 10957 static RawArray* NewDictionary(intptr_t initial_size) { | 10959 static RawArray* NewDictionary(intptr_t initial_size) { |
| 10958 const Array& dict = Array::Handle(Array::New(initial_size + 1, Heap::kOld)); | 10960 const Array& dict = Array::Handle(Array::New(initial_size + 1, Heap::kOld)); |
| 10959 // The last element of the dictionary specifies the number of in use slots. | 10961 // The last element of the dictionary specifies the number of in use slots. |
| 10960 dict.SetAt(initial_size, Smi::Handle(Smi::New(0))); | 10962 dict.SetAt(initial_size, Smi::Handle(Smi::New(0))); |
| 10961 return dict.raw(); | 10963 return dict.raw(); |
| 10962 } | 10964 } |
| 10963 | 10965 |
| 10964 | 10966 |
| 10965 void Library::InitResolvedNamesCache() const { | 10967 void Library::InitResolvedNamesCache() const { |
| 10966 ASSERT(Thread::Current()->IsMutatorThread()); | 10968 ASSERT(Thread::Current()->IsMutatorThread()); |
| 10967 StorePointer(&raw_ptr()->resolved_names_, | 10969 StorePointer(&raw_ptr()->resolved_names_, |
| 10968 HashTables::New<ResolvedNamesMap>(64)); | 10970 HashTables::New<ResolvedNamesMap>(64, Heap::kOld)); |
| 10969 } | 10971 } |
| 10970 | 10972 |
| 10971 | 10973 |
| 10972 void Library::ClearResolvedNamesCache() const { | 10974 void Library::ClearResolvedNamesCache() const { |
| 10973 ASSERT(Thread::Current()->IsMutatorThread()); | 10975 ASSERT(Thread::Current()->IsMutatorThread()); |
| 10974 StorePointer(&raw_ptr()->resolved_names_, Array::null()); | 10976 StorePointer(&raw_ptr()->resolved_names_, Array::null()); |
| 10975 } | 10977 } |
| 10976 | 10978 |
| 10977 | 10979 |
| 10978 void Library::InitExportedNamesCache() const { | 10980 void Library::InitExportedNamesCache() const { |
| 10979 StorePointer(&raw_ptr()->exported_names_, | 10981 StorePointer(&raw_ptr()->exported_names_, |
| 10980 HashTables::New<ResolvedNamesMap>(16)); | 10982 HashTables::New<ResolvedNamesMap>(16, Heap::kOld)); |
| 10981 } | 10983 } |
| 10982 | 10984 |
| 10983 | 10985 |
| 10984 void Library::ClearExportedNamesCache() const { | 10986 void Library::ClearExportedNamesCache() const { |
| 10985 StorePointer(&raw_ptr()->exported_names_, Array::null()); | 10987 StorePointer(&raw_ptr()->exported_names_, Array::null()); |
| 10986 } | 10988 } |
| 10987 | 10989 |
| 10988 | 10990 |
| 10989 void Library::InitClassDictionary() const { | 10991 void Library::InitClassDictionary() const { |
| 10990 // TODO(iposva): Find reasonable initial size. | 10992 // TODO(iposva): Find reasonable initial size. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11301 | 11303 |
| 11302 // A library is "registered" in two places: | 11304 // A library is "registered" in two places: |
| 11303 // - A growable array mapping from index to library. | 11305 // - A growable array mapping from index to library. |
| 11304 const String& lib_url = String::Handle(zone, url()); | 11306 const String& lib_url = String::Handle(zone, url()); |
| 11305 ASSERT(Library::LookupLibrary(thread, lib_url) == Library::null()); | 11307 ASSERT(Library::LookupLibrary(thread, lib_url) == Library::null()); |
| 11306 ASSERT(lib_url.HasHash()); | 11308 ASSERT(lib_url.HasHash()); |
| 11307 GrowableObjectArray& libs = | 11309 GrowableObjectArray& libs = |
| 11308 GrowableObjectArray::Handle(zone, object_store->libraries()); | 11310 GrowableObjectArray::Handle(zone, object_store->libraries()); |
| 11309 ASSERT(!libs.IsNull()); | 11311 ASSERT(!libs.IsNull()); |
| 11310 set_index(libs.Length()); | 11312 set_index(libs.Length()); |
| 11311 libs.Add(*this); | 11313 libs.Add(*this, Heap::kOld); |
| 11312 | 11314 |
| 11313 // - A map from URL string to library. | 11315 // - A map from URL string to library. |
| 11314 if (object_store->libraries_map() == Array::null()) { | 11316 if (object_store->libraries_map() == Array::null()) { |
| 11315 LibraryLookupMap map(HashTables::New<LibraryLookupMap>(16, Heap::kOld)); | 11317 LibraryLookupMap map(HashTables::New<LibraryLookupMap>(16, Heap::kOld)); |
| 11316 object_store->set_libraries_map(map.Release()); | 11318 object_store->set_libraries_map(map.Release()); |
| 11317 } | 11319 } |
| 11318 | 11320 |
| 11319 LibraryLookupMap map(object_store->libraries_map()); | 11321 LibraryLookupMap map(object_store->libraries_map()); |
| 11320 bool present = map.UpdateOrInsert(lib_url, *this); | 11322 bool present = map.UpdateOrInsert(lib_url, *this); |
| 11321 ASSERT(!present); | 11323 ASSERT(!present); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11698 RawLibraryPrefix* LibraryPrefix::New(const String& name, | 11700 RawLibraryPrefix* LibraryPrefix::New(const String& name, |
| 11699 const Namespace& import, | 11701 const Namespace& import, |
| 11700 bool deferred_load, | 11702 bool deferred_load, |
| 11701 const Library& importer) { | 11703 const Library& importer) { |
| 11702 const LibraryPrefix& result = LibraryPrefix::Handle(LibraryPrefix::New()); | 11704 const LibraryPrefix& result = LibraryPrefix::Handle(LibraryPrefix::New()); |
| 11703 result.set_name(name); | 11705 result.set_name(name); |
| 11704 result.set_num_imports(0); | 11706 result.set_num_imports(0); |
| 11705 result.set_importer(importer); | 11707 result.set_importer(importer); |
| 11706 result.StoreNonPointer(&result.raw_ptr()->is_deferred_load_, deferred_load); | 11708 result.StoreNonPointer(&result.raw_ptr()->is_deferred_load_, deferred_load); |
| 11707 result.StoreNonPointer(&result.raw_ptr()->is_loaded_, !deferred_load); | 11709 result.StoreNonPointer(&result.raw_ptr()->is_loaded_, !deferred_load); |
| 11708 result.set_imports(Array::Handle(Array::New(kInitialSize))); | 11710 result.set_imports(Array::Handle(Array::New(kInitialSize, Heap::kOld))); |
| 11709 result.AddImport(import); | 11711 result.AddImport(import); |
| 11710 return result.raw(); | 11712 return result.raw(); |
| 11711 } | 11713 } |
| 11712 | 11714 |
| 11713 | 11715 |
| 11714 void LibraryPrefix::set_name(const String& value) const { | 11716 void LibraryPrefix::set_name(const String& value) const { |
| 11715 ASSERT(value.IsSymbol()); | 11717 ASSERT(value.IsSymbol()); |
| 11716 StorePointer(&raw_ptr()->name_, value.raw()); | 11718 StorePointer(&raw_ptr()->name_, value.raw()); |
| 11717 } | 11719 } |
| 11718 | 11720 |
| (...skipping 6446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18165 const String& declared_bound_name = | 18167 const String& declared_bound_name = |
| 18166 String::Handle(declared_bound.UserVisibleName()); | 18168 String::Handle(declared_bound.UserVisibleName()); |
| 18167 const String& type_param_name = String::Handle(UserVisibleName()); | 18169 const String& type_param_name = String::Handle(UserVisibleName()); |
| 18168 const Class& cls = Class::Handle(parameterized_class()); | 18170 const Class& cls = Class::Handle(parameterized_class()); |
| 18169 const String& class_name = String::Handle(cls.Name()); | 18171 const String& class_name = String::Handle(cls.Name()); |
| 18170 const Script& script = Script::Handle(cls.script()); | 18172 const Script& script = Script::Handle(cls.script()); |
| 18171 // Since the bound may have been canonicalized, its token index is | 18173 // Since the bound may have been canonicalized, its token index is |
| 18172 // meaningless, therefore use the token index of this type parameter. | 18174 // meaningless, therefore use the token index of this type parameter. |
| 18173 *bound_error = LanguageError::NewFormatted( | 18175 *bound_error = LanguageError::NewFormatted( |
| 18174 *bound_error, script, token_pos(), Report::AtLocation, | 18176 *bound_error, script, token_pos(), Report::AtLocation, |
| 18175 Report::kMalboundedType, Heap::kNew, | 18177 Report::kMalboundedType, Heap::kOld, |
| 18176 "type parameter '%s' of class '%s' must extend bound '%s', " | 18178 "type parameter '%s' of class '%s' must extend bound '%s', " |
| 18177 "but type argument '%s' is not a subtype of '%s' where\n%s%s", | 18179 "but type argument '%s' is not a subtype of '%s' where\n%s%s", |
| 18178 type_param_name.ToCString(), class_name.ToCString(), | 18180 type_param_name.ToCString(), class_name.ToCString(), |
| 18179 declared_bound_name.ToCString(), bounded_type_name.ToCString(), | 18181 declared_bound_name.ToCString(), bounded_type_name.ToCString(), |
| 18180 upper_bound_name.ToCString(), | 18182 upper_bound_name.ToCString(), |
| 18181 String::Handle(bounded_type.EnumerateURIs()).ToCString(), | 18183 String::Handle(bounded_type.EnumerateURIs()).ToCString(), |
| 18182 String::Handle(upper_bound.EnumerateURIs()).ToCString()); | 18184 String::Handle(upper_bound.EnumerateURIs()).ToCString()); |
| 18183 } | 18185 } |
| 18184 } | 18186 } |
| 18185 return false; | 18187 return false; |
| (...skipping 5169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 23355 return UserTag::null(); | 23357 return UserTag::null(); |
| 23356 } | 23358 } |
| 23357 | 23359 |
| 23358 | 23360 |
| 23359 const char* UserTag::ToCString() const { | 23361 const char* UserTag::ToCString() const { |
| 23360 const String& tag_label = String::Handle(label()); | 23362 const String& tag_label = String::Handle(label()); |
| 23361 return tag_label.ToCString(); | 23363 return tag_label.ToCString(); |
| 23362 } | 23364 } |
| 23363 | 23365 |
| 23364 } // namespace dart | 23366 } // namespace dart |
| OLD | NEW |