5860
5861 void ClassFileParser::update_class_name(Symbol* new_class_name) {
5862 // Decrement the refcount in the old name, since we're clobbering it.
5863 _class_name->decrement_refcount();
5864
5865 _class_name = new_class_name;
5866 // Increment the refcount of the new name.
5867 // Now the ClassFileParser owns this name and will decrement in
5868 // the destructor.
5869 _class_name->increment_refcount();
5870 }
5871
5872
5873 // For an unsafe anonymous class that is in the unnamed package, move it to its host class's
5874 // package by prepending its host class's package name to its class name and setting
5875 // its _class_name field.
5876 void ClassFileParser::prepend_host_package_name(const InstanceKlass* unsafe_anonymous_host, TRAPS) {
5877 ResourceMark rm(THREAD);
5878 assert(strrchr(_class_name->as_C_string(), JVM_SIGNATURE_SLASH) == NULL,
5879 "Unsafe anonymous class should not be in a package");
5880 const char* host_pkg_name =
5881 ClassLoader::package_from_name(unsafe_anonymous_host->name()->as_C_string(), NULL);
5882
5883 if (host_pkg_name != NULL) {
5884 int host_pkg_len = (int)strlen(host_pkg_name);
5885 int class_name_len = _class_name->utf8_length();
5886 int symbol_len = host_pkg_len + 1 + class_name_len;
5887 char* new_anon_name = NEW_RESOURCE_ARRAY(char, symbol_len + 1);
5888 int n = os::snprintf(new_anon_name, symbol_len + 1, "%s/%.*s",
5889 host_pkg_name, class_name_len, _class_name->base());
5890 assert(n == symbol_len, "Unexpected number of characters in string");
5891
5892 // Decrement old _class_name to avoid leaking.
5893 _class_name->decrement_refcount();
5894
5895 // Create a symbol and update the anonymous class name.
5896 // The new class name is created with a refcount of one. When installed into the InstanceKlass,
5897 // it'll be two and when the ClassFileParser destructor runs, it'll go back to one and get deleted
5898 // when the class is unloaded.
5899 _class_name = SymbolTable::new_symbol(new_anon_name, symbol_len);
5900 }
5901 }
5902
5903 // If the host class and the anonymous class are in the same package then do
5904 // nothing. If the anonymous class is in the unnamed package then move it to its
5905 // host's package. If the classes are in different packages then throw an IAE
5906 // exception.
5907 void ClassFileParser::fix_unsafe_anonymous_class_name(TRAPS) {
5908 assert(_unsafe_anonymous_host != NULL, "Expected an unsafe anonymous class");
5909
|
5860
5861 void ClassFileParser::update_class_name(Symbol* new_class_name) {
5862 // Decrement the refcount in the old name, since we're clobbering it.
5863 _class_name->decrement_refcount();
5864
5865 _class_name = new_class_name;
5866 // Increment the refcount of the new name.
5867 // Now the ClassFileParser owns this name and will decrement in
5868 // the destructor.
5869 _class_name->increment_refcount();
5870 }
5871
5872
5873 // For an unsafe anonymous class that is in the unnamed package, move it to its host class's
5874 // package by prepending its host class's package name to its class name and setting
5875 // its _class_name field.
5876 void ClassFileParser::prepend_host_package_name(const InstanceKlass* unsafe_anonymous_host, TRAPS) {
5877 ResourceMark rm(THREAD);
5878 assert(strrchr(_class_name->as_C_string(), JVM_SIGNATURE_SLASH) == NULL,
5879 "Unsafe anonymous class should not be in a package");
5880 TempNewSymbol host_pkg_name =
5881 InstanceKlass::package_from_name(unsafe_anonymous_host->name());
5882
5883 if (host_pkg_name != NULL) {
5884 int host_pkg_len = host_pkg_name->utf8_length();
5885 int class_name_len = _class_name->utf8_length();
5886 int symbol_len = host_pkg_len + 1 + class_name_len;
5887 char* new_anon_name = NEW_RESOURCE_ARRAY(char, symbol_len + 1);
5888 int n = os::snprintf(new_anon_name, symbol_len + 1, "%.*s/%.*s",
5889 host_pkg_len, host_pkg_name->base(), class_name_len, _class_name->base());
5890 assert(n == symbol_len, "Unexpected number of characters in string");
5891
5892 // Decrement old _class_name to avoid leaking.
5893 _class_name->decrement_refcount();
5894
5895 // Create a symbol and update the anonymous class name.
5896 // The new class name is created with a refcount of one. When installed into the InstanceKlass,
5897 // it'll be two and when the ClassFileParser destructor runs, it'll go back to one and get deleted
5898 // when the class is unloaded.
5899 _class_name = SymbolTable::new_symbol(new_anon_name, symbol_len);
5900 }
5901 }
5902
5903 // If the host class and the anonymous class are in the same package then do
5904 // nothing. If the anonymous class is in the unnamed package then move it to its
5905 // host's package. If the classes are in different packages then throw an IAE
5906 // exception.
5907 void ClassFileParser::fix_unsafe_anonymous_class_name(TRAPS) {
5908 assert(_unsafe_anonymous_host != NULL, "Expected an unsafe anonymous class");
5909
|