summaryrefslogtreecommitdiff
path: root/src/dex_file.h
diff options
context:
space:
mode:
author Brian Carlstrom <bdc@google.com> 2011-07-21 14:07:47 -0700
committer Brian Carlstrom <bdc@google.com> 2011-07-22 15:23:33 -0700
commit578bbdc684db8ed68e9fedbc678669d27fa68b6e (patch)
treed752941d81ad6d7e248c349ce21371a8ae369693 /src/dex_file.h
parent45a76cb99104a222d6a9bd768a084893dcb7cf30 (diff)
Move DexFiles to be allocated on the heap
Removed pointer from DexFile to RawDexfile to allow heap allocation of DexFile. DexFile is now an ObjectArray of ObjectArrays. Removing the pointer from DexFile to RawDexfile meant adding arguments to pass the RawDexfile along to ClassLinker::LoadClass, LoadInterfaces, LoadField, LoadMethod, LinkClass, LinkInterfaces, ResolveClass to avoid the need to look a RawDexfile up from a DexFile. ClassLinker::CreateArrayClass now takes the raw_dex_file to assist in looking up the component class from the proper source. Moved Method::HasSame* methods to ClassLinker since for access to the RawDexfile (and tests of HasSame from ObjectTest to ClassLinkerTest. src/dex_file.cc src/dex_file.h src/class_linker.cc src/class_linker.h src/object.h RunTime::Create/RunTime::Init/ClassLinker::Create/ClassLinker::Init now take the boot class path. A boot class path with Ljava/lang/Object; must be provided to initalize [Ljava/lang/Object; during startup in order to heap allocate DexFiles. src/class_linker.cc src/class_linker.h src/runtime.cc src/runtime.h Restored FindClass to load from a specific dex file. This is for use by class loaders, otherwise it is assumed the caller wants to use the boot classpath. We now distinguish and track the boot classpath as separate from other dex files known to the class linker. Renamed AppendToClassPath to AppendToBootClassPath and FindInClassPath to FindInBootClassPath to clarify. src/class_linker.cc src/class_linker.h Cleaned up AllocCharArray to generic AllocArray and added AllocObjectArray. Added a functional ObjectArray implementation and a ObjectTest to cover it. src/heap.h src/object.h src/object_test.cc Switched more Object* downcasting to down_cast src/class_linker.cc Switched order of arguments for DexFile::SetResolved to follow more conventional collection ordering ( "(index, value)" vs "(value, index)" ) src/dex_file.h src/class_linker.cc src/class_linker.h Added class_linker_ and java_lang_raw_dex_file_ to RuntimeTest as convenience to test subclasses. ClassLinkerTest now can use these to simplify its ::Assert* methods. JniCompilerTest now uses it for setting up its boot class path. Removed now unneeded OpenDexFileBase64. src/common_test.h src/class_linker_test.cc src/jni_compiler_test.cc Add external/gtest/include to non-test include path so FRIEND_TEST can be used. Add src to include path to remove the need of using in in art/src files. build/Android.libart.host.mk build/Android.libart.mk src/assembler.cc src/assembler.h src/assembler_arm.cc src/assembler_arm.h src/assembler_x86.cc src/assembler_x86.h src/assembler_x86_test.cc src/base64.cc src/base64.h src/calling_convention.cc src/calling_convention.h src/calling_convention_arm.cc src/calling_convention_x86.cc src/casts.h src/class_linker.h src/class_linker_test.cc src/common_test.h src/constants.h src/constants_arm.h src/constants_x86.h src/dex_file.cc src/dex_file.h src/dex_file_test.cc src/dex_instruction.cc src/dex_instruction.h src/dex_instruction_visitor.h src/dex_instruction_visitor_test.cc src/dex_verifier.cc src/dex_verifier.h src/heap.cc src/heap.h src/jni_compiler.cc src/jni_compiler_test.cc src/jni_internal.cc src/jni_internal.h src/leb128.h src/managed_register.h src/managed_register_arm.cc src/managed_register_arm.h src/managed_register_arm_test.cc src/managed_register_x86.cc src/managed_register_x86.h src/managed_register_x86_test.cc src/mark_stack.cc src/mark_stack.h src/mark_sweep.cc src/mark_sweep.h src/memory_region.cc src/memory_region.h src/monitor.h src/object.cc src/object.h src/object_bitmap.cc src/object_bitmap.h src/object_test.cc src/offsets.cc src/offsets.h src/raw_dex_file.cc src/raw_dex_file.h src/raw_dex_file_test.cc src/runtime.cc src/runtime.h src/scoped_ptr.h src/space.cc src/space.h src/space_test.cc src/stringpiece.cc src/thread.cc src/thread.h src/thread_arm.cc src/thread_x86.cc src/utils.h Change-Id: Ib633cea878c36921e9037b0464cb903aec318c3e
Diffstat (limited to 'src/dex_file.h')
-rw-r--r--src/dex_file.h105
1 files changed, 52 insertions, 53 deletions
diff --git a/src/dex_file.h b/src/dex_file.h
index 1f4afa33c9..63393176c2 100644
--- a/src/dex_file.h
+++ b/src/dex_file.h
@@ -3,9 +3,9 @@
#ifndef ART_SRC_DEX_FILE_H_
#define ART_SRC_DEX_FILE_H_
-#include "src/globals.h"
-#include "src/macros.h"
-#include "src/raw_dex_file.h"
+#include "globals.h"
+#include "macros.h"
+#include "object.h"
namespace art {
@@ -15,82 +15,81 @@ class Method;
class String;
union JValue;
-class DexFile {
+class DexFile : public ObjectArray {
public:
- // Opens a .dex file from the file system. Returns NULL on failure.
- static DexFile* OpenFile(const char* filename);
- // Opens a .dex file from a RawDexFile. Takes ownership of the
- // RawDexFile.
- static DexFile* Open(RawDexFile* raw);
+ enum ArrayIndexes {
+ kStrings = 0,
+ kClasses = 1,
+ kMethods = 2,
+ kFields = 3,
+ kMax = 4,
+ };
- // Close and deallocate.
- ~DexFile();
+ void Init(ObjectArray* strings, ObjectArray* classes, ObjectArray* methods, ObjectArray* fields);
- size_t NumTypes() const {
- return num_classes_;
+ size_t NumStrings() const {
+ return GetStrings()->GetLength();
}
- size_t NumMethods() const {
- return num_methods_;
+ size_t NumClasses() const {
+ return GetClasses()->GetLength();
}
- bool HasClass(const StringPiece& descriptor) {
- return raw_->FindClassDef(descriptor) != NULL;
+ size_t NumMethods() const {
+ return GetMethods()->GetLength();
}
- RawDexFile* GetRaw() const {
- return raw_.get();
+ size_t NumFields() const {
+ return GetFields()->GetLength();
}
String* GetResolvedString(uint32_t string_idx) const {
- CHECK_LT(string_idx, num_strings_);
- return strings_[string_idx];
+ return down_cast<String*>(GetStrings()->Get(string_idx));
}
- void SetResolvedString(String* resolved, uint32_t string_idx) {
- CHECK_LT(string_idx, num_strings_);
- strings_[string_idx] = resolved;
+ void SetResolvedString(uint32_t string_idx, String* resolved) {
+ GetStrings()->Set(string_idx, resolved);
}
Class* GetResolvedClass(uint32_t class_idx) const {
- CHECK_LT(class_idx, num_classes_);
- return classes_[class_idx];
+ return down_cast<Class*>(GetClasses()->Get(class_idx));
}
- void SetResolvedClass(Class* resolved, uint32_t class_idx) {
- CHECK_LT(class_idx, num_classes_);
- classes_[class_idx] = resolved;
+ void SetResolvedClass(uint32_t class_idx, Class* resolved) {
+ GetClasses()->Set(class_idx, resolved);
}
- private:
- DexFile(RawDexFile* raw) : raw_(raw) {};
-
- void Init();
-
- // Table of contents for interned String objects.
- String** strings_;
- size_t num_strings_;
-
- // Table of contents for Class objects.
- Class** classes_;
- size_t num_classes_;
-
- // Table of contents for methods.
- Method** methods_;
- size_t num_methods_;
+ Method* GetResolvedMethod(uint32_t method_idx) const {
+ return down_cast<Method*>(GetMethods()->Get(method_idx));
+ }
- // Table of contents for fields.
- Field** fields_;
- size_t num_fields_;
+ void SetResolvedMethod(uint32_t method_idx, Method* resolved) {
+ GetMethods()->Set(method_idx, resolved);
+ }
- // The size of the DEX file, in bytes.
- size_t length_;
+ Field* GetResolvedField(uint32_t field_idx) const {
+ return down_cast<Field*>(GetFields()->Get(field_idx));
+ }
- // The underlying dex file.
- scoped_ptr<RawDexFile> raw_;
+ void SetResolvedfield(uint32_t field_idx, Field* resolved) {
+ GetFields()->Set(field_idx, resolved);
+ }
- DISALLOW_COPY_AND_ASSIGN(DexFile);
+ private:
+ ObjectArray* GetStrings() const {
+ return down_cast<ObjectArray*>(Get(kStrings));
+ }
+ ObjectArray* GetClasses() const {
+ return down_cast<ObjectArray*>(Get(kClasses));
+ }
+ ObjectArray* GetMethods() const {
+ return down_cast<ObjectArray*>(Get(kMethods));
+ }
+ ObjectArray* GetFields() const {
+ return down_cast<ObjectArray*>(Get(kFields));
+ }
+ DexFile();
};
} // namespace art