JP5564540B2 - Memory management method, computer and program - Google Patents

Memory management method, computer and program Download PDF

Info

Publication number
JP5564540B2
JP5564540B2 JP2012175538A JP2012175538A JP5564540B2 JP 5564540 B2 JP5564540 B2 JP 5564540B2 JP 2012175538 A JP2012175538 A JP 2012175538A JP 2012175538 A JP2012175538 A JP 2012175538A JP 5564540 B2 JP5564540 B2 JP 5564540B2
Authority
JP
Japan
Prior art keywords
memory area
memory
program
data
thread
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.)
Active
Application number
JP2012175538A
Other languages
Japanese (ja)
Other versions
JP2012234567A (en
Inventor
元樹 小幡
博泰 西山
恵 中島
浩一 岡田
卓真 長瀬
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 JP2012175538A priority Critical patent/JP5564540B2/en
Publication of JP2012234567A publication Critical patent/JP2012234567A/en
Application granted granted Critical
Publication of JP5564540B2 publication Critical patent/JP5564540B2/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Description

本発明は、コンピュータにおけるメモリ管理方法、そのコンピュータ及びプログラムに関するものである。   The present invention relates to a memory management method in a computer, the computer, and a program.

コンピュータプログラムを開発する上で、プログラムで利用するメモリ領域の確保・解放処理はプログラム開発者の手を煩わせる項目のうちの1つであり、プログラム不良を起こしやすい項目であることが知られている。例えば、一般的なプログラミング言語であるC/C++言語では、プログラムの実行で必要なメモリ領域の確保や解放処理をユーザが明示的に記述する必要があり、これに起因するプログラム不良が多発している。プログラム不良の例としては、確保したメモリ領域のデータを回収(削除)し忘れで発生するメモリリーク(プログラム作成者の意図に反して利用可能なメモリ領域が徐々に減少する現象)や、解放済みメモリ領域に対する不正な参照が挙げられる。プログラム開発者は、メモリの利用状態を常に気に留めながらプログラムを開発しなければならないが、複数人によるプログラム開発や、プログラムコードの肥大化によって、全てのメモリの確保・解放処理を完全に把握することは困難になりつつある。   When developing a computer program, securing and releasing the memory area used by the program is one of the items that bother the program developer and is known to be prone to program failures. Yes. For example, in the C / C ++ language, which is a general programming language, the user must explicitly describe the allocation and release processing of the memory area required for program execution, resulting in frequent program failures. Yes. Examples of program failures include memory leaks that occur when you forget to collect (delete) data in an allocated memory area (a phenomenon where the available memory area gradually decreases against the intention of the program creator) or has been released An illegal reference to the memory area is given. The program developer must develop the program while always paying attention to the state of memory usage. However, the program development by multiple people and the enlargement of the program code ensure a complete grasp of all memory allocation / release processes. It is becoming difficult to do.

これを解決する手段として、プログラム中でのメモリ管理を自動化するガベージコレクタの利用が挙げられる。ガベージコレクタを利用してメモリ管理する言語処理系の1つであるJava(Javaは、米国 Sun Microsystem,Inc.の商標である。)には、プログラム実行時のメモリ確保用API(Application Program Interface)は用意されているが、解放用APIは存在しない。すなわち、Javaプログラム(以下、単にプログラムと呼ぶことがある。)開発者はメモリ領域の確保は明示する必要があるが、確保したメモリ領域の解放処理は記述する必要がない。プログラム実行の過程で確保したメモリ領域は、プログラムを実行するJava仮想マシンに実装されたガベージコレクタが解放する。ガベージコレクタが実行する機能がガベージコレクション(以下、GC)である。すなわちGCとは、プログラムが動的に確保したメモリ領域のうち、不要になったデータを回収し、その領域を自動的に解放する機能である。   As a means for solving this, use of a garbage collector for automating memory management in a program can be mentioned. Java (Java is a trademark of Sun Microsystem, Inc., USA), one of the language processors that manage memory using a garbage collector, has an API (Application Program Interface) for securing memory during program execution. Is provided, but there is no release API. That is, a Java program (hereinafter, simply referred to as a program) developer needs to clearly indicate the allocation of the memory area, but does not need to describe the process for releasing the allocated memory area. The memory area secured in the process of program execution is released by the garbage collector implemented in the Java virtual machine that executes the program. The function executed by the garbage collector is garbage collection (hereinafter referred to as GC). In other words, the GC is a function of collecting unnecessary data from the memory area dynamically allocated by the program and automatically releasing the area.

GCでは、実装方式にもよるが、基本的に全てのJavaプログラム実行スレッドを停止させて、不要なデータを回収する。Java仮想マシンがGCを起動する(GC機能を有するガベージコレクタを実行する)のは、プログラム上で生成されるデータ(オブジェクト)を格納(単に、生成と呼ぶことがある。)するJavaヒープメモリの使用量がある閾値を超えた時である。プログラム実行によるメモリ使用量をユーザが見積もるのは困難であり、この閾値を越えるタイミングを予見することも難しい。よって、この閾値を越えたことによるGCの起動をユーザが予見することも困難であるため、GCの起動によりプログラムの実行は不定期に停止することになる。さらに、Java仮想マシンにおけるGCの実装方式として採用されていることが多い世代別ガベージコレクションでは、短時間で終了するGCと、長時間の停止を要するGCが発生するが、次にどちらのGCが発生するかを予見することは困難である。長時間停止するGCが発生することを予見できれば、実行環境(Java仮想マシン)の負荷が小さいときに明示的にGCを発生させることによって、予期しない長時間停止を避けることも可能であるが、上記のようにどの程度の時間を要するGCがいつ発生するのかは、ユーザにとって不明である。   Depending on the implementation method, GC basically stops all Java program execution threads and collects unnecessary data. The Java virtual machine starts the GC (executes a garbage collector having a GC function), which stores the data (object) generated in the program (sometimes referred to simply as generation) in the Java heap memory. When the usage exceeds a certain threshold. It is difficult for the user to estimate the amount of memory used by program execution, and it is also difficult to predict when the threshold will be exceeded. Therefore, since it is difficult for the user to foresee the start of the GC due to exceeding this threshold, the execution of the program is stopped irregularly by the start of the GC. Furthermore, generational garbage collection, which is often adopted as a GC implementation method in the Java virtual machine, generates a GC that finishes in a short time and a GC that requires a long stop. It is difficult to predict what will happen. If it can be predicted that a GC that stops for a long time will occur, it is possible to avoid an unexpected long stop by explicitly generating a GC when the load on the execution environment (Java virtual machine) is low. It is unclear to the user when the time-consuming GC occurs as described above.

近年、Javaシステム(Java言語で記述したプログラムをJava仮想マシン上で実行するシステム)がサーバや、携帯電話やカー・ナビゲーション・システムのような組み込み分野で用いられるようになってきた。しかし、これらの分野で予期しないGCの起動によるプログラム停止が発生するとシステム全体の応答がなくなることが問題になっており、これを解決する方法が開発されている[非特許文献1]、[非特許文献2]。   In recent years, Java systems (systems that execute programs written in the Java language on a Java virtual machine) have come to be used in embedded fields such as servers, mobile phones, and car navigation systems. However, in these fields, when a program stop due to unexpected GC startup occurs, there is a problem that the response of the entire system is lost, and a method for solving this has been developed [Non-Patent Document 1], [Non-Patent Document 1] Patent Document 2].

GCによるプログラムの停止を避けるため、例えばリアルタイム処理に特化したJavaの仕様 Real Time Specification for Java (以下、RTSJ)では、Scoped MemoryというGC対象外の外部メモリ領域を設定できる。一連のプログラム処理で生成するデータを、GCの対象であるJavaヒープメモリ内ではなく、プログラムで明示的に確保したScoped Memory内に生成することで、Javaヒープメモリの枯渇によるGCを発生しにくくしている。一連のプログラム処理終了後はScoped Memoryに生成されたデータは不要となるが、これをGCで不要データを回収するのではなく、Scoped Memoryごと削除(データを削除して利用可能な領域として確保しておくのではなく、領域を削除してしまい、領域を使いたいときは改めて領域を確保する)する。以下、このようなメモリ領域の削除を「解放」と呼ぶ。   In order to avoid program stoppage due to GC, for example, in the Java specification Real Time Specification for Java (hereinafter RTSJ) specialized for real-time processing, an external memory area that is not subject to GC can be set as Scoped Memory. Data generated by a series of program processing is generated not in the Java heap memory that is the target of GC, but in Scoped Memory that is explicitly secured by the program, making it difficult for GC to occur due to depletion of Java heap memory ing. After a series of program processing, the data generated in Scoped Memory is no longer necessary. However, instead of collecting unnecessary data with GC, it is deleted for each Scoped Memory (data is deleted and secured as an available area) Rather than deleting the area, if you want to use the area, reserve the area again). Hereinafter, such deletion of the memory area is referred to as “release”.

どのようなメモリ管理手法を用いるにしても、プログラムの実行に必要なデータはメモリ中に残存させなければならない。ガベージコレクタを用いたメモリ管理手法では、レジスタや実行時スタックといったルートセットと呼ばれる箇所から参照可能な全てのデータを実行に必要なデータとして扱うことで、プログラムの以降の実行に必要なデータと不要なデータを識別する。   Whatever memory management method is used, data necessary for executing the program must remain in the memory. In the memory management method using the garbage collector, all the data that can be referred to from the location called the root set, such as registers and runtime stacks, is handled as the data necessary for execution, and the data necessary for the subsequent execution of the program is unnecessary. The correct data.

一方、RTSJのようなGC対象外のメモリ領域設定によるGC回避手法を用いる場合、プログラムの実行結果が不正にならないよう、プログラミングAPIに一定の制約を課しており、実行時にこれに違反しないかどうかをチェックするオーバヘッドが発生する。ここで「一定の制約」とはScoped Memory存続のための制約や、データ間参照の制限である。RTSJにおけるScoped Memoryは、Javaプログラムで生成した1つ以上のスレッドがenterメソッドやexecuteInAreaメソッドで指示されたスコープ、すなわちある区間(プログラムの所定のステップから他の所定のステップまで)を実行中にのみ存在できるメモリ領域であり、全てのスレッドがこのスコープを抜けた場合は自動的に解放される。よって、Scoped Memoryを存続させるためには、1つ以上のスレッドがこのスコープを実行中でなければならず、テンポラリ的なデータ領域という位置づけとなっている。   On the other hand, when using a GC avoidance technique such as RTSJ that sets a memory area that is not subject to GC, a certain restriction is imposed on the programming API so that the execution result of the program will not be invalid. Overhead checking occurs. Here, the “constant constraint” is a constraint for Scoped Memory existence or a limitation of reference between data. Scoped Memory in RTSJ is only when one or more threads generated by a Java program are executing the scope indicated by the enter method or executeInArea method, that is, during a certain section (from a predetermined step of the program to another predetermined step) It is a memory area that can exist, and is automatically released when all threads leave this scope. Therefore, in order for Scoped Memory to survive, one or more threads must be executing this scope, which is positioned as a temporary data area.

ScopedMemoryの解放処理では、Scoped Memory内部のデータについて何も処理を行わずに解放するが、これを実現するため当該スコープ内で生成するデータに関する参照関係に制限[非特許文献1][非特許文献2]がある。   In the ScopedMemory release processing, the data in the Scoped Memory is released without performing any processing, but in order to realize this, the reference relationship regarding the data generated in the scope is limited [Non-patent document 1] [Non-patent document] 2].

図11(a)に示すメモリ領域とデータ配置を例に説明する。図11(a)は、GCの対象であるJavaヒープメモリ110上にデータ1102-1と1102-2、GCの対象外として確保されたScoped Memory1101上にデータ1103-1と1103-2がある。データ1102-1とデータ1103-2とがデータ1103-1を、またデータ1103-2がデータ1102-2を参照している様子を示している。これはRTSJとしては不正なメモリ状態である。図11(a)では、データ1102-1からデータ1103-1への参照を矢印1104で、データ1103-2からデータ1103-1への参照を矢印1105-1、データ1103-2からデータ1102-2への参照を矢印1105-2で示している。このScoped Memory1101を、内部データ1103-1、1103-2ごと解放したとすると、メモリ領域とデータの状態は図11(b)に示すようになる。   The memory area and data arrangement shown in FIG. 11 (a) will be described as an example. In FIG. 11A, there are data 1102-1 and 1102-2 on the Java heap memory 110 that is the target of the GC, and data 1103-1 and 1103-2 on the scoped memory 1101 that is reserved as a target of the GC. Data 1102-1 and data 1103-2 refer to data 1103-1, and data 1103-2 refers to data 1102-2. This is an invalid memory state for RTSJ. In FIG. 11A, the reference from the data 1102-1 to the data 1103-1 is indicated by the arrow 1104, the reference from the data 1103-2 to the data 1103-1 is indicated by the arrow 1105-1, and the reference from the data 1103-2 to the data 1102- Reference to 2 is indicated by arrow 1105-2. If this scoped memory 1101 is released together with the internal data 1103-1 and 1103-2, the memory area and the state of the data are as shown in FIG.

図11(b)に示すように、データ1102-1の参照先は既に解放された不正なメモリ領域であり、この状態でプログラムの実行を続行しても正しく動作しない。RTSJではこのような状態を防ぐため、スコープスタックというスタック的な概念を導入している。スコープスタックでは、深い位置にあるスコープで生成されたデータから浅い位置にあるスコープで生成されたデータを参照できないという制限を設け、図11(a)の参照1104のような参照をそもそも生成できないようにしている。(よって、図11(a)は不正な状態ということである。) この制限に従えば、あるScoped Memoryに対してデータを生成するスコープを実行するスレッドが1つもなくなった時点で、このScoped Memoryを解放しても、プログラムの実行には影響がないことを保証できる。   As shown in FIG. 11 (b), the reference destination of the data 1102-1 is an illegal memory area that has already been released, and even if the program execution is continued in this state, it does not operate correctly. RTSJ introduces a stack concept called scope stack to prevent this situation. In the scope stack, there is a restriction that data generated in a shallow scope cannot be referenced from data generated in a deep scope, so that a reference such as reference 1104 in Fig. 11 (a) cannot be generated in the first place. I have to. (Thus, FIG. 11 (a) is an invalid state.) According to this restriction, when there is no thread that executes a scope that generates data for a certain scoped memory, this scoped memory is lost. It can be assured that releasing the program does not affect the execution of the program.

例えば、図11(a)において、まずJavaヒープメモリ上にデータ(1102-1と1102-2)が生成されるスコープの実行を開始したとすると、この情報がスコープスタックに格納される。その後、Scoped Memoryが生成され、1つ以上のスレッドが当該Scoped Memoryに対するenterメソッド及びexecuteInAreaメソッドで指示されたスコープの区間の実行を開始した時点で、スコープスタックにこのスコープの情報が追加された状態を仮定する。この時点でスコープスタックには、スタックの深い位置に「Javaヒープメモリにデータを生成するスコープ」という情報が格納されており、浅い位置に「Scoped Memoryにデータを生成するスコープ」という情報が格納されていることになる。   For example, in FIG. 11A, if execution of a scope in which data (1102-1 and 1102-2) is first generated on the Java heap memory is started, this information is stored in the scope stack. After that, when Scoped Memory is created and one or more threads start executing the scope section specified by the enter method and executeInArea method for the Scoped Memory, this scope information is added to the scope stack. Assuming At this point, the scope stack stores information called “Scope that generates data in Java heap memory” at a deep position in the stack, and information called “Scope that generates data in Scoped Memory” at a shallow position. Will be.

RTSJにおけるデータ間の参照関係に関する制限に照らすと、図11(a)のデータ1102-1からデータ1103-1に対する参照は、スコープスタック上で深い位置にあるスコープで生成されたデータから浅い位置にあるスコープで生成されたデータに対する参照であるため、これを生成することはできない。一方、図11(a)のデータ1103-2からデータ1103-1に対する参照1105-1やデータ1102-2に対する参照1105-2は、スコープスタック上で浅い位置にあるスコープで生成されたデータ同士や、深い位置にあるスコープで生成されたデータに対する参照であるため生成可能である。全スレッドがこのScoped Memoryに対してデータを生成するスコープから脱した時点で、Scoped Memory内のデータを参照することができなくなるため、本メモリ領域を解放しても、プログラムの実行に影響を与えることはない。   In light of the restrictions on the reference relationship between data in RTSJ, references to data 1102-1 to data 1103-1 in Figure 11 (a) are shallower than the data generated by the scope that is deeper in the scope stack. Since it is a reference to data generated in a certain scope, it cannot be generated. On the other hand, the reference 1105-1 from the data 1103-2 to the data 1103-1 and the reference 1105-2 to the data 1102-2 in FIG. 11 (a) are the data generated by the scope at a shallow position on the scope stack. Since it is a reference to data generated in a deep scope, it can be generated. When all threads leave the scope that generates data for this scoped memory, it becomes impossible to refer to the data in the scoped memory, so even if this memory area is released, program execution will be affected. There is nothing.

Angelo Corsaro and Ron K. Cytron, Efficient Memory-Reference Checks for Real-time Java, Proceedings of the 2003 Conference on Languages, Compilers, and Tools for Embedded Systems, 2003.Angelo Corsaro and Ron K. Cytron, Efficient Memory-Reference Checks for Real-time Java, Proceedings of the 2003 Conference on Languages, Compilers, and Tools for Embedded Systems, 2003. F.Pizlo, J.M.Fox, D.Holmes and J.Vitek, Real-Time Java Scoped Memory: Design Patterns and Semantics, Proceedings of the Seventh IEEE Internal Symposium on Object-Oriented Real-Time Distributed Computing, 2004.F. Pizlo, J.M.Fox, D. Holmes and J. Vitek, Real-Time Java Scoped Memory: Design Patterns and Semantics, Proceedings of the Seventh IEEE Internal Symposium on Object-Oriented Real-Time Distributed Computing, 2004.

ガベージコレクションによってメモリ管理を行うJavaシステムのようなシステムにおいて、ガベージコレクションの対象外の、プログラムから明示的に確保可能なメモリ領域を利用できる場合に、そのメモリ領域の存続及び使用する際のデータ間の参照関係の制約事項は、このメモリ領域の利便性を著しく損ねている。つまり、プログラムから明示的に確保したメモリが存続する条件として、そのメモリ領域に対してデータを生成する区間を1つ以上のスレッドが実行中である必要があるが、この条件はプログラミングに著しい制約を課している。また、データ間の参照関係の制限のため、ユーザは常にデータ間の参照関係に留意しながらプログラミングする必要があるが、プログラム規模の肥大化や、ユーザプログラム上で記述されていない暗黙的データ生成の発生により、メモリ領域上の参照関係の完全な把握は極めて困難である。実行時のチェックにより、この制約に違反する参照関係が発生した際は、例外処理(Exception)が発生し、プログラムは正常に実行されないことがある。   In a system such as a Java system that manages memory by garbage collection, when a memory area that is not subject to garbage collection and can be explicitly secured from a program can be used, the data between the memory area's survival and use The restrictions on the reference relationship of the above significantly impair the convenience of this memory area. In other words, as a condition for the memory that has been explicitly secured from the program to exist, one or more threads must be running in the interval for generating data for that memory area. Imposing. In addition, due to the restriction of the reference relationship between data, the user must always program while paying attention to the reference relationship between data. However, the program size is enlarged and implicit data generation that is not described in the user program Due to the occurrence of this, it is extremely difficult to completely grasp the reference relationship in the memory area. When a reference relationship that violates this restriction occurs due to a check at the time of execution, exception handling (Exception) occurs and the program may not be executed normally.

また、上記制約事項に関する実行時チェックにより、このようなメモリ領域を使わない場合のプログラムの実行性能に対して、著しい性能低下が発生する点も問題である。   Another problem is that due to the execution check related to the above restrictions, a significant performance drop occurs with respect to the execution performance of the program when such a memory area is not used.

本発明および実施の形態の説明に際して、メモリ領域(単にメモリまたは領域とも言う。)の「解放」の意味を明らかにしておく。メモリ領域の解放とは、メモリ上の所定位置に確保された所定容量の領域またはその領域にあるデータをプログラムから認識できないようにすることである。したがって、解放後のメモリ領域へのプログラムからのアクセスは不正(アクセス)となる。メモリ領域の解放後に、新たにメモリ領域を必要とする場合は、新たにメモリ領域を生成(確保)する。このメモリ領域の解放に対して、メモリ上の所定位置に確保された所定容量の領域に格納されているデータを回収して、新たなデータの格納場所として利用可能にする場合がある。このデータの回収機能がガベージコレクションである。   In the description of the present invention and the embodiment, the meaning of “release” of a memory area (also simply referred to as memory or area) will be clarified. The release of the memory area is to prevent a program from recognizing an area of a predetermined capacity secured at a predetermined position on the memory or data in the area. Therefore, access from the program to the memory area after release is illegal (access). If a new memory area is required after the memory area is released, a new memory area is generated (secured). In response to the release of the memory area, data stored in a predetermined capacity area secured at a predetermined position on the memory may be collected and used as a storage location for new data. This data collection function is garbage collection.

本発明の態様の一つは、コンピュータ内のプロセッサにより実行されるプログラムによりメモリ領域を確保し、プログラムの実行に応じて確保したメモリ領域にデータを格納する。プログラムによる確保したメモリ領域の解放の指示に応答して、プログラムの以降の実行に必要なデータが解放を指示されたメモリ領域に存在するか否かをチェックする。チェックの結果、プログラムの以降の実行に必要なデータ(オブジェクト)が解放を指示されたメモリ領域に存在しないとき、解放を指示されたメモリ領域を解放するメモリ管理方法である。   In one aspect of the present invention, a memory area is secured by a program executed by a processor in a computer, and data is stored in the secured memory area in accordance with execution of the program. In response to an instruction to release the secured memory area by the program, it is checked whether data necessary for subsequent execution of the program exists in the memory area instructed to be released. This is a memory management method for releasing a memory area instructed to be released when data (object) necessary for subsequent execution of the program does not exist in the memory area instructed to be released as a result of the check.

本発明の他の態様は、メモリとプロセッサを有するコンピュータであり、次のように構成される。メモリには、ガベージコレクションによって管理される第一の領域、およびプログラムの実行に応じて、確保され、データが格納され、解放される第二の領域とを設ける。プロセッサは、プログラムの実行に伴う第二の領域の解放の指示に応答して、プログラムの以降の実行に必要なデータが第二の領域に存在するとき、そのデータを第一の領域へ移動する。   Another aspect of the present invention is a computer having a memory and a processor, and is configured as follows. The memory is provided with a first area managed by garbage collection and a second area that is secured, stores data, and is released according to the execution of the program. In response to an instruction to release the second area accompanying the execution of the program, the processor moves the data to the first area when data necessary for subsequent execution of the program exists in the second area. .

本発明によって、プログラムの実行に制約を与えずに、プログラムが確保したメモリ領域を解放できる。   According to the present invention, a memory area secured by a program can be released without restricting the execution of the program.

実施例のコンピュータの構成例である。It is a structural example of the computer of an Example. 外部ヒープメモリを生成、利用(データ生成)、解放するプログラム例である。It is an example of a program that generates, uses (data generation), and releases an external heap memory. 外部ヒープメモリにデータを生成、移動する例である。This is an example of generating and moving data to an external heap memory. 外部ヒープメモリ上の不要データを回収する例である。This is an example of collecting unnecessary data on the external heap memory. 外部ヒープメモリ上にデータを移動させる契機を指定した例である。This is an example of specifying an opportunity to move data to the external heap memory. 外部ヒープメモリの解放の様子の例である。It is an example of a state of releasing the external heap memory. 外部ヒープメモリの解放処理である。External heap memory release processing. 外部ヒープメモリの解放の様子の例である。It is an example of a state of releasing the external heap memory. 外部ヒープメモリの解放時に必要データが残存している場合に例外を発生させるよう指示する例である。This is an example of instructing to generate an exception when necessary data remains when the external heap memory is released. 外部ヒープメモリの解放時に必要データが残存している場合の動作を指定した場合の解放処理である。This is the release process when the operation when the necessary data remains when the external heap memory is released is specified. Scoped Memoryへのデータを生成する例である。This is an example of generating data to Scoped Memory.

本発明を実施するための最良の形態は、プロセッサにより実行されるプログラムによりメモリ領域を確保し、プログラムの実行に応じて確保したメモリ領域にデータを格納する(オブジェクトを生成する)。プログラムによる確保したメモリ領域の解放の指示に応答して、プログラムの以降の実行に必要なデータが解放を指示されたメモリ領域に存在するか否かをチェックする。チェックの結果、プログラムの以降の実行に必要なデータ(オブジェクト)が解放を指示されたメモリ領域に存在しないとき、解放を指示されたメモリ領域を解放する。   In the best mode for carrying out the present invention, a memory area is secured by a program executed by a processor, and data is stored (an object is generated) in the secured memory area in accordance with the execution of the program. In response to an instruction to release the secured memory area by the program, it is checked whether data necessary for subsequent execution of the program exists in the memory area instructed to be released. As a result of the check, when the data (object) necessary for the subsequent execution of the program does not exist in the memory area instructed to be released, the memory area instructed to be released is released.

チェックの結果、プログラムの以降の実行に必要なデータが解放を指示されたメモリ領域に存在するとき、そのデータを、解放を指示されたメモリ領域とは異なるメモリ領域へ移動する。プログラムの実行に必要なデータをメモリ領域とは異なるメモリ領域へ移動し、異なるメモリ領域はガベージコレクションが実行される。   As a result of the check, when data necessary for subsequent execution of the program exists in the memory area instructed to be released, the data is moved to a memory area different from the memory area instructed to be released. Data necessary for program execution is moved to a memory area different from the memory area, and garbage collection is executed in the different memory area.

本発明の他の態様は、メモリとプロセッサを有するコンピュータであり、次のように構成される。メモリには、ガベージコレクションによって管理される第一の領域、およびプログラムの実行に応じて、確保され、データが格納され、解放される第二の領域とを設ける。プロセッサは、プログラムの実行に伴う第二の領域の解放の指示に応答して、プログラムの以降の実行に必要なデータが第二の領域に存在するとき、そのデータを第一の領域へ移動する。これにより、プログラムの実行性能の低下を招かないコンピュータを実現できる。   Another aspect of the present invention is a computer having a memory and a processor, and is configured as follows. The memory is provided with a first area managed by garbage collection and a second area that is secured, stores data, and is released according to the execution of the program. In response to an instruction to release the second area accompanying the execution of the program, the processor moves the data to the first area when data necessary for subsequent execution of the program exists in the second area. . Thereby, it is possible to realize a computer that does not cause a decrease in the execution performance of the program.

本発明に係るメモリ管理方法の一実施形態について、図面を用いて説明する。なお、本実施例はJavaシステム(Java言語で記述されたプログラムがJava仮想マシン(実行環境とも言う。)上で実行されているシステム)を対象として説明するが、ガベージコレクション機能を有する他のシステムにおいても有効である。   An embodiment of a memory management method according to the present invention will be described with reference to the drawings. Although this embodiment is described for a Java system (a system in which a program written in the Java language is executed on a Java virtual machine (also referred to as an execution environment)), other systems having a garbage collection function are described. Is also effective.

図1は、本実施例のコンピュータ101の構成を示す図である。コンピュータ101は、各処理を実行するプロセッサ(CPU)102と、プロセッサ102上でJava仮想マシン(Java VM)105が実行するJavaプログラム104、Java仮想マシン105が用いるJavaヒープメモリ110、外部ヒープメモリ111-1〜3を含むメモリ103を含んでいる。外部ヒープメモリ111はJavaプログラム104に記述された外部ヒープメモリ生成文の実行に応じて生成される。なお、Javaプログラム104はメモリ103上ではなく、外部記憶装置112に格納されていることもある。   FIG. 1 is a diagram illustrating a configuration of a computer 101 according to the present embodiment. The computer 101 includes a processor (CPU) 102 for executing each process, a Java program 104 executed by the Java virtual machine (Java VM) 105 on the processor 102, a Java heap memory 110 used by the Java virtual machine 105, and an external heap memory 111. A memory 103 including −1 to 3 is included. The external heap memory 111 is generated in response to the execution of an external heap memory generation statement described in the Java program 104. Note that the Java program 104 may be stored not in the memory 103 but in the external storage device 112.

Javaプログラム104には、所要の処理に加えて、外部ヒープメモリを生成、外部ヒープメモリへのデータの格納(オブジェクトの生成)、外部ヒープメモリの解放といった記述がなされており、これをJava仮想マシン105が実行することで、外部ヒープメモリ111が生成され、利用され、解放される。一方、Javaヒープメモリ110はJava仮想マシン105によって、ガベージコレクション等のメモリ管理がなされ、Javaプログラム104からはメモリ管理できない。   In addition to the required processing, the Java program 104 includes descriptions such as creating an external heap memory, storing data in the external heap memory (generating objects), and releasing the external heap memory. By executing 105, the external heap memory 111 is generated, used, and released. On the other hand, the Java heap memory 110 is subjected to memory management such as garbage collection by the Java virtual machine 105 and cannot be managed from the Java program 104.

Javaプログラム104を実行するため、Java仮想マシン105はプログラム読込み部106でJavaプログラム104を読み込み、外部ヒープメモリ111を生成する文を実行した際には外部ヒープ生成部107で外部ヒープメモリ111を生成し、Javaプログラム104に記述された外部ヒープメモリ111へのデータ生成区間(所定のステップから他の所定のステップ)において、外部ヒープメモリ111へのデータ生成部によって外部ヒープメモリ111内にデータを生成する。また、Javaプログラム104上で外部ヒープメモリ111の解放が明示的に指示された場合は、外部ヒープ解放部109において、実行に必要なデータのうち外部ヒープメモリ111上にあるデータを解放対象外メモリ領域に移動させてから外部ヒープメモリ111を解放する。   In order to execute the Java program 104, the Java virtual machine 105 reads the Java program 104 by the program reading unit 106, and generates an external heap memory 111 by the external heap generation unit 107 when a statement for generating the external heap memory 111 is executed. In the data generation section for the external heap memory 111 described in the Java program 104 (from a predetermined step to another predetermined step), data is generated in the external heap memory 111 by the data generation unit for the external heap memory 111. To do. In addition, when the release of the external heap memory 111 is explicitly instructed on the Java program 104, the external heap release unit 109 causes the data on the external heap memory 111 among the data necessary for execution to be excluded from the release target memory. After moving to the area, the external heap memory 111 is released.

外部ヒープメモリ111を生成、外部ヒープメモリ111へのデータ生成、外部ヒープメモリ111の解放のための記述を含んだJavaプログラム104の例を図2に示す。図2における、各行左の数値は行番号であり、実際のプログラムには記述されていない。2行目の文201は、外部ヒープメモリ111を生成(確保)する記述であり、4行目のenterメソッドから6行目のexitメソッドまでの処理202において生成したデータは、外部メモリ111上に直接生成(格納)されるか、最初はJavaヒープメモリ110上に生成し、8行目の文204にあるcommitChangesメソッドで外部メモリ111に明示的に移動させることも可能である。ここでは、区間が4行目から6行目である。この区間の処理202中で直接外部ヒープメモリ111中にデータを生成すると、処理202中でデータの全てを外部ヒープメモリ111に生成してしまうので、すぐに不要となるデータも外部ヒープメモリ111に生成されてしまい、外部ヒープメモリ111のメモリ領域の利用効率が悪くなる。これに対して、Javaヒープメモリ110にデータを生成した上で、必要なデータを外部ヒープメモリ111に移動することで、メモリ領域の利用効率の悪化に対する対策となる。   FIG. 2 shows an example of the Java program 104 including descriptions for generating the external heap memory 111, generating data in the external heap memory 111, and releasing the external heap memory 111. The numbers on the left of each line in FIG. 2 are line numbers and are not described in the actual program. The statement 201 on the second line is a description for generating (allocating) the external heap memory 111. The data generated in the process 202 from the enter method on the fourth line to the exit method on the sixth line is stored in the external memory 111. It can be generated (stored) directly, or first generated on the Java heap memory 110 and explicitly moved to the external memory 111 with the commitChanges method in the statement 204 on the eighth line. Here, the section is from the 4th line to the 6th line. If data is generated directly in the external heap memory 111 during the processing 202 in this section, all of the data is generated in the external heap memory 111 during the processing 202. Therefore, unnecessary data is immediately stored in the external heap memory 111. As a result, the use efficiency of the memory area of the external heap memory 111 is deteriorated. On the other hand, by generating the data in the Java heap memory 110 and then moving the necessary data to the external heap memory 111, it is a countermeasure against deterioration in the use efficiency of the memory area.

