JP2006185456A - Memory allocation device, memory allocation method and program recording medium - Google Patents

Memory allocation device, memory allocation method and program recording medium Download PDF

Info

Publication number
JP2006185456A
JP2006185456A JP2006021497A JP2006021497A JP2006185456A JP 2006185456 A JP2006185456 A JP 2006185456A JP 2006021497 A JP2006021497 A JP 2006021497A JP 2006021497 A JP2006021497 A JP 2006021497A JP 2006185456 A JP2006185456 A JP 2006185456A
Authority
JP
Japan
Prior art keywords
area
size
memory
allocation
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.)
Granted
Application number
JP2006021497A
Other languages
Japanese (ja)
Other versions
JP4345748B2 (en
Inventor
Mitsuaki Hirono
光明 廣野
Kazuyuki Inui
和志 乾
Yoshiharu Konaka
義治 小中
Hiroshi Kuribayashi
博 栗林
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.)
Omron Corp
Original Assignee
Omron Corp
Omron Tateisi Electronics Co
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 Omron Corp, Omron Tateisi Electronics Co filed Critical Omron Corp
Priority to JP2006021497A priority Critical patent/JP4345748B2/en
Publication of JP2006185456A publication Critical patent/JP2006185456A/en
Application granted granted Critical
Publication of JP4345748B2 publication Critical patent/JP4345748B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Abstract

<P>PROBLEM TO BE SOLVED: To eliminate the compaction and to increase the use efficiency of a memory. <P>SOLUTION: This memory allocation device is provided with a characteristic detection means for detecting characteristics of an object generated in a heap area of the memory and an allocation determination means for determining allocation of the object to the heap area according to the characteristics detected by the characteristic detection means. Thus, allocation of the object to the heap area according to size and lifetime of the object, etc. and the user efficiency of the memory is improved. <P>COPYRIGHT: (C)2006,JPO&NCIPI

Description

この発明は、コンピュータのメモリ割当装置、メモリ割当方法、およびプログラム記録媒体に関する。   The present invention relates to a computer memory allocation device, a memory allocation method, and a program recording medium.

先ず、本願発明の明細書において用いる各種用語の定義を以下に示す。尚、出典記号は次のとおりである。   First, definitions of various terms used in the specification of the present invention are shown below. The source symbols are as follows.

JIS:JIS工業用語大辞典第4版(日本規格協会刊)
参1:情報技術用語事典(オーム社刊)
参2:情報処理用語大事典(オーム社刊)
参3:先端ソフトウエア用語事典(オーム社刊)
参A:SUPER ASCII Glossary Help on Internet
JIS: JIS Industrial Glossary Dictionary 4th Edition (published by Japanese Standards Association)
Reference 1: Information Technology Glossary (Ohm)
Reference 2: Encyclopedia of information processing terms (Ohm Publishing)
Reference 3: Advanced Software Glossary (Ohm)
Reference A: SUPER ASCII Glossary Help on Internet

(1) プロセス(process) :
処理や過程を意味する一般用語(参2)
(2) スレッド(thread):
プロセスまたはタスクと呼ばれる1つの実行環境の中で並列実行可能な処理を複数に分割した場合に、プロセッサのスケジュール対象となる実行単位または制御フローのこと。(参3)
(3) コンテキスト(context) :
(オブジェクト指向システムに関連して)メソッドを実行するために必要な情報を蓄えるオブジェクトをいう。コンテキストは、呼び出し先のコンテキスト、プログラムの入ったメソッドオブジェクト、プログラムカウンタ、スタックポインタという情報、引数や一時変数を取るところ、および評価スタックから成立する。このような実行環境をオブジェクトとしてとるが、プロセスなどをサポートする高級言語の特徴でヒープ言語と呼ばれる。他方PASCALやALGOL60では実行環境はスタックにとられFORTRANでは固定領域にとられる。(参1)
(4) タスク(task):
多重プログラミング又は多重プロセッシングの環境において、計算機によって実行されるべき仕事の要素として制御プログラムによって取り扱われる命令の1つ以上の列(JIS)
(5) ガベージ(garbage) :
どこからも参照されていないが、生成されてしまったオブジェクト。ガベージはガベージコレクタで回収する。(参1)
(6) ガベージコレクション(Garbage Collection):
(オブジェクト指向システムに関連して)メモリ管理の中心となるプログラムを言う。主記憶を使いきるとメインの計算を止め、ガベージコレクタを動かして、もはや使われていないオブジェクトを全部集める方法である。この方法でガベージコレクタが働くと、計算が止まってしまうため入出力が全く反応しなくなり、実時間の応答が必要な用途には使えない。(参1)
(7) インタプリタ(interpreter) :
解釈実行を行う翻訳プログラム(JIS)
(8) リアルタイム(real time) :
計算機外部の他の処理との関係をもちながら、かつ外部の処理によって定められる時間要件に従って、計算機の行うデータの処理に関する用語。実時間。(JIS)
(9) オブジェクト(object):
プロシジュア(定義した手続き)とデータの特性を結合させるエンティティ(実体)であり、これにより計算が行われ、局部的状態が蓄えられる。(参1)
(10) クラス(class) :
同一の手続き群とデータ構造を持つオブジェクトの集合。(参3)
(11) ヒープ領域(heap area) :
プログラム実行時に必要に応じて使用されるような作業領域。(参2)
(12) スケジュールする(scheduling):
ディスパッチされるべきジョブ又はタスクを選択すること。(JIS)
(13) イベント(event) :
ハードウエア/ソフトウエアが、自分自身の状態の変化を他のハードウエア/ソフトウエアに通知すること。一般にこの際の通知では、イベントの種類やハードウエア/ソフトウエアの状態を表す各種パラメータをメッセージとしてまとめ、相手に送信する。そしてイベントの通知を受けた側では、メッセージのパラメータなどから適切な処理を行う。(参A)
(14) イベントフラグ(event flag):
タスクが1つまたは複数の事象の発生を待ち合わせるための機能とその事象を通知する機能とからなるタスク間同期通信機構。(参3)
(15) セマフォ(semaphore) :
複数のプロセスやタスクを並列に処理するシステムで、各プロセス間,タスク間の同期やメッセージ制御、割込処理を行うための仕組み。(参3)
(16) 仮想マシーン(仮想機械)(virtual mathine) :
複数の特定のプラットホーム(OSやハードウエア)に組み込まれた、特定のプラットホームに依存しないアプリケーションプログラムを実行する環境。同じ仮想マシンさえ提供されていれば、プラットホームが変わっても同じアプリケーションプログラムが実行できる。
(1) Process:
General terms that mean processes and processes (Ref. 2)
(2) Thread:
An execution unit or control flow that is a target of a processor schedule when a process that can be executed in parallel in a single execution environment called a process or task is divided into a plurality of processes. (Reference 3)
(3) Context:
An object that stores the information needed to execute a method (in connection with an object-oriented system). The context consists of the context of the call destination, the method object containing the program, the program counter, the information of the stack pointer, the place to take arguments and temporary variables, and the evaluation stack. Although such an execution environment is taken as an object, it is called a heap language because it is a feature of a high-level language that supports processes and the like. On the other hand, in the case of PASCAL and ALGOL 60, the execution environment is taken in a stack, and in FORTRAN, it is taken in a fixed area. (Reference 1)
(4) task:
One or more sequences of instructions (JIS) that are handled by a control program as an element of work to be performed by a computer in a multiprogramming or multiprocessing environment
(5) Garbage:
An object that has not been referenced anywhere but has been created. Garbage is collected at the garbage collector. (Reference 1)
(6) Garbage Collection:
A program that is central to memory management (in relation to object-oriented systems). When the main memory is used up, the main calculation is stopped and the garbage collector is moved to collect all objects that are no longer used. If the garbage collector works in this way, the calculation stops and the input / output does not respond at all, and it cannot be used for applications that require real-time response. (Reference 1)
(7) Interpreter:
Translation program (JIS) that performs interpretation
(8) Real time:
Term related to processing of data performed by a computer in accordance with time requirements determined by external processing while having a relationship with other processing outside the computer. Real time. (JIS)
(9) Object:
An entity that combines a procedure (defined procedure) with the characteristics of the data, which performs calculations and stores the local state. (Reference 1)
(10) Class:
A collection of objects with the same set of procedures and data structures. (Reference 3)
(11) Heap area:
A work area that is used as needed during program execution. (Reference 2)
(12) Scheduling:
Selecting a job or task to be dispatched. (JIS)
(13) Event:
The hardware / software notifies other hardware / software of changes in its own state. In general, in this notification, various parameters representing the type of event and the state of hardware / software are collected as a message and transmitted to the other party. The side receiving the event notification performs appropriate processing based on the message parameters. (Reference A)
(14) Event flag:
An inter-task synchronous communication mechanism comprising a function for a task to wait for the occurrence of one or more events and a function for notifying the event. (Reference 3)
(15) Semaphore:
A system that processes multiple processes and tasks in parallel, and performs synchronization, message control, and interrupt processing between processes and tasks. (Reference 3)
(16) Virtual machine (virtual mathine):
An environment for executing application programs that are incorporated in a plurality of specific platforms (OS and hardware) and do not depend on a specific platform. As long as the same virtual machine is provided, the same application program can be executed even if the platform changes.

(17) Java VM(Java Virtual Machine) (JavaはSun Microsystems社の商標):
オペレーティングシステムに組み込まれた、Javaアプリケーションプログラム(JavaはSun Microsystems社の商標)を実行するための環境。一般的なプログラムは、ソースコードをコンパイルして、それぞれのオペレーティングシステムに最適化した実行コードを生成する、というスタイルを採る。Java(JavaはSun Microsystems社の商標)で書かれたプログラムも同様の手順で作成するが、コンパイル後のコードは、特定のオペレーティングシステムに依存しない中間コードの形をとる。これをロードし、各オペレーティングシステムに合わせたコードに変換しながら実行するのがJava仮想マシン(JavaはSun Microsystems社の商標)の役目であり、同じ仮想マシンさえ提供されていれば、プラットホームが変わっても同じコードが実行できるようになっている。
(17) Java VM (Java Virtual Machine) (Java is a trademark of Sun Microsystems):
An environment for executing a Java application program (Java is a trademark of Sun Microsystems) incorporated in an operating system. A general program takes the style of compiling source code and generating executable code optimized for each operating system. A program written in Java (Java is a trademark of Sun Microsystems) is also created in the same procedure, but the compiled code takes the form of intermediate code that does not depend on a specific operating system. It is the role of the Java virtual machine (Java is a trademark of Sun Microsystems, Inc.) that loads it and executes it while converting it into code suitable for each operating system. If the same virtual machine is provided, the platform will change. However, the same code can be executed.

(18) フリー領域(free area) :
ヒープ領域上の使用可能な領域、未使用領域。
(18) Free area:
Available and unused area on the heap area.

(19) ノーマルスレッド(normal thread) :
リアルタイム性が要求されない処理を行うスレッド。
(19) Normal thread:
A thread that performs processing that does not require real-time performance.

(20) マークテーブル(mark table):
オブジェクトがどこからも参照されないか否かを調べるために存在するオブジェクトに1対1に対応する表。或るオブジェクトに参照があることが確かめられた場合、そのオブジェクトに対応する表の欄にマークを付ける。全ての参照関係を調べたときマークの無いオブジェクトは不要であるので取り除くことができる。
(20) Mark table:
A table that has a one-to-one correspondence with objects that exist to check whether an object is not referenced from anywhere. When it is confirmed that a certain object has a reference, the table column corresponding to the object is marked. When all the reference relationships are examined, the object without the mark is unnecessary and can be removed.

(21) オブジェクトの寿命(life time of the object) :
オブジェクトが生成され、消去されるまでの時間。
(21) Life time of the object:
The time until an object is created and deleted.

(22) ライトバリア(write barrier) :
オブジェクトへの参照関係の変更をチェックし、書き替えが起こった場合に何らかの処理をすること。本件の場合は、書き替えが起きたとき、書き替える参照が指しているオブジェクトに対応するマークテーブルの欄にマークを付ける。
(22) Write barrier:
Check for changes in the reference relationship to an object, and do some processing when rewriting occurs. In this case, when rewriting occurs, a mark is placed in the mark table column corresponding to the object to which the reference to be rewritten points.

(23) スイープ(sweeping):
ヒープ領域上の不要なオブジェクトを取り除く処理。
(23) sweeping:
Processing to remove unnecessary objects on the heap area.

(24) オブジェクト生成(create the object) :
新しいオブジェクトを生成すること。具体的には、ヒープ領域の一部をオブジェクトに割り当て、内容を初期化すること。
(24) Create the object:
Create a new object. Specifically, allocate a part of the heap area to the object and initialize the contents.

(25) オブジェクト消去(delete the object) :
不要なオブジェクトを取り除くこと。具体的には、ヒープ領域に確保してある領域を解放すること。
(25) Delete the object:
Remove unnecessary objects. Specifically, release the area secured in the heap area.

(26) 参照(reference) :
或るオブジェクトAが別の特定のオブジェクトBにアクセスするためにオブジェクトBを特定する情報。具体的には、オブジェクトBを指すポインタまたはインデックス。
(26) Reference:
Information that identifies an object B in order for one object A to access another specific object B. Specifically, a pointer or index pointing to the object B.

(27) 参照変更(chenge the reference / reconnect the reference) :
参照を現在のオブジェクトBから別のオブジェクトCに変更すること。
(27) Change the reference (change the reference / reconnect the reference):
Changing the reference from the current object B to another object C.

さて、従来のシングルプロセッサのコンピュータシステムにおいて、オペレーティングシステム上で複数のスレッドを並行処理する場合、共有メモリを用いて排他制御するために、また複数のタスク間で同期をとるために、従来よりセマフォやイベントフラグなどを用いて排他制御が行われている。   In a conventional single processor computer system, when a plurality of threads are processed in parallel on an operating system, a semaphore is conventionally used for exclusive control using a shared memory and for synchronization between a plurality of tasks. Exclusive control is performed using event flags and the like.

また、例えばプログラムを少量のメモリ環境下で動作させることなどを目的として、仮想記憶を行わないで単一のアドレス空間のメモリをプログラムの実行時に動的に割り当てる、いわゆる動的記憶管理が従来より行われている。このような動的記憶管理によれば、プログラムにより明示的にメモリ領域の解放を行わなければ、プログラムの実行過程において使用されなくなったメモリ領域が発生する。その結果、プログラムが使用できるフリー領域が次第に不足する。こうした問題を回避するために、使用されなくなったメモリ領域(ガベージ)を抽出し、これらを集めて(コレクトして)再び使用可能なフリー領域とする、ガベージコレクションと呼ばれる処理を自動的に行うようにしている。   In addition, so-called dynamic storage management, which dynamically allocates memory in a single address space at the time of program execution without performing virtual storage, for example, for the purpose of operating a program in a small amount of memory environment, has been conventionally performed. Has been done. According to such dynamic storage management, unless the memory area is explicitly released by the program, a memory area that is no longer used in the program execution process is generated. As a result, the free area that the program can use gradually becomes insufficient. In order to avoid these problems, a memory area (garbage) that is no longer used is extracted and collected (collected) to make it a free area that can be used again automatically. I have to.

