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

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

Issue 2132073003: Validate cache consistency asynchronously. Compute modification times of physical files in a separa… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
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.context; 5 library analyzer.src.context.context;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 /** 151 /**
152 * The analysis driver used to perform analysis. 152 * The analysis driver used to perform analysis.
153 */ 153 */
154 AnalysisDriver driver; 154 AnalysisDriver driver;
155 155
156 /** 156 /**
157 * A list containing sources for which data should not be flushed. 157 * A list containing sources for which data should not be flushed.
158 */ 158 */
159 List<Source> _priorityOrder = <Source>[]; 159 List<Source> _priorityOrder = <Source>[];
160 160
161 CacheConsistencyValidatorImpl _cacheConsistencyValidator;
162
161 /** 163 /**
162 * A map from all sources for which there are futures pending to a list of 164 * A map from all sources for which there are futures pending to a list of
163 * the corresponding PendingFuture objects. These sources will be analyzed 165 * the corresponding PendingFuture objects. These sources will be analyzed
164 * in the same way as priority sources, except with higher priority. 166 * in the same way as priority sources, except with higher priority.
165 */ 167 */
166 HashMap<AnalysisTarget, List<PendingFuture>> _pendingFutureTargets = 168 HashMap<AnalysisTarget, List<PendingFuture>> _pendingFutureTargets =
167 new HashMap<AnalysisTarget, List<PendingFuture>>(); 169 new HashMap<AnalysisTarget, List<PendingFuture>>();
168 170
169 /** 171 /**
170 * A table mapping sources to the change notices that are waiting to be 172 * A table mapping sources to the change notices that are waiting to be
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } else { 342 } else {
341 _priorityOrder = sources; 343 _priorityOrder = sources;
342 } 344 }
343 } 345 }
344 for (WorkManager workManager in workManagers) { 346 for (WorkManager workManager in workManagers) {
345 workManager.applyPriorityTargets(_priorityOrder); 347 workManager.applyPriorityTargets(_priorityOrder);
346 } 348 }
347 driver.reset(); 349 driver.reset();
348 } 350 }
349 351
352 CacheConsistencyValidator get cacheConsistencyValidator =>
353 _cacheConsistencyValidator ??= new CacheConsistencyValidatorImpl(this);
354
350 @override 355 @override
351 set contentCache(ContentCache value) { 356 set contentCache(ContentCache value) {
352 _contentCache = value; 357 _contentCache = value;
353 } 358 }
354 359
355 @override 360 @override
356 DeclaredVariables get declaredVariables => _declaredVariables; 361 DeclaredVariables get declaredVariables => _declaredVariables;
357 362
358 @deprecated 363 @deprecated
359 @override 364 @override
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 entry.setState(RESOLVED_UNIT8, CacheState.FLUSHED); 1373 entry.setState(RESOLVED_UNIT8, CacheState.FLUSHED);
1369 entry.setState(RESOLVED_UNIT9, CacheState.FLUSHED); 1374 entry.setState(RESOLVED_UNIT9, CacheState.FLUSHED);
1370 entry.setState(RESOLVED_UNIT10, CacheState.FLUSHED); 1375 entry.setState(RESOLVED_UNIT10, CacheState.FLUSHED);
1371 entry.setState(RESOLVED_UNIT11, CacheState.FLUSHED); 1376 entry.setState(RESOLVED_UNIT11, CacheState.FLUSHED);
1372 entry.setState(RESOLVED_UNIT12, CacheState.FLUSHED); 1377 entry.setState(RESOLVED_UNIT12, CacheState.FLUSHED);
1373 entry.setState(RESOLVED_UNIT13, CacheState.FLUSHED); 1378 entry.setState(RESOLVED_UNIT13, CacheState.FLUSHED);
1374 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED); 1379 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED);
1375 } 1380 }
1376 1381
1377 @override 1382 @override
1378 bool validateCacheConsistency() {
1379 int consistencyCheckStart = JavaSystem.nanoTime();
1380 HashSet<Source> changedSources = new HashSet<Source>();
1381 HashSet<Source> missingSources = new HashSet<Source>();
1382 for (Source source in _privatePartition.sources) {
1383 CacheEntry entry = _privatePartition.get(source);
1384 int sourceTime = getModificationStamp(source);
1385 if (sourceTime != entry.modificationTime) {
1386 changedSources.add(source);
1387 PerformanceStatistics
1388 .cacheConsistencyValidationStatistics.numOfModified++;
1389 }
1390 if (entry.exception != null) {
1391 if (!exists(source)) {
1392 missingSources.add(source);
1393 PerformanceStatistics
1394 .cacheConsistencyValidationStatistics.numOfModified++;
1395 }
1396 }
1397 }
1398 for (Source source in changedSources) {
1399 _sourceChanged(source);
1400 }
1401 int removalCount = 0;
1402 for (Source source in missingSources) {
1403 if (getLibrariesContaining(source).isEmpty &&
1404 getLibrariesDependingOn(source).isEmpty) {
1405 _removeFromCache(source);
1406 removalCount++;
1407 }
1408 }
1409 int consistencyCheckEnd = JavaSystem.nanoTime();
1410 if (changedSources.length > 0 || missingSources.length > 0) {
1411 StringBuffer buffer = new StringBuffer();
1412 buffer.write("Consistency check took ");
1413 buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0);
1414 buffer.writeln(" ms and found");
1415 buffer.write(" ");
1416 buffer.write(changedSources.length);
1417 buffer.writeln(" inconsistent entries");
1418 buffer.write(" ");
1419 buffer.write(missingSources.length);
1420 buffer.write(" missing sources (");
1421 buffer.write(removalCount);
1422 buffer.writeln(" removed");
1423 for (Source source in missingSources) {
1424 buffer.write(" ");
1425 buffer.writeln(source.fullName);
1426 }
1427 _logInformation(buffer.toString());
1428 }
1429 return changedSources.length > 0;
1430 }
1431
1432 @override
1433 void visitContentCache(ContentCacheVisitor visitor) { 1383 void visitContentCache(ContentCacheVisitor visitor) {
1434 _contentCache.accept(visitor); 1384 _contentCache.accept(visitor);
1435 } 1385 }
1436 1386
1437 /** 1387 /**
1438 * Add all of the sources contained in the given source [container] to the 1388 * Add all of the sources contained in the given source [container] to the
1439 * given list of [sources]. 1389 * given list of [sources].
1440 */ 1390 */
1441 void _addSourcesInContainer(List<Source> sources, SourceContainer container) { 1391 void _addSourcesInContainer(List<Source> sources, SourceContainer container) {
1442 for (Source source in _cache.sources) { 1392 for (Source source in _cache.sources) {
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 if (!pendingFuture.evaluate(entry)) { 2044 if (!pendingFuture.evaluate(entry)) {
2095 _context._pendingFutureTargets 2045 _context._pendingFutureTargets
2096 .putIfAbsent(_target, () => <PendingFuture>[]) 2046 .putIfAbsent(_target, () => <PendingFuture>[])
2097 .add(pendingFuture); 2047 .add(pendingFuture);
2098 _context.dartWorkManager.addPriorityResult(_target, _descriptor); 2048 _context.dartWorkManager.addPriorityResult(_target, _descriptor);
2099 } 2049 }
2100 return pendingFuture.future; 2050 return pendingFuture.future;
2101 } 2051 }
2102 } 2052 }
2103 2053
2054 class CacheConsistencyValidatorImpl implements CacheConsistencyValidator {
2055 final AnalysisContextImpl context;
2056
2057 CacheConsistencyValidatorImpl(this.context);
2058
2059 @override
2060 List<Source> getSourcesToComputeModificationTimes() {
2061 List<Source> sources = <Source>[];
2062 for (Source source in context._privatePartition.sources) {
2063 if (context._contentCache.getModificationStamp(source) == null) {
2064 sources.add(source);
2065 }
2066 }
2067 return sources;
2068 }
2069
2070 @override
2071 bool sourceModificationTimesComputed(List<Source> sources, List<int> times) {
2072 int consistencyCheckStart = JavaSystem.nanoTime();
2073 HashSet<Source> changedSources = new HashSet<Source>();
2074 HashSet<Source> missingSources = new HashSet<Source>();
2075 for (int i = 0; i < sources.length; i++) {
2076 Source source = sources[i];
2077 int sourceTime = times[i];
2078 if (sourceTime != null) {
2079 CacheEntry entry = context._privatePartition.get(source);
2080 if (entry != null) {
2081 if (sourceTime != entry.modificationTime) {
2082 changedSources.add(source);
2083 PerformanceStatistics
2084 .cacheConsistencyValidationStatistics.numOfModified++;
2085 }
2086 if (entry.exception != null) {
2087 if (sourceTime == -1) {
2088 missingSources.add(source);
2089 PerformanceStatistics
2090 .cacheConsistencyValidationStatistics.numOfModified++;
2091 }
2092 }
2093 }
2094 }
2095 }
2096 for (Source source in changedSources) {
2097 context._sourceChanged(source);
2098 }
2099 int removalCount = 0;
2100 for (Source source in missingSources) {
2101 if (context.getLibrariesContaining(source).isEmpty &&
2102 context.getLibrariesDependingOn(source).isEmpty) {
2103 context._removeFromCache(source);
2104 removalCount++;
2105 }
2106 }
2107 int consistencyCheckEnd = JavaSystem.nanoTime();
2108 if (changedSources.length > 0 || missingSources.length > 0) {
2109 StringBuffer buffer = new StringBuffer();
2110 buffer.write("Consistency check took ");
2111 buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0);
2112 buffer.writeln(" ms and found");
2113 buffer.write(" ");
2114 buffer.write(changedSources.length);
2115 buffer.writeln(" inconsistent entries");
2116 buffer.write(" ");
2117 buffer.write(missingSources.length);
2118 buffer.write(" missing sources (");
2119 buffer.write(removalCount);
2120 buffer.writeln(" removed");
2121 for (Source source in missingSources) {
2122 buffer.write(" ");
2123 buffer.writeln(source.fullName);
2124 }
2125 context._logInformation(buffer.toString());
2126 }
2127 return changedSources.length > 0;
2128 }
2129 }
2130
2104 /** 2131 /**
2105 * An object that manages the partitions that can be shared between analysis 2132 * An object that manages the partitions that can be shared between analysis
2106 * contexts. 2133 * contexts.
2107 */ 2134 */
2108 class PartitionManager { 2135 class PartitionManager {
2109 /** 2136 /**
2110 * A table mapping SDK's to the partitions used for those SDK's. 2137 * A table mapping SDK's to the partitions used for those SDK's.
2111 */ 2138 */
2112 HashMap<DartSdk, SdkCachePartition> _sdkPartitions = 2139 HashMap<DartSdk, SdkCachePartition> _sdkPartitions =
2113 new HashMap<DartSdk, SdkCachePartition>(); 2140 new HashMap<DartSdk, SdkCachePartition>();
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2266 } 2293 }
2267 DartSdk sdk = factory.dartSdk; 2294 DartSdk sdk = factory.dartSdk;
2268 if (sdk == null) { 2295 if (sdk == null) {
2269 throw new IllegalArgumentException( 2296 throw new IllegalArgumentException(
2270 "The source factory for an SDK analysis context must have a DartUriRes olver"); 2297 "The source factory for an SDK analysis context must have a DartUriRes olver");
2271 } 2298 }
2272 return new AnalysisCache( 2299 return new AnalysisCache(
2273 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); 2300 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
2274 } 2301 }
2275 } 2302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698