RFR(S): 8149557: Resource mark breaks printing to string stream

Lindenmaier, Goetz goetz.lindenmaier at sap.com
Thu Feb 11 11:35:54 UTC 2016


Hi Volker,

thanks for your hint, but this is a utility function far down 
and I don't have the allocation of the stream at hand.
I just know it's an outputStream (not a stringStream).
I meant I would need st->assure_capacity(xy) for outputStream.

Best regards,
  Goetz.

> -----Original Message-----.
> From: Volker Simonis [mailto:volker.simonis at gmail.com]
> Sent: Donnerstag, 11. Februar 2016 12:22
> To: Lindenmaier, Goetz <goetz.lindenmaier at sap.com>
> Cc: hotspot-runtime-dev at openjdk.java.net
> Subject: Re: RFR(S): 8149557: Resource mark breaks printing to string stream
> 
> Hi Goetz,
> 
> maybe you could use something similar to the following code (from
> disassembleCodeBlob() in jvmciCompilerToVM) to fix the problem:
> 
>   // We don't want the stringStream buffer to resize during disassembly as it
>   // uses scoped resource memory. If a nested function called during
> disassembly uses
>   // a ResourceMark and the buffer expands within the scope of the mark,
>   // the buffer becomes garbage when that scope is exited. Experience
> shows that
>   // the disassembled code is typically about 10x the code size so a
> fixed buffer
>   // sized to 20x code size plus a fixed amount for header info should
> be sufficient.
>   int bufferSize = cb->code_size() * 20 + 1024;
>   char* buffer = NEW_RESOURCE_ARRAY(char, bufferSize);
>   stringStream st(buffer, bufferSize);
> 
> Regards,
> Volker
> 
> 
> On Thu, Feb 11, 2016 at 9:24 AM, Lindenmaier, Goetz
> <goetz.lindenmaier at sap.com> wrote:
> > Hi
> >
> > Please review this change. I please need a sponsor.
> > http://cr.openjdk.java.net/~goetz/wr16/8149557-ResMrk/webrev.01/
> >
> > If a stringStream is passed to Symbol::print_symbol_on(),
> > assertion "stringStream is re-allocated with a different ResourceMark." can
> fire in stringStream::write(const char* s, size_t len).
> > This can be verified by running TestLogTouchedMethods.java after adding
> the patch below to the VM.
> >
> > My fix copies the string to locally managed memory before popping the
> ResoreceMark.
> > A better solution would be to guarantee enough space on the stream
> > before doing the resource mark, but outputStream has no such
> > method as 'ensureCapacity' or the like.
> > Alternatively the ResourceMark could be skipped altogether.
> > But then the aux memory used remains on the ResourceArea too long.
> > Also, various ResourceMarks have to be added in other places.
> >
> > Best regards,
> >   Goetz.
> >
> >
> > --- a/src/share/vm/runtime/java.cpp     Wed Jan 13 11:33:21 2016 +0100
> > +++ b/src/share/vm/runtime/java.cpp     Wed Feb 10 08:56:14 2016 +0100
> > @@ -340,7 +340,10 @@
> >    }
> >
> >    if (LogTouchedMethods && PrintTouchedMethodsAtExit) {
> > -    Method::print_touched_methods(tty);
> > +    ResourceMark rm;
> > +    stringStream st(16);
> > +    Method::print_touched_methods(&st);
> > +    tty->print("%s", st.as_string());
> >    }
> >
> >    if (PrintBiasedLockingStatistics) {


More information about the hotspot-runtime-dev mailing list