Files
mercury/java/runtime/MercuryRuntime.java
Paul Bone 21fb0a74fc [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.
2015-01-05 16:01:37 +11:00

80 lines
2.2 KiB
Java

//
// Copyright (C) 2014 The Mercury Team
// This file may only be copied under the terms of the GNU Library General
// Public License - see the file COPYING.LIB in the Mercury distribution.
//
package jmercury.runtime;
/**
* Interface to the Mercury Runtime System for Java code.
*
* No instance of this class is ever created, all its members and methods
* are static.
*/
public class MercuryRuntime
{
/**
* Private constructor.
* This private constructor doesn't do anything and isn't called by
* anyone. It exists only to prevent people from creating an instance.
*/
private MercuryRuntime() {
}
private static MercuryThreadPool thread_pool = null;
/**
* Return the thread pool, initialising it if required.
* This does not start the thread pool. It is started either when
* startup() is called or automatically when the first task is
* submitted.
*/
public static synchronized MercuryThreadPool getThreadPool()
{
if (thread_pool == null) {
thread_pool = new MercuryThreadPool(
JavaInternal.getOptions().getNumProcessors());
}
return thread_pool;
}
/**
* Retrieve the exit status stored in the I/O state.
*/
public static int getExitStatus() {
return JavaInternal.exit_status;
}
/**
* 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 (unless abort=true).
*/
public static void finalise(boolean abort) {
MercuryThreadPool pool;
pool = getThreadPool();
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);
}
}