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

Side by Side Diff: pkg/analyzer/lib/src/generated/engine.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
« no previous file with comments | « pkg/analyzer/lib/src/context/context.dart ('k') | pkg/analyzer/test/generated/engine_test.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine; 8 library engine;
9 9
10 import 'dart:async'; 10 import 'dart:async';
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 void setChangedContents( 856 void setChangedContents(
857 Source source, String contents, int offset, int oldLength, int newLength); 857 Source source, String contents, int offset, int oldLength, int newLength);
858 858
859 /** 859 /**
860 * Set the contents of the given [source] to the given [contents] and mark the 860 * Set the contents of the given [source] to the given [contents] and mark the
861 * source as having changed. This has the effect of overriding the default 861 * source as having changed. This has the effect of overriding the default
862 * contents of the source. If the contents are `null` the override is removed 862 * contents of the source. If the contents are `null` the override is removed
863 * so that the default contents will be returned. 863 * so that the default contents will be returned.
864 */ 864 */
865 void setContents(Source source, String contents); 865 void setContents(Source source, String contents);
866
867 /**
868 * Check the cache for any invalid entries (entries whose modification time
869 * does not match the modification time of the source associated with the
870 * entry). Invalid entries will be marked as invalid so that the source will
871 * be re-analyzed. Return `true` if at least one entry was invalid.
872 */
873 bool validateCacheConsistency();
866 } 874 }
867 875
868 /** 876 /**
869 * An [AnalysisContext]. 877 * An [AnalysisContext].
870 */ 878 */
871 class AnalysisContextImpl implements InternalAnalysisContext { 879 class AnalysisContextImpl implements InternalAnalysisContext {
872 /** 880 /**
873 * The difference between the maximum cache size and the maximum priority 881 * The difference between the maximum cache size and the maximum priority
874 * order size. The priority list must be capped so that it is less than the 882 * order size. The priority list must be capped so that it is less than the
875 * cache size. Failure to do so can result in an infinite loop in 883 * cache size. Failure to do so can result in an infinite loop in
(...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 @override 2271 @override
2264 AnalysisResult performAnalysisTask() { 2272 AnalysisResult performAnalysisTask() {
2265 if (_TRACE_PERFORM_TASK) { 2273 if (_TRACE_PERFORM_TASK) {
2266 print("----------------------------------------"); 2274 print("----------------------------------------");
2267 } 2275 }
2268 return PerformanceStatistics.performAnaysis.makeCurrentWhile(() { 2276 return PerformanceStatistics.performAnaysis.makeCurrentWhile(() {
2269 int getStart = JavaSystem.currentTimeMillis(); 2277 int getStart = JavaSystem.currentTimeMillis();
2270 AnalysisTask task = PerformanceStatistics.nextTask 2278 AnalysisTask task = PerformanceStatistics.nextTask
2271 .makeCurrentWhile(() => nextAnalysisTask); 2279 .makeCurrentWhile(() => nextAnalysisTask);
2272 int getEnd = JavaSystem.currentTimeMillis(); 2280 int getEnd = JavaSystem.currentTimeMillis();
2273 if (task == null && _validateCacheConsistency()) {
2274 task = nextAnalysisTask;
2275 }
2276 if (task == null) { 2281 if (task == null) {
2277 _validateLastIncrementalResolutionResult(); 2282 _validateLastIncrementalResolutionResult();
2278 if (_performAnalysisTaskStopwatch != null) { 2283 if (_performAnalysisTaskStopwatch != null) {
2279 AnalysisEngine.instance.instrumentationService.logPerformance( 2284 AnalysisEngine.instance.instrumentationService.logPerformance(
2280 AnalysisPerformanceKind.FULL, _performAnalysisTaskStopwatch, 2285 AnalysisPerformanceKind.FULL, _performAnalysisTaskStopwatch,
2281 'context_id=$_id'); 2286 'context_id=$_id');
2282 _performAnalysisTaskStopwatch = null; 2287 _performAnalysisTaskStopwatch = null;
2283 } 2288 }
2284 return new AnalysisResult( 2289 return new AnalysisResult(
2285 _getChangeNotices(true), getEnd - getStart, null, -1); 2290 _getChangeNotices(true), getEnd - getStart, null, -1);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
2560 if (source.isInSystemLibrary) { 2565 if (source.isInSystemLibrary) {
2561 return _generateSdkErrors; 2566 return _generateSdkErrors;
2562 } else if (!dartEntry.explicitlyAdded) { 2567 } else if (!dartEntry.explicitlyAdded) {
2563 return _generateImplicitErrors; 2568 return _generateImplicitErrors;
2564 } else { 2569 } else {
2565 return true; 2570 return true;
2566 } 2571 }
2567 } 2572 }
2568 2573
2569 @override 2574 @override
2575 bool validateCacheConsistency() {
2576 int consistencyCheckStart = JavaSystem.nanoTime();
2577 List<Source> changedSources = new List<Source>();
2578 List<Source> missingSources = new List<Source>();
2579 MapIterator<Source, SourceEntry> iterator = _cache.iterator();
2580 while (iterator.moveNext()) {
2581 Source source = iterator.key;
2582 SourceEntry sourceEntry = iterator.value;
2583 int sourceTime = getModificationStamp(source);
2584 if (sourceTime != sourceEntry.modificationTime) {
2585 changedSources.add(source);
2586 }
2587 if (sourceEntry.exception != null) {
2588 if (!exists(source)) {
2589 missingSources.add(source);
2590 }
2591 }
2592 }
2593 int count = changedSources.length;
2594 for (int i = 0; i < count; i++) {
2595 _sourceChanged(changedSources[i]);
2596 }
2597 int removalCount = 0;
2598 for (Source source in missingSources) {
2599 if (getLibrariesContaining(source).isEmpty &&
2600 getLibrariesDependingOn(source).isEmpty) {
2601 _cache.remove(source);
2602 removalCount++;
2603 }
2604 }
2605 int consistencyCheckEnd = JavaSystem.nanoTime();
2606 if (changedSources.length > 0 || missingSources.length > 0) {
2607 StringBuffer buffer = new StringBuffer();
2608 buffer.write("Consistency check took ");
2609 buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0);
2610 buffer.writeln(" ms and found");
2611 buffer.write(" ");
2612 buffer.write(changedSources.length);
2613 buffer.writeln(" inconsistent entries");
2614 buffer.write(" ");
2615 buffer.write(missingSources.length);
2616 buffer.write(" missing sources (");
2617 buffer.write(removalCount);
2618 buffer.writeln(" removed");
2619 for (Source source in missingSources) {
2620 buffer.write(" ");
2621 buffer.writeln(source.fullName);
2622 }
2623 _logInformation(buffer.toString());
2624 }
2625 return changedSources.length > 0;
2626 }
2627
2628 @override
2570 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, 2629 void visitCacheItems(void callback(Source source, SourceEntry dartEntry,
2571 DataDescriptor rowDesc, CacheState state)) { 2630 DataDescriptor rowDesc, CacheState state)) {
2572 bool hintsEnabled = _options.hint; 2631 bool hintsEnabled = _options.hint;
2573 bool lintsEnabled = _options.lint; 2632 bool lintsEnabled = _options.lint;
2574 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); 2633 MapIterator<Source, SourceEntry> iterator = _cache.iterator();
2575 while (iterator.moveNext()) { 2634 while (iterator.moveNext()) {
2576 Source source = iterator.key; 2635 Source source = iterator.key;
2577 SourceEntry sourceEntry = iterator.value; 2636 SourceEntry sourceEntry = iterator.value;
2578 for (DataDescriptor descriptor in sourceEntry.descriptors) { 2637 for (DataDescriptor descriptor in sourceEntry.descriptors) {
2579 if (descriptor == DartEntry.SOURCE_KIND) { 2638 if (descriptor == DartEntry.SOURCE_KIND) {
(...skipping 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after
4026 bool _isTooBigHtmlSourceEntry(Source source, SourceEntry sourceEntry) => 4085 bool _isTooBigHtmlSourceEntry(Source source, SourceEntry sourceEntry) =>
4027 false; 4086 false;
4028 4087
4029 /** 4088 /**
4030 * Log the given debugging [message]. 4089 * Log the given debugging [message].
4031 */ 4090 */
4032 void _logInformation(String message) { 4091 void _logInformation(String message) {
4033 AnalysisEngine.instance.logger.logInformation(message); 4092 AnalysisEngine.instance.logger.logInformation(message);
4034 } 4093 }
4035 4094
4036 /**
4037 * Notify all of the analysis listeners that a task is about to be performed.
4038 */
4039 void _notifyAboutToPerformTask(String taskDescription) {
4040 int count = _listeners.length;
4041 for (int i = 0; i < count; i++) {
4042 _listeners[i].aboutToPerformTask(this, taskDescription);
4043 }
4044 }
4045
4046 // /** 4095 // /**
4047 // * Notify all of the analysis listeners that the given source is no longer i ncluded in the set of 4096 // * Notify all of the analysis listeners that the given source is no longer i ncluded in the set of
4048 // * sources that are being analyzed. 4097 // * sources that are being analyzed.
4049 // * 4098 // *
4050 // * @param source the source that is no longer being analyzed 4099 // * @param source the source that is no longer being analyzed
4051 // */ 4100 // */
4052 // void _notifyExcludedSource(Source source) { 4101 // void _notifyExcludedSource(Source source) {
4053 // int count = _listeners.length; 4102 // int count = _listeners.length;
4054 // for (int i = 0; i < count; i++) { 4103 // for (int i = 0; i < count; i++) {
4055 // _listeners[i].excludedSource(this, source); 4104 // _listeners[i].excludedSource(this, source);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
4115 // * @param unit the result of resolving the source 4164 // * @param unit the result of resolving the source
4116 // */ 4165 // */
4117 // void _notifyResolvedHtml(Source source, ht.HtmlUnit unit) { 4166 // void _notifyResolvedHtml(Source source, ht.HtmlUnit unit) {
4118 // int count = _listeners.length; 4167 // int count = _listeners.length;
4119 // for (int i = 0; i < count; i++) { 4168 // for (int i = 0; i < count; i++) {
4120 // _listeners[i].resolvedHtml(this, source, unit); 4169 // _listeners[i].resolvedHtml(this, source, unit);
4121 // } 4170 // }
4122 // } 4171 // }
4123 4172
4124 /** 4173 /**
4174 * Notify all of the analysis listeners that a task is about to be performed.
4175 */
4176 void _notifyAboutToPerformTask(String taskDescription) {
4177 int count = _listeners.length;
4178 for (int i = 0; i < count; i++) {
4179 _listeners[i].aboutToPerformTask(this, taskDescription);
4180 }
4181 }
4182
4183 /**
4125 * Notify all of the analysis listeners that the errors associated with the 4184 * Notify all of the analysis listeners that the errors associated with the
4126 * given [source] has been updated to the given [errors]. 4185 * given [source] has been updated to the given [errors].
4127 */ 4186 */
4128 void _notifyErrors( 4187 void _notifyErrors(
4129 Source source, List<AnalysisError> errors, LineInfo lineInfo) { 4188 Source source, List<AnalysisError> errors, LineInfo lineInfo) {
4130 int count = _listeners.length; 4189 int count = _listeners.length;
4131 for (int i = 0; i < count; i++) { 4190 for (int i = 0; i < count; i++) {
4132 _listeners[i].computedErrors(this, source, errors, lineInfo); 4191 _listeners[i].computedErrors(this, source, errors, lineInfo);
4133 } 4192 }
4134 } 4193 }
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
4725 LineInfo lineInfo = getLineInfo(unitSource); 4784 LineInfo lineInfo = getLineInfo(unitSource);
4726 ChangeNoticeImpl notice = getNotice(unitSource); 4785 ChangeNoticeImpl notice = getNotice(unitSource);
4727 notice.resolvedDartUnit = oldUnit; 4786 notice.resolvedDartUnit = oldUnit;
4728 notice.setErrors(dartEntry.allErrors, lineInfo); 4787 notice.setErrors(dartEntry.allErrors, lineInfo);
4729 } 4788 }
4730 // OK 4789 // OK
4731 return true; 4790 return true;
4732 }); 4791 });
4733 } 4792 }
4734 4793
4735 /**
4736 * Check the cache for any invalid entries (entries whose modification time
4737 * does not match the modification time of the source associated with the
4738 * entry). Invalid entries will be marked as invalid so that the source will
4739 * be re-analyzed. Return `true` if at least one entry was invalid.
4740 */
4741 bool _validateCacheConsistency() {
4742 int consistencyCheckStart = JavaSystem.nanoTime();
4743 List<Source> changedSources = new List<Source>();
4744 List<Source> missingSources = new List<Source>();
4745 MapIterator<Source, SourceEntry> iterator = _cache.iterator();
4746 while (iterator.moveNext()) {
4747 Source source = iterator.key;
4748 SourceEntry sourceEntry = iterator.value;
4749 int sourceTime = getModificationStamp(source);
4750 if (sourceTime != sourceEntry.modificationTime) {
4751 changedSources.add(source);
4752 }
4753 if (sourceEntry.exception != null) {
4754 if (!exists(source)) {
4755 missingSources.add(source);
4756 }
4757 }
4758 }
4759 int count = changedSources.length;
4760 for (int i = 0; i < count; i++) {
4761 _sourceChanged(changedSources[i]);
4762 }
4763 int removalCount = 0;
4764 for (Source source in missingSources) {
4765 if (getLibrariesContaining(source).isEmpty &&
4766 getLibrariesDependingOn(source).isEmpty) {
4767 _cache.remove(source);
4768 removalCount++;
4769 }
4770 }
4771 int consistencyCheckEnd = JavaSystem.nanoTime();
4772 if (changedSources.length > 0 || missingSources.length > 0) {
4773 StringBuffer buffer = new StringBuffer();
4774 buffer.write("Consistency check took ");
4775 buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0);
4776 buffer.writeln(" ms and found");
4777 buffer.write(" ");
4778 buffer.write(changedSources.length);
4779 buffer.writeln(" inconsistent entries");
4780 buffer.write(" ");
4781 buffer.write(missingSources.length);
4782 buffer.write(" missing sources (");
4783 buffer.write(removalCount);
4784 buffer.writeln(" removed");
4785 for (Source source in missingSources) {
4786 buffer.write(" ");
4787 buffer.writeln(source.fullName);
4788 }
4789 _logInformation(buffer.toString());
4790 }
4791 return changedSources.length > 0;
4792 }
4793
4794 void _validateLastIncrementalResolutionResult() { 4794 void _validateLastIncrementalResolutionResult() {
4795 if (incrementalResolutionValidation_lastUnitSource == null || 4795 if (incrementalResolutionValidation_lastUnitSource == null ||
4796 incrementalResolutionValidation_lastLibrarySource == null || 4796 incrementalResolutionValidation_lastLibrarySource == null ||
4797 incrementalResolutionValidation_lastUnit == null) { 4797 incrementalResolutionValidation_lastUnit == null) {
4798 return; 4798 return;
4799 } 4799 }
4800 CompilationUnit fullUnit = getResolvedCompilationUnit2( 4800 CompilationUnit fullUnit = getResolvedCompilationUnit2(
4801 incrementalResolutionValidation_lastUnitSource, 4801 incrementalResolutionValidation_lastUnitSource,
4802 incrementalResolutionValidation_lastLibrarySource); 4802 incrementalResolutionValidation_lastLibrarySource);
4803 if (fullUnit != null) { 4803 if (fullUnit != null) {
(...skipping 7017 matching lines...) Expand 10 before | Expand all | Expand 10 after
11821 PendingFuture pendingFuture = 11821 PendingFuture pendingFuture =
11822 new PendingFuture<T>(_context, source, computeValue); 11822 new PendingFuture<T>(_context, source, computeValue);
11823 if (!pendingFuture.evaluate(sourceEntry)) { 11823 if (!pendingFuture.evaluate(sourceEntry)) {
11824 _context._pendingFutureSources 11824 _context._pendingFutureSources
11825 .putIfAbsent(source, () => <PendingFuture>[]) 11825 .putIfAbsent(source, () => <PendingFuture>[])
11826 .add(pendingFuture); 11826 .add(pendingFuture);
11827 } 11827 }
11828 return pendingFuture.future; 11828 return pendingFuture.future;
11829 } 11829 }
11830 } 11830 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/context/context.dart ('k') | pkg/analyzer/test/generated/engine_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698