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

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

Issue 1195183002: Move cache consistency validation into Analysis Server. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Rework the CL. Created 5 years, 6 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/instrumentation/instrumentation.dart'; 10 import 'package:analyzer/instrumentation/instrumentation.dart';
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 // model. 1044 // model.
1045 throw new UnimplementedError( 1045 throw new UnimplementedError(
1046 'Not supported in the new task model; use parseHtmlDocument instead.'); 1046 'Not supported in the new task model; use parseHtmlDocument instead.');
1047 } 1047 }
1048 1048
1049 @override 1049 @override
1050 AnalysisResult performAnalysisTask() { 1050 AnalysisResult performAnalysisTask() {
1051 return PerformanceStatistics.performAnaysis.makeCurrentWhile(() { 1051 return PerformanceStatistics.performAnaysis.makeCurrentWhile(() {
1052 _evaluatePendingFutures(); 1052 _evaluatePendingFutures();
1053 bool done = !driver.performAnalysisTask(); 1053 bool done = !driver.performAnalysisTask();
1054 if (done) {
1055 done = !_validateCacheConsistency();
1056 }
1057 List<ChangeNotice> notices = _getChangeNotices(done); 1054 List<ChangeNotice> notices = _getChangeNotices(done);
1058 if (notices != null) { 1055 if (notices != null) {
1059 int noticeCount = notices.length; 1056 int noticeCount = notices.length;
1060 for (int i = 0; i < noticeCount; i++) { 1057 for (int i = 0; i < noticeCount; i++) {
1061 ChangeNotice notice = notices[i]; 1058 ChangeNotice notice = notices[i];
1062 _notifyErrors(notice.source, notice.errors, notice.lineInfo); 1059 _notifyErrors(notice.source, notice.errors, notice.lineInfo);
1063 } 1060 }
1064 } 1061 }
1065 return new AnalysisResult(notices, -1, '', -1); 1062 return new AnalysisResult(notices, -1, '', -1);
1066 }); 1063 });
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 if (source.isInSystemLibrary) { 1178 if (source.isInSystemLibrary) {
1182 return _options.generateSdkErrors; 1179 return _options.generateSdkErrors;
1183 } else if (!entry.explicitlyAdded) { 1180 } else if (!entry.explicitlyAdded) {
1184 return _options.generateImplicitErrors; 1181 return _options.generateImplicitErrors;
1185 } else { 1182 } else {
1186 return true; 1183 return true;
1187 } 1184 }
1188 } 1185 }
1189 1186
1190 @override 1187 @override
1188 bool validateCacheConsistency() {
1189 int consistencyCheckStart = JavaSystem.nanoTime();
1190 HashSet<Source> changedSources = new HashSet<Source>();
1191 HashSet<Source> missingSources = new HashSet<Source>();
1192 for (Source source in _cache.sources) {
1193 CacheEntry entry = _cache.get(source);
1194 int sourceTime = getModificationStamp(source);
1195 if (sourceTime != entry.modificationTime) {
1196 changedSources.add(source);
1197 }
1198 if (entry.exception != null) {
1199 if (!exists(source)) {
1200 missingSources.add(source);
1201 }
1202 }
1203 }
1204 for (Source source in changedSources) {
1205 _sourceChanged(source);
1206 }
1207 int removalCount = 0;
1208 for (Source source in missingSources) {
1209 if (getLibrariesContaining(source).isEmpty &&
1210 getLibrariesDependingOn(source).isEmpty) {
1211 _cache.remove(source);
1212 removalCount++;
1213 }
1214 }
1215 int consistencyCheckEnd = JavaSystem.nanoTime();
1216 if (changedSources.length > 0 || missingSources.length > 0) {
1217 StringBuffer buffer = new StringBuffer();
1218 buffer.write("Consistency check took ");
1219 buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0);
1220 buffer.writeln(" ms and found");
1221 buffer.write(" ");
1222 buffer.write(changedSources.length);
1223 buffer.writeln(" inconsistent entries");
1224 buffer.write(" ");
1225 buffer.write(missingSources.length);
1226 buffer.write(" missing sources (");
1227 buffer.write(removalCount);
1228 buffer.writeln(" removed");
1229 for (Source source in missingSources) {
1230 buffer.write(" ");
1231 buffer.writeln(source.fullName);
1232 }
1233 _logInformation(buffer.toString());
1234 }
1235 return changedSources.length > 0;
1236 }
1237
1238 @override
1191 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, 1239 void visitCacheItems(void callback(Source source, SourceEntry dartEntry,
1192 DataDescriptor rowDesc, CacheState state)) { 1240 DataDescriptor rowDesc, CacheState state)) {
1193 // TODO(brianwilkerson) Figure out where this is used and either remove it 1241 // TODO(brianwilkerson) Figure out where this is used and either remove it
1194 // or adjust the call sites to use CacheEntry's. 1242 // or adjust the call sites to use CacheEntry's.
1195 // bool hintsEnabled = _options.hint; 1243 // bool hintsEnabled = _options.hint;
1196 // bool lintsEnabled = _options.lint; 1244 // bool lintsEnabled = _options.lint;
1197 // MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator() ; 1245 // MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator() ;
1198 // while (iterator.moveNext()) { 1246 // while (iterator.moveNext()) {
1199 // Source source = iterator.key; 1247 // Source source = iterator.key;
1200 // cache.CacheEntry entry = iterator.value; 1248 // cache.CacheEntry entry = iterator.value;
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 notice.resolvedDartUnit = oldUnit; 1812 notice.resolvedDartUnit = oldUnit;
1765 AnalysisErrorInfo errorInfo = getErrors(unitSource); 1813 AnalysisErrorInfo errorInfo = getErrors(unitSource);
1766 notice.setErrors(errorInfo.errors, errorInfo.lineInfo); 1814 notice.setErrors(errorInfo.errors, errorInfo.lineInfo);
1767 } 1815 }
1768 // schedule 1816 // schedule
1769 dartWorkManager.unitIncrementallyResolved(librarySource, unitSource); 1817 dartWorkManager.unitIncrementallyResolved(librarySource, unitSource);
1770 // OK 1818 // OK
1771 return true; 1819 return true;
1772 }); 1820 });
1773 } 1821 }
1774
1775 /**
1776 * Check the cache for any invalid entries (entries whose modification time
1777 * does not match the modification time of the source associated with the
1778 * entry). Invalid entries will be marked as invalid so that the source will
1779 * be re-analyzed. Return `true` if at least one entry was invalid.
1780 */
1781 bool _validateCacheConsistency() {
1782 int consistencyCheckStart = JavaSystem.nanoTime();
1783 HashSet<Source> changedSources = new HashSet<Source>();
1784 HashSet<Source> missingSources = new HashSet<Source>();
1785 for (Source source in _cache.sources) {
1786 CacheEntry entry = _cache.get(source);
1787 int sourceTime = getModificationStamp(source);
1788 if (sourceTime != entry.modificationTime) {
1789 changedSources.add(source);
1790 }
1791 if (entry.exception != null) {
1792 if (!exists(source)) {
1793 missingSources.add(source);
1794 }
1795 }
1796 }
1797 for (Source source in changedSources) {
1798 _sourceChanged(source);
1799 }
1800 int removalCount = 0;
1801 for (Source source in missingSources) {
1802 if (getLibrariesContaining(source).isEmpty &&
1803 getLibrariesDependingOn(source).isEmpty) {
1804 _cache.remove(source);
1805 removalCount++;
1806 }
1807 }
1808 int consistencyCheckEnd = JavaSystem.nanoTime();
1809 if (changedSources.length > 0 || missingSources.length > 0) {
1810 StringBuffer buffer = new StringBuffer();
1811 buffer.write("Consistency check took ");
1812 buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0);
1813 buffer.writeln(" ms and found");
1814 buffer.write(" ");
1815 buffer.write(changedSources.length);
1816 buffer.writeln(" inconsistent entries");
1817 buffer.write(" ");
1818 buffer.write(missingSources.length);
1819 buffer.write(" missing sources (");
1820 buffer.write(removalCount);
1821 buffer.writeln(" removed");
1822 for (Source source in missingSources) {
1823 buffer.write(" ");
1824 buffer.writeln(source.fullName);
1825 }
1826 _logInformation(buffer.toString());
1827 }
1828 return changedSources.length > 0;
1829 }
1830 } 1822 }
1831 1823
1832 /** 1824 /**
1833 * An object that manages the partitions that can be shared between analysis 1825 * An object that manages the partitions that can be shared between analysis
1834 * contexts. 1826 * contexts.
1835 */ 1827 */
1836 class PartitionManager { 1828 class PartitionManager {
1837 /** 1829 /**
1838 * A table mapping SDK's to the partitions used for those SDK's. 1830 * A table mapping SDK's to the partitions used for those SDK's.
1839 */ 1831 */
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 new PendingFuture<T>(_context, target, computeValue); 2000 new PendingFuture<T>(_context, target, computeValue);
2009 if (!pendingFuture.evaluate(entry)) { 2001 if (!pendingFuture.evaluate(entry)) {
2010 _context._pendingFutureTargets 2002 _context._pendingFutureTargets
2011 .putIfAbsent(target, () => <PendingFuture>[]) 2003 .putIfAbsent(target, () => <PendingFuture>[])
2012 .add(pendingFuture); 2004 .add(pendingFuture);
2013 scheduleComputation(); 2005 scheduleComputation();
2014 } 2006 }
2015 return pendingFuture.future; 2007 return pendingFuture.future;
2016 } 2008 }
2017 } 2009 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/operation/operation_analysis.dart ('k') | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698