for (int i = 0; i < vms.size(); i++) {
vms.get(i).shutdown();
- vms.get(i).destroy();
}
Msg.info("Master done.");
}
Msg.info(" - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")");
Main.setEndOfTest();
- Msg.info("Destroy VMs");
- for (VM vm: vms)
- vm.destroy();
+ // no need to destroy the VMs: the garbage collector will get them all
}
}
Process.sleep(50000);
Msg.info("Destroy VMs");
vm0.shutdown();
- vm0.destroy();
Process.sleep(20000);
}
public static void test_vm_shutdown_destroy () throws HostFailureException {
- Msg.info("**** **** **** ***** ***** Test shutdown /destroy a VM ***** ***** **** **** ****");
+ Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****");
Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " +
- "destroy it and check whether you can reallocate the same VM");
+ "and check whether you can reallocate the same VM");
// Create VM0
Msg.info("Shutdown VM0");
vm0.shutdown();
Process.sleep(5000);
- Msg.info("Destroy VM0");
- vm0.destroy();
- Process.sleep(5000);
Msg.info("Restart VM0");
vm0 = new XVM(
host1,
Process.sleep(5000);
vm0.shutdown();
- Process.sleep(5000);
- vm0.destroy();
}
}
}
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Comm_destroy(JNIEnv *env, jobject jcomm) {
+Java_org_simgrid_msg_Comm_nativeFinalize(JNIEnv *env, jobject jcomm) {
msg_comm_t comm;
msg_task_t *task_received;
Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass cls);
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Comm_destroy(JNIEnv *env, jobject jcomm);
+Java_org_simgrid_msg_Comm_nativeFinalize(JNIEnv *env, jobject jcomm);
JNIEXPORT jboolean JNICALL
Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm);
(*env)->ReleaseStringUTFChars(env, jname, name);
}
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_RngStream_destroy(JNIEnv *env, jobject jrngstream) {
+Java_org_simgrid_msg_RngStream_nativeFinalize(JNIEnv *env, jobject jrngstream) {
RngStream rngstream = jrngstream_to_native(env, jrngstream);
RngStream_DeleteStream(&rngstream);
(*env)->SetLongField(env, jrngstream, jrngstream_bind, (intptr_t)NULL);
Java_org_simgrid_msg_RngStream_create(JNIEnv *env, jobject jrngstream, jstring name);
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_RngStream_destroy(JNIEnv *env, jobject jrngstream);
+Java_org_simgrid_msg_RngStream_nativeFinalize(JNIEnv *env, jobject jrngstream);
JNIEXPORT jboolean JNICALL
Java_org_simgrid_msg_RngStream_setPackageSeed(JNIEnv *env, jobject jrngstream, jintArray seed);
}
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Mutex_exit(JNIEnv * env, jobject obj) {
+Java_org_simgrid_msg_Mutex_nativeFinalize(JNIEnv * env, jobject obj) {
xbt_mutex_t mutex;
mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, jsyncro_field_Mutex_bind);
}
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Mutex_destroy(JNIEnv * env, jobject obj) {
+Java_org_simgrid_msg_Semaphore_nativeFinalize(JNIEnv * env, jobject obj) {
msg_sem_t sem;
sem = (msg_sem_t) (long) (*env)->GetLongField(env, obj, jsyncro_field_Semaphore_bind);
Java_org_simgrid_msg_Mutex_release(JNIEnv * env, jobject obj);
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Mutex_exit(JNIEnv * env, jobject obj);
+Java_org_simgrid_msg_Mutex_nativeFinalize(JNIEnv * env, jobject obj);
+
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Semaphore_nativeInit(JNIEnv *env, jclass cls);
JNIEXPORT jboolean JNICALL
Java_org_simgrid_msg_Semaphore_wouldBlock(JNIEnv * env, jobject obj);
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Mutex_destroy(JNIEnv * env, jobject obj);
+Java_org_simgrid_msg_Semaphore_nativeFinalize(JNIEnv * env, jobject obj);
#endif /* !MSG_JPROCESS_H */
}
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Task_doFinalize(JNIEnv * env, jobject jtask) {
+Java_org_simgrid_msg_Task_nativeFinalize(JNIEnv * env, jobject jtask) {
msg_task_t task = jtask_to_native_task(jtask, env);
if (!task) {
Java_org_simgrid_msg_Task_create
(JNIEnv * env, jobject jtask, jstring jname, jdouble jcomputeDuration, jdouble jmessageSize);
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Task_doFinalize(JNIEnv * env, jobject jtask);
+Java_org_simgrid_msg_Task_nativeFinalize(JNIEnv * env, jobject jtask);
/*
* Class org_simgrid_msg_Task
* Method parallelCreate
}
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_VM_destroy(JNIEnv *env, jobject jvm) {
+Java_org_simgrid_msg_VM_nativeFinalize(JNIEnv *env, jobject jvm) {
msg_vm_t vm = jvm_get_native(env,jvm);
MSG_vm_destroy(vm);
}
* Signature ()V
*/
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_VM_destroy(JNIEnv *env, jobject jvm);
+Java_org_simgrid_msg_VM_nativeFinalize(JNIEnv *env, jobject jvm);
/**
* Class org_simgrid_msg_VM
* Method start
protected Comm() {
}
- /**
- * Finalize the communication object, destroying it.
- */
- protected void finalize() throws Throwable {
- destroy();
+ /** Destroy the C communication object, when the GC reclaims the java part. */
+ @Override
+ protected void finalize() {
+ try {
+ nativeFinalize();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
}
- /**
- * Unbind the communication object
- */
- protected native void destroy() throws NativeException;
+ protected native void nativeFinalize();
/**
* Returns if the communication is finished or not.
* If the communication has finished and there was an error,
* raise an exception.
*/
public native boolean test() throws TransferFailureException, HostFailureException, TimeoutException ;
- /**
- * Wait for the complemetion of the communication for an indefinite time
- */
+ /** Wait infinitely for the completion of the communication (infinite timeout) */
public void waitCompletion() throws TransferFailureException, HostFailureException, TimeoutException {
waitCompletion(-1);
}
/**
* Wait for the completion of the communication.
* Throws an exception if there were an error in the communication.
- * @param timeout Time before giving up
+ * @param timeout Time before giving up (infinite time if negative)
*/
public native void waitCompletion(double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
public Mutex() {
init();
}
+ @Override
protected void finalize() {
- exit();
+ try {
+ nativeFinalize();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
}
- private native void exit();
+ private native void nativeFinalize();
private native void init();
public native void acquire();
public native void release();
* The natively implemented method to create a C RngStream object.
*/
private native void create(String name);
- /**
- * Destructor
- */
+ @Override
protected void finalize() {
- destroy();
+ try {
+ nativeFinalize();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
}
/**
* Release the C RngStream object
*/
- private native void destroy();
+ private native void nativeFinalize();
/**
* Sets the initial seed of the package RngStreams to the six integers in the vector seed. This will
}
- /** Deletes this semaphore
- */
+ /** Deletes this semaphore when the GC reclaims it */
+ @Override
protected void finalize() {
- destroy();
+ try {
+ nativeFinalize();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
}
- /** The native implementation for destroying a semaphore
- */
- private native void destroy();
+ private native void nativeFinalize();
/**
* Class initializer, to initialize various JNI stuff
*/
try {
// Exceptions in finalizers lead to bad situations:
// http://stackoverflow.com/questions/7644556/troubleshooting-a-java-memory-leak-finalization
- doFinalize();
+ nativeFinalize();
bind=0; // to avoid segfaults if the impossible happens yet again making this task surviving its finalize()
- } catch (Exception e) {
+ } catch (Throwable e) {
e.printStackTrace();
}
}
- protected native void doFinalize();
+ protected native void nativeFinalize();
/* * * *
* * Communication-related * *
* * * */
}
return null;
}
+ @Override
protected void finalize() {
- destroy();
+ try {
+ nativeFinalize();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
}
public native void restore();
- /**
- * Destroy the VM
- */
- public native void destroy();
+ private native void nativeFinalize();