JPH08272621A - Function call processing method for securing dynamic memory area - Google Patents
Function call processing method for securing dynamic memory areaInfo
- Publication number
- JPH08272621A JPH08272621A JP7500895A JP7500895A JPH08272621A JP H08272621 A JPH08272621 A JP H08272621A JP 7500895 A JP7500895 A JP 7500895A JP 7500895 A JP7500895 A JP 7500895A JP H08272621 A JPH08272621 A JP H08272621A
- Authority
- JP
- Japan
- Prior art keywords
- function
- memory area
- function call
- dynamic memory
- statement
- 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.)
- Pending
Links
Abstract
Description
【0001】[0001]
【産業上の利用分野】本発明は、動的にメモリ領域を確
保する関数呼出し文を含むソースプログラムをコンパイ
ルするコンパイラに関するものである。BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a compiler for compiling a source program including a function call statement for dynamically allocating a memory area.
【0002】[0002]
【従来の技術】従来、プログラムが動的にメモリ領域を
確保する必要がある場合、そのプログラム言語のライブ
ラリまたはオペレーティングシステムが用意するヒープ
操作を基にしたメモリ領域確保の関数を呼ぶことによつ
てメモリ領域を確保し、そのメモリ領域をプログラム中
で使用した後、同メモリ領域を解放する関数を呼び出し
ていた。2. Description of the Related Art Conventionally, when a program needs to dynamically reserve a memory area, a function for allocating a memory area based on a heap operation prepared by a library of the programming language or an operating system is called. After allocating a memory area and using that memory area in a program, a function that releases the memory area was called.
【0003】また関数スタック内に動的にメモリ領域を
確保することによって、処理関数の終了時に関数内の局
所的な変数領域と一緒にメモリ領域を解放して解放処理
を容易にし、ヒープ操作を基にした動的メモリ領域確保
の処理よりも高速に処理を行うライブラリもある。この
ライブラリの代表的なものとしてalloca関数があ
る。Further, by dynamically allocating a memory area in the function stack, the memory area is released together with the local variable area in the function at the end of the processing function to facilitate the release processing, and the heap operation is performed. There is also a library that performs processing faster than the dynamic memory area allocation processing based on it. A representative of this library is the alloca function.
【0004】[0004]
【発明が解決しようとする課題】ヒープ操作を基にした
動的メモリ領域の確保、解放を行う関数は、オペレーテ
ィングシステムを呼び出すために静的メモリ領域の確保
を行う処理と比べて多くの処理時間を要するという問題
がある。ここで静的メモリ領域とは、プログラム中で変
数を定義することによって確保されるメモリ領域であ
る。A function for allocating and releasing a dynamic memory area based on heap operations requires a lot of processing time as compared with a process for allocating a static memory area for calling an operating system. There is a problem that requires. Here, the static memory area is a memory area secured by defining variables in the program.
【0005】スタック内に動的メモリ領域を確保する関
数は、オペレーティングシステムが介入しないためヒー
プ操作に基づいて動的メモリ領域を確保する関数より高
速に処理することができるが、メモリ領域の確保を行っ
たプログラム処理関数の終了と共にスタックが消滅する
ため、処理関数を越えてメモリ領域を使用できない。こ
のためユーザの判断によって確保した動的メモリ領域が
有効な範囲を考慮しなければならない。The function for allocating the dynamic memory area in the stack can be processed at a higher speed than the function for allocating the dynamic memory area based on heap operation because the operating system does not intervene. Since the stack disappears when the executed program processing function ends, the memory area cannot be used beyond the processing function. Therefore, it is necessary to consider the effective range of the dynamic memory area secured by the user's judgment.
【0006】本発明は、コンパイラの処理によってソー
スプログラム中に現われる動的メモリ領域の確保を行う
処理の実行性能を向上させることを目的とする。An object of the present invention is to improve the execution performance of the process of securing the dynamic memory area appearing in the source program by the process of the compiler.
【0007】[0007]
【課題を解決するための手段】本発明は、コンパイラの
処理によってヒープ操作に基づいて動的にメモリ領域を
確保する関数呼出しと確保されたこのメモリ領域を開放
する関数呼出しとがソースプログラム中の同一関数内に
所在することを検出したとき、両方の関数呼出し文をま
とめて関数スタック内に動的にメモリ領域を確保する関
数呼び出し文に変換する動的メモリ領域を確保する関数
呼出しの処理方法を特徴とする。According to the present invention, a function call for dynamically allocating a memory area based on a heap operation by a process of a compiler and a function call for allocating the reserved memory area are provided in a source program. When it is detected that it is located in the same function, both function call statements are combined and converted into a function call statement that dynamically allocates a memory area in the function stack. A method for processing a function call that allocates a dynamic memory area. Is characterized by.
【0008】[0008]
【作用】ヒープ操作に基づいて動的にメモリ領域を確保
する関数呼出しと確保されたメモリ領域を開放する関数
呼出しとがソースプログラム中の同一関数内に所在する
ことを検出したとき、動的メモリ領域の確保を行う処理
を高速化できる余地を見い出したことになるので、両方
の関数呼出し文をまとめて関数スタック内に動的にメモ
リ領域を確保する関数呼び出し文に変換することによっ
てオブジェクトプログラムの実行性能を向上させること
ができる。When a function call for dynamically allocating a memory area based on a heap operation and a function call for allocating a memory area located in the same function in the source program are detected, the dynamic memory is detected. Since we have found room to speed up the process of allocating the area, both function call statements are grouped together and converted into a function call statement that dynamically allocates a memory area in the function stack. Execution performance can be improved.
【0009】[0009]
【実施例】以下、本発明の一実施例について図面を用い
て詳細に説明する。DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS An embodiment of the present invention will be described in detail below with reference to the drawings.
【0010】図1は、C言語で書かれたソースプログラ
ムを入力してオブジェクトプログラムを出力するコンパ
イラの一部であり、動的メモリ領域を確保するmall
oc関数及び動的メモリ領域を開放するfree関数を
処理する部分の構成を示す図である。malloc関数
検索部1は、ソースプログラムを検索してmalloc
関数が呼び出されている文を見つける部分である。デー
タフロー解析部2はソースプログラム中に出現する変数
のデータフローを解析して各変数の定義点及び使用点を
明らかにする。動的メモリ領域使用範囲解析部3は、デ
ータフロー解析の結果得られたデータフロー情報を用い
てmalloc関数で確保したメモリ領域の先頭アドレ
スを示す変数の使用点をたどり、このメモリ領域を開放
するfree関数を求めてソースプログラムを検索し、
このメモリ領域を開放するfree関数が呼び出されて
いる文を見つける。関数変換部4は、malloc関数
とこのmalloc関数に対応するfree関数とが同
一の処理関数の中に存在する場合にmalloc関数と
free関数の対をスタック操作によって動的メモリ領
域を確保する関数に変換する。なおコンパイラは、情報
処理装置の記憶装置に格納され、実行されるプログラム
の一種である。FIG. 1 is a part of a compiler that inputs a source program written in C language and outputs an object program, and a mall that secures a dynamic memory area.
It is a figure which shows the structure of the part which processes the oc function and the free function which releases a dynamic memory area. The malloc function search unit 1 searches the source program to find the malloc function.
This is the part that finds the statement in which the function is called. The data flow analysis unit 2 analyzes the data flow of variables appearing in the source program to clarify the definition points and usage points of each variable. The dynamic memory area usage range analysis unit 3 traces the usage point of the variable indicating the start address of the memory area secured by the malloc function using the data flow information obtained as a result of the data flow analysis, and releases this memory area. Search the source program for the free function,
Find the statement in which the free function that releases this memory area is called. When the malloc function and the free function corresponding to this malloc function exist in the same processing function, the function conversion unit 4 converts the pair of the malloc function and the free function into a function that secures a dynamic memory area by stack operation. Convert. The compiler is a type of program stored and executed in the storage device of the information processing device.
【0011】図2は、C言語で書かれたソースプログラ
ムの一例を示す図である。文5は、malloc関数を
呼び出す文であり、200バイトの動的メモリ領域を確
保してその先頭アドレスを変数aに代入するよう指定す
る。文6は、変数aの値を変数bに代入することを指定
する。文7は、先頭アドレスが変数bに示される動的メ
モリ領域を開放するよう指定する。FIG. 2 is a diagram showing an example of a source program written in C language. Statement 5 is a statement that calls the malloc function, and specifies that a dynamic memory area of 200 bytes is secured and the start address thereof is assigned to the variable a. Statement 6 specifies that the value of variable a is assigned to variable b. Statement 7 specifies to release the dynamic memory area whose start address is indicated by the variable b.
【0012】以下図2に示すソースプログラムを参照し
ながら図1に示すコンパイラの動作の詳細について説明
する。The operation of the compiler shown in FIG. 1 will be described in detail below with reference to the source program shown in FIG.
【0013】malloc関数検索部1は、ソースプロ
グラムを検索してmalloc関数が呼び出されている
文5を見つけ、見つけた文5からmalloc関数の返
却値である動的に確保されたメモリ領域の先頭アドレス
が代入されている変数を見つける。図2の例では変数a
である。The alloc function search unit 1 searches the source program for a statement 5 in which the alloc function is called, and from the found statement 5, the head of the dynamically secured memory area which is the return value of the alloc function. Find the variable to which the address is assigned. In the example of FIG. 2, the variable a
Is.
【0014】データフロー解析部2は、ソースプログラ
ム中に現われる変数のデータフローを解析する。この方
法については、例えばA.Aho、R.Sethi、
J.Ullman共著の″Compilers Pri
nciples,Techniques,and To
ols″に記載されている。ソースプログラム中の任意
の文をSとし、文Sを実行することによってその値が変
わる変数の集合をGEN[S]とする。文Sで定義され
る変数、文Sで呼び出す関数の引数等はGEN[S]に
含まれる。また文S以前に定義されている変数であっ
て、文Sでも定義される変数の集合をKILL[S]と
する。また文S以前に定義されている変数の集合をIN
[S]とする。また文Sまでで有効な変数の集合をOU
T[S]とするとき、OUT[S]は次のデータフロー
方程式によって求められる。 OUT[S]=GEN[S]∪(IN[S]−KILL
[S]) 例えば文5において、GEN[S]はa、KILL
[S]はa、IN[S]はaとbとcであるから、OU
T[S]はaとbとcである。文SについてOUT
[S]で求められる変数が、有効な変数の集合であるか
ら、その集合に含まれる変数であって文Sで定義される
変数と使用される変数が決定される。このようにしてデ
ータフロー解析部2は、ソースプログラム中のすべての
文について制御の流れに沿って各文で定義されている変
数と使用されている変数を配列する。これによってすべ
ての変数の定義点と使用点が判明する。処理関数が別の
関数を呼び出しているときには、同様にして別の関数プ
ログラム中に現われる変数についてデータフローを解析
する。次にデータフロー解析部2は、このようなデータ
フロー情報を基にして動的メモリ領域の先頭アドレスが
代入される変数を使用して別の変数を再定義する文、す
なわち別の変数に代入を行う文を検索する。代入を行う
文が存在するときはその文の定義変数を見つけ、この変
数の使用についても同様に検索をする。このようにして
先頭アドレス変数についてのデータフロー情報を抽出す
る。図2の例では文5で定義した変数aについて文6で
変数aから変数bへの代入があり、さらに文7で変数b
の使用がある。図3は、変数aの定義から変数bの使用
まで一連の文から構成されるデータフロー情報を示すも
のである。(1)、(2)及び(3)はそれぞれ文であ
る。The data flow analysis unit 2 analyzes the data flow of variables appearing in the source program. This method is described, for example, in A. Aho, R.A. Sethi,
J. "Compilers Pri", co-authored by Ullman
nciples, Techniques, and To
ls ". Let S be an arbitrary statement in the source program, and let GEN [S] be a set of variables whose values change by executing the statement S. Variables and statements defined by the statement S The arguments of the function called by S are included in GEN [S]. Further, a set of variables that are defined before sentence S and are also defined by sentence S is KILL [S]. IN a previously defined set of variables
[S]. In addition, the effective set of variables up to the sentence S is OU
When T [S], OUT [S] is obtained by the following data flow equation. OUT [S] = GEN [S] ∪ (IN [S] -KILL
[S]) For example, in sentence 5, GEN [S] is a, KILL
[S] is a and IN [S] is a, b, and c, so OU
T [S] is a, b, and c. About sentence S OUT
Since the variable obtained in [S] is a set of valid variables, the variables included in the set and defined by the statement S and the variables to be used are determined. In this way, the data flow analysis unit 2 arranges the variables defined in each sentence and the used variables according to the control flow for all the sentences in the source program. This reveals the definition and use points of all variables. When the processing function is calling another function, the data flow is similarly analyzed for variables appearing in another function program. Next, the data flow analysis unit 2 uses a variable to which the start address of the dynamic memory area is assigned based on such data flow information to redefine another variable, that is, to assign to another variable. Search for the sentence that does. If there is a statement that does the substitution, find the definition variable of the statement, and similarly search for the use of this variable. In this way, the data flow information about the head address variable is extracted. In the example of FIG. 2, there is an assignment from the variable a to the variable b in the statement 6 for the variable a defined in the statement 5, and further in the statement 7 the variable b.
There is use of. FIG. 3 shows data flow information composed of a series of statements from the definition of the variable a to the use of the variable b. (1), (2) and (3) are sentences respectively.
【0015】動的メモリ領域使用範囲解析部3は、デー
タフロー解析部2が求めた先頭アドレス変数のデータフ
ロー情報を基にしてソースプログラムを検索し、変数の
使用点にある文が動的メモリ領域の解放を行うfree
関数呼び出し文であるかどうか調べていく。処理関数が
別の関数を呼び出しているときにも同様にしてソースプ
ログラムを検索して関連するfree関数呼出し文の所
在をつきとめる。図2の例では図3の(3)の文に対応
する文7がfree関数呼出し文であることが判明す
る。malloc関数に対応するfree関数が見つか
ったとき、malloc関数とfree関数それぞれの
存在する処理関数が同じであるか否かをチェックし、同
じであることが判明した場合にmalloc関数の変換
が可能であると判断する。The dynamic memory area usage range analysis unit 3 searches the source program based on the data flow information of the head address variable obtained by the data flow analysis unit 2, and the statement at the point of use of the variable is the dynamic memory. Free to release area
Check whether it is a function call statement. Even when the processing function is calling another function, the source program is searched in the same manner to find the location of the related free function call statement. In the example of FIG. 2, it is found that the sentence 7 corresponding to the sentence (3) of FIG. 3 is a free function calling sentence. When the free function corresponding to the malloc function is found, it is checked whether or not the existing processing functions of the malloc function and the free function are the same, and if it is found that they are the same, conversion of the malloc function is possible. Judge that there is.
【0016】関数変換部4は、動的メモリ領域使用範囲
解析部3が求めた変換可能なmalloc関数呼び出し
文をスタック操作による動的メモリ領域を確保する処理
に変換する。また対応するfree関数を削除する。図
2の例では文5をa=alloca(200)に変更
し、文7を削除することになる。malloc関数に対
応するfree関数が検索できなかった場合、またはm
olloc関数と対応するfree関数の存在する処理
関数が異なる場合は、変換を行わずに処理を終える。The function conversion unit 4 converts the convertible malloc function call statement obtained by the dynamic memory area use range analysis unit 3 into a process for securing a dynamic memory area by stack operation. In addition, the corresponding free function is deleted. In the example of FIG. 2, the sentence 5 is changed to a = alloca (200) and the sentence 7 is deleted. If the free function corresponding to the malloc function cannot be found, or m
When the processing function in which the free function corresponding to the olloc function exists is different, the processing ends without conversion.
【0017】以上の処理を全てのmalloc関数につ
いて行う。The above processing is performed for all malloc functions.
【0018】[0018]
【発明の効果】本発明によれば、コンパイラがソースプ
ログラム中に現われるヒープ操作を基にした動的メモリ
領域を確保、開放する関数呼び出しを高速なスタックに
よる動的メモリ領域確保処理に変換するので、ユーザが
意識することなく動的メモリ領域を使用するプログラム
の実行性能を向上させることができる。According to the present invention, the compiler converts the function call for allocating and releasing the dynamic memory area based on the heap operation appearing in the source program into the dynamic memory area allocating process by the high speed stack. , It is possible to improve the execution performance of a program that uses the dynamic memory area without the user being aware of it.
【図1】本発明の実施例のコンパイラの一部の構成を示
す図である。FIG. 1 is a diagram showing a partial configuration of a compiler according to an embodiment of the present invention.
【図2】ソースプログラムの一例を示す図である。FIG. 2 is a diagram showing an example of a source program.
【図3】メモリ領域の先頭アドレス変数のデータフロー
情報の一例を示す図である。FIG. 3 is a diagram showing an example of data flow information of a head address variable of a memory area.
1・・・malloc関数検索部、2・・・データフロ
ー解析部、3・・・動的メモリ領域使用範囲解析部、4
・・・関数変換部1 ... malloc function search unit, 2 ... data flow analysis unit, 3 ... dynamic memory area usage range analysis unit, 4
... Function conversion unit
Claims (1)
確保する第1の関数呼出し文又は関数スタック内に動的
メモリ領域を確保する第2の関数呼出し文を含むソース
プログラムのコンパイラによる処理方法において、 第1の関数呼出し文によって指定される動的メモリ領域
の先頭アドレスを定義する変数について該ソースプログ
ラムを通じて使用され、再定義される文についてのデー
タフロー情報を求め、 該データフロー情報に含まれる文であってかつ第1の関
数呼出し文によって確保したメモリ領域を開放する第3
の関数呼出し文を検出し、 第1の関数呼出し文と第3の関数呼出し文が同一の関数
内に所在するとき第1の関数呼び出し文を第2の関数呼
出し文に変換し、第3の関数呼出し文を削除することを
特徴とする動的メモリ領域を確保する関数呼出しの処理
方法。1. Processing by a compiler of a source program including a first function call statement for dynamically allocating a memory area based on a heap operation or a second function call statement for allocating a dynamic memory area in a function stack. In the method, data flow information about a statement to be redefined, which is used through the source program for a variable that defines a start address of a dynamic memory area specified by the first function call statement, is obtained, and A third statement that is a contained statement and releases the memory area secured by the first function call statement
Of the first function call statement and the third function call statement are located in the same function, the first function call statement is converted into the second function call statement, and the third function call statement is converted to the third function call statement. A method for processing a function call that secures a dynamic memory area, characterized by deleting a function call statement.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP7500895A JPH08272621A (en) | 1995-03-31 | 1995-03-31 | Function call processing method for securing dynamic memory area |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP7500895A JPH08272621A (en) | 1995-03-31 | 1995-03-31 | Function call processing method for securing dynamic memory area |
Publications (1)
Publication Number | Publication Date |
---|---|
JPH08272621A true JPH08272621A (en) | 1996-10-18 |
Family
ID=13563746
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP7500895A Pending JPH08272621A (en) | 1995-03-31 | 1995-03-31 | Function call processing method for securing dynamic memory area |
Country Status (1)
Country | Link |
---|---|
JP (1) | JPH08272621A (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6647547B1 (en) | 1999-05-18 | 2003-11-11 | Matsushita Electric Industrial Co., Ltd. | Program conversion apparatus for eliminating unnecessary indications of dynamic memory allocation from a source program and generating an executable program |
JP2008226208A (en) * | 2007-03-16 | 2008-09-25 | Hitachi Information Systems Ltd | Program verification method, system and program |
CN104461915A (en) * | 2014-11-17 | 2015-03-25 | 苏州阔地网络科技有限公司 | Method and device for dynamically allocating internal storage in online class system |
US9940053B2 (en) | 2014-05-28 | 2018-04-10 | Nec Corporation | Information processing device, information processing system, memory management method, and program recording medium |
-
1995
- 1995-03-31 JP JP7500895A patent/JPH08272621A/en active Pending
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6647547B1 (en) | 1999-05-18 | 2003-11-11 | Matsushita Electric Industrial Co., Ltd. | Program conversion apparatus for eliminating unnecessary indications of dynamic memory allocation from a source program and generating an executable program |
JP2008226208A (en) * | 2007-03-16 | 2008-09-25 | Hitachi Information Systems Ltd | Program verification method, system and program |
JP4679540B2 (en) * | 2007-03-16 | 2011-04-27 | 株式会社日立情報システムズ | Program verification method, system, and program |
US9940053B2 (en) | 2014-05-28 | 2018-04-10 | Nec Corporation | Information processing device, information processing system, memory management method, and program recording medium |
CN104461915A (en) * | 2014-11-17 | 2015-03-25 | 苏州阔地网络科技有限公司 | Method and device for dynamically allocating internal storage in online class system |
CN104461915B (en) * | 2014-11-17 | 2017-06-20 | 阔地教育科技有限公司 | A kind of Online class Memory System dynamic allocation method and equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JPH05204656A (en) | Method for holding data inherent in thread | |
JPH08272621A (en) | Function call processing method for securing dynamic memory area | |
US5150474A (en) | Method for transferring arguments between object programs by switching address modes according to mode identifying flag | |
KR20060035077A (en) | Data processing device and register allocation method using data processing device | |
JP2003256215A (en) | Program conversion method, data processor using the same, and program | |
JP2000122876A (en) | Information processor | |
JP3278584B2 (en) | Computer program generation apparatus and method | |
JP2932812B2 (en) | Language processing program execution device | |
JP3161887B2 (en) | Value definition location determination device | |
JP3018666B2 (en) | Language processor | |
JPH06324882A (en) | Compiler device | |
JP3004340B2 (en) | Program optimization device | |
JPH07129408A (en) | Executing system for language processing program | |
JP3085309B2 (en) | Debug system | |
JPS62137641A (en) | High-grade language compiler | |
JPH06110702A (en) | Procedure call translator | |
JPH06301549A (en) | Program translation device | |
JPH1195995A (en) | Device and method for analyzing data flow, and recording medium recording computer program therefor | |
JPH0764800A (en) | Object program generating method | |
JPH0447337B2 (en) | ||
JPH0535495A (en) | Language processing program execution system | |
JPH0683633A (en) | Execution system for language processing program | |
JPH0749789A (en) | Compiling method and compiler | |
JPH10293691A (en) | Register allocating method | |
JPH04107605A (en) | Control program language processor |