METHOD TO REDUCE WASTED CHARACTER DATA AREAS OF JAVA STRINGS
A string handling method, program, and information processing apparatus capable of reducing the amount of data stored in a storage. An information processing apparatus handles strings. The information processing apparatus includes a storage storing a group of strings including a plurality of strings each of which consists of a plurality of pieces of character data, a reference section which refers to a particular string in the group of strings, a character data detecting section which detects character data that is not referenced as the particular string in the group of strings, and a character data deleting section which deletes the detected character data from the group of strings.
This application claims priority under 35 U.S.C. § 119 to Japanese Patent Application No. 2005-356226 filed Dec. 9, 2005, the entire text of which is specifically incorporated by reference herein.
BACKGROUND OF THE INVENTIONThe present invention relates to a method, program, and information processing apparatus for handling strings.
Computers, which are information processing apparatuses, conventionally operate in accordance with a program written in a programming language such as C or Java. The computer stores data such as numeric values and strings used in arithmetic in a memory which is a storage.
For example, in a computer operating in accordance with a Java program written in Java, which is an object-oriented language, garbage collection (hereinafter referred to as GC) that automatically frees a memory area in a memory that stores data that is no longer in use, without intervention of a programmer is used (see for example Patent document 1). According to GC described in Patent document 1, a memory is divided into two memory areas, a first memory area storing a first type of data group having a relatively short lifetime and a second memory area storing a second type of data group having a relatively long lifetime, and GC is executed more frequently on the first memory area than on the second memory area. In this way, GC is limited to a particular memory area in consideration of the characteristics of data, thereby efficiently freeing the memory area.
As described above, a computer operating in accordance with a Java program executes GC to free memory areas to reduce the amount of data stored in a memory used by the computer.
In a typical implementation of an execution environment of the Java program described above, strings represented by String objects are referred to in char array objects. The char array object generally has two characteristics.
A first characteristic is that a char array object may contain char data that is not referenced as a string of a String object. If such a char array object is not referred to by objects other than a String object, it is desirable that the memory area in which the char data that is not referenced as a string of the string object be freed to save the memory space consumed by the computer.
A second characteristic is that there may be multiple char array objects that have the same string data. In Java, strings of String objects cannot be handled. In the above case, it is desirable that two identical char array objects be consolidated into one and the memory area that stores one of the objects be freed to reduce the memory space consumed by the computer.
However, in a computer operating according to a Java program, conventional GC typically cannot detect char data that is not referred to or redundant char array objects described above among a group of char array objects and therefore cannot free memory areas storing these kinds of data. Therefore, there has been a problem that the amount of data stored in a memory used by the computer cannot sufficiently be reduced.
BRIEF SUMMARY OF THE INVENTIONAspects of the present invention may be used to provide a string handling method, program, and information processing apparatus capable of reducing the amount of data in storage. Character data that is not referred to and overlapping strings are detected and deleted among a group of strings, thereby freeing memory areas storing them. Char data that is not referred to and overlapping char arrays can be detected and deleted among a group of char array objects to free the memory areas storing these kinds of data. Thus, storage space of the storage consumed by the information processing apparatus can be reduced.
According to a first aspect of the present invention, there is provided a string handling method for handling a char array in an information processing apparatus which operates in accordance with a Java program and has a storage storing a group of char array objects, each of which consists of a plurality of pieces of char data, the method including: referring to a string of a String object in the group of char array objects; and deleting a given piece of char data and char array object from the group of char array objects when garbage collection is performed.
According to a second aspect of the present invention, there is provided a string handling method for handling a string in an information processing apparatus having a storage storing a group of strings including a plurality of strings each of which consists of a plurality of pieces of character data, the method including: referring to a particular string in the group of strings; detecting a piece of character data that is not referenced as the particular string among the group of strings; and deleting the detected piece of character data from the group of strings.
According to a third aspect of the present invention, there is provided a string handling method for handling a string in an information processing apparatus having a storage storing a group of strings including a plurality of strings each of which consists of a plurality of pieces of character data, the method including: referring to a particular character string in the group of strings; reordering the plurality of strings in accordance with the plurality of pieces of character data; detecting a first string and a second string identical to the first string in a group of strings including the reordered plurality of strings; and deleting the second string from the group of strings including the reordered plurality of strings.
According to a fourth aspect of the present invention, there is provided a string handling method for handling a string in an information processing apparatus having a storage storing a group of strings including a plurality of strings each of which consists of a plurality of pieces of character data, the method including: referring to a particular string in the group of strings; detecting a first string and a second string identical to a portion of the first string among the group of strings; and deleting the second string from the group of strings.
According to a fifth aspect of the present invention, there is provided a string handling method for handling a string in an information processing apparatus having a storage storing a group of strings including a plurality of strings each of which consists of a plurality of pieces of character data, the method including: referring to a particular string in the group of strings; detecting a first string and a second string whose front-end string including the first piece of character data is identical to a back-end string of the first string including the last piece of character data among the group of strings; and concatenating in the group of strings the first string with the second string by unifying the back-end string with the front-end string.
BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS
In the following, a description will be provided of the present invention through an embodiment of the present invention. However, the following embodiments do not restrict the invention in the scope of the invention and all combinations of features explained in the embodiment are not always essential to means of the invention for solving the problems.
As will be appreciated by one skilled in the art, the present invention may be embodied as a method, system, or computer program product. Accordingly, the present invention may take the form of a computer program product on a computer-usable storage medium having computer-usable program code embodied in the medium.
Any suitable computer usable or computer readable medium may be utilized. The computer-usable or computer-readable medium may be, for example but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, device, or propagation medium. More specific examples (a non-exhaustive list) of the computer-readable 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, or a magnetic storage device.
Embodiments of the present invention will be described with reference to the accompanying drawings. In the description of the embodiments that follows, like elements are labeled like reference numeral and the description of which will be omitted or simplified.
1. First Embodiment
The input unit 10 receives an input from a user and provides the input information to the control unit 40. The input unit 10 may be a keyboard and/or mouse, for example.
The output unit 20 outputs the result of processing performed by the information processing apparatus 1. The output unit 20 may be a CRT or liquid-crystal display.
The storage 30 stores an OS (operating system), middleware, and application programs as well as char array objects as strings. The storage 30 may be a memory of the computer.
The header of each of the char array objects ch_A[ ]-ch_E[ ] contains information about each object that is internally used by the information processing apparatus 1. Each header stores information such as the size of each of the char array object ch_A[ ]-ch_E[ ]. For example, the header of the char array object ch_A[ ] stores the size information “16”.
The char array object ch_A[ ] includes char data ch_A[0]-ch_A[15], which is character data. Similarly, the char array objects ch_B[ ]-ch_E[ ] include char data ch_B[0]-chB[13], ch_C[0]-ch_C[6], ch_D[0]-ch_D[10], and ch_E[0]-ch_E[12], respectively. For example the char data ch_B[8] of the char array object ch_B[ ] is “a”.
Returning to
The reference section 41 refers to the string represented by a String object as a particular string among a group of char array objects.
As shown in
The header of the String object indicates that the object is a String object.
The data section of the String object points to one char array object. In particular, the data section of the String object st_A represents the char array object ch_A[ ] containing the string “importance” represented by the String object st_A. The string represented by the String object is a portion of the char array object the location of which is represented by the remaining two values.
The start section of the String object represents the position in the char array object containing the string represented by the String object at which reference to the string represented by the String object starts. Specifically, the start section of the String object st_A represents “4”.
The length section of the String object represents the number of pieces of char data referenced as the string represented by the String object in the char array object containing the string represented by the String object. Specifically, the length section of the String object st_A represents the number of pieces of char data ch_A[4]-ch_A[13], that is, “10”.
Implementations other than the implementation described above may also be used as long as they enable a portion of char data of a char array object to be a string represented by a String object. For example, instead of the value of length, an index value of the last char data referred to may be held (“13” in the case of st_A).
Returning to
The list generating section 421 checks the storage 30 to determine which object refers to a char array in the storage 30, marks strings used as strings in the char data that are represented by String objects, and lists them by char array. In the example in
If a char array object is referred to by an object other than a String object, the char array object cannot be altered and therefore may be excluded from the list.
The character data detecting section 422 detects char data that is not referenced as a string represented by a String object among a group of the char array objects. In the example shown in
The character data deleting section 423 deletes the detected char data from the char array object. In the example shown in
The string reorganizing section 424 alters the char array object in response to the deletion of the char data by the character data deleting section 423 and reorganizes the String object. In the example shown in
Operation of the information processing apparatus 1 described above will be described with reference to
At step S203, determination is made as to whether deletion of char data that is not referenced as the string represented by the String object from the char array object is requested. If determination at step S203 is “Yes”, the process proceeds to step S301; otherwise, the process returns to step S201.
At step S301, each char array is checked for a group of char data used as strings represented by String objects and a group of String objects that reference the char array and they are listed. Then the process proceeds to step S302. If a char array object is referred to by an object other then a String object, the char array object is not listed and excluded from the subsequent processing.
At step S302, char data that is not referenced as a string represented by the String object in the char array object is detected and then the process proceeds to step S303.
At step S303, the char data detected at step S302 is deleted from the char array object and the char array object is reorganized, then the process proceeds to step S304. At step S304, the String object is reorganized.
Since the information processing apparatus 1 according to the first embodiment includes the reference section 41 as has been described above, a string represented by a String object in the char array object stored in the storage 30 can be referred to. Furthermore, the information processing apparatus 1 can detects char data that is not referenced as a string represented by a String object in the char array object stored in the storage 30 and can delete the detected char data. In this way, char data that is not referenced as a string represented by a String object can be deleted from a char array object to reduce the amount of data stored in the storage 30.
GC can generate a mark table that summarizes the referential relation between objects and can detect an object that is not referenced by any object on the basis of the mark table. By checking for char data that is not referenced as a string of a String object in that process, the efficiency of the listing at step S301 can be improved.
GC typically has a mechanism capable of searching for a group of objects referencing the objects in order to cause objects that have not been collected to operate. Techniques such as reverse pointer chasing can be used as the mechanism. The arrangement for recording a group of String objects that reference char array objects in the list generated at step S301 can use this mechanism to improve the efficiency of the recording.
Steps S301 through S304 for deleting char data that is not referenced as a string represented by the String object from the char array object may be performed on all char array objects at a time or may be performed on each char array object individually. That is, the sequence of the steps can be performed on each char array object independently.
Information about a group of char data used in each char array in the list generated by the list generating section 421 may be simplified down to the index value of the first char data and the index value of the last char data in the char date of the char array object. With this, if char data that is not used exists in between, the char data cannot be deleted but, on the other hand, the amount of data listed is reduced and therefore the memory space consumed for storing the list can be reduced.
2. Second Embodiment
The control unit 40A of the information processing apparatus 1A includes a reference section 41 and a deleting section 42A. The deleting section 42A includes a string ordering section 425, a string detecting section 426, a string deleting section 427, and a string reorganizing section 424A.
Returning to
The string detecting section 426 detects a first string and a second string that is identical to the first string in a group of char array objects. In the example shown in
The string deleting section 427 deletes a char array object containing the second string described above from the group of char array objects. In the example in
The string reorganizing section 424A reorders the String object in response to the deletion of the second string by the string deleting section 427. In the example shown in
Operation of the information processing apparatus 1A will be described with reference to
At step S403, the char array object containing the second string is deleted from the group of char array objects and then the process proceeds to step S404. At step S404, the String object is reorganized.
It should be noted that deletion of the char array object containing the second string at step S403 may be omitted and only the reorganization of the String object at step S404 may be performed. The reorganization eliminates the objects referencing the char array object containing the second string, and the objects can be collected by conventional GC.
Since the information processing apparatus 1A according to the second embodiment includes the deleting section 42A as has been described above, a first string and a second string identical to the first string can be detected from a group of char array objects stored in the storage 30 and the char array object that contains the second string can be deleted. In this way, the number of redundant strings can be reduced and the amount of data stored in the storage 30 can be reduced accordingly.
Third Embodiment
A control unit 40B of the information processing apparatus 1B includes a reference section 41 and a deleting section 42B. The deleting section 42B includes a string detecting section 426A, a string deleting section 427, and a string reorganizing section 424A.
Returning to
The string deleting section 427 deletes the second string. For example, it deletes the char array object ch_C[ ] as the second string in
The string reorganizing section 424A reorganizes the String object in response to the deletion of the second string by the string deleting section 427. In the example in
Operation of the information processing apparatus 1B descried above will be described with reference to
At step S503, the char array object that contains the second string is deleted from the group of char array objects and then the process proceeds to step S504, where the String object is reorganized.
It should be noted that the deletion of the char array object containing the second string at step S503 may be omitted and only the reorganization of the String object at step S504 may be performed. The reorganization eliminates the object that references the char array object containing the second string, and the object can be collected by using conventional GC.
Since the information processing apparatus 1B according to the third embodiment includes the deleting section 42B as has been described above, a first string and a second string identical to a portion of the first string can be detected among the char array objects stored in the storage 30 and the char array object that contains the second string can be deleted. In this way, the number of redundant strings can be reduced, thereby reducing the amount of data stored in the storage 30.
Fourth Embodiment
A control unit 40C of the information processing apparatus 1C includes a reference section 41 and a deleting section 42C. The deleting section 42C includes a string detecting section 426B, a string concatenating section 428, and a string reorganizing section 424A.
Returning to
The string concatenating section 428 concatenates the first string with the second string by consolidating the front-end string and the back-end string into one. In the example in
The string reorganizing section 424A reorganizes the char array object in response to the concatenation of the strings by the string concatenating section 428. For example, the string reorganizing section 424A modifies the data sections of the String objects st_I and st_J in
Operation of the information processing apparatus 1C will be described with reference to
At step S603, the front-end string and the back-end string are unified to concatenate the first string with the second string. Then, the process proceeds to step S604, where the String object is reorganized.
Since the information processing apparatus 1C according to the fourth embodiment includes the deleting section 42C as has been described, a first string and a second string whose front-end string is identical to the back-end string of the first string can be detected among a group of char array objects stored in the storage 30 and concatenated by unifying the front-end string with the back-end string. Thus, the number of overlapping strings can be reduced and therefore the amount of data stored in the storage 30 can be reduced.
While the present invention has been described with respect to preferred embodiments thereof, the technical scope of the present invention is not limited to the embodiments described above. Various modifications and improvements can be made to the embodiments described above. It will be apparent from the Claims that such modified or improved embodiments are also fall within the technical scope of the present invention. For example, the present invention may be a combination of features of any of the embodiments described above.
As mentioned above, the present invention can be implemented by a program on any of the information processing apparatuses 1, 1A, 1B, and 1C. The storage medium storing the program may be an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system (or apparatus or equipment) or a propagation medium. Examples of the computer-readable medium include a semiconductor or solid state storage device, a magnetic tape, a removable computer diskette, a random access memory (RAM), a read-only memory (ROM), a rigid magnetic disk, and an optical disc. Examples of the optical disk as of this point in time include a compact-disc read-only memory (CD-ROM), a compact-disc read/write (CD-R/W), and a DVD.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used herein, the singular forms “a”, “an” and “the” are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms “comprises” and/or “comprising,” when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
The corresponding structures, materials, acts, and equivalents of all means or step plus function elements in the claims below are intended to include any structure, material, or act for performing the function in combination with other claimed elements as specifically claimed. The description of the present invention has been presented for purposes of illustration and description, but is not intended to be exhaustive or limited to the invention in the form disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the invention. The embodiment was chosen and described in order to best explain the principles of the invention and the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated.
Having thus described the invention of the present application in detail and by reference to embodiments thereof, it will be apparent that modifications and variations are possible without departing from the scope of the invention defined in the appended claims.
Claims
1. A string handling method embodied in a computer readable medium for handling a character array in an information processing apparatus, the information processing apparatus having a storage storing a group of character array objects, each of the character array objects consisting of a plurality of pieces of character data, the method comprising:
- referring to a string of a string object in the group of character array objects; and
- deleting a given piece of character data and character array object from the group of character array objects when garbage collection is performed.
2. A string handling method for handling a string in an information processing apparatus having a storage storing a group of strings including a plurality of strings each of which consists of a plurality of pieces of character data, the method comprising:
- referring to a particular string in the group of strings;
- detecting a piece of character data that is not referenced as the particular string among the group of strings; and
- deleting the detected piece of character data from the group of strings.
3. A string handling method for handling a string in an information processing apparatus having a storage storing a group of strings including a plurality of strings each of which consists of a plurality of pieces of character data, the method comprising:
- referring to a particular character string in the group of strings;
- reordering the plurality of strings in accordance with the plurality of pieces of character data;
- detecting a first string and a second string identical to the first string in a group of strings including the reordered plurality of strings; and
- deleting the second string from the group of strings including the reordered plurality of strings.
4. A string handling method for handling a string in an information processing apparatus having a storage storing a group of strings including a plurality of strings each of which consists of a plurality of pieces of character data, the method comprising:
- referring to a particular string in the group of strings;
- detecting a first string and a second string identical to a portion of the first string among the group of strings; and
- deleting the second string from the group of strings.
5. A string handling method for handling a string in an information processing apparatus having a storage storing a group of strings including a plurality of strings each of which consists of a plurality of pieces of character data, the method comprising:
- referring to a particular string in the group of strings;
- detecting a first string and a second string whose front-end string including the first piece of character data is identical to a back-end string of the first string including the last piece of character data among the group of strings; and
- concatenating in the group of strings the first string with the second string by unifying the back-end string with the front-end string.
6. A computer program embodied in a computer readable medium for causing a computer having a storage storing a group of strings including a plurality of strings each of which consists of a plurality of pieces of character data to handle the strings, the computer program causing the computer to perform the steps of:
- referring to a particular string in the group of strings;
- detecting a piece of character data that is not referenced as the particular string among the group of strings; and
- deleting the detected piece of character data from the group of strings.
7. The computer program according to claim 6, causing the computer to perform, instead of the detecting step and the deleting step, the steps of:
- reordering the plurality of strings in accordance with the plurality of pieces of character data;
- detecting a first string and a second string identical to the first string in a group of strings including the reordered plurality of strings; and
- deleting the second string from the group of strings including the reordered plurality of strings.
8. The computer program according to claim 7, causing the computer to perform, instead of the detecting step, the step of:
- detecting a first string and a second string identical to a portion of the first string among the group of strings.
9. The computer program according to claim 7, causing the computer to perform, instead of the detecting step and the deleting step, the steps of:
- detecting a first string and a second string whose front-end string including the first piece of character data is identical to a back-end string of the first string including the last piece of character data among the group of strings; and
- concatenating in the group of strings the first string with the second string by unifying the back-end string with the front-end string.
10. An information processing apparatus including storage, the storage storing a group of strings including a plurality of strings each of which consists of a plurality of pieces of character data and handles the strings, the apparatus comprising:
- a reference section referring to a particular string in the group of strings;
- a first detecting section detecting a piece of character data that is not referenced as the particular string among the group of strings; and
- a first deleting section deleting the detected piece of character data from the group of strings.
11. The information processing apparatus according to claim 10, comprising, instead of the first detecting section and the first deleting section:
- a reordering section reordering the plurality of strings in accordance with the plurality of pieces of character data;
- a second detecting section detecting a first string and a second string identical to the first string in a group of strings including the reordered plurality of strings; and
- a second deleting section deleting the second string from the group of strings including the reordered plurality of strings.
12. The information processing apparatus according to claim 11, comprising, instead of the second detecting section:
- a third detecting section detecting a first string and a second string identical to a portion of the first string among the group of strings.
13. The information processing apparatus according to claim 11, comprising, instead of the second detecting section and the second deleting section:
- a fourth detecting section detecting a first string and a second string whose front-end string including the first piece of character data is identical to a back-end string of the first string including the last piece of character data among the group of strings; and
- a concatenating section concatenating in the group of strings the first string with the second string by unifying the back-end string with the front-end string.
Type: Application
Filed: Dec 8, 2006
Publication Date: Jun 21, 2007
Inventors: Kiyokuni Kawachiya (Yokohama-shi), Kazunori Ogata (Fujisawa-shi), Tamiya Onodera (Tokyo)
Application Number: 11/608,795
International Classification: G06F 17/30 (20060101);