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/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1801 | 1801 |
1802 | 1802 |
1803 void Class::AddFunction(const Function& function) const { | 1803 void Class::AddFunction(const Function& function) const { |
1804 const Array& arr = Array::Handle(functions()); | 1804 const Array& arr = Array::Handle(functions()); |
1805 const Array& new_arr = Array::Handle(Array::Grow(arr, arr.Length() + 1)); | 1805 const Array& new_arr = Array::Handle(Array::Grow(arr, arr.Length() + 1)); |
1806 new_arr.SetAt(arr.Length(), function); | 1806 new_arr.SetAt(arr.Length(), function); |
1807 SetFunctions(new_arr); | 1807 SetFunctions(new_arr); |
1808 } | 1808 } |
1809 | 1809 |
1810 | 1810 |
| 1811 intptr_t Class::FindFunctionIndex(const Function& needle) const { |
| 1812 Isolate* isolate = Isolate::Current(); |
| 1813 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 1814 return -1; |
| 1815 } |
| 1816 ReusableHandleScope reused_handles(isolate); |
| 1817 Array& funcs = reused_handles.ArrayHandle(); |
| 1818 funcs ^= functions(); |
| 1819 ASSERT(!funcs.IsNull()); |
| 1820 Function& function = reused_handles.FunctionHandle(); |
| 1821 const intptr_t len = funcs.Length(); |
| 1822 for (intptr_t i = 0; i < len; i++) { |
| 1823 function ^= funcs.At(i); |
| 1824 if (function.raw() == needle.raw()) { |
| 1825 return i; |
| 1826 } |
| 1827 } |
| 1828 // No function found. |
| 1829 return -1; |
| 1830 } |
| 1831 |
| 1832 |
| 1833 RawFunction* Class::FunctionFromIndex(intptr_t idx) const { |
| 1834 const Array& funcs = Array::Handle(functions()); |
| 1835 if ((idx < 0) || (idx >= funcs.Length())) { |
| 1836 return Function::null(); |
| 1837 } |
| 1838 Function& func = Function::Handle(); |
| 1839 func ^= funcs.At(idx); |
| 1840 ASSERT(!func.IsNull()); |
| 1841 return func.raw(); |
| 1842 } |
| 1843 |
| 1844 |
| 1845 RawFunction* Class::ImplicitClosureFunctionFromIndex(intptr_t idx) const { |
| 1846 const Array& funcs = Array::Handle(functions()); |
| 1847 if ((idx < 0) || (idx >= funcs.Length())) { |
| 1848 return Function::null(); |
| 1849 } |
| 1850 Function& func = Function::Handle(); |
| 1851 func ^= funcs.At(idx); |
| 1852 ASSERT(!func.IsNull()); |
| 1853 if (!func.HasImplicitClosureFunction()) { |
| 1854 return Function::null(); |
| 1855 } |
| 1856 const Function& closure_func = |
| 1857 Function::Handle(func.ImplicitClosureFunction()); |
| 1858 ASSERT(!closure_func.IsNull()); |
| 1859 return closure_func.raw(); |
| 1860 } |
| 1861 |
| 1862 |
| 1863 intptr_t Class::FindImplicitClosureFunctionIndex(const Function& needle) const { |
| 1864 Isolate* isolate = Isolate::Current(); |
| 1865 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 1866 return -1; |
| 1867 } |
| 1868 ReusableHandleScope reused_handles(isolate); |
| 1869 Array& funcs = reused_handles.ArrayHandle(); |
| 1870 funcs ^= functions(); |
| 1871 ASSERT(!funcs.IsNull()); |
| 1872 Function& function = reused_handles.FunctionHandle(); |
| 1873 Function& implicit_closure = Function::Handle(); |
| 1874 const intptr_t len = funcs.Length(); |
| 1875 for (intptr_t i = 0; i < len; i++) { |
| 1876 function ^= funcs.At(i); |
| 1877 implicit_closure ^= function.implicit_closure_function(); |
| 1878 if (implicit_closure.IsNull()) { |
| 1879 // Skip non-implicit closure functions. |
| 1880 continue; |
| 1881 } |
| 1882 if (needle.raw() == implicit_closure.raw()) { |
| 1883 return i; |
| 1884 } |
| 1885 } |
| 1886 // No function found. |
| 1887 return -1; |
| 1888 } |
| 1889 |
| 1890 |
| 1891 |
| 1892 intptr_t Class::FindInvocationDispatcherFunctionIndex( |
| 1893 const Function& needle) const { |
| 1894 Isolate* isolate = Isolate::Current(); |
| 1895 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 1896 return -1; |
| 1897 } |
| 1898 ReusableHandleScope reused_handles(isolate); |
| 1899 Array& funcs = reused_handles.ArrayHandle(); |
| 1900 funcs ^= invocation_dispatcher_cache(); |
| 1901 ASSERT(!funcs.IsNull()); |
| 1902 Object& object = reused_handles.ObjectHandle(); |
| 1903 const intptr_t len = funcs.Length(); |
| 1904 for (intptr_t i = 0; i < len; i++) { |
| 1905 object = funcs.At(i); |
| 1906 // The invocation_dispatcher_cache is a table with some entries that |
| 1907 // are functions. |
| 1908 if (object.IsFunction()) { |
| 1909 if (Function::Cast(object).raw() == needle.raw()) { |
| 1910 return i; |
| 1911 } |
| 1912 } |
| 1913 } |
| 1914 // No function found. |
| 1915 return -1; |
| 1916 } |
| 1917 |
| 1918 |
| 1919 |
| 1920 RawFunction* Class::InvocationDispatcherFunctionFromIndex(intptr_t idx) const { |
| 1921 ReusableHandleScope reused_handles(Isolate::Current()); |
| 1922 Array& dispatcher_cache = reused_handles.ArrayHandle(); |
| 1923 dispatcher_cache ^= invocation_dispatcher_cache(); |
| 1924 Object& object = reused_handles.ObjectHandle(); |
| 1925 object = dispatcher_cache.At(idx); |
| 1926 if (!object.IsFunction()) { |
| 1927 return Function::null(); |
| 1928 } |
| 1929 return Function::Cast(object).raw(); |
| 1930 } |
| 1931 |
| 1932 |
1811 void Class::AddClosureFunction(const Function& function) const { | 1933 void Class::AddClosureFunction(const Function& function) const { |
1812 GrowableObjectArray& closures = | 1934 GrowableObjectArray& closures = |
1813 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); | 1935 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); |
1814 if (closures.IsNull()) { | 1936 if (closures.IsNull()) { |
1815 closures = GrowableObjectArray::New(4); | 1937 closures = GrowableObjectArray::New(4); |
1816 StorePointer(&raw_ptr()->closure_functions_, closures.raw()); | 1938 StorePointer(&raw_ptr()->closure_functions_, closures.raw()); |
1817 } | 1939 } |
1818 ASSERT(function.IsNonImplicitClosureFunction()); | 1940 ASSERT(function.IsNonImplicitClosureFunction()); |
1819 closures.Add(function); | 1941 closures.Add(function); |
1820 } | 1942 } |
(...skipping 20 matching lines...) Expand all Loading... |
1841 best_fit_token_pos = closure.token_pos(); | 1963 best_fit_token_pos = closure.token_pos(); |
1842 } | 1964 } |
1843 } | 1965 } |
1844 closure = Function::null(); | 1966 closure = Function::null(); |
1845 if (best_fit_index >= 0) { | 1967 if (best_fit_index >= 0) { |
1846 closure ^= closures.At(best_fit_index); | 1968 closure ^= closures.At(best_fit_index); |
1847 } | 1969 } |
1848 return closure.raw(); | 1970 return closure.raw(); |
1849 } | 1971 } |
1850 | 1972 |
| 1973 intptr_t Class::FindClosureIndex(const Function& needle) const { |
| 1974 if (closures() == GrowableObjectArray::null()) { |
| 1975 return -1; |
| 1976 } |
| 1977 Isolate* isolate = Isolate::Current(); |
| 1978 ReusableHandleScope reused_handles(isolate); |
| 1979 const GrowableObjectArray& closures_array = |
| 1980 GrowableObjectArray::Handle(isolate, closures()); |
| 1981 Function& closure = reused_handles.FunctionHandle(); |
| 1982 intptr_t num_closures = closures_array.Length(); |
| 1983 for (intptr_t i = 0; i < num_closures; i++) { |
| 1984 closure ^= closures_array.At(i); |
| 1985 ASSERT(!closure.IsNull()); |
| 1986 if (closure.raw() == needle.raw()) { |
| 1987 return i; |
| 1988 } |
| 1989 } |
| 1990 return -1; |
| 1991 } |
| 1992 |
| 1993 |
| 1994 RawFunction* Class::ClosureFunctionFromIndex(intptr_t idx) const { |
| 1995 const GrowableObjectArray& closures_array = |
| 1996 GrowableObjectArray::Handle(closures()); |
| 1997 if ((idx < 0) || (idx >= closures_array.Length())) { |
| 1998 return Function::null(); |
| 1999 } |
| 2000 Function& func = Function::Handle(); |
| 2001 func ^= closures_array.At(idx); |
| 2002 ASSERT(!func.IsNull()); |
| 2003 return func.raw(); |
| 2004 } |
| 2005 |
1851 | 2006 |
1852 void Class::set_signature_function(const Function& value) const { | 2007 void Class::set_signature_function(const Function& value) const { |
1853 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); | 2008 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); |
1854 StorePointer(&raw_ptr()->signature_function_, value.raw()); | 2009 StorePointer(&raw_ptr()->signature_function_, value.raw()); |
1855 } | 2010 } |
1856 | 2011 |
1857 | 2012 |
1858 void Class::set_state_bits(intptr_t bits) const { | 2013 void Class::set_state_bits(intptr_t bits) const { |
1859 raw_ptr()->state_bits_ = static_cast<uint16_t>(bits); | 2014 raw_ptr()->state_bits_ = static_cast<uint16_t>(bits); |
1860 } | 2015 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1978 } | 2133 } |
1979 // Calling NumOwnTypeArguments() on a mixin application class will setup the | 2134 // Calling NumOwnTypeArguments() on a mixin application class will setup the |
1980 // type parameters if not already done. | 2135 // type parameters if not already done. |
1981 num_type_args += cls.NumOwnTypeArguments(); | 2136 num_type_args += cls.NumOwnTypeArguments(); |
1982 // Super type of Object class is null. | 2137 // Super type of Object class is null. |
1983 if ((cls.super_type() == AbstractType::null()) || | 2138 if ((cls.super_type() == AbstractType::null()) || |
1984 (cls.super_type() == isolate->object_store()->object_type())) { | 2139 (cls.super_type() == isolate->object_store()->object_type())) { |
1985 break; | 2140 break; |
1986 } | 2141 } |
1987 sup_type = cls.super_type(); | 2142 sup_type = cls.super_type(); |
| 2143 ClassFinalizer::ResolveType(cls, sup_type); |
1988 cls = sup_type.type_class(); | 2144 cls = sup_type.type_class(); |
1989 } while (true); | 2145 } while (true); |
1990 set_num_type_arguments(num_type_args); | 2146 set_num_type_arguments(num_type_args); |
1991 return num_type_args; | 2147 return num_type_args; |
1992 } | 2148 } |
1993 | 2149 |
1994 | 2150 |
1995 RawClass* Class::SuperClass() const { | 2151 RawClass* Class::SuperClass() const { |
1996 if (super_type() == AbstractType::null()) { | 2152 if (super_type() == AbstractType::null()) { |
1997 return Class::null(); | 2153 return Class::null(); |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2392 for (intptr_t i = 0; i < len; i++) { | 2548 for (intptr_t i = 0; i < len; i++) { |
2393 field ^= value.At(i); | 2549 field ^= value.At(i); |
2394 ASSERT(field.owner() == raw()); | 2550 ASSERT(field.owner() == raw()); |
2395 } | 2551 } |
2396 #endif | 2552 #endif |
2397 // The value of static fields is already initialized to null. | 2553 // The value of static fields is already initialized to null. |
2398 StorePointer(&raw_ptr()->fields_, value.raw()); | 2554 StorePointer(&raw_ptr()->fields_, value.raw()); |
2399 } | 2555 } |
2400 | 2556 |
2401 | 2557 |
| 2558 intptr_t Class::FindFieldIndex(const Field& needle) const { |
| 2559 Isolate* isolate = Isolate::Current(); |
| 2560 if (EnsureIsFinalized(isolate) != Error::null()) { |
| 2561 return -1; |
| 2562 } |
| 2563 ReusableHandleScope reused_handles(isolate); |
| 2564 Array& fields_array = reused_handles.ArrayHandle(); |
| 2565 fields_array ^= fields(); |
| 2566 ASSERT(!fields_array.IsNull()); |
| 2567 Field& field = reused_handles.FieldHandle(); |
| 2568 String& field_name = reused_handles.StringHandle(); |
| 2569 String& needle_name = String::Handle(isolate); |
| 2570 needle_name ^= needle.name(); |
| 2571 const intptr_t len = fields_array.Length(); |
| 2572 for (intptr_t i = 0; i < len; i++) { |
| 2573 field ^= fields_array.At(i); |
| 2574 field_name ^= field.name(); |
| 2575 if (field_name.Equals(needle_name)) { |
| 2576 return i; |
| 2577 } |
| 2578 } |
| 2579 // No field found. |
| 2580 return -1; |
| 2581 } |
| 2582 |
| 2583 |
| 2584 RawField* Class::FieldFromIndex(intptr_t idx) const { |
| 2585 const Array& flds = Array::Handle(fields()); |
| 2586 if ((idx < 0) || (idx >= flds.Length())) { |
| 2587 return Field::null(); |
| 2588 } |
| 2589 Field& field = Field::Handle(); |
| 2590 field ^= flds.At(idx); |
| 2591 ASSERT(!field.IsNull()); |
| 2592 return field.raw(); |
| 2593 } |
| 2594 |
| 2595 |
2402 template <class FakeInstance> | 2596 template <class FakeInstance> |
2403 RawClass* Class::New(intptr_t index) { | 2597 RawClass* Class::New(intptr_t index) { |
2404 ASSERT(Object::class_class() != Class::null()); | 2598 ASSERT(Object::class_class() != Class::null()); |
2405 Class& result = Class::Handle(); | 2599 Class& result = Class::Handle(); |
2406 { | 2600 { |
2407 RawObject* raw = Object::Allocate(Class::kClassId, | 2601 RawObject* raw = Object::Allocate(Class::kClassId, |
2408 Class::InstanceSize(), | 2602 Class::InstanceSize(), |
2409 Heap::kOld); | 2603 Heap::kOld); |
2410 NoGCScope no_gc; | 2604 NoGCScope no_gc; |
2411 result ^= raw; | 2605 result ^= raw; |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3241 void Class::PrintToJSONStream(JSONStream* stream, bool ref) const { | 3435 void Class::PrintToJSONStream(JSONStream* stream, bool ref) const { |
3242 JSONObject jsobj(stream); | 3436 JSONObject jsobj(stream); |
3243 if ((raw() == Class::null()) || (id() == kFreeListElement)) { | 3437 if ((raw() == Class::null()) || (id() == kFreeListElement)) { |
3244 jsobj.AddProperty("type", "Null"); | 3438 jsobj.AddProperty("type", "Null"); |
3245 return; | 3439 return; |
3246 } | 3440 } |
3247 const char* internal_class_name = String::Handle(Name()).ToCString(); | 3441 const char* internal_class_name = String::Handle(Name()).ToCString(); |
3248 const char* user_visible_class_name = | 3442 const char* user_visible_class_name = |
3249 String::Handle(UserVisibleName()).ToCString(); | 3443 String::Handle(UserVisibleName()).ToCString(); |
3250 jsobj.AddProperty("type", JSONType(ref)); | 3444 jsobj.AddProperty("type", JSONType(ref)); |
3251 jsobj.AddProperty("id", id()); | 3445 jsobj.AddPropertyF("id", "classes/%" Pd "", id()); |
3252 jsobj.AddProperty("name", internal_class_name); | 3446 jsobj.AddProperty("name", internal_class_name); |
3253 jsobj.AddProperty("user_name", user_visible_class_name); | 3447 jsobj.AddProperty("user_name", user_visible_class_name); |
3254 if (!ref) { | 3448 if (!ref) { |
3255 const Error& err = Error::Handle(EnsureIsFinalized(Isolate::Current())); | 3449 const Error& err = Error::Handle(EnsureIsFinalized(Isolate::Current())); |
3256 if (!err.IsNull()) { | 3450 if (!err.IsNull()) { |
3257 jsobj.AddProperty("error", err); | 3451 jsobj.AddProperty("error", err); |
3258 } | 3452 } |
3259 jsobj.AddProperty("implemented", is_implemented()); | 3453 jsobj.AddProperty("implemented", is_implemented()); |
3260 jsobj.AddProperty("abstract", is_abstract()); | 3454 jsobj.AddProperty("abstract", is_abstract()); |
3261 jsobj.AddProperty("patch", is_patch()); | 3455 jsobj.AddProperty("patch", is_patch()); |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4004 | 4198 |
4005 | 4199 |
4006 void InstantiatedTypeArguments::SetTypeAt(intptr_t index, | 4200 void InstantiatedTypeArguments::SetTypeAt(intptr_t index, |
4007 const AbstractType& value) const { | 4201 const AbstractType& value) const { |
4008 // We only replace individual argument types during resolution at compile | 4202 // We only replace individual argument types during resolution at compile |
4009 // time, when no type parameters are instantiated yet. | 4203 // time, when no type parameters are instantiated yet. |
4010 UNREACHABLE(); | 4204 UNREACHABLE(); |
4011 } | 4205 } |
4012 | 4206 |
4013 | 4207 |
| 4208 RawAbstractTypeArguments* InstantiatedTypeArguments::Canonicalize() const { |
| 4209 const intptr_t num_types = Length(); |
| 4210 const TypeArguments& type_args = TypeArguments::Handle( |
| 4211 TypeArguments::New(num_types, Heap::kOld)); |
| 4212 AbstractType& type = AbstractType::Handle(); |
| 4213 for (intptr_t i = 0; i < num_types; i++) { |
| 4214 type = TypeAt(i); |
| 4215 type_args.SetTypeAt(i, type); |
| 4216 } |
| 4217 return type_args.Canonicalize(); |
| 4218 } |
| 4219 |
| 4220 |
4014 void InstantiatedTypeArguments::set_uninstantiated_type_arguments( | 4221 void InstantiatedTypeArguments::set_uninstantiated_type_arguments( |
4015 const AbstractTypeArguments& value) const { | 4222 const AbstractTypeArguments& value) const { |
4016 StorePointer(&raw_ptr()->uninstantiated_type_arguments_, value.raw()); | 4223 StorePointer(&raw_ptr()->uninstantiated_type_arguments_, value.raw()); |
4017 } | 4224 } |
4018 | 4225 |
4019 | 4226 |
4020 void InstantiatedTypeArguments::set_instantiator_type_arguments( | 4227 void InstantiatedTypeArguments::set_instantiator_type_arguments( |
4021 const AbstractTypeArguments& value) const { | 4228 const AbstractTypeArguments& value) const { |
4022 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw()); | 4229 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw()); |
4023 } | 4230 } |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4353 | 4560 |
4354 | 4561 |
4355 RawType* Function::RedirectionType() const { | 4562 RawType* Function::RedirectionType() const { |
4356 ASSERT(IsRedirectingFactory()); | 4563 ASSERT(IsRedirectingFactory()); |
4357 const Object& obj = Object::Handle(raw_ptr()->data_); | 4564 const Object& obj = Object::Handle(raw_ptr()->data_); |
4358 ASSERT(!obj.IsNull()); | 4565 ASSERT(!obj.IsNull()); |
4359 return RedirectionData::Cast(obj).type(); | 4566 return RedirectionData::Cast(obj).type(); |
4360 } | 4567 } |
4361 | 4568 |
4362 | 4569 |
| 4570 const char* Function::KindToCString(RawFunction::Kind kind) { |
| 4571 switch (kind) { |
| 4572 case RawFunction::kRegularFunction: |
| 4573 return "kRegularFunction"; |
| 4574 break; |
| 4575 case RawFunction::kClosureFunction: |
| 4576 return "kClosureFunction"; |
| 4577 break; |
| 4578 case RawFunction::kSignatureFunction: |
| 4579 return "kSignatureFunction"; |
| 4580 break; |
| 4581 case RawFunction::kGetterFunction: |
| 4582 return "kGetterFunction"; |
| 4583 break; |
| 4584 case RawFunction::kSetterFunction: |
| 4585 return "kSetterFunction"; |
| 4586 break; |
| 4587 case RawFunction::kConstructor: |
| 4588 return "kConstructor"; |
| 4589 break; |
| 4590 case RawFunction::kImplicitGetter: |
| 4591 return "kImplicitGetter"; |
| 4592 break; |
| 4593 case RawFunction::kImplicitSetter: |
| 4594 return "kImplicitSetter"; |
| 4595 break; |
| 4596 case RawFunction::kImplicitStaticFinalGetter: |
| 4597 return "kImplicitStaticFinalGetter"; |
| 4598 break; |
| 4599 case RawFunction::kStaticInitializer: |
| 4600 return "kStaticInitializer"; |
| 4601 break; |
| 4602 case RawFunction::kMethodExtractor: |
| 4603 return "kMethodExtractor"; |
| 4604 break; |
| 4605 case RawFunction::kNoSuchMethodDispatcher: |
| 4606 return "kNoSuchMethodDispatcher"; |
| 4607 break; |
| 4608 case RawFunction::kInvokeFieldDispatcher: |
| 4609 return "kInvokeFieldDispatcher"; |
| 4610 break; |
| 4611 default: |
| 4612 UNREACHABLE(); |
| 4613 return NULL; |
| 4614 } |
| 4615 } |
| 4616 |
| 4617 |
4363 void Function::SetRedirectionType(const Type& type) const { | 4618 void Function::SetRedirectionType(const Type& type) const { |
4364 ASSERT(IsFactory()); | 4619 ASSERT(IsFactory()); |
4365 Object& obj = Object::Handle(raw_ptr()->data_); | 4620 Object& obj = Object::Handle(raw_ptr()->data_); |
4366 if (obj.IsNull()) { | 4621 if (obj.IsNull()) { |
4367 obj = RedirectionData::New(); | 4622 obj = RedirectionData::New(); |
4368 set_data(obj); | 4623 set_data(obj); |
4369 } | 4624 } |
4370 RedirectionData::Cast(obj).set_type(type); | 4625 RedirectionData::Cast(obj).set_type(type); |
4371 } | 4626 } |
4372 | 4627 |
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5612 OS::SNPrint(chars, len, kFormat, function_name, | 5867 OS::SNPrint(chars, len, kFormat, function_name, |
5613 static_str, abstract_str, kind_str, const_str); | 5868 static_str, abstract_str, kind_str, const_str); |
5614 return chars; | 5869 return chars; |
5615 } | 5870 } |
5616 | 5871 |
5617 | 5872 |
5618 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { | 5873 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { |
5619 const char* internal_function_name = String::Handle(name()).ToCString(); | 5874 const char* internal_function_name = String::Handle(name()).ToCString(); |
5620 const char* function_name = | 5875 const char* function_name = |
5621 String::Handle(QualifiedUserVisibleName()).ToCString(); | 5876 String::Handle(QualifiedUserVisibleName()).ToCString(); |
5622 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 5877 Class& cls = Class::Handle(Owner()); |
5623 intptr_t id = ring->GetIdForObject(raw()); | 5878 ASSERT(!cls.IsNull()); |
| 5879 Error& err = Error::Handle(); |
| 5880 err ^= cls.EnsureIsFinalized(Isolate::Current()); |
| 5881 ASSERT(err.IsNull()); |
| 5882 intptr_t id = -1; |
| 5883 const char* selector = NULL; |
| 5884 if (IsNonImplicitClosureFunction()) { |
| 5885 id = cls.FindClosureIndex(*this); |
| 5886 selector = "closures"; |
| 5887 } else if (IsImplicitClosureFunction()) { |
| 5888 id = cls.FindImplicitClosureFunctionIndex(*this); |
| 5889 selector = "implicit_closures"; |
| 5890 } else if (IsNoSuchMethodDispatcher() || IsInvokeFieldDispatcher()) { |
| 5891 id = cls.FindInvocationDispatcherFunctionIndex(*this); |
| 5892 selector = "dispatchers"; |
| 5893 } else { |
| 5894 id = cls.FindFunctionIndex(*this); |
| 5895 selector = "functions"; |
| 5896 } |
| 5897 ASSERT(id >= 0); |
| 5898 intptr_t cid = cls.id(); |
5624 JSONObject jsobj(stream); | 5899 JSONObject jsobj(stream); |
5625 jsobj.AddProperty("type", JSONType(ref)); | 5900 jsobj.AddProperty("type", JSONType(ref)); |
5626 jsobj.AddProperty("id", id); | 5901 jsobj.AddPropertyF("id", "classes/%" Pd "/%s/%" Pd "", cid, selector, id); |
5627 jsobj.AddProperty("name", internal_function_name); | 5902 jsobj.AddProperty("name", internal_function_name); |
5628 jsobj.AddProperty("user_name", function_name); | 5903 jsobj.AddProperty("user_name", function_name); |
5629 if (ref) return; | 5904 if (ref) return; |
5630 jsobj.AddProperty("is_static", is_static()); | 5905 jsobj.AddProperty("is_static", is_static()); |
5631 jsobj.AddProperty("is_const", is_const()); | 5906 jsobj.AddProperty("is_const", is_const()); |
5632 jsobj.AddProperty("is_optimizable", is_optimizable()); | 5907 jsobj.AddProperty("is_optimizable", is_optimizable()); |
5633 jsobj.AddProperty("is_inlinable", IsInlineable()); | 5908 jsobj.AddProperty("is_inlinable", IsInlineable()); |
5634 const char* kind_string = NULL; | 5909 const char* kind_string = Function::KindToCString(kind()); |
5635 switch (kind()) { | |
5636 case RawFunction::kRegularFunction: | |
5637 kind_string = "regular"; | |
5638 break; | |
5639 case RawFunction::kGetterFunction: | |
5640 kind_string = "getter"; | |
5641 break; | |
5642 case RawFunction::kSetterFunction: | |
5643 kind_string = "setter"; | |
5644 break; | |
5645 case RawFunction::kImplicitGetter: | |
5646 kind_string = "implicit getter"; | |
5647 break; | |
5648 case RawFunction::kImplicitSetter: | |
5649 kind_string = "implicit setter"; | |
5650 break; | |
5651 case RawFunction::kMethodExtractor: | |
5652 kind_string = "method extractor"; | |
5653 break; | |
5654 case RawFunction::kNoSuchMethodDispatcher: | |
5655 kind_string = "no such method"; | |
5656 break; | |
5657 case RawFunction::kClosureFunction: | |
5658 kind_string = "closure"; | |
5659 break; | |
5660 case RawFunction::kConstructor: | |
5661 kind_string = "constructor"; | |
5662 break; | |
5663 case RawFunction::kStaticInitializer: | |
5664 kind_string = "static initializer"; | |
5665 break; | |
5666 case RawFunction::kImplicitStaticFinalGetter: | |
5667 kind_string = "static final getter"; | |
5668 break; | |
5669 default: | |
5670 UNREACHABLE(); | |
5671 } | |
5672 jsobj.AddProperty("kind", kind_string); | 5910 jsobj.AddProperty("kind", kind_string); |
5673 jsobj.AddProperty("unoptimized_code", Object::Handle(unoptimized_code())); | 5911 jsobj.AddProperty("unoptimized_code", Object::Handle(unoptimized_code())); |
5674 jsobj.AddProperty("usage_counter", usage_counter()); | 5912 jsobj.AddProperty("usage_counter", usage_counter()); |
5675 jsobj.AddProperty("optimized_call_site_count", optimized_call_site_count()); | 5913 jsobj.AddProperty("optimized_call_site_count", optimized_call_site_count()); |
5676 jsobj.AddProperty("code", Object::Handle(CurrentCode())); | 5914 jsobj.AddProperty("code", Object::Handle(CurrentCode())); |
5677 jsobj.AddProperty("deoptimizations", | 5915 jsobj.AddProperty("deoptimizations", |
5678 static_cast<intptr_t>(deoptimization_counter())); | 5916 static_cast<intptr_t>(deoptimization_counter())); |
5679 } | 5917 } |
5680 | 5918 |
5681 | 5919 |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5945 PrintToJSONStreamWithInstance(stream, Object::null_instance(), ref); | 6183 PrintToJSONStreamWithInstance(stream, Object::null_instance(), ref); |
5946 } | 6184 } |
5947 | 6185 |
5948 | 6186 |
5949 void Field::PrintToJSONStreamWithInstance(JSONStream* stream, | 6187 void Field::PrintToJSONStreamWithInstance(JSONStream* stream, |
5950 const Instance& instance, | 6188 const Instance& instance, |
5951 bool ref) const { | 6189 bool ref) const { |
5952 JSONObject jsobj(stream); | 6190 JSONObject jsobj(stream); |
5953 const char* internal_field_name = String::Handle(name()).ToCString(); | 6191 const char* internal_field_name = String::Handle(name()).ToCString(); |
5954 const char* field_name = String::Handle(UserVisibleName()).ToCString(); | 6192 const char* field_name = String::Handle(UserVisibleName()).ToCString(); |
5955 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 6193 Class& cls = Class::Handle(owner()); |
5956 intptr_t id = ring->GetIdForObject(raw()); | 6194 intptr_t id = cls.FindFieldIndex(*this); |
| 6195 ASSERT(id >= 0); |
| 6196 intptr_t cid = cls.id(); |
5957 jsobj.AddProperty("type", JSONType(ref)); | 6197 jsobj.AddProperty("type", JSONType(ref)); |
5958 jsobj.AddProperty("id", id); | 6198 jsobj.AddPropertyF("id", "classes/%" Pd "/fields/%" Pd "", cid, id); |
5959 jsobj.AddProperty("name", internal_field_name); | 6199 jsobj.AddProperty("name", internal_field_name); |
5960 jsobj.AddProperty("user_name", field_name); | 6200 jsobj.AddProperty("user_name", field_name); |
5961 if (is_static()) { | 6201 if (is_static()) { |
5962 const Object& valueObj = Object::Handle(value()); | 6202 const Object& valueObj = Object::Handle(value()); |
5963 jsobj.AddProperty("value", valueObj); | 6203 jsobj.AddProperty("value", valueObj); |
5964 } else if (!instance.IsNull()) { | 6204 } else if (!instance.IsNull()) { |
5965 const Object& valueObj = Object::Handle(instance.GetField(*this)); | 6205 const Object& valueObj = Object::Handle(instance.GetField(*this)); |
5966 jsobj.AddProperty("value", valueObj); | 6206 jsobj.AddProperty("value", valueObj); |
5967 } | 6207 } |
5968 Class& cls = Class::Handle(owner()); | 6208 |
5969 jsobj.AddProperty("owner", cls); | 6209 jsobj.AddProperty("owner", cls); |
5970 AbstractType& declared_type = AbstractType::Handle(type()); | 6210 AbstractType& declared_type = AbstractType::Handle(type()); |
5971 cls = declared_type.type_class(); | 6211 cls = declared_type.type_class(); |
5972 jsobj.AddProperty("declared_type", cls); | 6212 jsobj.AddProperty("declared_type", cls); |
5973 jsobj.AddProperty("static", is_static()); | 6213 jsobj.AddProperty("static", is_static()); |
5974 jsobj.AddProperty("final", is_final()); | 6214 jsobj.AddProperty("final", is_final()); |
5975 jsobj.AddProperty("const", is_const()); | 6215 jsobj.AddProperty("const", is_const()); |
5976 if (ref) { | 6216 if (ref) { |
5977 return; | 6217 return; |
5978 } | 6218 } |
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7112 } | 7352 } |
7113 | 7353 |
7114 | 7354 |
7115 const char* Script::ToCString() const { | 7355 const char* Script::ToCString() const { |
7116 return "Script"; | 7356 return "Script"; |
7117 } | 7357 } |
7118 | 7358 |
7119 | 7359 |
7120 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const { | 7360 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const { |
7121 JSONObject jsobj(stream); | 7361 JSONObject jsobj(stream); |
7122 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | |
7123 intptr_t id = ring->GetIdForObject(raw()); | |
7124 jsobj.AddProperty("type", JSONType(ref)); | 7362 jsobj.AddProperty("type", JSONType(ref)); |
7125 jsobj.AddProperty("id", id); | |
7126 const String& name = String::Handle(url()); | 7363 const String& name = String::Handle(url()); |
| 7364 ASSERT(!name.IsNull()); |
| 7365 const String& encoded_url = String::Handle(String::EncodeURI(name)); |
| 7366 ASSERT(!encoded_url.IsNull()); |
| 7367 jsobj.AddPropertyF("id", "scripts/%s", encoded_url.ToCString()); |
7127 jsobj.AddProperty("name", name.ToCString()); | 7368 jsobj.AddProperty("name", name.ToCString()); |
| 7369 jsobj.AddProperty("user_name", name.ToCString()); |
7128 jsobj.AddProperty("kind", GetKindAsCString()); | 7370 jsobj.AddProperty("kind", GetKindAsCString()); |
7129 if (ref) { | 7371 if (ref) { |
7130 return; | 7372 return; |
7131 } | 7373 } |
7132 const String& source = String::Handle(Source()); | 7374 const String& source = String::Handle(Source()); |
7133 jsobj.AddProperty("source", source.ToCString()); | 7375 jsobj.AddProperty("source", source.ToCString()); |
7134 } | 7376 } |
7135 | 7377 |
7136 | 7378 |
7137 DictionaryIterator::DictionaryIterator(const Library& library) | 7379 DictionaryIterator::DictionaryIterator(const Library& library) |
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8186 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; | 8428 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; |
8187 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 8429 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
8188 OS::SNPrint(chars, len, kFormat, name.ToCString()); | 8430 OS::SNPrint(chars, len, kFormat, name.ToCString()); |
8189 return chars; | 8431 return chars; |
8190 } | 8432 } |
8191 | 8433 |
8192 | 8434 |
8193 void Library::PrintToJSONStream(JSONStream* stream, bool ref) const { | 8435 void Library::PrintToJSONStream(JSONStream* stream, bool ref) const { |
8194 const char* library_name = String::Handle(name()).ToCString(); | 8436 const char* library_name = String::Handle(name()).ToCString(); |
8195 const char* library_url = String::Handle(url()).ToCString(); | 8437 const char* library_url = String::Handle(url()).ToCString(); |
8196 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 8438 intptr_t id = index(); |
8197 intptr_t id = ring->GetIdForObject(raw()); | 8439 ASSERT(id >= 0); |
8198 JSONObject jsobj(stream); | 8440 JSONObject jsobj(stream); |
8199 jsobj.AddProperty("type", JSONType(ref)); | 8441 jsobj.AddProperty("type", JSONType(ref)); |
8200 jsobj.AddProperty("id", id); | 8442 jsobj.AddPropertyF("id", "libraries/%" Pd "", id); |
8201 jsobj.AddProperty("name", library_name); | 8443 jsobj.AddProperty("name", library_name); |
8202 jsobj.AddProperty("url", library_url); | 8444 jsobj.AddProperty("user_name", library_url); |
8203 if (ref) return; | 8445 if (ref) return; |
8204 { | 8446 { |
8205 JSONArray jsarr(&jsobj, "classes"); | 8447 JSONArray jsarr(&jsobj, "classes"); |
8206 ClassDictionaryIterator class_iter(*this); | 8448 ClassDictionaryIterator class_iter(*this); |
8207 Class& klass = Class::Handle(); | 8449 Class& klass = Class::Handle(); |
8208 while (class_iter.HasNext()) { | 8450 while (class_iter.HasNext()) { |
8209 klass = class_iter.GetNextClass(); | 8451 klass = class_iter.GetNextClass(); |
8210 if (!klass.IsCanonicalSignatureClass() && | 8452 if (!klass.IsCanonicalSignatureClass() && |
8211 !klass.IsAnonymousMixinApplication()) { | 8453 !klass.IsAnonymousMixinApplication()) { |
8212 jsarr.AddValue(klass); | 8454 jsarr.AddValue(klass); |
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9574 const intptr_t i = BinarySearchInSCallTable(pc); | 9816 const intptr_t i = BinarySearchInSCallTable(pc); |
9575 ASSERT(i >= 0); | 9817 ASSERT(i >= 0); |
9576 const Array& array = | 9818 const Array& array = |
9577 Array::Handle(raw_ptr()->static_calls_target_table_); | 9819 Array::Handle(raw_ptr()->static_calls_target_table_); |
9578 ASSERT(code.IsNull() || | 9820 ASSERT(code.IsNull() || |
9579 (code.function() == array.At(i + kSCallTableFunctionEntry))); | 9821 (code.function() == array.At(i + kSCallTableFunctionEntry))); |
9580 array.SetAt(i + kSCallTableCodeEntry, code); | 9822 array.SetAt(i + kSCallTableCodeEntry, code); |
9581 } | 9823 } |
9582 | 9824 |
9583 | 9825 |
9584 void Code::Disassemble() const { | 9826 void Code::Disassemble(DisassemblyFormatter* formatter) const { |
| 9827 const bool fix_patch = CodePatcher::CodeIsPatchable(*this) && |
| 9828 CodePatcher::IsEntryPatched(*this); |
| 9829 if (fix_patch) { |
| 9830 // The disassembler may choke on illegal instructions if the code has been |
| 9831 // patched, un-patch the code before disassembling and re-patch after. |
| 9832 CodePatcher::RestoreEntry(*this); |
| 9833 } |
9585 const Instructions& instr = Instructions::Handle(instructions()); | 9834 const Instructions& instr = Instructions::Handle(instructions()); |
9586 uword start = instr.EntryPoint(); | 9835 uword start = instr.EntryPoint(); |
9587 Disassembler::Disassemble(start, start + instr.size(), comments()); | 9836 if (formatter == NULL) { |
| 9837 Disassembler::Disassemble(start, start + instr.size(), comments()); |
| 9838 } else { |
| 9839 Disassembler::Disassemble(start, start + instr.size(), formatter, |
| 9840 comments()); |
| 9841 } |
| 9842 if (fix_patch) { |
| 9843 // Redo the patch. |
| 9844 CodePatcher::PatchEntry(*this); |
| 9845 } |
9588 } | 9846 } |
9589 | 9847 |
9590 | 9848 |
9591 const Code::Comments& Code::comments() const { | 9849 const Code::Comments& Code::comments() const { |
9592 Comments* comments = new Code::Comments(Array::Handle(raw_ptr()->comments_)); | 9850 Comments* comments = new Code::Comments(Array::Handle(raw_ptr()->comments_)); |
9593 return *comments; | 9851 return *comments; |
9594 } | 9852 } |
9595 | 9853 |
9596 | 9854 |
9597 void Code::set_comments(const Code::Comments& comments) const { | 9855 void Code::set_comments(const Code::Comments& comments) const { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9689 return FinalizeCode(function.ToFullyQualifiedCString(), | 9947 return FinalizeCode(function.ToFullyQualifiedCString(), |
9690 assembler, | 9948 assembler, |
9691 optimized); | 9949 optimized); |
9692 } else { | 9950 } else { |
9693 return FinalizeCode("", assembler); | 9951 return FinalizeCode("", assembler); |
9694 } | 9952 } |
9695 } | 9953 } |
9696 | 9954 |
9697 | 9955 |
9698 // Check if object matches find condition. | 9956 // Check if object matches find condition. |
9699 bool Code::FindRawCodeVisitor::FindObject(RawObject* obj) { | 9957 bool Code::FindRawCodeVisitor::FindObject(RawObject* obj) const { |
9700 return RawInstructions::ContainsPC(obj, pc_); | 9958 return RawInstructions::ContainsPC(obj, pc_); |
9701 } | 9959 } |
9702 | 9960 |
9703 | 9961 |
9704 RawCode* Code::LookupCode(uword pc) { | 9962 RawCode* Code::LookupCode(uword pc) { |
9705 Isolate* isolate = Isolate::Current(); | 9963 Isolate* isolate = Isolate::Current(); |
9706 NoGCScope no_gc; | 9964 NoGCScope no_gc; |
9707 FindRawCodeVisitor visitor(pc); | 9965 FindRawCodeVisitor visitor(pc); |
9708 RawInstructions* instr; | 9966 RawInstructions* instr; |
9709 if (isolate->heap() == NULL) { | 9967 if (isolate->heap() == NULL) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9759 const char* Code::ToCString() const { | 10017 const char* Code::ToCString() const { |
9760 const char* kFormat = "Code entry:%p"; | 10018 const char* kFormat = "Code entry:%p"; |
9761 intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint()) + 1; | 10019 intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint()) + 1; |
9762 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 10020 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
9763 OS::SNPrint(chars, len, kFormat, EntryPoint()); | 10021 OS::SNPrint(chars, len, kFormat, EntryPoint()); |
9764 return chars; | 10022 return chars; |
9765 } | 10023 } |
9766 | 10024 |
9767 | 10025 |
9768 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const { | 10026 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const { |
9769 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | |
9770 intptr_t id = ring->GetIdForObject(raw()); | |
9771 JSONObject jsobj(stream); | 10027 JSONObject jsobj(stream); |
| 10028 jsobj.AddProperty("type", JSONType(ref)); |
| 10029 jsobj.AddPropertyF("id", "code/%" Px "", EntryPoint()); |
| 10030 jsobj.AddPropertyF("start", "%" Px "", EntryPoint()); |
| 10031 jsobj.AddPropertyF("end", "%" Px "", EntryPoint() + Size()); |
| 10032 Function& func = Function::Handle(); |
| 10033 func ^= function(); |
| 10034 ASSERT(!func.IsNull()); |
| 10035 String& name = String::Handle(); |
| 10036 ASSERT(!func.IsNull()); |
| 10037 name ^= func.name(); |
| 10038 const char* internal_function_name = name.ToCString(); |
| 10039 jsobj.AddPropertyF("name", "%s%s", is_optimized() ? "*" : "", |
| 10040 internal_function_name); |
| 10041 name ^= func.QualifiedUserVisibleName(); |
| 10042 const char* function_name = name.ToCString(); |
| 10043 jsobj.AddPropertyF("user_name", "%s%s", is_optimized() ? "*" : "", |
| 10044 function_name); |
9772 if (ref) { | 10045 if (ref) { |
9773 jsobj.AddProperty("type", "@Code"); | |
9774 jsobj.AddProperty("id", id); | |
9775 return; | 10046 return; |
9776 } | 10047 } |
9777 jsobj.AddProperty("type", "Code"); | |
9778 jsobj.AddProperty("id", id); | |
9779 jsobj.AddProperty("is_optimized", is_optimized()); | 10048 jsobj.AddProperty("is_optimized", is_optimized()); |
9780 jsobj.AddProperty("is_alive", is_alive()); | 10049 jsobj.AddProperty("is_alive", is_alive()); |
9781 jsobj.AddProperty("function", Object::Handle(function())); | 10050 jsobj.AddProperty("function", Object::Handle(function())); |
9782 JSONArray jsarr(&jsobj, "disassembly"); | 10051 JSONArray jsarr(&jsobj, "disassembly"); |
9783 DisassembleToJSONStream formatter(jsarr); | 10052 DisassembleToJSONStream formatter(jsarr); |
9784 const Instructions& instr = Instructions::Handle(instructions()); | 10053 Disassemble(&formatter); |
9785 uword start = instr.EntryPoint(); | |
9786 Disassembler::Disassemble(start, start + instr.size(), &formatter, | |
9787 comments()); | |
9788 } | 10054 } |
9789 | 10055 |
9790 | 10056 |
9791 uword Code::GetPatchCodePc() const { | 10057 uword Code::GetPatchCodePc() const { |
9792 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors()); | 10058 const PcDescriptors& descriptors = PcDescriptors::Handle(pc_descriptors()); |
9793 return descriptors.GetPcForKind(PcDescriptors::kPatchCode); | 10059 return descriptors.GetPcForKind(PcDescriptors::kPatchCode); |
9794 } | 10060 } |
9795 | 10061 |
9796 | 10062 |
9797 uword Code::GetLazyDeoptPc() const { | 10063 uword Code::GetLazyDeoptPc() const { |
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11470 } | 11736 } |
11471 } | 11737 } |
11472 | 11738 |
11473 | 11739 |
11474 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11740 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { |
11475 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 11741 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
11476 intptr_t id = ring->GetIdForObject(raw()); | 11742 intptr_t id = ring->GetIdForObject(raw()); |
11477 | 11743 |
11478 JSONObject jsobj(stream); | 11744 JSONObject jsobj(stream); |
11479 jsobj.AddProperty("type", JSONType(ref)); | 11745 jsobj.AddProperty("type", JSONType(ref)); |
11480 jsobj.AddProperty("id", id); | 11746 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
11481 | 11747 |
11482 Class& cls = Class::Handle(this->clazz()); | 11748 Class& cls = Class::Handle(this->clazz()); |
11483 jsobj.AddProperty("class", cls); | 11749 jsobj.AddProperty("class", cls); |
11484 | 11750 |
11485 // Set the "preview" property for this instance. | 11751 // Set the "preview" property for this instance. |
11486 if (IsNull()) { | 11752 if (IsNull()) { |
11487 jsobj.AddProperty("preview", "null"); | 11753 jsobj.AddProperty("preview", "null"); |
11488 } else { | 11754 } else { |
11489 jsobj.AddProperty("preview", ToUserCString(40)); | 11755 jsobj.AddProperty("preview", ToUserCString(40)); |
11490 } | 11756 } |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12313 TypeParameter& type_arg = TypeParameter::Handle(isolate); | 12579 TypeParameter& type_arg = TypeParameter::Handle(isolate); |
12314 TypeParameter& type_param = TypeParameter::Handle(isolate); | 12580 TypeParameter& type_param = TypeParameter::Handle(isolate); |
12315 for (intptr_t i = 0; i < num_type_params; i++) { | 12581 for (intptr_t i = 0; i < num_type_params; i++) { |
12316 type_arg ^= type_args.TypeAt(num_type_args - num_type_params + i); | 12582 type_arg ^= type_args.TypeAt(num_type_args - num_type_params + i); |
12317 type_param ^= type_params.TypeAt(i); | 12583 type_param ^= type_params.TypeAt(i); |
12318 ASSERT(type_arg.Equals(type_param)); | 12584 ASSERT(type_arg.Equals(type_param)); |
12319 } | 12585 } |
12320 } | 12586 } |
12321 #endif | 12587 #endif |
12322 ASSERT(IsOld()); | 12588 ASSERT(IsOld()); |
| 12589 ASSERT(type_args.IsNull() || type_args.IsOld()); |
12323 SetCanonical(); | 12590 SetCanonical(); |
12324 return this->raw(); | 12591 return this->raw(); |
12325 } | 12592 } |
12326 | 12593 |
12327 | 12594 |
12328 intptr_t Type::Hash() const { | 12595 intptr_t Type::Hash() const { |
12329 ASSERT(IsFinalized()); | 12596 ASSERT(IsFinalized()); |
12330 uword result = 1; | 12597 uword result = 1; |
12331 if (IsMalformed()) return result; | 12598 if (IsMalformed()) return result; |
12332 result += Class::Handle(type_class()).id(); | 12599 result += Class::Handle(type_class()).id(); |
(...skipping 1995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14328 } | 14595 } |
14329 ASSERT(str.IsExternalTwoByteString()); | 14596 ASSERT(str.IsExternalTwoByteString()); |
14330 // If EscapeSpecialCharacters is frequently called on external two byte | 14597 // If EscapeSpecialCharacters is frequently called on external two byte |
14331 // strings, we should implement it directly on ExternalTwoByteString rather | 14598 // strings, we should implement it directly on ExternalTwoByteString rather |
14332 // than first converting to a TwoByteString. | 14599 // than first converting to a TwoByteString. |
14333 return TwoByteString::EscapeSpecialCharacters( | 14600 return TwoByteString::EscapeSpecialCharacters( |
14334 String::Handle(TwoByteString::New(str, Heap::kNew))); | 14601 String::Handle(TwoByteString::New(str, Heap::kNew))); |
14335 } | 14602 } |
14336 | 14603 |
14337 | 14604 |
| 14605 static bool IsPercent(int32_t c) { |
| 14606 return c == '%'; |
| 14607 } |
| 14608 |
| 14609 |
| 14610 static bool IsHexCharacter(int32_t c) { |
| 14611 if (c >= '0' && c <= '9') { |
| 14612 return true; |
| 14613 } |
| 14614 if (c >= 'A' && c <= 'F') { |
| 14615 return true; |
| 14616 } |
| 14617 return false; |
| 14618 } |
| 14619 |
| 14620 |
| 14621 static bool IsURISafeCharacter(int32_t c) { |
| 14622 if ((c >= '0') && (c <= '9')) { |
| 14623 return true; |
| 14624 } |
| 14625 if ((c >= 'a') && (c <= 'z')) { |
| 14626 return true; |
| 14627 } |
| 14628 if ((c >= 'A') && (c <= 'Z')) { |
| 14629 return true; |
| 14630 } |
| 14631 return (c == '-') || (c == '_') || (c == '.') || (c == '~'); |
| 14632 } |
| 14633 |
| 14634 |
| 14635 static int32_t GetHexCharacter(int32_t c) { |
| 14636 ASSERT(c >= 0); |
| 14637 ASSERT(c < 16); |
| 14638 const char* hex = "0123456789ABCDEF"; |
| 14639 return hex[c]; |
| 14640 } |
| 14641 |
| 14642 |
| 14643 static int32_t GetHexValue(int32_t c) { |
| 14644 if (c >= '0' && c <= '9') { |
| 14645 return c - '0'; |
| 14646 } |
| 14647 if (c >= 'A' && c <= 'F') { |
| 14648 return c - 'A' + 10; |
| 14649 } |
| 14650 UNREACHABLE(); |
| 14651 return 0; |
| 14652 } |
| 14653 |
| 14654 |
| 14655 static int32_t MergeHexCharacters(int32_t c1, int32_t c2) { |
| 14656 return GetHexValue(c1) << 4 | GetHexValue(c2); |
| 14657 } |
| 14658 |
| 14659 |
| 14660 RawString* String::EncodeURI(const String& str) { |
| 14661 // URI encoding is only specified for one byte strings. |
| 14662 ASSERT(str.IsOneByteString() || str.IsExternalOneByteString()); |
| 14663 intptr_t num_escapes = 0; |
| 14664 intptr_t len = str.Length(); |
| 14665 { |
| 14666 CodePointIterator cpi(str); |
| 14667 while (cpi.Next()) { |
| 14668 int32_t code_point = cpi.Current(); |
| 14669 if (!IsURISafeCharacter(code_point)) { |
| 14670 num_escapes += 2; |
| 14671 } |
| 14672 } |
| 14673 } |
| 14674 const String& dststr = String::Handle( |
| 14675 OneByteString::New(len + num_escapes, Heap::kNew)); |
| 14676 { |
| 14677 intptr_t index = 0; |
| 14678 CodePointIterator cpi(str); |
| 14679 while (cpi.Next()) { |
| 14680 int32_t code_point = cpi.Current(); |
| 14681 if (!IsURISafeCharacter(code_point)) { |
| 14682 OneByteString::SetCharAt(dststr, index, '%'); |
| 14683 OneByteString::SetCharAt(dststr, index + 1, |
| 14684 GetHexCharacter(code_point >> 4)); |
| 14685 OneByteString::SetCharAt(dststr, index + 2, |
| 14686 GetHexCharacter(code_point & 0xF)); |
| 14687 index += 3; |
| 14688 } else { |
| 14689 OneByteString::SetCharAt(dststr, index, code_point); |
| 14690 index += 1; |
| 14691 } |
| 14692 } |
| 14693 } |
| 14694 return dststr.raw(); |
| 14695 } |
| 14696 |
| 14697 |
| 14698 RawString* String::DecodeURI(const String& str) { |
| 14699 // URI encoding is only specified for one byte strings. |
| 14700 ASSERT(str.IsOneByteString() || str.IsExternalOneByteString()); |
| 14701 CodePointIterator cpi(str); |
| 14702 intptr_t num_escapes = 0; |
| 14703 intptr_t len = str.Length(); |
| 14704 { |
| 14705 CodePointIterator cpi(str); |
| 14706 while (cpi.Next()) { |
| 14707 int32_t code_point = cpi.Current(); |
| 14708 if (IsPercent(code_point)) { |
| 14709 // Verify that the two characters following the % are hex digits. |
| 14710 if (!cpi.Next()) { |
| 14711 return str.raw(); |
| 14712 } |
| 14713 int32_t code_point = cpi.Current(); |
| 14714 if (!IsHexCharacter(code_point)) { |
| 14715 return str.raw(); |
| 14716 } |
| 14717 if (!cpi.Next()) { |
| 14718 return str.raw(); |
| 14719 } |
| 14720 code_point = cpi.Current(); |
| 14721 if (!IsHexCharacter(code_point)) { |
| 14722 return str.raw(); |
| 14723 } |
| 14724 num_escapes += 2; |
| 14725 } |
| 14726 } |
| 14727 } |
| 14728 ASSERT(len - num_escapes > 0); |
| 14729 const String& dststr = String::Handle( |
| 14730 OneByteString::New(len - num_escapes, Heap::kNew)); |
| 14731 { |
| 14732 intptr_t index = 0; |
| 14733 CodePointIterator cpi(str); |
| 14734 while (cpi.Next()) { |
| 14735 int32_t code_point = cpi.Current(); |
| 14736 if (IsPercent(code_point)) { |
| 14737 cpi.Next(); |
| 14738 int32_t ch1 = cpi.Current(); |
| 14739 cpi.Next(); |
| 14740 int32_t ch2 = cpi.Current(); |
| 14741 int32_t merged = MergeHexCharacters(ch1, ch2); |
| 14742 OneByteString::SetCharAt(dststr, index, merged); |
| 14743 } else { |
| 14744 OneByteString::SetCharAt(dststr, index, code_point); |
| 14745 } |
| 14746 index++; |
| 14747 } |
| 14748 } |
| 14749 return dststr.raw(); |
| 14750 } |
| 14751 |
| 14752 |
14338 RawString* String::NewFormatted(const char* format, ...) { | 14753 RawString* String::NewFormatted(const char* format, ...) { |
14339 va_list args; | 14754 va_list args; |
14340 va_start(args, format); | 14755 va_start(args, format); |
14341 RawString* result = NewFormattedV(format, args); | 14756 RawString* result = NewFormattedV(format, args); |
14342 NoGCScope no_gc; | 14757 NoGCScope no_gc; |
14343 va_end(args); | 14758 va_end(args); |
14344 return result; | 14759 return result; |
14345 } | 14760 } |
14346 | 14761 |
14347 | 14762 |
(...skipping 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16512 return "_MirrorReference"; | 16927 return "_MirrorReference"; |
16513 } | 16928 } |
16514 | 16929 |
16515 | 16930 |
16516 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 16931 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
16517 Instance::PrintToJSONStream(stream, ref); | 16932 Instance::PrintToJSONStream(stream, ref); |
16518 } | 16933 } |
16519 | 16934 |
16520 | 16935 |
16521 } // namespace dart | 16936 } // namespace dart |
OLD | NEW |