Skip to content

Commit 7bfc198

Browse files
authored
Merge pull request #232 from mrubanov/master
Revert the demand load memory check
2 parents 9d86abc + 353f741 commit 7bfc198

File tree

5 files changed

+18
-86
lines changed

5 files changed

+18
-86
lines changed

com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/DefaultBuilderResourceLoadStrategy.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
/**
21-
* Determine when to stop loading resources during the build.
21+
* Determine when to stop loading resources during build.
2222
*/
2323
@SuppressWarnings("nls")
2424
// CHECKSTYLE:CONSTANTS-OFF
@@ -27,10 +27,10 @@ public class DefaultBuilderResourceLoadStrategy implements IBuilderResourceLoadS
2727
/** Class-wide logger. */
2828
private static final Logger LOGGER = Logger.getLogger(DefaultBuilderResourceLoadStrategy.class);
2929

30-
/** Property for setting target free memory value. (in megabytes). */
30+
/** Default value for target free memory in megabytes. */
3131
private static final String TARGET_FREE_MEMORY_PROPERTY = "com.avaloq.tools.ddk.xtext.builder.targetFreeMemory"; //$NON-NLS-1$
3232

33-
/** Property for setting minimum free memory value. (in megabytes) */
33+
/** Property for setting minimum free memory setting. */
3434
private static final String MIN_FREE_MEMORY_PROPERTY = "com.avaloq.tools.ddk.xtext.builder.minFreeMemory"; //$NON-NLS-1$
3535

3636
/** Property for setting the maximal cluster size. */
@@ -51,16 +51,16 @@ public class DefaultBuilderResourceLoadStrategy implements IBuilderResourceLoadS
5151
/** Default value for MINIMUM_FREE_MEMORY. */
5252
private static final long DEFAULT_MIN_FREE_MEMORY = 100 * ONE_MEGABYTE;
5353

54-
/** Cluster will always end if memory falls below this threshold. */
54+
/** Cluster will always end if memory falls bellow this threshold. */
5555
private static final long MINIMUM_FREE_MEMORY = getMinimumFreeMemory();
5656

57-
/** Attempt to cap a cluster when memory reaches this limit, as long as we processed more than the minimum cluster size. */
57+
/** Attempt to cap cluster when memory reaches this limit, as long as we processed more than the minimum cluster size. */
5858
private static final long TARGET_FREE_MEMORY = getTargetFreeMemory();
5959

6060
/** Cluster size. */
6161
@Inject(optional = true)
6262
@Named("org.eclipse.xtext.builder.clustering.ClusteringBuilderState.clusterSize")
63-
private int clusterSize = 50; // NOPMD Cannot be static because of the way Guice injection works.
63+
private int clusterSize = 20; // NOPMD Cannot be static because of the way Guice injection works.
6464

6565
/** The Java runtime; needed to get access to memory usage data. */
6666
private static final Runtime RUNTIME = Runtime.getRuntime();
@@ -100,6 +100,7 @@ public void setClusterSize(final int clusterSize) {
100100
this.clusterSize = clusterSize;
101101
}
102102

