src/hotspot/share/classfile/classFileParser.cpp
changeset 53739 4dab92cc7aed
parent 53728 675dbad7a9b0
child 53745 a535ba736cab
equal deleted inserted replaced
53738:7f3b27d9c22d 53739:4dab92cc7aed
  5718   debug_only(ik->verify();)
  5718   debug_only(ik->verify();)
  5719 }
  5719 }
  5720 
  5720 
  5721 void ClassFileParser::update_class_name(Symbol* new_class_name) {
  5721 void ClassFileParser::update_class_name(Symbol* new_class_name) {
  5722   // Decrement the refcount in the old name, since we're clobbering it.
  5722   // Decrement the refcount in the old name, since we're clobbering it.
  5723   if (_class_name != NULL) {
  5723   _class_name->decrement_refcount();
  5724     _class_name->decrement_refcount();
  5724 
  5725   }
       
  5726   _class_name = new_class_name;
  5725   _class_name = new_class_name;
  5727   // Increment the refcount of the new name.
  5726   // Increment the refcount of the new name.
  5728   // Now the ClassFileParser owns this name and will decrement in
  5727   // Now the ClassFileParser owns this name and will decrement in
  5729   // the destructor.
  5728   // the destructor.
  5730   _class_name->increment_refcount();
  5729   _class_name->increment_refcount();
  5751     new_anon_name[host_pkg_len] = '/';
  5750     new_anon_name[host_pkg_len] = '/';
  5752     // Append unsafe anonymous class name. The unsafe anonymous class name can contain odd
  5751     // Append unsafe anonymous class name. The unsafe anonymous class name can contain odd
  5753     // characters.  So, do a strncpy instead of using sprintf("%s...").
  5752     // characters.  So, do a strncpy instead of using sprintf("%s...").
  5754     strncpy(new_anon_name + host_pkg_len + 1, (char *)_class_name->base(), class_name_len);
  5753     strncpy(new_anon_name + host_pkg_len + 1, (char *)_class_name->base(), class_name_len);
  5755 
  5754 
       
  5755     // Decrement old _class_name to avoid leaking.
       
  5756     _class_name->decrement_refcount();
       
  5757 
  5756     // Create a symbol and update the anonymous class name.
  5758     // Create a symbol and update the anonymous class name.
  5757     Symbol* new_name = SymbolTable::new_symbol(new_anon_name,
  5759     // The new class name is created with a refcount of one. When installed into the InstanceKlass,
       
  5760     // it'll be two and when the ClassFileParser destructor runs, it'll go back to one and get deleted
       
  5761     // when the class is unloaded.
       
  5762     _class_name = SymbolTable::new_symbol(new_anon_name,
  5758                                           (int)host_pkg_len + 1 + class_name_len,
  5763                                           (int)host_pkg_len + 1 + class_name_len,
  5759                                           CHECK);
  5764                                           CHECK);
  5760     update_class_name(new_name);
       
  5761   }
  5765   }
  5762 }
  5766 }
  5763 
  5767 
  5764 // If the host class and the anonymous class are in the same package then do
  5768 // If the host class and the anonymous class are in the same package then do
  5765 // nothing.  If the anonymous class is in the unnamed package then move it to its
  5769 // nothing.  If the anonymous class is in the unnamed package then move it to its
  5859   _has_finalizer(false),
  5863   _has_finalizer(false),
  5860   _has_empty_finalizer(false),
  5864   _has_empty_finalizer(false),
  5861   _has_vanilla_constructor(false),
  5865   _has_vanilla_constructor(false),
  5862   _max_bootstrap_specifier_index(-1) {
  5866   _max_bootstrap_specifier_index(-1) {
  5863 
  5867 
  5864   update_class_name(name != NULL ? name : vmSymbols::unknown_class_name());
  5868   _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
       
  5869   _class_name->increment_refcount();
  5865 
  5870 
  5866   assert(THREAD->is_Java_thread(), "invariant");
  5871   assert(THREAD->is_Java_thread(), "invariant");
  5867   assert(_loader_data != NULL, "invariant");
  5872   assert(_loader_data != NULL, "invariant");
  5868   assert(stream != NULL, "invariant");
  5873   assert(stream != NULL, "invariant");
  5869   assert(_stream != NULL, "invariant");
  5874   assert(_stream != NULL, "invariant");
  6084     _this_class_index, CHECK);
  6089     _this_class_index, CHECK);
  6085 
  6090 
  6086   Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
  6091   Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
  6087   assert(class_name_in_cp != NULL, "class_name can't be null");
  6092   assert(class_name_in_cp != NULL, "class_name can't be null");
  6088 
  6093 
  6089   // Update _class_name which could be null previously
  6094   // Update _class_name to reflect the name in the constant pool
  6090   // to reflect the name in the constant pool
       
  6091   update_class_name(class_name_in_cp);
  6095   update_class_name(class_name_in_cp);
  6092 
  6096 
  6093   // Don't need to check whether this class name is legal or not.
  6097   // Don't need to check whether this class name is legal or not.
  6094   // It has been checked when constant pool is parsed.
  6098   // It has been checked when constant pool is parsed.
  6095   // However, make sure it is not an array type.
  6099   // However, make sure it is not an array type.