Skip to content

Commit

Permalink
Fixes #3307. Adds a timer and distinguishes between heap/non-heap memory
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Mar 17, 2022
1 parent b89eaca commit 4571e7b
Showing 1 changed file with 40 additions and 16 deletions.
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* GamaExecutorService.java, in msi.gama.core, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* GamaExecutorService.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package msi.gama.runtime.concurrent;

Expand Down Expand Up @@ -37,24 +37,48 @@
*/
public abstract class GamaExecutorService {

/** The Constant EXCEPTION_HANDLER. */
public static final UncaughtExceptionHandler EXCEPTION_HANDLER = (t, e) -> {
/**
* The Class GamaMemoryExceptionHandler.
*/
static class GamaMemoryExceptionHandler implements UncaughtExceptionHandler {

/** The last warning time stamp. */
long lastWarningTimeStamp = 0l;

if (e instanceof OutOfMemoryError) {
if (GamaPreferences.Runtime.CORE_MEMORY_ACTION.getValue()) {
GAMA.getGui().tell(
"GAMA is out of memory. Experiment will be closed now. Increase the memory allocated to the platform in the preferences.");
GAMA.closeAllExperiments(true, true);
@Override
public void uncaughtException(final Thread t, final Throwable e) {
if (e instanceof OutOfMemoryError) {
long currentTime = System.currentTimeMillis();
if (currentTime - lastWarningTimeStamp > 60000l) {
// 1 minute between warnings
lastWarningTimeStamp = currentTime;
String msg = e.getMessage();
msg = msg == null ? "" : msg.toLowerCase();
if (GamaPreferences.Runtime.CORE_MEMORY_ACTION.getValue() && GAMA.getExperiment() != null
&& msg.contains("heap")) {
GAMA.getGui().tell(
"GAMA is out of memory. Experiment will be closed now. Please consult: https://gama-platform.org/wiki/Troubleshooting#memory-problems");
GAMA.closeAllExperiments(true, true);
} else {
if (GAMA.getExperiment() != null && !msg.contains("heap")) {
GAMA.getGui().tell(
"GAMA cannot allocate more memory for displaying this experiment. The platform will exit now. Please try to quit other applications and relaunch it");
} else {
GAMA.getGui().tell(
"Your system is running out of memory. GAMA will exit now. Please try to quit other applications and relaunch it");
}
System.exit(0);
}
}
} else {
GAMA.getGui().tell(
"GAMA is out of memory. The platform will exit now. Relaunch it and increase the memory allocated in the preferences.");
System.exit(0);
e.printStackTrace();
}
} else {
e.printStackTrace();
}

};
}

/** The Constant EXCEPTION_HANDLER. */
public static final UncaughtExceptionHandler EXCEPTION_HANDLER = new GamaMemoryExceptionHandler();

/** The agent parallel executor. */
public static volatile ForkJoinPool AGENT_PARALLEL_EXECUTOR;
Expand Down

0 comments on commit 4571e7b

Please sign in to comment.