# HG changeset patch # User goetz # Date 1455119655 -3600 # Node ID 1c38e2346179dde6317d9aa45f2a88d363f2ca02 # Parent e3e5642da773c6851718796c611da8f92e2a324b 8149557: Resource mark breaks printing to string stream diff --git a/src/share/vm/oops/symbol.cpp b/src/share/vm/oops/symbol.cpp --- a/src/share/vm/oops/symbol.cpp +++ b/src/share/vm/oops/symbol.cpp @@ -158,9 +158,17 @@ } 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); + } + st->print("%s", s); + os::free(s); } char* Symbol::as_quoted_ascii() const { diff --git a/src/share/vm/utilities/ostream.cpp b/src/share/vm/utilities/ostream.cpp --- a/src/share/vm/utilities/ostream.cpp +++ b/src/share/vm/utilities/ostream.cpp @@ -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);