1. Field
This disclosure generally relates to a computing environment. More particularly, the disclosure relates to optimization of compiled code.
2. General Background
In general, as programmable computer processing is becoming more prevalent in a larger array of devices, e.g., handheld devices, smart appliances, embedded systems, etc., efficient utilization of computing resources has become more of a concern. An example of such a computing resource is memory, which stores one or more computer programs that control a computing device. Many of these computer programs tend to sacrifice program size for other efficiencies. The computer programs that are written in object oriented languages especially have such a tendency. Although the efficiencies typically allow program source code to be written and implemented faster than without such efficiencies, the complied program may include constructs that increase the size of the complied program without providing any actual function at runtime. As a result the implementation of the complied objected oriented code may be efficiently implemented, but not efficiently executed at runtime.
In one embodiment of the invention, a computer program product is provided for multi-threading. The computer program product includes a computer readable storage medium having computer readable program code embodied therewith. Computer readable program code is configured to compile a set of code to generate compiled code having a first size. Further, the computer readable code is configured to automatically remove, with an optimization tool operably connected to a processor, one or more abstract method definitions from the compiled code by iteratively examining each class file in the complied code and only adding the class file without the one or more abstract method definitions to an output file. The output file has a second size that is less than the first size. In addition, the computer readable code is configured to deploy the output file after the automatic removal of the one or more abstract method definitions.
In another embodiment of the invention, a process is provided. The process compiles, with a compiler, a set of code to generate compiled code having a first size. Further, the process automatically removes, with an optimization tool operably connected to a processor, one or more abstract method definitions from the compiled code by iteratively examining each class file in the complied code and only adding the class file without the one or more abstract method definitions to an output file. The output file has a second size that is less than the first size. In addition, the process deploys the output file after the automatic removal of the one or more abstract method definitions.
In yet another embodiment of the invention, a system is provided. The system includes a compiler, which is operably connected to a processor, that compiles a set of code to generate compiled code having a first size. Further, the system includes an optimization tool, which is operably connected to the processor, that automatically removes one or more abstract method definitions from the compiled code by iteratively examining each class file in the complied code and only adding the class file without the one or more abstract method definitions to an output file. The output file has a second size that is less than the first size. In addition, the system includes a deployment module that deploys the output file after the automatic removal of the one or more abstract method definitions.
The above-mentioned features of the present invention will become more apparent with reference to the following description taken in conjunction with the accompanying drawings wherein like reference numerals denote like elements and in which:
An object oriented program consists of classes, each which contain methods (or functional members, or functions) that contain the instructions to run the program. Classes also contain data members (fields). Classes are “instantiated” in order to create objects. Each object contains its own set of data as specified by the data members of the class, and the functional members of any given object are capable of acting on the data members of the object.
Some languages allow for the definition of “abstract” classes and interfaces. Similar to interfaces, abstract classes cannot be “instantiated”. Abstract classes and interfaces may contain abstract methods. These abstract methods are rules for classes which extend an abstract class or implement an interface to provide a concrete implementation of the abstract method. This technique allows for the development of robust extensible application frameworks at the cost of some overhead.
In certain programming languages, the class file is the structure which maintains the definition of a class and its members prior to runtime. Each class file maintains a list of the methods. The list includes the abstract methods. These lists consume file space. The amount of memory consumed can add up with a large number of classes and methods. On some platforms, e.g., embedded and mobile device platforms, memory usage has to be kept to a minimum. Small differences in memory requirements make a significant difference in cost savings in relation to the cost of the device.
In one embodiment of the present invention, one or more abstract method definitions in compiled class files are eliminated. An automated procedure may be performed by an optimization tool after development of the software program or library has completed, but prior to deployment of the application on a platform or device, in order to reduce memory usage and increase performance on the platform file system. Therefore, the changes would be invisible to the developer and to the user of the software, but would achieve savings in the deployment of the software. The user of the software would notice no difference in the behavior of the running programs.
Accordingly, abstract methods in interfaces and abstract class can be removed. As an example, an approximate range of twelve to several hundred bytes may be saved per method depending on the number types of arguments in the method signature and the number of exceptions listed in the throws clause of the method.
As an example, the implementation class (abstractMethodsRemoved.Implementor) extends an abstract class and implements two interfaces. Further, the implementation class is compiled against the “abstract_complete.jar” file which contains the complete abstract classes including the abstract methods:
At runtime the “abstract_complete.jar” can be replaced with the “abstract_empty.jar” file on the classpath of the application. The “abstract_empty.jar” file contains the abstract class and interfaces without abstract method definitions:
As a result, Class and ROM seizes are reduced in addition to times beings faster.
The process 200 illustrates an embodiment of the present invention in which the abstract methods are ignored and not added to the output file 122. In an alternative embodiment, the abstract methods may be deleted from the output file 122.
Further, in one embodiment, the optimization tool 120 may be configured to selectively ignore or remove abstract methods. For example, some native abstract methods may have to be on a particular platform. Accordingly, the optimization tool 120 may be configured so that one or more particular abstract methods are not ignored or removed.
In some situations, not all abstract methods may be removed without causing runtime errors. In one embodiment, the existing byte code is modified to avoid such runtime errors. The modifications to the byte code will not alter the runtime behavior of the program.
As an example of such a modification to the byte code, the abstract class P may define a method m( ) and the class S that extends the abstract class P. The abstract class P may implement the method m( ) as follows:
If the method m( ) in the abstract class P is removed, then the following direct and indirect usages of method P.m( ) are considered. First, an example of using the method (m) in the concrete class S directly is as follows:
This example is the standard situation, which will work without further modification.
Further, an example of declaring the variable as type P and calling the method m( ) in the abstract class P is as follows:
The result of this example is a NoSuchMethodError to be thrown when the run( ) method is invoked at runtime. An example of a possible modification is to change the type declaration of the local to or insert a cast to implementation class S:
In addition, an example of utilizing the abstract class P as an anonymous inner class is as follows:
The result of this example is also a NoSuchMethodError. However, the approach to solve this by changing the type declaration of the local to or inserting a cast to implementation class S fails with ClassCastException. In this situation, the anonymous inner class is transformed into a named inner class as follows:
No class size increase results if the inner class name can be kept short.
Further, if the anonymous inner class is utilizing an interface instead of an abstract class, the modifications are the same as illustrated in the following example:
A NoSuchMethodError also results, the anonymous inner class is transformed into a named inner class as follows:
As another example, the interface may be utilized as an argument type as follows:
As a result, the call to m2( ) fails. In this situation, if no other class implements the interface I and calls the method m2(I), then the argument type of m2(I) may be changed to m2(C) as follows:
If another class implements the interface I and calls the method m2(I), then the method cannot be removed without the addition the code which defeats the purpose improving efficiency. In this situation, this abstract method can only be removed by changes in the virtual machine to not throw the error when performing type checking.
In one embodiment, a process determines if the target type is an Interface or an Abstract Class and the option ignoreMissingAbstractMethods is not set. If so, the process gets the target method in Interface and if not found throws NoSuchMethodError. Otherwise, the process continues. The process proceeds to get the target method in the target object. The process then executes the target method. In one embodiment, this process involves the classes being pre-verified.
The processes described herein may be implemented in a general, multi-purpose or single purpose processor. Such a processor will execute instructions, either at the assembly, compiled or machine-level, to perform the processes. Those instructions can be written by one of ordinary skill in the art following the description of the figures corresponding to the processes and stored or transmitted on a computer readable medium. The instructions may also be created using source code or any other known computer-aided design tool.
The processor 104 is coupled, either directly or indirectly, to the memory 402 through a system bus. The memory 402 may include local memory employed during actual execution of the program code, bulk storage, and/or cache memories which provide temporary storage of at least some program code in order to reduce the number of times code must be retrieved from bulk storage during execution.
The input/output devices 404 may be coupled directly to the system 400 or through intervening input/output controllers. Further, the input/output devices 404 may include a keyboard, a keypad, a mouse, a microphone for capturing speech commands, a pointing device, and other user input devices that will be recognized by one of ordinary skill in the art. Further, the input/output devices 404 may include a receiver, transmitter, speaker, display, image capture sensor, biometric sensor, etc. In addition, the input/output devices 604 may include storage devices such as a tape drive, floppy drive, hard disk drive, compact disk (“CD”) drive, digital video disk (“DVD”) drive, etc.
Network adapters may also be coupled to the system 400 to enable the system 400 to become coupled to other systems, remote printers, or storage devices through intervening private or public networks. Modems, cable modems, and Ethernet cards are just a few of the currently available types of network adapters.
For any of the configurations described herein, various actions may take place when the call stack is retrieved. In one embodiment, the retrieved call stack is walked into a tree and the leaf node of the tree has its base count incremented, which allows for utilization of technology to produce reports or to view the collected information.
As will be appreciated by one skilled in the art, aspects of the present invention may be embodied as a system, method, or computer program product. Accordingly, aspects of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment (including firmware, resident software, micro-code, etc.) or an embodiment combining software and hardware aspects that may all generally be referred to herein as a “circuit,” “module” or “system.” Furthermore, aspects of the present invention may take the form of a computer program product embodied in one or more computer readable medium(s) having computer readable program code embodied thereon.
Any combination of one or more computer readable medium(s) may be utilized. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that may contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may be any computer readable medium that is not a computer readable storage medium and that may communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the “C” programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a local area network (“LAN”) or a wide area network (“WAN”), or the connection may be made to an external computer (for example, through the Internet using an Internet Service Provider).
Aspects of the present invention are described below with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, may be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks.
The “processor” of a general purpose computer, special purpose computer, or other programmable data processing apparatus may be referred to herein as a “microprocessor.” However, the term “microprocessor” should not be interpreted as being limited to a single-chip central processing unit or any other particular type of programmable data processing apparatus, unless explicitly so stated.
These computer program instructions may also be stored in a computer readable medium that may direct a computer, other programmable data processing apparatus, or other devices to function in a particular manner, such that the instructions stored in the computer readable medium produce an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks. The computer program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, may be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Reference throughout this Specification to “one embodiment,” “an embodiment,” or similar language means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the present invention. Thus, appearances of the phrase “in one embodiment,” “in an embodiment,” and similar language throughout this Specification may, but do not necessarily, all refer to the same embodiment. Furthermore, the described features, structures, or characteristics of the invention may be combined in any suitable manner in one or more embodiments. Correspondingly, even if features are initially claimed as acting in certain combinations, one or more features from a claimed combination may in some cases be excised from the combination, and the claimed combination may be directed to a subcombination or variation of a subcombination.
While the computer program product, method and system have been described in terms of what are presently considered to be the most practical and preferred embodiments, it is to be understood that the disclosure need not be limited to the disclosed embodiments. The disclosure is intended to cover various modifications and similar arrangements included within the spirit and scope of the claims, the scope of which should be accorded the broadest interpretation so as to encompass all such modifications and similar structures. The present disclosure includes any and all embodiments of the following claims.