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

Remove unnecessary InstanceKlass::cast()

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • None
    • hotspot

      We are calling InstanceKlass::cast(k) in many places where k is statically known to be an InstanceKlass. We probably have very old code that used "Klass* Klass::super()" before "InstanceKlass* InstanceKlass::java_super()" was introduced, or code written by people who didn't know the difference between "super()" and "java_super()".

      Example

      https://github.com/openjdk/jdk/blob/603526b55b5e9b6dfc9323d2cdc4a0b4d0f88a49/src/hotspot/share/oops/instanceKlass.cpp#L1855-L1857

        { Klass* supr = super();
          if (supr != nullptr) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
        }

      It should be rewritten to

         { InstanceKlass* supr = java_super();
          if (supr != nullptr) return supr->find_field(name, sig, fd);
        }

            iklam Ioi Lam
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: