[go: up one dir, main page]

AU2005236088B2 - Modified computer architecture with finalization of objects - Google Patents

Modified computer architecture with finalization of objects Download PDF

Info

Publication number
AU2005236088B2
AU2005236088B2 AU2005236088A AU2005236088A AU2005236088B2 AU 2005236088 B2 AU2005236088 B2 AU 2005236088B2 AU 2005236088 A AU2005236088 A AU 2005236088A AU 2005236088 A AU2005236088 A AU 2005236088A AU 2005236088 B2 AU2005236088 B2 AU 2005236088B2
Authority
AU
Australia
Prior art keywords
computers
computer
index
application program
public
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
AU2005236088A
Other versions
AU2005236088A1 (en
Inventor
John Matthew Holt
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Waratek Pty Ltd
Original Assignee
Waratek Pty Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Priority claimed from AU2004902146A external-priority patent/AU2004902146A0/en
Application filed by Waratek Pty Ltd filed Critical Waratek Pty Ltd
Priority to AU2005236088A priority Critical patent/AU2005236088B2/en
Priority claimed from PCT/AU2005/000581 external-priority patent/WO2005103927A1/en
Publication of AU2005236088A1 publication Critical patent/AU2005236088A1/en
Application granted granted Critical
Publication of AU2005236088B2 publication Critical patent/AU2005236088B2/en
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Landscapes

  • Stored Programmes (AREA)

Description

WO 2005/103927 PCTIAU2005000581 MODIFIED COMPUTER ARCHITECTURE WITH FINALIZATION OF OBJECTS Field of the Invention The present invention relates to computers and, in particular, to a modified machine architecture which enables the operation of an application program simultaneously on a plurality of computers interconnected via a communications network.
Background Art Ever since the advent of computers, and computing, software for computers has been written to be operated upon a single machine. As indicated in Fig. 1, that single prior art machine 1 is made up from a central processing unit, or CPU, 2 which is connected to a memory 3 via a bus 4. Also connected to the bus 4 are various other functional units of the single machine 1 such as a screen 5, keyboard 6 and mouse 7.
A fundamental limit to the performance of the machine 1 is that the data to be manipulated by the CPU 2, and the results of those manipulations, must be moved by the bus 4. The bus 4 suffers from a number of problems including so called bus "queues" formed by units wishing to gain an access to the bus, contention problems, and the like. These problems can, to some extent, be alleviated by various stratagems including cache memory, however, such stratagems invariably increase the administrative overhead of the machine I.
Naturally, over the years various attempts have been made to increase machine performance. One approach is to use symmetric multiple processors. This prior art approach has been used in so called "super" computers and is schematically indicated in Fig. 2. Here a plurality of CPU's 12 are connected to global memory 13. Again, a bottleneck arises in the communications between the CPU's 12 and the memory 13.
This process has been termed "Single System Image". There is only one application and one whole copy of the memory for the application which is distributed over the global memory. The single application can read from and write to, (ie share) any memory location completely transparently.
Where there are a number of such machines interconnected via a network, this is achieved by taking the single application written for a single machine and WO 2005/103927 PCT/AU20051000581 partitioning the required memory resources into parts. These parts are then distributed across a number of computers to form the global memory 13 accessible by all CPU's 12. This procedure relies on masking, or hiding, the memory partition from the single running application program. The performance degrades when one CPU on one machine must access (via a network) a memory location physically located in a different machine.
Although super computers have been technically successful in achieving high computational rates, they are not commercially successful in that their inherent complexity makes them extremely expensive not only to manufacture but to administer. In particular, the single system image concept has never been able to scale over "commodity" (or mass produced) computers and networks. In particular, the Single System Image concept has only found practical application on very fast (and hence very expensive) computers interconnected by very fast (and similarly expensive) networks.
A further possibility of increased computer power through the use of a plural number of machines arises from the prior art concept of distributed computing which is schematically illustrated in Fig. 3. In this known arrangement, a single application program (Ap) is partitioned by its author (or another programmer who has become familiar with the application program) into various discrete tasks so as to run upon, say, three machines in which case n in Fig. 3 is the integer 3. The intention here is that each of the machines M1...M3 runs a different third of the entire application and the intention is that the loads applied to the various machines be approximately equal.
The machines communicate via a network 14 which can be provided in various forms such as a communications link, the internet, intranets, local area networks, and the like. Typically the speed of operation of such networks 14 is an order of magnitude slower than the speed of operation of the bus 4 in each of the individual machines M1, M2, etc.
Distributed computing suffers from a number of disadvantages. Firstly, it is a difficult job to partition the application and this must be done manually. Secondly, communicating data, partial results, results and the like over the network 14 is an administrative overhead. Thirdly, the need for partitioning makes it extremely PCT/AU2005/00 0 5 81 Received 16 September 2005 difficult to scale upwardly by utilising more machines since the application having been partitioned into, say three, does not nm well upon four machines. Fourthly, in the event that one of the machines should become disabled, the overall performance of the entire system is substantially degraded.
A further prior art arrangement is known as network computing via "clusters" as is schematically illustrated in Fig. 4. In this approach, the entire application is loaded onto each of the machines Ml, M2 Mn. Each machine communicates with a common database but does not communicate directly with the other machines.
Although each machine runs the same application, each machine is doing a different '"job" and uses only its own memory, This is somewhat analogous to a number of windows each of which sell train tickets to the public. This approach does operate, is scalable and mainly suffers from the disadvantage that it is difficult to administer the network.
In computer languages such as JAVA and MICROSOFT.NET there are two major types of constructs with which programmers deal. In the JAVA language these are known as objects and classes. Every time an object is created there is an initialization routine run known as Similarly, every time a class is loaded there is an initialization routine known as "<clinit>". Other languages use different terms but utilize a similar concept. However, there is no equivalent "clean up" or deletion routine to delete an object or class once it is no longer required. Instead, this "clean up" happens unobtrusively in a background mode.
The present invention discloses a computing environment in which an application program operates simultaneously on a plurality of computers. In such an environment it is necessary to ensure that the "clean up" (or deletion or finalisation) operates in a consistent fashion across all the machines. It is this goal of consistent finalization that is the genesis of the present invention.
In accordance with a first aspect of the present invention there is disclosed a multiple computer system having at least one application program each written to operate only on a single computer but running simultaneously on a plurality of computers interconnected by a communications network, wherein different portions 3 5027D-WO AMED-.z SH lPBA-- PCT/AU2005/000581 Received 16 September 2005 of said application program(s) execute substantially simultaneously on different ones of said computers and for each said portion a like plurality of substantially identical objects are created, each in the corresponding computer and each having a substantially identical name, and wherein all said identical objects are collectively deleted when each one of said plurality of computers no longer needs to refer to their corresponding object.
In accordance with a second aspect of the present invention there is disclosed a plurality of computers interconnected via a communications link and operating simultaneously at least one application program each written to operate only on a single computer, wherein each said computer substantially simultaneously executes a different portion of said application program(s), each said computer in operating its application program portion needs, or no longer needs to refer to an object only in local memory physically located in each said computer, the contents of the local memory utilized by each said computer is funimdamentally similar but not, at each instant, identical, and every one of said computers has a finalization routine which deletes a non-referenced object only if each one of said plurality of computers no longer needs to refer to their corresponding object.
In accordance with a third aspect of the present invention there is disclosed a method of running simultaneously on a plurality of computers at least one application program each written to operate only on a single computer,, said computers being intercomnnected by means of a communications network, said method comprising the steps of: executing different portions of said application program(s) on different ones of said computers and for each said portion creating a like phlurality of substantially identical objects each in the corresponding computer and each having a substantially identical name, and (ii) deleting all said identical objects collectively when all of said plurality of computers no longer need to refer to their corresponding object.
In accordance with a fourth aspect of the present invention there is disclosed a method of ensuring consistent finalization of an application program written to operate only on a signle computer but different portions of which are to be executed substantially simultaneously each on a different one of a plurality of computers interconnected via a communications network, said method comprising the steps of: 4 5027D-WO AMEi IPFJV AU PCT/AU2005/0005 8 1 Received 16 September 2005 scrutinizing said application program at, or prior to, or after loading to detect each program step defining an finalization routine, and (ii) modifying said finalization routine to ensure collective deletion of corresponding objects in all said computers only when each one of said computers no longer needs to refer to their corresponding object.
In accordance with a fifth aspect of the present invention there is disclosed a method a multiple thread processing computer operation in which individual threads of a single application program written to operate only on a single computer are simultaneously being processed each on a corresponding different one of a plurality of computers interconnected via a communications link, and in which objects in local memory physically associated with the computer processing each thread have corresponding objects in the local memory of each other said computer, the improvement comprising collectively deleting all said corresponding objects when each one of said plurality of computers no longer needs to refer to their corresponding object, In accordance with a sixth aspect of the present invention there is disclosed a computer program product comprising a set of program instructions stored in a storage medium and operable to permit a plurality of computers to carry out the abovementioned methods.
BriefDescription of the Drawings Embodiments of the present invention will now be described with reference to the drawings in which: Fig. I is a schematic view of the internal architecture of a conventional computer, Fig. 2 is a schematic illustration showing the internal architecture of known symmetric multiple processors, Fig. 3 is a schematic representation of prior art distributed computing, Fig. 4 is a schematic representation of a prior art network computing using clusters, Fig. 5 is a schematic block diagram of a plurality of machines operating the same application program in accordance with a first embodiment of the present invention, Fig. 6 is a schematic illustration of a prior art computer arranged to operate JAVA code and thereby constitute a JAVA virtual machine, Fig. 7 is a drawing sjmilar to Fig. 6 but illustrating the initial loading of code in accordance with the preferred embodiment, 5027D-WO UN I
IPU
1 WO 2005/103927 PCTIAU2005/000581 Fig. 8 is a drawing similar to Fig. 5 but illustrating the interconnection of a plurality of computers each operating JAVA code in the manner illustrated in Fig. 7, Fig. 9 is a flow chart of the procedure followed during loading of the same application on each machine in the network, Fig. 10 is a flow chart showing a modified procedure similar to that of Fig. 9, Fig. 11 is a schematic representation of multiple thread processing carried out on the machines of Fig. 8 utilizing a first embodiment of memory updating, Fig. 12 is a schematic representation similar to Fig. 11 but illustrating an alternative embodiment, Fig. 13 illustrates multi-thread memory updating for the computers of Fig. 8, Fig. 14 is a schematic illustration of a prior art computer arranged to operate in JAVA code and thereby constitute a JAVA virtual machine, Fig. 15 is a schematic representation ofn machines running the application program and serviced by an additional server machine X, Fig. 16 is a flow chart of illustrating the modification of "clean up" or finalization routines, Fig. 17 is a flow chart illustrating the continuation or abortion of finalization routines, Fig. 18 is a flow chart illustrating the enquiry sent to the server machine X, Fig. 19 is a flow chart of the response of the server machine X to the request of Fig. 18, Fig. 20 is a schematic representation of two laptop computers interconnected to simultaneously run a plurality of applications, with both applications running on a single computer, Fig. 21 is a view similar to Fig. 20 but showing the Fig. 20 apparatus with one application operating on each computer, and Fig. 22 is a view similar to Figs. 20 and 21 but showing the Fig. 20 apparatus with both applications operating simultaneously on both computers.
The specification includes Annexures A and C which provide actual code fragments which implement various aspects of the described embodiments. Annexure A relates to fields and Annexure C to finalization.
Detailed Description WO 2005/103927 PCTIAU2005/000581 In connection with Fig. 5, in accordance with a preferred embodiment of the present invention a single application program 50 can be operated simultaneously on a number of machines Ml, M2...Mn communicating via network 53. As it will become apparent hereafter, each of the machines Ml, M2.. .Mn operates with the same application program 50 on each machine Ml, M2...Mn and thus all of the machines Ml, M2...Mn have the same application code and data 50. Similarly, each of the machines Ml, Mn operates with the same (or substantially the same) modifier 51 on each machine M1, M2...Mn and thus all of the machines M1, M2...Mn have the same (or substantially the same) modifier 51 with the modifier of machine M2 being designated 51/2. In addition, during the loading of, or preceding the execution of, the application 50 on each machine Ml, M2...Mn, each application 50 has been modified by the corresponding modifier 51 according to the same rules (or substantially the same rules since minor optimising changes are permitted within each modifier 51/1 51/n).
As a consequence of the above described arrangement, if each of the machines Ml, M2...Mn has, say, a shared memory capability of 10MB, then the total shared memory available to each application 50 is not, as one might expect, 10n MB but rather only 10MB. However, how this results in improved operation will become apparent hereafter. Naturally, each machine M1, M2...Mn has an unshared memory capability. The unshared memory capability of the machines Ml, M2.. .Mn are normally approximately equal but need not be.
It is known from the prior art to operate a machine (produced by one of various manufacturers and having an operating system operating in one of various different languages) in a particular language of the application, by creating a virtual machine as schematically illustrated in Fig. 6. The prior art arrangement of Fig. 6 takes the form of the application 50 written in the Java language and executing within a Java Virtual Machine 61. Thus, where the intended language of the application is the language JAVA, a JAVA virtual machine is created which is able to operate code in JAVA irrespective of the machine manufacturer and internal details of the machine.
For further details see "The JAVA Virtual Machine Specification" 2 d Edition by T.
Lindholm F. Yellin of Sun Microsystems Inc. of the USA.
WO 2005/103927 PCT/AU20051000581 This well known prior art arrangement of Fig. 6 is modified in accordance with the preferred embodiment of the present invention by the provision of an additional facility which is conveniently termed "distributed run time" or DRT 71 as seen in Fig. 7. In Fig. 7, the application 50 is loaded onto the Java Virtual Machine 72 via the distributed runtime system 71 through the loading procedure indicated by arrow 75. A distributed run time system is available from the Open Software Foundation under the name of Distributed Computing Environment (DCE). In particular, the distributed runtime 71 comes into operation during the loading procedure indicated by arrow 75 of the JAVA application 50 so as to initially create the JAVA virtual machine 72. The sequence of operations during loading will be described hereafter in relation to Fig. 9.
Fig. 8 shows in modified form the arrangement of Fig. 5 utilising JAVA virtual machines, each as illustrated in Fig. 7. It will be apparent that again the same application 50 is loaded onto each machine Ml, M2...Mn. However, the communications between each machine Ml, M2.. .Mn, and indicated by arrows 83, although physically routed through the machine hardware, are controlled by the individual DRT's 71/1...71/n within each machine. Thus, in practice this may be conceptionalised as the DRT's 71/1.. .71/n communicating with each other via the network 73 rather than the machines MI, M2...Mn themselves.
Turning now to Figs. 7 and 9, during the loading procedure 75, the program being loaded to create each JAVA virtual machine 72 is modified. This modification commences at 90 in Fig. 9 and involves the initial step 91 of detecting all memory locations (termed fields in JAVA but equivalent terms are used in other languages) in the application 50 being loaded. Such memory locations need to be identified for subsequent processing at steps 92 and 93. The DRT 71 during the loading procedure creates a list of all the memory locations thus identified, the JAVA fields being listed by object and class. Both volatile and synchronous fields are listed.
The next phase (designated 92 in Fig. 9) of the modification procedure is to search through the executable application code in order to locate every processing activity that manipulates or changes field values corresponding to the list generated at step 91 and thus writes to fields so the value at the corresponding memory location is WO 2005/103927 PCT/AU20051000581 changed. When such an operation (typically putstatic or putfield in the JAVA language) is detected which changes the field value, then an "updating propagation routine" is inserted by step 93 at this place in the program to ensure that all other machines are notified that the value of the field has changed. Thereafter, the loading procedure continues in a normal way as indicated by step 94 in Fig. 9.
An alternative form of initial modification during loading is illustrated in Fig. 10. Here the start and listing steps 90 and 91 and the searching step 92 are the same as in Fig. 9. However, rather than insert the "updating propagation routine" as in step 93 in which the processing thread carries out the updating, instead an "alert routine" is inserted at step 103. The "alert routine" instructs a thread or threads not used in processing and allocated to the DRT, to carry out the necessary propagation.
This step 103 is a quicker alternative which results in lower overhead.
Once this initial modification during the loading procedure has taken place, then either one of the multiple thread processing operations illustrated in Figs. 11 and 12 takes place. As seen in Fig. 11, multiple thread processing 110 on the machines consisting of threads 111/1... 111/4 is occurring and the processing of the second thread 111/2 (in this example) results in that thread 111/2 becoming aware at step 113 of a change of field value. At this stage the normal processing of that thread 111/2 is halted at step 114, and the same thread 111/2 notifies all other machines M2...Mn via the network 53 of the identity of the changed field and the changed value which occurred at step 113. At the end of that communication procedure, the thread 111/2 then resumes the processing at step 115 until the next instance where there is a change of field value.
In the alternative arrangement illustrated in Fig. 12, once a thread 121/2 has become aware of a change of field value at step 113, it instructs DRT processing 120 (as indicated by step 125 and arrow 127) that another thread(s) 121/1 allocated to the DRT processing 120 is to propagate in accordance with step 128 via the network 53 to all other machines M2...Mn the identity of the changed field and the changed value detected at step 113. This is an operation which can be carried out quickly and thus the processing of the initial thread 111/2 is only interrupted momentarily as indicated in step 125 before the thread 111/2 resumes processing in step 115. The other thread WO 2005/103927 PCTIAU2005/000581 121/1 which has been notified of the change (as indicated by arrow 127) then communicates that change as indicated in step 128 via the network 53 to each of the other machines M2.. .Mn.
This second arrangement of Fig. 12 makes better utilisation of the processing power of the various threads 111/1... 111/3 and 121/1 (which are not, in general, subject to equal demands) and gives better scaling with increasing size of (n being an integer greater than or equal to 2 which represents the total number of machines which are connected to the network 53 and which run the application program 50 simultaneously). Irrespective of which arrangement is used, the changed field and identities and values detected at step 113 are propagated to all the other machines M2.. .Mn on the network.
This is illustrated in Fig. 13 where the DRT 71/1 and its thread 121/1 of Fig.
12 (represented by step 128 in Fig. 13) sends via the network 53 the identity and changed value of the listed memory location generated at step 113 of Fig. 12 by processing in machine Ml, to each of the other machines M2.. .Mn.
Each of the other machines M2.. .Mn carries out the action indicated by steps 135 and 136 in Fig. 13 for machine Mn by receiving the identity and value pair from the network 53 and writing the new value into the local corresponding memory location.
In the prior art arrangement in Fig. 3 utilising distributed software, memory accesses from one machine's software to memory physically located on another machine are permitted by the network interconnecting the machines. However, such memory accesses can result in delays in processing of the order of 106 10 7 cycles of the central processing unit of the machine. This in large part accounts for the diminished performance of the multiple interconnected machines.
However, in the present arrangement as described above in connection with Fig. 8, it will be appreciated that all reading of data is satisfied locally because the current value of all fields is stored on the machine carrying out the processing which generates the demand to read memory. Such local processing can be satisfied within WO 2005/103927 PCTIAU2005/000581 2 -103 cycles of the central processing unit. Thus, in practice, there is substantially no waiting for memory accesses which involves reads.
However, most application software reads memory frequently but writes to memory relatively infrequently. As a consequence, the rate at which memory is being written or re-written is relatively slow compared to the rate at which memory is being read. Because of this slow demand for writing or re-writing of memory, the fields can be continually updated at a relatively low speed via the inexpensive commodity network 53, yet this low speed is sufficient to meet the application program's demand for writing to memory. The result is that the performance of the Fig. 8 arrangement is vastly superior to that of Fig. 3.
In a further modification in relation to the above, the identities and values of changed fields can be grouped into batches so as to further reduce the demands on the communication speed of the network 53 interconnecting the various machines.
It will also be apparent to those skilled in the art that in a table created by each DRT 71 when initially recording the fields, for each field there is a name or identity which is common throughout the network and which the network recognises.
However, in the individual machines the memory location corresponding to a given named field will vary over time since each machine will progressively store changed field values at different locations according to its own internal processes. Thus the table in each of the DRTs will have, in general, different memory locations but each global "field name" will have the same "field value" stored in the different memory locations.
It will also be apparent to those skilled in the art that the abovementioned modification of the application program during loading can be accomplished in up to five ways by: re-compilation at loading, (ii) by a pre-compilation procedure prior to loading, (iii) compilation prior to loading, (iv) a "just-in-time" compilation, or re-compilation after loading (but, or for example, before execution of the relevant or corresponding application code in a distributed environment).
WO 2005/103927 PCTIAU2005/000581 Traditionally the term "compilation" implies a change in code or language, eg from source to object code or one language to another. Clearly the use of the term "compilation" (and its grammatical equivalents) in the present specification is not so restricted and can also include or embrace modifications within the same code or language.
In the first embodiment, a particular machine, say machine M2, loads the application code on itself, modifies it, and then loads each of the other machines M1, M3 Mn (either sequentially or simultaneously) with the modified code. In this arrangement, which may be termed "master/slave", each of machines Ml, M3, Mn loads what it is given by machine M2.
In a still further embodiment, each machine receives the application code, but modifies it and loads the modified code on that machine. This enables the modification carried out by each machine to be slightly different being optimized based upon its architecture and operating system, yet still coherent with all other similar modifications.
In a further arrangement, a particular machine, say Ml, loads the unmodified code and all other machines M2, M3 Mn do a modification to delete the original application code and load the modified version.
In all instances, the supply can be branched (ie M2 supplies each of Ml, M3, M4, etc directly) or cascaded or sequential (ie M2 applies Ml which then supplies M3 which then supplies M4, and so on).
In a still further arrangement, the machines Ml to Mn, can send all load requests to an additional machine (not illustrated) which is not running the application program, which performs the modification via any of the aforementioned methods, and returns the modified routine to each of the machines Ml to Mn which then load the modified routine locally. In this arrangement, machines M1 to Mn forward all load requests to this additional machine which returns a modified routine to each WO 2005/103927 PCT/AU20051000581 machine. The modifications performed by this additional machine can include any of the modifications covered under the scope of the present invention.
Persons skilled in the computing arts will be aware of at least four techniques used in creating modifications in computer code. The first is to make the modification in the original (source) language. The second is to convert the original code (in say JAVA) into an intermediate representation (or intermediate language). Once this conversion takes place the modification is made and then the conversion is reversed.
This gives the desired result of modified JAVA code.
The third possibility is to convert to machine code (either directly or via the abovementioned intermediate language). Then the machine code is modified before being loaded and executed. The fourth possibility is to convert the original code to an intermediate representation, which is then modified and subsequently converted into machine code.
The present invention encompasses all four modification routes and also a combination of two, three or even all four, of such routes.
Turning now to Fig. 14, there is illustrated a schematic representation of a single prior art computer operated as a JAVA virtual machine. In this way, a machine (produced by any one of various manufacturers and having an operating system operating in any one of various different languages) can operate in the particular language of the application program 50, in this instance the JAVA language. That is, a JAVA virtual machine 72 is able to operate code 50 in the JAVA language, and utilize the JAVA architecture irrespective of the machine manufacturer and the internal details of the machine.
In the JAVA language, the initialization routine <clinit> happens only once when a given class file 50A is loaded. However, the initialization routine <init> happens often, for example every time a new object 50X, 50Y or 50Z is created. In addition, classes are loaded prior to objects so that in the application program illustrated in Fig. 14, having a single class 50A and three objects 50X-50Z, the first WO 2005/103927 PCTIAU2005/000581 class 50A is loaded first, then first object 50X is loaded, then second object 50Y is loaded and finally third object 50Z is loaded. Where, as in Fig. 14, there is only a single computer or machine 72, then no conflict or inconsistency arises in the running of the initialization routines intended to operate during the loading procedure because for conventional operation each initialization routine is executed only once.
Furthermore, the single machine of Fig. 14 is able to easily keep track of whether the specific objects 50X-50Z are, in future, liable to be required for the program 50. This is done by maintaining a "handle count" or similar. This count keeps track of the number of places in the executable code where reference is made to a specific object. When the handle count for a specific object reaches zero, there is nowhere in the executable code which makes reference to the object. The object is then said to be "finalizable".
Once this state has been achieved, the object can be safely deleted (or cleaned up or finalized) because it is no longer needed. The same procedure applies mutatis mutandis for classes. In particular, the computer programmer when writing a program using the JAVA language and architecture, need not write any specific code in order to provide for this cleaning up, deletion or finalization. Instead a single JAVA virtual machine 72 can keep track of the class and object handle counts and clean up (or carry out finalization) as necessary in an unobtrusive fashion.
However, in the arrangement illustrated in Fig. 8, (and also in Figs. 20-22), a plurality of individual computers or machines Ml, M2 Mn are provided each of which are interconnected via a communications network 53 and each of which is provided with a modifier 51 (as in Fig. 5 and realised by the DRT 71 of Fig. 8) and loaded with a common application program 50. Essentially the modifier 51 or DRT 71 modifies the application code 50 to execute clean up routines across the plurality of individual machines Ml, M2...Mn. It follows therefore that in such a computing environment it is necessary to ensure that each of the individual machines is finalized in a consistent fashion (with respect to the others).
WO 2005/103927 PCTIAU2005/000581 In particular, whilst one particular machine (say, M3) may have no further call on an object or class, another machine (say M5) may still need to refer to that object or class in future. Thus if the object or class were to be deleted from machine M3, then if M5 were to write to that object and amend its value, then that change in value could not be propagated throughout all the machines Ml, M2.. .Mn since the machine M3 would not include the relevant object in its local memory. Furthermore, were machine M3 to execute the cleanup routine on a given object or class, the cleanup routine would preform cleanup not just for that object on that machine, but all peerobjects on all other machines as well. Thus invalidating the object on machine Thus the goal of substantially identical memory contents for each of the machines Ml, M2...Mn, as required for simultaneous operation of the same application program, would not be achieved.
In order to ensure consistent finalization, or clean up, the application program is scrutinized in order to detect program steps which define a clean up routine.
This scrutiny can take place either prior to loading, or during the loading procedure, or even after the loading procedure (but before execution of the relevant corresponding portion of the application code 50). It may be likened to a compilation procedure with the understanding that the term compilation normally involves a change in code or language, eg from source to object code or one language to another.
However, in the present instance the term "compilation" (and its grammatical equivalents) is not so restricted and can also include embrace modifications within the same code or language.
As a consequence, in the abovementioned scrutiny clean up routines are initially looked for, and when found a modifying code is inserted so as to give rise to a modified clean up routine. This modified routine is to abort the clean up routine on any specific machine unless the class or object to be deleted is marked for deletion by all other machines. There are several different modes whereby this modification and loading can be carried out.
Thus, in one mode, the DRT 71/1 on the loading machine, in this example JVM#1, asks the DRT's 71/2...71/n of all the other machines M2...Mn if the first object 50X, say, is utilized (ie not marked for deletion) by any other machine WO 2005/103927 PCTIAU2005/000581 M2...Mn. If the answer to this question is yes, then the normal clean up procedure is turned off or disabled for the first object 50X on machine JVM#1. If the answer is no, (ie the first object 50X is marked for deletion on all other machines) then the normal clean up procedure is operated and the first object 50X is deleted not only on machine JVM#1 but on all other machines M2...Mn. Preferably the clean up task is allocated to the last machine Ml marking the object or class for deletion.
As seen in Fig. 15 a modification to the general arrangement of Fig. 8 is provided in that machines Ml, M2.. .Mn are as before and run the same application program 50 (or programmes) on all machines Ml, M2...Mn simultaneously.
However, the previous arrangement is modified by the provision of a server machine X which is conveniently able to supply housekeeping functions, for example, and especially the clean up of structures, assets and resources. Such a server machine X can be a low value commodity computer such as a PC since its computational load is low. As indicated by broken lines in Fig. 15, two server machines X and X+I can be provided for redundancy purposes to increase the overall reliability of the system.
Where two such server machines X and X+ 1 are provided, they are preferably operated as dual machines in a cluster.
It is not necessary to provide a server machine X as its computational load can be distributed over machines Ml, M2.. .Mn. Alternatively, a database operated by one machine (in a master/slave type operation) can be used for the housekeeping function(s).
Fig. 16 shows a preferred general procedure to be followed. After loading 161 has been commenced, the instructions to be executed are considered in sequence and all clean up routines are detected as indicated in step 162. In the JAVA language these are the "finalize( routine (or method in JAVA terminology). Other languages use different terms.
Where a clean up routine is detected, it is modified at step 163, typically by inserting further instructions into the routine. Alternatively, the modifying instructions could be inserted prior to the routine. Once the modification has been completed the loading procedure continues, as indicated in step 164.
WO 2005/103927 PCT/AU20051000581 Fig. 17 illustrates a particular form of modification. Firstly, the structures, assets or resources (in JAVA termed classes or objects) 50A, 50X...50Y which are possible candidates to be cleaned up, have already been allocated a name or tag which can be used globally by all machines M1, M2...Mn, as indicated by step 172. This preferably happens when the classes or objects are originally initialized. This is most conveniently done via a table maintained by server machine X. This table also includes the "clean up status" of the class or object. In the preferred embodiment, this table also includes a counter which stores a count of the number of machines which have marked this asset for deletion. Thus a total count value of less than (n-i) indicates a "do not clean up" status for the asset as a network whole.
As indicated in Fig. 17, if the global name is not marked for deletion on all other machines (ie all except on the machine proposing to carry out the clean up routine) then this means that the proposed clean up routine of the object or class should be aborted since the object or class is still required, as indicated by step 175.
However, if the global name is marked for deletion on all machines, this means that no other machine requires this class or object. As a consequence, the regular clean up routine indicated in step 176 can be, and should be, carried out.
Fig. 18 shows the enquiry made by the machine proposing to execute a clean up routine (one of M1, M2...Mn) to the server machine X. The operation of this proposing machine is temporarily interrupted, as shown in step 181 and 182, until the reply is received from machine X, indicated by step 182.
Fig. 19 shows the activity carried out by machine X in response to such an enquiry. The clean up status is determined as seen in step 192 and, if no the named resource is not marked for deletion on machines (ie is utilized elsewhere), the response to that effect is sent to the enquiring machine 194 but the "marked for deletion" counter is incremented by one as shown by step 197. Similarly, if the answer is yes the corresponding reply is sent as indicated by steps 195. The waiting enquiring machine 182 is then able to respond accordingly. As indicated by broken lines in Fig. 19, preferably in addition to the yes response shown in step 195, the shared table is updated so that the status of the globally named asset is changed to "cleaned up" as indicated by step 196.
WO 2005/103927 PCT/AU20051000581 Reference is made to the accompanying Annexure C in which: Annexure C is a typical code fragment from an unmodified finalize routine, Annexure C2 is an equivalent in respect of a modified finalize routine, and Annexure C3 is an equivalent in respect of a modified finalize routine.
Annexures Cl and C2 are the before and after excerpt of a finalize routine respectively. The modified code that is added to the method is highlighted in bold. In the original code sample of Annexure Cl, the finalize method prints "Deleted..." to the computer console on event of finalization (ie deletion) of this object. Thus, without management of object finalization in a distributed environment, each machine would re-finalize the same object, thus executing the finalize method more than once for a single globally-named object. Clearly this is not what the programmer of the application program expects to happen.
So, taking advantage of the DRT, the application code is modified as it is loaded into the machine by changing the finalize method. The changes made (highlighted in bold) are the initial instructions that the finalize method executes.
These added instructions check if this object is the last remaining object reference by calling the isLastReference() method, which returns either true or false corresponding to whether or not this object on this machine is the last of the peer objects to request finalization.
The isLastReferenceO method of the DRT can optionally take an argument which represents a unique identifier for this object (See Annexure C3), for example the name of the object, a reference to the object in question, or a unique number representing this object across all nodes, to be used in the determination of the finalization status of this class. This way, the DRT can support the finalization of multiple objects at the same time without becoming confused as to which of the multiple objects are already finalized and which are not, by using the unique identifier of each object to consult the correct record in the finalization table.
The DRT can determine the finalization state of the object in a number of ways. Preferably, it can ask each machine in turn if their local copy of this object has WO 2005/103927 PCT/AU20051000581 been marked for finalization, and if any machine replies false, then return true, otherwise false. Alternatively, the DRT on the local machine can consult a shared record table (perhaps on a separate machine (eg machine or a coherent shared record table on the local machine, or a database) to determine if this object has been marked for finalization by all machines except the current machine.
If the DRT returns false then this means that this object has been marked for finalization on all other machine in the distributed environment, and hence, the execution of the original finalize code-block is to proceed as this is considered the last remaining object reference.
On the other hand, if the DRT returns true, then this means that this object has not been marked for finalization by all other machines in the distributed environment, as recorded in the shared record table of finalized objects. In such a case, the original code block is NOT to be executed, as it will potentially invalidate the object on those machine(s) that are continuing to use the object and have yet to mark this object for finalization. Thus, when the DRT returns true, the inserted three instructions prevent execution of the original code, and return straight away to the application program.
Given the fundamental concept of testing to see a clean up is ready to be carried out, and if so carrying it out, and if not, not carrying it out, there are several different ways in which this concept can be implemented.
In the first embodiment, a particular machine, say machine M2, loads the clean up on itself, modifies it, and then loads each of the other machines Ml, M3 Mn (either sequentially or simultaneously) with the modified routine. In this arrangement, which may be termed "master/slave" each of machines Ml, M3, Mn loads what it is given by machine M2.
In a variation of this "master/slave" arrangement, machine M2 loads the clean up routine in unmodified form on machine M2 and then on the other machines deletes the clean up routine in its entirety and loads the modified code. Thus in this instance WO 2005/103927 PCTIAU2005/000581 the modification is not a by-passing of the clean up routine but a deletion of it on all machines except one.
In a still further embodiment, each machine receives the clean up routine, but modifies it and loads the modified routine on that machine. This enables the modification carried out by each machine to be slightly different being optimized based upon its architecture and operating system, yet still coherent with all other similar modifications.
In a further arrangement, a particular machine, say Ml, loads the unmodified clean up routine and all other machines M2, M3 Mn do a modification to delete the original clean up routine and load the modified version.
In all instances, the supply can be branched (ie M2 supplies each of Ml, M3, M4, etc directly) or cascaded or sequential (ie M2 applies Ml which then supplies M3 which then supplies M4, and so on).
In a still further arrangement, the machines Ml to Mn, can send all load requests to an additional machine X (of Fig. 15), which performs the modification via any of the afore mentioned methods, and returns the modified routine to each of the machines Ml to Mn which then load the modified routine locally. In this arrangement, machines Ml to Mn forward all load requests to machine X, which returns a modified routine to each machine. The modifications performed by machine X can include any of the modifications covered under the scope of the present invention.
Persons skilled in the computing arts will be aware of four techniques used in creating modifications in computer code. The first is to make the modification in the original (source) language. The second is to convert the original code (in say JAVA) into an intermediate representation (or intermediate language). Once this conversion takes place the modification is made and then the conversion is reversed. This gives the desired result of modified JAVA code.
WO 2005/103927 PCT/AU20051000581 The third possibility is to convert to machine code (either directly or via the abovementioned intermediate language). Then the machine code is modified before being loaded and executed. The fourth possibility is to convert the original code to an intermediate representation, which is then modified and subsequently converted into machine code.
The present invention encompasses all four modification routes and also a combination of two, three or even all four, of such routes.
Turning now to Figs. 20-22, two laptop computers 101 and 102 are illustrated.
The computers 101 and 102 are not necessarily identical and indeed, one can be an IBM or IBM-clone and the other can be an APPLE computer. The computers 101 and 102 have two screens 105, 115 two keyboards 106, 116 but a single mouse 107. The two machines 101, 102 are interconnected by a means of a single coaxial cable or twisted pair cable 314.
Two simple application programs are downloaded onto each of the machines 101, 102, the programs being modified as they are being loaded as described above.
In this embodiment the first application is a simple calculator program and results in the image of a calculator 108 being displayed on the screen 105. The second program is a graphics program which displays four coloured blocks 109 which are of different colours and which move about at random within a rectangular box 310. Again, after loading, the box 310 is displayed on the screen 105. Each application operates independently so that the blocks 109 are in random motion on the screen 105 whilst numerals within the calculator 108 can be selected (with the mouse 107) together with a mathematical operator (such as addition or multiplication) so that the calculator 108 displays the result.
The mouse 107 can be used to "grab" the box 310 and move same to the right across the screen 105 and onto the screen 115 so as to arrive at the situation illustrated in Fig. 21. In this arrangement, the calculator application is being conducted on machine 101 whilst the graphics application resulting in display of box 310 is being conducted on machine 102.
WO 2005/103927 PCT/AU20051000581 However, as illustrated in Fig. 22, it is possible by means of the mouse 107 to drag the calculator 108 to the right as seen in Fig. 21 so as to have a part of the calculator 108 displayed by each of the screens 105, 115. Similarly, the box 310 can be dragged by means of the mouse 107 to the left as seen in Fig. 21 so that the box 310 is partially displayed by each of the screens 105, 115 as indicated Fig. 22. In this configuration, part of the calculator operation is being performed on machine 101 and part on machine 102 whilst part of the graphics application is being carried out the machine 101 and the remainder is carried out on machine 102.
The foregoing describes only some embodiments of the present invention and modifications, obvious to those skilled in the art, can be made thereto without departing from the scope of the present invention. For example, reference to JAVA includes both the JAVA language and also JAVA platform and architecture.
Those skilled in the programming arts will be aware that when additional code or instructions is/are inserted into an existing code or instruction set to modify same, the existing code or instruction set may well require further modification (eg by re-numbering of sequential instructions) so that offsets, branching, attributes, mark up and the like are catered for.
Similarly, in the JAVA language memory locations include, for example, both fields and array types. The above description deals with fields and the changes required for array types are essentially the same mutatis mutandis. Also the present invention is equally applicable to similar programming languages (including procedural, declarative and object orientated) to JAVA including Micrsoft.NET platform and architecture (Visual Basic, Visual C/C and FORTRAN, COBOL, BASIC etc.
The abovementioned embodiment in which the code of the JAVA finalisation or clean up routine is modified, is based upon the assumption that either the run time system (say, JAVA HOTSPOT VIRTUAL MACHINE written in C and JAVA) or the operating system (LINUX written in C and Assembler, for example) of each machine Ml...Mn will call the JAVA finalisation routine. It is possible to leave the JAVA finalisation routine unamended and instead amend the LINUX or HOTSPOT routine which calls the JAVA finalisation routine, so that if the object or class is not to WO 2005/103927 PCT/AU2005/000581 be deleted, then the JAVA finalisation routine is not called. In order to embrace such an arrangement the term "finalisation routine" is to be understood to include within its scope both the JAVA finalisation routine and the "combination" of the JAVA finalisation routine and the LINUX or HOTSPOT code fragments which call or initiate the JAVA finalisation routine.
The terms object and class used herein are derived from the JAVA environment and are intended to embrace similar terms derived from different environments such as dynamically linked libraries (DLL), or object code packages, or function unit or memory locations.
The term "comprising" (and its grammatical variations) as used herein is used in the inclusive sense of "having" or "including" and not in the exclusive sense of "consisting only of'.
Copyright Notice This patent specification contains material which is subject to copyright protection. The copyright owner (which is the applicant) has no objection to the reproduction of this patent specification or related materials from publicly available associated Patent Office files for the purposes of review, but otherwise reserves all copyright whatsoever. In particular, the various instructions are not to be entered into a computer without the specific written approval of the copyright owner.
WO 2005/103927 PCT/AU2005/000581 Annexure A The following are program listings in the JAVA language: Al. This first excerpt is part of the modification code. It searches through the code array, and when it finds a putstatic instruction (opcode 178), it implements the modifications.
START
byte[] code Codeattribute.code; Bytecode of a given method in a given classfile.
int code length Code_attribute.code length; int DRT 99; Location of the CONSTANT Methodref info for the DRT.alert() method.
for (int i=0; i<code length; if ((code[i] Oxff) 179){ Putstatic instruction.
System.arraycopy(code, i+3, code, i+6, code length-(i+3)); code[i+3] (byte) 184; Invokestatic instruction for the DRT.alert() method.
codeli+4] (byte) ((DRT 8) Oxff); (byte) (DRT Oxff);
END
A2. This second excerpt is part of the DRT.alertO method. This is the body of the DRT.alert( method when it is called.
START
public static void alert()( synchronized (ALERT LOCK){ ALERT_LOCK.notify(); Alerts a waiting DRT thread in the background.
END
A3. This third excerpt is part of the DRT Sending. This code fragment shows the DRT in a separate thread, after being notified, sending the value across the network.
START
MulticastSocket ms DRT.getMulticastSocket(); The multicast socket used by the DRT for communication.
byte nameTag 33; This is the "name tag" on the network for this field.
WO 2005/103927 WO 205/13927PCT/A1J20051000581 Field field modifiedClass.getDeclaredield'ImyFieldl"); //Stores /the field /1from the /modified 1/class.
In this example, the field a byte field.
while (DRT.isRunning() synchronized (ALERT_LOCK){ ALERT LOCE.weito; IIThe DRT thread is waiting for the alert /method to be called.
byte[] b =new byte[flnameTag, field.getByte(nul.)); /1Stores /1the /1nameTag aI nd the 1/value 1/of the //fie--d from /the modified /class in a //buffer.
DatagramPacket dp new DatagrarsPacket(b, 0, b.length); ms.send(dp); Send the buffer out across the network.
//END
A4. The fourth excerpt is part of the DRT receiving. This is a fragment of code to receive a DRT sent alert over the network.
START
MulticastSocket ms DRT. getMulticastSocket)~I The multicast socket Iused by the DRT for 1/communication.
DatagremPecket dp new DetagramPacket(flew byte[2], 0, 2); byte nameTag =33; IIThis is the "name tag" on the network for this /1field.
Field field =modifiedClass.getDeclaredField("myFieldl"); IIStores the /1field from Ithe modified /1class.
IIn this example, the field is a byte field.
while (DRT.isRunnilg)l ms.receive(dp); Receive the previously sent buffer from the network.
byte[] b =dp.getDatao; if (b 0] ==nemeTag){ 1 Check the nametags match.
field.setlyte(flull, b[ll); /1Write the value from the network packet 1into the field location in memory.
WO 2005/103927 WO 205/13927PCT/A1J20051000581
END
The fifth excerpt is an example application before modification has occurred.
Method void setValues(int, int) o iload_1 1 putstatic #3 <Field int staticValue> 4 aload_0 iload_2 6 putfield #2 <Field int instanceValue> 9 return A6. The sixth excerpt is the same example application in 5 after modification has been performed. The modifications are highlighted in bold.
Method void setValues(int, int) o iload_1 1 putstatic #3 <Field mnt staticValue> 4 ide #4 <String "?example"Y> 6 iconst_0 7 invokestatic #5 <Method void alertojava.lang.Object, int)> aload_0 11 iload_2 12 putfield #2 <Field mnt instanceValue> aload_0 16 iconstI 17 invokestatic #5 <Method void alertojava.1ang.Object, int)> return A7. The seventh excerpt is the source-code of the example application used in excerpt 5 and 6.
import java.Iang.k; public class example{ /*Shared static field. public static mnt staticValue 0; Shared instance field. public int instanceValue 0; Example method that writas to memory (instance field) public void setValues(imt a, mnt b){ statioValue a; instanceValue b WO 2005/103927 WO 205/13927PCT/A1J20051000581 A8. The eighth excerpt is the source-code of FieldAlert, which alerts the "distributed run-time" to propagate a changed value.
import java.lang.*; import java.util.*; import java.net.*; import java.io.*; public class FieldAlert{ Table of alerts. public final static H-ashtable alerts new Hashtable(); Object handle. public Object referernce null; Table of field alerts for this object. public boolean[] fieldAlarts =null; Constructor. public FieldAlert(object o, int initialFieldCount){ reference =o fieldAlerts new boolean[initialFieldCountJ; /*Called when an application modifies a value. (Both objects and classes) public static void alert(Object o, mnt fieldlD)l Lock the alerts table.
synchronized (alerts)( FieldAlert alert (FieldAlert) alerts.get(o); if (alert null)[I This object hasn't been alerted already, /so add to alerts table.
alert new FieldAlert(o, fieldlD 1); alerts .put alert); if (fieldlD alert.fialdlerts.length)f 0k, enlarge fieldAlerts array.
boolean[) b =new boolean[fieliID+l]; Systen.arraycopy(alert.fieldAlarts, 0, b, 0, alert. fieldAlerts .length); alert.fieldAlerts b; R, Pecord the alert.
alert. fieldAlerts [fieldID] true; Mark as pending.
Fieldsend.pending true; IISignal that there is one or more 1propagations waiting.
1Finally, notify the waiting FieldSend thread(s) if (FieldSend.waiting)l FieldSend.waiting false; alerts.notifyo; WO 2005/103927 WO 205/13927PCT/A1J20051000581 A9. The ninth excerpt is the source-code of FieldSend, which propagates changes values alerted to it via FieldAlert.
import java.lang.*; import java. lang. reflect. import java.util.*; import java.net.*; import j ava.io. public class FieidSend implements Runnable{, Protocol specific values. public final Static int CLOSE public final static inc NACK 0; public final static int ACI( 1; public final static mnt PROPAGATE_-OBJECT public final static mnt PROPAGATE-CLASS FieldAlert network values. public final static String gruup= System. getPrcperty 'FeldAlert-network-group"l); public final static int port= Integer.parselnt(system.getProperty("FieldAlert_network port") /*Table of global ID's for local objects. (hashcode-to-globaliD mappings) public final static Hashtable objectTo~lobellD -new Hashtabla(); /*Table of global ID's for local classnames. (classname-to-globalID mappings) public final static Hashtable classNameToGlobalID new Hashtable(); Pending. True if a propagation is pending. public static boolean pending =false; Waiting. True if the FieldSend thread(s) are waiting. public static boolean waiting false; 1*Background send thread. Propagates values as this thread is alerted to their alteration./ public void run(){ System.out.println("FieldAlert -network-group=" group); System.out.printin("FieldAlert network _port="I port); try{ Create a DatagramSockat to send propagated field values.
Datagram.Socket datagramSocket new DetagramSocket (port, InetAddress .getBy~ama (group)); 1Next, create the buffer and packet for all transmissions.
byte[] buffer new byte[512]; IIWorking limit of 512 bytes /1per packet.
DatagramPacket datagramPacket WO 2005/103927 WO 205/13927PCT/A1J20051000581 new DatagramPacket(buffer, 0, buffer.length); while (!Thread.interruptedo) Object entries null; Lock the alerts table.
synchronized (FieldAlert.alerts)l Await for an alert to propagate something.
while (!pending){ waitin~g =true; FieldAlert.alerts.wait o; waiting false; pending false; entries FielcAlcrt.alcrts.entrySet().-ioArray((; Clear alerts once we have copied them.
FieldAlert, alerts, clear Process each object alert in turn.
for (mnt i=0; i<entries.length; FieldAlert alert =(FieldAlert) entries mnt index 0; datagram~acket. setLenqth (buffer, length); Object reference =null; if (alert.raferance instanceof String){ PROPAGATECLASS field operation.
buS fer[index+I] (byte) ((PROPAGATE_-CLASS 24) a Qxff); buffer~iidex++] (byte) ((PROPAGATECLASS 16) Oxif); buffer[index++J (byte) ((PROPAGATECLASS 8) Oxf buffer[index++] (byte) ((PROPAGATECLASS 0) Oxf String name =(String) alert.reference; mnt length =name.lengtho; buffer[indax++] (byte) ((length 24) Oxff); buffer[index+±] (byte) ((length 16) Oxff); bufferlindex++] (byte) ((length 8) Oxff); buffer[index++] (byte) ((length 0) Oxff(; byte[] bytes name.getBytes((; System.arraycopy(bytes, 0, buffer, index, length); index lengthp )else{ /1PROPAGATEOEJECT field operation.
buffer~index++]= (byte) ((PROPAGATEOBJECT 24) Oxff); buffer[index++J (byte) ((PROPAGATEOBJECT 16) Oxff); buffer~index++] (byte) ((PROPAGATE -OBJECT 8) Oxff); buffer[indx-I-= (byte) ((PROPAGATEOBJECT 0) Oxff); iet globalID ((Integer) objectToGloballD. get (alert. reference)) .intyalue o; buffer[indexi+] (byte) ((globalID 24) Oxff); WO 2005/103927 WO 205113927PCTiAU2005!000581 buffer~index+I- (byte) ((globalID 16) Oxff); buffer~index++] (byte) ((globalID 8) OXff); buffer(index++] (byte) ((globalID 0) CXff); reference alert.reference; 1Use reflection to get a table of fields that correspond to 1the field indexes used internally.
Field[] fields =null; if (reference ==null)j fields FieldLoader.loadClass( (String) alert. reference) getDeclaredFields o; elsef fields alert.reference.getClass().getleclaredFieldso; 1Now encode in batch mode the fieldID/value pairs.
for (lot j=O; j~alert.fieldAlerts.length; if (aleit.fieldAlerts[j] ==false) continue; buffer[index++) (byte) 24) Oxff); buffer[index++] (byte) 16) Oxff); buffer[index±+] (byte) 8) Oxff); buffer~index++: (byte) 0) Oxff); Encode value.
Class type fields[j].getType(); if (type Boolean.rTiPE){ buffer[index++] =(byte) (fields[j].getsoolean(reference)? 1 0); }else if (type Byte.TYPE){ buffer[index+1] fields .getoyte(reference); jelse if (type Short.TYPE){ short v f-'elds[jJ .getShort~reference); bufffer~indexf+] =(byte) 8) Oxff); buffer~index++] =(byte) 0) Oxff); )else if (type Character.TYPE)f char v =fields Ej] .getChar (reference); buffer[index++] (byte) 8) Oxff); buffer[index-+] (byte) 0) Oxff); Jelse if (type =Integer.TYPE)f mnt v fields[j].getlnt(refer ence); buffer[index++] (byte) 24) Oxff); buffer~index++] (byte) 16) Oxff); buffer[index++] =(byte) 8) Cxff); bufferfindex++] =(byte) 0) Oxff); jelse if (type Float.TYPE)f mnt v Float.floatToIntBits( fields[j) .get8loat(refarence)); buffer[indexl+] (byte) 24) Oxff); buffer[index++] =(byte) 16) Oxff); buffer[index++] (byte) 8) Cxff); buffer~index++4] (byte) 0) Oxff); Jelse if (type ==Long.TYPE){ long v =fields[jJ .getLong(reference); buffer[indexi+J (byte) 56) Oxff); buffer~index+-] =(byte) 48) Oxff); buffer[indxv+] =(byte) 40) Oxff); buffer[index++3 (byte) 32) Oxff); buffer[index-i] =(byte) 24) Oxff); buffer[index+-] =(byte) 16) Oxff); buffer[index+±] (byte) 8) Oxff); WO 2005/103927 WO 205/13927PCT/A1J20051000581 bu-Ffer[index+i] (byte) 0) Oxff); jelse if (type Double.TYPE){ long v Double.doubleToLongBits( fields [j getDouble (reference)); buffer[index++] (byte) 56) Oxff); buffer[index++- (byte) 48) Oxff); buffer[index+t- (byte) 40) Oxff); buffer[index++-] (byte) 32) Oxff); buffer[index++] (byte) 24) Oxff); buffer[index++] (byte) 16) Oxff); buffer[index++] (byte) 8) Oxff); buffer[index++] =(byte) 0) Oxff); )else{ throw new AssertionError ("Unsupported type."); /Now set the length of the datagrampacket.
data gramPacket .setLength (index); Now send the packet.
datagramSocket. send (datagramPacket); }catch (Exception e)( throw new AssertionError("Exception: e.toStringo); The tenth excerpt is the source-code of FieldReceive, which receives propagated changed values sent via FieldSend.
import java.lang.*; import java. lang. reflect. A; import java.util.*; Lmport java.net.*; import javs.io.*; public class FieldReceive implements Runnable( Protocol specific values. public final static int CLOSE public final static int NACE( 0; public final static int ACK 1; public final static mnt PROPAGATE_-OBJECT public final static int PROPAGATE-CLASS FieldAlert network values. public final static String group= System. qet~roperty( "Fiel cAlIert network group"); public final static mnt port Integer.parselnt(System.getproperty("FieldAlert_networ_pot")); WO 2005/103927 WO 205113927PCTiAU2005!000581 /~Table of global lID'S for local objects. (globalID-to-hashoode mappings) public final static Hashtable globalIDToObject new Hashtable(); /*Table of global ID's for local classnanies. (globalID-to-classname mappings) public final static IHashteble globalIDToClasoName new Hashtableo; Called when en application is to acquire a lock. public void run()[ System.out.println("Fieldlert -network-group=' group); System.out.println("FieldAlert-network_port=" 4 port); try( Create a DatagraniSocket to send propagated field values from M~ulticastfocket nulticastSocket new MulticastSoccet(port); multicastSockat.joinoroup(InetAddress.get~yName(group)); Next, create the buffer and packet for all transmissions.
byte!]l buffer new byte[512J; /W orking limit of 512 /bytes per packet.
DatagranPacket datagramPacket= new DetagramPacket(buffer, D, buffer.length); while (!Thread, interruptedo) Make sure to reset length.
datagramPacket. setLength(buffer.length); Receivce the next available packet.
inulticastSccket. receive (detagramPacket); mnt index length =datagramPacket.gettength(); Decode the command.
mnt command (int) (((buffarfindex++] Oxff) 24) 1 (bufferfindex+I] Oxfif) 16) 1 (buffer[indexl+] Oxff) 3) I (buffer[index++1 Oxff)); if (command -PROPAGATE_OBJECT) f 1 Propagate operation for Iobject fields.
UDecode global id.
mnt globalID =(int) (((buffer[indexi+] Oxff) 24) 1 ((buffer[indexH-] Oxff) 16) ((buffer~index±+] Oxff) 8) I(buffer~index+I] Oxff)); /Now, need to resolve the object in question.
Object reference =globalIDToObject.get( new Integer(globalID)); INext, get the array of fields for this object.
Field(] fields reference.getClass().getDeclaredFields!]; while (index length)( Decode the field id.
mnt fieldID (int) (((buffer~index-+] Oxff) 24) 1 ((buffer~index+i] Oxff) 16) 1 ((buffer[indexi+] Oxff I 8) WO 2005/103927 WO 205113927PCT1A1J20051000581 I buffer[index+±) Dxfi)); 1Determine value length based on corresponding field 1/type.
Field field fields (fieldID]; Class type ileld.getTypeo; if (type E= oolean.TYPE([ boolean v (bufferindex++] 1 true :felse); field.setBoolean(reieremce, v); )elsa if (type Byte.TYPE){ byte v buifer[indexi+J; iield.setByte (reference, v); jelse if (type Short.TYFE){ short v =(short) (((buifer[index±4) Cxii) 8) 1 (buiier[indexs+] Cxff)); iield.setShort (reterence, v); Jelse if (type Character.TYPE){ char vt (char) (((buffer[index44- Cxii) 8) 1 (buifer~index++) Cxii)); iield.setChar(reference, v); jelse if (type Integer.TYPtE){ mnt v (int) (((bufier[index++] Cxii) 24) 1 ((buifer~index±+J Oxff) 16) 1 ((huifer~index++J Cxff) 8) 1(buiier[index++) Cxii)); iield.setlnt (reference, v); )else if (type ==Float.TYPE)i mnt v (int) (((buiier[index+t] Oxii) 24) ((buifer[index++J Oxif) 16) I((buifer[index++] Oxii) 8) I(buiier[index+-] Oxii)); field. setFlcat (reference, Float.intBitsToyloat lelse if (type Long.TYPE)( long vt (long) (((buifer[index++] Cxii) 56) I((buiier[index-+] Cxii) 48) ((buiier[indax++) Cxii) I((buiier[index++] Cxii) 32) 1((buifer[ndex+s- Cxff) 24) 1 ((buter[index+4-] Cxi i) 16) 1 ((buiiertindex++J Cxii) 8) 1 (bufier[index++) Cxii)); field.setlong(reierence, v); )else if (type Double.TYPE){ long vt (long) )((bufierfindex++] Oxfi) 56) 1 ((buiier[indexi-] Dxii) 48) 1 ((bnifer~indx+i] Dxii) 1 ((buiier~indexri] Oxfi) 32) 1 )buiier[index+-] Dxii) 24) 1 ((huiier~indexi+] Oxii) 16) I((buiier[index+-] Oxff) 8) I(hufier[index++) Cxii)); field. set~ouhle(reierence, Double.long~itsToDouble jelse throw new AssertionError("Unaupported type."); )else if (command ==PROPAGATECLASS)l{ Propagate an update /to class fields.
//Decode the classname.
mnt nameLength= (tnt) )((buiier[indexs+] Cxii) 24) I((buiier[index+±] a Oxti) 16) I((buiier[lndex++] Cxii) 8) I(buffer(index+-I] Cxii)); WO 2005/103927 WO 205/13927PCT/A1J20051000581 String name new String(buffer, index, nameLength); index nameLength; Next, get the array of fields for this class.
Field[] fields= FieldLoader.loadClass (name) .getoeclaredFields(); 1Decode all batched fields included in this propagation /1packet.
while (index length)( Decode the field id.
mnt fieldTD (int) (((buffer[indexI++ Oxff) 24) 1 ((buffer[indexH-1 Oxff) 16) 1 ((buffer[indexI+1 Oxff) 8) 1 (buffer[index-4] Oxff)); 1Determine field type to determine value length.
Field field fields [fieldID]; Class type =field.getTypeo; if (type Boolean.TYPE8{ boolean v (buffer[index++] 1 true :false); field.set800lean(lull, v); (else if (type Byte.TYPE){ byte v buffer[index4I+]; field. setEyte (null, v); jelse if (type Short.TYPE){ short v (short) (((buffer[indexI+] Oxff) 8) I (huffer[index++] Oxff)); field.setShort(nulll, v); )else if (type Character.TYPE){ char v (char) (hufferliindex++7 Oxff) 8) 1 (buffer[index+±] Oxff)); field.setChar(null, v); )else if (type Intager.TYPE)[ mnt v (int) (((huffer[index++] Oxff) 24) I((buffer[index++] Oxff) 16) ((buffer[index+tl Oxff) 8) I(buffer[indexI+] Oxt));* field. setint (null, v); )else if (type Float.TYPE)i mnt v= (int) (((buffer[index++] R Oxff) 24) 1 ((buffer~index++-I] Oxff) 16) 1 ()buffer[index++( Oxff) 8) I(buffer[index++] Oxff)); field.setFloat (null, Bloat.int~itsToFloat(v)) )else if (type Long.TYFE){ long v (long) (((buffer[index++) Oxff) 56) 1 ((buffer[index+I] Oxff) 48) 1 ((buffer[index++I Oxff) 1 ((bufifer[indexI+] Oxff) 32) 1((buffer[index++] Oxff) 24) 1 ((bufferindexI+( Oxff) 16) 1 ((buffer[indexT+] Oxff) 8) I (bufter[index+±1 Oxff)); field.setLong(null, v); (else if (type Double.TYPE)l long v (long) (((buffer~index++] Oxff) 56) 1 ((buffer[index++] Oxff) 48) 1 ((buffer~index+±] Oxff) 1 ((buffer[index+I] Oxff) 32) 1 ((buffer[index±±1 Oxff) 24) 1 ((bufferjindex++] Oxff) 16) I((buffer[index++] 0xff) 8) I(buffer[index++1 Oxff)); field.setDouble(nul-, Double.longBitsToDouble(v)); WO 2005/103927 WO 205/13927PCT/A1J20051000581 }else{ Unsupported field type.
throw new AssertionError("Uflsupported type."); )catch (Exception e){ throw new AssertionError('Exceptiofl e.toStringW); All. FieldLoader.java This excerpt is the source-code of FieldLoader, which modifies an application as it is being loaded.
import java.lang.*; import java.ic.*; import java.net.*; public class FieldT~oadem extends URILClassLoaderl public FieldLoader(tJRL[] urls){ supar(urls); protected Class findClass (String name) throws ClassNotFoundException{ Class~ilce cf null; try BufferedlnputStream in new BufferednputStreamlfindRescurce( name.replace('.', '/').concat(".class")).openStreali); cf new ClassFile(in); )catch (Exception el (throw new ClassNotFoundException(e.toString());I Class-wide pointers to the ldc and alert index.
mnt ldcindex -1; int alertindex for (mt i=O; i<cf.methods count; for (int j=O; j<rf.methods~i] .ettributes-count; if (cf.methods~il .attributestj] instanceof Code-attribute)) continue;, Code attribute ca =(Code-attribute) cf.methods [ii .att ributes boolean changed falsep for (int z=O; z<ca.code.length; WO 2005/103927 PCT/AU20051000581 if ((ca.code[z] Oxff) 179){ Opcode for a
PUTSTATIC
1/ instruction.
changed true; /1 The code below only supports fields in this class.
/1 Thus, first off, check that this field is local to this /1 class.
CONSTANT Fieldref info fi (CONSTANT- ieldref info) cf.constentpool[(int) (((ca.codelz] Oxff) 8) (ca.code[z] Oxff)fl; CONSTANTClass info ci (CONSTANTClassinfo) cf.constant pool[fi.clessindex]; String clessName cf.constant pool [ci.name index] .toString; if (Iname.equels(className))T throw new AssertionError("This code only supports fields "local to this class"); 1/ Ok, now search for the fields name and index.
int index 0; CONSTANTNaneAndType info ni (CONSTANTNemeAndType info) cf.constant pool[fi.nameandtype_index]; String fieldName cf.constant pool[ni.nameindex] .toString 0; for (int a=0; a<cf.fieldscount; String in cf.constantpool[ cf.fialds[a].name-index].toString(( if (fieldName.euals(f))l index a; break; /1 Next, realign the code array, making room for the II insertions.
byte[][] code2 new byte[ca.code.length+ 3 1[1; System.arraycopy(ca.code, 0, code2, 0, z+l); system.erreycopy(ce.code, zIl, code2, z+4, ca.code.length-(z+1)); ca.code code2; Next, insert the LDC W instruction.
if (ldcindex CONSTANT String info csi new CONSTANTStringinfo(ci.nameindex); cp info[] cpi new cpinfo[cf.constentpool.length+l] System.erroycopy(cf.constantpool, 0, cpi, 0, cf.constant poul.length); cpi[cpi.length 1] csi; idcindex cpi.length-l; cf.constant pool cpi; cf.constant poolcount++; ca.code[z+l] new byte[3]; (byte) 19; ca.code[z+l1l] (byte) ((ldcindex 8) Oxff); ca.code[z+l][2] (byte) (ldcindex Oxff); Next, insert the SIPUSH instruction.
WO 2005/103927 WO 205/13927PCT/A1J20051000581 ca.code[z+2] =new byte[3]; ca.code[zI23 (byte) 17; ca.code[Z+2] El] (byte) ((index 8) Oxff); ca.code[zi2] -(byte) (index Oxff); /Finally, insert the INVOKESTATIC instruction.
if (alertindex 1This is the first time this class is encourtaring the /alert instruction, so have to add it to the constant /1pool.
cpinfo[] cpi new op -info[cf.constant_pool.lengthI6]; System. arraycopy(cff.constant pool, 0, opi, 0, cf. constantpool .length); cf.constent_pool opi; cf.constent pool count 6; CONSTANT Utf 8 info ul new CONSTANTO tf8_info('FieldAlert"); cf.comstant-pocl[cf.constant-pool.length-6] ul; CONSTANT_-Cless -info cl m ew CONSTANTClass-info( cf.constant_pool_count-6); cf.constant pool [of. constant pool. length-5] l ul new CONSTANT_-Utf 8_info("alert"); cf.conatant pool )cf. constant pool. langth-4] ul; ul new CONSTANT_-Utf 8_info("(ijava/lang/Object;I)V"); cf.constant-pool[cf.constantpool.length-3] ol; CONSTANT_-NaneAndType_info n1 new CONSTANTNaneArdType_info( of. constant pool. length-4, cf. constant-pool .length- 3); cf.oonstant_pool(cf.ccnstant~pool.length-2] n1; CONSTANTMethodref-info ml new CONSTANT D'ethodret-into( of. constant pool. length-5, cf. constant pool.length- 2); cf. constant pool [cf .constant_pool .length-1] =ml; alertindex cf.constent_pool.length-l; ca.code[z+3] =new byte[3]; ca.code[z+3](0[0= (byte) 184; ca.code[z+3) (byte) ((alertindex 8) Oxff); ca.codefz+3] [23 (byte) (alertindex Oxff); And lastly, increase the CODE_LENGTH and
ATTRIBUTE-LENGTH
values.
ca.code length 9; ca.attribute_length 9; J/ if we changed this method, then increase the stack size by cno.
if (changed)i ca.max stack+±; 1/Just to make sure.
WO 2005/103927 PCT/AU2005/000581 try{ ByteArrayOutputStream out new ByteArrayOutputStream(); cf.serialize(out); byte[] b out.toByteArray(); return defineClass(name, b, 0, b.length); }catch (Exception e){ throw new ClassNotFoundException(name); A12. Attribute_info.java Convience class for representing attribute info structures within ClassFiles.
import java.lang.*; import java.io.*; This abstract class represents all types of attribute info that are used in the JVM specifications.
All new attributeinfo subclasses are to always inherit from this class.
public abstract class attribute info{ public int attributenameindex; public int attribute length; This is used by subclasses to register themselves to their parent classFile.
attribute info(ClassFile cf){} Used during input serialization by ClassFile only. attributeinfo(ClassFile cf, DatalnputStream in) throws IOException{ attribute name index in.readChar(); attribute length in.readInt(); Used during output serialization by ClassFile only. void serialize(DataOutputStream out) throws IOException{ out.writeChar(attribute name index); out.writelnt(attribute length); This class represents an unknown attribute info that this current version of classfile specification does not understand.
public final static class Unknown extends attribute info{ byte[] info; WO 2005/103927 PCT/AU2005/000581 Used during input serialization by ClassFile only. Unknown(ClassFile cf, DataInputStream in) throws IOException{ super(cf, in); info new byte[attribute_length]; in.read(info, 0, attribute_length); Used during output serialization by ClassFile only. void serialize(DataOutputStream out) throws IOException{ ByteArrayOutputStream baos new ByteArrayOutputStream(); super.serialize(out); out.write(info, 0, attribute_length); A 13. ClassFile.java Convience class for representing ClassFile structures.
import java.lang.*; import java.io.*; import java.util.*; The ClassFile follows verbatim from the JVM specification. public final class ClassFile public int magic; public int minor_version; public int major_version; public int constant_pool_count; public cp_info[] constant pool; public int access_flags; public int this_class; public int superclass; public int interfaces_count; public int[] interfaces; public int fields count; public field info[] fields; public int methodscount; public method_info[] methods; public int attributes_count; public attributeinfo[] attributes; Constructor. Takes in a byte stream representation and transforms each of the attributes in the ClassFile into objects to allow for easier manipulation.
public ClassFile(InputStream ins) throws IOException{ DatalnputStream in (ins instanceof DataInputStream (DataInputStream) ins new DataInputStream(ins)); magic in.readInt(); minor version in.readChar(); majorversion in.readChar(); constant_pool_count in.readChar(); constant pool new cp_info[constant_pool_count]; for (int i=l; i<constant_pool_count; in.mark(l); int s in.read(); in.reset(); switch WO 2005/103927 WO 205/13927PCT/A1J20051000581 case 1: constant~pool [i] break; case 3: constant pool [1] break; case 4: constant pool [i] break; case El] break; case 6: constant-pool [ii break; case 7: constant_pool [i] break; case 8: constant,_pool [i] break; case 9: constant pool [i] break; case new CONSTANT_Utf8_info(thls, in); new CONSTANTInteger-into(this, in); =new CONSTANTFloat-info(this, in); new COSATLngit~hs in); =new CONSTANTDouble -info(this, in); new CONSTANT Class-info(this, in); new CONSTANT_String info(this, in); =new CONSTANT Fieldref info(this, in); constant_ po01(1] =new CONSTANT Methodref info(tbis, break; case 11: constant pool (i] new CONSTANT break; case 12: constant_poolE1] break; detault: InterfaceMethodref-info (this, in); =new CO3ATaen yeif(this, throw new ClassF'ormatError('lnvalid ConstantPoolTag"); access_flags in.readChar(); this-class in.readChar)); superclass in.readChar(); inreciChar)); interfaces new int~interfaces count]; for (mnt 1=0; i<lnterfaces count; interfaces~i] in.read~haro; fields count in.readChar(); fields new field -info~fields-count]; for (int A=0; i<fields -count; I++i)I fields new field info(this, in); methods count n.readCharo; methods new method -info[nethods-count]; for (int i=0; i<nethods count; i++-I)f nethods[i] new method-info(this, in); attributes-count. in.readCharo; attributes new attribute info~attributes count]; for (int. i-0; i<attributes -count; i-f+)f in. mark String s constant_pool[in.readCharo)].toStringo; in. reset if (s.equais ("SourceFilel")) WO 2005/103927 WO 205/13927PCT/A1J20051000581 attributes[il new SourceFile -attribute(this, in); else if (s.equals("Deprecated")) attributes[i] =new Deprecated -attribute(this, in); else if (s.equals("InnerClaases")) attributes~i] new InnerClasses-attribute(this, in); else attributes~i] new attribute info.Unknown(this, in); /~Serializes the ClassFile object into a byte stream. public void serialize(OutputStream o) throws COException{ DataOutputStrean out o instanceof DataOutputStreau CDataOutputStream) o new DataoutputStrean~o)); out .writelnt (magic); out.writeChar (minor version); out.writeChar (major-version); out.writeChar(constant_pool_count); for (mnt i=l; i<constant_pool_count-; constant~pool[i] .serialize (out); if (constant poolti] instanceof CONSTANT_Long info 1 constant pool~il instanceof CONSTANT Double info) out.writeChar (access flags); out.writaChar (this class); out.writeChar (super Iclass); out.writeChar~interfaces count); for (int i=O; i<interfaces_count; out.writeChar(interfaces out.writeChar(fields count); for (mnt i=C; i<fieldas count; fields serialize (out); out. writeChar (methods count); for (mt i~methods count; methods[i] .serializa(out); out. writeChar (attributes_count); for (mnt i=O; i<attributes count; i+4-) attributes [i].serialize (out); 1/Flush the outputstrean just to make sure.
out. Slush)); A14. Code -attribute.java Convience class for representing Code-attribute structures withfin ClassFiles.
import jave.util.*; import java.lang.*; import java.iJo.*; The code(] is stored as a 2D array. public final class Code-attribute extends attribute-info{ public mnt max stack; public mnt max locals; public int code -length; public byteL[] code, public mnt exception table length; public exception_tablef] exception-table; public mnt attributes -count; public attribute-info[] attributes; WO 2005/103927 PCTiAU2005!000581 Internal class that handles the exception table. public final static class exception table{ public int start pc; public int end_pc; public int handler pc; public mnt catch-type; /~Constructor called only by method-info. Code-attribute (ClassFile cf, mnt ani, mnt al, mnt ms, mnt ml, int cl, byte[][]1 cd, t-nt etl, exception table[] et, mnt ac, attribute-info[] a)[ super (cf); attribute name index =ani; attribute length al; max stack- ms; max locals =ml; code length cl; code cd; exception -table -length etl; exception_table e t; attributes count =ac; attributes a; /*Used during input serialization by ClassFile only. Code attribute(ClassS'ile cf, DetalnputStream in) Throws IOException{ super(cf, in); max stack in.readChar(o; max locals =in.readChax(); code length =in.readInto); code new byte[code_length][]; mnt 1 0; for (int pos=0; pos~code_length; in.mark (1) mnt a in.reado; in. reset o; switch case 16: case 18: case 21: case 22: case 23: case 24: case case 54: case case 56: case 57: case 58; case 169: case 188: case 196: code(i] -new byte(2]; break; case 17: case 19: case case 132: case 153: case 154: case 155: case 156: WO 2005/103927 PCT/AU20051000581 case 157: case 158: case 159: case 160: case 161: case 162: case 163: case 164: case 165: case 166: case 167: case 168: case 178: case 179: case 180: case 181: case 182: case 183: case 184: case 187: case 189: case 192: case 193: case 198: case 199: case 209: code[i] new byte[3]; break; case 197: code[i] new byte[4]; break; case 185: case 200: case 201: codefi] new break; case 170:{ int pad 3 (pos 4); in.mark(pad13); int low in.readlnto; code[i] /1 highbyte /1 lowbyte new byte~pad 13 -k ((in.readlnt() low 1) 4)1; in. reset break; )case 171:{ int pad 3 (pos 4); in.mark(pad+9); code[il new byte[pad 9 (An.readnt() 8)1; in.reset(); break; )default: code~i] new byte[l]; in.read(codefi], 0, codefi].length); pos code[i].Iength; 1/ adjust the array to the new size and store the size byte[] temp new byteti] System.arraycopy(code, 0, temp, 0, i); code tamp; exceptiontablelength in.readCharo; exception table WO 2005/103927 WO 205/13927PCT/A1J20051000581 new Code -attribute.exceptioi- table [exception-table-length]; for i<exception-table length; exception -table[i] =new exception_tableo; exception -table~l.start pc in.readCharo; exception table[i].end_PC in.readChar(); exception table [i].handler pc in. readChar o; exception-table~l.catch type ln.readCharo; attributes-count =in.readChar(); attributes new attribute -info[attributes-count]; for i<attributes-count; 1in.nark(2); String sa cf.conscant_pool[in.readCharofl.toStringo; in. reseto; if (s.equala (ILineNumberTable")) attributes[i] new LineNuinber~Jable attribute(cf, in); else if (s.oquals("lLocalVariableTable")) attributes =new LocalVariabieTable-attribute(cf, in); else attributes~il new attribute-info.lnlnown(cf, in); /*Used during output serialization by ClassFile only.
void serialize (DatatutputStream out) throws IOException{ attribute length =12 code length (exception-table_length 8); for (mnt i=O; i<attributes-count; 14+) attribute -length attributes[iJ .attribute length G; super. serialize (out); out.writeChar(max stack); out.wciteChar~max locals); out .writelnt (code length); for (mnt i=0, pos=O; pos<code_length; 1+1)j out.write(code[i], 0, coda[il.length); pea 4= code[i] .length; out.writethar(excaption_table_length); for (mnt i=O; i<exception_table_length; i1+)[ out.writaChar(exception -table[i] .start-pc); out.writeChar(exception-table .endpc), out.writnChar(exception -tabcle[i] .handier_pc); out.writaChar(axception-table[i] .catch-type); out. writeChar (attributes count); attributes .serialize (out); A 15. CONSTANT_-Class -info.java Convience class for representing CONSTANTClass-info structures within ClassFiles.
import java.lang.*; import java.io.*; Class subtype of a constant pool entry. public final class CONSTANT Class info extends cpinfo{ WO 2005/103927 WO 205/13927PCT/A1J20051000581 The index to the name of this class. public int name-index 0; /*Convenience constructor.
public CONSTANTClass-info(int index) tag -7; name index index; /*Used during input serialization by ClassFile only. CONSTANTClass info(ClassFile cf, DatalnputStream in) throws IOException{ supe-r(cf, in); if (tag 7) throw new ClassFormatError)); name-index in.readCharo; /~Used during output serialization by ClassFile only. void serialize (DataOutputStream out) throws IOExceptionj out.writeChar(name-index); A16. CONSTANT_-Double-info.java Convience class for representing CONSTANTDouble-info structures within ClassFiles.
import jave.lang.*; import jeva.io.*; Double subtype of a constant pool entry. public final class CONSTANTDouble-info extends cpinfo{ The actual value. public double bytes; public CONSTANTDouble-info(double d){ tag 6 bytes d /*used during input serialization by ClessFile only. CONSTANTDouble info )ClassFile of, DatalnputStream in) throws IOException{ superlaf, in); if (tag 6 throw new ClassFormetErroro; bytes in.readDoubleo; /*Used during output serialization by ClassFile only. void serialize )DataOutputStream out) throws IOException{ out.writeByte (tag); out.writeDouble (bytes); long 1 Double.doubleToLongBits~bytes); WO 2005/103927 PCT/AU2005/000581 A17. CONSTANTFieldref_info.java Convience class for representing CONSTANTFieldrefinfo structures within ClassFiles.
import java.lang.*; import java.io.*; Fieldref subtype of a constant pool entry. public final class CONSTANT_Fieldref_info extends cp_info{ The index to the class that this field is referencing to. public int classindex; The name and type index this field if referencing to. public int name and type index; Convenience constructor. public CONSTANTFieldrefinfo(int classindex, int name and_type_index) tag 9; this.class index class index; this.name and typeindex name_andtype_index; Used during input serialization by ClassFile only. CONSTANT Fieldref info(ClassFile cf, DatalnputStream in) throws IOException{ super(cf, in); if (tag 9) throw new ClassFormatError(); class index in.readChar(); name_and type index in.readChar(); Used during output serialization by ClassFile only. void serialize(DataOutputStream out) throws IOException{ out.writeByte(tag); out.writeChar(class index); out.writeChar(name and type index); A18. CONSTANTFloat_info.java Convience class for representing CONSTANTFloat_info structures within ClassFiles.
import java.lang.*; import java.io.*; Float subtype of a constant pool entry. public final class CONSTANT_Floatinfo extends cp info( The actual value. public float bytes; public CONSTANTFloat info(float f)( tag 4; WO 2005/103927 WO 205/13927PCT/A1J20051000581 bytes f /*Used during input serialization by ClassFile only. CONSTANTFloat info (ClassFile cf, DatalnputStream in) throws IOException{ 3uper(cf, in); if (tag 4) throw new ClassrormatErroro; bytes in.readFloat(); SUsed during output serialization by ClassFile cnly. public void serialize (DataautputStream out) throws IOException{ out.writeByte(4); out.writeFloat (bytes); A 19. CONSTANT Integer info.java Convience class for representing CONSTANTInteger info structures within ClassFiles.
imotjalag; import java.ion.*; Integer subtype of a constant pool entry. k public final class CONSTANT_Integer_info extends cpinfo{ The actual value. public mnt bytes; public CONSTANT Integer info (mt b) tag 3; bytes =b /~Used during input serialization by ClassFile only. CONSTANT_-Integer info(ClassFile cf, DatalnputStreal in) throws IaExceptionf super~cf, in); if (tag 3) throw new ClassFormatErroro; bytes in.readlnt(); /*Used during output serialization by ClassFile only. public void serialize(DataOutpu~tStream out) throws IOEzception{ out.writeByte (tag); out.writelnt (bytes); CONSTANT_-InterfaceMethodref info.java Convience class for representing CONSTANTInterfaceMethodref info structures within ClassFiles.
WO 2005/103927 PCT/AU2005/000581 import java.lang.*; import java.io.*; InterfaceMethodref subtype of a constant pool entry.
public final class CONSTANT_InterfaceMethodref_info extends cp_info) The index to the class that this field is referencing to. public int classindex; The name and type index this field if referencing to. public int name_andtype_index; public CONSTANT_InterfaceMethodrefinfo(int classindex, int name_and_type_index) tag 11; this.class index class index; this.name and type index name_and_type_index; Used during input serialization by ClassFile only. CONSTANTInterfaceMethodref info(ClassFile cf, DataInputStream in) throws IOException{ super(cf, in); if (tag 11) throw new ClassFormatError(); class index in.readChar(); name andtype_index in.readChar(); Used during output serialization by ClassFile only. void serialize(Data0utputStream out) throws IOException{ out.writeByte(tag); out.writeChar(class_index); out.writeChar(nameandtype_index); A21. CONSTANTLong_info.java Convience class for representing CONSTANTLong_info structures within ClassFiles.
import java.lang.*; import java.io.*; Long subtype of a constant pool entry. public final class CONSTANT Long_info extends cp info( The actual value. public long bytes; public CONSTANTLong_info(long b){ tag bytes b; Used during input serialization by ClassFile only. CONSTANTLong info(ClassFile cf, DataInputStream in) throws IOException{ WO 2005/103927 WO 205113927PCTiAU2005!000581 super'cf, in); if (tag throw new ClassFormatarroro; bytes in.readLongo; /"'Used during output serialization by ClassFile only. void serialize (DataOutputStroam out) throws IOExceptionf out .writeByte (tag); out.writeLcng(bytes); A22, CONSTANT_-Methodref info.java Convience class for representing CONSTANTMethodref info structures within ClassFiles.
import java.lang.*; import java~io.*; /~Methodref subtype of a constant pool entry.
public final class CONSTANTMethodref-info extends cpinfol The index to the class that this field is referencing to. public int class-index; The name and type index t~his fiald if referencing Lo. public int name and type_index; public CONSTANTMethodref-info(int class-index, int name_and_type-index) tag this.class -index class-index; this.name-and_type index name_and-type_index; /*Used during input serialization by Classn~ile only. CONSTANTN ethndref info(Class~ile cf, DatalnputStream in) throws ICExceptEion super(cf, in); if (tag throw new ClassFormatErroz(); class-index in.readChaz(); name_and type index in.reaedhar /*Used during output serialization by ClassFile only. void serialize (DataOutputStream out) throws IOException{ out.writesyte (tag); cut.writeChar(class index); out.writeChar(name-and-type _index); A23. CONSTAT-TNameAndType infojava WO 2005/103927 PCT/AU2005/000581 Convience class for representing CONSTANTNameAndType_info structures within ClassFiles.
import java.io.*; import java.lang.*; NameAndType subtype of a constant pool entry.
public final class CONSTANT_NameAndType info extends cp info{ The index to the Utf8 that contains the name. public int name index; The index fo the Utf8 that constains the signature. public int descriptorindex; public CONSTANT NameAndType info(int name_index, int descriptor_index) tag 12; this.name index name index; this.descriptor index descriptor index; Used during input serialization by ClassFile only. CONSTANTNameAndType info(ClassFile cf, DatalnputStream in) throws IOException{ super(cf, in); if (tag 12) throw new ClassFormatError(); name index in.readChar); descriptor index in.readChar(); Used during output serialization by ClassFile only. void serialize(DataOutputStream out) throws IOException{ out.writeByte(tag); out.writeChar(name index); out.writeChar(descriptor index); A24. CONSTANTStringinfo.java Convience class for representing CONSTANT_Stringinfo structures within ClassFiles.
import java.lang.*; import java.io.*; String subtype of a constant pool entry.
public final class CONSTANT String info extends cpinfo{ The index to the actual value of the string. public int string_index; public CONSTANT String_info(int value) tag 8; string index value; WO 2005/103927 PCT/AU2005/000581 ONLY TO BE USED BY CLASSFILE! public CONSTANT_String_info(ClassFile cf, DataInputStream in) throws IOException{ super(cf, in); if (tag 8) throw new ClassFormatError(); stringindex in.readChar(); Output serialization, ONLY TO BE USED BY CLASSFILE! public void serialize(DataOutputStream out) throws IOException{ out.writeByte(tag); out.writeChar(string_index); CONSTANT_Utf8_info.java Convience class for representing CONSTANTUtf8_info structures within ClassFiles.
import java.io.*; import java.lang.*; Utf8 subtype of a constant pool entry.
We internally represent the Utf8 info byte array as a String.
public final class CONSTANTUtfC_info extends cp_info{ Length of the byte array. public int length; The actual bytes, represented by a String. public String bytes; This constructor should be used for the purpose of part creation. It does not set the parent ClassFile reference.
public CONSTANT Utf8 info(String s) tag 1; length s.length(); bytes s; Used during input serialization by ClassFile only. public CONSTANTUtf8 info(ClassFile cf, DataInputStream in) throws IOException{ super(cf, in); if (tag 1) throw new ClassFormatError(); length in.readChar(); byte[] b new byte[length]; in.read(b, 0, length); WARNING: String constructor is deprecated.
bytes new String(b, 0, length); Used during output serialization by ClassFile only. public void serialize(DataOutputStream out) WO 2005/103927 WO 205/13927PCT/A1J20051000581 throws IQException{ out.writeByte (tag); out.writethar (length); WARNING: Handling of String coversioi here might be problematic.
out.write~ytes (bytes); public String toString(){ return bytes; A26. ConstantValue -attribute.java Convience class for representing ConstantValue-attribute structures within ClassFiles.
import java.lang.*; import jave.io.*; /*Attribute that allows for initialization of static variables in *classes. This attribute will only reside in a field-info struct.
public final class ConstantValue-attribute extends attribute infol public int constantvalue-index; public ConstantValue attribute(ClassFile cf, int ani, mnt al, mnt cvi)j super(cf), attribute -name-index =ani; attribute-length al; constantvalue-index cvi; public ConstantValue_attribute (ClassFile cf, DatalnputStream in) throws IGException) super(cf, in); constentvalue-index in.readCharo; public void serialize (Data~utputStrean out) throws IGExceptionf attribute length 2; super. serialize (out); out.writeChar(constantvalue-index); A27. cp -info.java Convience class for representing cp info structures within ClassFiles.
import jave.lang.*; import java.io.*; /~Represents the common interface of all constant pool parts *that all specific constant pool items must inherit from.
WO 2005/103927 PCT/AU2005/000581 public abstract class cp_info{ The type tag that signifies what kind of constant pool item it is public int tag; Used for serialization of the object back into a bytestream.-*/ abstract void serialize(DataOutputStream out) throws IOException; Default constructor. Simply does nothing. public cp_info() Constructor simply takes in the ClassFile as a reference to it's parent public cp_info(ClassFile cf) Used during input serialization by ClassFile only. cp info(ClassFile cf, DataInputStream in) throws IOException{ tag in.readUnsignedByte(); A28. Deprecated_attribute.java Convience class for representing Deprecated_attribute structures within ClassFiles.
import java.lang.*; import java.io.*; A fix attributed that can be located either in the ClassFile, field info or the method info attribute. Mark deprecated to indicate that the method, class or field has been superceded.
public final class Deprecatedattribute extends attribute_info{ public Deprecated_attribute(ClassFile cf, int ani, int al){ super(cf); attribute name index ani; attributelength al; Used during input serialization by ClassFile only. Deprecated_attribute(ClassFile cf, DataInputStream in) throws IOException{ super(cf, in); A29. Exceptionsattribute.java Convience class for representing Exceptions_attribute structures within ClassFiles.
import java.lang.*; import java.io.*; This is the struct where the exceptions table are located.
<br><br> This attribute can only appear once in a method_info struct.
public final class Exceptions_attribute extends attributeinfo( WO 2005/103927 PCT/AU2005/000581 public int numberofexceptions; public int[] exceptionindextable; public Exceptions_attribute(ClassFile cf, int ani, int al, int noe, int[] eit){ super(cf); attribute name index ani; attribute length al; number of exceptions noe; exceptionindextable eit; Used during input serialization by ClassFile only. Exceptionsattribute(ClassFile cf, DatalnputStream in) throws IOException{ super(cf, in); number of exceptions in.readChar(); exceptionindex_table new int[number_of_exceptions]; for (int i=0; i<number ofexceptions; exception_index_table[i] in.readChar(); Used during output serialization by ClassFile only. public void serialize(DataOutputStream out) throws IOException{ aLtribute_length 2 (number_of_exccptions*2); super.serialize(out); out.writeChar(number of exceptions); for (int i=0; i<number of exceptions; out.writeChar(exception_index table[il); fieldinfo.java Convience class for representing field_info structures within ClassFiles.
import java.lang.*; import java.io.*; Represents the fieldinfo structure as specified in the JVM specification.
public final class field_info{ public int accessflags; public int name_index; public int descriptor_index; public int attributescount; public attributeinfo[] attributes; Convenience constructor. public field_info(ClassFile cf, int flags, int ni, int di){ accessflags flags; name index ni; descriptor_index di; attributes count 0; attributes new attributeinfo[0]; Constructor called only during the serialization process.
<br><br> This is intentionally left as package protected as we should not normally call this constructor directly.
WO 2005/103927 PCT/AU2005/000581 <br><br> Warning: the handling of len is not correct (after String s field info(ClassFile cf, DataInputStream in) throws IOException{ access flags in.readChar(); name index in.readChar(); descriptor index in.readChar(); attributes count in.readChar(); attributes new attribute info[attributes_count]; for (int i=O; i<attributescount; in.mark(2); String s cf.constant_pool[in.readChar()].toString(); in.reset(); if (s.equals("ConstantValue")) attributes[i] rew ConstantValueattribute(cf, in); else if (s.equals("Synthetic")) attributes[i] new Synthetic_attribute(cf, in); else if (s.equals("Deprecated")) attributes[i] new Deprecatedattribute(cf, in); else attributes(i] new attribute_info.Unknown(cf, in); To serialize the contents into the output format.
public void serialize(DataOutputStream out) throws IOException{ out.writeChar(access_flags); out.writeChar(nameindex); out.writeChar(descriptorindex); out.writeChar(attributes_count); for (int i=0; i<attributescount; attributes[i].serialize(out); A31. InnerClassesattribute.java Convience class for representing InnerClasses_attribute structures within ClassFiles.
import java.lang.*; import java.ic.*; A variable length structure that contains information about an inner class of this class.
public final class InnerClassesattribute extends attributeinfo( public int numberofclasses; public classes[] classes; public final static class classes{ int inner class info index; int outer classinfo index; int inner name index; int inner class access flags; public InnerClassesattribute(ClassFile cf, int ani, int al, int noc, classes[] c){ super(cf); attribute name index ani; attribute length al; WO 2005/103927 PCT/AU2005/000581 number of classes noc; classes c; Used during input serialization by ClassFile only. InnerClasses attribute(ClassFile of, DataInputStream in) throws IOException{ super(cf, in); number of classes in.readChar(); classes new InnerClasses attribute.classes[number_of_classes]; for (int i=0; i<number ofclasses; classes[i] new classes(); classes[i].innerclass infoindex in.readChar(); classes[i].outer classinfoindex in.readChar(); classes[i].inner nameindex in.readChar(); classes[i].inner_class_access_flags in.readChar(); Used during output serialization by ClassFile only. public void serialize(DataOutputStream out) throws IOException{ attribute_length 2 (numberofclasses 8); super.serialize(out); out.writeChar(number of classes); for (int i=0; i<number ofclasses; out.writeChar(classes[i].inner_class_info_index); out.writeChar(classes[i].outer classinfo index); out.writeChar(classes[i].inner nameindex); out.writeChar(classes[i].inner_class_access_flags); A32. LineNumberTableattribute.java Convience class for representing LineNumberTable_attribute structures within ClassFiles.
import java.lang.*; import java.io.*; Determines which line of the binary code relates to the corresponding source code.
public final class LineNumberTableattribute extends attributeinfo{ public int line_numbertable_length; public line_number_table[] linenumber_table; public final static class line number_table( int start_pc; int linenumber; public LineNumberTable_attribute(ClassFile of, int ani, int al, int Intl, line number table[] Int){ super(cf); attribute name index ani; attribute length al; line numbertablelength Intl; line number table Int; WO 2005/103927 PCT/AU20051000581 Used during input serialization by ClassFile only. *1 LineNumberTable attribute(ClassFile cf, DatalnputStream in) throws IOException{ super(cf, in); line number table length i.n.readChar(); line number table new LineNumberTable ettribute.line number tabletlinenumber table-length]; for (int i=O; i<line-number-tablelength; i-+)i line number table[i] new line-numbertableo; line number table[i] .startpc in.readCharo; line-number-table[i].line number in.readChar(); Used during output serialization by ClassFile only. *1 void serielize(Data0utputStream out) throws lOExceptioni attribute length 2 (linenumbertable_length 4); super.serialize(out); out.writeChar(line number tablelength); for (int i=0; i<line numbertable_length; out.writeChar line number table[i].start_pc); out.writeCbar~line number table[i].linenumber); A3 3. LocalVariableTable attribute.j ava Convience class for representing LocalVariableTableattribute structures within ClassFiles.
import java.leng.*; import java.io.*; Used by debugger to find out how the source file line number is linked to the binary coda. It has many to one correspondence and is found in the Code attribute.
public final class LocalVariableTable attribute extends attribute info{ public int localvariabletablelength; public localvariabletable[] localvariabletable; public final static class local variable table{ int startpc; int length; int name index; int descriptor index; int index; public LocalVariableTebleattribute(ClassFile of, int ani, int al, int lvtl, local variable table[] lvt){ super(cf); attribute name index ani; attribute-length al; local variable table length lvtl; local variable table lvt; WO 2005/103927 PCT/AU20051000581 Used during input serialization by ClassFile only. LocalVariableTable attribute(ClassFile of, Datalnputstream in) throws IOException{ super(cf, in); local variable table length in.readChar(); local variable table new LocalVariableTableattribute.local variable table[local variable_table lengt h]; for (int i=0; i<local variabletablelength; local variable table[i] new local variabletable(); localvariabletable[i] .start pc in.readChar); local variable table[i].length in.readChar(); local variable tablefi].name index in.readChar(); local variable table[i).descriptor index in.readChar(); local variabletable[il.index in.readChar(); Used during output serialization by ClassFile only. void serialize(DataOutputStream out) throws IOException{ attribute length 2 (localvariabletablelength super.serialize(out); out.writeChar(localvariabletablelength); for (int i=0; i<localvariabletable_length; out.writeChar(local variable table[i].star_gc); out.writeChar(local variable table[i].length); out.writeChar(local variabletable[i].nameindex); out.writeChar(localvariable table[i) .descriptor index); out.writeChar(local variable table[i].index); A34. methodinfo.java Convience class for representing mcthod_info structures within ClassFiles.
import java.lang.*; import java.io.*; This follows the method-info in the JVM specification.
public final class method_info public int accessflags; public int nameindex; public int descriptor_index; public int attributes count; public attribute_info[] attributes; Constructor. Creates a methodinfo, initializes it with the flags set, and the name and descriptor indexes given.
A new uninitialized code attribute is also created, and stored Sin the <i>code</i> variable.*/ public methodinfo(ClassFile cf, int flags, int ni, int di, int ac, attribute info[] a) f access flags flags; name index ni; descriptorindex di; attributes count ac; attributes a; WO 2005/103927 PCT/AU2005/000581 This method creates a method info from the current pointer in the data stream. Only called by during the serialization of a complete ClassFile from a bytestream, not normally invoked directly.
method_info(ClassFile cf, DatalnputStream in) throws IOException{ access_flags in.readChar(); nameindex in.readChar(); descriptorindex in.readChar(); attributescount in.readChar(); attributes new attribute_info[attributescount]; for (int i=0; i<attributes count; in.mark(2); String s cf.constant_pool[in.readChar()].toString(); in.reset(); if (s.equals("Code")) attributes[i] new Codeattribute(cf, in); else if (s.equals("Exceptions")) attributes[i] new Exceptions_attribute(cf, in); else if (s.equals("Synthetic")) attributes[i] new Synthetic_attribute(cf, in); else if (s.equals("Deprecated")) attributes[i] new Deprecated_attribute(cf, in); else attributes[i] new attribute_info.Unknown(cf, in); Output serialization of the methodinfo to a byte array.
Not normally invoked directly.
public void serialize(DataOutputStream out) throws IOException{ out.writeChar(access flags); out.writeChar(name index); out.writeChar(descriptor index); out.writeChar(attributes count); for (int i=0; i<attributescount; attributes[i].serialize(out); SourceFile_attribute.java Convience class for representing SourceFile attribute structures within ClassFiles.
import java.lang.*; import java.io.*; A SourceFile attribute is an optional fixed length attribute in the attributes table. Only located in the ClassFile struct only once.
public final class SourceFileattribute extends attribute info{ public int sourcefile index; public SourceFile_attribute(ClassFile of, int ani, int al, int sfi){ super(cf); attribute name index ani; attribute length al; sourcefile index sfi; Used during input serialization by ClassFile only. WO 2005/103927 WO 205113927PCTiAU2005!000581 SourceFile attribute (ClassFile of, DatalnputStream in) throws IOExceptionf super (cf, in) sourcefile-index in.readCharo); /~Used during output serialization by ClassFile only. void serialize (DataOutputStream out) throws IOException{ attribute length 2; super. serialize (out); out.writeChar (sourcefile index); A3 6. Synthetic -attribute.java Convience class for representing Synthetic-attribute structures within ClassFiles.
import java.lang.*; import java.io., synthetic attribuLe indicates that this class does not have *a generated code source. It is likely to imply that the code Sis generated by machine means rather than coded directly. This *attribute can appear in the classfile, method-info or field-info.
SIt is fixed length.
public final class Synthetic-attribute extends attribute-infof public Synthetic ettribute(ClassFlle cf, lot aol, inL al)( super (cf); attribute name index =ani; attribute-lengt h al; /*Used during output serialization by ClassFile only. Synthetic -attribute (ClassFile cf, DatalnputStream in) throws IO~xception{ super(cf, in); Annexure C Cl. TYPICAL PRIOR ART FINALIZATION FOR A SINGLE MACHINE: Method fmnalizeo o getstatic #9 <Field java.io.PrintStreamn out> 3 Idc 1424 <String "'Deleted invokevirtual 16 <Method void printlnojava.lang. String)> 8 return C2. PREFERRED FINALIZATION FOR MULTIPLE MACHINES Method finalize() o invokestatic #3 <Method boolean isLastReferenceO> 3 ifue 7 6 return 7 getstatic #9 <Field java.io.PrintStream out> WO 2005/103927 PCT/AU2005/000581 Idc #24 <String "Deleted..."> 12 invokevirtual #16 <Method void println(java.lang.String)> return C3. PREFERRED FINALIZATION FOR MULTIPLE MACHINES (Alternative) Method finalize0 0 aload 0 1 invokestatic #3 <Method boolean isLastReference(java.lang.Object)> 4 ifne 8 7 return 8 getstatic #9 <Field java.io.PrintStream out> 11 Ide #24 <String "Deleted..."> 13 invokevirtual #16 <Method void println(java.lang.String)> 16 return Annexure C4 import java.lang.*; public class example{ Finalize method. protected void finalize() throws Throwable{ "Deleted..." is printed out when this object is garbaged.
System.out.printlr ("Deleted... Annexure import java.lang.*; import java.util.*; import java.net.*; import java.io.*; public class FinalClient{ Protocol specific values. public final static int CLOSE -1; public final static int NACK 0; public final static int ACK 1; public final static int FINALIZE_OBJECT FinalServer network values. public final static String serverAddress WO 2005/103927 WO 205113927PCTiAU2005!000581 System.getProperty ("FinalServer_network_address"); public final static int serverPort= Integer.parselnt(System.getProperty("FinalServer-network port")); /*Table of global ID's fcr local cbjects. (hashcode-to-globalID mappings) public final static Hashtable hashCodeToGlobalID new Hashtableo; Called when a object is being finalized. public static boolean isLastReference(Objact o){ /First of all, we need to resolve the globalID for object 'o.
ITo do this we use the bashCodeToGloballD table.
mnt globalID ((Integer) basbCodeToGlobalID.get(o)) .intValueo; try{ /Next, we want to connect to the FinalServer, which will inform /us of tbe finalization status of this object.
Socket socket new Socket(serverAddress, serverPort); DataOutputStream out new DatatutputStream(socket.getoutputStream 0); DatalnputStream in new DatalnputStream(socket.getmnputStreamo); Ok, now send the serialized request to the FinalServer.
out.writalnt (FINALIZEOBJECT); out.writelnt (globalID); out. flush)); Now wait for the reply.
mnt status =in.readInto; IIThis is a blocking call. So we 1will wait until the remote side 1sends something.
if (status ==NAC throw new AssertionError) "Negative acknowledgement. Request failed."); }else if (status ACK)) throw new AssertionError("Unknown acknowledgement:" status Request failed."); /Next, read in a 32bit argument which is the count of the /remaining finalizations WO 2005/103927 WO 205/13927PCT/A1J20051000581 mnt count in.readlnto; /If the count is equal to 1, then this is the lest finalization, /and hence isLastReference should be true.
/If however, the ccunt is greater than 1, then this is not the /last finalization, and thus islastReiference should be false.
boolean isLastReference (count 1 true :false); Close down the connection.
out.writelnt (CLOSE); out. flush out. close in .closeo; socket.closeo; /1Make sure to close the socket.
Return the value of the isLastReference variable.
return isLastReference; }catch (IOException e)( throw new AssertionError("Exceptio: e.toStringo); Annexure C6 import jeve.lang.*; import java.util.*; import java.net.*; import jeva.io.*; public class FinalServer implements Ruonable{ Protocol specific values public final static mnt CLOSE public final static mnt NACK 0; public final static int ACK =1; public final static t-nt FINALIZEOBJECT FinalServer network values. public final static iot serverPort =20001; Table of finalization records. public final static Hashteble finalizations new Hashtableo; WO 2005/103927 PCT/AU2005/000581 Private input/output objects. private Socket socket null; private DataOutputStream outputStream; private DataInputStream inputStream; private String address; public static void main(String[] s) throws Exception{ System.out.println("FinalServer_network_address=" InetAddress.getLocalHost().getHostAddress()); System.out.println("FinalServer_network_port=" serverPort); Create a serversocket to accept incoming initialization operation connections.
ServerSocket serverSocket new ServerSocket(serverPort); while (!Thread.interrupted()){ Block until an incoming initialization operation connection.
Socket socket serverSocket.accept(); Create a new instance of InitServer to manage this initialization operation connection.
new Thread(new FinalServer(socket)).start(); Constructor. Initialize this new FinalServer instance with necessary resources for operation. public FinalServer(Socket s){ socket s; try{ outputStream new DataOutputStream(s.getOutputStream()); inputStream new DataInputStream(s.getInputStream()); address s.getInetAddress().getHostAddress(); }catch (IOException e){ throw new AssertionError("Exception: e.toString()); Main code body. Decode incoming finalization operation requests and Main code body. Decode incoming finalization operation requests and WO 2005/103927 PCT/AU2005/000581 execute accordingly. public void run(){ try{ All commands are implemented as 32bit integers.
Legal commands are listed in the "protocol specific values" fields above.
int command inputStream.readInt(); Continue processing commands until a CLOSE operation.
while (command CLOSE){ if (command FINALIZE_OBJECT){ This is a FINALIZE OBJECT operation.
Read in the globalID of the object to be finalized.
int globalID inputStream.readInt(); Synchronize on the finalizations table in order to ensure thread-safety.
synchronized (finalizations){ Locate the previous finalizations entry for this object, if any.
Integer entry (Integer) finalizations.get( new Integer(globalID)); if (entry null){ throw new AssertionError("Unknown object."); )else if (entry.intValue() 1){ throw new AssertionError("Invalid count."); }else if (entry.intValue() Count of 1 means this is the last reference, hence remove from table.
finalizations.remove(new Integer(globalID)); Send a positive acknowledgement to FinalClient, together with the count of remaining references which in this case is 1.
outputStream.writeInt(ACK); WO 2005/103927 PCT/AU2005/000581 outputStream.writeInt(l); outputStream.flush(); )else{ This is not the last remaining reference, as count is greater than 1.
Decrement count by 1.
finalizations.put(new Integer(globalID), new Integer(entry.intValue() Send a positive acknowledgement to FinalClient, together with the count of remaining references to this object which in this case of must be value "entry.intValue()".
outputStream.writeInt(ACK); outputStream.writelnt(entry.intValue()); outputStream.flush(); }else{ Unknown command.
throw new AssertionError( "Unknown command. Operation failed."); Read in the next command.
command inputStream.readInt(); }catch (Exception e){ throw new AssertionError("Exception: e.toString()); )finally{ try{ Closing down. Cleanup this connection.
outputStream.flush(); outputStream.close(); inputStream.close(); socket.close(); )catch (Throwable t){ t.printStackTrace(); WO 2005/103927 WO 205/13927PCT/A1J20051000581 Garbage these references.
outputStream =null; inputStream null; socket null; ANNEXURE C7 FinalLoader.java This excerpt is the source-code of FinalLoader, which modifies an application as it is being loaded.
import java.lang.*7 import java.io.*'; import java.net.*; public class FinalIoader extends URLClassLoader{ public FinalLoader(URL(] urls){ super (uris); protected Class findClass (String name) throws ClassNotroundException{ ClassFile of null; try[ BufferedInputS~ream in= new BufferedlnputStream(findResourca (name. replace '/').concat(".class"l)).openStreamno); of= new Classyile(in); Icatch (Exception e) {throw new ClassNotroundException(e.toString() for (int i=O; i<cf.methods-count; Find the finalize method info struct.
String methodName cf.const antpool[ cf.methods [ii .name -index] .toStringo; if (!methodName.equals ("finalize"))I continue; Now find the Code attribute for the finalize method.
for (mnt j=O; j<cf.methods~i].attributes count; if (cf.methods[iJ .ettributes[j] instenceof Code-ettribute)) continue; Code attribute ca (Code-attribute) cf.methods .att ributes [jl; First, shift the code[] down by 4 instructions.
byte[][]l code2 new byte[ca.code.length+ 4 ]fl; System.arraycopy(ca.code, 0, code2, 4, ce.code.length); ce.code code2; WO 2005/103927 WO 205/13927PCT/A1J20051000581 Then enlarge the constant-pool by 6 items.
cpinfo[] cpi new cp -info[cf.constantpcol.length+6J; System.arraycopy(cf.constant pool, 0, cpi, 0, cf. constant pool .length);cf.constant pool cpi; cf.constant pool_count 6; Now add the UTF for class.
CONSTANT_-Utf8 info ui new CONSTANTUtf B-info("FinalClient"); cf.constantpool[cf.constantpool.lngth-6] ul; Now add the CLASS for the previous UTF.
CONSTANTClass -info cl new CONSTANTClass info(cf.constant-pocl.length-6); cl; Next add the first UTF for NameAndType.
ul new CONSTANT_-Utf8_info("isLastReterence"); cf .constant pool [cf. constant pool. iength-4] ul; Next: add the second UTF for NameAndType.
ul =new CONSTANT_-Utf8_info(I(Ljava/lang/Cbject;(Z"); cf.constant_pool[cf.constant_pool.iength-3] ul; Next add the NameAndType for the previous two tJTFs.
CONSTANTNameAndType info nl new CONSTANTNarneAndType_info( cf.constant-pool.length-4, cf.constant_pool.length-3); cf.constantpool[cf.constantpool.length-2] nl; Next add the Methodref for the previous CLASS and NameAndType.
CONSTANTN ethodref-info ml new CONSTANTMethedref-info) cf.constant -pool.length-S, cf.constant_pool.length-2); cf.constant pool [cf.constant-pool.iangth-l] ml; 1Now with that done, add the instructions into the code, starting /1with LDC.
ca.code[O] new byte ca.code[0] (byte) 42; Now Add he INVOI ESTATIC instruction.
ca.code~l] new byte[3]; (byte) 184; ca.code[l](1] (byte) ((Ucf.constant_pool.length-l) 8) Oxff); ca.code[l] (byte) ((cf.constantpool.length-l) Oxff); Next add the IFNE instruction.
ca.code[2] new byte[3]; ca.code[2] (byte) 154; ca.code[2] =(byte) 8) Oxff); ca.code[2] (byte) (4 Oxff), Finally, add the RETURN instruction.
ca.code[3] new byte~l]; ca.code[3] (byte) 177; Lastly, increment the CODE-LENGTH and ATTRIBUTE-LENGTH values.
ca.code length 8; ca.attrilbute length 8; WO 2005/103927 PCT/A1J20051000581 try ByteArrayOutputStrein out =new BvteArrayOutputStreamo; cf.serialize (out); byte[] b out.to~yteArrayo); return detineCliass (name, b, 0, b.length); }catch (Exception e)f e .printStackTraceoC; throw new ClassNotFoundException(name);

Claims (26)

1. A multiple computer system having at least one application program each written to operate only on a single computer but running simultaneously on a plurality of computers interconnected by a communications network, wherein different portions of said application program(s) execute substantially simultaneously on different ones of said computers and for each said portion a like plurality of substantially identical objects are created, each in the corresponding computer and each having a substantially identical name, and wherein all said identical objects are collectively deleted when each one of said plurality of computers no longer needs to refer to their corresponding object.
2. The system as claimed in claim 1 wherein each said computer includes a distributed run time means with the distributed run time means of each said computer able to communicate with all other computers whereby if a portion of said application program(s) running on one of said computers no longer needs to refer to an object in that computer then the identity of the unreferenced object is transmitted by the distributed run time means of said one computer to a shared table accessible by all the other computers.
3. The system as claimed in claim 2 wherein each said application program is modified before, during, or after loading by inserting a finalization routine to modify each instance at which said application program no longer needs to refer to an object.
4. The system as claimed in claim 3 wherein said inserted finalization routine modified a pre-existing finalization routine to enable the pre-existing finalization routine to execute if all computers no longer need to refer to their corresponding object, and to disable the pre-existing finalization routine if at least one computer does neet to refer to a corresponding object. The system as claimed in claim 4 wherein the application program is modified in accordance with a procedure selected from the group of procedures consisting of re-compilation at loading, pre-compilation prior to 24 5027D-WO KAM EU, IPE4pu PCT/AU200/0005/000581 Received 16 September 2005 loading, compilation prior to loading, just-in-time compilation, and re- compilation after loading and before execution of the relevant portion of application program.
6. The system as claimed in claim 2 wherein said modified application program is transferred to all said computers in accordance with a procedure selected from the group consisting of master/slave transfer, branched transfer and cascaded transfer.
7. A plurality of computers interconnected via a communications link and operating simultaneously at least one application program each written to operate only on a single computer, wherein each said computer substantially simultaneously executes a different portion of said application program(s), each said computer in operating its application program portion needs, or no longer needs to refer to an object only in local memory physically located in each said computer, the contents of the local memory utilized by each said computer is fundamentally similar but not, at each instant, identical, and every one of said computers has a finalization routine which deletes a non- referenced object only if each one of said plurality of computers no longer needs to refer to their corresponding object.
8. The plurality of computers as claimed in claim 7 wherein the local memory capacity allocated to the or each said application program is substantially identical and the total memory capacity available to the or each said application program is said allocated memory capacity.
9. The plurality of computers as claimed in claim 7 wherein all said distribution update means communicate via said communications link at a data transfer rate which is substantially less than the local memory read rate. The plurality of computers as claimed in claim 7 wherein at least some of said computers are manufactured by different manufacturers and/or have different operating systems. 5027D-WO IPLYVAI PCT/AU2005/000581 Received 16 September 2005
11. A method of running simultaneously on a plurality of computers at least one application program each written to operate only on a single computer, said computers being interconnected by means of a communications network, said method comprising the steps of: executing different portions of said application program(s) on different ones of said computers and for each said portion creating a like plurality of substantially identical objects each in the corresponding computer and each having a substantially identical name, and (ii) deleting all said identical objects collectively when all of said plurality of computers no longer need to refer to their corresponding object,
12. A method as claimed in claim 11 including the further step of: (iii) providing each said computer with a distributed run time means to communicate between said computers via said communications network.
13. A method as claimed in claim 12 including the further step of: (iv) providing a shared table accessible by each said distributed run time means and in which is stored the identity of any computer which no longer requires to access an object, together with the identity of the object,
14. A method as claimed in claim 13 including the further step of: associating a counter means with said shared table, said counter means storing a count of the number of said computers which no longer require to access said object. A method as claimed in claim 14 including the further step of: (vi) providing an additional computer on which said shared program does not run and which hosts said shared table and counter, said additional computer being connected to said communications network.
16. A method of ensuring consistent finalization of an application program written to operate only on a single computer but different portions of which are to be executed substantially simultaneously each on a different one of a plurality of computers interconnected via a communications network, said method comprising the steps of: scrutinizing said application program at, or prior to, or after loading to detect each program step defining an finalization routine, and (ii) modifying said finalization routine to ensure collective deletion of 26 5027D-WO ME PCT/AU2005/000581 Received 16 September 2005 corresponding objects in all said computers only when each one of said computers no longer needs to refer to their corresponding object.
17. The method as claimed in claim 16 wherein said finalization routine is modified to execute to clean-up an object once only and on only one of said computers and when all of said computers no longer need to refer to said object.
18. The method claimed in claim 16 or 17 wherein step (ii) comprises the steps of: (iii) loading and executing said finalization routine on one of said computers, (iv) modifying said finalization routine by said one computer, and transferring said modified finalization routine to each of the remaining computers.
19. The method as claimed in claim 18 wherein said modified finalization routine is supplied by said one computer direct to each of said remaining computers. The method as claimed in claim 18 wherein said modified finalization routine is supplied in cascade fashion from said one computer sequentially to each of said remaining computers,
21. T'he method claimed in claim 16 or 17 wherein step (ii) comprises the steps of: (vi) loading and modifying said finalization routine on one of said computers, (vii)said one computer sending said unmodified finalization routine to each of the remaining computers, and (viii) each of said remaining computers modifying said finalization routine after receipt of same.
22. The method claimed in claim 21 wherein said unmodified finalization routine is supplied by said one computer directly to each of said remaining computers.
23. The method claimed in claim 21 wherein said unmodified finalization routine is supplied in cascade fashion from said one computer sequentially to each of said remaining computers. 27 5027D-WO AME,,- PCT/AU2005/000581 Received 16 September 2005
24. The method as claimed in claim 16 or 17 including the further step of: (ix) modifying said application program utilizing a procedure selected from the group of procedures consisting of re-compilation at loading, pre- compilation prior to loading, compilation prior to loading, just-in-time compilation, and re-compilation after loading and before execution of the relevant portion of application program. The method as claimed in claim 16 or 17 including the further step of: transferring the modified application program to all said computers utilizing a procedure selected from the group consisting of master/slave transfer, branched transfer and cascaded transfer.
26. In a multiple thread processing computer operation in which individual threads of a single application program written to operate only on a single computer are simultaneously being processed each on a corresponding different one of a plurality of computers interconnected via a communications link, and in which objects in local memory physically associated with the computer processing each thread have corresponding objects in the local memory of each other said computer, the improvement comprising collectively deleting all said corresponding objects when each one of said plurality of computers no longer needs to refer to their corresponding object.
27. The improvement as claimed in claim 26 wherein an object residing in the memory associated with one said thread and to be deleted has its identity communicated by the computer of said one thread to a shared table accessable by all other said computers.
28. The improvement as claimed in claim 26 wherein an object residing in the memory associated with one said thread and to be deleted has its identity transmitted to the computer associated with another said thread and is transmitted thereby to a shared table accessable by all said other computers. 28 5027D-WO a PCT/AU2005/000581 Received 16 September 2005
29. A computer program product comprising a set of program instructions stored in a storage medium and operable to permit a plurality of computers to carry out the method as claimed in claim 1 or 16. A plurality of computers interconnected via a communication network and operable to ensure consistent initialization of an application program written to operate only on a single computer but running simultaneously on said computers, said computers being programmed to carry out the method as claimed in claim 11 or 16 or being loaded with the computer program product as claimed in claim 29. 29 5027D-WO W 4 EA r \O i 31. A multiple computer system substantially as herein described in Fig. 5, Fig. 8, or b43 Fig. 13 of Fig. 15 or Figs. 20-22 and with reference to Figs. 16-19 of the drawings. 00
32. A plurality of computers substantially as herein described in Fig. 5, Fig. 8, or Fig. 13 of Fig. 15 or Figs. 20-22 and with reference to Figs. 16-19 of the 00 00 drawings. \33. A method of running simultaneously a plurality of computers, said method being substantially as herein described with reference to Figs. 16-19 of the drawings.
34. A method of ensuring consistent finalization of an application program written to Soperate only on a single computer but different portions of which are to be executed substantially simultaneously each on a different one of a plurality of computers interconnected via a communications network, said method being substantially as herein described with reference to Figs. 16-19 of the drawings. In a multiple thread processing computer operation in which individual threads of a single application program written to operate only on a single computer are simultaneously being processed each on a corresponding different one of a plurality of computers interconnected via a communications link, and in which objects in local memory physically associated with the computer processing each thread have corresponding objects in the local memory of each other said computer, the improvement comprising deleting said corresponding objects substantially as herein described with reference to Figs. 16-19 of the drawings. Dated this 8" day of August 2006 WARATEK PTY LTD By FRASER OLD SOHN Patent Attorneys for the Applicant 5027D-AU
AU2005236088A 2004-04-22 2005-04-22 Modified computer architecture with finalization of objects Ceased AU2005236088B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
AU2005236088A AU2005236088B2 (en) 2004-04-22 2005-04-22 Modified computer architecture with finalization of objects

Applications Claiming Priority (4)

Application Number Priority Date Filing Date Title
AU2004902146 2004-04-22
AU2004902146A AU2004902146A0 (en) 2004-04-22 Modified Computer Architecture
PCT/AU2005/000581 WO2005103927A1 (en) 2004-04-22 2005-04-22 Modified computer architecture with finalization of objects
AU2005236088A AU2005236088B2 (en) 2004-04-22 2005-04-22 Modified computer architecture with finalization of objects

Publications (2)

Publication Number Publication Date
AU2005236088A1 AU2005236088A1 (en) 2005-11-03
AU2005236088B2 true AU2005236088B2 (en) 2007-01-04

Family

ID=36950989

Family Applications (1)

Application Number Title Priority Date Filing Date
AU2005236088A Ceased AU2005236088B2 (en) 2004-04-22 2005-04-22 Modified computer architecture with finalization of objects

Country Status (1)

Country Link
AU (1) AU2005236088B2 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5488723A (en) * 1992-05-25 1996-01-30 Cegelec Software system having replicated objects and using dynamic messaging, in particular for a monitoring/control installation of redundant architecture
WO2002044835A2 (en) * 2000-11-28 2002-06-06 Gingerich Gregory L A method and system for software and hardware multiplicity
US6625751B1 (en) * 1999-08-11 2003-09-23 Sun Microsystems, Inc. Software fault tolerant computer system
WO2003083614A2 (en) * 2002-03-25 2003-10-09 Eternal Systems, Inc. Transparent consistent active replication of multithreaded application programs
US20040073828A1 (en) * 2002-08-30 2004-04-15 Vladimir Bronstein Transparent variable state mirroring

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5488723A (en) * 1992-05-25 1996-01-30 Cegelec Software system having replicated objects and using dynamic messaging, in particular for a monitoring/control installation of redundant architecture
US6625751B1 (en) * 1999-08-11 2003-09-23 Sun Microsystems, Inc. Software fault tolerant computer system
WO2002044835A2 (en) * 2000-11-28 2002-06-06 Gingerich Gregory L A method and system for software and hardware multiplicity
WO2003083614A2 (en) * 2002-03-25 2003-10-09 Eternal Systems, Inc. Transparent consistent active replication of multithreaded application programs
US20040073828A1 (en) * 2002-08-30 2004-04-15 Vladimir Bronstein Transparent variable state mirroring

Non-Patent Citations (6)

* Cited by examiner, † Cited by third party
Title
H. E. Bal et al, A Distributed Implementation of the Shared Data-Object Model, Proc. USENIX Workshop on Experiences with Distributed and Multiprocessor Systems, pp. 1-19, October 1989 *
H. E. Bal et al, Object Distribution in Orca Using Compile-Time and Run-Time Techniques, Proc. Conference on Object-Oriented Programming Systems, Languages and Applications, pp. 162-177, September 1993 *
H. E. Bal et al, Orca: A Language for Parallel Programming of Distributed Systems, IEEE Transactions on Software Engineering, 18(3), pp. 190-205, March 1992 *
H. E. Bal et al, Replication Techniques for Speeding up Parallel Applications on Distributed Systems, Concurrency Practice & Experience, 4(5), pp. 337-55, August 1992 *
H.E. Bal et al, Experience with Distributed Programming in Orca, Proc. IEEE CS International Conference on Computer Languages, pp. 79-89, March 1990 *
T.C. Bressoud, TFT: A Software System for Application-Transparent Fault Tolerance, Proc. 28th Annual International Symposium on Fault-Tolerant computing, p. 128-37, 1998 *

Also Published As

Publication number Publication date
AU2005236088A1 (en) 2005-11-03

Similar Documents

Publication Publication Date Title
US7844665B2 (en) Modified computer architecture having coordinated deletion of corresponding replicated memory locations among plural computers
CA2563900C (en) Modified computer architecture with coordinated objects
US20060095483A1 (en) Modified computer architecture with finalization of objects
US20060020913A1 (en) Multiple computer architecture with synchronization
US20050262513A1 (en) Modified computer architecture with initialization of objects
US20060265705A1 (en) Computer architecture and method of operation for multi-computer distributed processing with finalization of objects
AU2005236088B2 (en) Modified computer architecture with finalization of objects
AU2005236087B2 (en) Modified computer architecture with coordinated objects
AU2005236085A1 (en) Modified computer architecture with initialization of objects
AU2005236086A1 (en) Multiple computer architecture with synchronization
AU2005236089A1 (en) Multiple computer architecture with replicated memory fields
AU2006238334A1 (en) Modified computer architecture for a computer to operate in a multiple computer system

Legal Events

Date Code Title Description
FGA Letters patent sealed or granted (standard patent)
MK14 Patent ceased section 143(a) (annual fees not paid) or expired