Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Java 1.8 and ExtendProperties
Java 1.8 and ExtendProperties [message #1744671] Thu, 29 September 2016 11:57 Go to next message
Sebastian Zitzelsberger is currently offline Sebastian ZitzelsbergerFriend
Messages: 33
Registered: August 2014
Member
Hi Epsilon Team,

I am currently evaluating whether i can use epsilon in a java standalone application while using a java 1.8 jdk as a runtime environment.

I found out that everything seems to be working fine, except the extendedProperties.
I am using ExtendProperties rather excessivley ( > 400k set properties in total) and everything is fine while using a 1.7 jdk.

When using java 1.8 however, your Cache implementation in the ExtendedProperties returns wrong properties for certain objects if the number of properties exceeds a certain (unknown) limit.

I have attached a minimal example that shows the effect.
I have a simple model with 300k entities.
Each entity has a single attribute, that is unique accross the model.
I set an extended Property for the first 150k that is a copy of that attribute and perform a check afterwards that prints all entities (within the first 150k) to the console whose extendedProperty value does not equal the attribute value.
The list is empty when using java 1.7 (as expected) but contains 4 entries when using java 1.8.


My first guesses are that something must have changed regarding java garbage collection ( you are using weak references in your Cache implementation) or regarding your hashCode generation ( see your IdentityBasedWeakReference Implementation).

When using my own implementation of your ExtendedProperties class that uses this collection
protected LinkedHashMap<Object, LinkedHashMap<String, Object>> properties = new LinkedHashMap<Object, LinkedHashMap<String, Object>>();

instead of your Cache implementation, i get the correct extended Properties in java 1.7 and java 1.8.

Can you please check the example and explain the use of your Cache Implementation?

Greetings
Sebastian

[Updated on: Thu, 29 September 2016 11:59]

Report message to a moderator

Re: Java 1.8 and ExtendProperties [message #1744970 is a reply to message #1744671] Mon, 03 October 2016 15:02 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

Sorry for the delay: Dimitris and I are currently away on a conference, so we are a bit busy. I have indeed confirmed your issue on my machine with JDK7 and JDK8. It is quite puzzling: we'll be definitely researching this as soon as possible. I have seen a similar problem with this style of cache on other open source systems in JDK8 (e.g. OrientDB).

Essentially, the cache uses weak references so we can reclaim memory as soon as we stop referring to the cached values. The cache uses object identity hashcodes as keys, which we assumed to be unique within a run of the JVM for practical reasons. It feels as if this assumption was no longer 100% true in JDK8: we will have to review this bit and fix the issue once we've found a good fix. Stay tuned Smile.

[Updated on: Mon, 03 October 2016 15:25]

Report message to a moderator

Re: Java 1.8 and ExtendProperties [message #1744972 is a reply to message #1744970] Mon, 03 October 2016 15:07 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

Some quick Googling shows Java 8 has a different hashCode() implementation for better threading performance, at the expense of more chances of twins:

http://www.javaspecialists.eu/archive/Issue222.html

Yeesh. This requires research!
Re: Java 1.8 and ExtendProperties [message #1744990 is a reply to message #1744972] Mon, 03 October 2016 20:36 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

We've reproduced the issue with an acceptance test case, filed the issue and pushed an initial fix:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=503152

We're waiting for Hudson [1] to confirm that everything is fine and refresh the interim standalone JARs. It should be ready in an hour or two, if everything goes well.

[1]: https://hudson.eclipse.org/epsilon/job/epsilon-interim-update-site/
Re: Java 1.8 and ExtendProperties [message #1745004 is a reply to message #1744990] Tue, 04 October 2016 07:05 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

The fix is now live. Please try the latest interim JARs (these will become 1.4 very soon) and let us know how it goes.

Re: Java 1.8 and ExtendProperties [message #1745020 is a reply to message #1745004] Tue, 04 October 2016 09:19 Go to previous messageGo to next message
Sebastian Zitzelsberger is currently offline Sebastian ZitzelsbergerFriend
Messages: 33
Registered: August 2014
Member
Hi Antonio,

Thank your for your analysis and the fix.

I tried out my example with the jars from the interim site and your fix seems to be working.

However i don't quite get why my solution with the LinkedHashMap worked with 1.8 as it should use the Object's hashCode() Method as well.

Your IdentityBasedWeakReference Implemenation forced the use of the default hashcode() Implementation with System.identityHashCode(Object).
But shouldn't that be same Method in my example as there is no hashCode() -Implementation within the ecore Framework. and we only set extended properties for Eobjects.

Quote:
The framework also assumes that implementations will not specialize {@link #equals(Object)} (nor {@link #hashCode()})
* so that "<code>==</code>" can be always used for equality testing;


Anyway thanks for the fix and do you have a schedule for the release of epsilon 1.4?
Re: Java 1.8 and ExtendProperties [message #1745040 is a reply to message #1745020] Tue, 04 October 2016 12:24 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

You're right: EObject uses the default hashCode, hmm. (We force this anyway because Epsilon with more things than just EMF, anyway.)

It might be because LinkedHashMap uses the hashCode() plus the equals() method: the hashCode is used to go to a bucket and then it loops through the linked elements in the bucket testing with equals. At least, this is what the JDK8 source code suggests:

    final Node<K,V> getNode(int hash, Object key) {
        Node<K,V>[] tab; Node<K,V> first, e; int n; K k;
        if ((tab = table) != null && (n = tab.length) > 0 &&
            (first = tab[(n - 1) & hash]) != null) {
            if (first.hash == hash && // always check first node
                ((k = first.key) == key || (key != null && key.equals(k))))
                return first;
            if ((e = first.next) != null) {
                if (first instanceof TreeNode)
                    return ((TreeNode<K,V>)first).getTreeNode(hash, key);
                do {
                    if (e.hash == hash &&
                        ((k = e.key) == key || (key != null && key.equals(k))))
                        return e;
                } while ((e = e.next) != null);
            }
        }
        return null;
    }


So in this case, the issue might have been in our IdentityBasedWeakReference wrapper, which originally implemented equals(...) as hashCode() == other.hashCode(). I'm pretty sure I tried replacing it with direct object comprison and it didn't help, but I'll look again into it. Perhaps the fix was easier than I thought Smile.

As for Epsilon 1.4, it's coming soon: the release review is underway. Hopefully it should be ready within October.
Re: Java 1.8 and ExtendProperties [message #1745042 is a reply to message #1745040] Tue, 04 October 2016 12:40 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

Well, actually that was the issue (the equals() method of IdentityBasedWeakReference). I have reverted the first fix I tried (which required Guava) and pushed this other fix.

Again, it'll be live in an hour or two: please try it out when you can and re-confirm. Thanks for the helpful discussion Smile.
Re: Java 1.8 and ExtendProperties [message #1745407 is a reply to message #1745042] Mon, 10 October 2016 12:14 Go to previous messageGo to next message
Sebastian Zitzelsberger is currently offline Sebastian ZitzelsbergerFriend
Messages: 33
Registered: August 2014
Member
I retested it with the lastest interim version and get the same results as with the previous fix.
Re: Java 1.8 and ExtendProperties [message #1745409 is a reply to message #1745407] Mon, 10 October 2016 12:32 Go to previous message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

Thank you for your help! Case closed then.
Previous Topic:How to move the containment's in ETL ?
Next Topic:problem with text file when opening the ecore as text file
Goto Forum:
  


Current Time: Thu Apr 18 23:26:38 GMT 2024

Powered by FUDForum. Page generated in 0.02807 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top