Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more consistant identifier names around Java objects' finalization
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 26 Apr 2015 12:43:48 +0000 (14:43 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 26 Apr 2015 12:43:48 +0000 (14:43 +0200)
19 files changed:
examples/java/cloud/Master.java
examples/java/cloud/migration/Test.java
examples/java/cloud/migration/TestHostOnOff.java
src/bindings/java/jmsg_comm.c
src/bindings/java/jmsg_comm.h
src/bindings/java/jmsg_rngstream.c
src/bindings/java/jmsg_rngstream.h
src/bindings/java/jmsg_synchro.c
src/bindings/java/jmsg_synchro.h
src/bindings/java/jmsg_task.c
src/bindings/java/jmsg_task.h
src/bindings/java/jmsg_vm.c
src/bindings/java/jmsg_vm.h
src/bindings/java/org/simgrid/msg/Comm.java
src/bindings/java/org/simgrid/msg/Mutex.java
src/bindings/java/org/simgrid/msg/RngStream.java
src/bindings/java/org/simgrid/msg/Semaphore.java
src/bindings/java/org/simgrid/msg/Task.java
src/bindings/java/org/simgrid/msg/VM.java

index a581aff..d3606c9 100644 (file)
@@ -81,7 +81,6 @@ public class Master extends Process {
                
                for (int i = 0; i < vms.size(); i++) {
                        vms.get(i).shutdown();
-                       vms.get(i).destroy();
                }                               
                Msg.info("Master done.");
        }
index 7edd538..f361ddc 100644 (file)
@@ -144,8 +144,6 @@ public class Test extends Process{
         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
     }
 }
index 1f4278f..47467bd 100644 (file)
@@ -121,16 +121,15 @@ public class TestHostOnOff extends Process{
         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
@@ -156,10 +155,7 @@ public class TestHostOnOff extends Process{
         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,
@@ -179,8 +175,6 @@ public class TestHostOnOff extends Process{
                
         Process.sleep(5000);
         vm0.shutdown();
-        Process.sleep(5000);
-        vm0.destroy();
     }
 
 }
index bf6a09b..2de313c 100644 (file)
@@ -62,7 +62,7 @@ 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) {
   msg_comm_t comm;
   msg_task_t *task_received;
 
index ec099e9..7849c6c 100644 (file)
@@ -20,7 +20,7 @@ JNIEXPORT void JNICALL
 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);
index 5bf195b..14afaae 100644 (file)
@@ -38,7 +38,7 @@ Java_org_simgrid_msg_RngStream_create(JNIEnv *env, jobject jrngstream, jstring j
   (*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);
index e50b218..69457d3 100644 (file)
@@ -20,7 +20,7 @@ JNIEXPORT void JNICALL
 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);
index 71ba2ef..feaeac1 100644 (file)
@@ -52,7 +52,7 @@ 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) {
   xbt_mutex_t mutex;
 
   mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, jsyncro_field_Mutex_bind);
@@ -104,7 +104,7 @@ 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) {
   msg_sem_t sem;
 
   sem = (msg_sem_t) (long) (*env)->GetLongField(env, obj, jsyncro_field_Semaphore_bind);
index d89ebcf..87fd365 100644 (file)
@@ -26,7 +26,8 @@ JNIEXPORT void JNICALL
 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);
@@ -39,5 +40,5 @@ Java_org_simgrid_msg_Semaphore_release(JNIEnv * env, jobject obj);
 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 */
index 40cffed..3530569 100644 (file)
@@ -652,7 +652,7 @@ MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask));
 }
 
 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) {
index 2edb2ca..b79450a 100644 (file)
@@ -72,7 +72,7 @@ JNIEXPORT void JNICALL
 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
index d16c3b0..9338bdc 100644 (file)
@@ -104,7 +104,7 @@ Java_org_simgrid_msg_VM_create(JNIEnv *env, jobject jvm, jobject jhost, jstring
 }
 
 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);
 }
index 5b97777..5aca833 100644 (file)
@@ -102,7 +102,7 @@ Java_org_simgrid_msg_VM_create(JNIEnv *env, jobject jvm, jobject jhost, jstring
  * 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
index ebe63fc..b4d2341 100644 (file)
@@ -40,32 +40,30 @@ public class Comm {
        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;
 
index fbcb634..503588b 100644 (file)
@@ -16,10 +16,15 @@ public class Mutex {
        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();
index c7d3a5d..49e7ac3 100644 (file)
@@ -41,16 +41,18 @@ public class RngStream {
         * 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
index d74a8bc..9be79f6 100644 (file)
@@ -65,14 +65,16 @@ public class Semaphore {
        }
 
 
-       /** 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
         */
index 16e54ef..0ee65c4 100644 (file)
@@ -167,13 +167,13 @@ public class Task {
                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 * *
         * *                       * */
index c6a5220..1406898 100644 (file)
@@ -73,8 +73,13 @@ public class VM extends Host{
                }
                return null; 
        }
+       @Override
        protected void finalize() {
-               destroy();
+               try {
+                       nativeFinalize();
+               } catch (Throwable e) {
+                       e.printStackTrace();
+               }
        }
 
 
@@ -199,10 +204,7 @@ public class VM extends Host{
        public native void restore();
 
 
-       /**
-        * Destroy the VM
-        */
-       public native void destroy();
+       private native void nativeFinalize();