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, Method** method, int* bci) {
1974 objArrayOop bt = (objArrayOop)backtrace(throwable);
1975 int depth = 0;
1976
1977 if (bt == NULL) {
1978 return false;
1979 }
1980
1981 oop ms = bt->obj_at(trace_methods_offset);
1982 typeArrayOop methods = typeArrayOop(ms);
1983 typeArrayOop bcis = (typeArrayOop)bt->obj_at(trace_bcis_offset);
1984 objArrayOop mirrors = (objArrayOop)bt->obj_at(trace_mirrors_offset);
1985 if ((methods == NULL) || (bcis == NULL) || (mirrors == NULL)) {
1986 return false;
1987 }
1988
1989 oop m = mirrors->obj_at(0);
1990 if (m == NULL) {
1991 return false;
1992 }
1993
1994 InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(m));
1995 int method_id = methods->short_at(0);
1996 Method* act_method = holder->method_with_idnum(method_id);
1997 if (act_method == NULL) {
1998 return false;
1999 }
2000
2001 int act_bci = Backtrace::bci_at(bcis->int_at(0));
2002 *method = act_method;
2003 *bci = act_bci;
2004 return true;
2005 }
2006
2007 // This class provides a simple wrapper over the internal structure of
2008 // exception backtrace to insulate users of the backtrace from needing
2009 // to know what it looks like.
2010 class BacktraceBuilder: public StackObj {
2011 friend class BacktraceIterator;
2012 private:
2013 Handle _backtrace;
2014 objArrayOop _head;
2015 typeArrayOop _methods;
2016 typeArrayOop _bcis;
2017 objArrayOop _mirrors;
2018 typeArrayOop _names; // needed to insulate method name against redefinition
2019 int _index;
2020 NoSafepointVerifier _nsv;
2021
2022 enum {
2023 trace_methods_offset = java_lang_Throwable::trace_methods_offset,
2024 trace_bcis_offset = java_lang_Throwable::trace_bcis_offset,
2025 trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,
|