< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page
rev 53693 : wq8218628: Add detailed message to NullPointerException describing what is null.


1508     return primitive_type(java_class);
1509   } else {
1510     if (reference_klass != NULL)
1511       (*reference_klass) = as_Klass(java_class);
1512     return T_OBJECT;
1513   }
1514 }
1515 
1516 
1517 oop java_lang_Class::primitive_mirror(BasicType t) {
1518   oop mirror = Universe::java_mirror(t);
1519   assert(mirror != NULL && mirror->is_a(SystemDictionary::Class_klass()), "must be a Class");
1520   assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1521   return mirror;
1522 }
1523 
1524 bool java_lang_Class::offsets_computed = false;
1525 int  java_lang_Class::classRedefinedCount_offset = -1;
1526 
1527 #define CLASS_FIELDS_DO(macro) \
1528   macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false) ; \
1529   macro(_class_loader_offset,       k, "classLoader",         classloader_signature, false); \
1530   macro(_component_mirror_offset,   k, "componentType",       class_signature,       false); \
1531   macro(_module_offset,             k, "module",              module_signature,      false); \
1532   macro(_name_offset,               k, "name",                string_signature,      false); \
1533 
1534 void java_lang_Class::compute_offsets() {
1535   if (offsets_computed) {
1536     return;
1537   }
1538 
1539   offsets_computed = true;
1540 
1541   InstanceKlass* k = SystemDictionary::Class_klass();
1542   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1543 
1544   // Init lock is a C union with component_mirror.  Only instanceKlass mirrors have
1545   // init_lock and only ArrayKlass mirrors have component_mirror.  Since both are oops
1546   // GC treats them the same.
1547   _init_lock_offset = _component_mirror_offset;
1548 


1953 
1954 void java_lang_Throwable::print(oop throwable, outputStream* st) {
1955   ResourceMark rm;
1956   Klass* k = throwable->klass();
1957   assert(k != NULL, "just checking");
1958   st->print("%s", k->external_name());
1959   oop msg = message(throwable);
1960   if (msg != NULL) {
1961     st->print(": %s", java_lang_String::as_utf8_string(msg));
1962   }
1963 }
1964 
1965 // After this many redefines, the stack trace is unreliable.
1966 const int MAX_VERSION = USHRT_MAX;
1967 
1968 static inline bool version_matches(Method* method, int version) {
1969   assert(version < MAX_VERSION, "version is too big");
1970   return method != NULL && (method->constants()->version() == version);
1971 }
1972 


















































1973 
1974 // This class provides a simple wrapper over the internal structure of
1975 // exception backtrace to insulate users of the backtrace from needing
1976 // to know what it looks like.
1977 class BacktraceBuilder: public StackObj {
1978  friend class BacktraceIterator;
1979  private:
1980   Handle          _backtrace;
1981   objArrayOop     _head;
1982   typeArrayOop    _methods;
1983   typeArrayOop    _bcis;
1984   objArrayOop     _mirrors;
1985   typeArrayOop    _names; // needed to insulate method name against redefinition
1986   int             _index;
1987   NoSafepointVerifier _nsv;
1988 
1989   enum {
1990     trace_methods_offset = java_lang_Throwable::trace_methods_offset,
1991     trace_bcis_offset    = java_lang_Throwable::trace_bcis_offset,
1992     trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,




1508     return primitive_type(java_class);
1509   } else {
1510     if (reference_klass != NULL)
1511       (*reference_klass) = as_Klass(java_class);
1512     return T_OBJECT;
1513   }
1514 }
1515 
1516 
1517 oop java_lang_Class::primitive_mirror(BasicType t) {
1518   oop mirror = Universe::java_mirror(t);
1519   assert(mirror != NULL && mirror->is_a(SystemDictionary::Class_klass()), "must be a Class");
1520   assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1521   return mirror;
1522 }
1523 
1524 bool java_lang_Class::offsets_computed = false;
1525 int  java_lang_Class::classRedefinedCount_offset = -1;
1526 
1527 #define CLASS_FIELDS_DO(macro) \
1528   macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
1529   macro(_class_loader_offset,       k, "classLoader",         classloader_signature, false); \
1530   macro(_component_mirror_offset,   k, "componentType",       class_signature,       false); \
1531   macro(_module_offset,             k, "module",              module_signature,      false); \
1532   macro(_name_offset,               k, "name",                string_signature,      false); \
1533 
1534 void java_lang_Class::compute_offsets() {
1535   if (offsets_computed) {
1536     return;
1537   }
1538 
1539   offsets_computed = true;
1540 
1541   InstanceKlass* k = SystemDictionary::Class_klass();
1542   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1543 
1544   // Init lock is a C union with component_mirror.  Only instanceKlass mirrors have
1545   // init_lock and only ArrayKlass mirrors have component_mirror.  Since both are oops
1546   // GC treats them the same.
1547   _init_lock_offset = _component_mirror_offset;
1548 


1953 
1954 void java_lang_Throwable::print(oop throwable, outputStream* st) {
1955   ResourceMark rm;
1956   Klass* k = throwable->klass();
1957   assert(k != NULL, "just checking");
1958   st->print("%s", k->external_name());
1959   oop msg = message(throwable);
1960   if (msg != NULL) {
1961     st->print(": %s", java_lang_String::as_utf8_string(msg));
1962   }
1963 }
1964 
1965 // After this many redefines, the stack trace is unreliable.
1966 const int MAX_VERSION = USHRT_MAX;
1967 
1968 static inline bool version_matches(Method* method, int version) {
1969   assert(version < MAX_VERSION, "version is too big");
1970   return method != NULL && (method->constants()->version() == version);
1971 }
1972 
1973 bool java_lang_Throwable::get_method_and_bci(oop throwable, int index, Method** method, int* bci) {
1974   if (index < 0) {
1975     return false;
1976   }
1977 
1978   objArrayOop bt = (objArrayOop)backtrace(throwable);
1979   int depth = 0;
1980 
1981   while (bt != NULL) {
1982     oop m = bt->obj_at(trace_methods_offset);
1983     typeArrayOop methods = typeArrayOop(m);
1984     typeArrayOop bcis = (typeArrayOop)bt->obj_at(trace_bcis_offset);
1985     objArrayOop mirrors = (objArrayOop)bt->obj_at(trace_mirrors_offset);
1986 
1987     if ((methods == NULL) || (bcis == NULL) || (mirrors == NULL)) {
1988       return false;
1989     }
1990 
1991     int length = methods->length();
1992 
1993     for (int i = 0; i < length; i++) {
1994       oop m = mirrors->obj_at(i);
1995       if (m == NULL) {
1996         return false;
1997       }
1998       InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(m));
1999       int method_id = methods->short_at(i);
2000       Method* act_method = holder->method_with_idnum(method_id);
2001 
2002       if (act_method == NULL) {
2003         return false;
2004       }
2005 
2006       int act_bci = Backtrace::bci_at(bcis->int_at(i));
2007 
2008       if (depth == index) {
2009         *method = act_method;
2010         *bci = act_bci;
2011 
2012         return true;
2013       }
2014 
2015       depth += 1;
2016     }
2017 
2018     bt = (objArrayOop)bt->obj_at(trace_next_offset);
2019   }
2020 
2021   return false;
2022 }
2023 
2024 // This class provides a simple wrapper over the internal structure of
2025 // exception backtrace to insulate users of the backtrace from needing
2026 // to know what it looks like.
2027 class BacktraceBuilder: public StackObj {
2028  friend class BacktraceIterator;
2029  private:
2030   Handle          _backtrace;
2031   objArrayOop     _head;
2032   typeArrayOop    _methods;
2033   typeArrayOop    _bcis;
2034   objArrayOop     _mirrors;
2035   typeArrayOop    _names; // needed to insulate method name against redefinition
2036   int             _index;
2037   NoSafepointVerifier _nsv;
2038 
2039   enum {
2040     trace_methods_offset = java_lang_Throwable::trace_methods_offset,
2041     trace_bcis_offset    = java_lang_Throwable::trace_bcis_offset,
2042     trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,


< prev index next >