プログラム上で外部ヒープメモリ111へのデータの移動を指示するcommitChangesメソッドは、引数に移動対象メモリのインスタンスを指定するだけでなく、移動するデータを明示することも可能である。図2の例では、移動対象の外部ヒープメモリemが指定されているだけであるので、ヒープメモリemへの移動対象となっているデータの全てを移動する。ちなみに、その他の部分(202の区間外)で生成されたデータはJavaヒープメモリ110上に生成される。図2中9行目に示すように、外部ヒープメモリ111上に生成されたデータを任意の処理で利用した後、外部ヒープメモリ111上のデータが不要となった際には、図2中11行目の文203のように外部ヒープメモリemの解放を指示する。なお、図2中9行目の任意の処理における外部ヒープメモリemの利用にあたっては、プログラム上の制限や実行時の参照関係の調査は存在しない。   The commitChanges method for instructing movement of data to the external heap memory 111 on the program can specify not only the instance of the movement target memory as an argument but also the data to be moved. In the example of FIG. 2, since only the external heap memory em to be moved is specified, all of the data to be moved to the heap memory em is moved. Incidentally, the data generated in the other part (outside the section 202) is generated on the Java heap memory 110. As shown on the 9th line in FIG. 2, after the data generated on the external heap memory 111 is used for arbitrary processing and the data on the external heap memory 111 becomes unnecessary, 11 in FIG. Instructs the release of the external heap memory em as in statement 203 on the line. When using the external heap memory em in the arbitrary process on the 9th line in FIG. 2, there are no restrictions on the program or investigation of the reference relationship at the time of execution.

図3、図4、および図5に他のプログラム例を示す。図3は、enter/exitメソッドで外部ヒープメモリ111へのデータ生成を指示するのではなく、4行目の文301に示すように既存のデータ(オブジェクト)を外部ヒープメモリemに移動させるmoveObjectメソッドや、6行目の文302に示すように生成するデータのクラスを指定して外部ヒープメモリem内に直接データを生成するnewInstanceメソッドを用いて、外部ヒープメモリemを利用している。   FIG. 3, FIG. 4, and FIG. 5 show other program examples. Figure 3 shows the moveObject method that moves existing data (object) to the external heap memory em as shown in the statement 301 on the 4th line, instead of instructing data generation to the external heap memory 111 with the enter / exit method. Alternatively, as shown in the statement 302 on the sixth line, the external heap memory em is used by using the newInstance method that specifies the class of data to be generated and generates data directly in the external heap memory em.

また、図4の文401に示すように、外部ヒープメモリemの不要データ(オブジェクト)の回収を指示するcompactメソッドを実行し、外部ヒープメモリemの空き領域を増やすこともできる。   Further, as shown in a sentence 401 in FIG. 4, a compact method for instructing collection of unnecessary data (objects) in the external heap memory em can be executed to increase the free space in the external heap memory em.

図4の12行目に示す任意の処理で外部ヒープメモリemにさらにデータを移動させるような場合には、あらかじめ11行目の文401に示すcompactメソッドを実行することによって、移動可能なデータ量を増やすことができる。   If you want to move more data to the external heap memory em in the arbitrary process shown on the 12th line in Fig. 4, the amount of data that can be moved by executing the compact method shown in the sentence 401 on the 11th line in advance Can be increased.

図5は、commitChangesメソッドでデータの移動を明示するのではなく、enterメソッドの引数としてCommitMode.MOVE_ON_GCを与えることによって、処理501内で生成されたデータは、Javaヒープメモリ110でのGCの発生を契機として、外部ヒープメモリemに移動する例である。Javaヒープメモリ110でのGCで、プログラムの以降の実行に必要なデータと判断されたデータで、かつ処理501内で生成されたデータが外部ヒープメモリemに移動するため、不要なデータが移動しにくく、外部メモリ領域emを有効に利用することができる。   Figure 5 shows that the data generated in the process 501 is not generated in the Java heap memory 110 by giving CommitMode.MOVE_ON_GC as an argument of the enter method instead of explicitly indicating the data movement with the commitChanges method. This is an example of moving to the external heap memory em as an opportunity. Since the data in the Java heap memory 110 is determined to be data necessary for the subsequent execution of the program and the data generated in the process 501 moves to the external heap memory em, unnecessary data moves. The external memory area em can be used effectively.

外部ヒープメモリ111の解放処理は、図1の外部ヒープ解放部109で実行される。この際、外部ヒープメモリ111上にあるデータがJavaプログラム104の実行に必要である場合を考慮しなければならない。例えば、図6(a)のようなメモリ103上のデータ配置である。図6(a)は、Javaヒープメモリ110上にデータ601-1と601-2、外部ヒープメモリ111上にデータ602-1と602-2があり、データ601-1とデータ602-2がデータ602-1を、またデータ602-2がデータ601-2を参照している様子を示している。図6(a)では、データ601-1からデータ602-1への参照を矢印603で、データ602-2からデータ602-1への参照を矢印604-1、データ602-2からデータ601-2への参照を矢印604-2で示している。この状態から外部メモリ111を解放すると、このメモリ上のデータ602-1と602-2を削除したことになり、データ602-2からの参照である604-1及び604-2がなくなってもJavaプログラム104の実行に問題は生じない。しかし、参照603については図6(b)に示すようにデータ601-1が参照するデータが不正なメモリ領域を参照することになり、Javaプログラム104は正しく動作しない。   The release process of the external heap memory 111 is executed by the external heap release unit 109 in FIG. At this time, the case where the data on the external heap memory 111 is necessary for the execution of the Java program 104 must be considered. For example, the data arrangement on the memory 103 as shown in FIG. 6A shows data 601-1 and 601-2 on the Java heap memory 110, data 602-1 and 602-2 on the external heap memory 111, and data 601-1 and data 602-2. 602-1 and data 602-2 refer to data 601-2. In FIG. 6A, the reference from the data 601-1 to the data 602-1 is indicated by the arrow 603, the reference from the data 602-2 to the data 602-1 is indicated by the arrow 604-1, and the reference from the data 602-2 to the data 601-2. Reference to 2 is indicated by arrow 604-2. When the external memory 111 is released from this state, the data 602-1 and 602-2 on this memory are deleted, and even if the references 604-1 and 604-2 that are references from the data 602-2 disappear, Java There is no problem in executing the program 104. However, for the reference 603, as shown in FIG. 6B, the data referred to by the data 601-1 refers to an invalid memory area, and the Java program 104 does not operate correctly.

このような場合には、Javaプログラム104の処理を続行できないという例外処理(プログラムに本来想定されていなかったエラーが発生した際に、エラーに対応して実行される処理)を実行する方法もあるが、Javaプログラム104を正常に続行させたい場合は、解放対象である外部ヒープメモリ111の解放前にデータ602-1を解放対象ではないJavaヒープメモリ110上に移動させ、データ間の参照関係を修正することによって、外部ヒープメモリ111を解放後も正しくJavaプログラム104の実行を続けることができる。   In such a case, there is a method of executing exception processing (processing executed in response to an error when an error that is not originally assumed in the program occurs) that the processing of the Java program 104 cannot be continued. However, if you want to continue the Java program 104 normally, move the data 602-1 onto the Java heap memory 110 that is not the release target before releasing the external heap memory 111 that is the release target, and change the reference relationship between the data. By correcting, the Java program 104 can be correctly executed even after the external heap memory 111 is released.

Javaプログラム104の正常な実行を保証する処理を含む外部ヒープ解放部109の処理を図7に示す。処理701において、解放対象外のメモリ領域のデータから解放対象メモリ領域のデータへの参照の有無を調査する。処理702においてその有無を判断し、参照がある場合は処理703において、その参照先データを解放対象外メモリに移動させる。その際、移動したデータへの移動元に対する他のデータからの参照を移動先に修正する。処理704において、処理703で移動させたデータが参照するデータを調べ、処理705においてその参照先データが解放対象メモリ内かどうかを判断し、解放対象メモリ内である場合は対象データをその参照先データとして処理703から実行する。逆に、解放対象メモリ外を参照している場合は処理701に戻り、解放対象メモリ領域のデータへの参照の調査を続ける。   FIG. 7 shows the processing of the external heap release unit 109 including processing that guarantees normal execution of the Java program 104. In process 701, the presence / absence of reference from the data in the memory area not to be released to the data in the memory area to be released is checked. In process 702, the presence or absence is determined. If there is a reference, the reference destination data is moved to a non-release target memory in process 703. At that time, the reference from other data to the movement source to the moved data is corrected to the movement destination. In process 704, the data referred to by the data moved in process 703 is examined. In process 705, it is determined whether or not the reference destination data is in the release target memory. The processing is executed from processing 703 as data. On the other hand, if the memory outside the release target memory is being referred to, the process returns to the process 701 and the investigation of the reference to the data in the release target memory area is continued.

