JPS63121929A - Stack processing system - Google Patents

Stack processing system

Info

Publication number
JPS63121929A
JPS63121929A JP26758886A JP26758886A JPS63121929A JP S63121929 A JPS63121929 A JP S63121929A JP 26758886 A JP26758886 A JP 26758886A JP 26758886 A JP26758886 A JP 26758886A JP S63121929 A JPS63121929 A JP S63121929A
Authority
JP
Japan
Prior art keywords
stack
stack memory
program
subprogram
memory
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
Application number
JP26758886A
Other languages
Japanese (ja)
Inventor
Noboru Tsuchiya
土屋 昇
Kazuhiro Sugino
杉野 和宏
Tadamasa Kamikubo
上久保 忠正
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.)
Hitachi Ltd
Original Assignee
Hitachi 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
Application filed by Hitachi Ltd filed Critical Hitachi Ltd
Priority to JP26758886A priority Critical patent/JPS63121929A/en
Publication of JPS63121929A publication Critical patent/JPS63121929A/en
Pending legal-status Critical Current

Links

Abstract

PURPOSE:To evade abnormal termination of a program due to a lack of capacity of a stack memory by reserving local variables used in a program in a fixed place of the program and saving values of local variables on a stack memory at the time of calling a subprogram and restoring them at the time of return to a main program. CONSTITUTION:A stack management part 12 stores values of prescribed variables in a variable save area 15 on a stack memory 14 and stores return information 16 on the stack memory 14 and transfers the control to a subprogram 13 thereafter. When execution of the subprogram 13 is completed, the stack management part 12 takes out return information 16 from the stack memory 14 and uses values saved in the variable value save area 15 to restore values of variables in a variable area 11 of a main program 10 to states before call of the subprogram 13 and transfers the control to the main program 10 thereafter.

Description

【発明の詳細な説明】 〔産業上の利用分野〕 本発明は、計算機システムのプログラム言語処理方式や
プログラム実行方式に係り、特に、副プログラムの再帰
呼出しを行なう際に使用するスタックメモリの効率良い
利用に好適なスタック処理方式に関する。
[Detailed Description of the Invention] [Field of Industrial Application] The present invention relates to a program language processing method and a program execution method for a computer system, and in particular to an efficient stack memory used when recursively calling subprograms. This invention relates to a stack processing method suitable for use.

〔従来の技術〕[Conventional technology]

従来の副プログラムの再帰呼出し方式は、ワース(Wi
rth )著片山訳「アルゴリズム子データ構造−プロ
グラム」日本コンビーータ協会、37Ili頁〜381
頁や、石井著「計算機の基本方式」共立出版27頁〜2
9頁に記載されているように、副プログラム内で用いる
局所変数をスタックメモリ上に確保して行なうものであ
る。このため、当該副プログラムの実行が完了するまで
の間、このスタック@域を高速な主記憶装置上に常駐さ
せておく必要がある。これを、第3図により説明する。
The conventional recursive calling method for subprograms is
rth), translated by Katayama, "Algorithm Child Data Structure - Program", Japan Combita Association, pp. 37Ili - 381
Pages, “Basic Methods of Computers” by Ishii, Kyoritsu Publishing, pp. 27-2
As described on page 9, this is done by allocating local variables used within the subprogram on the stack memory. Therefore, it is necessary to make this stack @ area resident on a high-speed main storage device until the execution of the subprogram is completed. This will be explained with reference to FIG.

