LCOV - code coverage report
Current view: top level - mm/boehm-gc - gcj_mlc.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 103 0.0 %
Date: 2015-06-10 18:10:59 Functions: 0 6 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
       3             :  * Copyright (c) 1999-2004 Hewlett-Packard Development Company, L.P.
       4             :  *
       5             :  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
       6             :  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
       7             :  *
       8             :  * Permission is hereby granted to use or copy this program
       9             :  * for any purpose,  provided the above notices are retained on all copies.
      10             :  * Permission to modify the code and to distribute modified code is granted,
      11             :  * provided the above notices are retained, and a notice that the code was
      12             :  * modified is included with the above copyright notice.
      13             :  *
      14             :  */
      15             : 
      16             : #include "private/gc_pmark.h"  /* includes gc_priv.h */
      17             : 
      18             : #ifdef GC_GCJ_SUPPORT
      19             : 
      20             : /*
      21             :  * This is an allocator interface tuned for gcj (the GNU static
      22             :  * java compiler).
      23             :  *
      24             :  * Each allocated object has a pointer in its first word to a vtable,
      25             :  * which for our purposes is simply a structure describing the type of
      26             :  * the object.
      27             :  * This descriptor structure contains a GC marking descriptor at offset
      28             :  * MARK_DESCR_OFFSET.
      29             :  *
      30             :  * It is hoped that this interface may also be useful for other systems,
      31             :  * possibly with some tuning of the constants.  But the immediate goal
      32             :  * is to get better gcj performance.
      33             :  *
      34             :  * We assume:
      35             :  *  1) Counting on explicit initialization of this interface is OK;
      36             :  *  2) FASTLOCK is not a significant win.
      37             :  */
      38             : 
      39             : #include "gc_gcj.h"
      40             : #include "private/dbg_mlc.h"
      41             : 
      42             : #ifdef GC_ASSERTIONS
      43             :   GC_INNER /* variable is also used in thread_local_alloc.c */
      44             : #else
      45             :   STATIC
      46             : #endif
      47             : GC_bool GC_gcj_malloc_initialized = FALSE;
      48             : 
      49             : int GC_gcj_kind = 0;    /* Object kind for objects with descriptors     */
      50             :                         /* in "vtable".                                 */
      51             : int GC_gcj_debug_kind = 0;
      52             :                         /* The kind of objects that is always marked    */
      53             :                         /* with a mark proc call.                       */
      54             : 
      55             : GC_INNER ptr_t * GC_gcjobjfreelist = NULL;
      56             : 
      57             : STATIC ptr_t * GC_gcjdebugobjfreelist = NULL;
      58             : 
      59             : /*ARGSUSED*/
      60           0 : STATIC struct GC_ms_entry * GC_gcj_fake_mark_proc(word * addr,
      61             :                                         struct GC_ms_entry *mark_stack_ptr,
      62             :                                         struct GC_ms_entry *mark_stack_limit,
      63             :                                         word env)
      64             : {
      65           0 :     ABORT("No client gcj mark proc is specified");
      66           0 :     return mark_stack_ptr;
      67             : }
      68             : 
      69             : /* Caller does not hold allocation lock. */
      70           0 : GC_API void GC_CALL GC_init_gcj_malloc(int mp_index,
      71             :                                        void * /* really GC_mark_proc */mp)
      72             : {
      73             :     GC_bool ignore_gcj_info;
      74             :     DCL_LOCK_STATE;
      75             : 
      76           0 :     if (mp == 0)        /* In case GC_DS_PROC is unused.        */
      77           0 :       mp = (void *)(word)GC_gcj_fake_mark_proc;
      78             : 
      79           0 :     GC_init();  /* In case it's not already done.       */
      80           0 :     LOCK();
      81           0 :     if (GC_gcj_malloc_initialized) {
      82           0 :       UNLOCK();
      83           0 :       return;
      84             :     }
      85           0 :     GC_gcj_malloc_initialized = TRUE;
      86             : #   ifdef GC_IGNORE_GCJ_INFO
      87             :       /* This is useful for debugging on platforms with missing getenv(). */
      88             :       ignore_gcj_info = 1;
      89             : #   else
      90           0 :       ignore_gcj_info = (0 != GETENV("GC_IGNORE_GCJ_INFO"));
      91             : #   endif
      92           0 :     if (GC_print_stats && ignore_gcj_info) {
      93           0 :         GC_log_printf("Gcj-style type information is disabled!\n");
      94             :     }
      95             :     GC_ASSERT(GC_mark_procs[mp_index] == (GC_mark_proc)0); /* unused */
      96           0 :     GC_mark_procs[mp_index] = (GC_mark_proc)(word)mp;
      97           0 :     if ((unsigned)mp_index >= GC_n_mark_procs)
      98           0 :         ABORT("GC_init_gcj_malloc: bad index");
      99             :     /* Set up object kind gcj-style indirect descriptor. */
     100           0 :       GC_gcjobjfreelist = (ptr_t *)GC_new_free_list_inner();
     101           0 :       if (ignore_gcj_info) {
     102             :         /* Use a simple length-based descriptor, thus forcing a fully   */
     103             :         /* conservative scan.                                           */
     104           0 :         GC_gcj_kind = GC_new_kind_inner((void **)GC_gcjobjfreelist,
     105             :                                         (0 | GC_DS_LENGTH),
     106             :                                         TRUE, TRUE);
     107             :       } else {
     108           0 :         GC_gcj_kind = GC_new_kind_inner(
     109             :                         (void **)GC_gcjobjfreelist,
     110             :                         (((word)(-(signed_word)MARK_DESCR_OFFSET
     111             :                                  - GC_INDIR_PER_OBJ_BIAS))
     112             :                          | GC_DS_PER_OBJECT),
     113             :                         FALSE, TRUE);
     114             :       }
     115             :     /* Set up object kind for objects that require mark proc call.      */
     116           0 :       if (ignore_gcj_info) {
     117           0 :         GC_gcj_debug_kind = GC_gcj_kind;
     118           0 :         GC_gcjdebugobjfreelist = GC_gcjobjfreelist;
     119             :       } else {
     120           0 :         GC_gcjdebugobjfreelist = (ptr_t *)GC_new_free_list_inner();
     121           0 :         GC_gcj_debug_kind = GC_new_kind_inner(
     122             :                                 (void **)GC_gcjdebugobjfreelist,
     123           0 :                                 GC_MAKE_PROC(mp_index,
     124             :                                              1 /* allocated with debug info */),
     125             :                                 FALSE, TRUE);
     126             :       }
     127           0 :     UNLOCK();
     128             : }
     129             : 
     130             : #define GENERAL_MALLOC_INNER(lb,k) \
     131             :     GC_clear_stack(GC_generic_malloc_inner(lb, k))
     132             : 
     133             : #define GENERAL_MALLOC_INNER_IOP(lb,k) \
     134             :     GC_clear_stack(GC_generic_malloc_inner_ignore_off_page(lb, k))
     135             : 
     136             : /* We need a mechanism to release the lock and invoke finalizers.       */
     137             : /* We don't really have an opportunity to do this on a rarely executed  */
     138             : /* path on which the lock is not held.  Thus we check at a              */
     139             : /* rarely executed point at which it is safe to release the lock.       */
     140             : /* We do this even where we could just call GC_INVOKE_FINALIZERS,       */
     141             : /* since it's probably cheaper and certainly more uniform.              */
     142             : /* FIXME - Consider doing the same elsewhere?                           */
     143           0 : static void maybe_finalize(void)
     144             : {
     145             :    static word last_finalized_no = 0;
     146             :    DCL_LOCK_STATE;
     147             : 
     148           0 :    if (GC_gc_no == last_finalized_no) return;
     149           0 :    if (!GC_is_initialized) return;
     150           0 :    UNLOCK();
     151           0 :    GC_INVOKE_FINALIZERS();
     152           0 :    LOCK();
     153           0 :    last_finalized_no = GC_gc_no;
     154             : }
     155             : 
     156             : /* Allocate an object, clear it, and store the pointer to the   */
     157             : /* type structure (vtable in gcj).                              */
     158             : /* This adds a byte at the end of the object if GC_malloc would.*/
     159             : #ifdef THREAD_LOCAL_ALLOC
     160           0 :   GC_INNER void * GC_core_gcj_malloc(size_t lb,
     161             :                                      void * ptr_to_struct_containing_descr)
     162             : #else
     163             :   GC_API void * GC_CALL GC_gcj_malloc(size_t lb,
     164             :                                       void * ptr_to_struct_containing_descr)
     165             : #endif
     166             : {
     167             :     ptr_t op;
     168             :     ptr_t * opp;
     169             :     word lg;
     170             :     DCL_LOCK_STATE;
     171             : 
     172           0 :     if(SMALL_OBJ(lb)) {
     173           0 :         lg = GC_size_map[lb];
     174           0 :         opp = &(GC_gcjobjfreelist[lg]);
     175           0 :         LOCK();
     176           0 :         op = *opp;
     177           0 :         if(EXPECT(op == 0, FALSE)) {
     178           0 :             maybe_finalize();
     179           0 :             op = (ptr_t)GENERAL_MALLOC_INNER((word)lb, GC_gcj_kind);
     180           0 :             if (0 == op) {
     181           0 :                 GC_oom_func oom_fn = GC_oom_fn;
     182           0 :                 UNLOCK();
     183           0 :                 return((*oom_fn)(lb));
     184             :             }
     185             :         } else {
     186           0 :             *opp = obj_link(op);
     187           0 :             GC_bytes_allocd += GRANULES_TO_BYTES(lg);
     188             :         }
     189           0 :         *(void **)op = ptr_to_struct_containing_descr;
     190             :         GC_ASSERT(((void **)op)[1] == 0);
     191           0 :         UNLOCK();
     192             :     } else {
     193           0 :         LOCK();
     194           0 :         maybe_finalize();
     195           0 :         op = (ptr_t)GENERAL_MALLOC_INNER((word)lb, GC_gcj_kind);
     196           0 :         if (0 == op) {
     197           0 :             GC_oom_func oom_fn = GC_oom_fn;
     198           0 :             UNLOCK();
     199           0 :             return((*oom_fn)(lb));
     200             :         }
     201           0 :         *(void **)op = ptr_to_struct_containing_descr;
     202           0 :         UNLOCK();
     203             :     }
     204           0 :     return((void *) op);
     205             : }
     206             : 
     207             : /* Similar to GC_gcj_malloc, but add debug info.  This is allocated     */
     208             : /* with GC_gcj_debug_kind.                                              */
     209           0 : GC_API void * GC_CALL GC_debug_gcj_malloc(size_t lb,
     210             :                 void * ptr_to_struct_containing_descr, GC_EXTRA_PARAMS)
     211             : {
     212             :     void * result;
     213             :     DCL_LOCK_STATE;
     214             : 
     215             :     /* We're careful to avoid extra calls, which could          */
     216             :     /* confuse the backtrace.                                   */
     217           0 :     LOCK();
     218           0 :     maybe_finalize();
     219           0 :     result = GC_generic_malloc_inner(lb + DEBUG_BYTES, GC_gcj_debug_kind);
     220           0 :     if (result == 0) {
     221           0 :         GC_oom_func oom_fn = GC_oom_fn;
     222           0 :         UNLOCK();
     223           0 :         GC_err_printf("GC_debug_gcj_malloc(%ld, %p) returning NULL (",
     224             :                       (unsigned long)lb, ptr_to_struct_containing_descr);
     225           0 :         GC_err_puts(s);
     226           0 :         GC_err_printf(":%d)\n", i);
     227           0 :         return((*oom_fn)(lb));
     228             :     }
     229           0 :     *((void **)((ptr_t)result + sizeof(oh))) = ptr_to_struct_containing_descr;
     230           0 :     UNLOCK();
     231           0 :     if (!GC_debugging_started) {
     232           0 :         GC_start_debugging();
     233             :     }
     234             :     ADD_CALL_CHAIN(result, ra);
     235           0 :     return (GC_store_debug_info(result, (word)lb, s, i));
     236             : }
     237             : 
     238             : /* There is no THREAD_LOCAL_ALLOC for GC_gcj_malloc_ignore_off_page().  */
     239           0 : GC_API void * GC_CALL GC_gcj_malloc_ignore_off_page(size_t lb,
     240             :                                      void * ptr_to_struct_containing_descr)
     241             : {
     242             :     ptr_t op;
     243             :     ptr_t * opp;
     244             :     word lg;
     245             :     DCL_LOCK_STATE;
     246             : 
     247           0 :     if(SMALL_OBJ(lb)) {
     248           0 :         lg = GC_size_map[lb];
     249           0 :         opp = &(GC_gcjobjfreelist[lg]);
     250           0 :         LOCK();
     251           0 :         if( (op = *opp) == 0 ) {
     252           0 :             maybe_finalize();
     253           0 :             op = (ptr_t)GENERAL_MALLOC_INNER_IOP(lb, GC_gcj_kind);
     254           0 :             if (0 == op) {
     255           0 :                 GC_oom_func oom_fn = GC_oom_fn;
     256           0 :                 UNLOCK();
     257           0 :                 return((*oom_fn)(lb));
     258             :             }
     259             :         } else {
     260           0 :             *opp = obj_link(op);
     261           0 :             GC_bytes_allocd += GRANULES_TO_BYTES(lg);
     262             :         }
     263             :     } else {
     264           0 :         LOCK();
     265           0 :         maybe_finalize();
     266           0 :         op = (ptr_t)GENERAL_MALLOC_INNER_IOP(lb, GC_gcj_kind);
     267           0 :         if (0 == op) {
     268           0 :             GC_oom_func oom_fn = GC_oom_fn;
     269           0 :             UNLOCK();
     270           0 :             return((*oom_fn)(lb));
     271             :         }
     272             :     }
     273           0 :     *(void **)op = ptr_to_struct_containing_descr;
     274           0 :     UNLOCK();
     275           0 :     return((void *) op);
     276             : }
     277             : 
     278             : #endif  /* GC_GCJ_SUPPORT */

Generated by: LCOV version 1.11