src/share/vm/oops/instanceKlass.cpp

Print this page




 830 }
 831 
 832 
 833 bool instanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
 834   for (JavaFieldStream fs(as_klassOop()); !fs.done(); fs.next()) {
 835     Symbol* f_name = fs.name();
 836     Symbol* f_sig  = fs.signature();
 837     if (f_name == name && f_sig == sig) {
 838       fd->initialize(as_klassOop(), fs.index());
 839       return true;
 840     }
 841   }
 842   return false;
 843 }
 844 
 845 
 846 void instanceKlass::shared_symbols_iterate(SymbolClosure* closure) {
 847   Klass::shared_symbols_iterate(closure);
 848   closure->do_symbol(&_generic_signature);
 849   closure->do_symbol(&_source_file_name);
 850   closure->do_symbol(&_source_debug_extension);
 851 
 852   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
 853     int name_index = fs.name_index();
 854     closure->do_symbol(constants()->symbol_at_addr(name_index));
 855     int sig_index  = fs.signature_index();
 856     closure->do_symbol(constants()->symbol_at_addr(sig_index));
 857   }
 858 }
 859 
 860 
 861 klassOop instanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
 862   const int n = local_interfaces()->length();
 863   for (int i = 0; i < n; i++) {
 864     klassOop intf1 = klassOop(local_interfaces()->obj_at(i));
 865     assert(Klass::cast(intf1)->is_interface(), "just checking type");
 866     // search for field in current interface
 867     if (instanceKlass::cast(intf1)->find_local_field(name, sig, fd)) {
 868       assert(fd->is_static(), "interface field must be static");
 869       return intf1;
 870     }


1927       PreviousVersionNode * pv_node = _previous_versions->at(i);
1928       delete pv_node;
1929     }
1930     delete _previous_versions;
1931     _previous_versions = NULL;
1932   }
1933 
1934   // deallocate the cached class file
1935   if (_cached_class_file_bytes != NULL) {
1936     os::free(_cached_class_file_bytes, mtClass);
1937     _cached_class_file_bytes = NULL;
1938     _cached_class_file_len = 0;
1939   }
1940 
1941   // Decrement symbol reference counts associated with the unloaded class.
1942   if (_name != NULL) _name->decrement_refcount();
1943   // unreference array name derived from this class name (arrays of an unloaded
1944   // class can't be referenced anymore).
1945   if (_array_name != NULL)  _array_name->decrement_refcount();
1946   if (_source_file_name != NULL) _source_file_name->decrement_refcount();
1947   if (_source_debug_extension != NULL) _source_debug_extension->decrement_refcount();
1948   // walk constant pool and decrement symbol reference counts
1949   _constants->unreference_symbols();


