1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-12 02:35:37 +02:00

[255390] memory checking

This commit is contained in:
David McKnight 2008-12-04 21:31:11 +00:00
parent bb0ad05d71
commit 24908d60f5

View file

@ -20,6 +20,7 @@
* Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers * Martin Oberhuber (Wind River) - [199854][api] Improve error reporting for archive handlers
* David McKnight (IBM) - [250168] handle malformed binary and always resolve canonical paths * David McKnight (IBM) - [250168] handle malformed binary and always resolve canonical paths
* David McKnight (IBM) - [250168] update to just search file of canonical paths (not symbolic links) * David McKnight (IBM) - [250168] update to just search file of canonical paths (not symbolic links)
* David McKnight (IBM) - [255390] memory checking
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.filesystem; package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
@ -27,7 +28,6 @@ package org.eclipse.rse.internal.dstore.universal.miners.filesystem;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.HashSet; import java.util.HashSet;
@ -35,6 +35,7 @@ import org.eclipse.dstore.core.model.DE;
import org.eclipse.dstore.core.model.DataElement; import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.dstore.core.model.DataStore; import org.eclipse.dstore.core.model.DataStore;
import org.eclipse.dstore.core.server.SecuredThread; import org.eclipse.dstore.core.server.SecuredThread;
import org.eclipse.dstore.core.server.SystemServiceManager;
import org.eclipse.dstore.core.util.StringCompare; import org.eclipse.dstore.core.util.StringCompare;
import org.eclipse.rse.dstore.universal.miners.ICancellableHandler; import org.eclipse.rse.dstore.universal.miners.ICancellableHandler;
import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants; import org.eclipse.rse.dstore.universal.miners.IUniversalDataStoreConstants;
@ -133,13 +134,15 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
_miner.statusCancelled(_status); _miner.statusCancelled(_status);
} }
else { else {
_alreadySearched.clear();
// previously, the status would be set to done immediately because search results were sent // previously, the status would be set to done immediately because search results were sent
// back to the client as they arrived. Now, the search handler wait until the search has // back to the client as they arrived. Now, the search handler wait until the search has
// completed before setting the status to done // completed before setting the status to done
_status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$ _status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$
_dataStore.refresh(_status); // true indicates refresh immediately _dataStore.refresh(_status); // true indicates refresh immediately
} }
_alreadySearched.clear();
_dataStore.disconnectObjects(_status);
} }
public boolean isCancelled() { public boolean isCancelled() {
@ -154,6 +157,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
_isCancelled = true; _isCancelled = true;
} }
protected boolean hasSearched(File file) protected boolean hasSearched(File file)
{ {
boolean result = false; boolean result = false;
@ -163,14 +167,14 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
// check whether it's already been searched // check whether it's already been searched
result = _alreadySearched.contains(canonicalPath); result = _alreadySearched.contains(canonicalPath);
} }
catch (IOException e){ catch (Exception e){
result = _alreadySearched.contains(file.getAbsolutePath());
_dataStore.trace(e); _dataStore.trace(e);
} }
return result; return result;
} }
protected void internalSearch(File theFile, int depth) throws SystemMessageException { protected void internalSearch(File theFile, int depth) throws SystemMessageException {
if (!hasSearched(theFile)) { if (!hasSearched(theFile)) {
@ -275,7 +279,7 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
} }
// do a refresh // do a refresh
//_dataStore.refresh(_status, true); //_dataStore.refresh(_status);
} }
// if the depth is not 0, then we need to recursively search // if the depth is not 0, then we need to recursively search
@ -327,6 +331,8 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
if (children != null) { if (children != null) {
for (int i = 0; i < children.length && !_isCancelled; i++) { for (int i = 0; i < children.length && !_isCancelled; i++) {
checkAndClearupMemory();
File child = children[i]; File child = children[i];
internalSearch(child, depth - 1); internalSearch(child, depth - 1);
} }
@ -356,6 +362,9 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
if (simpleSearch(inputStream, size, _stringMatcher)){ if (simpleSearch(inputStream, size, _stringMatcher)){
return true; return true;
} }
bufReader.close();
reader.close();
return false; return false;
} }
else { else {
@ -368,9 +377,16 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
convert(remoteFile, absPath, matches); convert(remoteFile, absPath, matches);
} }
bufReader.close();
reader.close();
return foundMatches; return foundMatches;
} }
} }
catch (OutOfMemoryError e){
if (SystemServiceManager.getInstance().getSystemService() == null)
System.exit(-1);
return false;
}
catch (Exception e) { catch (Exception e) {
UniversalServerUtilities.logError(_miner.getName(), "Error occured when trying to locate matches", e, _dataStore); //$NON-NLS-1$ UniversalServerUtilities.logError(_miner.getName(), "Error occured when trying to locate matches", e, _dataStore); //$NON-NLS-1$
remoteFile.setAttribute(DE.A_VALUE, e.getMessage()); remoteFile.setAttribute(DE.A_VALUE, e.getMessage());
@ -440,4 +456,36 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
obj.setAttribute(DE.A_SOURCE, obj.getSource() + ':'+ match.getLineNumber()); obj.setAttribute(DE.A_SOURCE, obj.getSource() + ':'+ match.getLineNumber());
} }
} }
public void checkAndClearupMemory()
{
int count = 0;
while(count < 5 && isMemoryThresholdExceeded()) {
System.gc();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
count ++;
}
if(count == 5) {
_dataStore.trace("heap memory low"); //$NON-NLS-1$
if (SystemServiceManager.getInstance().getSystemService() == null)
System.exit(-1);
}
}
private boolean isMemoryThresholdExceeded(){
// trying to avoid using Java 1.5
Runtime runtime = Runtime.getRuntime();
long freeMem = runtime.freeMemory();
if (freeMem < 10000){
return true;
}
return false;
}
} }