2011-04-22 Ivan Maidanski <ivmai@mail.ru>
authorivmai <ivmai>
Fri, 22 Apr 2011 21:40:15 +0000 (21:40 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 26 Jul 2011 17:06:58 +0000 (21:06 +0400)
* os_dep.c (GC_get_maps): Always close the file.
* pthread_support.c (GC_get_nprocs): Ditto.
* os_dep.c (READ): Define similarly across the file (without
parameters).
* pthread_support.c (GC_get_nprocs): Use signed int type for "i"
and "len" local variables (since read() may return -1).
* include/private/gc_pmark.h (LONG_MULT): Add prefix/suffix
double underscore; add "volatile" for asm.
* include/private/gc_pmark.h (LONG_MULT): Add missing
parentheses.
* include/private/gc_priv.h (OR_WORD): Ditto.
* include/private/gc_priv.h (OR_WORD): Remove unnecessary brackets
and ';' symbol.

ChangeLog
include/private/gc_pmark.h
include/private/gc_priv.h
os_dep.c
pthread_support.c

index b57c19e..a61a85f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2011-04-22  Ivan Maidanski  <ivmai@mail.ru>
 
+       * os_dep.c (GC_get_maps): Always close the file.
+       * pthread_support.c (GC_get_nprocs): Ditto.
+       * os_dep.c (READ): Define similarly across the file (without
+       parameters).
+       * pthread_support.c (GC_get_nprocs): Use signed int type for "i"
+       and "len" local variables (since read() may return -1).
+       * include/private/gc_pmark.h (LONG_MULT): Add prefix/suffix
+       double underscore; add "volatile" for asm.
+       * include/private/gc_pmark.h (LONG_MULT): Add missing
+       parentheses.
+       * include/private/gc_priv.h (OR_WORD): Ditto.
+       * include/private/gc_priv.h (OR_WORD): Remove unnecessary brackets
+       and ';' symbol.
+
+2011-04-22  Ivan Maidanski  <ivmai@mail.ru>
+
        * os_dep.c (GC_get_stack_base): Implement for Android (same as
        for Linux).
        * pthread_support.c (GC_get_nprocs): Return 1 (instead of -1) if
index a24dda8..05b082b 100644 (file)
@@ -189,20 +189,20 @@ exit_label: ; \
 # define SET_MARK_BIT_EXIT_IF_SET(hhdr,bit_no,exit_label) \
     { \
         word * mark_word_addr = hhdr -> hb_marks + divWORDSZ(bit_no); \
-      \
         OR_WORD_EXIT_IF_SET(mark_word_addr, (word)1 << modWORDSZ(bit_no), \
                             exit_label); \
     }
-#endif
+#endif /* USE_MARK_BITS */
 
 #if defined(I386) && defined(__GNUC__)
 # define LONG_MULT(hprod, lprod, x, y) { \
-        asm("mull %2" : "=a"(lprod), "=d"(hprod) : "g"(y), "0"(x)); \
+        __asm__ __volatile__("mull %2" : "=a"(lprod), "=d"(hprod) \
+                             : "g"(y), "0"(x)); \
   }
 #else /* No in-line X86 assembly code */
 # define LONG_MULT(hprod, lprod, x, y) { \
-        unsigned long long prod = (unsigned long long)x \
-                                  * (unsigned long long)y; \
+        unsigned long long prod = (unsigned long long)(x) \
+                                  * (unsigned long long)(y); \
         hprod = prod >> 32;  \
         lprod = (unsigned32)prod;  \
   }
@@ -216,7 +216,6 @@ exit_label: ; \
     { \
         char * mark_byte_addr = (char *)hhdr -> hb_marks + (bit_no); \
         char mark_byte = *mark_byte_addr; \
-          \
         if (mark_byte) goto exit_label; \
         *mark_byte_addr = 1;  \
     }
index 9d97e32..7168c14 100644 (file)
@@ -787,7 +787,7 @@ typedef word page_hash_table[PHT_SIZE];
 # if defined(THREADS) && defined(MPROTECT_VDB)
 #   include "atomic_ops.h"
 # endif
-#endif
+#endif /* !PARALLEL_MARK */
 
 /* We maintain layout maps for heap blocks containing objects of a given */
 /* size.  Each entry in this map describes a byte offset and has the     */
