335 buffer_pos += write_len;
336
337 // Note that the following does not depend on write_len.
338 // This means that position and count get updated
339 // even when overflow occurs.
340 update_position(s, len);
341 }
342
343 char* stringStream::as_string() {
344 char* copy = NEW_RESOURCE_ARRAY(char, buffer_pos + 1);
345 strncpy(copy, buffer, buffer_pos);
346 copy[buffer_pos] = 0; // terminating null
347 return copy;
348 }
349
350 stringStream::~stringStream() {}
351
352 xmlStream* xtty;
353 outputStream* tty;
354 outputStream* gclog_or_tty;
355 extern Mutex* tty_lock;
356
357 #define EXTRACHARLEN 32
358 #define CURRENTAPPX ".current"
359 #define FILENAMEBUFLEN 1024
360 // convert YYYY-MM-DD HH:MM:SS to YYYY-MM-DD_HH-MM-SS
361 char* get_datetime_string(char *buf, size_t len) {
362 os::local_time_string(buf, len);
363 int i = (int)strlen(buf);
364 while (i-- >= 0) {
365 if (buf[i] == ' ') buf[i] = '_';
366 else if (buf[i] == ':') buf[i] = '-';
367 }
368 return buf;
369 }
370
371 static const char* make_log_name_internal(const char* log_name, const char* force_directory,
372 int pid, const char* tms) {
373 const char* basename = log_name;
374 char file_sep = os::file_separator()[0];
446 }
447
448 int buf_pos = (int)strlen(buf);
449 const char* tail = nametail;
450
451 if (first >= 0) {
452 tail = nametail + first + 2;
453 strncpy(&buf[buf_pos], nametail, first);
454 strcpy(&buf[buf_pos + first], p1st);
455 buf_pos = (int)strlen(buf);
456 if (second >= 0) {
457 strncpy(&buf[buf_pos], tail, second - first - 2);
458 strcpy(&buf[buf_pos + second - first - 2], p2nd);
459 tail = nametail + second + 2;
460 }
461 }
462 strcat(buf, tail); // append rest of name, or all of name
463 return buf;
464 }
465
466 // log_name comes from -XX:LogFile=log_name or -Xloggc:log_name
467 // in log_name, %p => pid1234 and
468 // %t => YYYY-MM-DD_HH-MM-SS
469 static const char* make_log_name(const char* log_name, const char* force_directory) {
470 char timestr[32];
471 get_datetime_string(timestr, sizeof(timestr));
472 return make_log_name_internal(log_name, force_directory, os::current_process_id(),
473 timestr);
474 }
475
476 #ifndef PRODUCT
477 void test_loggc_filename() {
478 int pid;
479 char tms[32];
480 char i_result[FILENAMEBUFLEN];
481 const char* o_result;
482 get_datetime_string(tms, sizeof(tms));
483 pid = os::current_process_id();
484
485 // test.log
486 jio_snprintf(i_result, sizeof(char)*FILENAMEBUFLEN, "test.log", tms);
1086 tty->time_stamp().update_to(1);
1087 }
1088 }
1089
1090 void ostream_init_log() {
1091 // For -Xloggc:<file> option - called in runtime/thread.cpp
1092 // Note : this must be called AFTER ostream_init()
1093
1094 gclog_or_tty = tty; // default to tty
1095 if (Arguments::gc_log_filename() != NULL) {
1096 fileStream * gclog = new(ResourceObj::C_HEAP, mtInternal)
1097 gcLogFileStream(Arguments::gc_log_filename());
1098 if (gclog->is_open()) {
1099 // now we update the time stamp of the GC log to be synced up
1100 // with tty.
1101 gclog->time_stamp().update_to(tty->time_stamp().ticks());
1102 }
1103 gclog_or_tty = gclog;
1104 }
1105
1106 // If we haven't lazily initialized the logfile yet, do it now,
1107 // to avoid the possibility of lazy initialization during a VM
1108 // crash, which can affect the stability of the fatal error handler.
1109 defaultStream::instance->has_log_file();
1110 }
1111
1112 // ostream_exit() is called during normal VM exit to finish log files, flush
1113 // output and free resource.
1114 void ostream_exit() {
1115 static bool ostream_exit_called = false;
1116 if (ostream_exit_called) return;
1117 ostream_exit_called = true;
1118 if (gclog_or_tty != tty) {
1119 delete gclog_or_tty;
1120 }
1121 {
1122 // we temporaly disable PrintMallocFree here
1123 // as otherwise it'll lead to using of almost deleted
1124 // tty or defaultStream::instance in logging facility
1125 // of HeapFree(), see 6391258
1126 DEBUG_ONLY(FlagSetting fs(PrintMallocFree, false);)
1127 if (tty != defaultStream::instance) {
1128 delete tty;
1129 }
1130 if (defaultStream::instance != NULL) {
1131 delete defaultStream::instance;
1132 }
1133 }
1134 tty = NULL;
1135 xtty = NULL;
1136 gclog_or_tty = NULL;
1137 defaultStream::instance = NULL;
|
335 buffer_pos += write_len;
336
337 // Note that the following does not depend on write_len.
338 // This means that position and count get updated
339 // even when overflow occurs.
340 update_position(s, len);
341 }
342
343 char* stringStream::as_string() {
344 char* copy = NEW_RESOURCE_ARRAY(char, buffer_pos + 1);
345 strncpy(copy, buffer, buffer_pos);
346 copy[buffer_pos] = 0; // terminating null
347 return copy;
348 }
349
350 stringStream::~stringStream() {}
351
352 xmlStream* xtty;
353 outputStream* tty;
354 outputStream* gclog_or_tty;
355 fileStream* classlist_file; // Only dump the classes that can be stored into the CDS archive
356 extern Mutex* tty_lock;
357
358 #define EXTRACHARLEN 32
359 #define CURRENTAPPX ".current"
360 #define FILENAMEBUFLEN 1024
361 // convert YYYY-MM-DD HH:MM:SS to YYYY-MM-DD_HH-MM-SS
362 char* get_datetime_string(char *buf, size_t len) {
363 os::local_time_string(buf, len);
364 int i = (int)strlen(buf);
365 while (i-- >= 0) {
366 if (buf[i] == ' ') buf[i] = '_';
367 else if (buf[i] == ':') buf[i] = '-';
368 }
369 return buf;
370 }
371
372 static const char* make_log_name_internal(const char* log_name, const char* force_directory,
373 int pid, const char* tms) {
374 const char* basename = log_name;
375 char file_sep = os::file_separator()[0];
447 }
448
449 int buf_pos = (int)strlen(buf);
450 const char* tail = nametail;
451
452 if (first >= 0) {
453 tail = nametail + first + 2;
454 strncpy(&buf[buf_pos], nametail, first);
455 strcpy(&buf[buf_pos + first], p1st);
456 buf_pos = (int)strlen(buf);
457 if (second >= 0) {
458 strncpy(&buf[buf_pos], tail, second - first - 2);
459 strcpy(&buf[buf_pos + second - first - 2], p2nd);
460 tail = nametail + second + 2;
461 }
462 }
463 strcat(buf, tail); // append rest of name, or all of name
464 return buf;
465 }
466
467 // log_name comes from -XX:LogFile=log_name, -Xloggc:log_name or
468 // -XX:DumpLoadedClassList=<file_name>
469 // in log_name, %p => pid1234 and
470 // %t => YYYY-MM-DD_HH-MM-SS
471 static const char* make_log_name(const char* log_name, const char* force_directory) {
472 char timestr[32];
473 get_datetime_string(timestr, sizeof(timestr));
474 return make_log_name_internal(log_name, force_directory, os::current_process_id(),
475 timestr);
476 }
477
478 #ifndef PRODUCT
479 void test_loggc_filename() {
480 int pid;
481 char tms[32];
482 char i_result[FILENAMEBUFLEN];
483 const char* o_result;
484 get_datetime_string(tms, sizeof(tms));
485 pid = os::current_process_id();
486
487 // test.log
488 jio_snprintf(i_result, sizeof(char)*FILENAMEBUFLEN, "test.log", tms);
1088 tty->time_stamp().update_to(1);
1089 }
1090 }
1091
1092 void ostream_init_log() {
1093 // For -Xloggc:<file> option - called in runtime/thread.cpp
1094 // Note : this must be called AFTER ostream_init()
1095
1096 gclog_or_tty = tty; // default to tty
1097 if (Arguments::gc_log_filename() != NULL) {
1098 fileStream * gclog = new(ResourceObj::C_HEAP, mtInternal)
1099 gcLogFileStream(Arguments::gc_log_filename());
1100 if (gclog->is_open()) {
1101 // now we update the time stamp of the GC log to be synced up
1102 // with tty.
1103 gclog->time_stamp().update_to(tty->time_stamp().ticks());
1104 }
1105 gclog_or_tty = gclog;
1106 }
1107
1108 // For -XX:DumpLoadedClassList=<file> option
1109 if (DumpLoadedClassList != NULL) {
1110 const char* list_name = make_log_name(DumpLoadedClassList, NULL);
1111 classlist_file = new(ResourceObj::C_HEAP, mtInternal)
1112 fileStream(list_name);
1113 FREE_C_HEAP_ARRAY(char, list_name, mtInternal);
1114 }
1115
1116 // If we haven't lazily initialized the logfile yet, do it now,
1117 // to avoid the possibility of lazy initialization during a VM
1118 // crash, which can affect the stability of the fatal error handler.
1119 defaultStream::instance->has_log_file();
1120 }
1121
1122 // ostream_exit() is called during normal VM exit to finish log files, flush
1123 // output and free resource.
1124 void ostream_exit() {
1125 static bool ostream_exit_called = false;
1126 if (ostream_exit_called) return;
1127 ostream_exit_called = true;
1128 if (classlist_file != NULL) {
1129 delete classlist_file;
1130 }
1131 if (gclog_or_tty != tty) {
1132 delete gclog_or_tty;
1133 }
1134 {
1135 // we temporaly disable PrintMallocFree here
1136 // as otherwise it'll lead to using of almost deleted
1137 // tty or defaultStream::instance in logging facility
1138 // of HeapFree(), see 6391258
1139 DEBUG_ONLY(FlagSetting fs(PrintMallocFree, false);)
1140 if (tty != defaultStream::instance) {
1141 delete tty;
1142 }
1143 if (defaultStream::instance != NULL) {
1144 delete defaultStream::instance;
1145 }
1146 }
1147 tty = NULL;
1148 xtty = NULL;
1149 gclog_or_tty = NULL;
1150 defaultStream::instance = NULL;
|