< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page
rev 56222 : 8218628: Add detailed message to NullPointerException describing what is null.
Summary: This is the implementation of JEP 358: Helpful NullPointerExceptions.
Reviewed-by: coleenp


1524     return primitive_type(java_class);
1525   } else {
1526     if (reference_klass != NULL)
1527       (*reference_klass) = as_Klass(java_class);
1528     return T_OBJECT;
1529   }
1530 }
1531 
1532 
1533 oop java_lang_Class::primitive_mirror(BasicType t) {
1534   oop mirror = Universe::java_mirror(t);
1535   assert(mirror != NULL && mirror->is_a(SystemDictionary::Class_klass()), "must be a Class");
1536   assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1537   return mirror;
1538 }
1539 
1540 bool java_lang_Class::offsets_computed = false;
1541 int  java_lang_Class::classRedefinedCount_offset = -1;
1542 
1543 #define CLASS_FIELDS_DO(macro) \
1544   macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false) ; \
1545   macro(_class_loader_offset,       k, "classLoader",         classloader_signature, false); \
1546   macro(_component_mirror_offset,   k, "componentType",       class_signature,       false); \
1547   macro(_module_offset,             k, "module",              module_signature,      false); \
1548   macro(_name_offset,               k, "name",                string_signature,      false); \
1549 
1550 void java_lang_Class::compute_offsets() {
1551   if (offsets_computed) {
1552     return;
1553   }
1554 
1555   offsets_computed = true;
1556 
1557   InstanceKlass* k = SystemDictionary::Class_klass();
1558   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1559 
1560   // Init lock is a C union with component_mirror.  Only instanceKlass mirrors have
1561   // init_lock and only ArrayKlass mirrors have component_mirror.  Since both are oops
1562   // GC treats them the same.
1563   _init_lock_offset = _component_mirror_offset;
1564 


1917 
1918 void java_lang_Throwable::print(oop throwable, outputStream* st) {
1919   ResourceMark rm;
1920   Klass* k = throwable->klass();
1921   assert(k != NULL, "just checking");
1922   st->print("%s", k->external_name());
1923   oop msg = message(throwable);
1924   if (msg != NULL) {
1925     st->print(": %s", java_lang_String::as_utf8_string(msg));
1926   }
1927 }
1928 
1929 // After this many redefines, the stack trace is unreliable.
1930 const int MAX_VERSION = USHRT_MAX;
1931 
1932 static inline bool version_matches(Method* method, int version) {
1933   assert(version < MAX_VERSION, "version is too big");
1934   return method != NULL && (method->constants()->version() == version);
1935 }
1936 
1937 
1938 // This class provides a simple wrapper over the internal structure of
1939 // exception backtrace to insulate users of the backtrace from needing
1940 // to know what it looks like.
1941 class BacktraceBuilder: public StackObj {
1942  friend class BacktraceIterator;
1943  private:
1944   Handle          _backtrace;
1945   objArrayOop     _head;
1946   typeArrayOop    _methods;
1947   typeArrayOop    _bcis;
1948   objArrayOop     _mirrors;
1949   typeArrayOop    _names; // needed to insulate method name against redefinition




1950   int             _index;
1951   NoSafepointVerifier _nsv;
1952 
1953   enum {
1954     trace_methods_offset = java_lang_Throwable::trace_methods_offset,
1955     trace_bcis_offset    = java_lang_Throwable::trace_bcis_offset,
1956     trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,
1957     trace_names_offset   = java_lang_Throwable::trace_names_offset,
1958     trace_next_offset    = java_lang_Throwable::trace_next_offset,

1959     trace_size           = java_lang_Throwable::trace_size,
1960     trace_chunk_size     = java_lang_Throwable::trace_chunk_size
1961   };
1962 
1963   // get info out of chunks
1964   static typeArrayOop get_methods(objArrayHandle chunk) {
1965     typeArrayOop methods = typeArrayOop(chunk->obj_at(trace_methods_offset));
1966     assert(methods != NULL, "method array should be initialized in backtrace");
1967     return methods;
1968   }
1969   static typeArrayOop get_bcis(objArrayHandle chunk) {
1970     typeArrayOop bcis = typeArrayOop(chunk->obj_at(trace_bcis_offset));
1971     assert(bcis != NULL, "bci array should be initialized in backtrace");
1972     return bcis;
1973   }
1974   static objArrayOop get_mirrors(objArrayHandle chunk) {
1975     objArrayOop mirrors = objArrayOop(chunk->obj_at(trace_mirrors_offset));
1976     assert(mirrors != NULL, "mirror array should be initialized in backtrace");
1977     return mirrors;
1978   }
1979   static typeArrayOop get_names(objArrayHandle chunk) {
1980     typeArrayOop names = typeArrayOop(chunk->obj_at(trace_names_offset));
1981     assert(names != NULL, "names array should be initialized in backtrace");
1982     return names;
1983   }




1984 
1985  public:
1986 
1987   // constructor for new backtrace
1988   BacktraceBuilder(TRAPS): _head(NULL), _methods(NULL), _bcis(NULL), _mirrors(NULL), _names(NULL) {
1989     expand(CHECK);
1990     _backtrace = Handle(THREAD, _head);
1991     _index = 0;
1992   }
1993 
1994   BacktraceBuilder(Thread* thread, objArrayHandle backtrace) {
1995     _methods = get_methods(backtrace);
1996     _bcis = get_bcis(backtrace);
1997     _mirrors = get_mirrors(backtrace);
1998     _names = get_names(backtrace);

1999     assert(_methods->length() == _bcis->length() &&
2000            _methods->length() == _mirrors->length() &&
2001            _mirrors->length() == _names->length(),
2002            "method and source information arrays should match");
2003 
2004     // head is the preallocated backtrace
2005     _head = backtrace();
2006     _backtrace = Handle(thread, _head);
2007     _index = 0;
2008   }
2009 
2010   void expand(TRAPS) {
2011     objArrayHandle old_head(THREAD, _head);
2012     PauseNoSafepointVerifier pnsv(&_nsv);
2013 
2014     objArrayOop head = oopFactory::new_objectArray(trace_size, CHECK);
2015     objArrayHandle new_head(THREAD, head);
2016 
2017     typeArrayOop methods = oopFactory::new_shortArray(trace_chunk_size, CHECK);
2018     typeArrayHandle new_methods(THREAD, methods);
2019 
2020     typeArrayOop bcis = oopFactory::new_intArray(trace_chunk_size, CHECK);
2021     typeArrayHandle new_bcis(THREAD, bcis);
2022 
2023     objArrayOop mirrors = oopFactory::new_objectArray(trace_chunk_size, CHECK);
2024     objArrayHandle new_mirrors(THREAD, mirrors);
2025 
2026     typeArrayOop names = oopFactory::new_symbolArray(trace_chunk_size, CHECK);
2027     typeArrayHandle new_names(THREAD, names);
2028 
2029     if (!old_head.is_null()) {
2030       old_head->obj_at_put(trace_next_offset, new_head());
2031     }
2032     new_head->obj_at_put(trace_methods_offset, new_methods());
2033     new_head->obj_at_put(trace_bcis_offset, new_bcis());
2034     new_head->obj_at_put(trace_mirrors_offset, new_mirrors());
2035     new_head->obj_at_put(trace_names_offset, new_names());

2036 
2037     _head    = new_head();
2038     _methods = new_methods();
2039     _bcis = new_bcis();
2040     _mirrors = new_mirrors();
2041     _names  = new_names();
2042     _index = 0;
2043   }
2044 
2045   oop backtrace() {
2046     return _backtrace();
2047   }
2048 
2049   inline void push(Method* method, int bci, TRAPS) {
2050     // Smear the -1 bci to 0 since the array only holds unsigned
2051     // shorts.  The later line number lookup would just smear the -1
2052     // to a 0 even if it could be recorded.
2053     if (bci == SynchronizationEntryBCI) bci = 0;
2054 
2055     if (_index >= trace_chunk_size) {
2056       methodHandle mhandle(THREAD, method);
2057       expand(CHECK);
2058       method = mhandle();
2059     }
2060 
2061     _methods->ushort_at_put(_index, method->orig_method_idnum());
2062     _bcis->int_at_put(_index, Backtrace::merge_bci_and_version(bci, method->constants()->version()));
2063 
2064     // Note:this doesn't leak symbols because the mirror in the backtrace keeps the
2065     // klass owning the symbols alive so their refcounts aren't decremented.
2066     Symbol* name = method->name();
2067     _names->symbol_at_put(_index, name);
2068 
2069     // We need to save the mirrors in the backtrace to keep the class
2070     // from being unloaded while we still have this stack trace.
2071     assert(method->method_holder()->java_mirror() != NULL, "never push null for mirror");
2072     _mirrors->obj_at_put(_index, method->method_holder()->java_mirror());
2073     _index++;
2074   }
2075 










2076 };
2077 
2078 struct BacktraceElement : public StackObj {
2079   int _method_id;
2080   int _bci;
2081   int _version;
2082   Symbol* _name;
2083   Handle _mirror;
2084   BacktraceElement(Handle mirror, int mid, int version, int bci, Symbol* name) :
2085                    _method_id(mid), _bci(bci), _version(version), _name(name), _mirror(mirror) {}
2086 };
2087 
2088 class BacktraceIterator : public StackObj {
2089   int _index;
2090   objArrayHandle  _result;
2091   objArrayHandle  _mirrors;
2092   typeArrayHandle _methods;
2093   typeArrayHandle _bcis;
2094   typeArrayHandle _names;
2095 


2385         continue;
2386       }
2387       else {
2388         skip_fillInStackTrace_check = true; // gone past them all
2389       }
2390     }
2391     if (!skip_throwableInit_check) {
2392       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2393 
2394       // skip <init> methods of the exception class and superclasses
2395       // This is simlar to classic VM.
2396       if (method->name() == vmSymbols::object_initializer_name() &&
2397           throwable->is_a(method->method_holder())) {
2398         continue;
2399       } else {
2400         // there are none or we've seen them all - either way stop checking
2401         skip_throwableInit_check = true;
2402       }
2403     }
2404     if (method->is_hidden()) {
2405       if (skip_hidden)  continue;






2406     }
2407     bt.push(method, bci, CHECK);
2408     total_count++;
2409   }
2410 
2411   log_info(stacktrace)("%s, %d", throwable->klass()->external_name(), total_count);
2412 
2413   // Put completed stack trace into throwable object
2414   set_backtrace(throwable(), bt.backtrace());
2415   set_depth(throwable(), total_count);
2416 }
2417 
2418 void java_lang_Throwable::fill_in_stack_trace(Handle throwable, const methodHandle& method) {
2419   // No-op if stack trace is disabled
2420   if (!StackTraceInThrowable) {
2421     return;
2422   }
2423 
2424   // Disable stack traces for some preallocated out of memory errors
2425   if (!Universe::should_fill_in_stack_trace(throwable)) {


2500 
2501   int index = 0;
2502   while (iter.repeat()) {
2503     BacktraceElement bte = iter.next(THREAD);
2504 
2505     Handle stack_trace_element(THREAD, stack_trace_array_h->obj_at(index++));
2506 
2507     if (stack_trace_element.is_null()) {
2508       THROW(vmSymbols::java_lang_NullPointerException());
2509     }
2510 
2511     InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(bte._mirror()));
2512     methodHandle method (THREAD, holder->method_with_orig_idnum(bte._method_id, bte._version));
2513 
2514     java_lang_StackTraceElement::fill_in(stack_trace_element, holder,
2515                                          method,
2516                                          bte._version,
2517                                          bte._bci,
2518                                          bte._name, CHECK);
2519   }































2520 }
2521 
2522 oop java_lang_StackTraceElement::create(const methodHandle& method, int bci, TRAPS) {
2523   // Allocate java.lang.StackTraceElement instance
2524   InstanceKlass* k = SystemDictionary::StackTraceElement_klass();
2525   assert(k != NULL, "must be loaded in 1.4+");
2526   if (k->should_be_initialized()) {
2527     k->initialize(CHECK_0);
2528   }
2529 
2530   Handle element = k->allocate_instance_handle(CHECK_0);
2531 
2532   int version = method->constants()->version();
2533   fill_in(element, method->method_holder(), method, version, bci, method->name(), CHECK_0);
2534   return element();
2535 }
2536 
2537 void java_lang_StackTraceElement::fill_in(Handle element,
2538                                           InstanceKlass* holder, const methodHandle& method,
2539                                           int version, int bci, Symbol* name, TRAPS) {




1524     return primitive_type(java_class);
1525   } else {
1526     if (reference_klass != NULL)
1527       (*reference_klass) = as_Klass(java_class);
1528     return T_OBJECT;
1529   }
1530 }
1531 
1532 
1533 oop java_lang_Class::primitive_mirror(BasicType t) {
1534   oop mirror = Universe::java_mirror(t);
1535   assert(mirror != NULL && mirror->is_a(SystemDictionary::Class_klass()), "must be a Class");
1536   assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1537   return mirror;
1538 }
1539 
1540 bool java_lang_Class::offsets_computed = false;
1541 int  java_lang_Class::classRedefinedCount_offset = -1;
1542 
1543 #define CLASS_FIELDS_DO(macro) \
1544   macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
1545   macro(_class_loader_offset,       k, "classLoader",         classloader_signature, false); \
1546   macro(_component_mirror_offset,   k, "componentType",       class_signature,       false); \
1547   macro(_module_offset,             k, "module",              module_signature,      false); \
1548   macro(_name_offset,               k, "name",                string_signature,      false); \
1549 
1550 void java_lang_Class::compute_offsets() {
1551   if (offsets_computed) {
1552     return;
1553   }
1554 
1555   offsets_computed = true;
1556 
1557   InstanceKlass* k = SystemDictionary::Class_klass();
1558   CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1559 
1560   // Init lock is a C union with component_mirror.  Only instanceKlass mirrors have
1561   // init_lock and only ArrayKlass mirrors have component_mirror.  Since both are oops
1562   // GC treats them the same.
1563   _init_lock_offset = _component_mirror_offset;
1564 


1917 
1918 void java_lang_Throwable::print(oop throwable, outputStream* st) {
1919   ResourceMark rm;
1920   Klass* k = throwable->klass();
1921   assert(k != NULL, "just checking");
1922   st->print("%s", k->external_name());
1923   oop msg = message(throwable);
1924   if (msg != NULL) {
1925     st->print(": %s", java_lang_String::as_utf8_string(msg));
1926   }
1927 }
1928 
1929 // After this many redefines, the stack trace is unreliable.
1930 const int MAX_VERSION = USHRT_MAX;
1931 
1932 static inline bool version_matches(Method* method, int version) {
1933   assert(version < MAX_VERSION, "version is too big");
1934   return method != NULL && (method->constants()->version() == version);
1935 }
1936 

1937 // This class provides a simple wrapper over the internal structure of
1938 // exception backtrace to insulate users of the backtrace from needing
1939 // to know what it looks like.
1940 class BacktraceBuilder: public StackObj {
1941  friend class BacktraceIterator;
1942  private:
1943   Handle          _backtrace;
1944   objArrayOop     _head;
1945   typeArrayOop    _methods;
1946   typeArrayOop    _bcis;
1947   objArrayOop     _mirrors;
1948   typeArrayOop    _names; // Needed to insulate method name against redefinition.
1949   // This is set to a java.lang.Boolean(true) if the top frame
1950   // of the backtrace is omitted because it shall be hidden.
1951   // Else it is null.
1952   oop             _has_hidden_top_frame;
1953   int             _index;
1954   NoSafepointVerifier _nsv;
1955 
1956   enum {
1957     trace_methods_offset = java_lang_Throwable::trace_methods_offset,
1958     trace_bcis_offset    = java_lang_Throwable::trace_bcis_offset,
1959     trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,
1960     trace_names_offset   = java_lang_Throwable::trace_names_offset,
1961     trace_next_offset    = java_lang_Throwable::trace_next_offset,
1962     trace_hidden_offset  = java_lang_Throwable::trace_hidden_offset,
1963     trace_size           = java_lang_Throwable::trace_size,
1964     trace_chunk_size     = java_lang_Throwable::trace_chunk_size
1965   };
1966 
1967   // get info out of chunks
1968   static typeArrayOop get_methods(objArrayHandle chunk) {
1969     typeArrayOop methods = typeArrayOop(chunk->obj_at(trace_methods_offset));
1970     assert(methods != NULL, "method array should be initialized in backtrace");
1971     return methods;
1972   }
1973   static typeArrayOop get_bcis(objArrayHandle chunk) {
1974     typeArrayOop bcis = typeArrayOop(chunk->obj_at(trace_bcis_offset));
1975     assert(bcis != NULL, "bci array should be initialized in backtrace");
1976     return bcis;
1977   }
1978   static objArrayOop get_mirrors(objArrayHandle chunk) {
1979     objArrayOop mirrors = objArrayOop(chunk->obj_at(trace_mirrors_offset));
1980     assert(mirrors != NULL, "mirror array should be initialized in backtrace");
1981     return mirrors;
1982   }
1983   static typeArrayOop get_names(objArrayHandle chunk) {
1984     typeArrayOop names = typeArrayOop(chunk->obj_at(trace_names_offset));
1985     assert(names != NULL, "names array should be initialized in backtrace");
1986     return names;
1987   }
1988   static oop get_has_hidden_top_frame(objArrayHandle chunk) {
1989     oop hidden = chunk->obj_at(trace_hidden_offset);
1990     return hidden;
1991   }
1992 
1993  public:
1994 
1995   // constructor for new backtrace
1996   BacktraceBuilder(TRAPS): _head(NULL), _methods(NULL), _bcis(NULL), _mirrors(NULL), _names(NULL), _has_hidden_top_frame(NULL) {
1997     expand(CHECK);
1998     _backtrace = Handle(THREAD, _head);
1999     _index = 0;
2000   }
2001 
2002   BacktraceBuilder(Thread* thread, objArrayHandle backtrace) {
2003     _methods = get_methods(backtrace);
2004     _bcis = get_bcis(backtrace);
2005     _mirrors = get_mirrors(backtrace);
2006     _names = get_names(backtrace);
2007     _has_hidden_top_frame = get_has_hidden_top_frame(backtrace);
2008     assert(_methods->length() == _bcis->length() &&
2009            _methods->length() == _mirrors->length() &&
2010            _mirrors->length() == _names->length(),
2011            "method and source information arrays should match");
2012 
2013     // head is the preallocated backtrace
2014     _head = backtrace();
2015     _backtrace = Handle(thread, _head);
2016     _index = 0;
2017   }
2018 
2019   void expand(TRAPS) {
2020     objArrayHandle old_head(THREAD, _head);
2021     PauseNoSafepointVerifier pnsv(&_nsv);
2022 
2023     objArrayOop head = oopFactory::new_objectArray(trace_size, CHECK);
2024     objArrayHandle new_head(THREAD, head);
2025 
2026     typeArrayOop methods = oopFactory::new_shortArray(trace_chunk_size, CHECK);
2027     typeArrayHandle new_methods(THREAD, methods);
2028 
2029     typeArrayOop bcis = oopFactory::new_intArray(trace_chunk_size, CHECK);
2030     typeArrayHandle new_bcis(THREAD, bcis);
2031 
2032     objArrayOop mirrors = oopFactory::new_objectArray(trace_chunk_size, CHECK);
2033     objArrayHandle new_mirrors(THREAD, mirrors);
2034 
2035     typeArrayOop names = oopFactory::new_symbolArray(trace_chunk_size, CHECK);
2036     typeArrayHandle new_names(THREAD, names);
2037 
2038     if (!old_head.is_null()) {
2039       old_head->obj_at_put(trace_next_offset, new_head());
2040     }
2041     new_head->obj_at_put(trace_methods_offset, new_methods());
2042     new_head->obj_at_put(trace_bcis_offset, new_bcis());
2043     new_head->obj_at_put(trace_mirrors_offset, new_mirrors());
2044     new_head->obj_at_put(trace_names_offset, new_names());
2045     new_head->obj_at_put(trace_hidden_offset, NULL);
2046 
2047     _head    = new_head();
2048     _methods = new_methods();
2049     _bcis = new_bcis();
2050     _mirrors = new_mirrors();
2051     _names  = new_names();
2052     _index = 0;
2053   }
2054 
2055   oop backtrace() {
2056     return _backtrace();
2057   }
2058 
2059   inline void push(Method* method, int bci, TRAPS) {
2060     // Smear the -1 bci to 0 since the array only holds unsigned
2061     // shorts.  The later line number lookup would just smear the -1
2062     // to a 0 even if it could be recorded.
2063     if (bci == SynchronizationEntryBCI) bci = 0;
2064 
2065     if (_index >= trace_chunk_size) {
2066       methodHandle mhandle(THREAD, method);
2067       expand(CHECK);
2068       method = mhandle();
2069     }
2070 
2071     _methods->ushort_at_put(_index, method->orig_method_idnum());
2072     _bcis->int_at_put(_index, Backtrace::merge_bci_and_version(bci, method->constants()->version()));
2073 
2074     // Note:this doesn't leak symbols because the mirror in the backtrace keeps the
2075     // klass owning the symbols alive so their refcounts aren't decremented.
2076     Symbol* name = method->name();
2077     _names->symbol_at_put(_index, name);
2078 
2079     // We need to save the mirrors in the backtrace to keep the class
2080     // from being unloaded while we still have this stack trace.
2081     assert(method->method_holder()->java_mirror() != NULL, "never push null for mirror");
2082     _mirrors->obj_at_put(_index, method->method_holder()->java_mirror());
2083     _index++;
2084   }
2085 
2086   void set_has_hidden_top_frame(TRAPS) {
2087     if (_has_hidden_top_frame == NULL) {
2088       jvalue prim;
2089       prim.z = 1;
2090       PauseNoSafepointVerifier pnsv(&_nsv);
2091       _has_hidden_top_frame = java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK);
2092       _head->obj_at_put(trace_hidden_offset, _has_hidden_top_frame);
2093     }
2094   }
2095 
2096 };
2097 
2098 struct BacktraceElement : public StackObj {
2099   int _method_id;
2100   int _bci;
2101   int _version;
2102   Symbol* _name;
2103   Handle _mirror;
2104   BacktraceElement(Handle mirror, int mid, int version, int bci, Symbol* name) :
2105                    _method_id(mid), _bci(bci), _version(version), _name(name), _mirror(mirror) {}
2106 };
2107 
2108 class BacktraceIterator : public StackObj {
2109   int _index;
2110   objArrayHandle  _result;
2111   objArrayHandle  _mirrors;
2112   typeArrayHandle _methods;
2113   typeArrayHandle _bcis;
2114   typeArrayHandle _names;
2115 


2405         continue;
2406       }
2407       else {
2408         skip_fillInStackTrace_check = true; // gone past them all
2409       }
2410     }
2411     if (!skip_throwableInit_check) {
2412       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2413 
2414       // skip <init> methods of the exception class and superclasses
2415       // This is simlar to classic VM.
2416       if (method->name() == vmSymbols::object_initializer_name() &&
2417           throwable->is_a(method->method_holder())) {
2418         continue;
2419       } else {
2420         // there are none or we've seen them all - either way stop checking
2421         skip_throwableInit_check = true;
2422       }
2423     }
2424     if (method->is_hidden()) {
2425       if (skip_hidden) {
2426         if (total_count == 0) {
2427           // The top frame will be hidden from the stack trace.
2428           bt.set_has_hidden_top_frame(CHECK);
2429         }
2430         continue;
2431       }
2432     }
2433     bt.push(method, bci, CHECK);
2434     total_count++;
2435   }
2436 
2437   log_info(stacktrace)("%s, %d", throwable->klass()->external_name(), total_count);
2438 
2439   // Put completed stack trace into throwable object
2440   set_backtrace(throwable(), bt.backtrace());
2441   set_depth(throwable(), total_count);
2442 }
2443 
2444 void java_lang_Throwable::fill_in_stack_trace(Handle throwable, const methodHandle& method) {
2445   // No-op if stack trace is disabled
2446   if (!StackTraceInThrowable) {
2447     return;
2448   }
2449 
2450   // Disable stack traces for some preallocated out of memory errors
2451   if (!Universe::should_fill_in_stack_trace(throwable)) {


2526 
2527   int index = 0;
2528   while (iter.repeat()) {
2529     BacktraceElement bte = iter.next(THREAD);
2530 
2531     Handle stack_trace_element(THREAD, stack_trace_array_h->obj_at(index++));
2532 
2533     if (stack_trace_element.is_null()) {
2534       THROW(vmSymbols::java_lang_NullPointerException());
2535     }
2536 
2537     InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(bte._mirror()));
2538     methodHandle method (THREAD, holder->method_with_orig_idnum(bte._method_id, bte._version));
2539 
2540     java_lang_StackTraceElement::fill_in(stack_trace_element, holder,
2541                                          method,
2542                                          bte._version,
2543                                          bte._bci,
2544                                          bte._name, CHECK);
2545   }
2546 }
2547 
2548 bool java_lang_Throwable::get_method_and_bci(oop throwable, Method** method, int* bci) {
2549   Thread* THREAD = Thread::current();
2550   objArrayHandle result(THREAD, objArrayOop(backtrace(throwable)));
2551   BacktraceIterator iter(result, THREAD);
2552   // No backtrace available.
2553   if (!iter.repeat()) return false;
2554 
2555   // If the exception happened in a frame that has been hidden, i.e.,
2556   // omitted from the back trace, we can not compute the message.
2557   oop hidden = ((objArrayOop)backtrace(throwable))->obj_at(trace_hidden_offset);
2558   if (hidden != NULL) {
2559     return false;
2560   }
2561 
2562   // Get first backtrace element.
2563   BacktraceElement bte = iter.next(THREAD);
2564 
2565   InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(bte._mirror()));
2566   assert(holder != NULL, "first element should be non-null");
2567   Method* m = holder->method_with_orig_idnum(bte._method_id, bte._version);
2568 
2569   // Original version is no longer available.
2570   if (m == NULL || !version_matches(m, bte._version)) {
2571     return false;
2572   }
2573 
2574   *method = m;
2575   *bci = bte._bci;
2576   return true;
2577 }
2578 
2579 oop java_lang_StackTraceElement::create(const methodHandle& method, int bci, TRAPS) {
2580   // Allocate java.lang.StackTraceElement instance
2581   InstanceKlass* k = SystemDictionary::StackTraceElement_klass();
2582   assert(k != NULL, "must be loaded in 1.4+");
2583   if (k->should_be_initialized()) {
2584     k->initialize(CHECK_0);
2585   }
2586 
2587   Handle element = k->allocate_instance_handle(CHECK_0);
2588 
2589   int version = method->constants()->version();
2590   fill_in(element, method->method_holder(), method, version, bci, method->name(), CHECK_0);
2591   return element();
2592 }
2593 
2594 void java_lang_StackTraceElement::fill_in(Handle element,
2595                                           InstanceKlass* holder, const methodHandle& method,
2596                                           int version, int bci, Symbol* name, TRAPS) {


< prev index next >