A data processing system

Abstract: The present invention provides a data processing system and method of operating such a system, where the system comprises an operating system (10), memory (20) controlled by the operating system (10) and a first process (30) having a first portion (50) of the memory (20) associated therewith. An allocation means (60) is provided, which is accessible by the first process, and is used to create an object in the first portion of memory (50). The system is characterised by: a designation means (80) for designating the first portion of memory as memory to be shared between a plurality of processes; and an identification means (90) to indicate to a second process (100) the location of the object in the first portion of memory. By this technique instances of objects can be shared between a plurality of processes.

Description: The present invention relates to a data processing system having a message based environment in which 'objects' are created and utilised by processes running on the system. A message based environment is used by Object Oriented Programming (OOP) techniques, OOP being a particular approach to software development which implements required functions by way of 'messages' sent to 'objects'. An 'object' is a software component that contains a collection of related procedures (hereafter called 'methods') and data. Further objects can be grouped into 'Object Classes', an object class being a template for defining the methods and data for a particular type of object. All objects of a given class are identical in form and behaviour but have different data associated therewith. A 'message' is a signal sent to an object to request the object to carry out one of its methods. Hence a message sent to an object will cause a method to be invoked to implement the required function. When a process is running on a data processing system, there may be a requirement at some stage for an 'instance' of an object to be created for future use by the process. Typically the OOP environment in which the process is running will have a standard operator defined for creating instances of an object, and this operator would be expressed as part of the process to indicate that the process requires a particular object to be created. At the time that the process was initialised (or at some other convenient time before an instance of an object is created) the OOP environment would have obtained a block of memory from the operating system of the data processing system for use by the process. Hence the new object will be created in that piece of memory. Since the piece of memory would generally be private to the process for which it was obtained, then the object instance created in that memory will also be private to the particular process. However with the increase in complexity of applications written in OOP languages, it is becoming desirable for instances of objects to be accessible by processes other than the process which has created that instance. Techniques are known for designating portions of memory as shared memory, in which a plurality of processes can share data stored in that portion of memory. However these techniques do not allow instances of objects, which consist not only of data but also methods, to be shared between processes. The problem that arises is how to enable a process to have access to the methods of an object instance that it has not created, and so be able to share the object. Hence it is an object of the present invention to provide a data processing system in which objects created for a first process are accessible to one or more other processes. Accordingly the present invention provides a data processing system comprising: an operating system; memory controlled by the operating system; a first process having a first portion of the memory associated therewith; allocation means, accessible by the first process, for creating an object in the first portion of memory; the system being characterised by: designation means for designating the first portion of memory as memory to be shared between a plurality of processes; and an identification means to indicate to a second process the location of the object in the first portion of memory. In preferred embodiments the designation means is activated by the first process when the first process is initialised. However this need not be the case, and an alternative would be to operate the designation means at some other time before an object is to be allocated in a shared portion of memory. The designation means can either specifically identify the plurality of processes that are to be authorised to access the first portion of memory (eg the first and the second process), or alternatively, if security is not an issue, the designation means can just indicate that the portion of memory is to be made available to any process that can identify that portion of memory. The identification means can indicate to the second process the location of the object in a variety of different ways, eg. by using one of a number of possible IPC mechanisms. In the preferred embodiment the identification means indicates the location of the object by placing a pointer to that object in an input queue defined by the second process. With this technique it is possible to stack up a number of objects on the queue for subsequent receipt and running by the second process. The second process may be resident on the same data processing system as the first process, but alternatively it could be resident on another system connected via a network with the data processing system of the present invention. The first and second processes may perform any manner of functions, and may be client/server type processes, or alternatively similar processes that need to share information. In the preferred embodiment the second process is a database server process for administering requests to a database, and the first process is a client process of the second process. In this arrangement, the object created by the allocation means is the request for the database. In preferred embodiments a memory obtaining means is provided to obtain the first portion of memory from the operating system for use by the plurality of processes. This may be invoked as a separate method or alternatively can be included as part of a method carrying out this function in addition to the function of designating the memory as shared memory. Viewed from a second aspect the present invention provides a method of operating a data processing system comprising an operating system, memory controlled by the operating system, and a first process having a first portion of the memory associated therewith, the method comprising the steps of: invoking an allocation means, in response to the first process, to create an object in the first portion of memory; the method being characterised by the steps of: operating a designation means to designate the first portion of memory as memory to be shared between a plurality of processes; and in response to the first process, employing an identification means to indicate to a second process the location of the object in the first portion of memory. The present invention will be described further, by way of example only, with reference to an embodiment thereof as illustrated in the accompanying drawings, in which: Figure 1 is a block diagram illustrating the data processing system of the preferred embodiment; Figure 2 illustrates the technique of the preferred embodiment; and Figure 3 further illustrates the technique shown in Figure 2. In the preferred embodiment of the present invention we will consider a data processing system having the IBM OS/2 (IBM and OS/2 are Trade Marks of International Business Machines Corporation) operating system. The OOP environment will consist of all the elements necessary to enable OOP applications to be developed; in the preferred embodiment it comprises the IBM OS/2 V2.1 operating system, the IBM OS/2 Development Toolkit V2.1, and the IBM C++ Compiler CSet/2. Further in the preferred embodiment the data processing system also has the IBM DB2/2 database software (DB2/2 is a Trade Mark of International Business Machines Corporation). This environment will enable C++ applications to be written. In the preferred embodiment the C++ application being developed will be a client/server application. This application will include a number of processes which may need to interact. For instance there may be a process 'B' established to administer 'requests' to a database; generally it is advisable, for reasons of robustness and performance, to perform lengthy operations such as database access in a separate process. Another process 'A' may act as a client of process 'B' since it may require the services of process 'B' in order to extract some data from the database for its subsequent use. In the preferred embodiment the 'requests' which are packaged and sent by process 'B' to be serviced by the database are C++ objects, which we will hereafter refer to as "Request Objects". Several request objects can be defined, each one being able to perform one particular database transaction. Process A may create a request object and then make it available to process B using the technique of the preferred embodiment of the present invention. The technique by which a particular request object is created by process A and then made available to process B will now be discussed with reference to Figure 1, which is a block diagram of the data processing system of the preferred embodiment. The data processing system includes an operating system 10 such as the IBM OS/2 operating system which, amongst other things, has control of local memory 20. When process A is initialised it instructs the memory obtaining means 40 to obtain from the operating system 10 a first portion 50 of memory 20 for use by process A. In the preferred embodiment the designation means 80 will designate the first portion of memory 50 as memory to be shared between a plurality of processes. The designation means 80 will do this by informing the operating system 10 that a process or processes other than process A are to have read/write access to the first portion of memory 50. The other processes may be specifically identified to the operating system by the designation means or, alternatively, if security is not an issue, the designation means can just indicate that the portion of memory 50 is to be made available to any process that can identify that portion of memory. The memory obtaining means 40 and the designation means 50 are actually implemented as methods of a special object, hereafter called a "Shared Allocator Object". The Shared Allocator Object replaces the standard C++ code used to create new instances of objects (commonly referred to as the 'NEW' operator), and carries out the functions of creating and managing shared portions of memory, and of allocating new instances of objects in the shared portion of memory. The Shared Allocator object will be described in more detail later. In the preferred embodiment we will assume that security is not an issue, that the designation means has hence indicated to the operating system that the portion 50 of memory is to be shared by unspecified processes, and that process B knows where the portion 50 of memory is. Since any process can access the portion of memory 50, process B need not approach the Shared Allocator object (as manager of the shared portion of memory) to request access to the shared memory; instead process B can access the memory portion 50 directly. Once the shared portion 50 of memory has been established by the memory obtaining means 40 process A 30 can create instances of objects in that memory. This is done by invoking the allocation means 60 to create the instance from a particular class specified by process A. The allocation means 60 is another method of the Shared Allocator object, and accesses storage 70 to obtain details of the object class from which a particular instance is to be created. In our preferred embodiment the methods for particular objects are stored in code libraries, which in the OS/2 environment are referred to as Dynamic Link Libraries (DLL). Typically these libraries will be resident in the storage 70 of the data processing system. When the C++ runtime system (forming part of the compiler) creates an instance of an object in memory 50, it does so by establishing a table of pointers, each pointer pointing to a method in the code library, and then adding a block of data to be associated with that table. When a method is subsequently to be carried out, the pointer can be used to extract the relevant code from the code library and then run the code using the data as appropriate. The table mentioned above which contains a list of code pointers to the methods of a particular object is referred to as a "Virtual Function Table" (vft). Each object instance can hence be considered basically as a Vft and data. When an object instance is created by a first process its vft is set up with pointers to methods residing in the DLL. The DLLs are built as runtime libraries which other executables or DLLs can load code from on demand. By locating, in the preferred embodiment, the methods for objects in these DLLs they can in theory be shared by a number of concurrently executing programs (processes). The problem then is to make each process recognise which methods to run from the DLL whenever it receives an object from another process. If a second process receives access to an object created by process A, it must be able to reference the code (methods) pointed to by the Vft if it is to make use of that object. This is achieved as follows. Once the allocation means 60 has created a new instance of an object in shared memory 50, process A can then place necessary data in that object instance. This having been done process A may then require to make the instance available to process B. Process B may for example be the database server process mentioned earlier, and the instance created by process A may be a Request object. In the preferred embodiment process B is able to get access to the shared memory 50 since, as mentioned earlier, it knows the location of the memory portion and process A has not restricted access. However process B now needs to know where the object instance in question is located within that memory if it is to make use of that instance. Process A provides this information by way of a 'pointer' sent by the identification means 90 using an appropriate IPC mechanism. In the preferred embodiment process B defines an input queue, and waits for requests on that queue. The object pointer is then sent by the identification means 90 to that queue, where its presence is brought to the attention of process B by the operating system. By using a queue several object pointers can be 'stacked up' on the queue as a queue of requests for the server process B. Once the operating system has informed process B of the presence of a pointer on the queue, process B reads the pointer from the queue, which then enables it to access the object instance (vft plus data) in the shared memory. Once process B has linked in the appropriate DLL containing the methods of this object instance, process B is then in a position to utilise the object. In the preferred embodiment, when process B initialises itself, it loads in the DLL containing the code and vfts for all objects it intends to use (eg. receive on the queue). Although this need not necessarily happen at initialisation it will need to occur before process B is in a position to utilise any object instance indicated via a pointer on the queue. In the OS/2 environment the simplest way to load in the above-mentioned DLL is to use a function call called 'DosLoadModule'. The DosLoadModule call is a type of function call that loads a particular load module (DLL) into a program so that program can use any of the functions in that module. Similar function calls will be available in other environments. When process B receives a pointer to an object from process A (via the IPC), it needs to then cast this pointer to a type of object which encompasses all types of objects which it expects to receive. For instance in our preferred embodiment the database server process B will expect all objects received to be request objects, such objects having the common feature (as discussed later) of containing a RUN method which can be invoked by process B. Process B does this 'casting' by using any general parent class (eg. in the preferred embodiment it will use the general Request object class). When a message is sent to the shared object instance, the OOP environment (eg. C++) will immediately try to resolve this message into a method through the Vft of the object stored in shared memory 50. It will be able to resolve this message because the DLL where the code for the method resides will already have been loaded earlier by process B (eg. via a DosLoadModule call). In the preferred embodiment where the shared object is a Request object, all that the database server process B has to do is to invoke a 'Run' method in the Request object, no matter what the request actually is, and the Request object will then take over. The Request object will for instance access the database and extract the required data, but within the database server process B. Once the required data has been retrieved from the database the request object will store it in the shared memory, then open a return queue to the client process A, and return pointers to that data. The above technique has the following advantages. By using memory containing function pointers (in the vft) to addresses of code residing in DLLs it has been found that any secondary process can load code from this DLL to reconcile with the vft it receives in memory from the first process A. Further, by loading the code from the DLL in the secondary process, that process can 'run' any method of any object in that DLL, given a valid vft. The Shared Allocator that, as discussed earlier, carries out the functions of creating and managing shared portions of memory, and of allocating new instances of objects in the shared portion of memory, will now be discussed in more detail. In C++, two standard operators are provided to handle the dynamic creation and deletion of objects. These operators are referred to as NEW and DELETE, and similar operators will exist in other OOP environments. In the preferred embodiment of the present invention these two operators have been replaced, a new C++ object class having been created, which we refer to as the Shared Allocator Class. Any object allocated from such a class will supply the following 5 methods. 1. Constructor. This special method is called once when the Shared Allocator object is first created. Basically, this method calls the Operating System to allocate a block (portion) of memory, and makes this block shareable among other processes. With reference to Figure 1 this method is implemented by the memory obtaining means (40) and the designation means (80). It also calls the Operating System to prepare the memory block for use as a heap. This means that many individual pieces of memory can be "Sub-Allocated" from within this memory block. 2. AllocMemory This method is called when a piece of memory is to be allocated. This would normally be as a result of a NEW call in C++ programs, and is represented in Figure 1 by the allocation means (60). This method checks whether or not Shared Memory is in use within a process. (Each process using the Shared Allocator object has its own flag indicating this state.) If Shared Memory is in use, (ie. the client process A had called the UseSharedMemory method described below) then the space required is allocated from the Shared Memory heap managed by the Shared Allocator object. This is also done by a call to the Operating System. If Shared Memory is not in use, then the normal C++ method of allocating (non-shared) memory is used (called 'MALLOC' in OS/2). 3. FreeMemory This method is called when a piece of memory is to be freed. This would normally be as a result of a DELETE call in C++ programs. This method checks whether or not the block of memory has been allocated from the Shared Heap. ( The start address and size of the Shared Heap are kept as instance data in the Shared Allocator object.) If the memory block was allocated on the Shared Heap, then the appropriate Operating System call is made to return this block to the Heap. If the block was not allocated from the Shared Heap, then the normal C++ method of freeing (non-shared) memory is used (called FREE in OS/2). 4. UseSharedMemory This method simply sets a flag for the calling process, which indicates that any future allocation calls from that (client) process should use the Shared Heap. 5. Destructor This method is called when the Shared Allocator object is about to be destroyed, for example at the end of a program. It once again calls the Operating System to free up the block of Shared Memory which it had been managing. Now, all that is necessary is to declare a single Global Shared Allocator object, and use standard C++ Syntax to replace the standard NEW and DELETE operators. NEW should be made to call the AllocMemory method, and DELETE to call the FreeMemory method. The object code for the above described methods should then be added to the C++ runtime library, replacing the old NEW and DELETE code. The method for doing this is compiler dependant, but will be apparent to the person skilled in the art. To further illustrate the operation of the preferred embodiment we will now consider the diagram of Figure 2. When process A 30 is initialised, it calls the Shared Allocator object to obtain a base heap of memory 50 to be used as shared memory. The method of the Shared Allocator object which performs this function is the 'Constructor' method described earlier. After the constructor method has completed there will be a base heap of memory 50 for which a plurality of processes (specifically identified or unspecified depending on security requirements) have been allowed read/write access. In figure 2, process A 30 and process B 100 are shown having read/write access to the shared heap 50. Process A then uses the 'new' operator at step 1 of the process to invoke the AllocMemory method of the Shared Allocator object to create an object instance and allocate it on the base heap 50. As mentioned earlier the standard new operator has been overridden so that using the 'new' operator now directly invokes the AllocMemory method. Having allocated the object instance process A can then fill it with data. Then at step 2 of Process A, a pointer is sent by the identification means 90 to a queue 150. As mentioned earlier several such objects can be stacked up on the queue. The operating system will inform process B of the presence of an object pointer on the queue 150 and process B 100 will then retrieve that pointer. Using the pointer, process B can then access the object in the shared heap 50 and retrieve the data and vft. Since the DLL containing the methods for that object will already have been loaded by process B it can then use the vft to invoke the 'run' method for that object. This having been done the object will perform a set task such as retrieving data from a database, will store that data in the shared heap, and will then send a pointer back to process A to indicate where that retrieved data has been stored. Figure 3 further illustrates the technique shown in Figure 2. Process A creates an instance of an object with a pointer 'x' pointing to it. This instance is then filled with data and the pointer x sent to a queue 150. On the other side of the process boundary process B reads the pointer x using the OS/2 command "DosReadQueue". Then the vft and data in the shared memory heap 50 are automatically read using the pointer 'x'. In the preferred embodiment each Request object is responsible for performing one particular Database transaction. To implement this, each object implements a method called 'run()'. This method title is never changed, and is only invoked by the server process B. A class hierarchy of request objects is created, an example being as follows: As an example consider the following C++ class definition: The first line of the definition identifies a class that is to be called InsDbInfoReg and is to be inherited from the class DBMRequest. The "_Export" qualifier signifies that something (eg. another DLL) external to the DLL (in which the methods for this class are to be stored) will run the class. The word "public" appearing on the next line indicates that everything to follow is to be available to objects other than that be being defined (ie. InsDbInfoReq). The next line of code sets up a pointer 'dbData' to a data structure of the type 'DbInfo'. Then after the colon the term 'DXTDBMRequest()' is a call to the constructor method of the parent class DBMRequest. The next line sets the instance data IkeyData equal to the pointer dbData. The next line defines a 'run' method of the type 'unsigned short'. The function to be called is DBR_C_DBINFO. The last two lines define a piece of information that is private to the object class, namely a pointer IKeyData pointing to a data structure of the type DbInfo. Having defined the class InsDbInfo consider the following sample piece of code: Process A Process B DbInfo* info = new DbInfo info->name = "newDataRow" info->date = "010193" info->time = "13:15:09" // create object on heap InsDbInfoReq* x = new InsDbInfoReq( info ); // Hierarchy implements send method // Process B receives ptr to // which sends ptr to specific process // object and casts it to a x->send(); // general DBM request DosReadQueue( &ptr ); request = (DBMRequest *) ptr; // Run the request request->run(); The first four lines in process A handle the setting up of a pointer to a DbInfo structure called 'Info', and the placing of certain information (name, date time) in that data structure. Then an instance of the object class InsDbInfoReq is created with a pointer 'x' pointing to it; this instance has the data contained in the data structure called 'Info'. The 'send' method (resident in a parent class) is then invoked to send the object pointer 'x' to process B. Process B receives this pointer and casts it to the general class DBMRequest. This occurs automatically, it having already been decided that process B is to expect objects of the type DBMRequest from process A. Next the 'run' method of this request object is run, resulting in the request being processed and the desired information returned to process A.

