[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-hotspot-runtime-dev
Subject:    Question about klassOop instanceKlass::find_field with and without boolean is_static parameter
From:       sebastian.sickelmann () gmx ! de (Sebastian Sickelmann)
Date:       2011-11-12 22:31:45
Message-ID: 4EBEF3D1.1080702 () gmx ! de
[Download RAW message or body]

While evalutation some stuff in hotspot i got to the two 
instanceKlass::find_field methods.

First i thought it could be an easy target for an code-deduplication 
refactoring. But than i saw that
changing "instanceKlass::find_field(Symbol* name, Symbol* sig, 
fieldDescriptor* fd)" to

klassOop instanceKlass::find_field(Symbol* name, Symbol* sig, 
fieldDescriptor* fd) const {
     find_field(name,sig,false,fd);
}

would change behavoir.


There main reason that make me stop to refactor it was the difference 
between a call to
instanceKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd)
and a call to
instanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, 
fieldDescriptor* fd) with is_static = false.

It is the part of
   // 2) search for field recursively in direct superinterfaces
   if (is_static) {
     klassOop intf = find_interface_field(name, sig, fd);
     if (intf != NULL) return intf;
   }

in instanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, 
fieldDescriptor* fd) method that make the difference.

I searched for the calls to these two methods to understand what's going 
on here. I found that the three usage of the method
with the boolean parameter are needed by jni (GetFieldID and 
GetStaticFieldID) and the method ciInstanceKlass::get_field_by_name
which is only used by PhaseStringOpts::PhaseStringOpts to find the 
sizeTable instancefield of the Integer Class.

The Method without the boolean parameter is used for normal field lookup 
(JVM spec (5.4.3.2, p.167).)

I think that the comment to the jvm spec in the method with the boolean 
parameter is misleading. This is a special function
which is needed to fulfill the requirements of the two jni methods and 
the special case of the static sizeTable field. I think we
can change the sizeTable example to something that uses the other method 
and does some
checking(is field static and declaring class equals to Integer) afterwards.

If this is possible i would suggest to rename the method with the 
boolean parameter to something more special and remove
the comment to JVM spec (5.4.3.2, p.167).

If i am totally wrong, please let me know.

Kind regards
Sebastian

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic