Use class def index from java.lang.Class.
Bug: 10244719
This removes the computation of the dex file index, when necessary this is
computed by searching the dex file. Its only necessary in
dalvik.system.DexFile.defineClassNative and DexFile::FindInClassPath, the
latter not showing up significantly in profiling with this change.
(cherry-picked from 8b2c0b9abc3f520495f4387ea040132ba85cae69)
Change-Id: I20c73a3b17d86286428ab0fd21bc13f51f36c85c
diff --git a/runtime/mirror/art_method-inl.h b/runtime/mirror/art_method-inl.h
index 224b2ba..ccf3e59 100644
--- a/runtime/mirror/art_method-inl.h
+++ b/runtime/mirror/art_method-inl.h
@@ -178,7 +178,7 @@
}
inline bool ArtMethod::IsRuntimeMethod() const {
- return GetDexMethodIndex() == DexFile::kDexNoIndex16;
+ return GetDexMethodIndex() == DexFile::kDexNoIndex;
}
inline bool ArtMethod::IsCalleeSaveMethod() const {
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index 5e8b827..add7e1b 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -128,7 +128,10 @@
}
void Class::SetClassSize(size_t new_class_size) {
- DCHECK_GE(new_class_size, GetClassSize()) << " class=" << PrettyTypeOf(this);
+ if (kIsDebugBuild && (new_class_size < GetClassSize())) {
+ DumpClass(LOG(ERROR), kDumpClassFullDetail);
+ CHECK_GE(new_class_size, GetClassSize()) << " class=" << PrettyTypeOf(this);
+ }
SetField32(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size, false);
}
@@ -300,22 +303,8 @@
return true;
}
// Compare the package part of the descriptor string.
- if (LIKELY(!klass1->IsProxyClass() && !klass2->IsProxyClass())) {
- ClassHelper kh(klass1);
- const DexFile* dex_file1 = &kh.GetDexFile();
- const DexFile::TypeId* type_id1 = &dex_file1->GetTypeId(klass1->GetDexTypeIndex());
- const char* descriptor1 = dex_file1->GetTypeDescriptor(*type_id1);
- kh.ChangeClass(klass2);
- const DexFile* dex_file2 = &kh.GetDexFile();
- const DexFile::TypeId* type_id2 = &dex_file2->GetTypeId(klass2->GetDexTypeIndex());
- const char* descriptor2 = dex_file2->GetTypeDescriptor(*type_id2);
- return IsInSamePackage(descriptor1, descriptor2);
- }
- ClassHelper kh(klass1);
- std::string descriptor1(kh.GetDescriptor());
- kh.ChangeClass(klass2);
- std::string descriptor2(kh.GetDescriptor());
- return IsInSamePackage(descriptor1, descriptor2);
+ return IsInSamePackage(ClassHelper(klass1).GetDescriptor(),
+ ClassHelper(klass2).GetDescriptor());
}
bool Class::IsClassClass() const {
diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h
index 99f3850..d97b603 100644
--- a/runtime/mirror/class.h
+++ b/runtime/mirror/class.h
@@ -726,6 +726,14 @@
return GetFieldObject<Class*>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), false);
}
+ uint16_t GetDexClassDefIndex() const {
+ return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), false);
+ }
+
+ void SetDexClassDefIndex(uint16_t class_def_idx) {
+ SetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx, false);
+ }
+
uint16_t GetDexTypeIndex() const {
return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), false);
}
@@ -807,7 +815,7 @@
// If class verify fails, we must return same error on subsequent tries.
Class* verify_error_class_;
- // virtual methods defined in this class; invoked through vtable
+ // Virtual methods defined in this class; invoked through vtable.
ObjectArray<ArtMethod>* virtual_methods_;
// Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
@@ -816,24 +824,28 @@
// virtual_ methods_ for miranda methods.
ObjectArray<ArtMethod>* vtable_;
- // access flags; low 16 bits are defined by VM spec
+ // Access flags; low 16 bits are defined by VM spec.
uint32_t access_flags_;
// Total size of the Class instance; used when allocating storage on gc heap.
// See also object_size_.
size_t class_size_;
- // tid used to check for recursive <clinit> invocation
+ // Tid used to check for recursive <clinit> invocation.
pid_t clinit_thread_id_;
- // type index from dex file
+ // ClassDef index in dex file, -1 if no class definition such as an array.
// TODO: really 16bits
- uint32_t dex_type_idx_;
+ int32_t dex_class_def_idx_;
- // number of instance fields that are object refs
+ // Type index in dex file.
+ // TODO: really 16bits
+ int32_t dex_type_idx_;
+
+ // Number of instance fields that are object refs.
size_t num_reference_instance_fields_;
- // number of static fields that are object refs
+ // Number of static fields that are object refs,
size_t num_reference_static_fields_;
// Total object size; used when allocating storage on gc heap.
@@ -841,7 +853,7 @@
// See also class_size_.
size_t object_size_;
- // primitive type value, or Primitive::kPrimNot (0); set for generated prim classes
+ // Primitive type value, or Primitive::kPrimNot (0); set for generated primitive classes.
Primitive::Type primitive_type_;
// Bitmap of offsets of ifields.
@@ -850,7 +862,7 @@
// Bitmap of offsets of sfields.
uint32_t reference_static_offsets_;
- // state of class initialization
+ // State of class initialization.
Status status_;
// TODO: ?
@@ -873,7 +885,6 @@
class MANAGED ClassClass : public Class {
private:
- int32_t padding_;
int64_t serialVersionUID_;
friend struct art::ClassClassOffsets; // for verifying offset information
DISALLOW_IMPLICIT_CONSTRUCTORS(ClassClass);
diff --git a/runtime/mirror/dex_cache.h b/runtime/mirror/dex_cache.h
index 6cfab9e..0522f13 100644
--- a/runtime/mirror/dex_cache.h
+++ b/runtime/mirror/dex_cache.h
@@ -164,6 +164,7 @@
}
private:
+ Object* dex_;
ObjectArray<StaticStorageBase>* initialized_static_storage_;
String* location_;
ObjectArray<ArtField>* resolved_fields_;
diff --git a/runtime/mirror/proxy.h b/runtime/mirror/proxy.h
index 7c5bc39..18a84dc 100644
--- a/runtime/mirror/proxy.h
+++ b/runtime/mirror/proxy.h
@@ -25,6 +25,8 @@
namespace mirror {
+// All proxy objects have a class which is a synthesized proxy class. The synthesized proxy class
+// has the static fields used to implement reflection on proxy objects.
class MANAGED SynthesizedProxyClass : public Class {
public:
ObjectArray<Class>* GetInterfaces() {
@@ -41,6 +43,7 @@
DISALLOW_IMPLICIT_CONSTRUCTORS(SynthesizedProxyClass);
};
+// C++ mirror of java.lang.reflect.Proxy.
class MANAGED Proxy : public Object {
private:
Object* h_;
diff --git a/runtime/mirror/string.h b/runtime/mirror/string.h
index bf545ea..81fe42f 100644
--- a/runtime/mirror/string.h
+++ b/runtime/mirror/string.h
@@ -155,8 +155,8 @@
private:
CharArray* ASCII_;
Object* CASE_INSENSITIVE_ORDER_;
- uint32_t REPLACEMENT_CHAR_;
int64_t serialVersionUID_;
+ uint32_t REPLACEMENT_CHAR_;
friend struct art::StringClassOffsets; // for verifying offset information
DISALLOW_IMPLICIT_CONSTRUCTORS(StringClass);
};