< prev index next >

src/hotspot/share/runtime/sharedRuntime.cpp

Print this page




1942 
1943   // Get target class name from the checkcast instruction
1944   vframeStream vfst(thread, true);
1945   assert(!vfst.at_end(), "Java frame must exist");
1946   Bytecode_checkcast cc(vfst.method(), vfst.method()->bcp_from(vfst.bci()));
1947   constantPoolHandle cpool(thread, vfst.method()->constants());
1948   Klass* target_klass = ConstantPool::klass_at_if_loaded(cpool, cc.index());
1949   Symbol* target_klass_name = NULL;
1950   if (target_klass == NULL) {
1951     // This klass should be resolved, but just in case, get the name in the klass slot.
1952     target_klass_name = cpool->klass_name_at(cc.index());
1953   }
1954   return generate_class_cast_message(caster_klass, target_klass, target_klass_name);
1955 }
1956 
1957 
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.
1960 char* SharedRuntime::generate_class_cast_message(
1961     Klass* caster_klass, Klass* target_klass, Symbol* target_klass_name) {
1962 
1963   const char* caster_name = caster_klass->class_loader_and_module_name();
1964 
1965   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() :
1967                                                    target_klass->class_loader_and_module_name();













1968 
1969   size_t msglen = strlen(caster_name) + strlen(" cannot be cast to ") + strlen(target_name) + 1;

1970 
1971   char* message = NEW_RESOURCE_ARRAY_RETURN_NULL(char, msglen);
1972   if (message == NULL) {
1973     // Shouldn't happen, but don't cause even more problems if it does
1974     message = const_cast<char*>(caster_klass->external_name());
1975   } else {
1976     jio_snprintf(message,
1977                  msglen,
1978                  "%s cannot be cast to %s",
1979                  caster_name,
1980                  target_name);




1981   }
1982   return message;
1983 }
1984 
1985 JRT_LEAF(void, SharedRuntime::reguard_yellow_pages())
1986   (void) JavaThread::current()->reguard_stack();
1987 JRT_END
1988 
1989 
1990 // Handles the uncommon case in locking, i.e., contention or an inflated lock.
1991 JRT_BLOCK_ENTRY(void, SharedRuntime::complete_monitor_locking_C(oopDesc* _obj, BasicLock* lock, JavaThread* thread))
1992   if (!SafepointSynchronize::is_synchronizing()) {
1993     // Only try quick_enter() if we're not trying to reach a safepoint
1994     // so that the calling thread reaches the safepoint more quickly.
1995     if (ObjectSynchronizer::quick_enter(_obj, thread, lock)) return;
1996   }
1997   // NO_ASYNC required because an async exception on the state transition destructor
1998   // would leave you with the lock held and it would never be released.
1999   // The normal monitorenter NullPointerException is thrown without acquiring a lock
2000   // and the model is that an exception implies the method failed.




1942 
1943   // Get target class name from the checkcast instruction
1944   vframeStream vfst(thread, true);
1945   assert(!vfst.at_end(), "Java frame must exist");
1946   Bytecode_checkcast cc(vfst.method(), vfst.method()->bcp_from(vfst.bci()));
1947   constantPoolHandle cpool(thread, vfst.method()->constants());
1948   Klass* target_klass = ConstantPool::klass_at_if_loaded(cpool, cc.index());
1949   Symbol* target_klass_name = NULL;
1950   if (target_klass == NULL) {
1951     // This klass should be resolved, but just in case, get the name in the klass slot.
1952     target_klass_name = cpool->klass_name_at(cc.index());
1953   }
1954   return generate_class_cast_message(caster_klass, target_klass, target_klass_name);
1955 }
1956 
1957 
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.
1960 char* SharedRuntime::generate_class_cast_message(
1961     Klass* caster_klass, Klass* target_klass, Symbol* target_klass_name) {
1962   const char* caster_name = caster_klass->external_name();

1963 
1964   assert(target_klass != NULL || target_klass_name != NULL, "one must be provided");
1965   const char* target_name = target_klass == NULL ? target_klass_name->as_C_string() :
1966                                                    target_klass->external_name(); 
1967 
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;
1983 
1984   char* message = NEW_RESOURCE_ARRAY_RETURN_NULL(char, msglen);
1985   if (message == NULL) {
1986     // Shouldn't happen, but don't cause even more problems if it does
1987     message = const_cast<char*>(caster_klass->external_name());
1988   } else {
1989     jio_snprintf(message,
1990                  msglen,
1991                  "class %s cannot be cast to class %s (%s%s%s)",
1992                  caster_name,
1993                  target_name,
1994                  caster_klass_description,
1995                  klass_separator,
1996                  target_klass_description
1997                  );
1998   }
1999   return message;
2000 }
2001 
2002 JRT_LEAF(void, SharedRuntime::reguard_yellow_pages())
2003   (void) JavaThread::current()->reguard_stack();
2004 JRT_END
2005 
2006 
2007 // Handles the uncommon case in locking, i.e., contention or an inflated lock.
2008 JRT_BLOCK_ENTRY(void, SharedRuntime::complete_monitor_locking_C(oopDesc* _obj, BasicLock* lock, JavaThread* thread))
2009   if (!SafepointSynchronize::is_synchronizing()) {
2010     // Only try quick_enter() if we're not trying to reach a safepoint
2011     // so that the calling thread reaches the safepoint more quickly.
2012     if (ObjectSynchronizer::quick_enter(_obj, thread, lock)) return;
2013   }
2014   // NO_ASYNC required because an async exception on the state transition destructor
2015   // would leave you with the lock held and it would never be released.
2016   // The normal monitorenter NullPointerException is thrown without acquiring a lock
2017   // and the model is that an exception implies the method failed.


< prev index next >