全ての解放対象外メモリ領域のデータに対して処理701を適用しても、解放対象メモリのデータへの参照が見つからない場合は、処理702から処理706に進み、対象メモリを解放する。ここで、解放対象メモリ領域は複数であってもよく、その場合は処理701〜705を実行後、処理706で一度に複数の領域を解放する。処理701で調べる解放対象外メモリのデータから解放対象メモリのデータへの参照関係は、GCにおいてプログラムの実行に必要なデータを検出するためにGCルートと呼ばれる場所から指されるデータからたどるデータ間参照関係の一部である可能性がある。よって、この参照関係で参照可能なデータを解放対象外メモリ領域に移動させておけば、GCにおいて実行に必要と判断されるデータは少なくとも移動していることが保証されるため、解放対象メモリの解放後もプログラムの実行を安全に続行することができる。   Even if the process 701 is applied to all the data in the non-release target memory area, if no reference to the data in the release target memory is found, the process proceeds from the process 702 to the process 706 to release the target memory. Here, there may be a plurality of release target memory areas. In this case, after executing the processes 701 to 705, a plurality of areas are released at a time in the process 706. The reference relationship from the data in the memory not to be released to the data in the memory to be released checked in the process 701 is the data between the data pointed from the location called the GC root in order to detect the data necessary for program execution in the GC. May be part of a reference relationship. Therefore, if the data that can be referred to in this reference relationship is moved to the non-release target memory area, it is guaranteed that the data judged to be necessary for execution in the GC is at least moved. Even after release, program execution can continue safely.

図7に示す解放処理を図8(a)に適用すると、まず解放対象外メモリ(Javaヒープ)110上のデータ801-1から解放対象メモリ(外部ヒープ)111上のデータ802-1への参照803が見つかる。よって、処理703においてデータ802-1を解放対象外メモリ110上に移動させてデータ806とし、データ801-1からの参照803を参照807に示すように修正する。データ802-1がデータ806となることにより、参照808が新たに生じる。本処理703後のメモリ上のデータ配置を示したのが図8(b)である。   When the release processing shown in Fig. 7 is applied to Fig. 8 (a), reference is first made from data 801-1 on non-release target memory (Java heap) 110 to data 802-1 on release target memory (external heap) 111 803 is found. Therefore, in the process 703, the data 802-1 is moved to the non-release target memory 110 to be the data 806, and the reference 803 from the data 801-1 is corrected as indicated by the reference 807. Since the data 802-1 becomes the data 806, a reference 808 is newly generated. FIG. 8B shows the data arrangement on the memory after this processing 703.

次に、処理703において移動させたデータの移動元データ802-1から参照するデータを処理704において調べると、参照804をたどることでデータ802-2の存在がわかる。処理705において、データ802-2の所在を確認すると解放対象メモリ111内であることが分かるため、対象データを802-2に変更して処理703を実行する。図8(c)は2回目の処理703の処理後の様子であり、データ802-2が移動してデータ809となり、図8(b)におけるデータ806からデータ802-2への参照808が、参照810として修正されている。また、図8(b)におけるデータ802-2からデータ801-2への参照805は、データ802-2が移動して809となったことによって、参照811となる。   Next, when the data referenced from the movement source data 802-1 of the data moved in the process 703 is examined in the process 704, the existence of the data 802-2 can be found by following the reference 804. In processing 705, if the location of the data 802-2 is confirmed, it is found that it is in the release target memory 111, so the target data is changed to 802-2, and processing 703 is executed. FIG. 8C shows a state after the second processing 703, data 802-2 is moved to data 809, and reference 808 from data 806 to data 802-2 in FIG. Reference 810 has been modified. Further, the reference 805 from the data 802-2 to the data 801-2 in FIG. 8B becomes the reference 811 because the data 802-2 has moved to 809.

図8(c)の状態で、再度処理704及び705を実行するが、データ802-2から参照するデータ801-2は解放対象外メモリ110にあるため、処理701に戻る。2回目の処理701では解放対象メモリへの参照は発見できないため、処理702から処理706に進み、外部ヒープメモリ111を解放する。図8(c)より、外部ヒープメモリ111に対する参照は存在しないため、このメモリ領域111を解放してもプログラムの実行において問題は生じない。また、データ802-2からデータ801-2への参照を表す805については、参照元データ802-2が解放対象外メモリ上のデータから参照されないため、その存在がJavaプログラムのその後の実行に影響を及ぼすことはない。   In the state of FIG. 8C, the processes 704 and 705 are executed again. However, since the data 801-2 referenced from the data 802-2 is in the non-release target memory 110, the process returns to the process 701. Since the reference to the release target memory cannot be found in the second process 701, the process proceeds from process 702 to process 706 to release the external heap memory 111. As shown in FIG. 8 (c), since there is no reference to the external heap memory 111, there is no problem in executing the program even if the memory area 111 is released. In addition, for 805 representing the reference from the data 802-2 to the data 801-2, the reference source data 802-2 is not referenced from the data in the memory not to be released, so its presence affects the subsequent execution of the Java program. Will not affect.

プログラムによって明示的に確保されたメモリ領域の解放処理において、解放対象メモリ内に実行に必要なデータがある場合に、実行に必要なデータを移動させるのではなく、例外処理を実行することもできる。この場合、実行に必要なデータが残存していることを発見した時点で必ず例外処理を実行させることもできるし、領域解放を明示するreclaimメソッドの実行時の動作を図9の文901中のsetReclamationActionメソッドのように指定することもできる。文901では、領域解放時に実行に必要なデータが解放領域内に残存している場合は例外を発生させるという指示である。なお、setReclamationActionメソッドの引数には、例外を発生させる「EXCEPTION」の他に、実行に必要なデータをJavaヒープメモリに移動させる「MOVE_TO_JAVA_HEAP」を記述することができる。   In the process of releasing a memory area explicitly secured by a program, if there is data necessary for execution in the memory to be released, it is possible to execute exception processing instead of moving the data necessary for execution. . In this case, exception processing can always be executed when it is discovered that data necessary for execution remains, and the operation at the time of execution of the reclaim method that explicitly indicates area release is shown in the sentence 901 of FIG. It can also be specified like the setReclamationAction method. The statement 901 instructs to generate an exception when data necessary for execution remains in the release area when the area is released. In addition to “EXCEPTION” that generates an exception, “MOVE_TO_JAVA_HEAP” that moves data required for execution to the Java heap memory can be described in the argument of the setReclamationAction method.

setReclamationActionを利用可能な場合の領域解放処理を図10に示す。処理701で解放対象外メモリ領域内のデータから解放対象メモリ領域内のデータへの参照の有無を調べ、存在する場合は処理702より処理1001に移る。処理1001では、setReclamationActionメソッドでセットされた処理を調べ、EXCEPTIONが指定されていた場合は処理1002において例外を発行し、そうでない場合、つまりJavaヒープメモリ110に必要データを移動させるよう指示されていた場合は図7の処理703に移行する。参照が存在しない場合は処理706で解放対象メモリは解放される。   FIG. 10 shows the area release processing when setReclamationAction can be used. In process 701, the presence or absence of reference to the data in the release target memory area is checked from the data in the non-release target memory area, and if there exists, the process moves from process 702 to process 1001. In process 1001, the process set by the setReclamationAction method is examined, and if EXCEPTION is specified, an exception is issued in process 1002, otherwise it is instructed to move necessary data to the Java heap memory 110 In this case, the processing shifts to processing 703 in FIG. If there is no reference, the memory to be released is released in process 706.

以上の処理により、Javaプログラム上での記述の制限なく、外部ヒープメモリ111の生成、利用、および解放を安全に実行できる。   With the above processing, the generation, use, and release of the external heap memory 111 can be executed safely without restriction of description on the Java program.

