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

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

Issue 1650873002: Fix memory leak in incremental resolver (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
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';
11 import 'package:analyzer/src/generated/java_engine.dart'; 11 import 'package:analyzer/src/generated/java_engine.dart';
12 import 'package:analyzer/src/generated/source.dart'; 12 import 'package:analyzer/src/generated/source.dart';
13 import 'package:analyzer/src/generated/utilities_collection.dart'; 13 import 'package:analyzer/src/generated/utilities_collection.dart';
14 import 'package:analyzer/src/task/model.dart'; 14 import 'package:analyzer/src/task/model.dart';
15 import 'package:analyzer/task/model.dart'; 15 import 'package:analyzer/task/model.dart';
16 16
17 import 'package:analyzer/src/dart/element/element.dart' show ElementImpl;
18
17 /** 19 /**
18 * Return `true` if the given [target] is a priority one. 20 * Return `true` if the given [target] is a priority one.
19 */ 21 */
20 typedef bool IsPriorityAnalysisTarget(AnalysisTarget target); 22 typedef bool IsPriorityAnalysisTarget(AnalysisTarget target);
21 23
22 /** 24 /**
23 * An LRU cache of results produced by analysis. 25 * An LRU cache of results produced by analysis.
24 */ 26 */
25 class AnalysisCache { 27 class AnalysisCache {
26 /** 28 /**
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 if (data == null) { 379 if (data == null) {
378 return CacheState.INVALID; 380 return CacheState.INVALID;
379 } 381 }
380 return data.state; 382 return data.state;
381 } 383 }
382 384
383 /** 385 /**
384 * Return the value of the result represented by the given [descriptor], or 386 * Return the value of the result represented by the given [descriptor], or
385 * the default value for the result if this entry does not have a valid value. 387 * the default value for the result if this entry does not have a valid value.
386 */ 388 */
387 dynamic /*=V*/ getValue /*<V>*/ (ResultDescriptor /*<V>*/ descriptor) { 389 dynamic/*=V*/ getValue/*<V>*/(ResultDescriptor/*<V>*/ descriptor) {
388 ResultData data = _resultMap[descriptor]; 390 ResultData data = _resultMap[descriptor];
389 if (data == null) { 391 if (data == null) {
390 return descriptor.defaultValue; 392 return descriptor.defaultValue;
391 } 393 }
392 if (_partition != null) { 394 if (_partition != null) {
393 _partition.resultAccessed(target, descriptor); 395 _partition.resultAccessed(target, descriptor);
394 } 396 }
395 return data.value; 397 return data.value;
396 } 398 }
397 399
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 // 477 //
476 data.value = descriptor.defaultValue; 478 data.value = descriptor.defaultValue;
477 } 479 }
478 } 480 }
479 } 481 }
480 482
481 /** 483 /**
482 * Set the value of the result represented by the given [descriptor] to the 484 * Set the value of the result represented by the given [descriptor] to the
483 * given [value]. 485 * given [value].
484 */ 486 */
485 void setValue /*<V>*/ (ResultDescriptor /*<V>*/ descriptor, 487 void setValue/*<V>*/(ResultDescriptor/*<V>*/ descriptor, dynamic/*=V*/ value,
486 dynamic /*=V*/ value, List<TargetedResult> dependedOn) { 488 List<TargetedResult> dependedOn) {
487 // { 489 // {
488 // String valueStr = '$value'; 490 // String valueStr = '$value';
489 // if (valueStr.length > 20) { 491 // if (valueStr.length > 20) {
490 // valueStr = valueStr.substring(0, 20) + '...'; 492 // valueStr = valueStr.substring(0, 20) + '...';
491 // } 493 // }
492 // valueStr = valueStr.replaceAll('\n', '\\n'); 494 // valueStr = valueStr.replaceAll('\n', '\\n');
493 // print( 495 // print(
494 // 'setValue $descriptor for $target value=$valueStr $dependedOn=$depen dedOn'); 496 // 'setValue $descriptor for $target value=$valueStr $dependedOn=$depen dedOn');
495 // } 497 // }
496 _validateStateChange(descriptor, CacheState.VALID); 498 _validateStateChange(descriptor, CacheState.VALID);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 ResultData data = _partition._getDataFor(dependedOnResult); 577 ResultData data = _partition._getDataFor(dependedOnResult);
576 if (data != null && deltaResult != DeltaResult.KEEP_CONTINUE) { 578 if (data != null && deltaResult != DeltaResult.KEEP_CONTINUE) {
577 data.dependentResults.remove(thisResult); 579 data.dependentResults.remove(thisResult);
578 } 580 }
579 } 581 }
580 // Invalidate results that depend on this result. 582 // Invalidate results that depend on this result.
581 _invalidateDependentResults(id, thisData, delta, level + 1); 583 _invalidateDependentResults(id, thisData, delta, level + 1);
582 // If empty and not explicitly added, remove the entry altogether. 584 // If empty and not explicitly added, remove the entry altogether.
583 if (_resultMap.isEmpty && !explicitlyAdded) { 585 if (_resultMap.isEmpty && !explicitlyAdded) {
584 _partition.entryMap.remove(target); 586 _partition.entryMap.remove(target);
587 if (target is ElementImpl) {
588 // Allow mutations now that it's no longer a map key.
589 (target as ElementImpl).frozen = false;
590 }
585 _partition._removeIfSource(target); 591 _partition._removeIfSource(target);
586 } 592 }
587 // Notify controller. 593 // Notify controller.
588 _partition.onResultInvalidated 594 _partition.onResultInvalidated
589 .add(new InvalidatedResult(this, descriptor, thisData.value)); 595 .add(new InvalidatedResult(this, descriptor, thisData.value));
590 } 596 }
591 597
592 /** 598 /**
593 * Invalidates all the results of this entry, with propagation. 599 * Invalidates all the results of this entry, with propagation.
594 */ 600 */
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 * Puts the given [entry] into the partition. 921 * Puts the given [entry] into the partition.
916 */ 922 */
917 void put(CacheEntry entry) { 923 void put(CacheEntry entry) {
918 AnalysisTarget target = entry.target; 924 AnalysisTarget target = entry.target;
919 if (entry._partition != null) { 925 if (entry._partition != null) {
920 throw new StateError( 926 throw new StateError(
921 'The entry for $target is already in ${entry._partition}'); 927 'The entry for $target is already in ${entry._partition}');
922 } 928 }
923 entry._partition = this; 929 entry._partition = this;
924 entry.fixExceptionState(); 930 entry.fixExceptionState();
931 if (target is ElementImpl) {
932 // Detect attempts to mutate the map key.
933 target.frozen = true;
934 }
925 entryMap[target] = entry; 935 entryMap[target] = entry;
926 _addIfSource(target); 936 _addIfSource(target);
927 } 937 }
928 938
929 /** 939 /**
930 * Remove all information related to the given [target] from this partition. 940 * Remove all information related to the given [target] from this partition.
931 * Return the entry associated with the target, or `null` if there was cache 941 * Return the entry associated with the target, or `null` if there was cache
932 * entry for the target. 942 * entry for the target.
933 */ 943 */
934 CacheEntry remove(AnalysisTarget target) { 944 CacheEntry remove(AnalysisTarget target) {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 void resultAccessed(TargetedResult result) {} 1262 void resultAccessed(TargetedResult result) {}
1253 1263
1254 @override 1264 @override
1255 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { 1265 List<TargetedResult> resultStored(TargetedResult newResult, newValue) {
1256 return TargetedResult.EMPTY_LIST; 1266 return TargetedResult.EMPTY_LIST;
1257 } 1267 }
1258 1268
1259 @override 1269 @override
1260 void targetRemoved(AnalysisTarget target) {} 1270 void targetRemoved(AnalysisTarget target) {}
1261 } 1271 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/context/context.dart » ('j') | pkg/analyzer/lib/src/dart/element/element.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698