DESCRIPTION

tmf: Make TmfLocation and CtfLocation immutable

Make CtfLocation extend TmfLocation directly (saves a bit
of redundant code), and remove its .setLocation() method.

The fLocation field is now final, and can only be set at the
constructor. When seeking to different locations, a new Location
object is created instead of modifying the existing one
(while this is not the case with C for example, in Java it's
usually faster to do it this way).

TmfLocation.clone() has been simplified to do a shallow copy
of it's fLocation object. This is safe as long as the fLocation
is immutable. The only class that is currently used
(CtfLocationData) is indeed immutable.

Change-Id: I79bd28df682da830af6f5409d8e71a50225c662a
Signed-off-by: Braxton Mccarthy xxx@xxx.xxx


COMMENTS

author: Braxton Mccarthy
date: 2012-08-14 21:06:28.000000000

Patch Set 1:

Note, this probably breaks the legacy plugins too, so it should only be merged after the legacy LTTng support has been dropped from the branch.

-------------------------------------
author: Ricky Reeves
date: 2012-08-15 14:10:07.000000000

Patch Set 1: I would prefer that you didn't submit this

(2 inline comments)

I don't agree with the the shallow copy in TmfLocation.clone() and CtfLocation.clone() (see comments).

However, I like the initiative to simplify CtfLocation.

Line:77, lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java -> I'm not sure that a shallow copy is enough. Even if the member fLocation is final, it doesn't mean that some other class can have a handle on this object and modify it. So purpose of clone is to create a deep copy with a copy of fLocation.

Line:83, lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java -> I'm not sure that a shallow copy is enough. Some other class could have a reference to fLocation and could be modifying it. For clone a deep copy is needed.

-------------------------------------
author: Braxton Mccarthy
date: 2012-08-15 14:28:45.000000000

Patch Set 1:

If the field is immutable (which means its contents cannot be modified, like Strings), a shallow copy is safe.

In the case of a CtfLocation, the field type CtfLocationData is immutable. Its two fields are final. So another object having a pointer to the same object could not modify it, they'd have to create a new one.

Although for TmfLocation, I agree there is no guarantee. We do not control all possible implementations, like with CtfLocation. I did add a comment in the Javadoc description, but it's probably not enough.

I will re-spin the patch to do a deep-copy in TmfLocation. But I still think we can do a shallow-copy in CtfLocation, since we control CtfLocationData and we know it's immutable, and it'd be faster to do so.

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