Add support for initializing static fields.
Change-Id: I1c5397e9ef03f4cef1646fa833e17d64fc586dce
diff --git a/src/heap.h b/src/heap.h
index 340e51c..c04a60f 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -12,10 +12,30 @@
class Heap {
public:
static Class* AllocClass(size_t size) {
- byte* raw = new byte[size];
- memset(raw, 0, size);
+ byte* raw = new byte[size]();
return reinterpret_cast<Class*>(raw);
}
+
+ static CharArray* AllocCharArray(size_t length) {
+ size_t size = sizeof(Array) + length * sizeof(uint16_t);
+ byte* raw = new byte[size]();
+ return reinterpret_cast<CharArray*>(raw);
+ }
+
+ static String* AllocString() {
+ size_t size = sizeof(String);
+ byte* raw = new byte[size]();
+ return reinterpret_cast<String*>(raw);
+ }
+
+ static String* AllocStringFromModifiedUtf8(const char* data) {
+ String* string = AllocString();
+ uint32_t count = strlen(data); // TODO
+ CharArray* array = AllocCharArray(count);
+ string->array_ = array;
+ string->count_ = count;
+ return string;
+ }
};
} // namespace art