Пример #1
0
    /* Inline methods */
    Object* allocate(size_t bytes, bool *collect_now) {
      Object* obj;

#ifdef RBX_GC_STATS
      stats::GCStats::get()->young_bytes_allocated += bytes;
      stats::GCStats::get()->allocate_young.start();
#endif

      if(!current->enough_space_p(bytes)) {
#if 0
        if(!next->enough_space_p(bytes)) {
          return NULL;
        } else {
          total_objects++;
          obj = (Object*)next->allocate(bytes);
        }
#endif
        *collect_now = true;

#ifdef RBX_GC_STATS
      stats::GCStats::get()->allocate_young.stop();
#endif

        return NULL;
      } else {
        total_objects++;
        obj = (Object*)current->allocate(bytes);
      }

      if(watched_p(obj)) {
        std::cout << "detected " << obj << " during baker allocation.\n";
      }

      obj->init_header(YoungObjectZone, bytes);

#ifdef RBX_GC_STATS
      stats::GCStats::get()->allocate_young.stop();
#endif

      return obj;
    }
Пример #2
0
void* HeapManager::allocate(size_t sz) {
  void *rv = 0;
  for (size_t i=0; i<mHeaps.size(); ++i) {
    rv = mHeaps[i]->allocate(sz);
    if (rv != 0) {
      return rv;
    }
  }
  size_t newHeapSize = total() * 2;
  if (newHeapSize < sz) {
    newHeapSize = sz * 2;
  }
  Heap *h = new Heap(newHeapSize);
  mHeaps.push_back(h);
  return h->allocate(sz);
}
Пример #3
0
    /**
     * Allocates a slab of memory from the Eden space for use as a thread-local
     * allocation area that can be used without locking.
     */
    void* allocate_for_slab(size_t bytes) {
      if(!eden->enough_space_p(bytes)) {
        return NULL;
      }

      void* addr = 0;

      addr = eden->allocate(bytes);

      // If this takes us over the limit, return the bytes we just grabbed
      if(eden->over_limit_p(addr)) {
          eden->put_back(bytes);
          return NULL;
      }

      return addr;
    }
Пример #4
0
    // Allocate a MethodContext object containing +stack_slots+
    // stack positions.
    MethodContext* allocate_context(size_t stack_slots) {
      size_t full_size = sizeof(MethodContext) + (stack_slots * sizeof(Object*));

      // Off the end
      if(!contexts.enough_space_p(full_size)) return NULL;

      MethodContext* ctx = static_cast<MethodContext*>(
          contexts.allocate(full_size));

      // Masquerade as being in the Young zone so the write barrier
      // stays happy.
      ctx->init_header(YoungObjectZone,
                      ((sizeof(MethodContext) - sizeof(ObjectHeader))/ sizeof(Object*)) + stack_slots);

      ctx->full_size = full_size;
      return ctx;
    }
Пример #5
0
    /**
     * Attempts to allocate an object of the specified size from the Eden heap.
     * Unlike allocate, the header of the returned object is not initialized.
     *
     * If there is insufficient space remaining, NULL is returned and the
     * limit_hit parameter is set to true.
     */
    Object* raw_allocate(size_t bytes, bool* limit_hit) {
      Object* obj;

      if(!eden->enough_space_p(bytes)) {
        return NULL;
      } else {
        obj = eden->allocate(bytes).as<Object>();

        if(eden->over_limit_p(obj)) {
          *limit_hit = true;
        }
      }

#ifdef ENABLE_OBJECT_WATCH
      if(watched_p(obj)) {
        std::cout << "detected " << obj << " during baker allocation.\n";
      }
#endif

      return obj;
    }
Пример #6
0
    /* Inline methods */
    Object* raw_allocate(size_t bytes, bool* limit_hit) {
      Object* obj;

#ifdef RBX_GC_STATS
      stats::GCStats::get()->young_bytes_allocated += bytes;
      stats::GCStats::get()->allocate_young.start();
#endif

      if(!eden.enough_space_p(bytes)) {
#ifdef RBX_GC_STATS
       stats::GCStats::get()->allocate_young.stop();
#endif
        return NULL;
      } else {
        lock_.lock();

        total_objects++;
        obj = (Object*)eden.allocate(bytes);

        lock_.unlock();

        if(eden.over_limit_p(obj)) {
          *limit_hit = true;
        }
      }

#ifdef ENABLE_OBJECT_WATCH
      if(watched_p(obj)) {
        std::cout << "detected " << obj << " during baker allocation.\n";
      }
#endif

#ifdef RBX_GC_STATS
      stats::GCStats::get()->allocate_young.stop();
#endif

      return obj;
    }
Пример #7
0
    Object* allocate(size_t bytes) {
      Object* obj;

#ifdef RBX_GC_STATS
      stats::GCStats::get()->young_bytes_allocated += bytes;
      stats::GCStats::get()->allocate_young.start();
#endif

      if(!eden.enough_space_p(bytes)) {
#ifdef RBX_GC_STATS
       stats::GCStats::get()->allocate_young.stop();
#endif
        return NULL;
      } else {
        lock_.lock();

        total_objects++;
        obj = (Object*)eden.allocate(bytes);

        lock_.unlock();
      }

#ifdef ENABLE_OBJECT_WATCH
      if(watched_p(obj)) {
        std::cout << "detected " << obj << " during baker allocation.\n";
      }
#endif

      obj->init_header(YoungObjectZone, InvalidType);

#ifdef RBX_GC_STATS
      stats::GCStats::get()->allocate_young.stop();
#endif

      return obj;
    }
Пример #8
0
    /**
     * Attempts to allocate an object of the specified size from the Eden heap.
     *
     * If successful, the returned object's header is initiliazed to the young
     * generation.
     *
     * If there is insufficient space remaining, NULL is returned and the
     * limit_hit parameter is set to true.
     */
    Object* allocate(size_t bytes, bool* limit_hit) {
      Object* obj;

      if(!eden.enough_space_p(bytes)) {
        return NULL;
      } else {
        total_objects++;
        obj = eden.allocate(bytes).as<Object>();

        if(eden.over_limit_p(obj)) {
          *limit_hit = true;
        }
      }

#ifdef ENABLE_OBJECT_WATCH
      if(watched_p(obj)) {
        std::cout << "detected " << obj << " during baker allocation.\n";
      }
#endif

      obj->init_header(YoungObjectZone, InvalidType);

      return obj;
    }