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

Side by Side Diff: runtime/lib/mirrors.cc

Issue 1080393006: Mirrors memory usage tweaks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/mirrors.h ('k') | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "lib/mirrors.h" 5 #include "lib/mirrors.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/bootstrap_natives.h" 8 #include "vm/bootstrap_natives.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 const Array& args = Array::Handle(Array::New(2)); 235 const Array& args = Array::Handle(Array::New(2));
236 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 236 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
237 args.SetAt(1, type); 237 args.SetAt(1, type);
238 return CreateMirror(Symbols::_LocalFunctionTypeMirror(), args); 238 return CreateMirror(Symbols::_LocalFunctionTypeMirror(), args);
239 } 239 }
240 240
241 241
242 static RawInstance* CreateMethodMirror(const Function& func, 242 static RawInstance* CreateMethodMirror(const Function& func,
243 const Instance& owner_mirror, 243 const Instance& owner_mirror,
244 const AbstractType& instantiator) { 244 const AbstractType& instantiator) {
245 const Array& args = Array::Handle(Array::New(13)); 245 const Array& args = Array::Handle(Array::New(6));
246 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); 246 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func)));
247 247
248 String& name = String::Handle(func.name()); 248 String& name = String::Handle(func.name());
249 name = String::IdentifierPrettyNameRetainPrivate(name); 249 name = String::IdentifierPrettyNameRetainPrivate(name);
250 args.SetAt(1, name); 250 args.SetAt(1, name);
251
252 args.SetAt(2, owner_mirror); 251 args.SetAt(2, owner_mirror);
253 args.SetAt(3, instantiator); 252 args.SetAt(3, instantiator);
254 args.SetAt(4, Bool::Get(func.is_static())); 253 args.SetAt(4, Bool::Get(func.is_static()));
255 args.SetAt(5, Bool::Get(func.is_abstract()));
256 args.SetAt(6, Bool::Get(func.IsGetterFunction()));
257 args.SetAt(7, Bool::Get(func.IsSetterFunction()));
258 254
259 bool isConstructor = (func.kind() == RawFunction::kConstructor); 255 intptr_t kind_flags = 0;
260 args.SetAt(8, Bool::Get(isConstructor)); 256 kind_flags |= (func.is_abstract() << Mirrors::kAbstract);
261 args.SetAt(9, Bool::Get(isConstructor && func.is_const())); 257 kind_flags |= (func.IsGetterFunction() << Mirrors::kGetter);
262 args.SetAt(10, Bool::Get(isConstructor && func.IsGenerativeConstructor())); 258 kind_flags |= (func.IsSetterFunction() << Mirrors::kSetter);
263 args.SetAt(11, Bool::Get(isConstructor && func.is_redirecting())); 259 bool is_ctor = (func.kind() == RawFunction::kConstructor);
264 args.SetAt(12, Bool::Get(isConstructor && func.IsFactory())); 260 kind_flags |= (is_ctor << Mirrors::kConstructor);
261 kind_flags |= ((is_ctor && func.is_const()) << Mirrors::kConstCtor);
262 kind_flags |= ((is_ctor && func.IsGenerativeConstructor())
263 << Mirrors::kGenerativeCtor);
264 kind_flags |= ((is_ctor && func.is_redirecting())
265 << Mirrors::kRedirectingCtor);
266 kind_flags |= ((is_ctor && func.IsFactory()) << Mirrors::kFactoryCtor);
267 args.SetAt(5, Smi::Handle(Smi::New(kind_flags)));
265 268
266 return CreateMirror(Symbols::_LocalMethodMirror(), args); 269 return CreateMirror(Symbols::_LocalMethodMirror(), args);
267 } 270 }
268 271
269 272
270 static RawInstance* CreateVariableMirror(const Field& field, 273 static RawInstance* CreateVariableMirror(const Field& field,
271 const Instance& owner_mirror) { 274 const Instance& owner_mirror) {
272 const MirrorReference& field_ref = 275 const MirrorReference& field_ref =
273 MirrorReference::Handle(MirrorReference::New(field)); 276 MirrorReference::Handle(MirrorReference::New(field));
274 277
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 const Instance& root_library_mirror = 536 const Instance& root_library_mirror =
534 Instance::Handle(CreateLibraryMirror(root_library)); 537 Instance::Handle(CreateLibraryMirror(root_library));
535 538
536 const Array& args = Array::Handle(Array::New(2)); 539 const Array& args = Array::Handle(Array::New(2));
537 args.SetAt(0, debug_name); 540 args.SetAt(0, debug_name);
538 args.SetAt(1, root_library_mirror); 541 args.SetAt(1, root_library_mirror);
539 return CreateMirror(Symbols::_LocalIsolateMirror(), args); 542 return CreateMirror(Symbols::_LocalIsolateMirror(), args);
540 } 543 }
541 544
542 545
546 static void VerifyMethodKindShifts() {
547 #ifdef DEBUG
548 Isolate* isolate = Isolate::Current();
549 const Library& lib = Library::Handle(isolate, Library::MirrorsLibrary());
550 const Class& cls = Class::Handle(isolate,
551 lib.LookupClassAllowPrivate(Symbols::_LocalMethodMirror()));
552 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate));
553 ASSERT(error.IsNull());
554
555 Field& field = Field::Handle();
556 Smi& value = Smi::Handle();
557
558 #define CHECK_KIND_SHIFT(name) \
559 field = cls.LookupField(String::Handle(String::New(#name))); \
560 ASSERT(!field.IsNull()); \
561 value ^= field.value(); \
562 ASSERT(value.Value() == Mirrors::name);
563 MIRRORS_KIND_SHIFT_LIST(CHECK_KIND_SHIFT)
564 #undef CHECK_KIND_SHIFT
565 #endif
566 }
567
568
543 static RawInstance* CreateMirrorSystem() { 569 static RawInstance* CreateMirrorSystem() {
570 VerifyMethodKindShifts();
571
544 Isolate* isolate = Isolate::Current(); 572 Isolate* isolate = Isolate::Current();
545 const GrowableObjectArray& libraries = GrowableObjectArray::Handle( 573 const GrowableObjectArray& libraries = GrowableObjectArray::Handle(
546 isolate, isolate->object_store()->libraries()); 574 isolate, isolate->object_store()->libraries());
547 575
548 const intptr_t num_libraries = libraries.Length(); 576 const intptr_t num_libraries = libraries.Length();
549 const GrowableObjectArray& library_mirrors = GrowableObjectArray::Handle( 577 const GrowableObjectArray& library_mirrors = GrowableObjectArray::Handle(
550 isolate, GrowableObjectArray::New(num_libraries)); 578 isolate, GrowableObjectArray::New(num_libraries));
551 Library& library = Library::Handle(isolate); 579 Library& library = Library::Handle(isolate);
552 Instance& library_mirror = Instance::Handle(isolate); 580 Instance& library_mirror = Instance::Handle(isolate);
553 581
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 instantiator, 914 instantiator,
887 arguments->NativeArgAt(1)); 915 arguments->NativeArgAt(1));
888 const Class& cls = Class::Handle(ref.GetClassReferent()); 916 const Class& cls = Class::Handle(ref.GetClassReferent());
889 const Function& func = Function::Handle(CallMethod(cls)); 917 const Function& func = Function::Handle(CallMethod(cls));
890 ASSERT(!func.IsNull()); 918 ASSERT(!func.IsNull());
891 AbstractType& type = AbstractType::Handle(func.result_type()); 919 AbstractType& type = AbstractType::Handle(func.result_type());
892 return InstantiateType(type, instantiator); 920 return InstantiateType(type, instantiator);
893 } 921 }
894 922
895 923
896 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { 924 DEFINE_NATIVE_ENTRY(ClassMirror_libraryUri, 1) {
897 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 925 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
898 const Class& klass = Class::Handle(ref.GetClassReferent()); 926 const Class& klass = Class::Handle(ref.GetClassReferent());
899 const Library& library = Library::Handle(klass.library()); 927 const Library& library = Library::Handle(klass.library());
900 ASSERT(!library.IsNull()); 928 ASSERT(!library.IsNull());
901 return CreateLibraryMirror(library); 929 return library.url();
902 } 930 }
903 931
904 932
905 DEFINE_NATIVE_ENTRY(ClassMirror_supertype, 1) { 933 DEFINE_NATIVE_ENTRY(ClassMirror_supertype, 1) {
906 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); 934 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
907 ASSERT(!type.IsMalformed()); 935 ASSERT(!type.IsMalformed());
908 ASSERT(type.IsFinalized()); 936 ASSERT(type.IsFinalized());
909 if (!type.HasResolvedTypeClass()) { 937 if (!type.HasResolvedTypeClass()) {
910 Exceptions::ThrowArgumentError(type); 938 Exceptions::ThrowArgumentError(type);
911 UNREACHABLE(); 939 UNREACHABLE();
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 } 2062 }
2035 2063
2036 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { 2064 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) {
2037 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 2065 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
2038 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 2066 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
2039 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); 2067 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw();
2040 } 2068 }
2041 2069
2042 2070
2043 } // namespace dart 2071 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.h ('k') | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698