< prev index next >
src/share/vm/oops/instanceKlass.cpp
Print this page
*** 1167,1176 ****
--- 1167,1227 ----
if (f_name == name && f_sig == sig) {
fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
return true;
}
}
+ // field not found. Try to search for an accessor-method-pair
+ bool found = false;
+ int length = sig->utf8_length();
+ if (length > 0) {
+ // extract original signature+ one \0 char
+ char fSig[length+1];
+ sig->as_C_string(fSig,length+1);
+
+ // the signature of the get-Method is two chars longer + \0
+ char get_sig[length+3];
+ sprintf(get_sig,"()%s",fSig);
+
+ // the signature of the put-Method is three chars longer + \0
+ char put_sig[length+4];
+ sprintf(put_sig,"(%s)V",fSig);
+
+ // Look through all methods in the class.
+ Array<Method*>* methods = this->methods();
+ for (int i = 0; i < methods->length(); i++) {
+ Method* m = methods->at(i);
+
+ // extract name of accessor-field
+ u2 af = m->accessor_field_name();
+ // Is zero an valid index?
+ if (af != 0) {
+ Symbol* fn = m->constMethod()->constants()->symbol_at(af);
+ char mname[name->utf8_length()+1];
+ name->as_C_string(mname,name->utf8_length()+1);
+ // if fieldname matches. record match and store name and
+ // signature in fielddescriptor
+ if (fn->equals(mname)) {
+ found = true;
+ fd->set_field_name_from_accessor(af);
+ fd->set_sig_for_accessor(sig);
+ if (m->signature()->equals(get_sig)) {
+ // remember get method
+ fd->set_get_accessor(m->method_idnum());
+ }else if (m->signature()->equals(put_sig)) {
+ // remember put method
+ fd->set_put_accessor(m->method_idnum());
+ }
+ }
+ }
+ }
+ }
+ if (found) {
+ // initialize accesor-values in fielddescriptor
+ fd->reinitialize_accessor(const_cast<InstanceKlass*>(this));
+ // is the fielddescriptor a valid accessor-fielddescriptor?
+ return fd->is_accessor();
+ }
return false;
}
Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
< prev index next >