Class clean-up and compute name during image writing.
Name is computed lazily, if this occurs for an image class it will cause
a card mark and for that part of the image to be scanned every GC. By
precomputing the name we avoid the GC overhead, speed up some reflection
operations, save allocation heap footprint at a cost of ~300kb in the
image.
Remove and reorganize reflection native methods to agree with patch to
libcore.
Change-Id: I4b621be4a9d9bb381a647963066c3305ce40745f
diff --git a/src/object.h b/src/object.h
index 58c36be..3cbe9d6 100644
--- a/src/object.h
+++ b/src/object.h
@@ -1059,14 +1059,13 @@
//
// kStatusIdx: LoadClass populates with Class with information from
// the DexFile, moving the status to kStatusIdx, indicating that the
- // Class values in super_class_ and interfaces_ have not been
- // populated based on super_class_type_idx_ and
- // interfaces_type_idx_. The new Class can then be inserted into the
- // classes table.
+ // Class value in super_class_ has not been populated. The new Class
+ // can then be inserted into the classes table.
//
// kStatusLoaded: After taking a lock on Class, the ClassLinker will
// attempt to move a kStatusIdx class forward to kStatusLoaded by
- // using ResolveClass to initialize the super_class_ and interfaces_.
+ // using ResolveClass to initialize the super_class_ and ensuring the
+ // interfaces are resolved.
//
// kStatusResolved: Still holding the lock on Class, the ClassLinker
// shows linking is complete and fields of the Class populated by making
@@ -1193,8 +1192,10 @@
return (GetAccessFlags() & kAccClassIsPhantomReference) != 0;
}
- String* GetName() const;
- void SetName(String* name);
+
+ String* GetName() const ; // Returns the cached name
+ void SetName(String* name); // Sets the cached name
+ String* ComputeName(); // Computes the name, then sets the cached value
bool IsProxyClass() const {
// Read access flags without using getter as whether something is a proxy can be check in
@@ -1724,9 +1725,6 @@
bool IsArrayAssignableFromArray(const Class* klass) const;
bool IsAssignableFromArray(const Class* klass) const;
- // descriptor for the class such as "java.lang.Class" or "[C"
- String* name_; // TODO initialize
-
// defining class loader, or NULL for the "bootstrap" system loader
ClassLoader* class_loader_;
@@ -1768,12 +1766,13 @@
// of the concrete vtable_ methods for the methods in the interface.
ObjectArray<InterfaceEntry>* iftable_;
+ // descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
+ String* name_;
+
// Static fields
ObjectArray<Field>* sfields_;
- // The superclass, or NULL if this is java.lang.Object or a
- // primitive type.
- // see also super_class_type_idx_;
+ // The superclass, or NULL if this is java.lang.Object, an interface or primitive type.
Class* super_class_;
// If class verify fails, we must return same error on subsequent tries.
@@ -1788,10 +1787,6 @@
// virtual_ methods_ for miranda methods.
ObjectArray<Method>* vtable_;
- // type index from dex file
- // TODO: really 16bits
- uint32_t dex_type_idx_;
-
// access flags; low 16 bits are defined by VM spec
uint32_t access_flags_;
@@ -1802,6 +1797,10 @@
// tid used to check for recursive <clinit> invocation
pid_t clinit_thread_id_;
+ // type index from dex file
+ // TODO: really 16bits
+ uint32_t dex_type_idx_;
+
// number of instance fields that are object refs
size_t num_reference_instance_fields_;
@@ -1813,7 +1812,7 @@
// See also class_size_.
size_t object_size_;
- // primitive type index, or Primitive::kPrimNot (0); set for generated prim classes
+ // primitive type value, or Primitive::kPrimNot (0); set for generated prim classes
Primitive::Type primitive_type_;
// Bitmap of offsets of ifields.