Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4290047

Inlining of Object.getClass()

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P5 P5
    • 1.4.0
    • 1.4.0
    • hotspot
    • None
    • beta
    • generic
    • generic
    • Verified

      Object.getClass() is called often in reflection code, and some customers (e.g. Nortel) use the class object for hash table lookup of class specific data:

        Object obj = ...
        ClassInfo info = lookup_class_info(obj.getClass());

        ClassInfo lookup_class_info(Class cls) {
          int hash = cls.hashCode();
          // do hash table lookup
          ...
        }

      Calling Object.hashCode() is already fast, but getClass() is not. Storing a pointer to the class (or class info) in each instance will have footprint impact.



      Inlining it is trivial. Object.getClass() is already "final native", and the implementation would be:


      const int klass_offset = oopDesc::klass_offset_in_bytes();
      const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();

      // receiver in eax
      __ movl(eax, Address(eax, oopDesc::klass_offset_in_bytes()));
      __ movl(eax, Address(eax, mirror_offset));


      There has to be a null check on the receiver somewhere (throwing a NullPointerException).

      This should be done in both compiler1 and compiler2.
      steffen.grarup@eng 1999-11-10

            mgharahgsunw Mohammad Gharahgouzloo (Inactive)
            sgrarupsunw Steffen Grarup (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: