JP2000132406A - Optimization method for object memory - Google Patents

Optimization method for object memory

Info

Publication number
JP2000132406A
JP2000132406A JP10299312A JP29931298A JP2000132406A JP 2000132406 A JP2000132406 A JP 2000132406A JP 10299312 A JP10299312 A JP 10299312A JP 29931298 A JP29931298 A JP 29931298A JP 2000132406 A JP2000132406 A JP 2000132406A
Authority
JP
Japan
Prior art keywords
analysis
memory
application
section
code
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
JP10299312A
Other languages
Japanese (ja)
Inventor
Takahiro Hirose
隆裕 廣瀬
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 JP10299312A priority Critical patent/JP2000132406A/en
Publication of JP2000132406A publication Critical patent/JP2000132406A/en
Pending legal-status Critical Current

Links

Landscapes

  • Devices For Executing Special Programs (AREA)

Abstract

PROBLEM TO BE SOLVED: To reduce the load of a garbage collection and to enhance the execution performance of an application by carrying out the data flow analysis of a program, checking the section where an object is referred to and inserting an object opening instruction into the end of a reference section of the object. SOLUTION: An intermediate code 201 which finished the analysis of data undergoes an object reference analysis 202. Then the code 201 undergoes an object existence section analysis 203 after the analysis 202 is over. An object existence section means a program section where an object holds the effective data. When the analysis 203 is over, an object opening instruction is inserted (204) into the end of a reference section of the object. In such a constitution, the load of a garbage collection is reduced and the execution performance of an application is improved.

Description

【発明の詳細な説明】DETAILED DESCRIPTION OF THE INVENTION

【0001】[0001]

【発明の属する技術分野】計算機の利用において、メモ
リを管理方式に関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a method for managing a memory in use of a computer.

【0002】[0002]

【従来の技術】計算機システムにおいて、メモリの管理
はシステムの性能や信頼性を左右する重要な要素であ
る。メモリ管理方式は大きく分けて2通りの方法があ
る。
2. Description of the Related Art In a computer system, memory management is an important factor that affects system performance and reliability. There are two main types of memory management methods.

【0003】ひとつはアプリケーションが明示的にメモ
リの開放を行う方式である。この方式の代表はC言語で
ある。詳細は「B.W.カーニハン、D.M.リッチー著 プロ
グラミング言語C」にある。C言語の仕様によると、局所
変数や静的変数として割り当てられる領域を除いて、ア
プリケーションプログラム自身でメモリを管理しなくは
ならない。典型的なやり方は、ライブラリ関数malloc()
で必要なメモリをシステムから取得し、使い終わったら
ライブラリ関数free()でシステムに返却するというもの
である。確保したメモリの扱いはすべてアプリケーショ
ンプログラムに任されいる。
One is a method in which an application explicitly releases a memory. A typical example of this method is the C language. See "Programming Language C by BW Kernighan, DM Richie" for details. According to the C language specification, the application program itself must manage the memory, except for areas allocated as local or static variables. A typical approach is to use the library function malloc ()
The necessary memory is acquired from the system by using, and when it has been used, it is returned to the system using the library function free (). The handling of the reserved memory is entirely up to the application program.

【0004】もうひとつは、ガベージコレクションを行
い、システムが暗黙のうちに不要となったメモリを回収
する方式である。この方式の代表はJava言語である。詳
細は「ローラ・リメイ、チャールズ・パーキンソン著
Java言語入門」に記述されている。Java言語の仕様によ
るとアプリケーションは、new命令を使ってシステムか
らオブジェクトのメモリを得る。しかし、C言語と違っ
て、システムにメモリを返却する命令は存在しない。Ja
va言語の実行環境では、ガベージコレクタと呼ばれるプ
ロセスが常に動作している。ガベージコレクタは、アプ
リケーションのメモリ使用状況を監視し、使われなくな
ったオブジェクトメモリを自動的に回収する。アプリケ
ーションが明示的にメモリを解放する必要はない。
[0004] The other is a system in which garbage collection is performed and the system silently collects unnecessary memory. A representative of this method is the Java language. See Laura Limey and Charles Parkinson for details.
An introduction to the Java language ". According to the Java language specification, an application obtains an object's memory from the system using a new instruction. However, unlike C, there is no instruction to return memory to the system. Ja
In the va language execution environment, a process called the garbage collector is always running. The garbage collector monitors application memory usage and automatically reclaims unused object memory. Applications do not need to explicitly free memory.

【0005】[0005]

【発明が解決しようとする課題】アプリケーションが明
示的にメモリを管理する方式は、効率的であるが、メモ
リの管理が複雑になるという問題がある。メモリが必要
になるタイミングと不要になるタイミングは、アプリケ
ーションの制御構造に深く関わりがあり、一般に極めて
複雑である。使用中のメモリを誤って開放してしまう
と、不正動作を引き起こす。逆に、使い終わったメモリ
正しく開放しないと、別の問題を引き起こす。これはメ
モリーリークと呼ばれる。不要なメモリがメモリ領域を
占領して、ついにシステムのメモリを使い尽くしてしま
う。
The method of explicitly managing a memory by an application is efficient, but has a problem that memory management becomes complicated. The timing at which the memory is required and the timing at which the memory is not required are closely related to the control structure of the application and are generally extremely complicated. If the used memory is released by mistake, incorrect operation will occur. Conversely, not properly releasing used memory can cause other problems. This is called a memory leak. Unnecessary memory occupies the memory area and eventually runs out of system memory.

【0006】ガベージコレクションを実行する方式は、
アプリケーション側で複雑なメモリ管理が不要という利
点はある。アプリケーションの実行性能が低下してしま
うという問題がある。アプリケーションの実行と平行し
て、常にガベージコレクターのプロセスが動く。ガベー
ジコレクタは、メモリの参照関係を広範囲に調べる処理
なので、システムの負荷は決して軽くない。アプリケー
ションの実行性能はその分だけ確実に低下してしまう。
A method for performing garbage collection is as follows.
An advantage is that complicated memory management is not required on the application side. There is a problem that the execution performance of the application is reduced. The garbage collector process always runs in parallel with the execution of the application. Since the garbage collector is a process for examining memory reference relationships in a wide range, the load on the system is not light. The execution performance of the application will surely decrease accordingly.

【0007】[0007]

【課題を解決するための手段】プログラムのデータフロ
ー解析を行い、オブジェクトが参照される区間を調べ
る。オブジェクトの参照区間の最後にオブジェクト開放
命令を挿入する。これによりガベージコレクションの負
荷を削減し、アプリケーションの実行性能を高めること
ができる。
A data flow analysis of a program is performed to check a section in which an object is referred to. An object release instruction is inserted at the end of the object reference section. As a result, the load of garbage collection can be reduced and the execution performance of the application can be improved.

【0008】[0008]

【発明の実施の形態】図1に全体の構成を示す。処理系
101は入力として仮想コード102又はソースコード103を
受け取る。仮想コードの場合はコード変換104を行い、
後のデータフロー処理106に適した中間コードに変換す
る。ソースコードの場合は構文解析105を行い中間コー
ドに変換する。生成した中間コードは、データフロー解
析106にかけられる。データフロー解析とは、中間コー
ドを解析して、各種データの参照関係を明らかにする処
理である。このデータフロー解析は、通常の最適化コン
パイラが行うデータフロー解析と全く同じ古典的なもの
である。中間コードとデータフロー解析の詳細は「A.V.
エイホ、R.セシィ、J.D.ウルマン著 コンパイラ-原理
・技法・ツール」にある。解析が終わると、オブジェク
トメモリ最適化処理107に移る。これはオブジェクトの
参照関係を調べて、ガベージコレクタを介さずにメモリ
の開放を行うものである。詳細は以降図2で述べる。オ
ブジェクトメモリ最適化が終わった中間コードはコード
生成処理に送られる。コード生成は目的とする実行環境
によって2通りある。通常のネイティブな実行環境向け
の場合は、機械コード生成処理108にかけ、最適化した
機械コード110を生成する。仮想マシンの環境向けの場
合は、仮想コード再生成処理109にかけ、最適化した仮
想コード111を生成する。
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS FIG. 1 shows the overall configuration. Processing system
101 receives as input a virtual code 102 or a source code 103. If it is a virtual code, perform code conversion 104,
It is converted into an intermediate code suitable for the subsequent data flow processing 106. In the case of a source code, a syntax analysis 105 is performed to convert it into an intermediate code. The generated intermediate code is subjected to data flow analysis 106. The data flow analysis is a process of analyzing an intermediate code and clarifying a reference relationship between various data. This data flow analysis is exactly the same classical one as the data flow analysis performed by an ordinary optimizing compiler. For details on intermediate code and data flow analysis, see “AV
Compilers-Principles, Techniques and Tools "by Ayho, R. Sessy and JD Ullman. When the analysis is completed, the process proceeds to the object memory optimizing process 107. This is to check the reference relationship of objects and release memory without going through the garbage collector. Details will be described later with reference to FIG. The intermediate code for which the object memory optimization has been completed is sent to a code generation process. There are two types of code generation depending on the target execution environment. In the case of a normal native execution environment, a machine code generation process 108 is performed to generate an optimized machine code 110. In the case of a virtual machine environment, an optimized virtual code 111 is generated by performing a virtual code regeneration process 109.

【0009】図2はオブジェクトメモリ最適化処理107
の詳細な手順を示している。データフロー解析106が終
わった中間コード201は、まずオブジェクト参照解析202
にかけられる。解析の詳細は図4で述べる。
FIG. 2 shows an object memory optimizing process 107.
The detailed procedure is shown. The intermediate code 201 for which the data flow analysis 106 has been completed is, first, an object reference analysis 202
To Details of the analysis are described in FIG.

【0010】オブジェクト参照解析が終わると次はオブ
ジェクト生存区間解析203に入る。オブジェクト生存区
間とは、オブジェクトが有効なデータを保持しているプ
ログラム区間のことである。生存区間の外にあるオブジ
ェクトは死んでいる。オブジェクトが死んでいるとは、
もはやオブジェクトが参照されることはないという意味
である。死んでいるオブジェクトは、メモリを開放し
て、それまでオブジェクトが占領していたメモリを、他
の目的のために利用することができる。生存区間の概念
の詳細は、前述「A.V.エイホ、R.セシィ、J.D.ウルマン
著 コンパイラ-原理・技法・ツール」にある。
When the object reference analysis is completed, the process enters the object life cycle analysis 203 next. An object life cycle is a program section in which an object holds valid data. Objects outside the life cycle are dead. An object is dead
This means that objects are no longer referenced. Dead objects can free up memory and use the memory previously occupied by the object for other purposes. The details of the concept of the life cycle can be found in the above-mentioned "Compiler-Principles, Techniques and Tools" by AV Eiho, R. Cessy and JD Ullman.

【0011】オブジェクト生存区間解析が終わったら、
オブジェクト解放命令の挿入204を行う。オブジェクト
が死んだ地点に解放命令を挿入することで、ガベージコ
レクターを介することなく、オブジェクトを解放するこ
とができる。
After the object life cycle analysis is completed,
An object release instruction insertion 204 is performed. By inserting a release command at the point where the object died, the object can be released without going through the garbage collector.

【0012】図3の301は、オブジェクトメモリ最適化
の処理手順を説明するためのプログラム例である。例題
プログラムは、入力としてオブジェクトxとオブジェク
トyを受け取り、内容を交換する働きをする。関数内で
は2つのオブジェクトが作られている。これらはデータ
を一時的に待避するためのオブジェクトとして使われて
いる。関数が終了したら不要となり、通常はガベージコ
レクタにより回収されるものである。
Reference numeral 301 in FIG. 3 is an example of a program for explaining a processing procedure of object memory optimization. The example program accepts objects x and y as input and serves to exchange the contents. Two objects are created in the function. These are used as objects to temporarily save data. They are no longer needed after the function has finished and are usually collected by the garbage collector.

【0013】図4の401は、例のプログラムに対してオ
ブジェクト参照解析をした状態を示している。1行目で
x.member1の内容をtmp1に複写している。これによりtmp
1には有効なデータが格納されたことになる。このよう
な操作をここではtmp1の定義と呼んでいる。2行目でも
同様にx.member2の内容をtmp2に複写している。
Reference numeral 401 in FIG. 4 shows a state in which object reference analysis has been performed on the example program. On the first line
The contents of x.member1 are copied to tmp1. This causes tmp
1 means that valid data has been stored. Such an operation is referred to herein as the definition of tmp1. In the second line, the contents of x.member2 are also copied to tmp2.

【0014】4行目でtmp1の内容をy.member1に複写し
ている。これによりtmp1からy.member1に有効なデータ
が移動したことになる。このような操作をここではtmp1
の参照と呼んでいる。tmp1はこの地点以降で参照される
ことはないので、メモリを解放してしまっても問題は起
きない。6行目でも同様にtmp2の内容をy.member2に複写
している。
In the fourth line, the contents of tmp1 are copied to y.member1. This means that valid data has been moved from tmp1 to y.member1. Such an operation here is tmp1
Call it a reference. Since tmp1 will not be referenced after this point, there is no problem if you release the memory. Line 6 also copies the contents of tmp2 to y.member2.

【0015】図5の501は、例のプログラムに対してオ
ブジェクト生存区間解析をした状態を示している。前述
のように、tmp1は1行目で定義され、5行目で参照され
る。即ち、1行目から5行目までの区間では有効なデータ
を格納している。このようにオブジェクトが有効なデー
タを保持している状態をオブジェクトが生きていると呼
ぶ。tmp1は5行目以降で参照されることはない。5行目以
降でtmp1の内容が破壊されたとしても、アプリケーショ
ンは正しく動作する。このような状態をオブジェクトが
死んでいると呼ぶ。死んでいるオブジェクトはガベージ
コレクションによって回収される。実際に何時オブジェ
クトが回収されるかは、ガベージコレクションの実装に
依存する。多くの実装では、死んだオブジェクトを直ち
に回収せずに、ある程度まとまったところで一括して回
収するようにしている。
Reference numeral 501 in FIG. 5 shows a state where the object live range analysis is performed on the example program. As mentioned above, tmp1 is defined on the first line and is referenced on the fifth line. That is, valid data is stored in the section from the first row to the fifth row. Such a state in which the object holds valid data is called that the object is alive. tmp1 will not be referenced in the fifth and subsequent lines. Even if the contents of tmp1 are destroyed after the fifth line, the application will work properly. Such a state is called a dead object. Dead objects are collected by garbage collection. When the object is actually collected depends on the garbage collection implementation. Many implementations do not collect dead objects immediately, but collect them collectively at a certain level.

【0016】図6の601は例のプログラムに対してオブ
ジェクト解放命令を挿入した状態を示している。前記の
解析結果に基づいて、オブジェクトが死んだ直後に解放
命令を挿入する。オブジェクトtmp1は5行目で死ぬの
で、その直後にオブジェクト解放命令free()を挿入す
る。オブジェクトtmp2は6行目で死ぬので、その直後で
解放する。オブジェクト解放命令が実行されると、直ち
にオブジェクトは削除され、オブジェクトが使用してい
たメモリは、システムのメモリプールに返却される。ガ
ベージコレクタを介さずにメモリを回収できるので、シ
ステム負荷は極めて小さい。
FIG. 6 shows a state 601 in which an object release instruction is inserted into the example program. Based on the analysis result, a release command is inserted immediately after the object dies. Since the object tmp1 dies on the fifth line, an object release instruction free () is inserted immediately after that. The object tmp2 dies on line 6, so release it immediately afterwards. As soon as the object release instruction is executed, the object is deleted and the memory used by the object is returned to the system memory pool. Since the memory can be collected without going through the garbage collector, the system load is extremely small.

【0017】オブジェクト解放命令を挿入する処理は、
コンパイル時に行われるので、アプリケーションの実行
性能を低下させることはない。ガベージコレクション
は、アプリケーションと同時に実行される。ガベージコ
レクションが頻繁に実行されれば、確実にアプリケーシ
ョンの実行性能が低下する。
The processing for inserting the object release instruction is as follows.
Since it is performed at the time of compilation, the execution performance of the application is not reduced. Garbage collection is performed simultaneously with the application. If the garbage collection is executed frequently, the execution performance of the application is surely reduced.

【0018】[0018]

【発明の効果】以上のように、本発明によれば、ガベー
ジコレクションの負荷が軽減され、アプリケーションの
実行性能が向上する。
As described above, according to the present invention, the load of garbage collection is reduced, and the execution performance of an application is improved.

【図面の簡単な説明】[Brief description of the drawings]

【図1】本発明の実施例であるオブジェクトメモリの全
体構成図。
FIG. 1 is an overall configuration diagram of an object memory according to an embodiment of the present invention.

【図2】オブジェクトメモリ最適化処理の手順を示すフ
ローチャート。
FIG. 2 is a flowchart illustrating a procedure of an object memory optimization process.

【図3】最適化手順を説明するための例題プログラムを
示す図。
FIG. 3 is a diagram showing an example program for explaining an optimization procedure.

【図4】オブジェクト参照解析の例を示す図。FIG. 4 is a diagram showing an example of object reference analysis.

【図5】オブジェクト生存区間解析の例を示す図。FIG. 5 is a diagram showing an example of object life cycle analysis.

【図6】オブジェクト解放命令挿入の例を示す図。FIG. 6 is a diagram showing an example of inserting an object release instruction.

【符号の説明】[Explanation of symbols]

101…処理系、 102…仮想コード、 103…
ソースコード、104…コード変換、105…構文解
析。
101: processing system, 102: virtual code, 103:
Source code, 104: code conversion, 105: syntax analysis.

Claims (1)

【特許請求の範囲】[Claims] 【請求項1】計算機システムにおいて、予めアプリケー
ションプログラムを解析し、メモリ解放命令を挿入して
おくことによって、実行時のガベージコレクションの負
荷を軽減し、アプリケーションの実行性能を改善するこ
とを特徴とするプログラム最適化方法。
In a computer system, by analyzing an application program in advance and inserting a memory release instruction, a load of garbage collection at the time of execution is reduced, and the execution performance of the application is improved. Program optimization method.
JP10299312A 1998-10-21 1998-10-21 Optimization method for object memory Pending JP2000132406A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP10299312A JP2000132406A (en) 1998-10-21 1998-10-21 Optimization method for object memory

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP10299312A JP2000132406A (en) 1998-10-21 1998-10-21 Optimization method for object memory

Publications (1)

Publication Number Publication Date
JP2000132406A true JP2000132406A (en) 2000-05-12

Family

ID=17870916

Family Applications (1)

Application Number Title Priority Date Filing Date
JP10299312A Pending JP2000132406A (en) 1998-10-21 1998-10-21 Optimization method for object memory

Country Status (1)

Country Link
JP (1) JP2000132406A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
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
US9009715B2 (en) 2009-10-07 2015-04-14 International Business Machines Corporation Object optimal allocation device, method and program
CN108804233A (en) * 2018-06-27 2018-11-13 联想(北京)有限公司 Memory headroom recovery method, device, electronic equipment and storage medium

Cited By (7)

* Cited by examiner, † Cited by third party
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
US9009715B2 (en) 2009-10-07 2015-04-14 International Business Machines Corporation Object optimal allocation device, method and program
US10296388B2 (en) 2009-10-07 2019-05-21 International Business Machines Corporation Object optimal allocation device, method and program
US11086680B2 (en) 2009-10-07 2021-08-10 International Business Machines Corporation Object optimal allocation device, method and program
CN108804233A (en) * 2018-06-27 2018-11-13 联想(北京)有限公司 Memory headroom recovery method, device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
US6314436B1 (en) Space-limited marking structure for tracing garbage collectors
US8336033B2 (en) Method and system for generating a hierarchical tree representing stack traces
US7904493B2 (en) Method and system for object age detection in garbage collection heaps
US7971010B2 (en) Mechanism for performing loitering trace of objects that cause memory leaks in a post-garbage collection heap
US8667471B2 (en) Method and system for customizing profiling sessions
US7533123B1 (en) Declarative pinning
US6658653B1 (en) Debugging methods for heap misuse
US20080244547A1 (en) Method and system for integrating profiling and debugging
JP4917138B2 (en) Object optimum arrangement device, object optimum arrangement method, and object optimum arrangement program
US6487563B1 (en) Memory reclamation method
US20080244546A1 (en) Method and system for providing on-demand profiling infrastructure for profiling at virtual machines
US7069279B1 (en) Timely finalization of system resources
US8478738B2 (en) Object deallocation system and method
US6647547B1 (en) Program conversion apparatus for eliminating unnecessary indications of dynamic memory allocation from a source program and generating an executable program
US20100262954A1 (en) Method for Locating Resource Leaks during Software Development
EP3635561B1 (en) Asynchronous operation query
US20020062478A1 (en) Compiler for compiling source programs in an object-oriented programming language
JP2000132406A (en) Optimization method for object memory
US20080307174A1 (en) Dual Use Memory Management Library
KR20020070270A (en) A method for garbage collection of unused methods
CN112487438B (en) Heap object Use-After-Free vulnerability detection method based on identifier consistency
Yip WRL Research Report 91/8
KR20030044319A (en) Debugging method of memory allocation and deallocation for real-time operating system
JPS62137641A (en) High-grade language compiler
JPH1021087A (en) Compiling method