Claims: A data processing system comprising: an operating system (10); memory (20) controlled by the operating system (10); a first process (30) having a first portion (50) of the memory (20) associated therewith; allocation means (60), accessible by the first process, for creating an object in the first portion of memory (50); the system being characterised by: designation means (80) for designating the first portion of memory as memory to be shared between a plurality of processes; and an identification means (90) to indicate to a second process (100) the location of the object in the first portion of memory. A data processing system as claimed in Claim 1, wherein the designation means (80) is activated by the first process (30) when the first process is initialised. A data processing system as claimed in Claim 2, wherein the designation means (80) specifies the second process as being authorised to access the first portion of memory. A data processing system as claimed in any preceding claim, wherein the identification means (90) indicates the location of the object by placing a pointer to that object in an input queue defined by the second process (100). A data processing system as claimed in any preceding claim, wherein the second process (100) is resident on another system connected via a network with the data processing system. A data processing system as claimed in any preceding claim wherein the second process (100) is a database server process for administering requests to a database, and the first process is a client process of the second process, the object created by the allocation means (60) being the request for the database. A data processing system as claimed in any preceding claim, wherein a memory obtaining means is provided to obtain the first portion of memory from the operating system for use by the plurality of processes. A method of operating a data processing system comprising an operating system (10), memory (20) controlled by the operating system (10), and a first process (30) having a first portion (50) of the memory (20) associated therewith, the method comprising the steps of: invoking an allocation means (60), in response to the first process, to create an object in the first portion of memory (50); the method being characterised by the steps of: operating a designation means (80) to designate the first portion of memory as memory to be shared between a plurality of processes; and in response to the first process, employing an identification means (90) to indicate to a second process (100) the location of the object in the first portion of memory (50).

Inventors: CUNNINGHAM CONNEL G, O'ROURKE FERGHILL J, CUNNINGHAM, CONNEL G., O'ROURKE, FERGHILL J.
Applicants: IBM, INTERNATIONAL BUSINESS MACHINES CORPORATION
Application year: 1994
Main classification: G06F9
IPC codes: G06F9