System and method for determining a root cause of a failure

A system, comprising a receiving module to receive a request to load a component, a stack to record the request and a loader to fulfill the request, wherein when the request has been fulfilled the request is removed from the stack and when the loading of the component is unsuccessful, contents of the stack are made available to a user to indicate the unsuccessfully loaded component.

BACKGROUND INFORMATION

Many devices such as personal computers (“PCs”), personal digital assistants (“PDAs”), embedded devices, etc., contain applications and software that need to be loaded for the device to accomplish the functions requested by a user. This software may be loaded in various stages into, for example, a processor or temporary memory of the device. For example, software that provides basic services to the device may be loaded during the boot process so that these services are immediately available to the device, whereas other software may be loaded on an as needed basis depending on requests made by the user. Individual software components may be loaded in whole or in part onto the device.

The different stages of software component or sub-component loading may be dependent upon the loading of other software components or sub-components. In certain instances, software components may fail to load correctly. When a software component fails to load correctly, the user may receive an indication that the software component did not load correctly, but not an indication as to the reason for the failure in the loading of the software component.

SUMMARY OF THE INVENTION

A system, comprising a receiving module to receive a request to load a component, a stack to record the request and a loader to fulfill the request, wherein when the request has been fulfilled the request is removed from the stack and when the loading of the component is unsuccessful, contents of the stack are made available to a user to indicate the unsuccessfully loaded component.

Furthermore, a method of loading software modules, comprising the steps of receiving a request to load a first software module, placing a representation of the first software module onto a stack, determining if the first software module is dependent on a second software module, placing, when the first software module is dependent on the second software module, a representation of the second software module onto the stack, loading the second software module, removing the representation of the second software module from the stack when the second software module has been successfully loaded, loading the first software module and removing the representation of the first software module from the stack when the first software module has been successfully loaded.

DETAILED DESCRIPTION

The present invention may be further understood with reference to the following description of preferred exemplary embodiments and the related appended drawings, wherein like elements are provided with the same reference numerals. It should be understood that the present invention may be implemented on any processor or controller based device such as PCs, servers, PDAs, embedded devices, etc. (and development platforms for the same), and the term devices will be used throughout this description to generically refer to all such devices. The exemplary embodiment of the present invention is also described using the terms load, loading and loaded. The equivalent terms resolve, resolving and resolved are sometimes used interchangeably by those skilled in the art. Additionally, the preferred embodiment of the present invention will be described with reference to class loaders for Java® applications. Those skilled in the art will understand that the present invention is not limited to class loading in Java® applications, but may be implemented to determine the root cause of loading failures of modules for any software component.

FIG. 1shows an exemplary block diagram illustrating the creation of class object30from class10using class loader20. Class10is the basic unit of object orientation in Java and may be considered a blueprint for class object30. Those skilled in the art will understand that the present description is describing a single class, class loader and class object, but that there may be multiple classes, class loaders and class objects in a software component. Class10allows the software developer to define all the properties and methods that internally define class object30, all the application program interface (“API”) methods that externally define class object30and all the syntax necessary for handling other features of class object30. Class10is generally stored in the form of byte code and may be stored on the device in, for example, a hard drive or flash memory, or may also be stored externally from the device, for example, on a network storage device accessible via a network. Class loader20is responsible for finding the byte code for class10when an execution module, for example, the Java Virtual Machine (“JVM”) needs to load class10. As is well known, the JVM is a virtual computing environment implemented in software on top of the device hardware and operating system to run compiled Java programs. Class loader20may itself be considered an object that can be managed by the JVM. When class loader20finds class10, it reads in the byte code for class10to create or instantiate class object30which is used by the JVM to run the program. As described above, class10functions as a blueprint for class object30which becomes the actual object which is stored in the device memory. Class object30may then utilize the methods and APIs defined by class10.

Class loader20may be a primordial or default class loader generally responsible for loading essential functions into the JVM. The primordial class loader may also load classes from a classpath defined by the user or developer. The primordial class loader is limited in this manner for a variety of reasons including, for example, security issues relating to loading classes from untrusted sources. However, most developers and/or users find this too limiting and want to load, during runtime, new classes that are not on the predefined classpath. To accomplish this goal, developers write their own class loaders which may be referred to as custom class loaders. In the example described above, class loader20may be a primordial class loader or a custom class loader. Some examples of custom class loaders include, applet class loaders, secure class loaders, remote method invocation (“RMI”) class loaders, etc. These custom class loaders may search, find and load classes from virtually any location or type of file. For example, the classes may be located in a database which is on the device itself or may be located on a network and accessed via a uniform resource locater (“URL”) link. Thus, a single device may contain multiple custom class loaders in addition to the primordial class loader. Those skilled in the art will understand that the system and method of the present invention will be described with reference to a custom class loader. However, the present invention may be implemented in the primordial or default class loader.

An issue that may arise with multiple class loaders is that there may be similarly named classes or the same classes may be stored in different locations. It is desirable to load the correct class or the class from its primary location and not have multiple class loaders loading the same class. For example, if a class is on a predefined classpath and the primordial class loader is loading the class, the developer does not want a custom class loader to load that class from a different location. It is possible to create a hierarchical relationship between the multiple class loaders so that such a conflict does not occur.FIG. 2shows an exemplary hierarchical relationship between multiple class loaders40-70. Those of skill in the art will understand that the entire set of class loader40-70may be referred to as a loader or class loader and then each of the individual loaders may be referred to as loading modules. In this relationship primordial class loader40is the ultimate parent class loader to each of custom class loaders50-70. Primordial class loader40is the ultimate parent because it is the default class loader for the JVM and if primordial class loader40can load a particular class (e.g., that class is on the predefined classpath), it will load the class. The order of the remaining custom class loaders50-70may be determined by the software developer based on, for example, device requirements. This order also denotes a parent-child relationship between the custom class loaders50-70. For example, custom class loader50is a parent to custom class loader60which, in turn, is a parent to custom class loader70. Those skilled in the art will understand that the hierarchical relationship described with respect toFIG. 2may be nested to any number of levels based on the number of class loaders included in a software component. The hierarchical relationship between the class loaders allows the correct class loader to load a particular class.

FIG. 3shows an exemplary process100for fulfilling a request to load a class using the hierarchical relationship between class loaders. In step105a class loader receives a request to load a class. For example, there may be a request to custom class loader70to load a class. The request to load a class may come from the portion of software code that is currently being executed on the device. The portion of software code that is currently being executed is part of a class and any requests for a class made by that portion of software code will go to the class loader that loaded the class containing the currently executing portion of software code. Before custom class loader70fulfills this request, it determines whether any other class loader which is at a higher level (e.g., class loaders40-60) can fulfill the request. In step110, the class loader that received the request determines whether it has a parent. If the class loader has a parent, the process continues to step115where the class loader that received the request passes the request to its parent. The process then continues back to step105where the parent receives the request and determines whether it has a parent class (step110). Thus, in the example started above, the first request is received by custom class loader70which determines that it has a parent (custom class loader60) and passes the request to that parent. Similarly, custom class loader60determines that it has a parent (custom class loader50) and passes the request to that parent. Thus, the process continues to loop until the request is passed to primordial class loader40at which point no parent class loader exists in step110. The process then continues to step120to determine whether the requested class has loaded. The first time the process reaches step120, the requested class cannot have loaded because none of the class loaders have yet attempted to load the requested class. Therefore, the process continues to step125where the current class loader attempts to fulfill the request. A class loader can fulfill a request if it is capable of finding the requested class. In the example started above, primordial class loader40will be the first class loader to attempt to load the requested class.

After the current class loader has attempted to load the requested class, the request is passed back to the next lowest class loader in step130. For example, after primordial class loader40has attempted to load the requested class, the request is then passed back to custom class loader50. The process then loops to step120to again determine if the class has loaded. When the process reaches step120for a second time, it is possible that the requested class has been loaded. For example, if primordial class loader40was capable of loading the requested class in step125, custom class loader50would determine that the requested class has been loaded in step120. If the class has been loaded the process ends. However, if the class has not been loaded the process again continues to step125where the current class loader attempts to load the requested class. In this example, custom class loader50would attempt to fulfill the request. After the attempt to fulfill the request was made, the process then continues to step130where the request is passed to the next lowest class loader (e.g., custom class loader60). The process continues to loop until the requested class is loaded.

Classes may be dependent upon other classes and therefore these other classes may need to be loaded prior to the loading of the originally requested class. The classes which a requested class are dependent on may be included in the class definition or information. Thus, when a class loader receives a request to load a class, the class definition includes the dependent classes.FIG. 4shows an exemplary class loading scenario200having multiple dependencies between classes205-250. In this exemplary scenario200, the originally requested class to load was class A205. However, class A205is dependent upon three other classes, class B210, class E230and class F235. Thus, before class A205may be loaded, each of class B210, class E230and class F235must be loaded. Similarly, class B210is dependent on class C215and class D220. Class F235is dependent on class G240and class H245which is, in turn, dependent on class1250. Therefore, class A205cannot be loaded until all of classes B-I210-250have been loaded. If any of classes B-I210-250do not load properly, class A205will not load properly. For example, if class E230does not load correctly, class A205will not load because it is dependent on class E230. If the developer receives only an indication that class A205did not load correctly, the developer may not know the ultimate reason for the failure in the loading of class A205.

The exemplary embodiment of present invention allows developers to easily determine the root cause for failure in the loading of classes through the implementation of a class loader containing a stack. As described above, developers may define custom class loaders to include any number of features. The exemplary embodiment of the present invention is implemented via a custom class loader in the form of a stack. Those skilled in the art will understand that the present invention may also be implemented in the primordial or default class loader. The stack keeps track of classes as they are loaded by the class loader. The stack will contain a complete history of the loading scenario for requested classes that have failed to load. In this manner, the developer will know which class or classes caused the loading failure. Those skilled in the art will understand that the implementation of the stack in a class loader is only exemplary. A stack, as will be described in greater detail below, may be implemented in any software application as either a component of the software application or as a stand alone software application that may be used in conjunction with other applications (e.g., a software development suite such as the WindStorm® software product available from Wind River Systems, Inc. of Alameda, Calif.).

FIG. 5shows an exemplary stack300in different stages301-318as the exemplary loading scenario200ofFIG. 4is carried out in the device. As described above, in exemplary scenario200, class A205is the originally requested class. In the exemplary embodiment of the present invention the adding of a representation of a class to a stack is referred to as “pushing” a class onto the stack and removing a representation of a class from a stack is referred to as “popping” a class off the stack. In the exemplary embodiment described below, the representation of the class is the class name. However, any representation that uniquely identifies a class may be used for the representation. Thus, when the request for class A205is received, the class loader pushes the name of class A205onto stack300(stage301). As described above, stack300may be considered part of the class loader and may be stored, for example, in random access memory (“RAM”) during the class loading procedure. Stack300may be implemented, for example, in the form of an array, table, scalar, database entry, text file, etc. Since class A205is dependent on class B210, a request is made to load class B210, and the class loader pushes class B210onto stack300with class A205(stage302). Similarly, since class B210is dependent on class C215, a request is made to load class C215, and the class loader pushes class C215onto stack300(stage303). Class C215is not dependent on any other class, therefore the class loader may load class C215and when class C215is successfully loaded, the class loader pops class C215off of stack300(stage304). Thus, after a class has been successfully loaded it no longer appears on stack300. Only those classes which still need to be loaded appear on stack300.

Continuing with the example, class B210is also dependent on class D220and therefore there is a request to load class D220, and the class loader pushes class D220onto stack300(stage305). Since class D220is not dependent on any other classes, it is loaded by the class loader. When class D220has been successfully loaded, the class loader pops class D220off of stack300(stage306). After both class C215and class D220have been loaded, the class loader may then load class B210and then pop class B210off of stack300(stage307). Class A205is also dependent on class E230and therefore there is a request to load class E230. The class loader pushes class E230onto stack300with class A205(stage308). Class E230is not dependent on any other classes, therefore the class loader may load class E230and pop class E230off of stack300(stage309).

