Re: 8198888: Reduce string allocation churninInvokerBytecodeGenerator

2018-03-01 Thread mandy chung



On 3/1/18 12:56 PM, Claes Redestad wrote:


yes, for the startup metrics I'm concerned with then a single element 
implementation is even ever so slightly better:


http://cr.openjdk.java.net/~redestad/819/jdk.01/

Looks good to me.

Mandy


Re: 8198888: Reduce string allocation churninInvokerBytecodeGenerator

2018-03-01 Thread Claes Redestad

Hi,

On 2018-03-01 20:45, Bernd Eckenfels wrote:

Cool, the lastClass varient then is pretty tempting (and I wont fix the 
multi-slot Version below, it misses a „lastUsedSlot“ field)


yes, for the startup metrics I'm concerned with then a single element 
implementation is even ever so slightly better:


http://cr.openjdk.java.net/~redestad/819/jdk.01/



Unrelated to this patch I feel that unifying internal names and external names 
will be a hard task, so Class#getInternalName() looks temting for a lot of 
similiar usecases mid term.


See Paul's replies elsewhere in this thread about ongoing work on a 
symbolic ref API, which may end up allowing us to express these things 
without having to go via smelly string representations.


/Claes


Re: 8198888: Reduce string allocation churninInvokerBytecodeGenerator

2018-03-01 Thread Bernd Eckenfels
Cool, the lastClass varient then is pretty tempting (and I wont fix the 
multi-slot Version below, it misses a „lastUsedSlot“ field)

Unrelated to this patch I feel that unifying internal names and external names 
will be a hard task, so Class#getInternalName() looks temting for a lot of 
similiar usecases mid term.

Gruss
Bernd
-- 
http://bernd.eckenfels.net

Von: Claes Redestad
Gesendet: Donnerstag, 1. März 2018 20:05
An: core-libs-dev@openjdk.java.net; e...@zusammenkunft.net
Betreff: Re: 819: Reduce string allocation churninInvokerBytecodeGenerator

Hi Bernd,

to dispel your concerns about keeping references to classes then 
InvokerBytecodeGenerators are shortlived and go out of scope after 
they've been used to generate an invoker (or LF) class, so the impl. 
here should be safe from a class leak perspective. A static cache is 
tempting, but would then of course require the use of weak (or soft) 
references and a concurrent collection, which might make it cost more 
than it'd save us.

It does seem the typical answer for the number of entries that get put 
into each generator's cache is exactly one, so a single entry cache 
isn't an unreasonable alternative here.

/Claes

On 2018-03-01 19:39, Bernd Eckenfels wrote:
> +if (nameMap == null) {
> +nameMap = new HashMap<>(2);
>
> What is the typical size the map ends up with? If it stays this small 
> linearly searching an Array (or „last value“) may be faster.
>
> If the map typically grows more than a few entries having some more initial 
> buckets will decrease collissions and avoid resizes. Especially considering 
> the fact that HashMap is a rather fat object, it does not hurt to start with 
> a bigger initial table. Does the lazy initialisation actually help anything?
>
> Single entry alternative
> 
> Object lastClass; String lastName;
>
> If (lastClass == c)
>return lastName;
> lastClass = c;
> lastName = c.getName().replace(‘.‘, ‘/‘);
> return lastName;
>
> (or make it a x Slot Version…):
> ---
> Object tab_obj = new tab_obj[8];
> String tab_val = new String[8];
>
> for(int i=0; i < tab_obj.length; i++)
> {
>If (tab_obj[i] == c);
>  return tab_val[i];
> }
> i = (i+1 % tab_obj.length);
> tab_obj[i] = c;
> return (tab_val[i] = c.getName().replace());
>
> (not sure about the concurrent semantics and having this static may actually 
> help)
>
> Gruss
> Bernd