101…コンピュータ、102…プロセッサ、103…メモリ、104…Javaプログラム、105…Java仮想マシン、106…Javaプログラム読込み部、107…外部ヒープ生成部、108…外部ヒープへのデータ生成部、109…外部ヒープ解放部、110…Javaヒープメモリ、111…外部ヒープメモリ、112…外部記憶装置。 DESCRIPTION OF SYMBOLS 101 ... Computer, 102 ... Processor, 103 ... Memory, 104 ... Java program, 105 ... Java virtual machine, 106 ... Java program reading part, 107 ... External heap generation part, 108 ... Data generation part to external heap, 109 ... External Heap release unit, 110 ... Java heap memory, 111 ... external heap memory, 112 ... external storage device.

Claims (20)

プロセッサと、メモリとを有するコンピュータのメモリ管理方法であって、
オブジェクトを含む少なくとも一つのスレッドを有するプログラムが、前記コンピュータ内の前記プロセッサで実行されることにより、前記メモリに第2メモリ領域を確保し、
前記プログラムの実行に応じて第1メモリ領域に前記オブジェクトを格納し、
前記第1メモリ領域に格納された前記オブジェクトを、前記第2メモリ領域に移動し、
前記プログラムからの前記第2メモリ領域の解放指示に応じて、前記スレッドの以降の実行で必要なオブジェクトが、前記第2メモリ領域に存在するか否かを判断し、
前記判断の結果、前記スレッドの以降の実行に必要なオブジェクトが前記第2メモリ領域に存在しない場合、前記第2メモリ領域を解放し、
前記スレッドの以降の実行に必要なオブジェクトが前記第2メモリ領域に存在する場合、前記第2メモリ領域に存在する、前記スレッドの以降の実行に必要なオブジェクトを前記解放指示の対象外のメモリ領域に移動させ、前記第2メモリ領域を解放するメモリ管理方法。
A memory management method for a computer having a processor and a memory,
A program having at least one thread including an object is executed by the processor in the computer, thereby securing a second memory area in the memory,
Storing the object in a first memory area in response to execution of the program;
Moving the object stored in the first memory area to the second memory area;
In response to an instruction to release the second memory area from the program, it is determined whether or not an object necessary for subsequent execution of the thread exists in the second memory area;
As a result of the determination, if an object necessary for subsequent execution of the thread does not exist in the second memory area, the second memory area is released,
When an object necessary for subsequent execution of the thread is present in the second memory area, an object required for subsequent execution of the thread is excluded from the memory area that is not subject to the release instruction. And a memory management method for releasing the second memory area.
請求項1に記載のメモリ管理方法であって、
前記第1メモリ領域におけるガベージコレクションの発生に応じて、前記第1メモリ領域に格納された前記オブジェクトを、前記第2メモリ領域に移動するメモリ管理方法。
The memory management method according to claim 1, comprising:
A memory management method for moving the object stored in the first memory area to the second memory area in response to occurrence of garbage collection in the first memory area.
請求項1又は2に記載のメモリ管理方法であって、前記解放指示の対象外の前記メモリ領域が、ガベージコレクションの対象であるメモリ管理方法。   The memory management method according to claim 1, wherein the memory area that is not the target of the release instruction is a target of garbage collection. 請求項1から3の何れか一項に記載のメモリ管理方法であって、
前記解放指示の対象外の前記メモリ領域は、前記第1メモリ領域を含むメモリ管理方法。
A memory management method according to any one of claims 1 to 3, wherein
The memory management method, wherein the memory area not subject to the release instruction includes the first memory area.
請求項1から4の何れか一項に記載のメモリ管理方法であって、
前記スレッドの以降の実行に必要なオブジェクトは、前記解放指示の対象外の前記メモリ領域に格納されたオブジェクトから参照されるものであるメモリ管理方法。
A memory management method according to any one of claims 1 to 4, comprising:
The memory management method, wherein an object necessary for subsequent execution of the thread is referred to by an object stored in the memory area not subject to the release instruction.
請求項1から5の何れか一項に記載のメモリ管理方法であって、
前記解放指示の対象外の前記メモリ領域に移動したオブジェクトが参照するオブジェクトが前記第2メモリ領域に存在するとき、該参照されるオブジェクトも前記解放指示の対象外の前記メモリ領域へ移動するメモリ管理方法。
A memory management method according to any one of claims 1 to 5,
Memory management in which when the object referred to by the object moved to the memory area not subject to the release instruction is present in the second memory area, the referenced object is also moved to the memory area not subject to the release instruction Method.
請求項1から6の何れか一項に記載のメモリ管理方法であって、
前記プログラムによる指示に応答して、前記第2メモリ領域に存在する前記オブジェクトを前記解放指示の対象外の前記メモリ領域に移動するメモリ管理方法。
A memory management method according to any one of claims 1 to 6, comprising:
A memory management method for moving the object existing in the second memory area to the memory area not subject to the release instruction in response to an instruction by the program.
オブジェクトを含む少なくとも一つのスレッドを有するプログラムが、コンピュータ内のプロセッサにより実行されることにより前記コンピュータ内に確保される第2メモリ領域を提供するメモリと、
前記プログラムの実行に応じて前記オブジェクトが格納される第メモリ領域と、
前記プログラムによる前記第2メモリ領域の解放指示に応答して、前記スレッドの以降の実行に必要なオブジェクトが前記第2メモリ領域に存在するか否かをチェックし、
前記チェックの結果、前記スレッドの以降の実行に必要なオブジェクトが前記第2メモリ領域に存在しないとき、前記第2メモリ領域を解放し、
前記チェックの結果、前記スレッドの以降の実行に必要なオブジェクトが前記第2メモリ領域に存在するとき、前記第2メモリ領域に存在する、前記スレッドの以降の実行に必要なオブジェクトを前記解放指示の対象外のメモリ領域へ移動し、前記第2メモリ領域を解放する前記プロセッサとを有するコンピュータ。
A memory that provides a second memory area secured in the computer by a program having at least one thread including an object being executed by a processor in the computer;
A first memory area in which the object is stored in response to execution of the program;
In response to an instruction to release the second memory area by the program, it is checked whether or not an object necessary for subsequent execution of the thread exists in the second memory area;
As a result of the check, when an object necessary for subsequent execution of the thread does not exist in the second memory area, the second memory area is released,
As a result of the check, when an object required for subsequent execution of the thread exists in the second memory area, an object required for subsequent execution of the thread existing in the second memory area is set in the release instruction. A computer having the processor that moves to a non-target memory area and releases the second memory area.
請求項8に記載のコンピュータであって、前記プロセッサは、
前記第1メモリ領域におけるガベージコレクションの発生に応じて、前記第1メモリ領域に格納された前記オブジェクトを、前記第2メモリ領域に移動するコンピュータ。
9. The computer of claim 8, wherein the processor is
A computer that moves the object stored in the first memory area to the second memory area in response to occurrence of garbage collection in the first memory area.
請求項8又は9に記載のコンピュータであって、前記解放指示の対象外のメモリ領域が、ガベージコレクションの対象であるコンピュータ。   10. The computer according to claim 8, wherein the memory area that is not subject to the release instruction is a garbage collection target. 請求項8から10の何れか一項に記載のコンピュータであって、
前記解放指示の対象外のメモリ領域は、前記第1メモリ領域を含むコンピュータ。
A computer according to any one of claims 8 to 10,
The memory area that is not subject to the release instruction includes the first memory area.
請求項8から11の何れか一項に記載のコンピュータであって、
前記スレッドの以降の実行に必要なオブジェクトは、前記解放指示の対象外の前記メモリ領域に格納されたオブジェクトから参照されるものであるコンピュータ。
A computer according to any one of claims 8 to 11, comprising:
An object required for subsequent execution of the thread is referred to by an object stored in the memory area that is not subject to the release instruction.
請求項8から12の何れか一項に記載のコンピュータであって、前記プロセッサは、
前記解放指示の対象外の前記メモリ領域に移動したオブジェクトが参照するオブジェクトが前記第2メモリ領域に存在するとき、該参照されるオブジェクトも前記解放指示の対象外の前記メモリ領域へ移動するコンピュータ。
The computer according to any one of claims 8 to 12, wherein the processor is
A computer in which, when an object referred to by an object moved to the memory area not subject to the release instruction is present in the second memory area, the referenced object is also moved to the memory area not subject to the release instruction.
請求項8から13の何れか一項に記載のコンピュータであって、前記プロセッサは、
前記プログラムによる指示に応答して、前記第2メモリ領域に存在する前記オブジェクトを前記解放指示の対象外の前記メモリ領域に移動するコンピュータ。
The computer according to any one of claims 8 to 13, wherein the processor is
In response to an instruction from the program, the computer moves the object existing in the second memory area to the memory area not subject to the release instruction.
オブジェクトを含む少なくとも一つのスレッドを有するプログラムであって、
コンピュータに、
前記プログラムの指示に応じて第2メモリ領域を確保させる第1の手順と、
前記プログラムの実行に応じて第1メモリ領域に前記オブジェクトを格納させる第2の手順と、
前記第1メモリ領域に格納された前記オブジェクトを、前記第2メモリ領域に移動させる第3の手順と、
前記プログラムからの前記第2メモリ領域の解放指示に応じて、前記スレッドの以降の実行で必要なオブジェクトが、前記第2メモリ領域に存在するか否かを判断させる第4の手順と、
前記判断の結果、前記スレッドの以降の実行に必要なオブジェクトが前記第2メモリ領域に存在しない場合、前記第2メモリ領域を解放させる第5の手順と、
前記スレッドの以降の実行に必要なオブジェクトが前記第2メモリ領域に存在する場合、前記第2メモリ領域に存在する、前記スレッドの以降の実行に必要なオブジェクトを前記解放指示の対象外のメモリ領域に移動させ、前記第2メモリ領域を解放させる第6の手順と、を実行させるプログラム。
A program having at least one thread containing an object,
On the computer,
A first procedure for securing a second memory area in accordance with an instruction of the program;
A second procedure for storing the object in a first memory area in accordance with execution of the program;
A third procedure for moving the object stored in the first memory area to the second memory area;
A fourth procedure for determining whether an object required for subsequent execution of the thread exists in the second memory area in response to an instruction to release the second memory area from the program;
As a result of the determination, if an object necessary for subsequent execution of the thread does not exist in the second memory area, a fifth procedure for releasing the second memory area;
When an object necessary for subsequent execution of the thread is present in the second memory area, an object required for subsequent execution of the thread is excluded from the memory area that is not subject to the release instruction. And a sixth procedure for releasing the second memory area.
請求項15に記載のプログラムであって、
前記第1メモリ領域におけるガベージコレクションの発生に応じて、前記第3の手順を実行させるプログラム。
The program according to claim 15,
A program for executing the third procedure in response to occurrence of garbage collection in the first memory area.
請求項15又は1に記載のプログラムであって、
前記第6の手順で、ガベージコレクションの対象であり、前記解放指示の対象外の前記メモリ領域に、前記スレッドの以降の実行に必要なオブジェクトを移動させ、前記第2メモリ領域を解放させるプログラム。
The program according to claim 15 or 16 ,
In the sixth procedure, a program that moves an object necessary for subsequent execution of the thread to a memory area that is a target of garbage collection and that is not a target of the release instruction, and releases the second memory area.
請求項15から17の何れか一項に記載のプログラムであって、
前記第6の手順で、前記第1メモリ領域を含む、前記解放指示の対象外の前記メモリ領域に、前記スレッドの以降の実行に必要なオブジェクトを移動させ、前記第2メモリ領域を解放させるプログラム。
A program according to any one of claims 15 to 17,
In the sixth procedure, a program for moving an object necessary for subsequent execution of the thread to the memory area that is not subject to the release instruction, including the first memory area, and releasing the second memory area .
請求項15から18の何れか一項に記載のプログラムであって、
前記第4の手順で、前記第2メモリ領域以外に格納されたオブジェクトから参照されるオブジェクトを、前記スレッドの以降の実行に必要オブジェクトとして、前記第2メモリ領域に存在するか否かを判断させるプログラム。
A program according to any one of claims 15 to 18, comprising:
In the fourth procedure, it is determined whether or not an object referenced from an object stored outside the second memory area exists in the second memory area as an object necessary for subsequent execution of the thread. program.
請求項15から19の何れか一項に記載のプログラムであって、
前記第6の手順で、
前記解放指示の対象外の前記メモリ領域に移動させたオブジェクトが参照するオブジェクトが前記第2メモリ領域に存在するとき、該参照されるオブジェクトも前記解放指示の対象外の前記メモリ領域へ移動させ、前記第2メモリ領域を解放させるプログラム。
A program according to any one of claims 15 to 19,
In the sixth procedure,
When an object referred to by the object moved to the memory area not subject to the release instruction is present in the second memory area, the referenced object is also moved to the memory area not subject to the release instruction, A program for releasing the second memory area.
JP2012175538A 2012-08-08 2012-08-08 Memory management method, computer and program Active JP5564540B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2012175538A JP5564540B2 (en) 2012-08-08 2012-08-08 Memory management method, computer and program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2012175538A JP5564540B2 (en) 2012-08-08 2012-08-08 Memory management method, computer and program

