Optimizing parameter passing

Data processing: software development – installation – and managem – Software program development tool – Translation of code

Reexamination Certificate

Rate now

  [ 0.00 ] – not rated yet Voters 0   Comments 0

Details

Reexamination Certificate

active

06481007

ABSTRACT:

FIELD OF THE INVENTION
This invention relates to the run-time efficiency of computer programs and, more specifically, to a method for optimizing parameter passing.
BACKGROUND OF THE INVENTION
An important consideration in many computer programs and programming languages is performance. Speed and correctness are examples of performance metrics, and are critical to the viability of computation intensive computer programs.
The quest for greater run-time speeds has often focussed on ways that information or data and data structures can be accessed and manipulated. Often, computer programs include routines that carry out well-defined operations on data specified by parameters. As used herein, the term “routine” refers to functions, procedures, methods and/or subroutines. To transfer control to a routine, a call is made to the routine. For the purposes of explanation, the portion of code that makes a call to a routine will be referred to as the “calling routine”, while the portion of the code thus called is the “called routine”. Typically, parameters are provided from the calling routine to the called routine as input for each call.
The act of passing parameter values to a called routine is known as “parameter passing”. Two common methods of parameter passing are “call by value”, and “call by reference”. The following definitions aid in explaining parameter passing. A “formal parameter” is a parameter value stored in a storage location that is used by the called routine. An “actual parameter” is a parameter value stored in a storage location used by the calling routine. From the perspective of the calling routine, the “actual parameter” is passed to and/or received from the called routine. From the perspective of the called routine, the “formal parameter” is received from and/or passed to the calling routine.
In the case of “call by value”, the actual parameter and the corresponding formal parameter are stored in separate storage locations. Specifically, the value of the actual parameter in the calling routine is copied to a separate storage allocated for holding the formal parameter in the called routine. Therefore, any changes made to the formal parameters of the routine modify only the copy of the actual parameter. Only upon successful completion of execution of the called routine, the modified value of the formal parameter is copied back to the actual parameter. Thus, when the called routine fails with an unanticipated error (“unhandled exception”), the modified value of the formal parameter is not copied back to the actual parameter. This ensures that the actual parameter remains uncorrupted by any exception occurring during execution of the called routine. Note that for anticipated errors (handled exceptions), it is assumed that the proper recovery mechanism is employed.
However, the disadvantage of “call by value” parameter passing is that it is inefficient. As explained above, in executing a call, two copy operations are performed for each parameter for “call by value”. The first copy is performed when the value of the actual parameter is copied to a separate storage allocated for holding the formal parameter of the routine before execution of the routine (copy-in). The second copy is performed when the modified value of the formal parameter of the called routine is copied back to the actual parameter upon successful completion of execution of the called routine (copy-out). Thus, the copy-in and copy-out transactions incurred in “call by value” parameter passing are inefficient. This is of particular concern in database systems where applications manipulate large volumes of data and where a parameter can comprise a very large data structure, such as a large record, or large array.
In the case of “call by reference”, the same storage location is used for both the actual and formal parameters. Specifically, the address of the actual parameter of the calling routine is passed to the called routine. Any changes made by the called routine to the formal parameter directly modify the actual parameter. There is no copy-in and copy-out of the parameters. Because no copies of the values of the parameters are required in “call by reference” parameter passing, it is more efficient than “call by value” parameter passing. However, there are at least two disadvantages to “call by reference” parameter passing.
One obvious disadvantage to “call by reference” parameter passing is that the routine directly modifies the actual parameter as explained above. Thus, when the called routine fails due to an unhandled exception, whatever undesirable modifications made by the called routine are made directly to the actual parameters.
Another disadvantage to “call by reference” parameter passing is in the context of aliases. Two parameters in a program are said to be aliased if they both point to the same memory location. This can cause unintended results. For example, consider a procedure that has two parameters. Suppose the same parameter is passed twice in the same call to the procedure using “call by reference” as illustrated in the following pseudocode, interspersed with explanatory comments denoted by the prefix, “ - - - ”:
main ( )
n number;
begin
n:=10;
proc (n, n); - - - call to the routine proc end;
Assume that the routine proc is as follows:
proc (p
1
number, p
2
number) is
begin
p
1
:=5;
print (p
2
);
end;
The print statement in the above routine will produce the value 5 if p
1
and p
2
are passed using “call by reference”. Both p
1
and p
2
point to the same memory location, i.e. the memory location of the actual parameter, n. The first assignment,
p
1
:=5;
would modify the value of p
2
as well. Clearly, this produces an unintended result.
Note that if the p
1
and p
2
were passed to routine proc using “call by value” parameter passing, the print statement would produce the value 10. Even though the same variable n was passed twice to the routine proc as actual parameters, two separate copies of the actual parameter, one bound to p
1
and the other bound to p
2
, were made before execution of routine proc. Thus, the following assignment would only modify the copy of the actual parameter that is bound to p
1
.
p
1
:=5;
However, the copy of the actual parameter that is bound to p
2
remained intact. Thus, the following print statement would produce the value 10.
print (p
2
);
To summarize, “call by value” parameter passing has the advantage of clean semantics in the context of exception handling and aliases. However, this advantage comes at the expense of performance. Whereas “call by reference” parameter passing has the advantage of good performance but may produce unintended results in the context of aliases. “Call by reference” parameter passing may also cause corruption of actual parameters due to unhandled exceptions.
Alias detection and prevention is a well-researched problem. A number of techniques have been suggested in the literature. An appropriate technique can be used in conjunction with this invention to determine the presence of aliasing among parameters as well as among global variables and subprogram parameters.
Based on the foregoing, there is a need for a method or mechanism to take advantage of better performance provided by “call by reference” parameter passing while obviating unintended results in the context of aliases and corruption of actual parameters due to unhandled exceptions.
SUMMARY OF THE INVENTION
The foregoing needs are addressed by the present invention, which comprises, in one aspect, a method and system for optimizing the passing of a parameter to a routine. It is determined if any parameters are aliased in a call to a called routine. In the absence of aliases, calling routines pass parameters to called routines using “call by reference”. Recovery mechanisms are provided, when appropriate, when unhandled exceptions occur during execution of the called routines.
According to one aspect of the invention, a recovery mechanism includes encapsulating the called routine and call statement block with a “catch-all” exception handl

LandOfFree

Say what you really think

Search LandOfFree.com for the USA inventors and patents. Rate them and share your experience with other people.

Rating

Optimizing parameter passing does not yet have a rating. At this time, there are no reviews or comments for this patent.

If you have personal experience with Optimizing parameter passing, we encourage you to share that experience with our LandOfFree.com community. Your opinion is very important and Optimizing parameter passing will most certainly appreciate the feedback.

Rate now

     

Profile ID: LFUS-PAI-O-2965286

  Search
All data on this website is collected from public sources. Our data reflects the most accurate information available at the time of publication.