978 st->print("Time: %s", timestring);
979 }
980
981 double t = os::elapsedTime();
982 // NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in
983 // Linux. Must be a bug in glibc ? Workaround is to round "t" to int
984 // before printf. We lost some precision, but who cares?
985 int eltime = (int)t; // elapsed time in seconds
986
987 // print elapsed time in a human-readable format:
988 int eldays = eltime / secs_per_day;
989 int day_secs = eldays * secs_per_day;
990 int elhours = (eltime - day_secs) / secs_per_hour;
991 int hour_secs = elhours * secs_per_hour;
992 int elmins = (eltime - day_secs - hour_secs) / secs_per_min;
993 int minute_secs = elmins * secs_per_min;
994 int elsecs = (eltime - day_secs - hour_secs - minute_secs);
995 st->print_cr(" elapsed time: %d seconds (%dd %dh %dm %ds)", eltime, eldays, elhours, elmins, elsecs);
996 }
997
998 // moved from debug.cpp (used to be find()) but still called from there
999 // The verbose parameter is only set by the debug code in one case
1000 void os::print_location(outputStream* st, intptr_t x, bool verbose) {
1001 address addr = (address)x;
1002 // Handle NULL first, so later checks don't need to protect against it.
1003 if (addr == NULL) {
1004 st->print_cr("0x0 is NULL");
1005 return;
1006 }
1007 CodeBlob* b = CodeCache::find_blob_unsafe(addr);
1008 if (b != NULL) {
1009 if (b->is_buffer_blob()) {
1010 // the interpreter is generated into a buffer blob
1011 InterpreterCodelet* i = Interpreter::codelet_containing(addr);
1012 if (i != NULL) {
1013 st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an Interpreter codelet", p2i(addr), (int)(addr - i->code_begin()));
1014 i->print_on(st);
1015 return;
1016 }
1017 if (Interpreter::contains(addr)) {
1077 } else if (p == NULL && oopDesc::is_oop(oop(addr))) {
1078 p = (HeapWord*) addr;
1079 print = true;
1080 }
1081 if (print) {
1082 if (p == (HeapWord*) addr) {
1083 st->print_cr(INTPTR_FORMAT " is an oop", p2i(addr));
1084 } else {
1085 st->print_cr(INTPTR_FORMAT " is pointing into object: " INTPTR_FORMAT, p2i(addr), p2i(p));
1086 }
1087 oop(p)->print_on(st);
1088 return;
1089 }
1090 } else {
1091 if (Universe::heap()->is_in_reserved(addr)) {
1092 st->print_cr(INTPTR_FORMAT " is an unallocated location "
1093 "in the heap", p2i(addr));
1094 return;
1095 }
1096 }
1097 if (JNIHandles::is_global_handle((jobject) addr)) {
1098 st->print_cr(INTPTR_FORMAT " is a global jni handle", p2i(addr));
1099 return;
1100 }
1101 if (JNIHandles::is_weak_global_handle((jobject) addr)) {
1102 st->print_cr(INTPTR_FORMAT " is a weak global jni handle", p2i(addr));
1103 return;
1104 }
1105 #ifndef PRODUCT
1106 // we don't keep the block list in product mode
1107 if (JNIHandles::is_local_handle((jobject) addr)) {
1108 st->print_cr(INTPTR_FORMAT " is a local jni handle", p2i(addr));
1109 return;
1110 }
1111 #endif
1112
1113 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
1114 // Check for privilege stack
1115 if (thread->privileged_stack_top() != NULL &&
1116 thread->privileged_stack_top()->contains(addr)) {
1117 st->print_cr(INTPTR_FORMAT " is pointing into the privilege stack "
1118 "for thread: " INTPTR_FORMAT, p2i(addr), p2i(thread));
1119 if (verbose) thread->print_on(st);
1120 return;
1121 }
1122 // If the addr is a java thread print information about that.
1123 if (addr == (address)thread) {
1124 if (verbose) {
1125 thread->print_on(st);
1126 } else {
1127 st->print_cr(INTPTR_FORMAT " is a thread", p2i(addr));
1128 }
1129 return;
1130 }
1131 // If the addr is in the stack region for this thread then report that
1135 INTPTR_FORMAT, p2i(addr), p2i(thread));
1136 if (verbose) thread->print_on(st);
1137 return;
1138 }
1139 }
1140
1141 // Check if in metaspace and print types that have vptrs (only method now)
1142 if (Metaspace::contains(addr)) {
1143 if (Method::has_method_vptr((const void*)addr)) {
1144 ((Method*)addr)->print_value_on(st);
1145 st->cr();
1146 } else {
1147 // Use addr->print() from the debugger instead (not here)
1148 st->print_cr(INTPTR_FORMAT " is pointing into metadata", p2i(addr));
1149 }
1150 return;
1151 }
1152
1153 // Try an OS specific find
1154 if (os::find(addr, st)) {
1155 return;
1156 }
1157
1158 st->print_cr(INTPTR_FORMAT " is an unknown value", p2i(addr));
1159 }
1160
1161 // Looks like all platforms can use the same function to check if C
1162 // stack is walkable beyond current frame. The check for fp() is not
1163 // necessary on Sparc, but it's harmless.
1164 bool os::is_first_C_frame(frame* fr) {
1165 // Load up sp, fp, sender sp and sender fp, check for reasonable values.
1166 // Check usp first, because if that's bad the other accessors may fault
1167 // on some architectures. Ditto ufp second, etc.
1168 uintptr_t fp_align_mask = (uintptr_t)(sizeof(address)-1);
1169 // sp on amd can be 32 bit aligned.
1170 uintptr_t sp_align_mask = (uintptr_t)(sizeof(int)-1);
1171
1172 uintptr_t usp = (uintptr_t)fr->sp();
1173 if ((usp & sp_align_mask) != 0) return true;
1174
|
978 st->print("Time: %s", timestring);
979 }
980
981 double t = os::elapsedTime();
982 // NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in
983 // Linux. Must be a bug in glibc ? Workaround is to round "t" to int
984 // before printf. We lost some precision, but who cares?
985 int eltime = (int)t; // elapsed time in seconds
986
987 // print elapsed time in a human-readable format:
988 int eldays = eltime / secs_per_day;
989 int day_secs = eldays * secs_per_day;
990 int elhours = (eltime - day_secs) / secs_per_hour;
991 int hour_secs = elhours * secs_per_hour;
992 int elmins = (eltime - day_secs - hour_secs) / secs_per_min;
993 int minute_secs = elmins * secs_per_min;
994 int elsecs = (eltime - day_secs - hour_secs - minute_secs);
995 st->print_cr(" elapsed time: %d seconds (%dd %dh %dm %ds)", eltime, eldays, elhours, elmins, elsecs);
996 }
997
998
999 // Check if pointer can be read from (4-byte read access).
1000 // Helps to prove validity of a not-NULL pointer.
1001 // Returns true in very early stages of VM life when stub is not yet generated.
1002 #define SAFEFETCH_DEFAULT true
1003 bool os::is_readable_pointer(const void* p) {
1004 if (!CanUseSafeFetch32()) {
1005 return SAFEFETCH_DEFAULT;
1006 }
1007 int* const aligned = (int*) align_down((intptr_t)p, 4);
1008 int cafebabe = 0xcafebabe; // tester value 1
1009 int deadbeef = 0xdeadbeef; // tester value 2
1010 return (SafeFetch32(aligned, cafebabe) != cafebabe) || (SafeFetch32(aligned, deadbeef) != deadbeef);
1011 }
1012
1013
1014 // moved from debug.cpp (used to be find()) but still called from there
1015 // The verbose parameter is only set by the debug code in one case
1016 void os::print_location(outputStream* st, intptr_t x, bool verbose) {
1017 address addr = (address)x;
1018 // Handle NULL first, so later checks don't need to protect against it.
1019 if (addr == NULL) {
1020 st->print_cr("0x0 is NULL");
1021 return;
1022 }
1023 CodeBlob* b = CodeCache::find_blob_unsafe(addr);
1024 if (b != NULL) {
1025 if (b->is_buffer_blob()) {
1026 // the interpreter is generated into a buffer blob
1027 InterpreterCodelet* i = Interpreter::codelet_containing(addr);
1028 if (i != NULL) {
1029 st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an Interpreter codelet", p2i(addr), (int)(addr - i->code_begin()));
1030 i->print_on(st);
1031 return;
1032 }
1033 if (Interpreter::contains(addr)) {
1093 } else if (p == NULL && oopDesc::is_oop(oop(addr))) {
1094 p = (HeapWord*) addr;
1095 print = true;
1096 }
1097 if (print) {
1098 if (p == (HeapWord*) addr) {
1099 st->print_cr(INTPTR_FORMAT " is an oop", p2i(addr));
1100 } else {
1101 st->print_cr(INTPTR_FORMAT " is pointing into object: " INTPTR_FORMAT, p2i(addr), p2i(p));
1102 }
1103 oop(p)->print_on(st);
1104 return;
1105 }
1106 } else {
1107 if (Universe::heap()->is_in_reserved(addr)) {
1108 st->print_cr(INTPTR_FORMAT " is an unallocated location "
1109 "in the heap", p2i(addr));
1110 return;
1111 }
1112 }
1113
1114 bool accessible = is_readable_pointer(addr);
1115
1116 if (align_down((intptr_t)addr, sizeof(intptr_t)) != 0 && accessible) {
1117 if (JNIHandles::is_global_handle((jobject) addr)) {
1118 st->print_cr(INTPTR_FORMAT " is a global jni handle", p2i(addr));
1119 return;
1120 }
1121 if (JNIHandles::is_weak_global_handle((jobject) addr)) {
1122 st->print_cr(INTPTR_FORMAT " is a weak global jni handle", p2i(addr));
1123 return;
1124 }
1125 #ifndef PRODUCT
1126 // we don't keep the block list in product mode
1127 if (JNIHandles::is_local_handle((jobject) addr)) {
1128 st->print_cr(INTPTR_FORMAT " is a local jni handle", p2i(addr));
1129 return;
1130 }
1131 #endif
1132 }
1133
1134 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
1135 // Check for privilege stack
1136 if (thread->privileged_stack_top() != NULL &&
1137 thread->privileged_stack_top()->contains(addr)) {
1138 st->print_cr(INTPTR_FORMAT " is pointing into the privilege stack "
1139 "for thread: " INTPTR_FORMAT, p2i(addr), p2i(thread));
1140 if (verbose) thread->print_on(st);
1141 return;
1142 }
1143 // If the addr is a java thread print information about that.
1144 if (addr == (address)thread) {
1145 if (verbose) {
1146 thread->print_on(st);
1147 } else {
1148 st->print_cr(INTPTR_FORMAT " is a thread", p2i(addr));
1149 }
1150 return;
1151 }
1152 // If the addr is in the stack region for this thread then report that
1156 INTPTR_FORMAT, p2i(addr), p2i(thread));
1157 if (verbose) thread->print_on(st);
1158 return;
1159 }
1160 }
1161
1162 // Check if in metaspace and print types that have vptrs (only method now)
1163 if (Metaspace::contains(addr)) {
1164 if (Method::has_method_vptr((const void*)addr)) {
1165 ((Method*)addr)->print_value_on(st);
1166 st->cr();
1167 } else {
1168 // Use addr->print() from the debugger instead (not here)
1169 st->print_cr(INTPTR_FORMAT " is pointing into metadata", p2i(addr));
1170 }
1171 return;
1172 }
1173
1174 // Try an OS specific find
1175 if (os::find(addr, st)) {
1176 return;
1177 }
1178
1179 if (accessible) {
1180 st->print_cr(INTPTR_FORMAT " points into unknown readable memory", p2i(addr));
1181 return;
1182 }
1183
1184 st->print_cr(INTPTR_FORMAT " is an unknown value", p2i(addr));
1185 }
1186
1187 // Looks like all platforms can use the same function to check if C
1188 // stack is walkable beyond current frame. The check for fp() is not
1189 // necessary on Sparc, but it's harmless.
1190 bool os::is_first_C_frame(frame* fr) {
1191 // Load up sp, fp, sender sp and sender fp, check for reasonable values.
1192 // Check usp first, because if that's bad the other accessors may fault
1193 // on some architectures. Ditto ufp second, etc.
1194 uintptr_t fp_align_mask = (uintptr_t)(sizeof(address)-1);
1195 // sp on amd can be 32 bit aligned.
1196 uintptr_t sp_align_mask = (uintptr_t)(sizeof(int)-1);
1197
1198 uintptr_t usp = (uintptr_t)fr->sp();
1199 if ((usp & sp_align_mask) != 0) return true;
1200
|