ここで従来のガベージコレクションの処理手順をフローチャートとして図54に示す。ガベージコレクションのアルゴリズムにはマーク&スイープ法、複写法、参照カウント法などの各種方法が考えられているが、ここではマーク&スイープ法について例示する。図54に示すように、まずガベージコレクションの途中でガベージコレクションスレッド以外の他のスレッドが実行されないように割り込みを禁止し、シングルスレッドモードにする(s201)。続いてメモリ上のガベージコレクションの対象となる領域(以下「ヒープ領域」という。)に割り当てられているオブジェクトにそれぞれ対応するマークの記憶領域(以下「マークテーブル」という。)をクリアする(s202)。続いてヒープ領域内に割り当てられているオブジェクトの参照関係を示す情報を基に何れかのオブジェクから参照されているオブジェクトを検出し、それらに対応するマークテーブル上の位置にマークを付ける処理を行う(s203)。この処理により、何れのオブジェクトからも参照されていないオブジェクトはもはや使われなくなったオブジェクトであり、それに相当するマークテーブルにはマークが付けられないことになる。従ってそのマークしていないオブジェクトを新たなオブジェクトの割当可能な領域、すなわちフリー領域として抽出する(s204)。例えばこのフリー領域をリスト構造のデータとして生成する。その後、割り込み禁止を解除し、マルチスレッドのモードに戻す(s205)。   FIG. 54 is a flowchart showing a conventional garbage collection processing procedure. Various methods such as a mark & sweep method, a copying method, and a reference counting method are considered as the garbage collection algorithm. Here, the mark & sweep method is exemplified. As shown in FIG. 54, first, interrupts are prohibited so that no thread other than the garbage collection thread is executed during the garbage collection, and the single thread mode is set (s201). Subsequently, the mark storage areas (hereinafter referred to as “mark tables”) respectively corresponding to the objects allocated to the garbage collection target areas (hereinafter referred to as “heap areas”) are cleared (s202). . Subsequently, an object referenced from any object is detected based on information indicating the reference relationship of the objects allocated in the heap area, and a mark processing is performed on a mark table corresponding to the detected object. (s203). By this process, an object that is not referenced by any object is an object that is no longer used, and a mark table corresponding to the object is not marked. Therefore, the unmarked object is extracted as a new object assignable area, that is, a free area (s204). For example, this free area is generated as list structure data. Thereafter, the interrupt prohibition is canceled and the multi-thread mode is restored (s205).

従来はこのようなガベージコレクションが、メモリのフリー領域が所定量まで減少した時点で自動的に起動されるようにしていた。   Conventionally, such garbage collection is automatically started when the free area of the memory is reduced to a predetermined amount.

また、ガベージコレクションを行ったとき、任意の大きさ(メモリサイズ)のオブジェクトが任意に解放されるのでフラグメントが発生する。そこで、連続したサイズの大きな領域がとれるように、オブジェクトの割当領域を例えば先頭から順次詰めるメモリコンパクション(以下単に「コンパクション」という。)を実行していた。   Further, when garbage collection is performed, an object having an arbitrary size (memory size) is arbitrarily released, so that a fragment is generated. In view of this, memory compaction (hereinafter simply referred to as “compaction”) in which the object allocation areas are sequentially packed from the top, for example, is performed so that a continuous large area can be obtained.

ここで、先行技術調査を行った際に発見した文献について示しておく。   Here, the literature discovered when conducting the prior art search is shown.

(1) Incremental Garbage Collection of Concurrent Objects for Real-Time Application
この論文はBaker が書いたという1978年のリアルタイムGCに対して、全体の処理時間から必要なGCの処理時間の割合を求めるものである。
(1) Incremental Garbage Collection of Concurrent Objects for Real-Time Application
This paper calculates the ratio of the required GC processing time from the total processing time for the 1978 real-time GC written by Baker.

(2) Distributed Garbage Collection for the Parallel Inference Machine:PIE64
GCを行う領域を細かく分けることにより、個々の処理時間を短くしてリアルタイム性を向上する方法であり、全ての領域を対象にするものではない。また、スケジューリングについては述べられていない。
(2) Distributed Garbage Collection for the Parallel Inference Machine: PIE64
This is a method of improving the real-time property by shortening the individual processing time by finely dividing the area where GC is performed, and does not cover all areas. Further, scheduling is not described.

(3) Garbage Collection in Distributed Enviroment
Baker の考えを発展させ、ネットワークの分散環境に適応したもの。ネットワーク固有の問題を解決しようとするものである。
(3) Garbage Collection in Distributed Enviroment
An evolution of Baker's idea adapted to a distributed network environment. It tries to solve network specific problems.

(4) 特開平1−220039号
システムコール発行時に、そのシステムコールにより起動されるタスクの優先度を制御するものである。
(4) When a system call is issued, the priority of a task activated by the system call is controlled.

(5) 特開平3−231333号
オブジェクトのサイズを検出し、そのサイズに応じてワークエリアをメモリに確保することが一応示されている。
(5) Japanese Patent Application Laid-Open No. Hei 3-231333 It is once shown that the size of an object is detected and a work area is secured in a memory according to the size.

(6) 電子情報通信学会誌Vol.80 No.6 pp586-592
マルチメディアオペレーティングシステムのコンセプトが示されている。
(6) IEICE Vol.80 No.6 pp586-592
The concept of multimedia operating system is shown.

(7) 日本ソフトウェア科学会第12回D7−4
スタック上のオブジェクトの一番上にオブジェクトの大きさを書いておくことが示されている。
(7) Japan Software Science Society 12th D7-4
It is shown that the size of the object is written at the top of the object on the stack.

(8) 11TH Real-Time System Symposium "Incremental Garbage Collection of Concurrent Object for Real-Time Applications"
オブジェクト間の参照ツリーの考え方が示されている。
(8) 11TH Real-Time System Symposium "Incremental Garbage Collection of Concurrent Object for Real-Time Applications"
The idea of a reference tree between objects is shown.

(9) 情報処理学会第38回全国大会5U-7
オブジェクトの寿命に関連してメモリ割当を行うことが示されている。
(9) Information Processing Society of Japan 38th National Convention 5U-7
It has been shown that memory allocation is made in relation to the lifetime of the object.

(10)Lecture Notes in Computer Science 259 "Garbage Collection in a Distributed Environment"
アプリケーションプログラムインタフェースの呼出に応じてGCを制御することと、オブジェクト参照に関する技術思想が示されている。
(10) Lecture Notes in Computer Science 259 "Garbage Collection in a Distributed Environment"
The technical idea about controlling the GC according to the call of the application program interface and the object reference is shown.

上述した排他制御の機能をセマフォやイベントフラグなどのコンピュータ資源を用いることで実現している従来のシステムにおいては、その資源が他のスレッドなどで使用されている場合には、他のスレッドはその資源が解放されるのを待たなければならない。このような資源待ちの時間が生じると、リアルタイム性の要求されるシステムにおいては大きな障害となる。すなわち、資源待ち状態にあるスレッドは、その資源が解放されるまで、処理できずリアルタイムな応答が不可能となる。   In a conventional system that implements the exclusive control function described above by using computer resources such as semaphores and event flags, when the resource is used by another thread, the other thread You have to wait for the resources to be released. When such a resource waiting time occurs, it becomes a major obstacle in a system that requires real-time performance. In other words, a thread in a resource waiting state cannot process until the resource is released and cannot respond in real time.

例えば上記従来のガベージコレクション(以下「GC」という。)の方法によれば、メモリ空間が広いほど、ガベージとしてコレクトしてもよい領域を見つけ出すのに時間がかかり、例えば64〜128MBのヒープ領域で数秒間を要し、且つGCはフリー領域がある程度減少した時点で不定期に行われるので、リアルタイム性の要求されるシステムには用いることができなかった。   For example, according to the conventional garbage collection (hereinafter referred to as “GC”) method, the larger the memory space, the longer it takes to find an area that may be collected as garbage. For example, in a heap area of 64 to 128 MB Since several seconds are required and GC is performed irregularly when the free area decreases to some extent, it cannot be used in a system that requires real-time performance.

リアルタイム性の要求されるシステムでは、あるタスクを実行中に何らかのイベント(割り込み)が発生すれば、そのイベントに応じた他のスレッドを処理することになるが、そのスレッドの切替に要する時間は、最悪値として例えば数十μsec以下であることが要求される。ところが、上述したようにGCが何時起動されるか予測できず、一旦起動されれば、CPUは数秒間GCに専念することになるため、その間リアルタイム処理は不可能となる。   In a system that requires real-time performance, if some event (interrupt) occurs during execution of a certain task, other threads corresponding to the event will be processed. For example, the worst value is required to be several tens of μsec or less. However, as described above, when the GC is activated cannot be predicted, and once activated, the CPU is devoted to the GC for several seconds, and real-time processing is impossible during that time.

上述の問題はGCの場合に限らず、長時間の資源待ち状態が生じるシステムに共通の問題である。   The above problem is not limited to the case of GC, but is a problem common to systems in which a long resource waiting state occurs.

GCの他の方法として、従来の複写法をインクリメンタルに行うようにして、リアルタイム性を確保する方法が情報処理Vol.35 No.11 pp1008 〜pp1010に示されている。この方法によれば、GCの途中で中断を許すことができるので、時分割的に他のスレッドと並行処理することが一応はできる。しかし、この複写法をインクリメンタルに行うようにする方法では、複写中に他のスレッドがメモリを使用する訳にはいかないので、メモリを使用しない極一部のスレッドしか並行処理できない。また、複写法では、複写元と複写先のメモリ領域を確保しておかなければならないので、メモリの使用効率が低く、少量のメモリ環境下で動作させるシステムには向かない。   Information processing Vol. 35 No. 11 pp1008 to pp1010 shows a method of ensuring the real-time property by performing the conventional copying method incrementally as another method of GC. According to this method, since interruption can be permitted in the middle of GC, it is possible to perform parallel processing with other threads in a time division manner. However, in the method of performing the copying method incrementally, other threads cannot use the memory during copying, so only a very small part of threads that do not use the memory can perform parallel processing. Also, the copying method requires that the memory areas of the copy source and the copy destination be secured, so that the memory use efficiency is low and it is not suitable for a system that operates in a small memory environment.

また、マーク&スイープ法でマルチスレッドに対応するために参照関係が変更される度にマークを付与する方法は、「On-the-fly GC 」という名前で、GC専用のCPUに処理を割り当てるマルチCPU化のための方法が情報処理Vol.35 No.11 pp1006 〜pp1008に示されている。しかし、この方法では、オブジェクトが常に作成されて、且つ参照関係が変更されている場合に、既にマークしているツリーを何回も辿り直して新しいノードを見つけてマークしなければならず、マーク作業がいつまでも終わらない場合が生じたり、非常に長い時間がかかる。また、この方法ではスイープ中にシステムをロックする必要があった。   In addition, a method of assigning a mark every time the reference relationship is changed in order to cope with multi-threading by the mark & sweep method is called “On-the-fly GC”. A method for implementing a CPU is shown in Information Processing Vol.35 No.11 pp1006 to pp1008. However, with this method, if the object is always created and the reference relationship has changed, you must go through the already marked tree many times to find and mark the new node, The work may not end indefinitely, or it takes a very long time. This method also required the system to be locked during the sweep.

そして、従来のマーク&スイープ法等のGCによるフラグメントを解消するためにコンパクションを行う際、多大なCPUパワーを必要としていた。また、このコンパクションを行わなければメモリの使用効率が低下するという問題があった。   Then, when performing compaction in order to eliminate a fragment caused by GC such as the conventional mark and sweep method, a large amount of CPU power is required. In addition, if this compaction is not performed, there is a problem that the memory use efficiency is lowered.

この発明の目的は、コンパクションを不要とし、且つメモリの使用効率を向上させることにある。   An object of the present invention is to eliminate the need for compaction and to improve the use efficiency of a memory.

さらに、従来のオブジェクト指向システムにおいては、永続的に存在する寿命の長いオブジェクトと短時間で消滅する寿命の短いオブジェクトがヒープ領域内に混在していたため、GCを行うと、短寿命のオブジェクトから消去されて確実にフラグメントが生じてメモリ使用効率が急に低下する。また、GCを行う場合に、永続的に存在するオブジェクトに対してもガベージであるか否かの判定を毎回行わなければならないので、このことがCPUパワーの無駄となっていた。これに対して、一定期間存在していたオブジェクトを永久に存在するものと見なして、そのオブジェクトを存在調査から外す、いわゆる世代別ガベージコレクションという方法も従来から考えられているが、このような方法でも不要なオブジェクトが存続したり、それぞれのオブジェクトについて一定期間の存続調査をしなければならないという欠点があった。   Furthermore, in the conventional object-oriented system, the long-lived object that exists permanently and the short-lived object that disappears in a short time are mixed in the heap area. As a result, a fragment is surely generated, and the memory use efficiency is suddenly lowered. In addition, when GC is performed, it is necessary to determine whether or not an object that is permanently present is garbage, and this is a waste of CPU power. In contrast, a so-called generational garbage collection method that considers an object that has existed for a certain period of time as being permanently present and removes that object from the existence survey has been conventionally considered. However, there were drawbacks that unnecessary objects persisted or that each object had to be examined for a certain period of time.

この発明の他の目的はオブジェクトごとの寿命を考慮してフラグメントを低減し、メモリの使用効率を向上させ、CPUパワーの無駄を削減することにある。   Another object of the present invention is to reduce fragmentation in consideration of the lifetime of each object, to improve memory use efficiency, and to reduce waste of CPU power.

この発明は、上記課題を解決するために以下の構成を備えている。   The present invention has the following configuration in order to solve the above problems.

(1)メモリのヒープ領域内に生成されたオブジェクトの特性を検知する特性検知手段と、
前記特性検知手段が検知した特性に応じて、前記ヒープ領域に対する当該オブジェクトの割り当てを決定する割当決定手段と、を設けている。
(1) characteristic detection means for detecting characteristics of an object generated in the heap area of the memory;
Allocation determining means for determining allocation of the object to the heap area according to the characteristics detected by the characteristic detecting means;

この構成では、特性検知手段が、メモリのヒープ領域内に生成されたオブジェクトの特性、例えばオブジェクトのサイズや、オブジェクトの寿命、を検知し、割当決定手段が検知された特性に応じてヒープ領域に対する当該オブジェクトの割り当てを決定する。したがって、オブジェクトの特性に応じて、ヒープ領域に対する当該オブジェクトの割り当てを決定することができるので、メモリの使用効率の向上が図れる。   In this configuration, the characteristic detection unit detects the characteristic of the object generated in the heap area of the memory, for example, the size of the object and the life of the object, and the allocation determination unit detects the characteristic of the heap area according to the detected characteristic. Determine the assignment of the object. Therefore, the allocation of the object to the heap area can be determined according to the object characteristics, so that the memory usage efficiency can be improved.

(2)前記特性検知手段は、前記ヒープ領域内に割り当てられるオブジェクトのサイズの分布を検知する手段であり、
前記割当決定手段は、前記分布の中心より大きな固定サイズの整数倍を前記ヒープ領域に対する新たなオブジェクトの割り当てサイズに決定する割当サイズ決定手段を含む。
(2) The characteristic detection means is means for detecting a distribution of the size of an object allocated in the heap area,
The allocation determining means includes an allocation size determining means for determining an integer multiple of a fixed size larger than the center of the distribution as an allocation size of a new object for the heap area.

