Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1 | // 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 | |
| 10 | namespace art { |
| 11 | |
| 12 | class Heap { |
| 13 | public: |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame^] | 14 | static Class* AllocClass() { |
| 15 | byte* raw = new byte[sizeof(Class)](); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 16 | return reinterpret_cast<Class*>(raw); |
| 17 | } |
Carl Shapiro | 5fafe2b | 2011-07-09 15:34:41 -0700 | [diff] [blame] | 18 | |
| 19 | static CharArray* AllocCharArray(size_t length) { |
| 20 | size_t size = sizeof(Array) + length * sizeof(uint16_t); |
| 21 | byte* raw = new byte[size](); |
| 22 | return reinterpret_cast<CharArray*>(raw); |
| 23 | } |
| 24 | |
| 25 | static String* AllocString() { |
| 26 | size_t size = sizeof(String); |
| 27 | byte* raw = new byte[size](); |
| 28 | return reinterpret_cast<String*>(raw); |
| 29 | } |
| 30 | |
| 31 | static String* AllocStringFromModifiedUtf8(const char* data) { |
| 32 | String* string = AllocString(); |
| 33 | uint32_t count = strlen(data); // TODO |
| 34 | CharArray* array = AllocCharArray(count); |
| 35 | string->array_ = array; |
| 36 | string->count_ = count; |
| 37 | return string; |
| 38 | } |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | } // namespace art |
| 42 | |
| 43 | #endif // ART_SRC_HEAP_H_ |