Example #1
0
File: gc.c Project: Han40/spamOSEK
void mark (Object *obj)
{
    if (obj == JNULL)
        return;

#ifdef VERIFY_GC
    assert (is_allocated (obj), GC0);
#endif

    if (is_gc_marked (obj))
        return;
    set_gc_marked (obj);
    if (is_array (obj))
    {
        if (get_element_type (obj) == T_REFERENCE)
        {
            unsigned short i;
            unsigned short length = get_array_length (obj);
            REFERENCE *refarr = ref_array (obj);

            for (i = 0; i < length; i++)
                mark (refarr[i]);
        }
    }
    else
    {
        ClassRecord *classRecord;
        byte classIndex;

        classIndex = get_na_class_index (obj);
        for (;;)
        {
            classRecord = get_class_record (classIndex);
            // Mark fields of type REFERENCE.
            mark_reference_fields (obj, classRecord);
            if (classIndex == JAVA_LANG_OBJECT)
                break;
            classIndex = classRecord -> parentClass;
        }
    }
}
Example #2
0
/* Recursively mark reference fields.  */
static void
mark_reference_fields (tree field,
		       wide_int *mask,
		       unsigned int ubit,
		       int *pointer_after_end,
		       int *all_bits_set,
		       int *last_set_index,
		       HOST_WIDE_INT *last_view_index)
{
  /* See if we have fields from our superclass.  */
  if (DECL_NAME (field) == NULL_TREE)
    {
      mark_reference_fields (TYPE_FIELDS (TREE_TYPE (field)),
			     mask, ubit,
			     pointer_after_end, all_bits_set,
			     last_set_index, last_view_index);
      field = DECL_CHAIN (field);
    }

  for (; field != NULL_TREE; field = DECL_CHAIN (field))
    {
      HOST_WIDE_INT offset;
      HOST_WIDE_INT size_bytes;

      if (FIELD_STATIC (field))
	continue;

      offset = int_byte_position (field);
      size_bytes = int_size_in_bytes (TREE_TYPE (field));

      if (JREFERENCE_TYPE_P (TREE_TYPE (field))
	  /* An `object' of type gnu.gcj.RawData is actually non-Java
	     data.  */
	  && TREE_TYPE (field) != rawdata_ptr_type_node)
	{
	  unsigned int count;
	  unsigned int size_words;
	  unsigned int i;

	  /* If this reference slot appears to overlay a slot we think
	     we already covered, then we are doomed.  */
	  gcc_assert (offset > *last_view_index);

	  if (offset % (HOST_WIDE_INT) (POINTER_SIZE / BITS_PER_UNIT))
	    {
	      *all_bits_set = -1;
	      *pointer_after_end = 1;
	      break;
	    }

	  count = offset * BITS_PER_UNIT / POINTER_SIZE;
	  size_words = size_bytes * BITS_PER_UNIT / POINTER_SIZE;

	  *last_set_index = count;
	     
	  if (count >= ubit - 2)
	    *pointer_after_end = 1;
	  else
	    /* First word in object corresponds to most significant byte of 
	       bitmap. 
	     
	       In the case of a multiple-word record, we set pointer 
	       bits for all words in the record. This is conservative, but the 
	       size_words != 1 case is impossible in regular java code. */
	    for (i = 0; i < size_words; ++i)
	      *mask = wi::set_bit (*mask, ubit - count - i - 1);

	  /* If we saw a non-reference field earlier, then we can't
	     use the count representation.  We keep track of that in
	     *ALL_BITS_SET.  */
	  if (! *all_bits_set)
	    *all_bits_set = -1;
	}
      else if (*all_bits_set > 0)
	*all_bits_set = 0;

      *last_view_index = offset;
    }
}
Example #3
0
/* Return the marking bitmap for the class TYPE.  For now this is a
   single word describing the type.  */
tree
get_boehm_type_descriptor (tree type)
{
  unsigned int count, log2_size, ubit;
  int bit;
  int all_bits_set = 1;
  int last_set_index = 0;
  HOST_WIDE_INT last_view_index = -1;
  int pointer_after_end = 0;
  tree field, value, value_type;

  /* If the GC wasn't requested, just use a null pointer.  */
  if (! flag_use_boehm_gc)
    return null_pointer_node;

  value_type = java_type_for_mode (ptr_mode, 1);
  wide_int mask = wi::zero (TYPE_PRECISION (value_type));

  /* If we have a type of unknown size, use a proc.  */
  if (int_size_in_bytes (type) == -1)
    goto procedure_object_descriptor;

  bit = POINTER_SIZE / BITS_PER_UNIT;
  /* The size of this node has to be known.  And, we only support 32
     and 64 bit targets, so we need to know that the log2 is one of
     our values.  */
  log2_size = exact_log2 (bit);
  if (bit == -1 || (log2_size != 2 && log2_size != 3))
    {
      /* This means the GC isn't supported.  We should probably
	 abort or give an error.  Instead, for now, we just silently
	 revert.  FIXME.  */
      return null_pointer_node;
    }
  bit *= BITS_PER_UNIT;

  /* Warning avoidance.  */
  ubit = (unsigned int) bit;

  if (type == class_type_node)
    goto procedure_object_descriptor;

  field = TYPE_FIELDS (type);
  mark_reference_fields (field, &mask, ubit,
			 &pointer_after_end, &all_bits_set,
			 &last_set_index, &last_view_index);

  /* If the object is all pointers, or if the part with pointers fits
     in our bitmap, then we are ok.  Otherwise we have to allocate it
     a different way.  */
  if (all_bits_set != -1 || (pointer_after_end && flag_reduced_reflection))
    {
      /* In this case the initial part of the object is all reference
	 fields, and the end of the object is all non-reference
	 fields.  We represent the mark as a count of the fields,
	 shifted.  In the GC the computation looks something like
	 this:
	 value = DS_LENGTH | WORDS_TO_BYTES (last_set_index + 1);
	 DS_LENGTH is 0.
	 WORDS_TO_BYTES shifts by log2(bytes-per-pointer).

         In the case of flag_reduced_reflection and the bitmap would
         overflow, we tell the gc that the object is all pointers so
         that we don't have to emit reflection data for run time
         marking. */
      count = 0;
      mask = wi::zero (TYPE_PRECISION (value_type));
      ++last_set_index;
      while (last_set_index)
	{
	  if ((last_set_index & 1))
	    mask = wi::set_bit (mask, log2_size + count);
	  last_set_index >>= 1;
	  ++count;
	}
      value = wide_int_to_tree (value_type, mask);
    }