Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » BuddyPolicy dependents are not sorted(classes are loaded from an older Bundle )
BuddyPolicy dependents are not sorted [message #1073092] Wed, 24 July 2013 05:56 Go to next message
Jakob Braeuchi is currently offline Jakob Braeuchi
Messages: 69
Registered: July 2009
Location: Switzerland
Member
hi,

i'm debugging a strange problem with BuddyPolicy.
in my target platform i have 5 version of bundle A (version 1.0.0_xx14 - 1.0.0_xx18). Bundle A is also a registered buddy of Bundle B.

Sometimes when Bundle B requests a class from it's buddy A, the class is loaded from an older version of Bundle A.

after some digging in the classes RegisteredPolicy and DependentPolicy i found that the order of the BundleDesriptors in the variable allDependents is random. Thus the class is loaded from the Bundle A that appears first in the list.

i think that the list allDependents should be sorted by version descending (the method toString() of BundleDescriptor could be used).

what do you think about it ? will the additional sorting cause some performance problems ? or is this simply the wrong place to sort ?

thanks
jakob

Re: BuddyPolicy dependents are not sorted [message #1073261 is a reply to message #1073092] Wed, 24 July 2013 12:23 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas Watson
Messages: 427
Registered: July 2009
Senior Member
I think sorting it will cause a lot of complications to the code without significant changes. allDependents list is initialized with the list of immediate dependents but then grows as classes and resources are loaded. This bit of code would have to be reworked if that list got reordered as we were adding more dependents while iterating over the list. You will notice this comment in the code:

//size may change, so we must check it every time
for (int i = 0; i < allDependents.size() && result == null; i++) {

Here the loop assumes we always add new dependents to the end of the list as we are looping through it. Not my favorite code pattern (and I would not be surprised if there is some thread safety gotcha lurking here), but this code has not really been touched much over the years.

I wonder if a more simple solution would be to change org.eclipse.osgi.internal.loader.buddy.DependentPolicy.basicAddImmediateDependents(ModuleWiring) to gather the immediate dependents and only add the highest version of each dependent to the overall list of allDependents.

Feel free to open an Equinox bug to discuss more.

Re: BuddyPolicy dependents are not sorted [message #1073291 is a reply to message #1073261] Wed, 24 July 2013 13:29 Go to previous messageGo to next message
Jakob Braeuchi is currently offline Jakob Braeuchi
Messages: 69
Registered: July 2009
Location: Switzerland
Member
hi thomas,

thanks for your answer.
Does the list allDependents really grow after it has been filtered in the constructor of RegisteredPolicy:

	public RegisteredPolicy(BundleLoader requester) {
		super(requester);

		//Filter the dependents;
		if (allDependents == null)
			return;

		for (Iterator<BundleDescription> iter = allDependents.iterator(); iter.hasNext();) {
			BundleLoaderProxy proxy = buddyRequester.getLoaderProxy(iter.next());
			if (proxy == null)
				iter.remove();

			...
                }
 
		//After the filtering, if nothing is left then null out the variable for optimization
		if (allDependents.size() == 0)
			allDependents = null;
	}



jakob

[Updated on: Wed, 24 July 2013 13:30]

Report message to a moderator

Re: BuddyPolicy dependents are not sorted [message #1073432 is a reply to message #1073291] Wed, 24 July 2013 19:16 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas Watson
Messages: 427
Registered: July 2009
Senior Member
I see your point, for RegisteredPolicy the allDependents does not change after construction. So we could sort that, but then we would still have this issue for DependentPolicy.
Re: BuddyPolicy dependents are not sorted [message #1073585 is a reply to message #1073432] Thu, 25 July 2013 05:38 Go to previous message
Jakob Braeuchi is currently offline Jakob Braeuchi
Messages: 69
Registered: July 2009
Location: Switzerland
Member
That's true. But I would be happy with a fix in RegisteredPolicy Wink
Previous Topic:Starter Kit OSX 64 doesn't start
Next Topic:Websocket bundle
Goto Forum:
  


Current Time: Fri Sep 19 15:50:47 GMT 2014

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

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