Class A205is also dependent on class F235and therefore a request to load class F235is generated, and the class loader pushes class F235onto stack300with class A205(stage310). Class F235is dependent on class G240and therefore there is a request to load class G240, and the class loader pushes class G240onto stack300(stage311). Class G240is not dependent on any other classes, therefore the class loader may load class G240and then pop class G240off of stack300(stage312). Class F235is dependent on class H245and therefore a request to load class H245is generated, and the class loader pushes class H245onto stack300(stage313). Class H245is dependent on class1250and therefore a request to load class1250is generated, and the class loader pushes class1250onto stack300(stage314). Class I250is not dependent on any other classes, therefore the class loader may load class1250and then pop class I250off of stack300(stage315). Since class1250has been loaded, the class loader may then load class H245and pop class H245off of stack300(stage316). After both class G240and class H245have been loaded, the class loader may then load class F235and then pop class F235off of stack300(stage317). Finally, when all of the classes that class A205is dependent upon have been loaded, the class loader may load class A205and then pop class A205off of stack300(stage318).

In the example described above, all required classes were loaded successfully. In such a case, the actions of pushing and popping classes onto and off of stack300will be transparent to the developer. However, if a problem arises during the loading of any of the classes, stack300will be available to the developer to diagnose the root cause of the loading failure. For example, as described above in the exemplary loading scenario200, the originally requested class to load was class A205. The developer did not specifically request all the dependent classes210-250to be loaded, but rather they were requested indirectly because of the dependencies of class A205. Thus, if one of the dependent classes210-250had failed to load, the developer would know that the requested class A205did not load. By accessing stack300, the developer may learn the root cause of the loading failure of class A205. For example, if class I250had failed to load correctly, the system may return an error message stating that the requested class A205had failed to load properly and may then display stack300in its current state. Stage314displays the state of stack300when class I250was requested to load and pushed onto stack300. Stack300(in stage314) indicates to the developer that the last requested class was class I250and therefore, class I250did not load correctly. It also indicates to the developer that class H245is dependent on class I250, class F235is dependent on class H245and requested class A205is dependent on class F235. The developer now knows that the root cause of the problems with the loading of the requested class A205lie in the failure of class I250to load. The developer also knows why class I250was attempting to load in the first place—because requested class A205is dependent on class1250. The developer may then attempt to remedy the problems with class I205.

As a further example, class D220may have failed to load correctly. The system may return an error message stating that the requested class A205had failed to load properly and then may display stack300in its current state. At the point where class D220is requested to load and pushed onto stack300, the stack is in the state of stage305. Stack300(in stage305) indicates to the developer that class D220was the last requested class and that it did not load correctly. The failure of class D220to load correctly prevented class B210from loading correctly because it was dependent on class D220. Finally, the requested class A205did not load correctly because it was dependent on class B210. Thus, the developer knows that the root cause of the loading problem of the requested class A205was the failure of class D220to load correctly. This knowledge of the root cause of the failure, saves the developer time and resources by allowing the developer to directly address the class that is the cause of the problem. If the developer did not know the root cause of the problem, the developer would need to go through the code of the requested class A205to determine all its dependencies and then go through all the dependent classes to determine their dependencies. The developer would then need to troubleshoot all the classes (e.g., classes205-250) to determine which class was causing the problem.

FIG. 6shows an exemplary process400for the operation of a class loader working in conjunction with stack300which may be part of the class loader or may be a separate variable. In step405, the class loader receives a load request, for example, load class A205. Those skilled in the art will understand that the request may be an explicit request from the user or the developer to load a particular class or may be an indirect request through an application program or other software component. In step410, the class loader determines whether a stack currently exists for the particular thread in which the request was made. A thread may be one of several paths or routes of execution inside a single program, routine, process or context. Threaded programs allow background and foreground actions to take place without the overhead of launching multiple processes or inter-process communication. Threading allows the sharing of a single processor between multiple tasks in a way designed to minimize the time required to switch threads. This is accomplished by sharing as much as possible of the program execution environment between the different threads so that very little state information needs to be saved and restored when changing threads. Every thread may have its own stack, and therefore, when a new thread is opened, a new stack is created for that thread. If there is no current stack for the thread on which the request was received, the process continues to step415where a new stack is created. After the new stack has been created in step415or if a stack exists for the current thread as determined in step410, the process continues to step420where the requested class is pushed onto stack300. For example, if the requested class is class A205, the class loader will push class A205onto stack300which will be in the state as shown in stage301of FIG.5. Stack300, whether newly created in step415or already existing, will be empty or blank prior to the class loader pushing the requested class onto the stack.

The process then continues to step425where it is determined whether the requested class has any dependencies. If the requested class has dependencies, the process continues to step430where a request is made to load the dependent class(es). For example, if the first requested class is class A205, in step425it would be determined that there are dependencies and the process would continue to step430where a request would be made for the first dependent class (e.g., class B210). The process would then loop back to step420where the dependent class (e.g., class B210) would be pushed on to stack300and the process would continue for the dependent class. If in step425, it is determined that the current class has no dependencies, the process continues to step435where the load request is fulfilled by the class loader. As described above, loading a class may involve a variety of steps including those described with respect to FIG.3. Thus, step435may include, for example, the entire process described with respect to FIG.3. Each of the stacks may be implemented in such a manner that any of the class loaders on the device have access to the stacks and are free to modify the stacks by pushing a class on or popping a class off the stack. Such an implementation may be in the form of implementing the stacks as, for example, a static variable, a global variable, or other similar variable that allows access by multiple class loaders. This arrangement allows for minimal communication between different class loaders which means that developers do not have to worry about whether the custom class loader they are developing can communicate with other custom class loaders that may be loaded onto the device. For example, if the current class is class E230and it is determined in step425that class E230has no dependencies, in step435the class loader will attempt to load class E230. However, referring toFIG. 2, the request may be received by custom class loader60, but through the process described with respect toFIG. 3, custom class loader50is the actual class loader which loads class E230. Because stack300is implemented in such a manner that any class loader may interact with it, custom class loader50may push class E230onto the stack and pop class E230off of stack300. This means that the class loader which loads the requested class is the class loader responsible for pushing the requested class onto the stack and popping the requested class off of the stack when it is loaded correctly.

After the class loader has attempted to load the class, the process continues to step440to determine whether the class loaded correctly. If the class did not load correctly, the process would continue to step445where the system makes available (e.g., on-screen display, printout, file, etc.) to the developer stack300. As described above, stack300indicates to the developer the root cause of the loading failure. The developer may then troubleshoot the appropriate software code based on the information provided by stack300. When a class has failed to load correctly and stack300has been provided in step445, the process ends and the class loader does not attempt to load any additional classes. If it is determined in step440that the class loaded correctly, the process continues to step450where the class loader pops the class off of the stack. For example, when class A205has been loaded correctly, the class loader pops class A205off of stack300(stages317-318of FIG.5).

The process then continues to step455to determine whether the requested class (including all the dependent classes) have been loaded. If additional classes need to be loaded, the process continues to step460where the class loader determines if all dependencies for the previous class have been loaded. For example, referring toFIG. 5, after class E230has been successfully loaded, class A205is the previous class remaining on stack300(stages308-309). Thus, the process continues to step460where it is determined whether all the dependencies of class A205have been loaded. In the exemplary scenario200, class F235must still be loaded in order for class A205to be loaded. In this case, the process loops back to step430where the dependent class is requested (e.g., class F235). If there were no remaining dependencies for the previous class (e.g., after class F235was loaded successfully), the process loops back to step435to load the requested class (e.g., class A205). If in step455, the requested class has been loaded, the process ends because all classes have been loaded successfully. Those of skill in the art will understand that stack300may be used for diagnostic purposes to determine the root cause of a loading failure. Thus, the operation of the stack may be disabled when the user and/or developer does not require diagnostic functions.

The following shows exemplary pseudo code for implementing portions of process400illustrated in FIG.6:

FIG. 7shows an exemplary interaction between class loader500, stack510and execution module520. As described above, a load request comes from code that is currently executing on execution module520which may be, for example, a Java Virtual Machine. Class loader500receives the load request from execution module520and pushes a representation of the requested class onto stack510. Class loader500then attempts to load the requested class (including any dependent classes). Class loader500reads in the byte code from the requested class, creating a class object which includes instructions that may be executed by execution module520. If the requested class is successfully loaded, class loader500pops the representation of the requested class off of stack510. If the requested class in not loaded successfully, the contents of stack510are made available to the user or developer so they may determine the root cause of the failure.

In the preceding specification, the present invention has been described with reference to specific exemplary embodiments thereof. It will, however, be evident that various modifications and changes may be made thereunto without departing from the broadest spirit and scope of the present invention as set forth in the claims that follow. The specification and drawings are accordingly to be regarded in an illustrative rather than restrictive sense.