src/hotspot/share/runtime/sharedRuntime.cpp
changeset 50761 cb07f4b539fc
parent 50666 3e66d204af9b
child 51267 2cd8bbccbd2d
equal deleted inserted replaced
50760:8e296de294e7 50761:cb07f4b539fc
  1957 
  1957 
  1958 // The caller of generate_class_cast_message() (or one of its callers)
  1958 // The caller of generate_class_cast_message() (or one of its callers)
  1959 // must use a ResourceMark in order to correctly free the result.
  1959 // must use a ResourceMark in order to correctly free the result.
  1960 char* SharedRuntime::generate_class_cast_message(
  1960 char* SharedRuntime::generate_class_cast_message(
  1961     Klass* caster_klass, Klass* target_klass, Symbol* target_klass_name) {
  1961     Klass* caster_klass, Klass* target_klass, Symbol* target_klass_name) {
  1962 
  1962   const char* caster_name = caster_klass->external_name();
  1963   const char* caster_name = caster_klass->class_loader_and_module_name();
       
  1964 
  1963 
  1965   assert(target_klass != NULL || target_klass_name != NULL, "one must be provided");
  1964   assert(target_klass != NULL || target_klass_name != NULL, "one must be provided");
  1966   const char* target_name = target_klass == NULL ? target_klass_name->as_C_string() :
  1965   const char* target_name = target_klass == NULL ? target_klass_name->as_C_string() :
  1967                                                    target_klass->class_loader_and_module_name();
  1966                                                    target_klass->external_name();
  1968 
  1967 
  1969   size_t msglen = strlen(caster_name) + strlen(" cannot be cast to ") + strlen(target_name) + 1;
  1968   size_t msglen = strlen(caster_name) + strlen("class ") + strlen(" cannot be cast to class ") + strlen(target_name) + 1;
       
  1969 
       
  1970   const char* caster_klass_description = "";
       
  1971   const char* target_klass_description = "";
       
  1972   const char* klass_separator = "";
       
  1973   if (target_klass != NULL && caster_klass->module() == target_klass->module()) {
       
  1974     caster_klass_description = caster_klass->joint_in_module_of_loader(target_klass);
       
  1975   } else {
       
  1976     caster_klass_description = caster_klass->class_in_module_of_loader();
       
  1977     target_klass_description = (target_klass != NULL) ? target_klass->class_in_module_of_loader() : "";
       
  1978     klass_separator = (target_klass != NULL) ? "; " : "";
       
  1979   }
       
  1980 
       
  1981   // add 3 for parenthesis and preceeding space
       
  1982   msglen += strlen(caster_klass_description) + strlen(target_klass_description) + strlen(klass_separator) + 3;
  1970 
  1983 
  1971   char* message = NEW_RESOURCE_ARRAY_RETURN_NULL(char, msglen);
  1984   char* message = NEW_RESOURCE_ARRAY_RETURN_NULL(char, msglen);
  1972   if (message == NULL) {
  1985   if (message == NULL) {
  1973     // Shouldn't happen, but don't cause even more problems if it does
  1986     // Shouldn't happen, but don't cause even more problems if it does
  1974     message = const_cast<char*>(caster_klass->external_name());
  1987     message = const_cast<char*>(caster_klass->external_name());
  1975   } else {
  1988   } else {
  1976     jio_snprintf(message,
  1989     jio_snprintf(message,
  1977                  msglen,
  1990                  msglen,
  1978                  "%s cannot be cast to %s",
  1991                  "class %s cannot be cast to class %s (%s%s%s)",
  1979                  caster_name,
  1992                  caster_name,
  1980                  target_name);
  1993                  target_name,
       
  1994                  caster_klass_description,
       
  1995                  klass_separator,
       
  1996                  target_klass_description
       
  1997                  );
  1981   }
  1998   }
  1982   return message;
  1999   return message;
  1983 }
  2000 }
  1984 
  2001 
  1985 JRT_LEAF(void, SharedRuntime::reguard_yellow_pages())
  2002 JRT_LEAF(void, SharedRuntime::reguard_yellow_pages())