この構成では、オブジェクトの特性としてオブジェクトのサイズの分布を検知する。一般に、オブジェクト指向のシステムにおいては、プログラムの実行時に生成されるオブジェクトの大きさ(メモリ上のサイズ)の発生頻度分布は正規分布を示す。一方、新たなオブジェクトを生成する際、メモリ上のフリー領域から割り当て可能な領域を抽出するが、上述のようにオブジェクトのサイズの分布中心より、大きなサイズを新たなオブジェクトの割り当てサイズとしておくことによって、その割り当てられたオブジェクトが消去された後、新たなオブジェクトが割り当てられるとき、上記割り当てサイズより小さなオブジェクトであれば再利用できる。上記割り当てサイズは正規分布の分布中心より大きなサイズであるため、多くのオブジェクトが先に使用されていたメモリ領域を再利用できることになる。また、このことにより、コンパクションを行わなくてもメモリの使用効率が向上することになる。また、コンパクションのためのCPUパワーが不要となり、小規模のCPUで応答性の高いシステムを構成することができる。   In this configuration, the size distribution of the object is detected as the characteristic of the object. In general, in an object-oriented system, an occurrence frequency distribution of the size of an object (size on a memory) generated when a program is executed shows a normal distribution. On the other hand, when a new object is generated, an allocatable area is extracted from a free area on the memory. As described above, a size larger than the center of the object size distribution is set as a new object allocation size. When a new object is allocated after the allocated object is deleted, an object smaller than the allocated size can be reused. Since the allocation size is larger than the distribution center of the normal distribution, a memory area in which many objects have been used can be reused. This also improves the memory usage efficiency without performing compaction. In addition, CPU power for compaction is not required, and a highly responsive system can be configured with a small CPU.

(3)前記特性検知手段は、システムの使用開始時にシステムに組み込まれ、前記オブジェクトのサイズの分布を検知した後にシステムから切り離されるプログラムモジュールによるものである。   (3) The characteristic detection means is a program module that is incorporated into the system at the start of use of the system, and is separated from the system after detecting the size distribution of the object.

この構成では、一度オブジェクトのサイズの分布が検知された後は、また、オブジェクトの割り当てサイズが決定された後は、メモリ領域とCPUパワーの無駄がなくなる。   In this configuration, once the object size distribution is detected and after the object allocation size is determined, the memory area and CPU power are not wasted.

(4)前記割当サイズ決定手段は、システムの使用開始時にシステムに組み込まれ、前記固定サイズが決定された後にシステムから切り離されるプログラムモジュールによるものである。   (4) The allocation size determining means is a program module that is incorporated in the system at the start of use of the system and is disconnected from the system after the fixed size is determined.

この構成では、一度オブジェクトのサイズの分布が検知された後は、また、オブジェクトの割り当てサイズが決定された後は、メモリ領域とCPUパワーの無駄がなくなる。   In this configuration, once the object size distribution is detected and after the object allocation size is determined, the memory area and CPU power are not wasted.

(5)前記ヒープ領域内を予め複数のサイズに分割するヒープ領域分割手段と、
オブジェクト生成時に当該オブジェクトのサイズより大きく且つ最も小さなサイズの領域を割り当てる手段を設けたことを特徴とする。
(5) heap area dividing means for dividing the heap area into a plurality of sizes in advance;
Means is provided for allocating an area having a size smaller than the size of the object when the object is generated.

この構成では、多くのオブジェクトがメモリのヒープ領域を無駄なく再利用できることになり、コンパクションを行わなくてもメモリの使用効率が向上する。また、コンパクションのためのCPUパワーが不要となり、小規模のCPUで応答性の高いシステムを構成することができる。   In this configuration, many objects can reuse the heap area of the memory without waste, and the use efficiency of the memory is improved without performing compaction. In addition, CPU power for compaction is not required, and a highly responsive system can be configured with a small CPU.

(6)前記ヒープ領域分割手段は、前記複数のサイズの分割数と各サイズを引数とするアプリケーションプログラムインタフェースの呼び出しによって、前記ヒープ領域を分割する手段である。   (6) The heap area dividing unit is a unit that divides the heap area by calling an application program interface having the number of divisions of the plurality of sizes and each size as an argument.

この構成では、多くのオブジェクトがメモリのヒープ領域を無駄なく再利用できることになり、コンパクションを行わなくてもメモリの使用効率が向上する。また、コンパクションのためのCPUパワーが不要となり、小規模のCPUで応答性の高いシステムを構成することができる。   In this configuration, many objects can reuse the heap area of the memory without waste, and the use efficiency of the memory is improved without performing compaction. In addition, CPU power for compaction is not required, and a highly responsive system can be configured with a small CPU.

(7)アプリケーションプログラムインタフェースの呼び出しによって前記固定サイズを設定する手段を設けたことを特徴とする。   (7) Means for setting the fixed size by calling an application program interface is provided.

この構成では、別の装置、システム、およびアルゴリズムで、メモリのヒープ領域内に割り当てられるオブジェクトのサイズの分布を測定して、決定したオブジェクトの割り当てサイズの基になる固定サイズを登録することができ、CPUパワーとメモリの使用効率を向上させることができる。   With this configuration, another device, system, and algorithm can measure the size distribution of objects allocated within the heap area of memory and register a fixed size that is the basis for the determined object allocation size. CPU power and memory usage efficiency can be improved.

(8)クラスからオブジェクトが生成された時刻に相当するデータを記憶し、前記オブジェクトを削除する際に、当該オブジェクトの寿命を検出し、該寿命のデータをクラスに設ける手段を備え、
前記特性検知手段は、クラスから生成されたオブジェクトの寿命を検知する手段であり、
前記割当決定手段は、前記特性検知手段により検知されたオブジェクトの寿命に基づいて、このオブジェクトに割り当てる、前記ヒープ領域に対するオブジェクトの生成領域を決定する手段である。
(8) storing data corresponding to the time when the object is generated from the class, and detecting the life of the object when deleting the object, and providing means for providing the data of the life to the class,
The characteristic detection means is means for detecting the lifetime of an object generated from a class,
The allocation determination means is a means for determining an object generation area for the heap area to be allocated to the object based on the life of the object detected by the characteristic detection means.

一般にオブジェクト指向のシステムにおいては、クラスをテンプレートとしてオブジェクトが生成されるため、同一のクラスから生成されたオブジェクトは略同一の寿命を持つ。そこで、或るクラスからオブジェクトが生成された時刻に相当するデータを記憶し、そのオブジェクトが削除された際に、当該オブジェクトの寿命を検出して、これをそのオブジェクトを生成したクラスの寿命データとして記憶し、そのクラスからオブジェクトを生成する際に、寿命データに基づいて、異なったヒープ領域にオブジェクトを生成することによって、長寿命のオブジェクトと短寿命のオブジェクトが異なった領域に生成される。これにより、長寿命領域でのフラグメントが大幅に低下し、メモリの使用効率が向上する。また、GCを行う場合に、短寿命のオブジェクトが生成される領域を重点的に処理することによって、GCに消費されるCPUパワーを低減することができるようになる。   In general, in an object-oriented system, an object is generated using a class as a template. Therefore, objects generated from the same class have substantially the same lifetime. Therefore, the data corresponding to the time when the object is generated from a certain class is stored, and when the object is deleted, the lifetime of the object is detected, and this is used as the lifetime data of the class that generated the object. When storing and generating an object from the class, a long-life object and a short-life object are generated in different areas by generating objects in different heap areas based on the lifetime data. As a result, fragments in the long-life region are greatly reduced, and the memory usage efficiency is improved. In addition, when performing GC, the CPU power consumed by the GC can be reduced by intensively processing the region where the short-lived object is generated.

この発明によれば、多くのオブジェクトが先に使用されていたメモリ領域を再利用できることになり、このことにより、コンパクションを行わなくてもメモリの使用効率が向上することになる。また、コンパクションのためのCPUパワーが不要となり、小規模のCPUで応答性の高いシステムを構成することができる。   According to the present invention, a memory area in which many objects have been used can be reused, and this improves the memory use efficiency without performing compaction. In addition, CPU power for compaction is not required, and a highly responsive system can be configured with a small CPU.

また、寿命データに基づいて、異なったヒープ領域にオブジェクトを生成することによって、長寿命のオブジェクトと短寿命のオブジェクトが異なった領域に生成されるため、長寿命領域でのフラグメントが大幅に低下し、メモリの使用効率が向上する。また、GCを行う場合に、短寿命のオブジェクトが生成される領域を重点的に処理することによって、GCに消費されるCPUパワーを低減することができるようになる。   In addition, by generating objects in different heap areas based on lifetime data, long-lived objects and short-lived objects are generated in different areas, so fragments in the long-lived area are greatly reduced. , Memory usage efficiency is improved. In addition, when GC is performed, the CPU power consumed by the GC can be reduced by intensively processing the area where the short-lived object is generated.

以下、この発明の実施形態であるプログラム制御装置について、図1〜図53を参照して順次説明する。   Hereinafter, a program control apparatus according to an embodiment of the present invention will be sequentially described with reference to FIGS.

図1は装置のハードウエアの構成を示すブロック図である。装置は基本的にCPU1とオブジェクト群を生成するヒープ領域およびマークテーブル等を記憶するメモリ2、および外部との入出力を行うI/O3とから構成する。また、外部から必要なプログラムをメモリにロードする場合は、CD−ROM読取インタフェース4を用い、プログラムが予め書き込まれたCD−ROM5を読み取るようにする。このCD−ROMが本願発明に係るプログラム記録媒体に相当する。   FIG. 1 is a block diagram showing the hardware configuration of the apparatus. The apparatus basically comprises a CPU 1, a heap area for generating an object group, a memory 2 for storing a mark table and the like, and an I / O 3 for input / output from / to the outside. When a necessary program is loaded from the outside into the memory, the CD-ROM reading interface 4 is used to read the CD-ROM 5 on which the program has been written in advance. This CD-ROM corresponds to a program recording medium according to the present invention.

図2はソフトウエアの構成を示すブロック図である。同図において、カーネル部分はCPUやメモリを資源として管理し、時分割によるマルチスレッドの機能を実現する。VM(仮想マシーン)部分はプログラムとカーネルとのインタフェースを行うソフトウエアであり、ここではアプリケーションプログラムから見てVM以下の階層全体が例えばJava仮想マシン(JavaはSun Microsystems社の商標)として作用させる。この場合、カーネルとVM部分がJavaOS(JavaはSun Microsystems社の商標)を構成する。このVMにはプログラムがバイトコード等の中間コードで与えられるとき、これを解釈するインタプリタとその解釈に応じて呼び出されるプログラムモジュール等を含む。同図におけるプログラムは中間コードによる各種スレッドであり、上記インタプリタを介して、内部のプログラムモジュールを実行する。   FIG. 2 is a block diagram showing a software configuration. In the figure, the kernel part manages CPU and memory as resources and realizes a multi-thread function by time division. The VM (virtual machine) portion is software that interfaces the program and the kernel. Here, the entire hierarchy below the VM as seen from the application program acts as, for example, a Java virtual machine (Java is a trademark of Sun Microsystems). In this case, the kernel and the VM portion constitute Java OS (Java is a trademark of Sun Microsystems). The VM includes an interpreter that interprets a program when given as an intermediate code such as a byte code, and a program module that is called according to the interpretation. The programs in the figure are various threads based on intermediate codes, and execute internal program modules via the interpreter.

図3はメモリのヒープ領域に生成されるオブジェクトの参照関係およびスタックとの関係を示す図である。ヒープ領域に対してオブジェクトを生成した際、或るオブジェクトから他のオブジェクトへの参照関係は同図に示すようにルートノードから延びるツリー構造を成す。例えばグローバル変数を宣言すれば、その変数に対応するオブジェクトが生成される。またスレッド毎に引き数領域、戻り番地、ローカル変数、作業領域等の情報を記憶するスタックが生成され、例えば図中矢印で示すようなスタック上のローカル変数からツリー上のグローバル変数への参照関係なども記憶される。これらのスタックはヒープ領域外の所定領域に格納される。   FIG. 3 is a diagram showing the reference relationship of objects generated in the heap area of the memory and the relationship with the stack. When an object is generated for the heap area, a reference relationship from one object to another object forms a tree structure extending from the root node as shown in FIG. For example, if a global variable is declared, an object corresponding to the variable is generated. In addition, a stack for storing information such as argument area, return address, local variable, work area, etc. is generated for each thread. For example, a reference relationship from a local variable on the stack to a global variable on the tree as shown by an arrow in the figure. Etc. are also memorized. These stacks are stored in a predetermined area outside the heap area.

図4は図2に示したソフトウエアの構成をブロック図として詳細に示したものである。同図において、GCモジュール10はGCを行うための各種処理のプログラムモジュールであり、GCスレッド11はこれらのモジュールを呼び出すことによって、GCを実行させる。また、インタプリタ12は、この例で、「スレッド4」からオブジェクト生成依頼があったとき、GCモジュール10の「オブジェクト生成」を呼び出し、またオブジェクト間の参照関係の変更依頼があったとき、GCモジュール10の「マーク付与」を呼び出す。   FIG. 4 is a detailed block diagram showing the configuration of the software shown in FIG. In the figure, a GC module 10 is a program module for various processes for performing GC, and a GC thread 11 executes GC by calling these modules. Further, in this example, the interpreter 12 calls the “object generation” of the GC module 10 when there is an object generation request from the “thread 4”, and when there is a request to change the reference relation between objects, the GC module 10 10 “Mark assignment” is called.

なお、図4に示した例では、各スレッドが中間コード(例えばJavaアプレット(JavaはSun Microsystems社の商標)の場合バイトコード)で表されているが、中間コードをVMに対するネイティブコードに変換するコンパイラを設けてもよい。(例えばJava(JavaはSun Microsystems社の商標)の場合、JIT(Just-In-Time コンパイラ)等を設ける。)この場合、ネイティブコードで記述したスレッドであるので、図4に示したインタプリタ12を介さずにGCモジュール10を直接アクセスすることになる。   In the example shown in FIG. 4, each thread is represented by an intermediate code (for example, a byte code in the case of a Java applet (Java is a trademark of Sun Microsystems)), but the intermediate code is converted into a native code for the VM. A compiler may be provided. (For example, in the case of Java (Java is a trademark of Sun Microsystems), JIT (Just-In-Time Compiler) is provided.) In this case, the interpreter 12 shown in FIG. The GC module 10 is directly accessed without intervention.

図5はGCを行うことによって、ヒープ領域内に生じるフラグメントを解消するためのコンパクションを行った例を示す図である。図中ハッチング部分がオブジェクトであり、これをコンパクションすることによって、(B)に示すようにフラグメントが解消されて、連続したメモリ空間が広がることになる。   FIG. 5 is a diagram showing an example in which compaction is performed to eliminate fragments generated in the heap area by performing GC. In the figure, the hatched portion is an object, and by compacting this, fragments are eliminated as shown in (B), and a continuous memory space is expanded.

上記コンパクションは図4に示したGCモジュールの「コンパクション」のプログラムにより行う。   The compaction is performed by the “compaction” program of the GC module shown in FIG.

図6はコンテキストスイッチ発生有無を検出するためのAPIの使用例を示す図である。同図の(A)に示すように、処理1を実行する前にコンテキストスイッチ発生有無の検出開始を依頼するAPI#Aを発行してから処理1を実行する。処理1の終了後、コンテキストスイッチ発生有無検出の終了を依頼するAPI#Bを発行する。(A)に示す例ではこの間にコンテキストスイッチが発生していないので、そのまま次の処理2を行う。もし、(B)に示すように、処理1の途中でスレッド#2の処理が行われれば、すなわちコンテキストスイッチが発生していれば、API#Bの発行後、処理1を破棄する。たとえばメモリの領域Aの内容を領域Bにコピーするような処理で、コピー処理中にコンテキストスイッチが発生した場合、領域Aの内容が変わって領域AとBの内容が不一致となる場合がある。不一致ではコピーしたことにならないので、領域Bを無効にする。このことは、最初から処理が行われなかったのと同じであり、処理自体を破棄したことに他ならない。   FIG. 6 is a diagram illustrating an example of using an API for detecting whether or not a context switch has occurred. As shown in FIG. 5A, before executing the process 1, the process 1 is executed after issuing an API #A requesting the start of detecting whether or not a context switch has occurred. After the end of process 1, API #B is issued to request the end of the context switch occurrence detection. In the example shown in (A), since no context switch has occurred during this time, the next processing 2 is performed as it is. If the process of thread # 2 is performed in the middle of process 1, as shown in (B), that is, if a context switch has occurred, process 1 is discarded after issuing API #B. For example, in the process of copying the contents of the area A of the memory to the area B, if a context switch occurs during the copying process, the contents of the area A may change and the contents of the areas A and B may not match. If they do not match, the copy is not made, so the area B is invalidated. This is the same as the case where the process was not performed from the beginning, and it is nothing other than discarding the process itself.

図7は上記の処理をフローチャートとして示したものである。まず、API#Aを発行してから処理1を実行する(s1→s2)。この処理1が終了した後、API#Bを発行して、その戻り値を取得する(s3)。戻り値がコンテキストスイッチの発生を表す場合、処理1を破棄して、再び処理1を実行する(s4→s5→s1→s2)。戻り値がコンテキストスイッチの非発生を表す場合、処理を終了する。このように所定の期間内でのコンテキストスイッチの発生有無が分かるので、コンテキストスイッチが発生すれば、その間の処理を破棄し無効とすることによって、システムを現実にはロックしていないにも拘らず排他的制御を行うことが可能となる。   FIG. 7 shows the above processing as a flowchart. First, after issuing API #A, processing 1 is executed (s1 → s2). After this processing 1 is completed, API # B is issued to obtain the return value (s3). If the return value indicates the occurrence of a context switch, the process 1 is discarded and the process 1 is executed again (s4 → s5 → s1 → s2). If the return value represents the absence of a context switch, the process ends. In this way, it is possible to know whether or not a context switch has occurred within a predetermined period, so if a context switch occurs, the processing during that time is discarded and invalidated, even though the system is not actually locked. Exclusive control can be performed.

図8は上記API#AおよびAPI#Bのカーネルにおける処理手順を示すフローチャートである。API#Aの発行(システムコール)があれば、コンテキストスイッチの発生有無を示すフラグをクリアする。また、API#Bが発行されると、上記フラグの状態を戻り値としてスレッドに返す。   FIG. 8 is a flowchart showing a processing procedure in the kernel of API #A and API #B. If API # A is issued (system call), the flag indicating whether or not a context switch has occurred is cleared. When API # B is issued, the flag state is returned to the thread as a return value.

図9はコンテキストスイッチの処理手順を示すフローチャートである。コンテキストスイッチがスケジューラによって行われると、上記フラグをセットしてからコンテキストスイッチを実行する。すなわちスイッチ前のスレッドの実行状態をコンテキストとして格納するとともに、スイッチ後のスレッドのコンテキストを読み出してCPUのレジスタ等に設定する。   FIG. 9 is a flowchart showing the processing procedure of the context switch. When context switching is performed by the scheduler, the above-described flag is set and then context switching is executed. That is, the execution state of the thread before the switch is stored as a context, and the context of the thread after the switch is read and set in a CPU register or the like.

図10は上記コンパクションの処理手順を示すフローチャートである。先ず、ヒープ領域内の先頭のオブジェクトを指定し(s11)、そのオブジェクトをヒープ領域の先頭にコピーするための領域を確保し(s12)、コピー中に他のスレッドによってその領域に何らかのデータが書き込まれないようにしてから上記API#Aを発行する(s13)。そして、図5に示したように、ヒープ領域内のオブジェクトを先頭から順次空き領域へコピーすることによって詰めていく(s14)。1つのオブジェクトについてのコピーが終われば、上記API#Bを発行する(s15)。このことにより、API#Aを発行してから、API#Bを発行するまでの期間にコンテキストスイッチが発生したか否かがAPI#Bの戻り値として得られる。もしコンテキストスイッチが発生していれば、今回コピーを行ったオブジェクトを既に確保している領域に再びコピーする(s16→s13→・・・)。もしコンテキストスイッチが発生していなければ、次のオブジェクトについて同様に処理を行う(s16→s17→s18→・・・)。このようにシステムをロックすることなく、しかも他のスレッドとともに、コンパクションを同時に行うことが可能となる。   FIG. 10 is a flowchart showing a processing procedure of the compaction. First, the head object in the heap area is specified (s11), an area for copying the object to the head of the heap area is secured (s12), and some data is written to the area by another thread during copying. Then, the API # A is issued (s13). Then, as shown in FIG. 5, the objects in the heap area are sequentially packed from the top to the empty area (s14). When copying for one object is completed, the API #B is issued (s15). As a result, whether or not a context switch has occurred during a period from when API #A is issued until API #B is issued is obtained as a return value of API #B. If a context switch has occurred, the object copied this time is copied again to the area already secured (s16 → s13 →...). If no context switch has occurred, the same processing is performed for the next object (s16 → s17 → s18 →...). Thus, compaction can be performed simultaneously with other threads without locking the system.

上述の例ではマーク&スイープ法によるGCにおけるコンパクションに適用したが、複写法によるGCに適用する場合、図11および図12に示す処理を行う。   In the above-described example, the present invention is applied to compaction in GC by the mark & sweep method. However, in the case of application to GC by the copying method, the processing shown in FIGS.

図11は上記複写法によるGCのフローチャートである。先ず、オブジェクトの参照関係を表すツリー構造のデータのルートノードへポインタを移動し(s21)、そのルートノードに相当する、From領域にあるオブジェクトをTo領域に複写する(s22)。(ヒープ領域はFrom領域とTo領域に分けられ、From領域内の残すべきオブジェクトのみをTo領域に複写することによってTo領域にガベージのないオブジェクトだけを再構成する。次回は現在のFrom領域をTo領域とし、To領域をFrom領域として、その操作を交互に繰り返すのが、複写法によるガベージコレクションである。)その後、ツリーを辿って、参照関係にある次のオブジェクトへポインタを移動させ(s23)、そのオブジェクトをTo領域に複写する(s24)。この処理をツリーで辿れるすべてのオブジェクトについて行う。   FIG. 11 is a flowchart of GC according to the above copying method. First, the pointer is moved to the root node of the tree-structured data representing the object reference relationship (s21), and the object in the From area corresponding to the root node is copied to the To area (s22). (The heap area is divided into a From area and a To area, and only objects that are not garbage in the To area are reconstructed by copying only the objects that should remain in the From area to the To area. It is garbage collection by the copying method that alternately repeats the operation using the To area as the From area and the To area as the From area.) Thereafter, the pointer is moved to the next object in the reference relationship by tracing the tree (s23). The object is copied to the To area (s24). This process is performed for all objects that can be traced in the tree.

図12は図11における複写処理の内容を示すフローチャートである。先ず、複写すべきオブジェクトをTo領域内の所定位置にコピーするための領域を確保し、コピー中に他のスレッドによってその領域に何らかのデータが書き込まれないようにし、上記API#Aを発行してから(s31)、オブジェクトをFrom領域からTo領域に複写する(s32)。その後、上記API#Bを発行する(s33)。このことにより、API#Aを発行してから、API#Bを発行するまでの期間にコンテキストスイッチが発生したか否かがAPI#Bの戻り値として得られる。もしコンテキストスイッチが発生していれば、今回複写を行ったオブジェクトを既に確保している領域に再び複写する(s34→s31→・・・)。   FIG. 12 is a flowchart showing the contents of the copying process in FIG. First, an area for copying an object to be copied to a predetermined position in the To area is secured, and no data is written to the area by another thread during copying, and the above API # A is issued. From (s31), the object is copied from the From area to the To area (s32). Thereafter, the API # B is issued (s33). As a result, whether or not a context switch has occurred during a period from when API #A is issued until API #B is issued is obtained as a return value of API #B. If a context switch has occurred, the object copied this time is copied again to the area already secured (s34 → s31 →...).

図13および図14はコンテキストスイッチの発生有無を検出して排他性を確保するのではなく、複写しようとするオブジェクトが複写前に書き替えられたか否かを検出して排他性を確保する場合の処理手順を示すフローチャートである。   FIG. 13 and FIG. 14 do not detect the presence / absence of a context switch and ensure the exclusivity, but the processing procedure when the exclusivity is ensured by detecting whether or not the object to be copied has been rewritten before copying. It is a flowchart which shows.

複写を行う場合、先ず複写すべきオブジェクトをTo領域内の所定位置にコピーするための領域を確保し、コピー中に他のスレッドによってその領域に何らかのデータが書き込まれないようにしてから、図13に示すようにAPI#Cを発行する(s41)。このAPIは指定したメモリ領域に対する書き込みが発生したか否かの検出を依頼するアプリケーションプログラムインタフェースである。続いてオブジェクトをFrom領域からTo領域に複写する(s42)。その後、API#Dを発行する(s43)。このAPIは上記API#Cが呼び出されてから、このAPI#Dが呼び出されるまでの間に指定メモリ領域に何らかのデータの書き込みが発生したか否かが戻り値として返されるアプリケーションプログラムインタフェースである。したがって、複写しようとするオブジェクトのメモリ領域を指定してAPI#Cを発行し、API#Dの戻り値を見れば、そのオブジェクトが参照されたか否かが判る。オブジェクトが参照されていれば、内容が書き変わっている可能性があるので、そのオブジェクトの複写をやり直す(s44→s41→・・・)。   When copying, first, an area for copying an object to be copied to a predetermined position in the To area is secured, and some data is not written in the area by another thread during copying, and then FIG. As shown, API # C is issued (s41). This API is an application program interface that requests detection of whether or not writing to a specified memory area has occurred. Subsequently, the object is copied from the From area to the To area (s42). Thereafter, API # D is issued (s43). This API is an application program interface that returns as a return value whether or not any data has been written to a specified memory area between the time API # C is called and the time API # D is called. Therefore, by designating the memory area of the object to be copied and issuing API # C and looking at the return value of API # D, it can be determined whether or not the object has been referenced. If the object is referenced, there is a possibility that the contents have been rewritten, so the object is copied again (s44 → s41 →...).

図14は上記API#CおよびAPI#Dのカーネルにおける処理手順を示すフローチャートである。API#Cの発行(システムコール)があれば、所定のワークエリアをクリアし、API#Cのパラメータで指定された領域がライトされたときに例外が発生するようにMMU(Memory Management Unit) を設定する。また、API#Dが発行されると、上記パラメータで指定された領域がライトされたときに例外が発生しないように、MMUに対する上記設定を解除する。そして上記ワーク領域にセットされるフラグの状態を戻り値としてスレッドに返す。   FIG. 14 is a flowchart showing a processing procedure in the kernel of API # C and API # D. If API # C is issued (system call), clear the specified work area and set the MMU (Memory Management Unit) so that an exception occurs when the area specified by the API # C parameter is written. Set. When API # D is issued, the above setting for the MMU is canceled so that no exception occurs when the area specified by the above parameter is written. The state of the flag set in the work area is returned to the thread as a return value.

図15は上記例外発生時のMMUの処理内容を示すフローチャートである。例外が発生すると、上記ワーク領域内の参照フラグをセットする。   FIG. 15 is a flowchart showing the processing contents of the MMU when the exception occurs. When an exception occurs, the reference flag in the work area is set.

なお、上述の例では複写法によるGCの場合について示したが、マーク&スイープ法におけるコンパクションの場合にも同様に適用できる。   In the above example, the case of GC by the copying method is shown, but the present invention can be similarly applied to the case of compaction by the mark & sweep method.

次に、インクリメンタルにガベージコレクションできるGCスレッドの優先度を自動的に切り替えるようにした場合について説明する。図16および図17はインクリメンタルにガベージコレクションできるGCスレッドの優先度を自動的に切り替えるようにした場合の例を示す図である。   Next, a case will be described in which the priority of GC threads that can be incrementally collected is automatically switched. FIGS. 16 and 17 are diagrams showing an example in which the priority of GC threads that can be incrementally collected is automatically switched.

図16の(A)に示すように、GCスレッドの優先度を、高優先度時間は高め(例えば最高優先度にし)、低優先度時間は低く(例えば最低優先度)する動作を交互に行う。   As shown in FIG. 16A, operations of increasing the priority of the GC thread in a high priority time (for example, the highest priority) and lowering the low priority time (for example, the lowest priority) are alternately performed. .

同図の(B)はGCスレッド以外の中程度の優先度のスレッドを同時に行った場合の例について示している。すなわちGCスレッドの優先度が低いとき、それより優先度の高いスレッドがReady状態となれば、コンテキストがスイッチされ、そのスレッドの実行中にGCスレッドの優先度が高くなれば、そのGCスレッドにコンテキストがスイッチされ、そのGCスレッドの処理が中断すると、上記のGCスレッド以外のスレッドの処理を行うことになる。このようにすれば、一定周期で必ずGCスレッドが実行されるため、フリー領域が慢性的に不足状態となることが防止され、常に高いパフォーマンスを維持することができる。   (B) of the figure shows an example in which a thread having a medium priority other than the GC thread is simultaneously performed. That is, when the priority of the GC thread is low, if a thread with a higher priority is in the Ready state, the context is switched. If the priority of the GC thread becomes high during execution of the thread, the context is assigned to the GC thread. Is switched and processing of the GC thread is interrupted, processing of threads other than the above-described GC thread is performed. In this way, since the GC thread is always executed at a constant period, it is possible to prevent the free area from being chronically insufficient, and to always maintain high performance.

図17はスレッドの優先度の切替に関するカーネルの行う処理手順を示すフローチャートである。優先度の値は複数段階あり、その値の設定は対応するAPIの発行により行えるようにしている。ここでは、GCスレッドの2つの優先度を設定する際、高優先度の値を設定するAPIが発行されると、図17の(A)に示すように、その値をGCスレッドの高優先度の値として設定する。同様に、低優先度の値を設定するAPIが発行されると、(B)に示すように、その値をGCスレッドの低優先度の値として設定する。また、GCスレッドの高優先度の時間を設定するAPIが発行されると、同図の(C)に示すように、その値を設定し、同様に低優先度の時間を設定するAPIが発行されると、同図の(D)に示すように、その値を設定する。   FIG. 17 is a flowchart showing a processing procedure performed by the kernel regarding switching of thread priorities. There are a plurality of priority values, and the values can be set by issuing corresponding APIs. Here, when setting two priorities of the GC thread, if an API for setting a high priority value is issued, as shown in FIG. Set as the value of. Similarly, when an API for setting a low priority value is issued, the value is set as the low priority value of the GC thread, as shown in (B). When an API for setting a high priority time of a GC thread is issued, as shown in (C) of the figure, an API for setting the value and similarly setting a low priority time is issued. Then, the value is set as shown in FIG.

図17の(E)は、カーネルのスケジューラに対する処理手順を示すフローチャートである。ここでは、初期状態で、高優先度のキューにGCスレッドが資源の割当を受けようとする待ち行列に入っているものとし、先ず、そのデータ(GCスレッドを識別するデータ)を高優先度のキューから取り出して低優先度のキューに挿入する(s51)。そしてスケジューラは、既に設定されている低優先度時間だけ時間待ちを行い(s52)、続いて低優先度のキューからGCスレッドを識別するデータを取り出して高優先度のキューに挿入する(s53)。そしてスケジューラは、既に設定されている高優先度時間だけ時間待ちを行う(s54)。以上の処理を繰り返すことによって、スケジューラの動作により図16(A)に示したようにGCスレッドの優先度が交互に切り替わる。GCスレッド以外のスレッドについては、そのスレッドの優先度に対応するキューの待ち行列に応じて従来と同様のスケジューリングが行われ、図16の(B)に示したように、コンテキストスイッチがなされる。   FIG. 17E is a flowchart showing the processing procedure for the kernel scheduler. Here, in the initial state, it is assumed that the GC thread is queued for resource allocation in the high priority queue. First, the data (data for identifying the GC thread) is transferred to the high priority queue. Remove from the queue and insert into the low priority queue (s51). Then, the scheduler waits for the preset low priority time (s52), and then extracts data for identifying the GC thread from the low priority queue and inserts it into the high priority queue (s53). . Then, the scheduler waits for the set high priority time (s54). By repeating the above processing, the priority of the GC thread is alternately switched as shown in FIG. 16A by the operation of the scheduler. For threads other than the GC thread, scheduling similar to the prior art is performed according to the queue of the queue corresponding to the priority of the thread, and context switching is performed as shown in FIG.

図18は上記のGCスレッドの高優先度時間をAPIによって設定可能とした場合について示している。また、図19はそのAPIの呼び出しに応じたカーネルにおける処理手順を示すフローチャートである。このAPIの発行(システムコール)があれば、上記の高優先度時間をそのAPIのパラメータによって設定(登録)する。   FIG. 18 shows a case where the high priority time of the GC thread can be set by the API. FIG. 19 is a flowchart showing a processing procedure in the kernel in response to the API call. If this API is issued (system call), the above high priority time is set (registered) by the API parameter.

図20は上記のGCスレッドの高優先度時間を設定可能とするAPIを使うプログラムの例を示すフローチャートである。先ず、ループの1回目の示すフラグの状態を見る(s61)。最初はOFF状態であるので、このフラグをONし(s62)、現在のフリー領域を調べ、それを記録する(s63)。初めはGCの高優先度時間と低優先度時間は予め定められたデフォルト値である。スケジューラにより、一定時間停止した後(s64)、今度は、前回に調べたフリー領域の容量と現在のフリー領域の容量との大小比較を行い(s65)、フリー領域の容量が増加していれば、GCスレッドの高優先度時間を短くし(s66→s67)、フリー領域の容量が減少していれば、GCスレッドの高優先度時間を長くする(s68)。以上の処理を繰り返す。
このことによって、GCの優先度が動的に自動調整される。
FIG. 20 is a flowchart showing an example of a program that uses an API that allows the high priority time of the GC thread to be set. First, the state of the flag shown in the first loop is checked (s61). Since it is initially in an OFF state, this flag is turned on (s62), the current free area is checked, and it is recorded (s63). Initially, the GC high priority time and low priority time are predetermined default values. After stopping for a certain time by the scheduler (s64), this time, the size of the free area capacity examined last time is compared with the current free area capacity (s65), and if the free area capacity has increased, The high priority time of the GC thread is shortened (s66 → s67), and if the free area capacity is reduced, the high priority time of the GC thread is lengthened (s68). The above processing is repeated.
As a result, the priority of GC is automatically adjusted automatically.

図21はGCスレッドの高優先度時間と低優先度時間とによる周期を設定可能とした場合について示している。(A)は周期が長い場合、(B)は短い場合である。   FIG. 21 shows a case where a cycle based on the high priority time and the low priority time of the GC thread can be set. (A) is when the period is long, and (B) is when the period is short.

図22は上記周期を設定可能とする周期設定APIの呼び出しに応じたカーネルにおける処理手順を示すフローチャートである。この周期設定APIの発行があれば、現在設定されている高優先度時間および低優先度時間の値を読み取り、その割合(比率)を計算する(s71→s72→s73)。その後、この周期設定APIのパラメータで指定された周期の値に応じて高・低優先度時間を再計算する(s74)。そして、その高優先度時間および低優先度時間を設定更新する(s75→s76)。   FIG. 22 is a flowchart showing a processing procedure in the kernel in response to a call to the period setting API that allows the period to be set. If this period setting API is issued, the values of the currently set high priority time and low priority time are read, and the ratio (ratio) is calculated (s71 → s72 → s73). Thereafter, the high / low priority times are recalculated according to the value of the period specified by the parameter of the period setting API (s74). Then, the high priority time and the low priority time are set and updated (s75 → s76).

たとえば連続的なパルスを処理するような、連続してCPU資源が必要なアプリケーションプログラムの場合には、GCスレッドの周期が短くなるように周期設定APIを発行し、通常のアプリケーションプログラムのように断続的にCPU資源を利用するアプリケーションプログラムでは周期が長くなるように周期設定APIを発行する。   For example, in the case of an application program that requires continuous CPU resources, such as processing a continuous pulse, issue a cycle setting API so that the cycle of the GC thread is shortened, and it will be interrupted like a normal application program In an application program that uses CPU resources, a cycle setting API is issued so that the cycle becomes longer.

次に、必要な時点でGCスレッドを実行し、且つリアルタイム性を確保するようにした場合について説明する。   Next, a case where a GC thread is executed at a necessary time and real-time performance is ensured will be described.

図23および図24は必要な時点でGCスレッドを実行し、且つリアルタイム性を確保するようにした例であり、図23に示す例では、スレッド1とスレッド3がリアルタイム性の要求されるスレッド、スレッド2がリアルタイム性の要求されないスレッド(ノーマルスレッド)である。また、スレッド3がGCスレッドである。メモリのフリー領域が多い通常状態で、スレッド2が実行されているときにイベント1が発生すれば処理がスレッド1に移され、イベント1の処理に起因するスレッド1の処理が終了すればスレッド2へ戻る。同様に、イベント2が発生すればスレッド3に処理が移る。もしスレッド2の処理によってフリー領域が予め定めた警告レベルまで低下したとき、スレッド2の処理を中断して、スレッド3のGCスレッドを実行する。この処理によってフリー領域が確保されるとスレッド2の処理へ戻る。もしGCスレッドの処理途中でイベント1が発生すれば、GCの途中であってもスレッド1へ処理が移る。このようにリアルタイム性の要求されるスレッドでは、一般に生成されるオブジェクトの量が少なく、大体の予測が可能であるので、それに応じて上記警告レベルを設定しておけば、スレッド2に処理によって、フリー領域が大幅に減少してスレッド1やスレッド3のリアルタイム性の要求される処理が実行できなくなるといった、不都合が回避できる。 FIG. 23 and FIG. 24 are examples in which the GC thread is executed at a necessary time and the real-time property is ensured. In the example shown in FIG. 23, the thread 1 and the thread 3 are threads that require real-time property. The thread 2 is a thread that does not require real-time property (normal thread). The thread 3 is a GC thread. If event 1 occurs when thread 2 is being executed in a normal state where there are many free areas in the memory, the process is transferred to thread 1, and if the process of thread 1 resulting from the process of event 1 is completed, thread 2 Return to. Similarly, if event 2 occurs, the process moves to thread 3. If the free area is lowered to a predetermined warning level by the processing of the thread 2, the processing of the thread 2 is interrupted and the GC thread of the thread 3 is executed. When a free area is secured by this process, the process returns to the thread 2 process. If event 1 occurs during the processing of the GC thread, the processing moves to thread 1 even during the GC. In such a thread that requires real-time properties, the amount of objects that are generated is generally small and can be roughly predicted. Therefore, if the warning level is set accordingly, the thread 2 can perform processing, It is possible to avoid the disadvantage that the free area is greatly reduced and the processing requiring the real time property of the thread 1 and the thread 3 cannot be executed.

図24は上記コンテキストスイッチの処理を行うスケジューラの処理手順を示すフローチャートである。先ずイベントの発生有無を検知し(s81)、イベントが発生していれば、対応するリアルタイムスレッドにコンテキストをスイッチする(s82)。イベントが発生していなくて、フリー領域が警告レベルより多ければ、ノーマルスレッドのうち優先度の最も高いもの(図23に示した例ではスレッド2)にコンテキストをスイッチする(s83→s84)。もしフリー領域が警告レベルより少なくなれば、GCスレッドにコンテキストをスイッチする(s85)。   FIG. 24 is a flowchart showing the processing procedure of the scheduler that performs the context switch processing. First, whether or not an event has occurred is detected (s81). If an event has occurred, the context is switched to the corresponding real-time thread (s82). If no event has occurred and the free area is greater than the warning level, the context is switched to the normal thread with the highest priority (thread 2 in the example shown in FIG. 23) (s83 → s84). If the free area is less than the warning level, the context is switched to the GC thread (s85).

次に、コンテキストスイッチの検出を依頼するAPIにおける強制コンテキストスイッチの例について説明する。図25はコンテキストスイッチの検出を依頼するAPIにおける強制コンテキストスイッチの例を示している。先に示した例では、API#Aを発行してから、API#Bを発行するまでの間にコンテキストスイッチが発生したか否かが判るようにしたものであったが、この図25に示す例は、GCの優先度を高・低交互に切り替える場合に、上記の排他制御のためのAPIを発行している間にコンテキストスイッチが発生することを予測して、無駄な処理を行わないようにしたものである。すなわち、高優先度GCスレッドを実行中にAPI#A′を発行した際、API#A′は高優先度時間が終了するまでに、必要な処理が完了するか否かを判定して、もし完了しなければ、その時点でGCスレッドの優先度を低くする。図25に示した例では、GCスレッドの優先度が低くなったことにより、GCスレッド以外の中優先度のスレッドにコンテキストスイッチされることになる。このことにより無駄な処理が避けられる。   Next, an example of a forced context switch in the API that requests detection of a context switch will be described. FIG. 25 shows an example of a forced context switch in the API that requests detection of a context switch. In the example shown above, it is possible to determine whether or not a context switch has occurred between the issuance of API #A and the issuance of API #B. In the example, when the priority of GC is switched between high and low alternately, it is predicted that a context switch will occur while issuing the API for exclusive control described above, so that unnecessary processing is not performed. It is a thing. That is, when API #A ′ is issued while the high priority GC thread is being executed, API #A ′ determines whether or not necessary processing is completed before the high priority time ends. If it is not completed, the priority of the GC thread is lowered at that time. In the example shown in FIG. 25, since the priority of the GC thread is lowered, the context is switched to a medium priority thread other than the GC thread. This avoids wasteful processing.

図26は上記API#A′の呼び出しに応じたカーネルにおける処理手順を示すフローチャートである。このAPIの呼び出しがあれば、コンテキストスイッチフラグをクリアし(s91)、GCスレッドの高優先度時間の残時間を取得する(s92)。そして、このAPI#A′のパラメータである排他時間(API#A′を発行してから、API#Bを発行するまでの時間)と上記残時間との大小比較を行う(s93)。もし、残時間が排他時間より短ければGCスレッドの優先度を強制的に低くする(s94)。なお、API#B呼び出しによる処理内容とコンテキストスイッチの処理内容は図8および図9に示したものと同様である。   FIG. 26 is a flowchart showing a processing procedure in the kernel in response to the API #A 'call. If this API is called, the context switch flag is cleared (s91), and the remaining time of the high priority time of the GC thread is acquired (s92). Then, the exclusive time (time from issuing API # A 'to issuing API # B), which is a parameter of API # A', is compared with the remaining time (s93). If the remaining time is shorter than the exclusion time, the priority of the GC thread is forcibly lowered (s94). Note that the processing content by the API #B call and the processing content of the context switch are the same as those shown in FIGS.

次に、メモリ(ヒープ領域)使用量に応じてGCのアルゴリズムを切り替える例について説明する。図27はメモリ(ヒープ領域)使用量に応じてGCのアルゴリズムを切り替えるための処理手順を示すフローチャートである。先ず、メモリ使用量の値とそれに応じてどのアルゴリズムでGCを行うかを示すしきい値を設定し(s101)、メモリ使用量を取得する(s102)。これはヒープ領域内に生成されたオブジェクトのメモリサイズの合計値である。メモリ使用量がしきい値th1を超えた場合、GCアルゴリズム(1)の手順でGCを行う(s103→s104)。メモリ使用量がしきい値th2を超えたなら、GCアルゴリズム(2)の手順でGCを行う(s105→s106)。以下同様である。ここで、しきい値th1はしきい値th2より小さく、GCアルゴリズム(1)としては図16に示した、GCスレッドの優先度の高低を交互に繰り返す処理を行う。しきい値の高いときに行うGCアルゴリズムとしては、図23に示した不定期のGCを実行する。ここでGC自体は例えばマーク&スイープ法により行う。通常、前者の場合にはCPU負荷が軽く、専らこの方法によりGCが行われるが、ノーマルスレッドによって短時間に大量のメモリが使用された場合には、図23に示した方法によりGCを重点的に行う。このことによって常に広いフリー領域を確保し、且つリアルタイム性を維持する。   Next, an example of switching the GC algorithm according to the memory (heap area) usage will be described. FIG. 27 is a flowchart showing a processing procedure for switching the GC algorithm according to the memory (heap area) usage. First, a memory usage value and a threshold value indicating which algorithm is used for GC are set (s101), and the memory usage is acquired (s102). This is the total memory size of the objects generated in the heap area. When the memory usage exceeds the threshold th1, GC is performed according to the procedure of the GC algorithm (1) (s103 → s104). If the memory usage exceeds the threshold th2, GC is performed according to the procedure of the GC algorithm (2) (s105 → s106). The same applies hereinafter. Here, the threshold value th1 is smaller than the threshold value th2, and the GC algorithm (1) performs the process of alternately repeating the priority of the GC thread shown in FIG. As the GC algorithm performed when the threshold is high, the irregular GC shown in FIG. 23 is executed. Here, the GC itself is performed by, for example, a mark & sweep method. Normally, in the former case, the CPU load is light and GC is performed exclusively by this method. However, when a large amount of memory is used in a short time by a normal thread, the GC is emphasized by the method shown in FIG. To do. In this way, a wide free area is always secured and real-time performance is maintained.

次に、オブジェクト生成時のヒープ領域に対する新たなオブジェクトの割り当てサイズを定める例について説明する。図28〜図30はオブジェクト生成時のヒープ領域に対する新たなオブジェクトの割り当てサイズを定めるための処理に関する図である。一般にプログラムの実行により生成されるオブジェクトのサイズの分布は図28に示すように略正規分布を示す。その中心値は32と64バイトの間に納まる程度である。そこで、図29の(A)に示すように、この中心値より大きなサイズで、且つ2の巾乗バイトの整数倍のサイズをオブジェクトの割り当てサイズとする。従来は同図の(B)に示すように、生成すべきオブジェクトのサイズの量だけ任意に割り当てられていたため、そのオブジェクトの消去の際、不揃いのサイズのフラグメントが生じる。本願発明によれば、新たに生成されるオブジェクトのサイズが上記固定値の整数倍であるため、メモリ領域の再利用性が高まり、メモリ使用効率が全体に高まる。しかも場合によってはコンパクションが不要となる。   Next, an example of determining a new object allocation size for the heap area at the time of object generation will be described. 28 to 30 are diagrams relating to processing for determining a new object allocation size for the heap area at the time of object generation. In general, the distribution of the size of an object generated by executing a program shows a substantially normal distribution as shown in FIG. Its central value is within the range of 32 and 64 bytes. Therefore, as shown in FIG. 29A, a size larger than this central value and an integer multiple of the power-of-two bytes is set as the object allocation size. Conventionally, as shown in FIG. 5B, since the object is arbitrarily assigned in an amount corresponding to the size of the object to be generated, fragments of irregular sizes are generated when the object is deleted. According to the present invention, since the size of the newly generated object is an integral multiple of the fixed value, the reusability of the memory area is increased, and the memory usage efficiency is increased as a whole. In some cases, compaction is not necessary.

図30はそのオブジェクト生成時の処理手順を示すフローチャートである。先ず、これまでに生成したオブジェクトのサイズの発生頻度の分布データを求める(s111)。既に前回までに分布データを求めている場合には、それを更新する。続いて、今回割り当てるべきメモリの空いている領域で、且つ生成しようとするオブジェクトのサイズより大きな領域を探し、上記の固定サイズの整数倍のメモリ領域にオブジェクトを割り当てる(s112→s113→s114→s115)。上記2の巾乗バイトはシステム定数であるが、必ずしもこの値を固定サイズとする必要はなく、任意である。固定サイズをもし大き過ぎる値に採れば、サイズの大きな領域に小さなオブジェクトが割り当てられる場合が増えることになり、逆に、固定サイズを小さ過ぎる値に採れば、オブジェクトの生成に再利用できない領域が増えることになる。分布データを基に上記固定サイズを決定する場合には、メモリの使用効率が最適となるように決定すればよい。また、最適値でなくても、例えば2の巾乗の値を採れば、アドレス決定がやり易くなるという効果を奏する。   FIG. 30 is a flowchart showing a processing procedure when the object is generated. First, distribution data of the frequency of occurrence of the object size generated so far is obtained (s111). If distribution data has already been obtained by the previous time, it is updated. Subsequently, an area that is free in the memory to be allocated this time and that is larger than the size of the object to be generated is searched, and the object is allocated to a memory area that is an integral multiple of the fixed size (s112 → s113 → s114 → s115). ). Although the above power-of-two byte is a system constant, this value does not necessarily have to be a fixed size and is arbitrary. If the fixed size is too large, small objects will be allocated to large areas. Conversely, if the fixed size is too small, there are areas that cannot be reused for object generation. Will increase. When the fixed size is determined based on the distribution data, it may be determined so that the memory usage efficiency is optimal. Even if the value is not the optimum value, for example, if the value of the power of 2 is taken, there is an effect that it becomes easier to determine the address.

図31は上記オブジェクトのサイズの発生頻度分布データを求めるプログラムモジュール、およびオブジェクトの割り当てサイズを決定するプログラムモジュールの処理内容を示すフローチャートである。先ず、オブジェクトのサイズの発生頻度分布データを求めるプログラムモジュールをロードし(s121)、そのプログラムモジュールを起動する。すなわち一定時間が経過するまで(たとえばアプリケーションプログラムの起動・終了が10回行われるまで、またたとえば24時間経過するまで)、生成された各オブジェクトのサイズをサイズ毎に計数し、その分布データを求める(s122→s123)。その後、その分布データをシステムに登録し(s124)、オブジェクトのサイズの発生頻度分布データを求めるプログラムモジュールをアンロードする(s125)。続いて固定サイズを決定するプログラムモジュールをロードし(s126)、そのプログラムモジュールを実行する。すなわちシステムの登録された分布データを取得し、その分布中心値より大きなサイズで、且つたとえば2の巾乗バイトを固定サイズとして決定し、その値をシステムに登録する(s127→s128)。その後、固定サイズを決定するプログラムモジュールをアンロードする(s129)。   FIG. 31 is a flowchart showing the processing contents of the program module for determining the occurrence frequency distribution data of the object size and the program module for determining the allocation size of the object. First, a program module for obtaining occurrence frequency distribution data of the object size is loaded (s121), and the program module is activated. That is, until a certain time elapses (for example, until the application program is started / finished 10 times, or for example, 24 hours elapses), the size of each generated object is counted for each size to obtain distribution data. (S122 → s123). Thereafter, the distribution data is registered in the system (s124), and the program module for obtaining the occurrence frequency distribution data of the object size is unloaded (s125). Subsequently, a program module for determining a fixed size is loaded (s126), and the program module is executed. That is, distribution data registered in the system is acquired, a size larger than the distribution center value, for example, a power-of-two byte of 2 is determined as a fixed size, and the value is registered in the system (s127 → s128). Thereafter, the program module for determining the fixed size is unloaded (s129).

このように、一度オブジェクトのサイズの分布が検知された後、および固定サイズが決定された後は、それらのためのプログラムモジュールをアンロードすることによって、メモリ領域とCPUパワーの無駄を無くす。   As described above, once the object size distribution is detected and after the fixed size is determined, the program modules for these are unloaded, thereby eliminating the waste of the memory area and CPU power.

次に、固定サイズをAPIによって設定する例について説明する。図49は上記固定サイズをAPIによって設定する例を示している。図に示すように、固定サイズ設定処理では、固定サイズを引数として固定サイズ設定APIを呼び出す。呼び出されたAPIでは、引数を固定サイズとしてシステムに登録する。オブジェクト生成時にはオブジェクトのサイズと固定サイズを比較し(s211)、固定サイズ以下であれば、ヒープ上の固定サイズの空き領域を探し、見つかった領域をオブジェクトに割り当てる(s212→s213)。固定サイズを超える場合は、ヒープ上のオブジェクトサイズより大きな空き領域を探し、見つかった領域をオブジェクトに割り当てる(s214→s215)。   Next, an example in which a fixed size is set by API will be described. FIG. 49 shows an example in which the fixed size is set by the API. As shown in the figure, in the fixed size setting process, a fixed size setting API is called with a fixed size as an argument. In the called API, the argument is registered in the system as a fixed size. When an object is generated, the size of the object is compared with a fixed size (s211). If the size is equal to or smaller than the fixed size, a fixed-size free area on the heap is searched and the found area is assigned to the object (s212 → s213). If the size exceeds the fixed size, an empty area larger than the object size on the heap is searched, and the found area is allocated to the object (s214 → s215).

次に、固定サイズをAPIによって設定する他の例について説明する。図50は上記固定サイズをAPIによって設定する他の例を示している。図50に示すように、この例では、まずオブジェクトサイズの分布データをオブジェクトサイズ分布設定APIを呼び出して設定する。この分布データは予め所定時間所定のアプリケーションを実行して測定したものである。オブジェクトサイズ分布設定APIは呼び出しに応答して、引数をオブジェクトサイズ配列変数にセットする。続いて、その中心値より大きなサイズで、且つ2の巾乗バイトを固定サイズとして決定し、これを固定サイズ変数にセットする。   Next, another example in which a fixed size is set by API will be described. FIG. 50 shows another example in which the fixed size is set by the API. As shown in FIG. 50, in this example, first, object size distribution data is set by calling an object size distribution setting API. This distribution data is measured in advance by executing a predetermined application for a predetermined time. In response to the call, the object size distribution setting API sets an argument to the object size array variable. Subsequently, a size larger than the center value and a power of 2 bytes is determined as a fixed size, and this is set to a fixed size variable.

次に、オブジェクトの割り当てサイズを予めいくつかのサイズに定めておく例について説明する。図51〜図53はオブジェクトの割り当てサイズを予めいくつかのサイズに定めておく例を示す図である。図51は事前に所定のアプリケーションを所定時間実行して測定したオブジェクトサイズの分布および分割領域の集合を表している。予めヒープ領域を分割する場合、実際のオブジェクトサイズの分布を測定し、その分布に近くなるように、分割サイズと数を定める。たとえば、ヒープ領域が2MBの場合、分割サイズ指定変数を
集合No.n バイトk 個数m
1 64 5000
2 256 10000
3 1k 10000
4 4k 5000
5 32k 500
とする。
Next, an example will be described in which the allocation size of the object is set to several sizes in advance. 51 to 53 are diagrams showing examples in which the object allocation size is determined in advance to several sizes. FIG. 51 shows an object size distribution and a set of divided regions measured by executing a predetermined application for a predetermined time in advance. When the heap area is divided in advance, the distribution of the actual object size is measured, and the division size and the number are determined so as to be close to the distribution. For example, if the heap area is 2 MB, set the partition size specification variable to set No. n bytes k number m
1 64 5000
2 256 10000
3 1k 10000
4 4k 5000
5 32k 500
And

上記分割サイズを設定する場合、図52に示すように、分割サイズ設定APIを呼び出して行う。呼び出された分割サイズ設定APIは図53に示すように、引数を分割サイズ指定変数にセットし、それに応じてヒープ領域を分割する。すなわち、まずループカウンタnを0とし(s221)、n番目の分割サイズ指定変数からサイズkと個数mを取得する(s222)。続いてヒープ領域からサイズkの領域をm個に分割し(m個分確保し)、リストに登録する(s223)。この処理をループカウンタnを1インクリメントしながら繰り返し、全てのサイズの分割を行う(s225→s222→・・・)。なお、上記の例で、サイズが32kバイトを超えるオブジェクトを生成する場合は、ヒープ領域内の上記分割された領域以外の領域に割り当てる。   The division size is set by calling a division size setting API as shown in FIG. As shown in FIG. 53, the called partition size setting API sets an argument to a partition size designation variable and divides the heap area accordingly. That is, first, the loop counter n is set to 0 (s221), and the size k and the number m are obtained from the nth division size designation variable (s222). Subsequently, the area of size k is divided from the heap area into m pieces (m pieces are secured) and registered in the list (s223). This process is repeated while incrementing the loop counter n by 1, and all sizes are divided (s225 → s222 →...). In the above example, when an object having a size exceeding 32 kbytes is generated, the object is allocated to an area other than the divided area in the heap area.

次に、オブジェクトの寿命を考慮してGCの効率を高める例について説明する。図32〜図34はオブジェクトの寿命を考慮してGCの効率を高めるための処理を行う例を示す図である。図32の(A)に示す例では、ヒープ領域として、短寿命のオブジェクトを生成する領域と長寿命のオブジェクトを生成する領域とに分け、クラスは長寿命領域に確保する。尚、クラスはその他の固定領域に確保してもよい。そして、クラスにはオブジェクトを生成するためのテンプレートとしての定義情報以外に、生成するオブジェクトの寿命を示す寿命フラグを持たせる。この寿命フラグはクラスの生成時に自動的に生成する。同図の(B)は従来のヒープ領域に対するオブジェクトの割り当て例を示す図である。   Next, an example in which the GC efficiency is increased in consideration of the lifetime of the object will be described. FIGS. 32 to 34 are diagrams illustrating an example of performing processing for improving the efficiency of GC in consideration of the lifetime of an object. In the example shown in FIG. 32A, the heap area is divided into an area for generating a short-life object and an area for generating a long-life object, and the class is secured in the long-life area. The class may be secured in other fixed areas. In addition to the definition information as a template for generating an object, the class has a lifetime flag indicating the lifetime of the generated object. This life flag is automatically generated when a class is generated. FIG. 6B is a diagram showing an example of object allocation to the conventional heap area.

図33はオブジェクトの消去の手順を示すフローチャートである。同図に示すようにオブジェクトを消去した際に、そのオブジェクトの寿命が長いか短いかを判定し、寿命が短ければ、そのオブジェクトのクラスの寿命フラグを短寿命にセットする。例えばオブジェクトの領域内にそのオブジェクトが生成された時刻を格納しておき、そのオブジェクトを消去する時刻との差によって、そのオブジェクトの寿命を求める。上記時刻は例えばGCの回数を単位としてもよい。   FIG. 33 is a flowchart showing a procedure for deleting an object. As shown in the figure, when an object is deleted, it is determined whether the life of the object is long or short. If the life is short, the life flag of the class of the object is set to short life. For example, the time when the object is generated is stored in the object area, and the lifetime of the object is obtained based on the difference from the time when the object is deleted. The time may be based on the number of times of GC, for example.

図34はオブジェクトの生成の処理手順を示すフローチャートである。クラスの寿命フラグが短寿命を示していれば、短寿命領域にオブジェクトを生成し、そうでなけば、長寿命領域にオブジェクトを生成する。   FIG. 34 is a flowchart showing a processing procedure for generating an object. If the life flag of the class indicates a short life, an object is generated in the short life area, and if not, an object is generated in the long life area.

このようにオブジェクトの寿命に応じてメモリの割り当て領域を区分することによって、長寿命領域ではフラグメントを大幅に低下でき、メモリの使用効率が向上する。また、例えば寿命領域についてGCを重点的に行うことにより、GCに消費されるCPUパワーを小さくすることができる。   By dividing the memory allocation area according to the lifetime of the object in this way, fragments can be greatly reduced in the long-life area, and the use efficiency of the memory is improved. Further, for example, by concentrating GC on the lifetime region, CPU power consumed by GC can be reduced.

次に、マーク&スイープ法によるインクリメンタルGCについて図35〜48を参照して説明する。   Next, the incremental GC by the mark & sweep method will be described with reference to FIGS.

図35はマーク&スイープ法によるGCの全体の処理手順を示すフローチャートである。このGCはマークテーブルのクリア、上記ツリー探索によるマーク付与およびオブジェクトの消去(スイープ)を繰り返し行う。   FIG. 35 is a flowchart showing the overall processing procedure of GC by the mark and sweep method. This GC repeatedly performs clearing of the mark table, marking by the tree search, and erasing (sweeping) of the object.

図36は図35における「マーククリア」の処理内容を示すフローチャートである。この処理はマークテーブルの内容を一旦クリアするものであり、まずマークテーブルの先頭にポインタを移動し(s131)、その位置のマークをクリアし(s132)、次のマークの位置までポインタを移動させる(s133)。この処理を全てのマークについて繰り返す(s134→s132→・・・)。   FIG. 36 is a flowchart showing the processing content of “mark clear” in FIG. In this process, the contents of the mark table are temporarily cleared. First, the pointer is moved to the head of the mark table (s131), the mark at that position is cleared (s132), and the pointer is moved to the position of the next mark. (S133). This process is repeated for all marks (s134 → s132 →...).

