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

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

Issue 1211993004: Dispose private cache partition on AnalysisContext.dispose(). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/context/context.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) 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 _setFlag(_EXPLICITLY_ADDED_FLAG, explicitlyAdded); 312 _setFlag(_EXPLICITLY_ADDED_FLAG, explicitlyAdded);
313 } 313 }
314 314
315 /** 315 /**
316 * Return a list of result descriptors for results whose state is not 316 * Return a list of result descriptors for results whose state is not
317 * [CacheState.INVALID]. 317 * [CacheState.INVALID].
318 */ 318 */
319 List<ResultDescriptor> get nonInvalidResults => _resultMap.keys.toList(); 319 List<ResultDescriptor> get nonInvalidResults => _resultMap.keys.toList();
320 320
321 /** 321 /**
322 * Notifies the entry that the client is going to stop using it.
323 */
324 void dispose() {
325 _resultMap.forEach((descriptor, data) {
326 TargetedResult result = new TargetedResult(target, descriptor);
327 for (TargetedResult dependedOnResult in data.dependedOnResults) {
328 ResultData dependedOnData = _partition._getDataFor(dependedOnResult);
329 if (dependedOnData != null) {
330 dependedOnData.dependentResults.remove(result);
331 }
332 }
333 });
334 _resultMap.clear();
335 }
336
337 /**
322 * Fix the state of the [exception] to match the current state of the entry. 338 * Fix the state of the [exception] to match the current state of the entry.
323 */ 339 */
324 void fixExceptionState() { 340 void fixExceptionState() {
325 if (!hasErrorState()) { 341 if (!hasErrorState()) {
326 _exception = null; 342 _exception = null;
327 } 343 }
328 } 344 }
329 345
330 /** 346 /**
331 * Look up the [ResultData] of [descriptor], or add a new one if it isn't 347 * Look up the [ResultData] of [descriptor], or add a new one if it isn't
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 529 }
514 if (deltaResult == DeltaResult.KEEP_CONTINUE) { 530 if (deltaResult == DeltaResult.KEEP_CONTINUE) {
515 thisData = _resultMap[descriptor]; 531 thisData = _resultMap[descriptor];
516 } 532 }
517 if (thisData == null) { 533 if (thisData == null) {
518 return; 534 return;
519 } 535 }
520 // Stop depending on other results. 536 // Stop depending on other results.
521 TargetedResult thisResult = new TargetedResult(target, descriptor); 537 TargetedResult thisResult = new TargetedResult(target, descriptor);
522 for (TargetedResult dependedOnResult in thisData.dependedOnResults) { 538 for (TargetedResult dependedOnResult in thisData.dependedOnResults) {
523 ResultData data = _partition._getDataFor(dependedOnResult, orNull: true); 539 ResultData data = _partition._getDataFor(dependedOnResult);
524 if (data != null) { 540 if (data != null) {
525 data.dependentResults.remove(thisResult); 541 data.dependentResults.remove(thisResult);
526 } 542 }
527 } 543 }
528 // Invalidate results that depend on this result. 544 // Invalidate results that depend on this result.
529 List<TargetedResult> dependentResults = thisData.dependentResults.toList(); 545 List<TargetedResult> dependentResults = thisData.dependentResults.toList();
530 for (TargetedResult dependentResult in dependentResults) { 546 for (TargetedResult dependentResult in dependentResults) {
531 CacheEntry entry = _partition.get(dependentResult.target); 547 CacheEntry entry = _partition.get(dependentResult.target);
532 if (entry != null) { 548 if (entry != null) {
533 entry._invalidate(dependentResult.result, delta); 549 entry._invalidate(dependentResult.result, delta);
(...skipping 18 matching lines...) Expand all
552 _invalidate(result, null); 568 _invalidate(result, null);
553 } 569 }
554 } 570 }
555 571
556 /** 572 /**
557 * Set the [dependedOn] on which this result depends. 573 * Set the [dependedOn] on which this result depends.
558 */ 574 */
559 void _setDependedOnResults(ResultData thisData, TargetedResult thisResult, 575 void _setDependedOnResults(ResultData thisData, TargetedResult thisResult,
560 List<TargetedResult> dependedOn) { 576 List<TargetedResult> dependedOn) {
561 thisData.dependedOnResults.forEach((TargetedResult dependedOnResult) { 577 thisData.dependedOnResults.forEach((TargetedResult dependedOnResult) {
562 ResultData data = _partition._getDataFor(dependedOnResult, orNull: true); 578 ResultData data = _partition._getDataFor(dependedOnResult);
563 if (data != null) { 579 if (data != null) {
564 data.dependentResults.remove(thisResult); 580 data.dependentResults.remove(thisResult);
565 } 581 }
566 }); 582 });
567 thisData.dependedOnResults = dependedOn; 583 thisData.dependedOnResults = dependedOn;
568 thisData.dependedOnResults.forEach((TargetedResult dependedOnResult) { 584 thisData.dependedOnResults.forEach((TargetedResult dependedOnResult) {
569 ResultData data = _partition._getDataFor(dependedOnResult, orNull: true); 585 ResultData data = _partition._getDataFor(dependedOnResult);
570 if (data != null) { 586 if (data != null) {
571 data.dependentResults.add(thisResult); 587 data.dependentResults.add(thisResult);
572 } 588 }
573 }); 589 });
574 } 590 }
575 591
576 /** 592 /**
577 * Set states of the given and dependent results to [CacheState.ERROR] and 593 * Set states of the given and dependent results to [CacheState.ERROR] and
578 * their values to the corresponding default values 594 * their values to the corresponding default values
579 */ 595 */
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 */ 838 */
823 Map<AnalysisTarget, CacheEntry> get map => _targetMap; 839 Map<AnalysisTarget, CacheEntry> get map => _targetMap;
824 840
825 /** 841 /**
826 * Return the stream that is notified when a value is invalidated. 842 * Return the stream that is notified when a value is invalidated.
827 */ 843 */
828 Stream<InvalidatedResult> get onResultInvalidated => 844 Stream<InvalidatedResult> get onResultInvalidated =>
829 _onResultInvalidated.stream; 845 _onResultInvalidated.stream;
830 846
831 /** 847 /**
848 * Notifies the partition that the client is going to stop using it.
849 */
850 void dispose() {
851 for (CacheEntry entry in _targetMap.values) {
852 entry.dispose();
853 }
854 _targetMap.clear();
855 }
856
857 /**
832 * Return the entry associated with the given [target]. 858 * Return the entry associated with the given [target].
833 */ 859 */
834 CacheEntry get(AnalysisTarget target) => _targetMap[target]; 860 CacheEntry get(AnalysisTarget target) => _targetMap[target];
835 861
836 /** 862 /**
837 * Return [Source]s whose full path is equal to the given [path]. 863 * Return [Source]s whose full path is equal to the given [path].
838 * Maybe empty, but not `null`. 864 * Maybe empty, but not `null`.
839 */ 865 */
840 List<Source> getSourcesWithFullName(String path) { 866 List<Source> getSourcesWithFullName(String path) {
841 List<Source> sources = _pathToSources[path]; 867 List<Source> sources = _pathToSources[path];
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 void _addIfSource(AnalysisTarget target) { 948 void _addIfSource(AnalysisTarget target) {
923 if (target is Source) { 949 if (target is Source) {
924 _sources.add(target); 950 _sources.add(target);
925 { 951 {
926 String fullName = target.fullName; 952 String fullName = target.fullName;
927 _pathToSources.putIfAbsent(fullName, () => <Source>[]).add(target); 953 _pathToSources.putIfAbsent(fullName, () => <Source>[]).add(target);
928 } 954 }
929 } 955 }
930 } 956 }
931 957
932 ResultData _getDataFor(TargetedResult result, {bool orNull: false}) { 958 ResultData _getDataFor(TargetedResult result) {
933 CacheEntry entry = context.analysisCache.get(result.target); 959 CacheEntry entry = context.analysisCache.get(result.target);
934 if (orNull) { 960 return entry != null ? entry._resultMap[result.result] : null;
935 return entry != null ? entry._resultMap[result.result] : null;
936 } else {
937 return entry.getResultData(result.result);
938 }
939 } 961 }
940 962
941 /** 963 /**
942 * Return the [CacheFlushManager] for the given [descriptor], not `null`. 964 * Return the [CacheFlushManager] for the given [descriptor], not `null`.
943 */ 965 */
944 CacheFlushManager _getFlushManager(ResultDescriptor descriptor) { 966 CacheFlushManager _getFlushManager(ResultDescriptor descriptor) {
945 ResultCachingPolicy policy = descriptor.cachingPolicy; 967 ResultCachingPolicy policy = descriptor.cachingPolicy;
946 if (identical(policy, DEFAULT_CACHING_POLICY)) { 968 if (identical(policy, DEFAULT_CACHING_POLICY)) {
947 return UnlimitedCacheFlushManager.INSTANCE; 969 return UnlimitedCacheFlushManager.INSTANCE;
948 } 970 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 void resultAccessed(TargetedResult result) {} 1179 void resultAccessed(TargetedResult result) {}
1158 1180
1159 @override 1181 @override
1160 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { 1182 List<TargetedResult> resultStored(TargetedResult newResult, newValue) {
1161 return TargetedResult.EMPTY_LIST; 1183 return TargetedResult.EMPTY_LIST;
1162 } 1184 }
1163 1185
1164 @override 1186 @override
1165 void targetRemoved(AnalysisTarget target) {} 1187 void targetRemoved(AnalysisTarget target) {}
1166 } 1188 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/context/context.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698