[java] Run finalisers only if main/2 returns normally

finalisers should be executed only if main/2 returns normally, it does not
throw an exception.  The C backends already do this correctly but the Java
backend did not.  The C# backend has the same bug, this patch does not fix
the C# backend.

java/runtime/MercuryThreadPool.java:
    Add a parameter to the shutdown() method to specify whether the backend
    is aborting.

    In runMain(), run finalisers only if the runtime is exiting normally.

java/runtime/MercuryRuntime.java:
    Add a new finalise() method that takes a parameter allowing standalone
    Java applications to specify whether or not they are aborting when the
    finalise the RTS.

doc/reference_manual.texi:
    Specify the behaviour of finalise directives if main/2 terminates
    with an uncaught exception.

samples/java_interface/standalone_java/JavaMain.java:
    Conform to changes in MercuryRuntime.java.
This commit is contained in:
Paul Bone
2014-12-29 22:34:15 +11:00
parent c60aab937b
commit 21fb0a74fc
4 changed files with 43 additions and 13 deletions

View File

@@ -48,17 +48,32 @@ public class MercuryRuntime
/**
* Finalise the runtime system.
* This _must_ be called at the normal end of any program. It runs
* finalisers and stops the thread pool.
* This will wait for the thread pool to shutdown.
* This _must_ be called at the end of any program. It runs
* finalisers and stops the thread pool. This will wait for the thread
* pool to shutdown (unless abort=true).
*/
public static void finalise() {
public static void finalise(boolean abort) {
MercuryThreadPool pool;
pool = getThreadPool();
JavaInternal.run_finalisers();
pool.shutdown();
pool.waitForShutdown();
if (!abort) {
JavaInternal.run_finalisers();
}
pool.shutdown(abort);
if (!abort) {
pool.waitForShutdown();
}
}
/**
* Finalise the runtime system.
* This _must_ be called at the end of any program. It runs
* finalisers and stops the thread pool. This will wait for the thread
* pool to shutdown.
* This is the same as calling finalise(false)
*/
public static void finalise() {
finalise(false);
}
}