DESCRIPTION

tmf: Implement a cache of TmfStateValue.

This patch provides a caching implementation in the TmfStateValue factory.
TmfStateValue are immutable and can be shared.

By chaging the size of the cache, we obsersed this cache ratio.

size         hit      total     ratio
  2 count:  7369956/15551000 [0.4739216770625683]
  4 count: 11742495/15530000 [0.7561168705730843]
  8 count: 14622383/15545000 [0.9406486330009649]
 16 count: 15007948/15552000 [0.965017232510288]
 32 count: 15372868/15543000 [0.9890541079585665]
 64 count: 15432506/15523000 [0.9941703279005347]
128 count: 15488720/15534000 [0.9970851036436205]

Which seems to be an excellent ratio for a really small cache.
The same idea is used with Integer.valueOf(...).

Change-Id: I3701b900035d83b19531101ab60e7292899d8cef
Signed-off-by: Jordon Obrien xxx@xxx.xxx


COMMENTS

author: Jordon Obrien
date: 2013-11-28 05:33:59.000000000

Patch Set 1:

For a 128 entries cache, instead of allocating 15,488,720 object, we only allocate 45,280.
The metrics seems too good to be real.
Where's my mistake?

I take a look to numbers on a lltng trace and there is a lot of <0, 1, 2, 3>.

I didn't take care of synchronization. I don't know if this cache can be accessed by multiple thread. But, still I think it's valid with the java memory model.

-------------------------------------
author: Brenden Conley
date: 2013-11-28 08:53:01.000000000

Patch Set 1:

Build Started https://hudson.eclipse.org/linuxtools/job/linuxtools-gerrit/4264/

-------------------------------------
author: Brenden Conley
date: 2013-11-28 09:23:15.000000000

Patch Set 1: Verified+1

Build Successful 

https://hudson.eclipse.org/linuxtools/job/linuxtools-gerrit/4264/ : SUCCESS

-------------------------------------
author: Braxton Mccarthy
date: 2013-11-28 19:20:40.000000000

Patch Set 1: Code-Review-1

(3 comments)

Interesting idea! I'm not sure if the JVM already did some caching due to the final/immutable objects, but for our particular uses cases this could definitely help (as you mentioned, the values we use are usually quite limited, e.g. lttng2.kernel.core.StateValues)

Small comments, also it will have to be rebased once https://git.eclipse.org/r/#/c/19027/ is in.

Line:47, lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java -> "private static final"

Line:115, lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java -> spaces before and after -

you can use Ctrl+Shift+F to auto-format the selection (or the whole file if there is no selection)

Line:122, lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java -> C/C++ programmer identified!

Java standard is to use camelCase, so call this newValue.

-------------------------------------
author: Braxton Mccarthy
date: 2013-11-28 19:21:31.000000000

Patch Set 1:

(1 comment)

Line:12, /COMMIT_MSG -> changing, observed

-------------------------------------
author: Jordon Obrien
date: 2013-11-28 19:24:52.000000000

Patch Set 1:

I don't think the JVM optimize this case.
It could be an idea to look at the memory consumption.

And, btw, this can also be done for "Long" and "String".
I expect a bigger cache for the string.

I just throw an idea.

For the int, I believe a cache from -128 to 127 could be a good idea, + a small cache for other values. More benchmarks should be done.

-------------------------------------
author: Jordon Obrien
date: 2013-11-28 19:31:57.000000000

Patch Set 1:

I check in the manual, for the intern documentation:

"Java won't do this for your own immutable objects. "

So, I think you could not rely on it.

-------------------------------------
author: Jordon Obrien
date: 2013-11-28 19:35:39.000000000

Patch Set 1:

(4 comments)

Thank Alex.
I'll take care of that tonight.
I'll add a cache for Long and String too.
I wanted to share my observation.

Line:12, /COMMIT_MSG -> oups, 2am

Line:47, lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java -> strange, I copy paste this snippet from eclipse code base.

Line:115, lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java -> yep, I missed this one. I know the rule.
Will fix.

Line:122, lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java -> I'm a C, C++, Java, Scheme, Ruby, Perl, ... I'm having hard time with all those "coding-style". ;p~
You know the name for this_kind_of_naming?
Snake style.

-------------------------------------
author: Braxton Mccarthy
date: 2013-11-28 20:22:03.000000000

Patch Set 1:

(2 comments)

Line:47, lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java -> Eclipse code is relatively ugly in general ;)

The standard order from the JLS is [public|private|protected] [abstract|static] [final] [synchronized] [native]. Sonar actually complains if it's not like that.

Line:122, lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java -> Another nomenclature I like is {
   Egyptian brackets
}

-------------------------------------
