mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
GP-400 add dispose to ManagerDB to allow ProgramDB to release resources. Ensure that other uses of DataTypeManagerDB dispose on close.
This commit is contained in:
parent
2094a5d0e8
commit
2c09ef0f26
9 changed files with 49 additions and 36 deletions
|
@ -195,6 +195,11 @@ public class DataTypeArchiveDB extends DomainObjectAdapterDB
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void close() {
|
||||
dataTypeManager.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setDomainFile(DomainFile df) {
|
||||
super.setDomainFile(df);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,13 +15,13 @@
|
|||
*/
|
||||
package ghidra.program.database;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.address.AddressOverflowException;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Interface that all subsection managers of a program must implement.
|
||||
*/
|
||||
|
@ -65,7 +64,7 @@ public interface ManagerDB {
|
|||
* @param monitor the task monitor to use in any upgrade operations.
|
||||
* @throws CancelledException if the user cancelled the operation via the task monitor.
|
||||
*/
|
||||
public void deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
|
||||
void deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
|
||||
throws CancelledException;
|
||||
|
||||
/**
|
||||
|
@ -79,4 +78,12 @@ public interface ManagerDB {
|
|||
*/
|
||||
void moveAddressRange(Address fromAddr, Address toAddr, long length, TaskMonitor monitor)
|
||||
throws AddressOverflowException, CancelledException;
|
||||
|
||||
/**
|
||||
* Callback from the program after being closed to signal this manager to release memory and resources.
|
||||
* <p>
|
||||
*/
|
||||
default void dispose() {
|
||||
// default do nothing
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2333,6 +2333,9 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
|
|||
super.close();
|
||||
intRangePropertyMap.clear();
|
||||
addrSetPropertyMap.clear();
|
||||
for (ManagerDB manager : managers) {
|
||||
manager.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2915,6 +2915,16 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
|
|||
return (new ArrayList<Composite>()).iterator();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
sortedDataTypes = null;
|
||||
enumValueMap = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates the cache.
|
||||
*/
|
||||
|
@ -3875,7 +3885,7 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
|
|||
for (DataTypeComponent m : c.getDefinedComponents()) {
|
||||
CompositeDB refC = getCompositeBaseType(m.getDataType());
|
||||
if (refC != null) {
|
||||
graph.addEdge(new DefaultGEdge<CompositeDB>(c, refC));
|
||||
graph.addEdge(new DefaultGEdge<>(c, refC));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -253,6 +253,7 @@ public class ProgramDataTypeManager extends DataTypeManagerDB
|
|||
@Override
|
||||
public void close() {
|
||||
// do nothing - cannot close the program's data type manager
|
||||
// dispose should be invoked by the owner of the instance
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -196,9 +196,6 @@ public class ProjectDataTypeManager extends DataTypeManagerDB
|
|||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.data.DataTypeManager#startTransaction(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public int startTransaction(String description) {
|
||||
return dataTypeArchive.startTransaction(description);
|
||||
|
@ -209,26 +206,11 @@ public class ProjectDataTypeManager extends DataTypeManagerDB
|
|||
dataTypeArchive.flushEvents();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.data.DataTypeManager#endTransaction(int, boolean)
|
||||
*/
|
||||
@Override
|
||||
public void endTransaction(int transactionID, boolean commit) {
|
||||
dataTypeArchive.endTransaction(transactionID, commit);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ghidra.program.model.data.DataTypeManager#close()
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ghidra.program.model.data.DomainFileBasedDataTypeManager#getDomainFile()
|
||||
*/
|
||||
@Override
|
||||
public DomainFile getDomainFile() {
|
||||
return dataTypeArchive.getDomainFile();
|
||||
|
@ -257,4 +239,10 @@ public class ProjectDataTypeManager extends DataTypeManagerDB
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// do nothing - cannot close a project data type manager
|
||||
// dispose should be invoked by the owner of the instance
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,12 +46,12 @@ public class BuiltInDataTypeManager extends StandAloneDataTypeManager {
|
|||
public static synchronized BuiltInDataTypeManager getDataTypeManager() {
|
||||
if (manager == null) {
|
||||
manager = new BuiltInDataTypeManager();
|
||||
Runnable cleanupTask = new Thread((Runnable) () -> {
|
||||
Runnable cleanupTask = () -> {
|
||||
if (manager != null) {
|
||||
manager.dispose();
|
||||
manager.closeStaticInstance();
|
||||
manager = null;
|
||||
}
|
||||
}, "Builtin DataType Manager Cleanup Thread");
|
||||
};
|
||||
ShutdownHookRegistry.addShutdownHook(cleanupTask,
|
||||
ShutdownPriority.DISPOSE_DATABASES.before());
|
||||
}
|
||||
|
@ -92,19 +92,11 @@ public class BuiltInDataTypeManager extends StandAloneDataTypeManager {
|
|||
return super.createCategory(path);
|
||||
}
|
||||
|
||||
private synchronized void dispose() {
|
||||
private synchronized void closeStaticInstance() {
|
||||
ClassSearcher.removeChangeListener(classSearcherListener);
|
||||
super.close();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ghidra.program.model.data.DataTypeManager#close()
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
// static shared instance can't be closed
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the list of Built-In data types found by searching the class path.
|
||||
*/
|
||||
|
@ -202,4 +194,10 @@ public class BuiltInDataTypeManager extends StandAloneDataTypeManager {
|
|||
boolean updateCategoryPath) throws DataTypeDependencyException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// do nothing - cannot close a built-in data type manager
|
||||
// close performed automatically during shutdown
|
||||
}
|
||||
}
|
||||
|
|
|
@ -227,11 +227,11 @@ public class FileDataTypeManager extends StandAloneDataTypeManager
|
|||
|
||||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
if (packedDB != null) {
|
||||
packedDB.dispose();
|
||||
packedDB = null;
|
||||
}
|
||||
super.close();
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
|
|
|
@ -120,6 +120,7 @@ public class StandAloneDataTypeManager extends DataTypeManagerDB {
|
|||
dbHandle.close();
|
||||
dbHandle = null;
|
||||
}
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue