RFR: 8241837: Cleanup stringStream usage in ObjectSynchronizer

David Holmes david.holmes at oracle.com
Tue Mar 31 00:15:00 UTC 2020


On 31/03/2020 10:03 am, Claes Redestad wrote:
> On 2020-03-31 01:55, David Holmes wrote:
>> Hi Claes,
>>
>> On 31/03/2020 9:02 am, Claes Redestad wrote:
>>> Hi,
>>>
>>> this removes one unused stringStream, and refactors two other
>>> so that they're only defined in the slow path error where they are used:
>>>
>>> http://cr.openjdk.java.net/~redestad/8241837/open.00/
>>
>> Looks good.
> 
> Thanks!
> 
>>
>> Does make me wonder where the ResourceMarks are that should be needed 
>> to use the stringStream ??
> 
> I think you'll find that you only need a RM if you call ss.as_string() -
> the ss itself is allocated on stack and its backing storage malloc'd on
> C heap.

Ah! Usage is more subtle than I thought. There's a modification coming 
in via JEP-371 that allows as_string() to optionally return C-Heap copy 
of internal buffer - for when you need the string to live more 
permanently. That gives three usage patterns:

- use base() when the string can be deleted by the stringStream destructor
- use as_string(false) (default) when you need the string live longer 
than the stringStream, but within an enclosing ResourceMark scope.
- use as_string(true) to get a "permanent" copy (that you have to free)

Cheers,
David

> /Claes
> 
>>
>> Thanks,
>> David
>>
>>> While a very small startup performance gain (removes ~50k instructions
>>> on a Hello World), these stringStreams mallocs on init, which could be
>>> problematic at times in this particular area.
>>>
>>> Thanks!
>>>
>>> /Claes


More information about the hotspot-runtime-dev mailing list