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

Side by Side Diff: pkg/analyzer/lib/src/context/cache.dart

Issue 1480393004: Clean source maps during partition dispose. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library analyzer.src.context.cache; 5 library analyzer.src.context.cache;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/engine.dart' 10 import 'package:analyzer/src/generated/engine.dart'
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 }); 59 });
60 onResultInvalidatedPartitionSubscriptions.add(subscription); 60 onResultInvalidatedPartitionSubscriptions.add(subscription);
61 } 61 }
62 } 62 }
63 63
64 /** 64 /**
65 * Return an iterator returning all of the [Source] targets. 65 * Return an iterator returning all of the [Source] targets.
66 */ 66 */
67 Iterable<Source> get sources { 67 Iterable<Source> get sources {
68 return _partitions 68 return _partitions
69 .map((CachePartition partition) => partition._sources) 69 .map((CachePartition partition) => partition.sources)
70 .expand((Iterable<Source> sources) => sources); 70 .expand((Iterable<Source> sources) => sources);
71 } 71 }
72 72
73 // TODO(brianwilkerson) Implement or delete this. 73 // TODO(brianwilkerson) Implement or delete this.
74 // /** 74 // /**
75 // * Return information about each of the partitions in this cache. 75 // * Return information about each of the partitions in this cache.
76 // */ 76 // */
77 // List<AnalysisContextStatistics_PartitionData> get partitionData { 77 // List<AnalysisContextStatistics_PartitionData> get partitionData {
78 // int count = _partitions.length; 78 // int count = _partitions.length;
79 // List<AnalysisContextStatistics_PartitionData> data = 79 // List<AnalysisContextStatistics_PartitionData> data =
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 * Return an iterator returning all of the map entries mapping targets to 184 * Return an iterator returning all of the map entries mapping targets to
185 * cache entries. If the [context] is not `null`, then only entries that are 185 * cache entries. If the [context] is not `null`, then only entries that are
186 * owned by the given context will be returned. 186 * owned by the given context will be returned.
187 */ 187 */
188 MapIterator<AnalysisTarget, CacheEntry> iterator( 188 MapIterator<AnalysisTarget, CacheEntry> iterator(
189 {InternalAnalysisContext context: null}) { 189 {InternalAnalysisContext context: null}) {
190 List<Map<AnalysisTarget, CacheEntry>> maps = 190 List<Map<AnalysisTarget, CacheEntry>> maps =
191 <Map<AnalysisTarget, CacheEntry>>[]; 191 <Map<AnalysisTarget, CacheEntry>>[];
192 for (CachePartition partition in _partitions) { 192 for (CachePartition partition in _partitions) {
193 if (context == null || partition.context == context) { 193 if (context == null || partition.context == context) {
194 maps.add(partition.map); 194 maps.add(partition.entryMap);
195 } 195 }
196 } 196 }
197 return new MultipleMapIterator<AnalysisTarget, CacheEntry>(maps); 197 return new MultipleMapIterator<AnalysisTarget, CacheEntry>(maps);
198 } 198 }
199 199
200 /** 200 /**
201 * Puts the given [entry] into the cache. 201 * Puts the given [entry] into the cache.
202 */ 202 */
203 void put(CacheEntry entry) { 203 void put(CacheEntry entry) {
204 AnalysisTarget target = entry.target; 204 AnalysisTarget target = entry.target;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 for (TargetedResult dependedOnResult in thisData.dependedOnResults) { 578 for (TargetedResult dependedOnResult in thisData.dependedOnResults) {
579 ResultData data = _partition._getDataFor(dependedOnResult); 579 ResultData data = _partition._getDataFor(dependedOnResult);
580 if (data != null && deltaResult != DeltaResult.KEEP_CONTINUE) { 580 if (data != null && deltaResult != DeltaResult.KEEP_CONTINUE) {
581 data.dependentResults.remove(thisResult); 581 data.dependentResults.remove(thisResult);
582 } 582 }
583 } 583 }
584 // Invalidate results that depend on this result. 584 // Invalidate results that depend on this result.
585 _invalidateDependentResults(id, thisData, delta, level + 1); 585 _invalidateDependentResults(id, thisData, delta, level + 1);
586 // If empty and not explicitly added, remove the entry altogether. 586 // If empty and not explicitly added, remove the entry altogether.
587 if (_resultMap.isEmpty && !explicitlyAdded) { 587 if (_resultMap.isEmpty && !explicitlyAdded) {
588 _partition._targetMap.remove(target); 588 _partition.entryMap.remove(target);
589 _partition._removeIfSource(target); 589 _partition._removeIfSource(target);
590 } 590 }
591 // Notify controller. 591 // Notify controller.
592 _partition.onResultInvalidated 592 _partition.onResultInvalidated
593 .add(new InvalidatedResult(this, descriptor, thisData.value)); 593 .add(new InvalidatedResult(this, descriptor, thisData.value));
594 } 594 }
595 595
596 /** 596 /**
597 * Invalidates all the results of this entry, with propagation. 597 * Invalidates all the results of this entry, with propagation.
598 */ 598 */
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 /** 851 /**
852 * The [StreamController] reporting [InvalidatedResult]s. 852 * The [StreamController] reporting [InvalidatedResult]s.
853 */ 853 */
854 final ReentrantSynchronousStream<InvalidatedResult> onResultInvalidated = 854 final ReentrantSynchronousStream<InvalidatedResult> onResultInvalidated =
855 new ReentrantSynchronousStream<InvalidatedResult>(); 855 new ReentrantSynchronousStream<InvalidatedResult>();
856 856
857 /** 857 /**
858 * A table mapping the targets belonging to this partition to the information 858 * A table mapping the targets belonging to this partition to the information
859 * known about those targets. 859 * known about those targets.
860 */ 860 */
861 HashMap<AnalysisTarget, CacheEntry> _targetMap = 861 final HashMap<AnalysisTarget, CacheEntry> entryMap =
862 new HashMap<AnalysisTarget, CacheEntry>(); 862 new HashMap<AnalysisTarget, CacheEntry>();
863 863
864 /** 864 /**
865 * A set of the [Source] targets. 865 * A set of the [Source] targets.
866 */ 866 */
867 final HashSet<Source> _sources = new HashSet<Source>(); 867 final HashSet<Source> sources = new HashSet<Source>();
868 868
869 /** 869 /**
870 * A table mapping full paths to lists of [Source]s with these full paths. 870 * A table mapping full paths to lists of [Source]s with these full paths.
871 */ 871 */
872 final Map<String, List<Source>> _pathToSources = <String, List<Source>>{}; 872 final Map<String, List<Source>> pathToSource = <String, List<Source>>{};
873 873
874 /** 874 /**
875 * Initialize a newly created cache partition, belonging to the given 875 * Initialize a newly created cache partition, belonging to the given
876 * [context]. 876 * [context].
877 */ 877 */
878 CachePartition(this.context); 878 CachePartition(this.context);
879 879
880 /** 880 /**
881 * Return a table mapping the targets known to the context to the information
882 * known about the target.
883 *
884 * <b>Note:</b> This method is only visible for use by [AnalysisCache] and
885 * should not be used for any other purpose.
886 */
887 Map<AnalysisTarget, CacheEntry> get map => _targetMap;
888
889 /**
890 * Notifies the partition that the client is going to stop using it. 881 * Notifies the partition that the client is going to stop using it.
891 */ 882 */
892 void dispose() { 883 void dispose() {
893 for (CacheEntry entry in _targetMap.values) { 884 for (CacheEntry entry in entryMap.values) {
894 entry.dispose(); 885 entry.dispose();
895 } 886 }
896 _targetMap.clear(); 887 entryMap.clear();
888 sources.clear();
889 pathToSource.clear();
897 } 890 }
898 891
899 /** 892 /**
900 * Return the entry associated with the given [target]. 893 * Return the entry associated with the given [target].
901 */ 894 */
902 CacheEntry get(AnalysisTarget target) => _targetMap[target]; 895 CacheEntry get(AnalysisTarget target) => entryMap[target];
903 896
904 /** 897 /**
905 * Return [Source]s whose full path is equal to the given [path]. 898 * Return [Source]s whose full path is equal to the given [path].
906 * Maybe empty, but not `null`. 899 * Maybe empty, but not `null`.
907 */ 900 */
908 List<Source> getSourcesWithFullName(String path) { 901 List<Source> getSourcesWithFullName(String path) {
909 List<Source> sources = _pathToSources[path]; 902 List<Source> sources = pathToSource[path];
910 return sources != null ? sources : Source.EMPTY_LIST; 903 return sources != null ? sources : Source.EMPTY_LIST;
911 } 904 }
912 905
913 /** 906 /**
914 * Return `true` if this partition is responsible for the given [target]. 907 * Return `true` if this partition is responsible for the given [target].
915 */ 908 */
916 bool isResponsibleFor(AnalysisTarget target); 909 bool isResponsibleFor(AnalysisTarget target);
917 910
918 /** 911 /**
919 * Return an iterator returning all of the map entries mapping targets to 912 * Return an iterator returning all of the map entries mapping targets to
920 * cache entries. 913 * cache entries.
921 */ 914 */
922 MapIterator<AnalysisTarget, CacheEntry> iterator() => 915 MapIterator<AnalysisTarget, CacheEntry> iterator() =>
923 new SingleMapIterator<AnalysisTarget, CacheEntry>(_targetMap); 916 new SingleMapIterator<AnalysisTarget, CacheEntry>(entryMap);
924 917
925 /** 918 /**
926 * Puts the given [entry] into the partition. 919 * Puts the given [entry] into the partition.
927 */ 920 */
928 void put(CacheEntry entry) { 921 void put(CacheEntry entry) {
929 AnalysisTarget target = entry.target; 922 AnalysisTarget target = entry.target;
930 if (entry._partition != null) { 923 if (entry._partition != null) {
931 throw new StateError( 924 throw new StateError(
932 'The entry for $target is already in ${entry._partition}'); 925 'The entry for $target is already in ${entry._partition}');
933 } 926 }
934 entry._partition = this; 927 entry._partition = this;
935 entry.fixExceptionState(); 928 entry.fixExceptionState();
936 _targetMap[target] = entry; 929 entryMap[target] = entry;
937 _addIfSource(target); 930 _addIfSource(target);
938 } 931 }
939 932
940 /** 933 /**
941 * Remove all information related to the given [target] from this partition. 934 * Remove all information related to the given [target] from this partition.
942 * Return the entry associated with the target, or `null` if there was cache 935 * Return the entry associated with the target, or `null` if there was cache
943 * entry for the target. 936 * entry for the target.
944 */ 937 */
945 CacheEntry remove(AnalysisTarget target) { 938 CacheEntry remove(AnalysisTarget target) {
946 for (CacheFlushManager flushManager in _flushManagerMap.values) { 939 for (CacheFlushManager flushManager in _flushManagerMap.values) {
947 flushManager.targetRemoved(target); 940 flushManager.targetRemoved(target);
948 } 941 }
949 CacheEntry entry = _targetMap.remove(target); 942 CacheEntry entry = entryMap.remove(target);
950 if (entry != null) { 943 if (entry != null) {
951 entry._invalidateAll(); 944 entry._invalidateAll();
952 } 945 }
953 _removeIfSource(target); 946 _removeIfSource(target);
954 return entry; 947 return entry;
955 } 948 }
956 949
957 /** 950 /**
958 * Records that a value of the result described by the given [descriptor] 951 * Records that a value of the result described by the given [descriptor]
959 * for the given [target] was just read from the cache. 952 * for the given [target] was just read from the cache.
(...skipping 18 matching lines...) Expand all
978 if (data != null) { 971 if (data != null) {
979 data.flush(); 972 data.flush();
980 } 973 }
981 } 974 }
982 } 975 }
983 } 976 }
984 977
985 /** 978 /**
986 * Return the number of targets that are mapped to cache entries. 979 * Return the number of targets that are mapped to cache entries.
987 */ 980 */
988 int size() => _targetMap.length; 981 int size() => entryMap.length;
989 982
990 /** 983 /**
991 * If the given [target] is a [Source], adds it to [_sources]. 984 * If the given [target] is a [Source], adds it to [sources].
992 */ 985 */
993 void _addIfSource(AnalysisTarget target) { 986 void _addIfSource(AnalysisTarget target) {
994 if (target is Source) { 987 if (target is Source) {
995 _sources.add(target); 988 sources.add(target);
996 String fullName = target.fullName; 989 String fullName = target.fullName;
997 _pathToSources.putIfAbsent(fullName, () => <Source>[]).add(target); 990 pathToSource.putIfAbsent(fullName, () => <Source>[]).add(target);
998 } 991 }
999 } 992 }
1000 993
1001 ResultData _getDataFor(TargetedResult result) { 994 ResultData _getDataFor(TargetedResult result) {
1002 CacheEntry entry = context.analysisCache.get(result.target); 995 CacheEntry entry = context.analysisCache.get(result.target);
1003 return entry != null ? entry._resultMap[result.result] : null; 996 return entry != null ? entry._resultMap[result.result] : null;
1004 } 997 }
1005 998
1006 /** 999 /**
1007 * Return the [CacheFlushManager] for the given [descriptor], not `null`. 1000 * Return the [CacheFlushManager] for the given [descriptor], not `null`.
1008 */ 1001 */
1009 CacheFlushManager _getFlushManager(ResultDescriptor descriptor) { 1002 CacheFlushManager _getFlushManager(ResultDescriptor descriptor) {
1010 ResultCachingPolicy policy = descriptor.cachingPolicy; 1003 ResultCachingPolicy policy = descriptor.cachingPolicy;
1011 if (identical(policy, DEFAULT_CACHING_POLICY)) { 1004 if (identical(policy, DEFAULT_CACHING_POLICY)) {
1012 return UnlimitedCacheFlushManager.INSTANCE; 1005 return UnlimitedCacheFlushManager.INSTANCE;
1013 } 1006 }
1014 CacheFlushManager manager = _flushManagerMap[policy]; 1007 CacheFlushManager manager = _flushManagerMap[policy];
1015 if (manager == null) { 1008 if (manager == null) {
1016 manager = new CacheFlushManager(policy, _isPriorityAnalysisTarget); 1009 manager = new CacheFlushManager(policy, _isPriorityAnalysisTarget);
1017 _flushManagerMap[policy] = manager; 1010 _flushManagerMap[policy] = manager;
1018 } 1011 }
1019 return manager; 1012 return manager;
1020 } 1013 }
1021 1014
1022 bool _isPriorityAnalysisTarget(AnalysisTarget target) { 1015 bool _isPriorityAnalysisTarget(AnalysisTarget target) {
1023 return context.priorityTargets.contains(target); 1016 return context.priorityTargets.contains(target);
1024 } 1017 }
1025 1018
1026 /** 1019 /**
1027 * If the given [target] is a [Source], remove it from the list of [_sources]. 1020 * If the given [target] is a [Source], remove it from the list of [sources].
1028 */ 1021 */
1029 void _removeIfSource(AnalysisTarget target) { 1022 void _removeIfSource(AnalysisTarget target) {
1030 if (target is Source) { 1023 if (target is Source) {
1031 _sources.remove(target); 1024 sources.remove(target);
1032 String fullName = target.fullName; 1025 String path = target.fullName;
1033 List<Source> sources = _pathToSources[fullName]; 1026 List<Source> pathSources = pathToSource[path];
1034 if (sources != null) { 1027 if (pathSources != null) {
1035 sources.remove(target); 1028 pathSources.remove(target);
1036 if (sources.isEmpty) { 1029 if (pathSources.isEmpty) {
1037 _pathToSources.remove(fullName); 1030 pathToSource.remove(path);
1038 } 1031 }
1039 } 1032 }
1040 } 1033 }
1041 } 1034 }
1042 } 1035 }
1043 1036
1044 /** 1037 /**
1045 * The description for a change. 1038 * The description for a change.
1046 */ 1039 */
1047 class Delta { 1040 class Delta {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 void resultAccessed(TargetedResult result) {} 1256 void resultAccessed(TargetedResult result) {}
1264 1257
1265 @override 1258 @override
1266 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { 1259 List<TargetedResult> resultStored(TargetedResult newResult, newValue) {
1267 return TargetedResult.EMPTY_LIST; 1260 return TargetedResult.EMPTY_LIST;
1268 } 1261 }
1269 1262
1270 @override 1263 @override
1271 void targetRemoved(AnalysisTarget target) {} 1264 void targetRemoved(AnalysisTarget target) {}
1272 } 1265 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/cache_test.dart » ('j') | pkg/analyzer/test/src/context/cache_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698