第3図に示す主プログラム21が開始すると、先ず主プ
ログラム21で使用する局所変数を格納する変数領域(
りをスタックメモリ30上に確保し(ステップ22)、
主プログラム21の実行時にはスタックメモリ30上の
変数領域(1)を参照する。
When the main program 21 shown in FIG. 3 starts, first the variable area (
is secured on the stack memory 30 (step 22),
When the main program 21 is executed, the variable area (1) on the stack memory 30 is referred to.

主プログラム21から副プログラム24を呼ぶときには
、副プログラム24から主プログラム21に戻るために
必要な戻り情報をスタックメモリ50上に格納してから
副プログラム24にジャンプする。
When calling the subprogram 24 from the main program 21, return information necessary for returning from the subprogram 24 to the main program 21 is stored on the stack memory 50, and then the subprogram 24 is jumped.

呼出された副プログラム24の先頭においても、主プロ
グラム21と同様に、副プログラム24の中で使う局所
変数を格納する変数領域(2)をスタックメモリ30上
に確保する(ステップ25)。そして、副プログラム2
4の実行時には、スタックメモリ30上の変数領域(2
)を参照する一方、主プログラム21から引数として渡
される変数領域(1)中の変数に対しても、直接変数領
域(1)を参照する。到プログラム24の実行終了にあ
たっては、ステップ26でスタックメモリ50上の変数
領域(2)を解放し、ステップ27でスタックメモリ3
0上の戻り情報を用い主プログラム21へ戻る。主プロ
グラム21の実行終了時には、ステップ23でスタック
メモリ30上の変数領域(りを解放する。
At the beginning of the called subprogram 24, similarly to the main program 21, a variable area (2) for storing local variables used in the subprogram 24 is secured on the stack memory 30 (step 25). And subprogram 2
4, the variable area (2) on the stack memory 30 is
), while the variable area (1) is also directly referenced for variables in the variable area (1) passed as arguments from the main program 21. When the execution of the program 24 ends, the variable area (2) on the stack memory 50 is released in step 26, and the variable area (2) on the stack memory 50 is released in step 27.
Return to the main program 21 using the return information above 0. At the end of execution of the main program 21, the variable area on the stack memory 30 is released in step 23.

〔発明が解決しようとする問題点〕[Problem that the invention seeks to solve]

上記従来方式においては、副プログラム24から主プロ
グラム21用の変数領域(りを直接参照できるようにす
るため、このスタック領域を主記憶装置上に常駐させ、
常に参照可能な状態にしている。
In the conventional method described above, in order to enable direct reference to the variable area for the main program 21 from the subprogram 24, this stack area is made resident on the main memory,
Always available for reference.

実際のプログラムでは、副プログラムから更に別の副プ
ログラムや自分自身な再帰的に呼ぶ場合がある。この様
に再帰的に自分自身を呼び出すと、つまり、副プログラ
ム24かも副プログラム24を呼び出すと、2度目に呼
ばれた際に再度と新たにスタックメモリ上に変数領域を
別に確保することになる。この様な副プログラムの呼出
しが多重に行なわれると、スタックメモリとして数10
0にバイトから数メガバイト以上の容量が必要になり、
スタック容量不足からプログラムが異常終了してしまう
という問題が発生してしまう。
In an actual program, a subprogram may call another subprogram or itself recursively. If you call yourself recursively in this way, that is, if you call subprogram 24 or subprogram 24, the second time it is called, a separate variable area will be allocated on the stack memory again. . If such subprogram calls are made multiple times, the stack memory will be reduced to several tens of digits.
0 requires a byte to several megabytes or more,
A problem occurs in which the program terminates abnormally due to insufficient stack space.

本発明の目的は、主記憶装置に設けるスタックメモリの
有効活用を図り、スタックメモリの容量不足に起因する
プログラムの異常終了を回避するスタック処理方式を提
供することにある。
SUMMARY OF THE INVENTION An object of the present invention is to provide a stack processing method that makes effective use of a stack memory provided in a main storage device and avoids abnormal termination of a program due to insufficient capacity of the stack memory.

〔問題点を解決するための手段〕[Means for solving problems]

上記目的は、プログラム内で用いる局所変数をスタック
メモリ上に動的に確保するのではなく、プログラム内等
の固定的な場所に確保し、副プログラムを呼出す際にス
タックメモリ上に局所変数の値を退避させ、主プログラ
ムに戻る際にその値を回復させることにより、達成され
る。
The above purpose is not to dynamically allocate the local variables used within the program on the stack memory, but to allocate them in a fixed location within the program, and when calling the subprogram, the local variable values are stored on the stack memory. This is accomplished by saving the value and restoring its value when returning to the main program.

〔作用〕[Effect]

スタックメモリ上に退避された値は制御が主プログラム
に戻るまでの間は参照されることが無い。
The values saved on the stack memory are not referenced until control is returned to the main program.

軸プログラムが更に副プログラムを呼び出すという呼び
出しのネストが深くなるに従い、スタックメモリが大量
に必要となる。しかし、この場合、スタックメモリの最
初の方に格納された値は、その後から格納された値が全
て取り出されるまでの間は主記憶装置に常駐させておく
必要が無いので、ディスク記憶装置等の帰助記憶装置に
格納しておいても、実行効率への影響は少ない。また、
大量のスタックメモリ中のデータを参照せずに、固定的
に確保した変数領域のみを参照するだけであるため、主
記憶装置へのアクセスが局所化され、仮想記憶方式を採
用している近年の計算機においてはゝ−シフオールドの
確率が減少する。
As the axis program calls further subprograms and the nesting of calls becomes deeper, a large amount of stack memory is required. However, in this case, the values stored at the beginning of the stack memory do not need to remain resident in the main memory until all subsequently stored values are retrieved, so the values stored at the beginning of the stack memory do not need to remain resident in the main memory, so Even if it is stored in the auxiliary storage device, there is little effect on execution efficiency. Also,
In recent years, access to main memory has been localized, and virtual memory has been adopted, since only the fixedly allocated variable area is referenced without referring to the data in a large amount of stack memory. In computers, the probability of ゝ- shift fold decreases.

〔実施例〕〔Example〕

以下、本発明の一実施例を第1図及び第2図を参照して
説明する。
An embodiment of the present invention will be described below with reference to FIGS. 1 and 2.

第1図は本発明の一実施例に係るスタック処理方式の説
明図である。第1図に示すスタックメモリ14は、計算
機システムの図示しない主記憶装置上に設けられた先入
れ後出し型のメモリである。
FIG. 1 is an explanatory diagram of a stack processing method according to an embodiment of the present invention. The stack memory 14 shown in FIG. 1 is a first-in, last-out type memory provided on a main storage device (not shown) of a computer system.

つまり、スタックメモリ14かも情報を取り出す場合に
は、格納されている情報の中で最後に格納された情報か
ら順番に取り出される。本実施例では、主プログラム1
0内部に、該主プログラム1゜で新たに使用する局所変
数を固定的に確保する変数領域11を設けてあり、また
、副プログラム13にも同様の変数領域17を設けであ
る。尚、この様に変数領域11 、17をプログラム1
0 、1′5内に設けるのではなく、システムで指定し
た他の場所に設けるようにしてもよい。
That is, when information is taken out from the stack memory 14, it is taken out in order from the last stored information among the stored information. In this embodiment, main program 1
0 is provided with a variable area 11 for fixedly securing local variables newly used in the main program 1°, and a similar variable area 17 is also provided in the subprogram 13. In this way, variable areas 11 and 17 are set to program 1.
Instead of providing it in 0, 1'5, it may be provided in another location specified by the system.

主プログラム10から副プログラム13を呼ぶと。When the subprogram 13 is called from the main program 10.

スタック管理部12は、所定変数の値をスタックメモリ
30上の変数退避領域15に格納し、更にスタックメそ
り14上に戻り情報16を格納し、その後に副プログラ
ム16に制御を移す。副プログラム13の実行時には副
プログラム15用に確保しである変数領域17参照し、
また、主プログラム10から引数として渡される変数も
スタックメモリ14中ではなく、主プログラム10内の
変数領域11や、さらに、主プログラムが他のプログラ
ムから呼ばれている場合にはその主プログラム用の変数
領域を直接に参照する。副プログラム13の実行が完了
すると、スタック管理部12はスタックメモリ14から
戻り情報16を取り出し、変数値退避領域15に退避し
である値を用いて主プログラム10の変数領域11中に
ある変数の値を副プログラム13を呼ぶ前の状態に回復
し、その後に主プログラム10に制御を移す。
The stack management unit 12 stores the value of a predetermined variable in the variable save area 15 on the stack memory 30, further stores return information 16 on the stack memory 14, and then transfers control to the subprogram 16. When executing the subprogram 13, refer to the variable area 17 reserved for the subprogram 15,
In addition, variables passed as arguments from the main program 10 are not stored in the stack memory 14, but in the variable area 11 within the main program 10, and further, if the main program is called from another program, the variables for that main program are stored. Refer to variable area directly. When the execution of the subprogram 13 is completed, the stack management unit 12 takes out the return information 16 from the stack memory 14, saves it to the variable value save area 15, and uses the value to save the variables in the variable area 11 of the main program 10. The value is restored to the state before calling the subprogram 13, and then control is transferred to the main program 10.

以上のように、本実施例によれば、副プログラム13が
実行中にはスタックメモリ14を参照することが無いの
で、スタックメモリ14を主記憶上に常駐させておく必
要が無くなる。また、プログラム10や13を実行中に
参照する変数領域は、あらかじめ定められている領域1
1や17だけであるので、主記憶装置の参照が局所化さ
れ、仮想記憶方式を採用している計算機システムにおい
てはページフォールトの確率が減少し、処理効率を上げ
ることができる。さらに、スタックメモリ14に入、り
ている情報は最後に入れた情報から順番に取り出される
ので、最初の方に入れられたデータをディスクファイル
等の補助記憶装置に格納しておくことができる。
As described above, according to this embodiment, the stack memory 14 is not referenced while the subprogram 13 is being executed, so there is no need to make the stack memory 14 resident in the main memory. In addition, the variable area referenced during execution of programs 10 and 13 is the predetermined area 1.
Since there are only 1 and 17, references to the main storage device are localized, and in a computer system that employs a virtual storage method, the probability of page faults is reduced and processing efficiency can be improved. Furthermore, since the information stored in the stack memory 14 is retrieved in order from the information input last, the data input earlier can be stored in an auxiliary storage device such as a disk file.

第2図は、補助記憶装置を利用してスタックメモリのオ
ーバーフローを避ける手順を示すフローチャートチする
。スタック管理部12は、ntJ 述した様に、主プロ
グラム10内の変数領域中にある局所変数値をスタック
メモリ14上に退避するが、このとき先ず、第2図(a
)に示すように、スタックメモリ14上に上記値を退避
させるのに十分な空きがあるか否かをチェックする(ス
テップ1)。
FIG. 2 is a flowchart showing a procedure for avoiding stack memory overflow by using an auxiliary storage device. As described above, the stack management unit 12 saves the local variable values in the variable area in the main program 10 onto the stack memory 14.
), it is checked whether there is enough free space on the stack memory 14 to save the above value (step 1).

−もし十分な空きがあるとステップ2ア判定された場合
はステップ4に飛び、変数値をスタックメモリ14Il
?:退避させる。ステップ2で十分な空きがないと判定
された場合は、ステップ3に進み、スタックメモリ14
内に古くから入っている情報から順にディスクファイル
に書き出してスタックメモリ14に空きを作り、その後
にステップ4に進む。
- If it is determined that there is sufficient space in step 2A, jump to step 4 and save the variable value to the stack memory 14Il.
? : Evacuate. If it is determined in step 2 that there is not enough free space, proceed to step 3 and use the stack memory 14.
The oldest information is written out to the disk file in order to free up space in the stack memory 14, and then the process proceeds to step 4.

主プログラム10に戻る場合には、第2図(b)に示す
ように、主記憶装置内のスタックメモリ14中に退避デ
ータが有るか否かをチェックする(ステップ5)oこの
退避データが有るとステップ6で判定された場合にはス
テップ8へ飛び、変数値をスタックメモリ14からプロ
グラム10へ回復させる。退避データがスタックメモリ
14内に無いと判定された場合は、該当する退避データ
はディスクファイル上に書き出されているため、ステッ
プ7で該退避データをディスクファイルからスタックメ
モリ14に読み込み、その後にステップ8に進む。
When returning to the main program 10, as shown in FIG. 2(b), it is checked whether there is saved data in the stack memory 14 in the main storage device (step 5) o If this saved data exists If it is determined in step 6, the process jumps to step 8 and the variable value is restored from the stack memory 14 to the program 10. If it is determined that the saved data is not in the stack memory 14, the corresponding saved data has been written to the disk file, so the saved data is read from the disk file to the stack memory 14 in step 7, and then Proceed to step 8.

この様にすると、上記ディスク等の大容量の補助記憶装
置の利用が可能となり、スタックメモリのオーバ70−
による集常終了を回避でき、プログラムの実行に必要と
なる主記憶装置の容量を減らすことかでざる。
In this way, it becomes possible to use a large-capacity auxiliary storage device such as the above-mentioned disk, and the stack memory becomes over 70-
It is possible to avoid abnormal termination caused by program execution, and to reduce the main memory capacity required for program execution.

〔発明の効果〕〔Effect of the invention〕

本発明によれば、動的に変数の記憶領域を確保したり副
プログラムから主プログラムへ戻るための情報を格納す
るために用いられるスタックメモリに対し、スタック内
の領域を参照せずに、固定的な変数領域だけを参照する
ことによりプログラムを実行できるので、主記憶装置へ
のアクセスの局所化が可能となり、仮想記憶方式の計算
機においてはページフォールトの確率が減小する効果が
ある。さらに、スタックの一部として大容置の補助記憶
装置の使用が可能となり、プログラムの実行に必要とな
るスタックに割り当てるべき主記憶容tが減少する効果
がある。また、スタックオーバ70−による異常終了が
起りK<<なり、プログラム開発者や利用者に対し、ス
タック容量な意像する必要性を排除できる。
According to the present invention, the stack memory used for dynamically allocating a storage area for variables and storing information for returning from a subprogram to the main program can be fixed without referring to the area in the stack. Since a program can be executed by referencing only the variable area, it is possible to localize access to the main memory, which has the effect of reducing the probability of page faults in virtual memory type computers. Furthermore, it becomes possible to use a large-capacity auxiliary storage device as part of the stack, which has the effect of reducing the main storage capacity t that must be allocated to the stack required for program execution. In addition, an abnormal termination due to stack overflow 70- occurs and K<<, which eliminates the need for program developers and users to consider the stack capacity.

【図面の簡単な説明】[Brief explanation of the drawing]

第1図は本発明の一実施例に係るスタック処理方式の説
明図、第2図(α) t (b)は補助記憶装置を使用
するときの70−チャート、第3図は従来のスタック処
理方式の説明図である。 10・・・主プログラム、11 、17・・・変数領域
、12・・・スタック管理部、13・・・副プログラム
、14・・・スタックメモリ。 7・′−〜 代理人弁理士 小  川  勝  男 第 l 図 祐 2 図 (O−)          (b) 第 3 図
Fig. 1 is an explanatory diagram of a stack processing method according to an embodiment of the present invention, Fig. 2 (α) t (b) is a 70-chart when using an auxiliary storage device, and Fig. 3 is a conventional stack processing FIG. 2 is an explanatory diagram of the method. 10...Main program, 11, 17...Variable area, 12...Stack management section, 13...Subprogram, 14...Stack memory. 7・'-~ Patent Attorney Katsutoshi Ogawa No. 1 Figure 2 (O-) (b) Figure 3

Claims (1)

【特許請求の範囲】 1、プログラムの再帰呼び出し用のスタックメモリを主
記憶装置に備える計算機システムにおいて、プログラム
内等のスタックメモリ以外の場所に変数領域を設け、副
プログラムを呼ぶ際に主プログラムの局所変数値と該主
プログラムへの戻り情報とを前記スタックメモリに格納
し、前記副プログラム実行中は前記スタックメモリ内の
データを参照しないようにしたことを特徴とするスタッ
ク処理方式。 2、前記スタックメモリに格納したデータを、該スタッ
クメモリに空きがなくなったとき古いデータから補助記
憶装置に移し、必要に応じて該補助記憶装置から前記ス
タックメモリに戻すようにしたことを特徴とする特許請
求の範囲第1項記載のスタック処理方式。
[Claims] 1. In a computer system that includes a stack memory in the main storage for recursive calling of a program, a variable area is provided in a location other than the stack memory within the program, and when calling a subprogram, the main program is A stack processing method characterized in that local variable values and return information to the main program are stored in the stack memory, and data in the stack memory is not referenced while the subprogram is being executed. 2. The data stored in the stack memory is moved from the oldest data to an auxiliary storage device when there is no more space in the stack memory, and is returned from the auxiliary storage device to the stack memory as necessary. A stack processing method according to claim 1.
JP26758886A 1986-11-12 1986-11-12 Stack processing system Pending JPS63121929A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP26758886A JPS63121929A (en) 1986-11-12 1986-11-12 Stack processing system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP26758886A JPS63121929A (en) 1986-11-12 1986-11-12 Stack processing system

Publications (1)

Publication Number Publication Date
JPS63121929A true JPS63121929A (en) 1988-05-26

Family

ID=17446845

Family Applications (1)

Application Number Title Priority Date Filing Date
JP26758886A Pending JPS63121929A (en) 1986-11-12 1986-11-12 Stack processing system

Country Status (1)

Country Link
JP (1) JPS63121929A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH02139633A (en) * 1988-11-19 1990-05-29 Fujitsu Ltd Process synchronizing control system

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH02139633A (en) * 1988-11-19 1990-05-29 Fujitsu Ltd Process synchronizing control system

Similar Documents

Publication Publication Date Title
US4951194A (en) Method for reducing memory allocations and data copying operations during program calling sequences
US4812981A (en) Memory management system improving the efficiency of fork operations
US5490256A (en) Method and mechanism for calling 32-bit functions from 16-bit functions
US6665747B1 (en) Method and apparatus for interfacing with a secondary storage system
US20040243986A1 (en) Interpreter and native code execution method
JP2850808B2 (en) Data processing device and data processing method
JP2821345B2 (en) Asynchronous I / O control method
US6058457A (en) Method for storing method frames in multiple stacks
JPS63121929A (en) Stack processing system
US6067602A (en) Multi-stack-caching memory architecture
US6092152A (en) Method for stack-caching method frames
JPS5848289A (en) Buffer memory controlling system
JPS63200257A (en) Program loading system for computer
JP2671160B2 (en) Exception handling method
JP2932812B2 (en) Language processing program execution device
JP3822449B2 (en) Stack saving method, stack saving program, and highly reliable computer system
JPH07152574A (en) Program loading system
JP3118348B2 (en) Program cache method
JP2787107B2 (en) Buffer control system and device
JP3209560B2 (en) Interrupt management method for microprocessor system
JP2572435B2 (en) Instruction execution method of demand paging computer
JPH02270032A (en) Loading system
JPS6353650A (en) Computer
JPS60132241A (en) Data processing device
JPS6212555B2 (en)