図37は図35における「オブジェクトの消去」の処理内容を示すフローチャートである。先ず、マークテーブルの先頭にポインタを移動させ(s141)、マークの有無を検出し、マークされていなければ、そのマークテーブル上の位置に相当するオブジェクトのヒープ領域内の位置を計算し、該当のオブジェクトを消去する(s142→s143→s144)。続いて、マークテーブルのポインタを次に移動して、同様の処理を繰り返す(s145→s146→s142→・・・)。これによりマークテーブルにマークされているオブジェクトを残し、その他のオブジェクトをヒープ領域から消去する。   FIG. 37 is a flowchart showing the processing content of “delete object” in FIG. First, the pointer is moved to the head of the mark table (s141), the presence / absence of the mark is detected, and if not marked, the position in the heap area of the object corresponding to the position on the mark table is calculated. The object is deleted (s142 → s143 → s144). Subsequently, the pointer of the mark table is moved to the next, and the same processing is repeated (s145 → s146 → s142 →...). This leaves the marked object in the mark table and erases other objects from the heap area.

説明を容易にするために、先ず前提となるマーク&スイープ法におけるマーク付与について説明する。   In order to facilitate the explanation, first, mark provision in the mark & sweep method as a premise will be described.

図38はツリー探索によるマーク付与の手順を示す図である。(A)に示すように、ルートノード10から各ノードへ、ツリー構造で表される参照関係を辿って、参照関係にあるノード(オブジェクト)にマークを付与する。具体的にはマークテーブル上の該当位置のビットをセットする。このツリー構造は、たとえば或るオブジェクトが他のどのオブジェクトを参照しているかを示す、オブジェクト内に設けられる変数の内容によって構成され、このオブジェクトの参照関係を辿ることが、すなわちツリーを辿ることである。   FIG. 38 is a diagram showing a procedure for assigning marks by tree search. As shown in (A), a reference relationship represented by a tree structure is traced from the root node 10 to each node, and a mark is given to a node (object) in the reference relationship. Specifically, the bit at the corresponding position on the mark table is set. This tree structure is composed of, for example, the contents of variables provided in an object that indicate which object an object is referring to, and tracing the reference relationship of this object, that is, following the tree is there.

(A)のように、ノード番号3までマーク付与を行った時点で割込が発生し、その割込処理によって、(B)のように、ルートノードからノード番号7で表されるオブジェクトへの参照関係が絶たれて、ノード番号2で表されるオブジェクトからノード番号7で表されるオブジェクトが参照される関係となれば、割込処理が終了してGCスレッドに戻って、マーク付与を再開したとき、ルートノードからノード番号7で表されるオブジェクトへの参照関係が絶たれているので、(C)に示すようにポインタをルートノードに戻して次の参照関係にあるノード番号8に進むことになる。この時点ではノード番号5,6に対してはマーク付与されない。そこで、参照関係の変更のあったオブジェクトについては、そのオブジェクトからツリーを辿ってそのオブジェクトから参照されているオブジェクトについてマークを付与する必要がある。   As shown in (A), an interrupt occurs when a mark is assigned up to node number 3, and by the interrupt processing, an object represented by node number 7 is obtained from the root node as shown in (B). When the reference relationship is broken and the object represented by node number 7 is referenced from the object represented by node number 2, the interrupt process is completed and the process returns to the GC thread to resume the mark assignment. In this case, since the reference relationship from the root node to the object represented by the node number 7 is broken, the pointer is returned to the root node as shown in (C) and the process proceeds to the node number 8 in the next reference relationship. It will be. At this time, the node numbers 5 and 6 are not marked. Therefore, for an object whose reference relationship has been changed, it is necessary to trace a tree from the object and mark the object referenced from the object.

