@@ -991,16 +991,6 @@ bufferedStream::bufferedStream(size_t initial_size, size_t bufmax) : outputStrea
991991 buffer_length = initial_size;
992992 buffer = NEW_C_HEAP_ARRAY (char , buffer_length, mtInternal);
993993 buffer_pos = 0 ;
994- buffer_fixed = false ;
995- buffer_max = bufmax;
996- truncated = false ;
997- }
998-
999- bufferedStream::bufferedStream (char * fixed_buffer, size_t fixed_buffer_size, size_t bufmax) : outputStream() {
1000- buffer_length = fixed_buffer_size;
1001- buffer = fixed_buffer;
1002- buffer_pos = 0 ;
1003- buffer_fixed = true ;
1004994 buffer_max = bufmax;
1005995 truncated = false ;
1006996}
@@ -1017,39 +1007,33 @@ void bufferedStream::write(const char* s, size_t len) {
10171007
10181008 size_t end = buffer_pos + len;
10191009 if (end >= buffer_length) {
1020- if (buffer_fixed) {
1021- // if buffer cannot resize, silently truncate
1022- len = buffer_length - buffer_pos - 1 ;
1023- truncated = true ;
1024- } else {
1025- // For small overruns, double the buffer. For larger ones,
1026- // increase to the requested size.
1027- if (end < buffer_length * 2 ) {
1028- end = buffer_length * 2 ;
1029- }
1030- // Impose a cap beyond which the buffer cannot grow - a size which
1031- // in all probability indicates a real error, e.g. faulty printing
1032- // code looping, while not affecting cases of just-very-large-but-its-normal
1033- // output.
1034- const size_t reasonable_cap = MAX2 (100 * M, buffer_max * 2 );
1035- if (end > reasonable_cap) {
1036- // In debug VM, assert right away.
1037- assert (false , " Exceeded max buffer size for this string." );
1038- // Release VM: silently truncate. We do this since these kind of errors
1039- // are both difficult to predict with testing (depending on logging content)
1040- // and usually not serious enough to kill a production VM for it.
1041- end = reasonable_cap;
1042- size_t remaining = end - buffer_pos;
1043- if (len >= remaining) {
1044- len = remaining - 1 ;
1045- truncated = true ;
1046- }
1047- }
1048- if (buffer_length < end) {
1049- buffer = REALLOC_C_HEAP_ARRAY (char , buffer, end, mtInternal);
1050- buffer_length = end;
1010+ // For small overruns, double the buffer. For larger ones,
1011+ // increase to the requested size.
1012+ if (end < buffer_length * 2 ) {
1013+ end = buffer_length * 2 ;
1014+ }
1015+ // Impose a cap beyond which the buffer cannot grow - a size which
1016+ // in all probability indicates a real error, e.g. faulty printing
1017+ // code looping, while not affecting cases of just-very-large-but-its-normal
1018+ // output.
1019+ const size_t reasonable_cap = MAX2 (100 * M, buffer_max * 2 );
1020+ if (end > reasonable_cap) {
1021+ // In debug VM, assert right away.
1022+ assert (false , " Exceeded max buffer size for this string." );
1023+ // Release VM: silently truncate. We do this since these kind of errors
1024+ // are both difficult to predict with testing (depending on logging content)
1025+ // and usually not serious enough to kill a production VM for it.
1026+ end = reasonable_cap;
1027+ size_t remaining = end - buffer_pos;
1028+ if (len >= remaining) {
1029+ len = remaining - 1 ;
1030+ truncated = true ;
10511031 }
10521032 }
1033+ if (buffer_length < end) {
1034+ buffer = REALLOC_C_HEAP_ARRAY (char , buffer, end, mtInternal);
1035+ buffer_length = end;
1036+ }
10531037 }
10541038 if (len > 0 ) {
10551039 memcpy (buffer + buffer_pos, s, len);
@@ -1066,9 +1050,7 @@ char* bufferedStream::as_string() {
10661050}
10671051
10681052bufferedStream::~bufferedStream () {
1069- if (!buffer_fixed) {
1070- FREE_C_HEAP_ARRAY (char , buffer);
1071- }
1053+ FREE_C_HEAP_ARRAY (char , buffer);
10721054}
10731055
10741056#ifndef PRODUCT
0 commit comments