Petals ESB Container

Improve classloading for components

Details

  • Type: Task Task
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 4.2.4
  • Fix Version/s: 5.0.0
  • Component/s: Classloader
  • Security Level: Public
  • Description:
    Hide

    The classloading for components and shared libraries should be implemented as follows (according to the JBI spec):

    • The JBI classloader contains jbi classes and optionally some container's specific classes
      • Normally they should be separated in two classloaders inheriting from each other, but for now it corresponds to the system classloader initialised by petals-bootstrap-launcher).
    • A component's classloader has all its shared libraries (in their declaration order) as parents (or if no shared libaries, the JBI classloader as parent).
    • A shared library has the JBI classloader as parent
    • Component or SLs can be parent-first or self-first, in the first case, the default, they first look at their parent and then at their own classes; in the second case, they first look at their own class, then at their parents.

    So there is a flat organisation of classloaders with the JBI classloader at the top, then inheriting from it, some SLs, then, for each components, they inherit from a set of SLs or if this set is empty, they directly inherit from the JBI classloader.

    The current classloading implementation has some shortcomings:

    • The parent JBI classloader is queried many times during the class resolution.
    • Classloaders acts as bottleneck (Java 7 introduced a per-class locking mechanism), and even more if the JBI classloader is so often queried.
    • The class hierarchy that implements it does not reflect properly the spec (there is only one object that takes care of dispatching to SLs classloader), so it introduces complex code in some places.
    • It seems that sometimes the spec is not respected (but it's hard to be completely sure because the code is complex because of previous point).
    • getResources is not implemented w.r.t. the JBI specs.
    • Code comments are not up-to-date.
    Show
    The classloading for components and shared libraries should be implemented as follows (according to the JBI spec):
    • The JBI classloader contains jbi classes and optionally some container's specific classes
      • Normally they should be separated in two classloaders inheriting from each other, but for now it corresponds to the system classloader initialised by petals-bootstrap-launcher).
    • A component's classloader has all its shared libraries (in their declaration order) as parents (or if no shared libaries, the JBI classloader as parent).
    • A shared library has the JBI classloader as parent
    • Component or SLs can be parent-first or self-first, in the first case, the default, they first look at their parent and then at their own classes; in the second case, they first look at their own class, then at their parents.
    So there is a flat organisation of classloaders with the JBI classloader at the top, then inheriting from it, some SLs, then, for each components, they inherit from a set of SLs or if this set is empty, they directly inherit from the JBI classloader. The current classloading implementation has some shortcomings:
    • The parent JBI classloader is queried many times during the class resolution.
    • Classloaders acts as bottleneck (Java 7 introduced a per-class locking mechanism), and even more if the JBI classloader is so often queried.
    • The class hierarchy that implements it does not reflect properly the spec (there is only one object that takes care of dispatching to SLs classloader), so it introduces complex code in some places.
    • It seems that sometimes the spec is not respected (but it's hard to be completely sure because the code is complex because of previous point).
    • getResources is not implemented w.r.t. the JBI specs.
    • Code comments are not up-to-date.
  • Environment:
    -

Activity

Hide
Victor NOËL added a comment - Mon, 11 May 2015 - 12:49:35 +0200

getPackage and getPackages should be reimplemented for ComponentClassLoader in order to take the shared libraries into account, but it doesn't seem to be so easy to do so.

The problem is technical and conceptual:

  • The current implementation of getPackage relies on storing all the package of a classloader, including the parent's, in the class, so we may need to duplicate the whole code for it to work with our special requirements
  • It's not totally clear how we should handle packages from different shared libraries...
Show
Victor NOËL added a comment - Mon, 11 May 2015 - 12:49:35 +0200 getPackage and getPackages should be reimplemented for ComponentClassLoader in order to take the shared libraries into account, but it doesn't seem to be so easy to do so. The problem is technical and conceptual:
  • The current implementation of getPackage relies on storing all the package of a classloader, including the parent's, in the class, so we may need to duplicate the whole code for it to work with our special requirements
  • It's not totally clear how we should handle packages from different shared libraries...
Hide
Victor NOËL added a comment - Mon, 11 May 2015 - 13:01:27 +0200

Improving the design of these classes will help with the package problem: if the parent of each ComponentClassLoader is an object (of type ClassLoader) that represents the set of SL classloader, then it can also manage the packages.

Show
Victor NOËL added a comment - Mon, 11 May 2015 - 13:01:27 +0200 Improving the design of these classes will help with the package problem: if the parent of each ComponentClassLoader is an object (of type ClassLoader) that represents the set of SL classloader, then it can also manage the packages.
Hide
Victor NOËL added a comment - Tue, 12 May 2015 - 11:10:20 +0200

Should be alright now.

Show
Victor NOËL added a comment - Tue, 12 May 2015 - 11:10:20 +0200 Should be alright now.
Hide
Christophe DENEUX added a comment - Fri, 3 Jul 2015 - 09:15:20 +0200

I reopen this issue because of PETALSESBCONT-341 occurring on the last SNAPSHOT (#68) of Petals ESB v5.

Show
Christophe DENEUX added a comment - Fri, 3 Jul 2015 - 09:15:20 +0200 I reopen this issue because of PETALSESBCONT-341 occurring on the last SNAPSHOT (#68) of Petals ESB v5.
Hide
Victor NOËL added a comment - Fri, 3 Jul 2015 - 13:26:38 +0200

Back to fixed, PETALSESBCONT-341 wasn't related to this.

Show
Victor NOËL added a comment - Fri, 3 Jul 2015 - 13:26:38 +0200 Back to fixed, PETALSESBCONT-341 wasn't related to this.

People

Dates

  • Created:
    Mon, 11 May 2015 - 11:34:19 +0200
    Updated:
    Fri, 3 Jul 2015 - 13:26:38 +0200
    Resolved:
    Fri, 3 Jul 2015 - 13:26:38 +0200