# HG changeset patch # User goetz # Date 1457297413 18000 # Node ID 9608a7830fe9137816958833de853d7e97f7530b # Parent 3bc27d7f3e758728811112c998a43883fe685137 8149557: Resource mark breaks printing to string stream Reviewed-by: stuefe, dholmes diff -r 3bc27d7f3e75 -r 9608a7830fe9 hotspot/src/share/vm/oops/symbol.cpp --- a/hotspot/src/share/vm/oops/symbol.cpp Thu Mar 03 17:33:13 2016 +0000 +++ b/hotspot/src/share/vm/oops/symbol.cpp Sun Mar 06 15:50:13 2016 -0500 @@ -158,9 +158,21 @@ } void Symbol::print_symbol_on(outputStream* st) const { - ResourceMark rm; + char *s; st = st ? st : tty; - st->print("%s", as_quoted_ascii()); + { + // ResourceMark may not affect st->print(). If st is a string + // stream it could resize, using the same resource arena. + ResourceMark rm; + s = as_quoted_ascii(); + s = os::strdup(s); + } + if (s == NULL) { + st->print("(null)"); + } else { + st->print("%s", s); + os::free(s); + } } char* Symbol::as_quoted_ascii() const { diff -r 3bc27d7f3e75 -r 9608a7830fe9 hotspot/src/share/vm/utilities/ostream.cpp --- a/hotspot/src/share/vm/utilities/ostream.cpp Thu Mar 03 17:33:13 2016 +0000 +++ b/hotspot/src/share/vm/utilities/ostream.cpp Sun Mar 06 15:50:13 2016 -0500 @@ -338,7 +338,9 @@ } char* oldbuf = buffer; assert(rm == NULL || Thread::current()->current_resource_mark() == rm, - "stringStream is re-allocated with a different ResourceMark"); + "StringStream is re-allocated with a different ResourceMark. Current: " + PTR_FORMAT " original: " PTR_FORMAT, + p2i(Thread::current()->current_resource_mark()), p2i(rm)); buffer = NEW_RESOURCE_ARRAY(char, end); if (buffer_pos > 0) { memcpy(buffer, oldbuf, buffer_pos);