comparison src/share/vm/utilities/ostream.cpp @ 6197:d2a62e0f25eb

6995781: Native Memory Tracking (Phase 1) 7151532: DCmd for hotspot native memory tracking Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd Reviewed-by: acorn, coleenp, fparain
author zgu
date Thu, 28 Jun 2012 17:03:16 -0400
parents 11c26bfcf8c7
children 957c266d8bc5 4ee06e614636
comparison
equal deleted inserted replaced
6174:74533f63b116 6197:d2a62e0f25eb
382 382
383 rotatingFileStream::~rotatingFileStream() { 383 rotatingFileStream::~rotatingFileStream() {
384 if (_file != NULL) { 384 if (_file != NULL) {
385 if (_need_close) fclose(_file); 385 if (_need_close) fclose(_file);
386 _file = NULL; 386 _file = NULL;
387 FREE_C_HEAP_ARRAY(char, _file_name); 387 FREE_C_HEAP_ARRAY(char, _file_name, mtInternal);
388 _file_name = NULL; 388 _file_name = NULL;
389 } 389 }
390 } 390 }
391 391
392 rotatingFileStream::rotatingFileStream(const char* file_name) { 392 rotatingFileStream::rotatingFileStream(const char* file_name) {
393 _cur_file_num = 0; 393 _cur_file_num = 0;
394 _bytes_writen = 0L; 394 _bytes_writen = 0L;
395 _file_name = NEW_C_HEAP_ARRAY(char, strlen(file_name)+10); 395 _file_name = NEW_C_HEAP_ARRAY(char, strlen(file_name)+10, mtInternal);
396 jio_snprintf(_file_name, strlen(file_name)+10, "%s.%d", file_name, _cur_file_num); 396 jio_snprintf(_file_name, strlen(file_name)+10, "%s.%d", file_name, _cur_file_num);
397 _file = fopen(_file_name, "w"); 397 _file = fopen(_file_name, "w");
398 _need_close = true; 398 _need_close = true;
399 } 399 }
400 400
401 rotatingFileStream::rotatingFileStream(const char* file_name, const char* opentype) { 401 rotatingFileStream::rotatingFileStream(const char* file_name, const char* opentype) {
402 _cur_file_num = 0; 402 _cur_file_num = 0;
403 _bytes_writen = 0L; 403 _bytes_writen = 0L;
404 _file_name = NEW_C_HEAP_ARRAY(char, strlen(file_name)+10); 404 _file_name = NEW_C_HEAP_ARRAY(char, strlen(file_name)+10, mtInternal);
405 jio_snprintf(_file_name, strlen(file_name)+10, "%s.%d", file_name, _cur_file_num); 405 jio_snprintf(_file_name, strlen(file_name)+10, "%s.%d", file_name, _cur_file_num);
406 _file = fopen(_file_name, opentype); 406 _file = fopen(_file_name, opentype);
407 _need_close = true; 407 _need_close = true;
408 } 408 }
409 409
522 jio_snprintf(pid, sizeof(pid), "%u", os::current_process_id()); 522 jio_snprintf(pid, sizeof(pid), "%u", os::current_process_id());
523 buffer_length += strlen(pid); 523 buffer_length += strlen(pid);
524 } 524 }
525 525
526 // Create big enough buffer. 526 // Create big enough buffer.
527 char *buf = NEW_C_HEAP_ARRAY(char, buffer_length); 527 char *buf = NEW_C_HEAP_ARRAY(char, buffer_length, mtInternal);
528 528
529 strcpy(buf, ""); 529 strcpy(buf, "");
530 if (force_directory != NULL) { 530 if (force_directory != NULL) {
531 strcat(buf, force_directory); 531 strcat(buf, force_directory);
532 strcat(buf, os::file_separator()); 532 strcat(buf, os::file_separator());
547 547
548 void defaultStream::init_log() { 548 void defaultStream::init_log() {
549 // %%% Need a MutexLocker? 549 // %%% Need a MutexLocker?
550 const char* log_name = LogFile != NULL ? LogFile : "hotspot.log"; 550 const char* log_name = LogFile != NULL ? LogFile : "hotspot.log";
551 const char* try_name = make_log_name(log_name, NULL); 551 const char* try_name = make_log_name(log_name, NULL);
552 fileStream* file = new(ResourceObj::C_HEAP) fileStream(try_name); 552 fileStream* file = new(ResourceObj::C_HEAP, mtInternal) fileStream(try_name);
553 if (!file->is_open()) { 553 if (!file->is_open()) {
554 // Try again to open the file. 554 // Try again to open the file.
555 char warnbuf[O_BUFLEN*2]; 555 char warnbuf[O_BUFLEN*2];
556 jio_snprintf(warnbuf, sizeof(warnbuf), 556 jio_snprintf(warnbuf, sizeof(warnbuf),
557 "Warning: Cannot open log file: %s\n", try_name); 557 "Warning: Cannot open log file: %s\n", try_name);
558 // Note: This feature is for maintainer use only. No need for L10N. 558 // Note: This feature is for maintainer use only. No need for L10N.
559 jio_print(warnbuf); 559 jio_print(warnbuf);
560 FREE_C_HEAP_ARRAY(char, try_name); 560 FREE_C_HEAP_ARRAY(char, try_name, mtInternal);
561 try_name = make_log_name("hs_pid%p.log", os::get_temp_directory()); 561 try_name = make_log_name("hs_pid%p.log", os::get_temp_directory());
562 jio_snprintf(warnbuf, sizeof(warnbuf), 562 jio_snprintf(warnbuf, sizeof(warnbuf),
563 "Warning: Forcing option -XX:LogFile=%s\n", try_name); 563 "Warning: Forcing option -XX:LogFile=%s\n", try_name);
564 jio_print(warnbuf); 564 jio_print(warnbuf);
565 delete file; 565 delete file;
566 file = new(ResourceObj::C_HEAP) fileStream(try_name); 566 file = new(ResourceObj::C_HEAP, mtInternal) fileStream(try_name);
567 FREE_C_HEAP_ARRAY(char, try_name); 567 FREE_C_HEAP_ARRAY(char, try_name, mtInternal);
568 } 568 }
569 if (file->is_open()) { 569 if (file->is_open()) {
570 _log_file = file; 570 _log_file = file;
571 xmlStream* xs = new(ResourceObj::C_HEAP) xmlStream(file); 571 xmlStream* xs = new(ResourceObj::C_HEAP, mtInternal) xmlStream(file);
572 _outer_xmlStream = xs; 572 _outer_xmlStream = xs;
573 if (this == tty) xtty = xs; 573 if (this == tty) xtty = xs;
574 // Write XML header. 574 // Write XML header.
575 xs->print_cr("<?xml version='1.0' encoding='UTF-8'?>"); 575 xs->print_cr("<?xml version='1.0' encoding='UTF-8'?>");
576 // (For now, don't bother to issue a DTD for this private format.) 576 // (For now, don't bother to issue a DTD for this private format.)
813 // (else there was no lock to break) 813 // (else there was no lock to break)
814 } 814 }
815 815
816 void ostream_init() { 816 void ostream_init() {
817 if (defaultStream::instance == NULL) { 817 if (defaultStream::instance == NULL) {
818 defaultStream::instance = new(ResourceObj::C_HEAP) defaultStream(); 818 defaultStream::instance = new(ResourceObj::C_HEAP, mtInternal) defaultStream();
819 tty = defaultStream::instance; 819 tty = defaultStream::instance;
820 820
821 // We want to ensure that time stamps in GC logs consider time 0 821 // We want to ensure that time stamps in GC logs consider time 0
822 // the time when the JVM is initialized, not the first time we ask 822 // the time when the JVM is initialized, not the first time we ask
823 // for a time stamp. So, here, we explicitly update the time stamp 823 // for a time stamp. So, here, we explicitly update the time stamp
831 // Note : this must be called AFTER ostream_init() 831 // Note : this must be called AFTER ostream_init()
832 832
833 gclog_or_tty = tty; // default to tty 833 gclog_or_tty = tty; // default to tty
834 if (Arguments::gc_log_filename() != NULL) { 834 if (Arguments::gc_log_filename() != NULL) {
835 fileStream * gclog = UseGCLogFileRotation ? 835 fileStream * gclog = UseGCLogFileRotation ?
836 new(ResourceObj::C_HEAP) 836 new(ResourceObj::C_HEAP, mtInternal)
837 rotatingFileStream(Arguments::gc_log_filename()) : 837 rotatingFileStream(Arguments::gc_log_filename()) :
838 new(ResourceObj::C_HEAP) 838 new(ResourceObj::C_HEAP, mtInternal)
839 fileStream(Arguments::gc_log_filename()); 839 fileStream(Arguments::gc_log_filename());
840 if (gclog->is_open()) { 840 if (gclog->is_open()) {
841 // now we update the time stamp of the GC log to be synced up 841 // now we update the time stamp of the GC log to be synced up
842 // with tty. 842 // with tty.
843 gclog->time_stamp().update_to(tty->time_stamp().ticks()); 843 gclog->time_stamp().update_to(tty->time_stamp().ticks());
938 write(str, len); 938 write(str, len);
939 } 939 }
940 940
941 bufferedStream::bufferedStream(size_t initial_size, size_t bufmax) : outputStream() { 941 bufferedStream::bufferedStream(size_t initial_size, size_t bufmax) : outputStream() {
942 buffer_length = initial_size; 942 buffer_length = initial_size;
943 buffer = NEW_C_HEAP_ARRAY(char, buffer_length); 943 buffer = NEW_C_HEAP_ARRAY(char, buffer_length, mtInternal);
944 buffer_pos = 0; 944 buffer_pos = 0;
945 buffer_fixed = false; 945 buffer_fixed = false;
946 buffer_max = bufmax; 946 buffer_max = bufmax;
947 } 947 }
948 948
969 // For small overruns, double the buffer. For larger ones, 969 // For small overruns, double the buffer. For larger ones,
970 // increase to the requested size. 970 // increase to the requested size.
971 if (end < buffer_length * 2) { 971 if (end < buffer_length * 2) {
972 end = buffer_length * 2; 972 end = buffer_length * 2;
973 } 973 }
974 buffer = REALLOC_C_HEAP_ARRAY(char, buffer, end); 974 buffer = REALLOC_C_HEAP_ARRAY(char, buffer, end, mtInternal);
975 buffer_length = end; 975 buffer_length = end;
976 } 976 }
977 } 977 }
978 memcpy(buffer + buffer_pos, s, len); 978 memcpy(buffer + buffer_pos, s, len);
979 buffer_pos += len; 979 buffer_pos += len;
987 return copy; 987 return copy;
988 } 988 }
989 989
990 bufferedStream::~bufferedStream() { 990 bufferedStream::~bufferedStream() {
991 if (!buffer_fixed) { 991 if (!buffer_fixed) {
992 FREE_C_HEAP_ARRAY(char, buffer); 992 FREE_C_HEAP_ARRAY(char, buffer, mtInternal);
993 } 993 }
994 } 994 }
995 995
996 #ifndef PRODUCT 996 #ifndef PRODUCT
997 997