mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +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
|
@Override
|
||||||
protected void setDomainFile(DomainFile df) {
|
protected void setDomainFile(DomainFile df) {
|
||||||
super.setDomainFile(df);
|
super.setDomainFile(df);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
/* ###
|
/* ###
|
||||||
* IP: GHIDRA
|
* IP: GHIDRA
|
||||||
* REVIEWED: YES
|
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,13 +15,13 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.program.database;
|
package ghidra.program.database;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
import ghidra.program.model.address.AddressOverflowException;
|
import ghidra.program.model.address.AddressOverflowException;
|
||||||
import ghidra.util.exception.CancelledException;
|
import ghidra.util.exception.CancelledException;
|
||||||
import ghidra.util.task.TaskMonitor;
|
import ghidra.util.task.TaskMonitor;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface that all subsection managers of a program must implement.
|
* 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.
|
* @param monitor the task monitor to use in any upgrade operations.
|
||||||
* @throws CancelledException if the user cancelled the operation via the task monitor.
|
* @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;
|
throws CancelledException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,4 +78,12 @@ public interface ManagerDB {
|
||||||
*/
|
*/
|
||||||
void moveAddressRange(Address fromAddr, Address toAddr, long length, TaskMonitor monitor)
|
void moveAddressRange(Address fromAddr, Address toAddr, long length, TaskMonitor monitor)
|
||||||
throws AddressOverflowException, CancelledException;
|
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();
|
super.close();
|
||||||
intRangePropertyMap.clear();
|
intRangePropertyMap.clear();
|
||||||
addrSetPropertyMap.clear();
|
addrSetPropertyMap.clear();
|
||||||
|
for (ManagerDB manager : managers) {
|
||||||
|
manager.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2915,6 +2915,16 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
|
||||||
return (new ArrayList<Composite>()).iterator();
|
return (new ArrayList<Composite>()).iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
sortedDataTypes = null;
|
||||||
|
enumValueMap = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidates the cache.
|
* Invalidates the cache.
|
||||||
*/
|
*/
|
||||||
|
@ -3875,7 +3885,7 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
|
||||||
for (DataTypeComponent m : c.getDefinedComponents()) {
|
for (DataTypeComponent m : c.getDefinedComponents()) {
|
||||||
CompositeDB refC = getCompositeBaseType(m.getDataType());
|
CompositeDB refC = getCompositeBaseType(m.getDataType());
|
||||||
if (refC != null) {
|
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
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
// do nothing - cannot close the program's data type manager
|
// do nothing - cannot close the program's data type manager
|
||||||
|
// dispose should be invoked by the owner of the instance
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -196,9 +196,6 @@ public class ProjectDataTypeManager extends DataTypeManagerDB
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.data.DataTypeManager#startTransaction(java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int startTransaction(String description) {
|
public int startTransaction(String description) {
|
||||||
return dataTypeArchive.startTransaction(description);
|
return dataTypeArchive.startTransaction(description);
|
||||||
|
@ -209,26 +206,11 @@ public class ProjectDataTypeManager extends DataTypeManagerDB
|
||||||
dataTypeArchive.flushEvents();
|
dataTypeArchive.flushEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.data.DataTypeManager#endTransaction(int, boolean)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void endTransaction(int transactionID, boolean commit) {
|
public void endTransaction(int transactionID, boolean commit) {
|
||||||
dataTypeArchive.endTransaction(transactionID, 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
|
@Override
|
||||||
public DomainFile getDomainFile() {
|
public DomainFile getDomainFile() {
|
||||||
return dataTypeArchive.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() {
|
public static synchronized BuiltInDataTypeManager getDataTypeManager() {
|
||||||
if (manager == null) {
|
if (manager == null) {
|
||||||
manager = new BuiltInDataTypeManager();
|
manager = new BuiltInDataTypeManager();
|
||||||
Runnable cleanupTask = new Thread((Runnable) () -> {
|
Runnable cleanupTask = () -> {
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
manager.dispose();
|
manager.closeStaticInstance();
|
||||||
manager = null;
|
manager = null;
|
||||||
}
|
}
|
||||||
}, "Builtin DataType Manager Cleanup Thread");
|
};
|
||||||
ShutdownHookRegistry.addShutdownHook(cleanupTask,
|
ShutdownHookRegistry.addShutdownHook(cleanupTask,
|
||||||
ShutdownPriority.DISPOSE_DATABASES.before());
|
ShutdownPriority.DISPOSE_DATABASES.before());
|
||||||
}
|
}
|
||||||
|
@ -92,19 +92,11 @@ public class BuiltInDataTypeManager extends StandAloneDataTypeManager {
|
||||||
return super.createCategory(path);
|
return super.createCategory(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void dispose() {
|
private synchronized void closeStaticInstance() {
|
||||||
ClassSearcher.removeChangeListener(classSearcherListener);
|
ClassSearcher.removeChangeListener(classSearcherListener);
|
||||||
super.close();
|
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.
|
* 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 {
|
boolean updateCategoryPath) throws DataTypeDependencyException {
|
||||||
throw new UnsupportedOperationException();
|
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
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
super.close();
|
|
||||||
if (packedDB != null) {
|
if (packedDB != null) {
|
||||||
packedDB.dispose();
|
packedDB.dispose();
|
||||||
packedDB = null;
|
packedDB = null;
|
||||||
}
|
}
|
||||||
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClosed() {
|
public boolean isClosed() {
|
||||||
|
|
|
@ -120,6 +120,7 @@ public class StandAloneDataTypeManager extends DataTypeManagerDB {
|
||||||
dbHandle.close();
|
dbHandle.close();
|
||||||
dbHandle = null;
|
dbHandle = null;
|
||||||
}
|
}
|
||||||
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue