comparison src/share/vm/utilities/ostream.cpp @ 8124:5fc51c1ecdeb

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 05 Mar 2013 23:44:54 +0100
parents 3ac7d10a6572 0598674c0056
children b8f261ba79c6
comparison
equal deleted inserted replaced
7943:a413bcd552a4 8124:5fc51c1ecdeb
430 } 430 }
431 } 431 }
432 432
433 rotatingFileStream::rotatingFileStream(const char* file_name) { 433 rotatingFileStream::rotatingFileStream(const char* file_name) {
434 _cur_file_num = 0; 434 _cur_file_num = 0;
435 _bytes_writen = 0L; 435 _bytes_written = 0L;
436 _file_name = NEW_C_HEAP_ARRAY(char, strlen(file_name)+10, mtInternal); 436 _file_name = NEW_C_HEAP_ARRAY(char, strlen(file_name)+10, mtInternal);
437 jio_snprintf(_file_name, strlen(file_name)+10, "%s.%d", file_name, _cur_file_num); 437 jio_snprintf(_file_name, strlen(file_name)+10, "%s.%d", file_name, _cur_file_num);
438 _file = fopen(_file_name, "w"); 438 _file = fopen(_file_name, "w");
439 _need_close = true; 439 _need_close = true;
440 } 440 }
441 441
442 rotatingFileStream::rotatingFileStream(const char* file_name, const char* opentype) { 442 rotatingFileStream::rotatingFileStream(const char* file_name, const char* opentype) {
443 _cur_file_num = 0; 443 _cur_file_num = 0;
444 _bytes_writen = 0L; 444 _bytes_written = 0L;
445 _file_name = NEW_C_HEAP_ARRAY(char, strlen(file_name)+10, mtInternal); 445 _file_name = NEW_C_HEAP_ARRAY(char, strlen(file_name)+10, mtInternal);
446 jio_snprintf(_file_name, strlen(file_name)+10, "%s.%d", file_name, _cur_file_num); 446 jio_snprintf(_file_name, strlen(file_name)+10, "%s.%d", file_name, _cur_file_num);
447 _file = fopen(_file_name, opentype); 447 _file = fopen(_file_name, opentype);
448 _need_close = true; 448 _need_close = true;
449 } 449 }
450 450
451 void rotatingFileStream::write(const char* s, size_t len) { 451 void rotatingFileStream::write(const char* s, size_t len) {
452 if (_file != NULL) { 452 if (_file != NULL) {
453 // Make an unused local variable to avoid warning from gcc 4.x compiler.
454 size_t count = fwrite(s, 1, len, _file); 453 size_t count = fwrite(s, 1, len, _file);
455 Atomic::add((jlong)count, &_bytes_writen); 454 _bytes_written += count;
456 } 455 }
457 update_position(s, len); 456 update_position(s, len);
458 } 457 }
459 458
460 // rotate_log must be called from VMThread at safepoint. In case need change parameters 459 // rotate_log must be called from VMThread at safepoint. In case need change parameters
464 // That is, no mutator threads and concurrent GC threads run parallel with VMThread to 463 // That is, no mutator threads and concurrent GC threads run parallel with VMThread to
465 // write to gc log file at safepoint. If in future, changes made for mutator threads or 464 // write to gc log file at safepoint. If in future, changes made for mutator threads or
466 // concurrent GC threads to run parallel with VMThread at safepoint, write and rotate_log 465 // concurrent GC threads to run parallel with VMThread at safepoint, write and rotate_log
467 // must be synchronized. 466 // must be synchronized.
468 void rotatingFileStream::rotate_log() { 467 void rotatingFileStream::rotate_log() {
469 if (_bytes_writen < (jlong)GCLogFileSize) return; 468 if (_bytes_written < (jlong)GCLogFileSize) {
469 return;
470 }
471
470 #ifdef ASSERT 472 #ifdef ASSERT
471 Thread *thread = Thread::current(); 473 Thread *thread = Thread::current();
472 assert(thread == NULL || 474 assert(thread == NULL ||
473 (thread->is_VM_thread() && SafepointSynchronize::is_at_safepoint()), 475 (thread->is_VM_thread() && SafepointSynchronize::is_at_safepoint()),
474 "Must be VMThread at safepoint"); 476 "Must be VMThread at safepoint");
475 #endif 477 #endif
476 if (NumberOfGCLogFiles == 1) { 478 if (NumberOfGCLogFiles == 1) {
477 // rotate in same file 479 // rotate in same file
478 rewind(); 480 rewind();
479 _bytes_writen = 0L; 481 _bytes_written = 0L;
480 return; 482 return;
481 } 483 }
482 484
483 // rotate file in names file.0, file.1, file.2, ..., file.<MaxGCLogFileNumbers-1> 485 // rotate file in names file.0, file.1, file.2, ..., file.<MaxGCLogFileNumbers-1>
484 // close current file, rotate to next file 486 // close current file, rotate to next file
490 fclose(_file); 492 fclose(_file);
491 _file = NULL; 493 _file = NULL;
492 } 494 }
493 _file = fopen(_file_name, "w"); 495 _file = fopen(_file_name, "w");
494 if (_file != NULL) { 496 if (_file != NULL) {
495 _bytes_writen = 0L; 497 _bytes_written = 0L;
496 _need_close = true; 498 _need_close = true;
497 } else { 499 } else {
498 tty->print_cr("failed to open rotation log file %s due to %s\n", 500 tty->print_cr("failed to open rotation log file %s due to %s\n",
499 _file_name, strerror(errno)); 501 _file_name, strerror(errno));
500 _need_close = false; 502 _need_close = false;