@@ -1338,10 +1338,9 @@ struct GC_traced_stack_sect_s {
 /* Set mark bit correctly, even if mark bits may be concurrently        */
 /* accessed.                                                            */
 #ifdef PARALLEL_MARK
-# define OR_WORD(addr, bits) \
-        { AO_or((volatile AO_t *)(addr), (AO_t)bits); }
+# define OR_WORD(addr, bits) AO_or((volatile AO_t *)(addr), (AO_t)(bits))
 #else
-# define OR_WORD(addr, bits) *(addr) |= (bits)
+# define OR_WORD(addr, bits) (void)(*(addr) |= (bits))
 #endif
 
 /* Mark bit operations */
@@ -1355,16 +1354,15 @@ struct GC_traced_stack_sect_s {
 
 #ifdef USE_MARK_BYTES
 # define mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[n])
-# define set_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[n]) = 1
-# define clear_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[n]) = 0
-#else /* !USE_MARK_BYTES */
-# define mark_bit_from_hdr(hhdr,n) (((hhdr)->hb_marks[divWORDSZ(n)] \
-                            >> (modWORDSZ(n))) & (word)1)
+# define set_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[n] = 1)
+# define clear_mark_bit_from_hdr(hhdr,n) ((hhdr)->hb_marks[n] = 0)
+#else
+# define mark_bit_from_hdr(hhdr,n) \
+              (((hhdr)->hb_marks[divWORDSZ(n)] >> modWORDSZ(n)) & (word)1)
 # define set_mark_bit_from_hdr(hhdr,n) \
-                            OR_WORD((hhdr)->hb_marks+divWORDSZ(n), \
-                                    (word)1 << modWORDSZ(n))
-# define clear_mark_bit_from_hdr(hhdr,n) (hhdr)->hb_marks[divWORDSZ(n)] \
-                                &= ~((word)1 << modWORDSZ(n))
+              OR_WORD((hhdr)->hb_marks+divWORDSZ(n), (word)1 << modWORDSZ(n))
+# define clear_mark_bit_from_hdr(hhdr,n) \
+              ((hhdr)->hb_marks[divWORDSZ(n)] &= ~((word)1 << modWORDSZ(n)))
 #endif /* !USE_MARK_BYTES */
 
 #ifdef MARK_BIT_PER_OBJ
@@ -1381,8 +1379,8 @@ struct GC_traced_stack_sect_s {
 #  define MARK_BIT_OFFSET(sz) BYTES_TO_GRANULES(sz)
 #  define IF_PER_OBJ(x)
 #  define FINAL_MARK_BIT(sz) \
-        ((sz) > MAXOBJBYTES? MARK_BITS_PER_HBLK \
-                        : BYTES_TO_GRANULES((sz) * HBLK_OBJS(sz)))
+                ((sz) > MAXOBJBYTES ? MARK_BITS_PER_HBLK \
+                                : BYTES_TO_GRANULES((sz) * HBLK_OBJS(sz)))
 #endif
 
 /* Important internal collector routines */
@@ -1628,7 +1626,7 @@ GC_INNER void GC_freehblk(struct hblk * p);
 
 /*  Misc GC: */
 GC_INNER GC_bool GC_expand_hp_inner(word n);
-GC_INNER void GC_start_reclaim(int abort_if_found);
+GC_INNER void GC_start_reclaim(GC_bool abort_if_found);
                                 /* Restore unmarked objects to free     */
                                 /* lists, or (if abort_if_found is      */
                                 /* TRUE) report them.                   */
index a562b79..db3fd2b 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -264,10 +264,13 @@ GC_INNER char * GC_get_maps(void)
             maps_size = 0;
             do {
                 result = GC_repeat_read(f, maps_buf, maps_buf_sz-1);
-                if (result <= 0) return 0;
+                if (result <= 0)
+                  break;
                 maps_size += result;
             } while (result == maps_buf_sz-1);
             close(f);
+            if (result <= 0)
+              return 0;
 #           ifdef THREADS
               if (maps_size > old_maps_size) {
                 if (GC_print_stats)
@@ -3662,7 +3665,7 @@ GC_INNER void GC_dirty_init(void)
 GC_INNER void GC_remove_protection(struct hblk *h, word nblocks,
                                    GC_bool is_ptrfree) {}
 
-# define READ(fd,buf,nbytes) read(fd, buf, nbytes)
+#define READ read
 
 GC_INNER void GC_read_dirty(void)
 {
index 16d0dc9..d9c3792 100644 (file)
@@ -727,13 +727,14 @@ STATIC void GC_remove_all_threads_but_me(void)
     /* Some old kernels only have a single "cpu nnnn ..."     */
     /* entry in /proc/stat.  We identify those as             */
     /* uniprocessors.                                         */
-    size_t i, len = 0;
+    int i, len;
 
     f = open("/proc/stat", O_RDONLY);
-    if (f < 0 || (len = STAT_READ(f, stat_buf, STAT_BUF_SIZE)) < 100) {
+    if (f < 0) {
       WARN("Couldn't read /proc/stat\n", 0);
       return 1; /* assume an uniprocessor */
     }
+    len = STAT_READ(f, stat_buf, STAT_BUF_SIZE);
     close(f);
 
     for (i = 0; i < len - 100; ++i) {