Return-Path: Delivered-To: apmail-felix-dev-archive@www.apache.org Received: (qmail 15566 invoked from network); 28 Feb 2011 10:51:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Feb 2011 10:51:02 -0000 Received: (qmail 61668 invoked by uid 500); 28 Feb 2011 10:51:02 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 61307 invoked by uid 500); 28 Feb 2011 10:50:59 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 61299 invoked by uid 99); 28 Feb 2011 10:50:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Feb 2011 10:50:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Feb 2011 10:50:56 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id D7EBE414F3 for ; Mon, 28 Feb 2011 10:50:36 +0000 (UTC) Date: Mon, 28 Feb 2011 10:50:36 +0000 (UTC) From: "Alexander Berger (JIRA)" To: dev@felix.apache.org Message-ID: <99880285.1207.1298890236866.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] Commented: (FELIX-2400) High contention (or deadlock) in PackageAdmin and StartLevel MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/FELIX-2400?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13000215#comment-13000215 ] Alexander Berger commented on FELIX-2400: ----------------------------------------- I did not yet manage to test this problem with a 3.* release of the framework. At the moment we are using framework version 3.0.6 with our work around (as described above) applied. But from a logical point of view, as long as the locking behaviour within the framework is the same the contention will stay. > High contention (or deadlock) in PackageAdmin and StartLevel > ------------------------------------------------------------- > > Key: FELIX-2400 > URL: https://issues.apache.org/jira/browse/FELIX-2400 > Project: Felix > Issue Type: Bug > Components: Framework > Affects Versions: framework-2.0.5 > Environment: Felix 2.0.5 > java version "1.6.0_12" > Java(TM) SE Runtime Environment (build 1.6.0_12-b04) > Java HotSpot(TM) 64-Bit Server VM (build 11.2-b01, mixed mode) > SunOS castor 5.10 Generic_138888-06 sun4u sparc SUNW,Sun-Fire-V890 > Reporter: Alexander Berger > > Imagine the following code: > void createProblem(PackageAdmin pa, StartLevel sl, Bundle bundles[], int level){ > for ( final Bundle b : bundles) { > sl.setBundleStartLevel(b, level); > } > pa.refreshPackages(null); > pa.resolveBundles(null); > } > If there have been many bundles updated or uninstalled the code above might create what looks like a deadlock (see Stack traces below) > but in fact is a high contention problem. On our system (16 core Sun Sparcv9, 64GB) with about 20 bundles (all updated, so refresh will be busy) > this will result in very poor runtime performance, it will take about 30 to 60 minutes for pa.resolveBundles(null) to return. > The problem lies in the asynchronous nature of setBundleStartLevel/refreshPackages and the way that Felix uses locking (acquireGlobalLock and acquireBundleLock). For example the following code works fine (and for pa.resolveBundles(null) returns within some seconds) but poses the problem of how to implement "magicWait": > void createNoProblem(PackageAdmin pa, StartLevel sl, Bundle bundles[], int level){ > for ( final Bundle b : bundles) { > sl.setBundleStartLevel(b, level); > } > // wait until the asynchronous sl.setBundleStartLevel logic has finished > magicWait(sl); > pa.refreshPackages(null); > // wait until the asynchronous pa.refreshPackages logic has finished > magicWait(pa); > pa.resolveBundles(null); > } > At the moment I solved the problem by patching PackageAdminImpl like this (I know this is an ugly solution buts its only a show case): > public boolean isDone() { > synchronized(this) { > final Bundle tmp[][] = m_reqBundles; > return tmp == null || tmp.length == 0; > } > } > And implementing magicWait like this: > void magicWait(final PackageAdmin pa){ > final Method method = pa.getClass().getMethod("isDone"); > method.setAccessible(true); > while ( ! (Boolean)method.invoke(pa) ) { > Thread.yield(); > } > } > Then I did something similar for StartLevel. > For me this patch/work around is fine for the moment but I think the problem > should be investigated and solved in the Felix framework. > "FelixPackageAdmin" daemon prio=3 tid=0x00000001005ac800 nid=0x1a in Object.wait() [0xffffffff4f6fe000] > java.lang.Thread.State: WAITING (on object monitor) > at java.lang.Object.wait(Native Method) > - waiting on <0xffffffff554000e0> (a [Ljava.lang.Object;) > at java.lang.Object.wait(Object.java:485) > at org.apache.felix.framework.Felix.acquireGlobalLock(Felix.java:4535) > - locked <0xffffffff554000e0> (a [Ljava.lang.Object;) > at org.apache.felix.framework.Felix.refreshPackages(Felix.java:3314) > at org.apache.felix.framework.PackageAdminImpl.run(PackageAdminImpl.java:331) > at java.lang.Thread.run(Unknown Source) > Locked ownable synchronizers: > - None > > "FelixStartLevel" daemon prio=3 tid=0x0000000100848000 nid=0x19 in Object.wait() [0xffffffff4f8fe000] > java.lang.Thread.State: WAITING (on object monitor) > at java.lang.Object.wait(Native Method) > - waiting on <0xffffffff554000e0> (a [Ljava.lang.Object;) > at java.lang.Object.wait(Object.java:485) > at org.apache.felix.framework.Felix.acquireBundleLock(Felix.java:4462) > - locked <0xffffffff554000e0> (a [Ljava.lang.Object;) > at org.apache.felix.framework.Felix.setBundleStartLevel(Felix.java:1266) > at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:270) > at java.lang.Thread.run(Unknown Source) > Locked ownable synchronizers: > - None > > "OSKi" prio=3 tid=0x00000001006ea800 nid=0x1b runnable [0xffffffff4f4fd000] > java.lang.Thread.State: RUNNABLE > at org.apache.felix.framework.searchpolicy.ResolvedPackage.clone(ResolvedPackage.java:62) > at org.apache.felix.framework.searchpolicy.Resolver.isClassSpaceConsistent(Resolver.java:846) > at org.apache.felix.framework.searchpolicy.Resolver.isClassSpaceConsistent(Resolver.java:807) > at org.apache.felix.framework.searchpolicy.Resolver.isClassSpaceConsistent(Resolver.java:807) > at org.apache.felix.framework.searchpolicy.Resolver.findConsistentClassSpace(Resolver.java:549) > at org.apache.felix.framework.searchpolicy.Resolver.resolve(Resolver.java:103) > at org.apache.felix.framework.Felix$FelixResolver.resolve(Felix.java:3861) > at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3292) > at org.apache.felix.framework.Felix.resolveBundles(Felix.java:3267) > at org.apache.felix.framework.PackageAdminImpl.resolveBundles(PackageAdminImpl.java:288) > at Test.createProblem(Test.java:10) -- This message is automatically generated by JIRA. - For more information on JIRA, see: http://www.atlassian.com/software/jira