blob: 7c679ebf2f8d7257a131b489b6451df4eafa1908 [file] [log] [blame]
Carl Shapiro1fb86202011-06-27 17:43:13 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2// Author: cshapiro@google.com (Carl Shapiro)
3
4#ifndef ART_SRC_HEAP_H_
5#define ART_SRC_HEAP_H_
6
7#include "src/globals.h"
8#include "src/object.h"
9
10namespace art {
11
12class Heap {
13 public:
Carl Shapiro61e019d2011-07-14 16:53:09 -070014 static Heap* Create() {
15 Heap* new_heap = new Heap();
16 // TODO: should return NULL if the heap could not be created.
17 return new_heap;
18 }
19
20 ~Heap() {}
21
Brian Carlstrom934486c2011-07-12 23:42:50 -070022 static Class* AllocClass(DexFile* dex_file) {
Carl Shapiro565f5072011-07-10 13:39:43 -070023 byte* raw = new byte[sizeof(Class)]();
Brian Carlstrom934486c2011-07-12 23:42:50 -070024 Class* klass = reinterpret_cast<Class*>(raw);
25 klass->dex_file_ = dex_file;
26 return klass;
Carl Shapiro1fb86202011-06-27 17:43:13 -070027 }
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070028
29 static CharArray* AllocCharArray(size_t length) {
30 size_t size = sizeof(Array) + length * sizeof(uint16_t);
31 byte* raw = new byte[size]();
32 return reinterpret_cast<CharArray*>(raw);
33 }
34
35 static String* AllocString() {
36 size_t size = sizeof(String);
37 byte* raw = new byte[size]();
38 return reinterpret_cast<String*>(raw);
39 }
40
41 static String* AllocStringFromModifiedUtf8(const char* data) {
42 String* string = AllocString();
43 uint32_t count = strlen(data); // TODO
44 CharArray* array = AllocCharArray(count);
45 string->array_ = array;
46 string->count_ = count;
47 return string;
48 }
Carl Shapiro61e019d2011-07-14 16:53:09 -070049
50 private:
51 Heap() {}
52
53 DISALLOW_COPY_AND_ASSIGN(Heap);
Carl Shapiro1fb86202011-06-27 17:43:13 -070054};
55
56} // namespace art
57
58#endif // ART_SRC_HEAP_H_