src/hotspot/share/classfile/javaClasses.cpp
changeset 58664 e3618c902d17
parent 58555 7252d89e3a4e
child 58679 9c3209ff7550
child 58728 6d5c7f91e0b5
equal deleted inserted replaced
58663:11a574b352d0 58664:e3618c902d17
  1543 
  1543 
  1544 bool java_lang_Class::offsets_computed = false;
  1544 bool java_lang_Class::offsets_computed = false;
  1545 int  java_lang_Class::classRedefinedCount_offset = -1;
  1545 int  java_lang_Class::classRedefinedCount_offset = -1;
  1546 
  1546 
  1547 #define CLASS_FIELDS_DO(macro) \
  1547 #define CLASS_FIELDS_DO(macro) \
  1548   macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false) ; \
  1548   macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature,         false); \
  1549   macro(_class_loader_offset,       k, "classLoader",         classloader_signature, false); \
  1549   macro(_class_loader_offset,       k, "classLoader",         classloader_signature, false); \
  1550   macro(_component_mirror_offset,   k, "componentType",       class_signature,       false); \
  1550   macro(_component_mirror_offset,   k, "componentType",       class_signature,       false); \
  1551   macro(_module_offset,             k, "module",              module_signature,      false); \
  1551   macro(_module_offset,             k, "module",              module_signature,      false); \
  1552   macro(_name_offset,               k, "name",                string_signature,      false); \
  1552   macro(_name_offset,               k, "name",                string_signature,      false); \
  1553 
  1553 
  1936 static inline bool version_matches(Method* method, int version) {
  1936 static inline bool version_matches(Method* method, int version) {
  1937   assert(version < MAX_VERSION, "version is too big");
  1937   assert(version < MAX_VERSION, "version is too big");
  1938   return method != NULL && (method->constants()->version() == version);
  1938   return method != NULL && (method->constants()->version() == version);
  1939 }
  1939 }
  1940 
  1940 
  1941 
       
  1942 // This class provides a simple wrapper over the internal structure of
  1941 // This class provides a simple wrapper over the internal structure of
  1943 // exception backtrace to insulate users of the backtrace from needing
  1942 // exception backtrace to insulate users of the backtrace from needing
  1944 // to know what it looks like.
  1943 // to know what it looks like.
  1945 class BacktraceBuilder: public StackObj {
  1944 class BacktraceBuilder: public StackObj {
  1946  friend class BacktraceIterator;
  1945  friend class BacktraceIterator;
  1948   Handle          _backtrace;
  1947   Handle          _backtrace;
  1949   objArrayOop     _head;
  1948   objArrayOop     _head;
  1950   typeArrayOop    _methods;
  1949   typeArrayOop    _methods;
  1951   typeArrayOop    _bcis;
  1950   typeArrayOop    _bcis;
  1952   objArrayOop     _mirrors;
  1951   objArrayOop     _mirrors;
  1953   typeArrayOop    _names; // needed to insulate method name against redefinition
  1952   typeArrayOop    _names; // Needed to insulate method name against redefinition.
       
  1953   // This is set to a java.lang.Boolean(true) if the top frame
       
  1954   // of the backtrace is omitted because it shall be hidden.
       
  1955   // Else it is null.
       
  1956   oop             _has_hidden_top_frame;
  1954   int             _index;
  1957   int             _index;
  1955   NoSafepointVerifier _nsv;
  1958   NoSafepointVerifier _nsv;
  1956 
  1959 
  1957   enum {
  1960   enum {
  1958     trace_methods_offset = java_lang_Throwable::trace_methods_offset,
  1961     trace_methods_offset = java_lang_Throwable::trace_methods_offset,
  1959     trace_bcis_offset    = java_lang_Throwable::trace_bcis_offset,
  1962     trace_bcis_offset    = java_lang_Throwable::trace_bcis_offset,
  1960     trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,
  1963     trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,
  1961     trace_names_offset   = java_lang_Throwable::trace_names_offset,
  1964     trace_names_offset   = java_lang_Throwable::trace_names_offset,
  1962     trace_next_offset    = java_lang_Throwable::trace_next_offset,
  1965     trace_next_offset    = java_lang_Throwable::trace_next_offset,
       
  1966     trace_hidden_offset  = java_lang_Throwable::trace_hidden_offset,
  1963     trace_size           = java_lang_Throwable::trace_size,
  1967     trace_size           = java_lang_Throwable::trace_size,
  1964     trace_chunk_size     = java_lang_Throwable::trace_chunk_size
  1968     trace_chunk_size     = java_lang_Throwable::trace_chunk_size
  1965   };
  1969   };
  1966 
  1970 
  1967   // get info out of chunks
  1971   // get info out of chunks
  1983   static typeArrayOop get_names(objArrayHandle chunk) {
  1987   static typeArrayOop get_names(objArrayHandle chunk) {
  1984     typeArrayOop names = typeArrayOop(chunk->obj_at(trace_names_offset));
  1988     typeArrayOop names = typeArrayOop(chunk->obj_at(trace_names_offset));
  1985     assert(names != NULL, "names array should be initialized in backtrace");
  1989     assert(names != NULL, "names array should be initialized in backtrace");
  1986     return names;
  1990     return names;
  1987   }
  1991   }
       
  1992   static oop get_has_hidden_top_frame(objArrayHandle chunk) {
       
  1993     oop hidden = chunk->obj_at(trace_hidden_offset);
       
  1994     return hidden;
       
  1995   }
  1988 
  1996 
  1989  public:
  1997  public:
  1990 
  1998 
  1991   // constructor for new backtrace
  1999   // constructor for new backtrace
  1992   BacktraceBuilder(TRAPS): _head(NULL), _methods(NULL), _bcis(NULL), _mirrors(NULL), _names(NULL) {
  2000   BacktraceBuilder(TRAPS): _head(NULL), _methods(NULL), _bcis(NULL), _mirrors(NULL), _names(NULL), _has_hidden_top_frame(NULL) {
  1993     expand(CHECK);
  2001     expand(CHECK);
  1994     _backtrace = Handle(THREAD, _head);
  2002     _backtrace = Handle(THREAD, _head);
  1995     _index = 0;
  2003     _index = 0;
  1996   }
  2004   }
  1997 
  2005 
  1998   BacktraceBuilder(Thread* thread, objArrayHandle backtrace) {
  2006   BacktraceBuilder(Thread* thread, objArrayHandle backtrace) {
  1999     _methods = get_methods(backtrace);
  2007     _methods = get_methods(backtrace);
  2000     _bcis = get_bcis(backtrace);
  2008     _bcis = get_bcis(backtrace);
  2001     _mirrors = get_mirrors(backtrace);
  2009     _mirrors = get_mirrors(backtrace);
  2002     _names = get_names(backtrace);
  2010     _names = get_names(backtrace);
       
  2011     _has_hidden_top_frame = get_has_hidden_top_frame(backtrace);
  2003     assert(_methods->length() == _bcis->length() &&
  2012     assert(_methods->length() == _bcis->length() &&
  2004            _methods->length() == _mirrors->length() &&
  2013            _methods->length() == _mirrors->length() &&
  2005            _mirrors->length() == _names->length(),
  2014            _mirrors->length() == _names->length(),
  2006            "method and source information arrays should match");
  2015            "method and source information arrays should match");
  2007 
  2016 
  2035     }
  2044     }
  2036     new_head->obj_at_put(trace_methods_offset, new_methods());
  2045     new_head->obj_at_put(trace_methods_offset, new_methods());
  2037     new_head->obj_at_put(trace_bcis_offset, new_bcis());
  2046     new_head->obj_at_put(trace_bcis_offset, new_bcis());
  2038     new_head->obj_at_put(trace_mirrors_offset, new_mirrors());
  2047     new_head->obj_at_put(trace_mirrors_offset, new_mirrors());
  2039     new_head->obj_at_put(trace_names_offset, new_names());
  2048     new_head->obj_at_put(trace_names_offset, new_names());
       
  2049     new_head->obj_at_put(trace_hidden_offset, NULL);
  2040 
  2050 
  2041     _head    = new_head();
  2051     _head    = new_head();
  2042     _methods = new_methods();
  2052     _methods = new_methods();
  2043     _bcis = new_bcis();
  2053     _bcis = new_bcis();
  2044     _mirrors = new_mirrors();
  2054     _mirrors = new_mirrors();
  2073     // We need to save the mirrors in the backtrace to keep the class
  2083     // We need to save the mirrors in the backtrace to keep the class
  2074     // from being unloaded while we still have this stack trace.
  2084     // from being unloaded while we still have this stack trace.
  2075     assert(method->method_holder()->java_mirror() != NULL, "never push null for mirror");
  2085     assert(method->method_holder()->java_mirror() != NULL, "never push null for mirror");
  2076     _mirrors->obj_at_put(_index, method->method_holder()->java_mirror());
  2086     _mirrors->obj_at_put(_index, method->method_holder()->java_mirror());
  2077     _index++;
  2087     _index++;
       
  2088   }
       
  2089 
       
  2090   void set_has_hidden_top_frame(TRAPS) {
       
  2091     if (_has_hidden_top_frame == NULL) {
       
  2092       jvalue prim;
       
  2093       prim.z = 1;
       
  2094       PauseNoSafepointVerifier pnsv(&_nsv);
       
  2095       _has_hidden_top_frame = java_lang_boxing_object::create(T_BOOLEAN, &prim, CHECK);
       
  2096       _head->obj_at_put(trace_hidden_offset, _has_hidden_top_frame);
       
  2097     }
  2078   }
  2098   }
  2079 
  2099 
  2080 };
  2100 };
  2081 
  2101 
  2082 struct BacktraceElement : public StackObj {
  2102 struct BacktraceElement : public StackObj {
  2404         // there are none or we've seen them all - either way stop checking
  2424         // there are none or we've seen them all - either way stop checking
  2405         skip_throwableInit_check = true;
  2425         skip_throwableInit_check = true;
  2406       }
  2426       }
  2407     }
  2427     }
  2408     if (method->is_hidden()) {
  2428     if (method->is_hidden()) {
  2409       if (skip_hidden)  continue;
  2429       if (skip_hidden) {
       
  2430         if (total_count == 0) {
       
  2431           // The top frame will be hidden from the stack trace.
       
  2432           bt.set_has_hidden_top_frame(CHECK);
       
  2433         }
       
  2434         continue;
       
  2435       }
  2410     }
  2436     }
  2411     bt.push(method, bci, CHECK);
  2437     bt.push(method, bci, CHECK);
  2412     total_count++;
  2438     total_count++;
  2413   }
  2439   }
  2414 
  2440 
  2519                                          method,
  2545                                          method,
  2520                                          bte._version,
  2546                                          bte._version,
  2521                                          bte._bci,
  2547                                          bte._bci,
  2522                                          bte._name, CHECK);
  2548                                          bte._name, CHECK);
  2523   }
  2549   }
       
  2550 }
       
  2551 
       
  2552 bool java_lang_Throwable::get_top_method_and_bci(oop throwable, Method** method, int* bci) {
       
  2553   Thread* THREAD = Thread::current();
       
  2554   objArrayHandle result(THREAD, objArrayOop(backtrace(throwable)));
       
  2555   BacktraceIterator iter(result, THREAD);
       
  2556   // No backtrace available.
       
  2557   if (!iter.repeat()) return false;
       
  2558 
       
  2559   // If the exception happened in a frame that has been hidden, i.e.,
       
  2560   // omitted from the back trace, we can not compute the message.
       
  2561   oop hidden = ((objArrayOop)backtrace(throwable))->obj_at(trace_hidden_offset);
       
  2562   if (hidden != NULL) {
       
  2563     return false;
       
  2564   }
       
  2565 
       
  2566   // Get first backtrace element.
       
  2567   BacktraceElement bte = iter.next(THREAD);
       
  2568 
       
  2569   InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(bte._mirror()));
       
  2570   assert(holder != NULL, "first element should be non-null");
       
  2571   Method* m = holder->method_with_orig_idnum(bte._method_id, bte._version);
       
  2572 
       
  2573   // Original version is no longer available.
       
  2574   if (m == NULL || !version_matches(m, bte._version)) {
       
  2575     return false;
       
  2576   }
       
  2577 
       
  2578   *method = m;
       
  2579   *bci = bte._bci;
       
  2580   return true;
  2524 }
  2581 }
  2525 
  2582 
  2526 oop java_lang_StackTraceElement::create(const methodHandle& method, int bci, TRAPS) {
  2583 oop java_lang_StackTraceElement::create(const methodHandle& method, int bci, TRAPS) {
  2527   // Allocate java.lang.StackTraceElement instance
  2584   // Allocate java.lang.StackTraceElement instance
  2528   InstanceKlass* k = SystemDictionary::StackTraceElement_klass();
  2585   InstanceKlass* k = SystemDictionary::StackTraceElement_klass();