1499 return primitive_type(java_class);
1500 } else {
1501 if (reference_klass != NULL)
1502 (*reference_klass) = as_Klass(java_class);
1503 return T_OBJECT;
1504 }
1505 }
1506
1507
1508 oop java_lang_Class::primitive_mirror(BasicType t) {
1509 oop mirror = Universe::java_mirror(t);
1510 assert(mirror != NULL && mirror->is_a(SystemDictionary::Class_klass()), "must be a Class");
1511 assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1512 return mirror;
1513 }
1514
1515 bool java_lang_Class::offsets_computed = false;
1516 int java_lang_Class::classRedefinedCount_offset = -1;
1517
1518 #define CLASS_FIELDS_DO(macro) \
1519 macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false) ; \
1520 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1521 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1522 macro(_module_offset, k, "module", module_signature, false); \
1523 macro(_name_offset, k, "name", string_signature, false); \
1524
1525 void java_lang_Class::compute_offsets() {
1526 if (offsets_computed) {
1527 return;
1528 }
1529
1530 offsets_computed = true;
1531
1532 InstanceKlass* k = SystemDictionary::Class_klass();
1533 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1534
1535 // Init lock is a C union with component_mirror. Only instanceKlass mirrors have
1536 // init_lock and only ArrayKlass mirrors have component_mirror. Since both are oops
1537 // GC treats them the same.
1538 _init_lock_offset = _component_mirror_offset;
1539
1944
1945 void java_lang_Throwable::print(oop throwable, outputStream* st) {
1946 ResourceMark rm;
1947 Klass* k = throwable->klass();
1948 assert(k != NULL, "just checking");
1949 st->print("%s", k->external_name());
1950 oop msg = message(throwable);
1951 if (msg != NULL) {
1952 st->print(": %s", java_lang_String::as_utf8_string(msg));
1953 }
1954 }
1955
1956 // After this many redefines, the stack trace is unreliable.
1957 const int MAX_VERSION = USHRT_MAX;
1958
1959 static inline bool version_matches(Method* method, int version) {
1960 assert(version < MAX_VERSION, "version is too big");
1961 return method != NULL && (method->constants()->version() == version);
1962 }
1963
1964
1965 // This class provides a simple wrapper over the internal structure of
1966 // exception backtrace to insulate users of the backtrace from needing
1967 // to know what it looks like.
1968 class BacktraceBuilder: public StackObj {
1969 friend class BacktraceIterator;
1970 private:
1971 Handle _backtrace;
1972 objArrayOop _head;
1973 typeArrayOop _methods;
1974 typeArrayOop _bcis;
1975 objArrayOop _mirrors;
1976 typeArrayOop _names; // needed to insulate method name against redefinition
1977 int _index;
1978 NoSafepointVerifier _nsv;
1979
1980 enum {
1981 trace_methods_offset = java_lang_Throwable::trace_methods_offset,
1982 trace_bcis_offset = java_lang_Throwable::trace_bcis_offset,
1983 trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,
|
1499 return primitive_type(java_class);
1500 } else {
1501 if (reference_klass != NULL)
1502 (*reference_klass) = as_Klass(java_class);
1503 return T_OBJECT;
1504 }
1505 }
1506
1507
1508 oop java_lang_Class::primitive_mirror(BasicType t) {
1509 oop mirror = Universe::java_mirror(t);
1510 assert(mirror != NULL && mirror->is_a(SystemDictionary::Class_klass()), "must be a Class");
1511 assert(java_lang_Class::is_primitive(mirror), "must be primitive");
1512 return mirror;
1513 }
1514
1515 bool java_lang_Class::offsets_computed = false;
1516 int java_lang_Class::classRedefinedCount_offset = -1;
1517
1518 #define CLASS_FIELDS_DO(macro) \
1519 macro(classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false); \
1520 macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
1521 macro(_component_mirror_offset, k, "componentType", class_signature, false); \
1522 macro(_module_offset, k, "module", module_signature, false); \
1523 macro(_name_offset, k, "name", string_signature, false); \
1524
1525 void java_lang_Class::compute_offsets() {
1526 if (offsets_computed) {
1527 return;
1528 }
1529
1530 offsets_computed = true;
1531
1532 InstanceKlass* k = SystemDictionary::Class_klass();
1533 CLASS_FIELDS_DO(FIELD_COMPUTE_OFFSET);
1534
1535 // Init lock is a C union with component_mirror. Only instanceKlass mirrors have
1536 // init_lock and only ArrayKlass mirrors have component_mirror. Since both are oops
1537 // GC treats them the same.
1538 _init_lock_offset = _component_mirror_offset;
1539
1944
1945 void java_lang_Throwable::print(oop throwable, outputStream* st) {
1946 ResourceMark rm;
1947 Klass* k = throwable->klass();
1948 assert(k != NULL, "just checking");
1949 st->print("%s", k->external_name());
1950 oop msg = message(throwable);
1951 if (msg != NULL) {
1952 st->print(": %s", java_lang_String::as_utf8_string(msg));
1953 }
1954 }
1955
1956 // After this many redefines, the stack trace is unreliable.
1957 const int MAX_VERSION = USHRT_MAX;
1958
1959 static inline bool version_matches(Method* method, int version) {
1960 assert(version < MAX_VERSION, "version is too big");
1961 return method != NULL && (method->constants()->version() == version);
1962 }
1963
1964 bool java_lang_Throwable::get_method_and_bci(oop throwable, Method** method, int* bci) {
1965 objArrayOop bt = (objArrayOop)backtrace(throwable);
1966
1967 if (bt == NULL) {
1968 return false;
1969 }
1970
1971 oop ms = bt->obj_at(trace_methods_offset);
1972 typeArrayOop methods = typeArrayOop(ms);
1973 typeArrayOop bcis = (typeArrayOop)bt->obj_at(trace_bcis_offset);
1974 objArrayOop mirrors = (objArrayOop)bt->obj_at(trace_mirrors_offset);
1975 if ((methods == NULL) || (bcis == NULL) || (mirrors == NULL)) {
1976 return false;
1977 }
1978
1979 oop m = mirrors->obj_at(0);
1980 if (m == NULL) {
1981 return false;
1982 }
1983
1984 InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(m));
1985 int method_id = methods->short_at(0);
1986 Method* act_method = holder->method_with_idnum(method_id);
1987 if (act_method == NULL) {
1988 return false;
1989 }
1990
1991 int act_bci = Backtrace::bci_at(bcis->int_at(0));
1992 *method = act_method;
1993 *bci = act_bci;
1994 return true;
1995 }
1996
1997 // This class provides a simple wrapper over the internal structure of
1998 // exception backtrace to insulate users of the backtrace from needing
1999 // to know what it looks like.
2000 class BacktraceBuilder: public StackObj {
2001 friend class BacktraceIterator;
2002 private:
2003 Handle _backtrace;
2004 objArrayOop _head;
2005 typeArrayOop _methods;
2006 typeArrayOop _bcis;
2007 objArrayOop _mirrors;
2008 typeArrayOop _names; // needed to insulate method name against redefinition
2009 int _index;
2010 NoSafepointVerifier _nsv;
2011
2012 enum {
2013 trace_methods_offset = java_lang_Throwable::trace_methods_offset,
2014 trace_bcis_offset = java_lang_Throwable::trace_bcis_offset,
2015 trace_mirrors_offset = java_lang_Throwable::trace_mirrors_offset,
|