Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please sonar
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 13 Jul 2017 09:41:20 +0000 (11:41 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 13 Jul 2017 09:41:20 +0000 (11:41 +0200)
examples/java/dht/chord/Node.java
src/bindings/java/jmsg_process.cpp
src/xbt/mmalloc/mfree.c
src/xbt/mmalloc/mm_module.c

index 87c4e50..f29ead5 100644 (file)
@@ -58,8 +58,8 @@ public class Node extends Process {
       create();
       joinSuccess = true;
     } else {
-      int knownId = Integer.valueOf(args[1]);
-      deadline = Integer.valueOf(args[3]);
+      int knownId = Integer.parseInt(args[1]);
+      deadline = Integer.parseInt(args[3]);
       Msg.debug("Hey! Let's join the system with the id " + id + ".");
 
       joinSuccess = join(knownId);
@@ -202,7 +202,6 @@ public class Node extends Process {
       }
       catch (MsgException e) {
         commReceive = null;
-        stop = true;
       }
     }
     catch (MsgException e) {
index 8fcbe02..2676857 100644 (file)
@@ -74,9 +74,9 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv* env, jobject
   /* Actually build the MSG process */
   jstring jname         = (jstring)env->GetObjectField(jprocess, jprocess_field_Process_name);
   const char* name      = env->GetStringUTFChars(jname, 0);
-  msg_process_t process = MSG_process_create_from_stdfunc(
-      name, [jprocess]() -> void { simgrid::kernel::context::java_main_jprocess(jprocess); },
-      /*data*/ nullptr, jhost_get_native(env, jhost), /* properties*/ nullptr);
+  msg_process_t process =
+      MSG_process_create_from_stdfunc(name, [jprocess]() { simgrid::kernel::context::java_main_jprocess(jprocess); },
+                                      /*data*/ nullptr, jhost_get_native(env, jhost), /* properties*/ nullptr);
   env->ReleaseStringUTFChars(jname, name);
 
   /* bind the java process instance to the native process */
index 66ec157..38b5fc0 100644 (file)
@@ -20,8 +20,7 @@
 /* Return memory to the heap.  */
 void mfree(struct mdesc *mdp, void *ptr)
 {
-  int type;
-  size_t block, frag_nb;
+  size_t frag_nb;
   size_t i;
   int it;
 
@@ -31,14 +30,14 @@ void mfree(struct mdesc *mdp, void *ptr)
   if (ptr == NULL)
     return;
 
-  block = BLOCK(ptr);
+  size_t block = BLOCK(ptr);
 
   if ((char *) ptr < (char *) mdp->heapbase || block > mdp->heapsize) {
     fprintf(stderr,"Ouch, this pointer is not mine, I refuse to free it. Give me valid pointers, or give me death!!\n");
     abort();
   }
 
-  type = mdp->heapinfo[block].type;
+  int type = mdp->heapinfo[block].type;
 
   switch (type) {
   case MMALLOC_TYPE_HEAPINFO:
@@ -59,10 +58,8 @@ void mfree(struct mdesc *mdp, void *ptr)
     mdp -> heapstats.bytes_free +=
       mdp -> heapinfo[block].busy_block.size * BLOCKSIZE;
 
-    if(MC_is_active()){
-      if(mdp->heapinfo[block].busy_block.ignore > 0)
-        MC_remove_ignore_heap(ptr, mdp -> heapinfo[block].busy_block.busy_size);
-    }
+    if (MC_is_active() && mdp->heapinfo[block].busy_block.ignore > 0)
+      MC_remove_ignore_heap(ptr, mdp->heapinfo[block].busy_block.busy_size);
 
     /* Find the free cluster previous to this one in the free list.
        Start searching at the last block referenced; this may benefit
@@ -171,10 +168,8 @@ void mfree(struct mdesc *mdp, void *ptr)
       THROWF(system_error, 0, "Asked to free a fragment that is already free. I'm puzzled\n");
     }
 
-    if(MC_is_active()){
-      if(mdp->heapinfo[block].busy_frag.ignore[frag_nb] > 0)
-        MC_remove_ignore_heap(ptr, mdp->heapinfo[block].busy_frag.frag_size[frag_nb]);
-    }
+    if (MC_is_active() && mdp->heapinfo[block].busy_frag.ignore[frag_nb] > 0)
+      MC_remove_ignore_heap(ptr, mdp->heapinfo[block].busy_frag.frag_size[frag_nb]);
 
     /* Set size used in the fragment to -1 */
     mdp->heapinfo[block].busy_frag.frag_size[frag_nb] = -1;
index eac80c8..6c04fdf 100644 (file)
@@ -120,7 +120,8 @@ xbt_mheap_t xbt_mheap_new_options(int fd, void *baseaddr, int options)
          unsuccessful for some reason. */
 
       struct mdesc newmd;
-      struct mdesc *mdptr = NULL, *mdptemp = NULL;
+      struct mdesc* mdptr   = NULL;
+      struct mdesc* mdptemp = NULL;
 
       if (lseek(fd, 0L, SEEK_SET) != 0)
         return NULL;
@@ -156,15 +157,13 @@ xbt_mheap_t xbt_mheap_new_options(int fd, void *baseaddr, int options)
     }
   }
 
-  /* NULL is not a valid baseaddr as we cannot map anything there.
-     C'mon, user. Think! */
+  /* NULL is not a valid baseaddr as we cannot map anything there. C'mon, user. Think! */
   if (baseaddr == NULL)
     return (NULL);
 
-  /* We start off with the malloc descriptor allocated on the stack, until
-     we build it up enough to call _mmalloc_mmap_morecore() to allocate the
-     first page of the region and copy it there.  Ensure that it is zero'd and
-     then initialize the fields that we know values for. */
+  /* We start off with the malloc descriptor allocated on the stack, until we build it up enough to
+   * call _mmalloc_mmap_morecore() to allocate the first page of the region and copy it there.  Ensure that it is
+   * zero'd and then initialize the fields that we know values for. */
 
   mdp = &mtemp;
   memset((char *) mdp, 0, sizeof(mtemp));
@@ -187,10 +186,9 @@ xbt_mheap_t xbt_mheap_new_options(int fd, void *baseaddr, int options)
   /* If we have not been passed a valid open file descriptor for the file
      to map to, then open /dev/zero and use that to map to. */
 
-  /* Now try to map in the first page, copy the malloc descriptor structure
-     there, and arrange to return a pointer to this new copy.  If the mapping
-     fails, then close the file descriptor if it was opened by us, and arrange
-     to return a NULL. */
+  /* Now try to map in the first page, copy the malloc descriptor structure there, and arrange to return a pointer to
+   * this new copy.  If the mapping fails, then close the file descriptor if it was opened by us, and arrange to return
+   * a NULL. */
 
   if ((mbase = mmorecore(mdp, sizeof(mtemp))) != NULL) {
     memcpy(mbase, mdp, sizeof(mtemp));
@@ -229,41 +227,35 @@ void xbt_mheap_destroy_no_free(xbt_mheap_t md)
   }
 }
 
-/** Terminate access to a mmalloc managed region by unmapping all memory pages
-    associated with the region, and closing the file descriptor if it is one
-    that we opened.
+/** Terminate access to a mmalloc managed region by unmapping all memory pages associated with the region, and closing
+ *  the file descriptor if it is one that we opened.
 
     Returns NULL on success.
 
-    Returns the malloc descriptor on failure, which can subsequently be used
-    for further action, such as obtaining more information about the nature of
-    the failure.
+    Returns the malloc descriptor on failure, which can subsequently be used for further action, such as obtaining more
+    information about the nature of the failure.
 
-    Note that the malloc descriptor that we are using is currently located in
-    region we are about to unmap, so we first make a local copy of it on the
-    stack and use the copy. */
+    Note that the malloc descriptor that we are using is currently located in region we are about to unmap, so we first
+    make a local copy of it on the stack and use the copy. */
 
 void *xbt_mheap_destroy(xbt_mheap_t mdp)
 {
-  struct mdesc mtemp, *mdptemp;
-
   if (mdp != NULL) {
     /* Remove the heap from the linked list of heaps attached by mmalloc */
-    mdptemp = __mmalloc_default_mdp;
+    struct mdesc* mdptemp = __mmalloc_default_mdp;
     while(mdptemp->next_mdesc != mdp )
       mdptemp = mdptemp->next_mdesc;
 
     mdptemp->next_mdesc = mdp->next_mdesc;
 
     xbt_mheap_destroy_no_free(mdp);
-    mtemp = *mdp;
+    struct mdesc mtemp = *mdp;
 
     /* Now unmap all the pages associated with this region by asking for a
        negative increment equal to the current size of the region. */
 
     if (mmorecore(&mtemp, (char *)mtemp.base - (char *)mtemp.breakval) == NULL) {
-      /* Deallocating failed.  Update the original malloc descriptor
-         with any changes */
+      /* Deallocating failed.  Update the original malloc descriptor with any changes */
       *mdp = mtemp;
     } else {
       if (mtemp.flags & MMALLOC_DEVZERO) {
@@ -277,8 +269,7 @@ void *xbt_mheap_destroy(xbt_mheap_t mdp)
 }
 
 /* Safety gap from the heap's break address.
- * Try to increase this first if you experience strange errors under
- * valgrind. */
+ * Try to increase this first if you experience strange errors under valgrind. */
 #define HEAP_OFFSET   (128UL<<20)
 
 xbt_mheap_t mmalloc_get_default_md(void)