summaryrefslogtreecommitdiffstats
path: root/src/space.h
blob: ac69ba633cc5327c7dc3b6f8c4383a1094a46e0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2011 Google Inc. All Rights Reserved.
// Author: cshapiro@google.com (Carl Shapiro)

#ifndef ART_SRC_SPACE_H_
#define ART_SRC_SPACE_H_

#include "src/globals.h"
#include "src/macros.h"

namespace art {

class Object;

// A space contains memory allocated for managed objects.
class Space {
 public:
  static Space* Create(size_t startup_size, size_t maximum_size);

  ~Space();

  Object* AllocWithGrowth(size_t num_bytes);

  Object* AllocWithoutGrowth(size_t num_bytes);

  size_t Free(void* ptr);

  void Trim();

  size_t MaxAllowedFootprint();

  void Grow(size_t num_bytes);

  byte* GetBase() {
    return base_;
  }

  size_t Size() {
    return limit_ - base_;
  }

 private:
  Space(size_t startup_size, size_t maximum_size) :
      mspace_(NULL),
      base_(NULL),
      startup_size_(startup_size),
      maximum_size_(maximum_size) {
  }

  bool Init();

  void* CreateMallocSpace(void* base, size_t startup_size,
                          size_t maximum_size);

  static void DontNeed(void* start, void* end, void* num_bytes);

  void* mspace_;

  byte* base_;

  byte* limit_;

  size_t startup_size_;

  size_t maximum_size_;

  DISALLOW_IMPLICIT_CONSTRUCTORS(Space);
};

}  // namespace art

#endif  // ART_SRC_SPACE_H_