1950 }
1951 
1952 void instanceKlass::set_source_file_name(Symbol* n) {
1953   _source_file_name = n;
1954   if (_source_file_name != NULL) _source_file_name->increment_refcount();
1955 }
1956 
1957 void instanceKlass::set_source_debug_extension(Symbol* n) {
1958   _source_debug_extension = n;
1959   if (_source_debug_extension != NULL) _source_debug_extension->increment_refcount();













1960 }
1961 
1962 address instanceKlass::static_field_addr(int offset) {
1963   return (address)(offset + instanceMirrorKlass::offset_of_static_fields() + (intptr_t)java_mirror());
1964 }
1965 
1966 
1967 const char* instanceKlass::signature_name() const {
1968   const char* src = (const char*) (name()->as_C_string());
1969   const int src_length = (int)strlen(src);
1970   char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
1971   int src_index = 0;
1972   int dest_index = 0;
1973   dest[dest_index++] = 'L';
1974   while (src_index < src_length) {
1975     dest[dest_index++] = src[src_index++];
1976   }
1977   dest[dest_index++] = ';';
1978   dest[dest_index] = '\0';
1979   return dest;




 830 }
 831 
 832 
 833 bool instanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
 834   for (JavaFieldStream fs(as_klassOop()); !fs.done(); fs.next()) {
 835     Symbol* f_name = fs.name();
 836     Symbol* f_sig  = fs.signature();
 837     if (f_name == name && f_sig == sig) {
 838       fd->initialize(as_klassOop(), fs.index());
 839       return true;
 840     }
 841   }
 842   return false;
 843 }
 844 
 845 
 846 void instanceKlass::shared_symbols_iterate(SymbolClosure* closure) {
 847   Klass::shared_symbols_iterate(closure);
 848   closure->do_symbol(&_generic_signature);
 849   closure->do_symbol(&_source_file_name);

 850 
 851   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
 852     int name_index = fs.name_index();
 853     closure->do_symbol(constants()->symbol_at_addr(name_index));
 854     int sig_index  = fs.signature_index();
 855     closure->do_symbol(constants()->symbol_at_addr(sig_index));
 856   }
 857 }
 858 
 859 
 860 klassOop instanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
 861   const int n = local_interfaces()->length();
 862   for (int i = 0; i < n; i++) {
 863     klassOop intf1 = klassOop(local_interfaces()->obj_at(i));
 864     assert(Klass::cast(intf1)->is_interface(), "just checking type");
 865     // search for field in current interface
 866     if (instanceKlass::cast(intf1)->find_local_field(name, sig, fd)) {
 867       assert(fd->is_static(), "interface field must be static");
 868       return intf1;
 869     }


1926       PreviousVersionNode * pv_node = _previous_versions->at(i);
1927       delete pv_node;
1928     }
1929     delete _previous_versions;
1930     _previous_versions = NULL;
1931   }
1932 
1933   // deallocate the cached class file
1934   if (_cached_class_file_bytes != NULL) {
1935     os::free(_cached_class_file_bytes, mtClass);
1936     _cached_class_file_bytes = NULL;
1937     _cached_class_file_len = 0;
1938   }
1939 
1940   // Decrement symbol reference counts associated with the unloaded class.
1941   if (_name != NULL) _name->decrement_refcount();
1942   // unreference array name derived from this class name (arrays of an unloaded
1943   // class can't be referenced anymore).
1944   if (_array_name != NULL)  _array_name->decrement_refcount();
1945   if (_source_file_name != NULL) _source_file_name->decrement_refcount();

1946   // walk constant pool and decrement symbol reference counts
1947   _constants->unreference_symbols();
1948 
1949   if (_source_debug_extension != NULL) FREE_C_HEAP_ARRAY(u1, _source_debug_extension, mtClass);
1950 }
1951 
1952 void instanceKlass::set_source_file_name(Symbol* n) {
1953   _source_file_name = n;
1954   if (_source_file_name != NULL) _source_file_name->increment_refcount();
1955 }
1956 
1957 void instanceKlass::set_source_debug_extension(char* array, int length) {
1958   if (array == NULL) {
1959     _source_debug_extension = NULL;
1960   } else {
1961     // Adding one to the attribute length in order to store a null terminator
1962     // character could cause an overflow because the attribute length is
1963     // already coded with an u4 in the classfile, but in practice, it's
1964     // unlikely to happen.
1965     assert((length+1) > length, "Overflow checking");
1966     char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
1967     for (int i = 0; i < length; i++) {
1968       sde[i] = array[i];
1969     }
1970     sde[length] = '\0';
1971     _source_debug_extension = (char*)sde;
1972   }
1973 }
1974 
1975 address instanceKlass::static_field_addr(int offset) {
1976   return (address)(offset + instanceMirrorKlass::offset_of_static_fields() + (intptr_t)java_mirror());
1977 }
1978 
1979 
1980 const char* instanceKlass::signature_name() const {
1981   const char* src = (const char*) (name()->as_C_string());
1982   const int src_length = (int)strlen(src);
1983   char* dest = NEW_RESOURCE_ARRAY(char, src_length + 3);
1984   int src_index = 0;
1985   int dest_index = 0;
1986   dest[dest_index++] = 'L';
1987   while (src_index < src_length) {
1988     dest[dest_index++] = src[src_index++];
1989   }
1990   dest[dest_index++] = ';';
1991   dest[dest_index] = '\0';
1992   return dest;