blob: 7b31ebc093bedaba4ea8057a71cac12291b42f36 [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:
Brian Carlstrom934486c2011-07-12 23:42:50 -070014 static Class* AllocClass(DexFile* dex_file) {
Carl Shapiro565f5072011-07-10 13:39:43 -070015 byte* raw = new byte[sizeof(Class)]();
Brian Carlstrom934486c2011-07-12 23:42:50 -070016 Class* klass = reinterpret_cast<Class*>(raw);
17 klass->dex_file_ = dex_file;
18 return klass;
Carl Shapiro1fb86202011-06-27 17:43:13 -070019 }
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070020
21 static CharArray* AllocCharArray(size_t length) {
22 size_t size = sizeof(Array) + length * sizeof(uint16_t);
23 byte* raw = new byte[size]();
24 return reinterpret_cast<CharArray*>(raw);
25 }
26
27 static String* AllocString() {
28 size_t size = sizeof(String);
29 byte* raw = new byte[size]();
30 return reinterpret_cast<String*>(raw);
31 }
32
33 static String* AllocStringFromModifiedUtf8(const char* data) {
34 String* string = AllocString();
35 uint32_t count = strlen(data); // TODO
36 CharArray* array = AllocCharArray(count);
37 string->array_ = array;
38 string->count_ = count;
39 return string;
40 }
Carl Shapiro1fb86202011-06-27 17:43:13 -070041};
42
43} // namespace art
44
45#endif // ART_SRC_HEAP_H_