図39は「オブジェクトの生成」の処理内容を示すフローチャートである。まずカーネルに対してシステムのロックを起動し(s151)、ヒープ領域内の空いている領域を探し(s152)、生成しようとするオブジェクトのサイズより大きな領域に対して必要なサイズを割り当て(s153→s154)、参照変更のマーク付与(ライトバリア)を行い(s155)、システムをアンロックする(s156)。   FIG. 39 is a flowchart showing the processing content of “object generation”. First, a system lock is activated for the kernel (s151), a free area in the heap area is searched (s152), and a necessary size is allocated to an area larger than the size of the object to be generated (s153 → In step s154, a reference change mark is added (write barrier) (s155), and the system is unlocked (s156).

図40は上記「参照変更のマーク付与」の処理手順を示すフローチャートである。先ず、参照変更されたオブジェクトからマークテーブル上の位置を計算し、該当のマークがWhite であるか否かを判定する。このWhite マークはたとえば00の2ビットで表され、未だマークされていない状態を意味する。もし、White マークでなければ、すでにマークされているので、そのまま処理を終了する。White マークであれば、それをGrayにマークする。このGrayマークはたとえば01の2ビットで表され、参照変更のあったオブジェクトであることを意味する。なお、オブジェクトからマークの位置を計算する際、たとえばオブジェクトのアドレスを1/8してオフセットを加えることによって行うか、オブジェクトの通し番号により計算する。   FIG. 40 is a flowchart showing the processing procedure of “reference change mark assignment”. First, the position on the mark table is calculated from the reference-changed object, and it is determined whether or not the corresponding mark is white. This White mark is represented by 2 bits of 00, for example, and means that the mark is not marked yet. If it is not the White mark, it has already been marked, so the processing ends. If it is a White mark, mark it as Gray. This Gray mark is represented by 2 bits of 01, for example, and means that the object has been changed in reference. When calculating the position of the mark from the object, for example, it is performed by adding 1/8 the address of the object and adding an offset, or by calculating the serial number of the object.

図41は「ツリー探索によるマーク付与」の処理手順を示すフローチャートである。まず、ツリーを辿るためのポインタをツリーのルートノードに移動させ(s161)、新たに生成するオブジェクトに対応するマークを付与する(s162)。続いてツリーを辿って、ポインタを次のオブジェクトへ移動させ(s163)、この処理をツリーの最後まで繰り返す(s164→s162→・・・)。その後、各スレッドスタックの先頭へポインタを移動させ(s165)、スタックにあるオブジェクトに対応するマークを付与する(s166)。その後、ポインタをスタックの次に移動させて(s167)、この処理をツリーの最後まで繰り返す(s168→s166→・・・)。その後、スレッドスタックの次に移り(s169)、同様の処理をスレッドスタックの最後まで繰り返す(s170→s166→・・・)。さらにこのスレッドスタックについての処理をすべてのスレッドスタックについて行う(s171→s172→s165→・・・)。この一連のツリー探索において、Grayマークが途中で1度でも検出された場合、もう一度ルートノードから探索およびマーク付与を行う(s173→s161→・・・)。   FIG. 41 is a flowchart showing the processing procedure of “mark addition by tree search”. First, the pointer for tracing the tree is moved to the root node of the tree (s161), and a mark corresponding to the newly generated object is assigned (s162). Subsequently, the tree is traced to move the pointer to the next object (s163), and this process is repeated until the end of the tree (s164 → s162 →...). Thereafter, the pointer is moved to the head of each thread stack (s165), and a mark corresponding to the object on the stack is given (s166). Thereafter, the pointer is moved next to the stack (s167), and this process is repeated until the end of the tree (s168 → s166 →...). Thereafter, the process moves to the next thread stack (s169), and the same processing is repeated until the end of the thread stack (s170 → s166 →...). Further, this thread stack is processed for all thread stacks (s171 → s172 → s165 →...). In this series of tree searches, if the Gray mark is detected even once in the middle, the search and mark assignment are performed again from the root node (s173 → s161 →...).

図42は図41における「オブジェクトに対応するマーク付与」の処理手順を示すフローチャートである。この処理は、生成されているオブジェクトからマークテーブル上の位置を計算し、Black マークを付与する。このBlack マークはたとえば1xの2ビットで表され、マークされている状態を意味する。   FIG. 42 is a flowchart showing the processing procedure of “marking corresponding to object” in FIG. In this process, the position on the mark table is calculated from the generated object, and a black mark is assigned. This black mark is represented by 2 bits of 1x, for example, and means a marked state.

上述したようなマーク付与の方法では、その途中で割込がかかってオブジェクトの参照関係が変化すると、Grayマークが付与されるので、ツリー探索を繰り返さなければならない。場合によってはいつまでたってもマーク付与が完了せずに、GCがいつまでも行われないといった事態に陥る。   In the mark assigning method as described above, if an interrupt is applied in the middle of the change and the object reference relationship changes, a Gray mark is assigned, and thus the tree search must be repeated. In some cases, mark assignment is not completed indefinitely, and GC is not performed indefinitely.

図43は上記の問題を解消するための「ツリー探索によるマーク付与」の手順を示す図である。(A)は図38に示した(A)の状態で割込がかかって参照関係が変化したときの状態を示す。このように、ノード番号3までマーク付与を行った時点で割込が発生し、その割込処理によって、ルートノードからノード番号7で表されるオブジェクトへの参照関係が絶たれて、ノード番号2で表されるオブジェクトからノード番号7で表されるオブジェクトが参照される関係となれば、参照先のノード番号7表すデータをマークスタックに積む。その後、割込処理が終了してGCスレッドに戻って、マーク付与を再開したとき、ルートノードからノード番号7で表されるオブジェクトへの参照関係が絶たれているので、(B)に示すようにポインタをルートノードに戻して次の参照関係にあるノード番号8をマークする。この時点で一通りのツリー探索を終了し、その後は、(C)に示すようにマークスタックの内容によって示されるノードからツリーを辿って参照関係にあるオブジェクトについてマークを付与する。これにより(D)に示すように、参照関係にある全てのオブジェクトについてのマーク付与が完了する。   FIG. 43 is a diagram showing a procedure of “mark addition by tree search” for solving the above problem. (A) shows a state when the reference relationship is changed due to an interruption in the state of (A) shown in FIG. In this way, an interrupt is generated when the mark is assigned up to the node number 3, and the reference process from the root node to the object represented by the node number 7 is cut off by the interrupt process, and the node number 2 If the object represented by the node number 7 is referred to from the object represented by (2), the data representing the node number 7 of the reference destination is loaded on the mark stack. After that, when the interrupt process is completed and the process returns to the GC thread and the mark assignment is resumed, the reference relationship from the root node to the object represented by the node number 7 is cut off, as shown in (B). Return the pointer to the root node to mark node number 8 in the next reference relationship. At this point, the tree search is completed, and thereafter, as shown in (C), a mark is given to an object having a reference relationship by tracing the tree from the node indicated by the contents of the mark stack. As a result, as shown in (D), mark assignment for all objects in the reference relationship is completed.

図44は「参照変更のマーク付与」の処理手順を示すフローチャートである。このように、参照変更されたオブジェクトを示すデータを上記マークスタックに積む。なお、オブジェクトの生成の処理は図39に示したもの変わらない。   FIG. 44 is a flowchart showing the processing procedure of “reference change mark assignment”. In this manner, data indicating the object whose reference has been changed is stacked on the mark stack. The object generation process is the same as that shown in FIG.

図45は、「ツリー探索によるマーク付与」の処理手順を示すフローチャートである。ステップs161〜s172の部分は図41に示したフローチャートのステップs161〜s172と同じである。この図45に示す例では、全スレッドスタックについてのツリー探索を完了した後、マークスタックからデータを取り出し(s181→s182)、そのデータで示されるオブジェクトに対応するマーク付与を行い(s183)、そのオブジェクトからツリーを辿ってツリーの最後まで、参照関係にあるオブジェクトのマーク付与を行う(s184→s185→s183→・・・)。この処理をマークスタックが空になるまでマークスタックのポインタを更新しながら繰り返す(s181→s182→・・・)。   FIG. 45 is a flowchart showing a processing procedure of “mark addition by tree search”. Steps s161 to s172 are the same as steps s161 to s172 in the flowchart shown in FIG. In the example shown in FIG. 45, after completing the tree search for all thread stacks, data is extracted from the mark stack (s181 → s182), and a mark is assigned to the object indicated by the data (s183). The object is traced from the object through the tree to the end of the tree (s184 → s185 → s183 →...). This process is repeated while updating the pointer of the mark stack until the mark stack becomes empty (s181 → s182 →...).

図46は図45における「オブジェクトに対応するマーク付与」の処理手順を示すフローチャートである。この処理は、生成されているオブジェクトからマークテーブル上の位置を計算し、マークを付与する。   FIG. 46 is a flowchart showing the processing procedure of “marking corresponding to object” in FIG. In this process, the position on the mark table is calculated from the generated object, and a mark is given.

このようにマークスタックを用いることによって、ツリー探索をルートノードから再開する必要がなくなり、マーク付与に要する全体の処理時間を大幅に短縮化できる。   By using the mark stack in this way, it is not necessary to restart the tree search from the root node, and the overall processing time required for mark assignment can be greatly shortened.

図47および図48は上記マークスタックを用いてマーク付与を行う場合に、更に無駄な処理時間を無くすようするフローチャートである。
図47は上記「参照変更のマーク付与」の処理手順を示すフローチャートである。先ず、参照変更されたオブジェクトからマークテーブル上の位置を計算し、該当のマークがWhite であるか否かを判定する(s191→s192)。このWhite マークは上述したように未だマークされていない状態を意味する。もし、White マークでなければ、すでにマークされているので、そのまま処理を終了する。White マークであれば、それをGrayにマークする(s193)。上述したようにこのGrayマークは参照変更のあったオブジェクトであることを意味する。続いてマークスタックに参照先のオブジェクトを示すデータを積む(s194)。
FIG. 47 and FIG. 48 are flowcharts for further eliminating unnecessary processing time when the mark is applied using the mark stack.
FIG. 47 is a flowchart showing the processing procedure of “reference change mark assignment”. First, the position on the mark table is calculated from the object whose reference is changed, and it is determined whether or not the corresponding mark is white (s191 → s192). This White mark means that the mark has not been marked as described above. If it is not the White mark, it has already been marked, so the processing ends. If it is a white mark, it is marked as gray (s193). As described above, this Gray mark means an object whose reference has been changed. Subsequently, data indicating the reference destination object is loaded on the mark stack (s194).

図48は上記「オブジェクトに対応するマーク付与」の処理手順を示すフローチャートである。この処理は、生成されているオブジェクトからマークテーブル上の位置を計算し、Black マークを付与する。このBlack マークは上述したように、マークされている状態を意味する。なお、「オブジェクトの生成」の処理は図39に示したものと同様である。   FIG. 48 is a flowchart showing the processing procedure of “marking corresponding to an object”. In this process, the position on the mark table is calculated from the generated object, and a black mark is assigned. This black mark means a marked state as described above. The “object generation” process is the same as that shown in FIG.

このように、参照変更のあったオブジェクトについてマークを付与する場合、そのオブジェクトが初めて検出されたオブジェクトである場合にのみマークを付与するようにしたため、マークスタックの内容によるツリー探索に要する時間およびマークスタックの読み出しに要する時間を短縮化できる。   In this way, when a mark is assigned to an object whose reference has been changed, the mark is attached only when the object is the first detected object, so the time and mark required for tree search based on the contents of the mark stack The time required for reading the stack can be shortened.

なお、参照変更のあったオブジェクトについてのマークを記憶するのはスタックでなくてもよく、FIFOのバッファを用いてもよい。   The mark for the object whose reference has been changed may not be stored in the stack, but a FIFO buffer may be used.

また、実施形態ではマークテーブルにマークを付与するようにしたが、オブジェクトの内部にマーク用の情報を設けて、オブジェクトに直接マークを付与するようにしてもよい。   In the embodiment, the mark is added to the mark table. However, mark information may be provided inside the object to directly add the mark to the object.

実施形態に係る装置のハードウエアの構成を示すブロック図The block diagram which shows the structure of the hardware of the apparatus which concerns on embodiment 同装置のソフトウエアの構成を示すブロック図Block diagram showing the software configuration of the device オブジェクト間の参照関係を示すツリーおよび各スレッドのスタックとの関係を示す図Diagram showing the reference relationship between objects and the relationship with each thread's stack ソフトウエアの機能ブロック図Functional block diagram of software コンパクションの作用を説明するための図Diagram for explaining the effect of compaction コンテキストスイッチの有無によるスレッドの処理内容の変化の例を示す図The figure which shows the example of the change of the processing content of the thread by the presence or absence of context switch 排他制御の処理手順を示すフローチャートFlow chart showing processing procedure of exclusive control コンテキストスイッチ発生有無検出のAPIに関する処理手順を示すフローチャートA flowchart showing a processing procedure related to an API for detecting whether or not a context switch has occurred コンテキストスイッチの処理手順を示すフローチャートFlow chart showing processing procedure of context switch コンパクションの処理手順を示すフローチャートFlow chart showing the compaction process 複写法によるGCの処理手順を示すフローチャートThe flowchart which shows the processing procedure of GC by the copying method 複写法GCにおける排他制御の処理手順を示すフローチャートFlowchart showing processing procedure of exclusive control in copying method GC 複写法GCにおける他の排他制御の処理手順を示すフローチャートThe flowchart which shows the processing procedure of the other exclusive control in the copying method GC 図13における排他制御用APIに関する処理手順を示すフローチャートThe flowchart which shows the process sequence regarding API for exclusive control in FIG. 図13における排他制御用APIに関する処理手順を示すフローチャートThe flowchart which shows the process sequence regarding API for exclusive control in FIG. GCスレッドの優先度の自動切替の例を示す図The figure which shows the example of the automatic switching of the priority of GC thread | sled スレッドの優先度値および優先度時間の切替に関するフローチャートFlowchart for switching thread priority values and priority times GCスレッドの高優先度時間を変更した例を示す図The figure which shows the example which changed the high priority time of GC thread GCスレッドの高優先度時間を変更可能とするためのフローチャートFlow chart for making it possible to change the high priority time of the GC thread GCスレッドの高優先度時間を自動変更する例を示すフローチャートFlowchart showing an example of automatically changing the high priority time of the GC thread GCスレッドの高・低優先度時間の切り替え周期を変更した例を示す図The figure which shows the example which changed the switching cycle of the high / low priority time of GC thread GCスレッドの高・低優先度時間の切り替え周期を変更するためのフローチャートFlowchart for changing the switching cycle of the GC thread high / low priority time 不定期なGC処理の例を示す図The figure which shows the example of irregular GC processing 図21に対応するフローチャートFlowchart corresponding to FIG. 排他制御APIによるGCスレッドの優先度の強制変更の例を示す図The figure which shows the example of the forced change of the priority of the GC thread by exclusive control API 排他制御APIによるGCスレッドの優先度を強制変更するためのフローチャートFlowchart for forcibly changing the priority of a GC thread by exclusive control API GCのアルゴリズムを切り替える処理手順を示すフローチャートThe flowchart which shows the process sequence which switches the algorithm of GC 生成されるオブジェクトのサイズの分布の例を示す図The figure which shows the example of size distribution of the object which is generated オブジェクトのメモリの割り当てサイズの例を示す図Figure showing an example of memory allocation size of an object オブジェクト生成の処理手順を示すフローチャートFlow chart showing the object generation process オブジェクトサイズの分布検知および固定サイズの決定処理に関するフローチャートFlow chart regarding object size distribution detection and fixed size determination processing ヒープ領域の構成を示す図Diagram showing heap area configuration オブジェクト消去の手順を示すフローチャートFlow chart showing the procedure for erasing objects オブジェクト生成の手順を示すフローチャートFlow chart showing object generation procedure マーク&スイープ法によるGCの手順を示すフローチャートFlowchart showing GC procedure by mark & sweep method マーククリアの処理手順を示すフローチャートFlow chart showing mark clear processing procedure オブジェクト消去の処理手順を示すフローチャートFlow chart showing object erasure processing procedure ツリー探索によるマーク付与の例を示す図The figure which shows the example of mark grant by tree search 図38に対応するフローチャートFlowchart corresponding to FIG. 図38に対応するフローチャートFlowchart corresponding to FIG. 図38に対応するフローチャートFlowchart corresponding to FIG. 図38に対応するフローチャートFlowchart corresponding to FIG. ツリー探索によるマーク付与の例を示す図The figure which shows the example of mark grant by tree search 図43に対応するフローチャートFlowchart corresponding to FIG. 図43に対応するフローチャートFlowchart corresponding to FIG. 図43に対応するフローチャートFlowchart corresponding to FIG. 参照変更のマーク付与の他の処理手順を示すフローチャートFlowchart showing another processing procedure for adding a reference change mark オブジェクトに対応するマーク付与の他の処理手順を示すフローチャートFlowchart showing another processing procedure for adding a mark corresponding to an object 固定サイズの設定とオブジェクト生成に関する処理手順を示すフローチャートFlow chart showing processing procedure for fixed size setting and object generation オブジェクトサイズ分布設定に関する処理手順を示すフローチャートFlow chart showing processing procedure for object size distribution setting オブジェクトサイズの分布と分割サイズの例を示す図Figure showing examples of object size distribution and division size ヒープ領域を所定サイズで分割する処理とオブジェクト生成に関する処理手順を示すフローチャートFlow chart showing the processing procedure related to object generation and processing to divide the heap area by a predetermined size ヒープ領域を所定サイズで分割する処理に関する処理手順を示すフローチャートThe flowchart which shows the processing procedure regarding the processing which divides the heap area with the predetermined size 従来のマーク&スイープ法によるGCの手順を示すフローチャートFlowchart showing the procedure of GC by the conventional mark & sweep method

Claims (10)

メモリのヒープ領域内に生成されたオブジェクトの特性を検知する特性検知手段と、
前記特性検知手段が検知した特性に応じて、前記ヒープ領域に対する当該オブジェクトの割り当てを決定する割当決定手段と、を設けたことを特徴とするメモリ割当装置。
Characteristic detection means for detecting characteristics of objects generated in the heap area of the memory;
A memory allocation device comprising: an allocation determination unit that determines allocation of the object to the heap area according to the characteristic detected by the characteristic detection unit.
前記特性検知手段は、前記ヒープ領域内に割り当てられるオブジェクトのサイズの分布を検知する手段であり、
前記割当決定手段は、前記分布の中心より大きな固定サイズの整数倍を前記ヒープ領域に対する新たなオブジェクトの割り当てサイズに決定する割当サイズ決定手段を含む請求項1に記載のメモリ割当装置。
The characteristic detection means is means for detecting a distribution of size of objects allocated in the heap area,
2. The memory allocation apparatus according to claim 1, wherein the allocation determination unit includes an allocation size determination unit that determines an integer multiple of a fixed size larger than the center of the distribution as an allocation size of a new object for the heap area.
前記特性検知手段は、システムの使用開始時にシステムに組み込まれ、前記オブジェクトのサイズの分布を検知した後にシステムから切り離されるプログラムモジュールによるものである請求項2に記載のメモリ割当装置。 3. The memory allocation device according to claim 2, wherein the characteristic detection unit is a program module that is incorporated in the system at the start of use of the system and is separated from the system after detecting the size distribution of the object. 前記割当サイズ決定手段は、システムの使用開始時にシステムに組み込まれ、前記固定サイズが決定された後にシステムから切り離されるプログラムモジュールによるものである請求項2に記載のメモリ割当装置。 3. The memory allocation device according to claim 2, wherein the allocation size determination means is a program module that is incorporated in the system at the start of use of the system and is disconnected from the system after the fixed size is determined. 前記ヒープ領域内を予め複数のサイズに分割するヒープ領域分割手段と、
オブジェクト生成時に当該オブジェクトのサイズより大きく且つ最も小さなサイズの領域を割り当てる手段を設けたことを特徴とする請求項2に記載のメモリ割当装置。
Heap area dividing means for dividing the heap area into a plurality of sizes in advance;
3. The memory allocation apparatus according to claim 2, further comprising means for allocating an area having a size that is larger than and smaller than the size of the object.
前記ヒープ領域分割手段は、前記複数のサイズの分割数と各サイズを引数とするアプリケーションプログラムインタフェースの呼び出しによって、前記ヒープ領域を分割する手段である請求項5に記載のメモリ割当装置。 6. The memory allocation device according to claim 5, wherein the heap area dividing unit is a unit that divides the heap area by calling an application program interface using the division number of the plurality of sizes and each size as an argument. アプリケーションプログラムインタフェースの呼び出しによって前記固定サイズを設定する手段を設けたことを特徴とする請求項2に記載のメモリ割当装置。 3. The memory allocation apparatus according to claim 2, further comprising means for setting the fixed size by calling an application program interface. クラスからオブジェクトが生成された時刻に相当するデータを記憶し、前記オブジェクトを削除する際に、当該オブジェクトの寿命を検出し、該寿命のデータをクラスに設ける手段を備え、
前記特性検知手段は、クラスから生成されたオブジェクトの寿命を検知する手段であり、
前記割当決定手段は、前記特性検知手段により検知されたオブジェクトの寿命に基づいて、このオブジェクトに割り当てる、前記ヒープ領域に対するオブジェクトの生成領域を決定する手段である請求項1に記載のメモリ割当装置。
Storing data corresponding to the time when the object is generated from the class, and when deleting the object, comprising means for detecting the life of the object and providing the data of the life in the class,
The characteristic detection means is means for detecting the lifetime of an object generated from a class,
2. The memory allocation device according to claim 1, wherein the allocation determination unit is a unit that determines an object generation area for the heap area to be allocated to the object based on the lifetime of the object detected by the characteristic detection unit.
メモリのヒープ領域内に生成されたオブジェクトの特性を検知する第1のステップと、
前記第1のステップが検知した特性に応じて、前記ヒープ領域に対する当該オブジェクトの割り当てを決定する第2のステップと、をコンピュータに実行させるメモリ割当方法。
A first step of detecting characteristics of an object generated in a heap area of memory;
A memory allocation method for causing a computer to execute a second step of determining allocation of the object to the heap area according to the characteristic detected by the first step.
メモリのヒープ領域内に生成されたオブジェクトの特性を検知する第1のステップと、
前記第1のステップが検知した特性に応じて、前記ヒープ領域に対する当該オブジェクトの割り当てを決定する第2のステップと、をコンピュータに実行させる処理プログラムを記録したコンピュータ読取可能な記録媒体。
A first step of detecting characteristics of an object generated in a heap area of memory;
A computer-readable recording medium recording a processing program for causing a computer to execute a second step of determining allocation of the object to the heap area according to the characteristic detected by the first step.
JP2006021497A 1997-11-21 2006-01-30 Memory allocation device, memory allocation method, and program recording medium Expired - Fee Related JP4345748B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2006021497A JP4345748B2 (en) 1997-11-21 2006-01-30 Memory allocation device, memory allocation method, and program recording medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
JP32176697 1997-11-21
JP2006021497A JP4345748B2 (en) 1997-11-21 2006-01-30 Memory allocation device, memory allocation method, and program recording medium

Related Parent Applications (1)

Application Number Title Priority Date Filing Date
JP20034599A Division JP3826626B2 (en) 1997-11-21 1999-07-14 Program control apparatus, program control method, and program recording medium

Publications (2)

Publication Number Publication Date
JP2006185456A true JP2006185456A (en) 2006-07-13
JP4345748B2 JP4345748B2 (en) 2009-10-14

Family

ID=36738480

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2006021497A Expired - Fee Related JP4345748B2 (en) 1997-11-21 2006-01-30 Memory allocation device, memory allocation method, and program recording medium

Country Status (1)

Country Link
JP (1) JP4345748B2 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2008135940A (en) * 2006-11-28 2008-06-12 Toshiba Corp Mobile terminal
JP2009003533A (en) * 2007-06-19 2009-01-08 Yahoo Japan Corp Chatbot system
JP2010211644A (en) * 2009-03-11 2010-09-24 Nec Corp Memory power consumption reduction system, method and program

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP2158981B1 (en) * 2007-04-25 2012-07-04 Toyo Seikan Kaisha, Ltd. Stripper for can drawing and ironing device

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2008135940A (en) * 2006-11-28 2008-06-12 Toshiba Corp Mobile terminal
JP2009003533A (en) * 2007-06-19 2009-01-08 Yahoo Japan Corp Chatbot system
JP2010211644A (en) * 2009-03-11 2010-09-24 Nec Corp Memory power consumption reduction system, method and program

Also Published As

Publication number Publication date
JP4345748B2 (en) 2009-10-14

Similar Documents

Publication Publication Date Title
JP3027845B2 (en) Program control device and method
JP4265610B2 (en) Program control apparatus, program control method, and program recording medium
US7167881B2 (en) Method for heap memory management and computer system using the same method
JP4511653B2 (en) Method and apparatus for memory allocation in a multi-threaded virtual machine
US7454447B1 (en) Declarative pinning
US6192517B1 (en) Method, apparatus, and product for improved garbage collection in a memory system through the removal of reference conflicts
US7225439B2 (en) Combining write-barriers within an inner loop with fixed step
US6842759B2 (en) Single-instance class objects across multiple JVM processes in a real-time system
JP4333676B2 (en) Program control apparatus, program control method, and program recording medium
US7412580B1 (en) Concurrent incremental garbage collector with a card table summarizing modified reference locations
EP1659496B1 (en) Garbage collection system
EP3577565B1 (en) Garbage collector
WO2018144286A1 (en) Multiple stage garbage collector
US7620943B1 (en) Using class properties to segregate objects in a generation managed by the train algorithm
US20040186863A1 (en) Elision of write barriers for stores whose values are in close proximity
JP3826626B2 (en) Program control apparatus, program control method, and program recording medium
JP4345748B2 (en) Memory allocation device, memory allocation method, and program recording medium
JP2004503869A (en) Method and apparatus for implementing a modular garbage collector
US7096329B2 (en) Better placement of objects promoted into a generation managed by the train algorithm
CN114051610A (en) Arena-based memory management
CN112313631A (en) Closed-loop garbage collector
US7024437B2 (en) Better placement of objects reachable from special objects during collection based on the train algorithm
EP3807771A1 (en) Arena-based memory management
US20040172428A1 (en) Numbering sequences of cars with the same number in a generation managed by the train algorithm
Charan et al. Development of Real-Time Capability in Application Virtual Machine using Concurrent Automatic Memory Management Algorithm

Legal Events

Date Code Title Description
A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20090116

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20090127

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20090330

RD02 Notification of acceptance of power of attorney

Free format text: JAPANESE INTERMEDIATE CODE: A7422

Effective date: 20090330

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20090511

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20090601

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: 20090623

A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20090706

R150 Certificate of patent or registration of utility model

Free format text: JAPANESE INTERMEDIATE CODE: R150

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20120724

Year of fee payment: 3

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20130724

Year of fee payment: 4

LAPS Cancellation because of no payment of annual fees