Related Parent Applications (1)

Application Number Title Priority Date Filing Date
JP2007203288A Division JP5064134B2 (en) 2007-08-03 2007-08-03 Memory management method and computer using the method

Related Child Applications (1)

Application Number Title Priority Date Filing Date
JP2014123044A Division JP5756549B2 (en) 2014-06-16 2014-06-16 Storage area management method, computer system, and program

Publications (2)

Publication Number Publication Date
JP2012234567A JP2012234567A (en) 2012-11-29
JP5564540B2 true JP5564540B2 (en) 2014-07-30

Family

ID=47434750

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2012175538A Active JP5564540B2 (en) 2012-08-08 2012-08-08 Memory management method, computer and program

Country Status (1)

Country Link
JP (1) JP5564540B2 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB2502076A (en) 2012-05-15 2013-11-20 Ibm Managing memory in a computer system
JP6011329B2 (en) * 2012-12-28 2016-10-19 日本電気株式会社 PROGRAM GENERATION DEVICE, PROGRAM GENERATION METHOD, AND COMPUTER PROGRAM

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH02216550A (en) * 1989-02-17 1990-08-29 Hitachi Ltd System for controlling mains storage area
JPH11345166A (en) * 1998-06-02 1999-12-14 Hitachi Ltd Method for memory use
JP3939975B2 (en) * 2001-12-14 2007-07-04 松下電器産業株式会社 Garbage collection apparatus, garbage collection method, and garbage collection program
JP2003241967A (en) * 2002-02-15 2003-08-29 Matsushita Electric Ind Co Ltd Program execution device, its method and program executed therein
JP2007086838A (en) * 2005-09-20 2007-04-05 National Institute Of Advanced Industrial & Technology Communication mediation device for zero garbage collection

Also Published As

Publication number Publication date
JP2012234567A (en) 2012-11-29

Similar Documents

Publication Publication Date Title
JP5064134B2 (en) Memory management method and computer using the method
JP5153539B2 (en) Memory management method and computer using the method
Joshi et al. CalFuzzer: An extensible active testing framework for concurrent programs
CN107257959B (en) System and method for garbage collection control in managed code
EP3577565B1 (en) Garbage collector
EP3084598B1 (en) Execution guards in dynamic programming
Genç et al. Dependence-aware, unbounded sound predictive race detection
JP5281452B2 (en) Memory management method, computer, and memory management program
US20120198184A1 (en) Memory management method, computer system and computer readable medium
JP5564540B2 (en) Memory management method, computer and program
JP5380695B2 (en) Memory management method, computer system, and memory management program
JP2006172495A (en) Program control apparatus and method, and program recording medium
Middha et al. Mtss: Multitask stack sharing for embedded systems
JP5756549B2 (en) Storage area management method, computer system, and program
US7549045B2 (en) Delegate registration in a managed code execution environment
Jones et al. A fast analysis for thread-local garbage collection with dynamic class loading
JP2006185456A (en) Memory allocation device, memory allocation method and program recording medium
US9501314B2 (en) Reducing aborts caused by a runtime helper called during execution of a transaction block
Stilkerich et al. A practical getaway: Applications of escape analysis in embedded real-time systems
Vitásek et al. Shadowdata: Shadowing heap objects in java
Gherghina et al. A specification logic for exceptions and beyond
Higuera-Toledano Studying the behaviour of the single parent rule in real-time Java
Iqbal et al. A comparative study of garbage collection techniques in java virtual machines
Rios et al. Reusable Libraries for Safety-Critical Java
Kulkarni 4.14 Efficiently detecting cross-thread dependences to enforce stronger memory models

Legal Events

Date Code Title Description
A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20130909

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20130924

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20131118

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20131210

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20140207

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20140304

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20140424

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20140520

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20140616

R150 Certificate of patent (=grant) or registration of utility model

Ref document number: 5564540

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150