Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_DEX_CACHE_H_ |
| 4 | #define ART_SRC_DEX_CACHE_H_ |
| 5 | |
| 6 | #include "globals.h" |
| 7 | #include "macros.h" |
| 8 | #include "object.h" |
| 9 | |
| 10 | namespace art { |
| 11 | |
| 12 | class Class; |
| 13 | class Field; |
| 14 | class Method; |
| 15 | class String; |
| 16 | union JValue; |
| 17 | |
| 18 | class DexCache : public ObjectArray { |
| 19 | public: |
| 20 | |
| 21 | enum ArrayIndexes { |
| 22 | kStrings = 0, |
| 23 | kClasses = 1, |
| 24 | kMethods = 2, |
| 25 | kFields = 3, |
| 26 | kMax = 4, |
| 27 | }; |
| 28 | |
| 29 | void Init(ObjectArray* strings, |
| 30 | ObjectArray* classes, |
| 31 | ObjectArray* methods, |
| 32 | ObjectArray* fields); |
| 33 | |
| 34 | size_t NumStrings() const { |
| 35 | return GetStrings()->GetLength(); |
| 36 | } |
| 37 | |
| 38 | size_t NumClasses() const { |
| 39 | return GetClasses()->GetLength(); |
| 40 | } |
| 41 | |
| 42 | size_t NumMethods() const { |
| 43 | return GetMethods()->GetLength(); |
| 44 | } |
| 45 | |
| 46 | size_t NumFields() const { |
| 47 | return GetFields()->GetLength(); |
| 48 | } |
| 49 | |
| 50 | String* GetResolvedString(uint32_t string_idx) const { |
| 51 | return down_cast<String*>(GetStrings()->Get(string_idx)); |
| 52 | } |
| 53 | |
| 54 | void SetResolvedString(uint32_t string_idx, String* resolved) { |
| 55 | GetStrings()->Set(string_idx, resolved); |
| 56 | } |
| 57 | |
| 58 | Class* GetResolvedClass(uint32_t class_idx) const { |
| 59 | return down_cast<Class*>(GetClasses()->Get(class_idx)); |
| 60 | } |
| 61 | |
| 62 | void SetResolvedClass(uint32_t class_idx, Class* resolved) { |
| 63 | GetClasses()->Set(class_idx, resolved); |
| 64 | } |
| 65 | |
| 66 | Method* GetResolvedMethod(uint32_t method_idx) const { |
| 67 | return down_cast<Method*>(GetMethods()->Get(method_idx)); |
| 68 | } |
| 69 | |
| 70 | void SetResolvedMethod(uint32_t method_idx, Method* resolved) { |
| 71 | GetMethods()->Set(method_idx, resolved); |
| 72 | } |
| 73 | |
| 74 | Field* GetResolvedField(uint32_t field_idx) const { |
| 75 | return down_cast<Field*>(GetFields()->Get(field_idx)); |
| 76 | } |
| 77 | |
| 78 | void SetResolvedfield(uint32_t field_idx, Field* resolved) { |
| 79 | GetFields()->Set(field_idx, resolved); |
| 80 | } |
| 81 | |
| 82 | private: |
| 83 | ObjectArray* GetStrings() const { |
| 84 | return down_cast<ObjectArray*>(Get(kStrings)); |
| 85 | } |
| 86 | ObjectArray* GetClasses() const { |
| 87 | return down_cast<ObjectArray*>(Get(kClasses)); |
| 88 | } |
| 89 | ObjectArray* GetMethods() const { |
| 90 | return down_cast<ObjectArray*>(Get(kMethods)); |
| 91 | } |
| 92 | ObjectArray* GetFields() const { |
| 93 | return down_cast<ObjectArray*>(Get(kFields)); |
| 94 | } |
| 95 | DexCache(); |
| 96 | }; |
| 97 | |
| 98 | } // namespace art |
| 99 | |
| 100 | #endif // ART_SRC_DEX_CACHE_H_ |