103+
/** {@inheritDoc} */
103104
@Override
104105
public boolean mayProcessAnotherResource(final ResourceSet resourceSet, final int alreadyProcessed) {
105106
if (alreadyProcessed == 0) {
@@ -114,13 +115,13 @@ public boolean mayProcessAnotherResource(final ResourceSet resourceSet, final in
114115
return false;
115116
}
116117

117-
if (isMemoryLimitReached()) {
118+
final long freeMemory = RUNTIME.freeMemory();
119+
if (freeMemory < MINIMUM_FREE_MEMORY) {
118120
return false;
119121
} else if (alreadyProcessed < clusterSize) {
120122
return true; // Process at least up to cluster size
121123
}
122124

123-
final long freeMemory = RUNTIME.freeMemory();
124125
if (freeMemory < TARGET_FREE_MEMORY) {
125126
// Running GC here might free memory, but would not significantly speed up processing.
126127
// We may use slightly smaller clusters than strictly necessary without GC, though.
@@ -133,10 +134,4 @@ public boolean mayProcessAnotherResource(final ResourceSet resourceSet, final in
133134
}
134135
return true; // Keep on loading resources into this resource set
135136
}
136-
137-
@Override
138-
public boolean isMemoryLimitReached() {
139-
return RUNTIME.freeMemory() < MINIMUM_FREE_MEMORY;
140-
}
141-
142137
}

com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/DemandLoadFailedException.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/IBuilderResourceLoadStrategy.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public interface IBuilderResourceLoadStrategy {
2323

2424
/**
25-
* Determine whether the builder may process yet another resource.
25+
* Determine whether the builder may, in its second phase, process yet another resource.
2626
*
2727
* @param resourceSet
2828
* The builder's resource set, containing all currently loaded resources.
@@ -32,11 +32,4 @@ public interface IBuilderResourceLoadStrategy {
3232
*/
3333
boolean mayProcessAnotherResource(ResourceSet resourceSet, int alreadyProcessed);
3434

35-
/**
36-
* Checks whether the builder has reached the minimal amount of free memory, which prevents further progress without clearing the resource set.
37-
*
38-
* @return {@code true} if the described condition is met, {@code false} otherwise
39-
*/
40-
boolean isMemoryLimitReached();
41-
4235
}

com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/Messages.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
//CHECKSTYLE:OFF
1717
public class Messages extends NLS {
18-
1918
private static final String BUNDLE_NAME = "com.avaloq.tools.ddk.xtext.builder.messages"; //$NON-NLS-1$
20-
2119
public static String MonitoredClusteringBuilderState_CANNOT_LOAD_RESOURCE;
2220
public static String MonitoredClusteringBuilderState_NO_MORE_RESOURCES;
2321
public static String MonitoredClusteringBuilderState_PHASE_ONE_DONE;

com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/MonitoredClusteringBuilderState.java

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -852,14 +852,11 @@ protected boolean recordDeltaAsNew(final Delta newDelta) {
852852
* The progress monitor used for user feedback
853853
* @return the list of {@link URI}s of loaded resources to be processed in the second phase
854854
*/
855-
private List<URI> writeResources(final Collection<URI> toWrite, final BuildData buildData, final IResourceDescriptions oldState, final CurrentDescriptions newState, final IProgressMonitor monitor) { // NOPMD
855+
private List<URI> writeResources(final Collection<URI> toWrite, final BuildData buildData, final IResourceDescriptions oldState, final CurrentDescriptions newState, final IProgressMonitor monitor) {
856856
ResourceSet resourceSet = buildData.getResourceSet();
857857
IProject currentProject = getBuiltProject(buildData);
858-
List<URI> toBuild = Lists.newArrayList();
859-
858+
List<URI> toBuild = Lists.newLinkedList();
860859
IResourceLoader.LoadOperation loadOperation = null;
861-
URI resourceToRetry = null;
862-
863860
try {
864861
int resourcesToWriteSize = toWrite.size();
865862
int index = 1;
@@ -869,23 +866,16 @@ private List<URI> writeResources(final Collection<URI> toWrite, final BuildData
869866

870867
// Not using the loadingStrategy here; seems to work fine with a reasonable clusterSize (20 by default), even with
871868
// large resources and "scarce" memory (say, about 500MB).
872-
while (loadOperation.hasNext() || resourceToRetry != null) {
869+
while (loadOperation.hasNext()) {
873870
if (monitor.isCanceled()) {
874871
loadOperation.cancel();
875872
throw new OperationCanceledException();
876873
}
877-
878874
URI uri = null;
879875
Resource resource = null;
880876
try {
881-
if (resourceToRetry == null) {
882-
resource = addResource(loadOperation.next().getResource(), resourceSet);
883-
} else {
884-
resource = resourceSet.getResource(resourceToRetry, true);
885-
resourceToRetry = null;
886-
}
877+
resource = addResource(loadOperation.next().getResource(), resourceSet);
887878
uri = resource.getURI();
888-
889879
final Object[] bindings = {Integer.valueOf(index), Integer.valueOf(resourcesToWriteSize), uri.fileExtension(), URI.decode(uri.lastSegment())};
890880
monitor.subTask(NLS.bind(Messages.MonitoredClusteringBuilderState_WRITE_ONE_DESCRIPTION, bindings));
891881
traceSet.started(ResourceIndexingEvent.class, uri);
@@ -901,11 +891,6 @@ private List<URI> writeResources(final Collection<URI> toWrite, final BuildData
901891
newState.register(intermediateDelta);
902892
toBuild.add(uri);
903893
}
904-
} catch (final DemandLoadFailedException e) {
905-
// Demand load failed because of memory shortage, save the uri to process again in the next cluster
906-
// Resource set will be cleared at the end of this loop iteration
907-
resourceToRetry = uri;
908-
LOGGER.info("Demand load failed during resource indexing: " + resourceToRetry); //$NON-NLS-1$
909894
} catch (final WrappedException ex) {
910895
pollForCancellation(monitor);
911896
if (uri == null && ex instanceof LoadOperationException) { // NOPMD
@@ -940,13 +925,10 @@ private List<URI> writeResources(final Collection<URI> toWrite, final BuildData
940925
monitor.worked(1);
941926
}
942927

943-
if (!loadingStrategy.mayProcessAnotherResource(resourceSet, resourceSet.getResources().size()) || resourceToRetry != null) {
928+
if (!loadingStrategy.mayProcessAnotherResource(resourceSet, resourceSet.getResources().size())) {
944929
clearResourceSet(resourceSet);
945930
}
946-
947-
if (resourceToRetry == null) {
948-
index++;
949-
}
931+
index++;
950932
}
951933
} finally {
952934
if (loadOperation != null) {
@@ -956,32 +938,17 @@ private List<URI> writeResources(final Collection<URI> toWrite, final BuildData
956938
return toBuild;
957939
}
958940

959-
/**
960-
* Writes resources descriptions to the database.
961-
*
962-
* @param buildData
963-
* builder's data, must not be {@code null}
964-
* @param oldState
965-
* represents old index state, must not be {@code null}
966-
* @param newState
967-
* represents the new index state, must not be {@code null}
968-
* @param newData
969-
* new resource descriptions, must not be {@code null}
970-
* @param monitor
971-
* progress monitor, must not be {@code null}
972-
*/
941+
/** {@inheritDoc} */
973942
protected void writeNewResourceDescriptions(final BuildData buildData, final IResourceDescriptions oldState, final CurrentDescriptions newState, final ResourceDescriptionsData newData, final IProgressMonitor monitor) {
974943
final List<List<URI>> toWriteGroups = phaseOneBuildSorter.sort(buildData.getToBeUpdated(), oldState);
944+
final List<URI> toBuild = Lists.newLinkedList();
975945
ResourceSet resourceSet = buildData.getResourceSet();
976946
BuildPhases.setIndexing(resourceSet, true);
977-
978947
int totalSize = 0;
979948
for (List<URI> group : toWriteGroups) {
980949
totalSize = totalSize + group.size();
981950
}
982-
983951
final SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.MonitoredClusteringBuilderState_WRITE_DESCRIPTIONS, totalSize);
984-
final List<URI> toBuild = Lists.newArrayListWithCapacity(totalSize);
985952

986953
try {
987954
traceSet.started(BuildIndexingEvent.class);

0 commit comments

Comments
 (0)