ManagementFactory クラスを介して取得できるMXBeanの一つが実装するインタフェース。
- java.lang.management パッケージ - ManagementFactory クラス - HHeLiBeXの日記 正道編
- MemoryManagerMXBean (Java 2 Platform SE 5.0)
Java VMのメモリマネージャに関する情報を取得するためのインタフェース。メモリマネージャはJava VM中の1つ以上のメモリプールを管理する。以上、APIドキュメントの棒読み(謎)。この明確に説明できないあたり、ちゃんと勉強しなおさないとだめだな。
それはそれとして、とりあえず実際に実行してみる。
今回用いたのは、次のJava VM。
import java.lang.management.GarbageCollectorMXBean; import java.lang.management.ManagementFactory; import java.lang.management.MemoryManagerMXBean; import java.util.List; public class Main { /** * @param args */ public static void main(String[] args) { System.out.printf("%-20s = %s\n", "java.version", System.getProperty("java.version")); System.out.printf("%-20s = %s\n", "java.vendor", System.getProperty("java.vendor")); System.out.printf("%-20s = %s\n", "java.runtime.version", System.getProperty("java.runtime.version")); System.out.printf("%-20s = %s\n", "os.name", System.getProperty("os.name")); System.out.println("========"); List<MemoryManagerMXBean> memoryManagerMXBeans = ManagementFactory.getMemoryManagerMXBeans(); System.out.printf("%-20s: %s\n", "number of MXBeans", memoryManagerMXBeans.size()); { int i = 0; for (MemoryManagerMXBean memoryManagerMXBean : memoryManagerMXBeans) { System.out.printf("[%2d]\n", i); System.out.printf(" %-24s: %s\n", "GarbageCollectorMXBean?", (memoryManagerMXBean instanceof GarbageCollectorMXBean)); System.out.printf(" %s\n", "--------"); System.out.printf(" %-24s: %s\n", "name", memoryManagerMXBean.getName()); String[] memoryPoolNames = memoryManagerMXBean.getMemoryPoolNames(); System.out.printf(" %-24s: %s\n", "memoryPoolNames.length", memoryPoolNames.length); for (int j = 0; j < memoryPoolNames.length; ++j) { System.out.printf(" %-20s[%2d]: %s\n", "memoryPoolName", j, memoryPoolNames[j]); } System.out.printf(" %-24s: %s\n", "isValid", memoryManagerMXBean.isValid()); ++i; } } } }
MemoryManagerMXBeanのサブインタフェースとしてGarbageCollectorMXBeanがあるので、GarbageCollectorMXBeanなのかそうでないのかも併せて判定して表示。
Sun Java 2 SDK 1.5.0_11
java.version = 1.5.0_11
java.vendor = Sun Microsystems Inc.
java.runtime.version = 1.5.0_11-b03
os.name = Windows Vista
========
number of MXBeans : 3
[ 0]
GarbageCollectorMXBean? : false
--------
name : CodeCacheManager
memoryPoolNames.length : 1
memoryPoolName [ 0]: Code Cache
isValid : true
[ 1]
GarbageCollectorMXBean? : true
--------
name : Copy
memoryPoolNames.length : 2
memoryPoolName [ 0]: Eden Space
memoryPoolName [ 1]: Survivor Space
isValid : true
[ 2]
GarbageCollectorMXBean? : true
--------
name : MarkSweepCompact
memoryPoolNames.length : 6
memoryPoolName [ 0]: Eden Space
memoryPoolName [ 1]: Survivor Space
memoryPoolName [ 2]: Tenured Gen
memoryPoolName [ 3]: Perm Gen
memoryPoolName [ 4]: Perm Gen [shared-ro]
memoryPoolName [ 5]: Perm Gen [shared-rw]
isValid : true
java.version = 1.5.0
java.vendor = IBM Corporation
java.runtime.version = pwi32dev-20090707 (SR10 )
os.name = Windows Vista
========
number of MXBeans : 2
[ 0]
GarbageCollectorMXBean? : false
--------
name : J9 non-heap manager
memoryPoolNames.length : 4
memoryPoolName [ 0]: class storage
memoryPoolName [ 1]: JIT code cache
memoryPoolName [ 2]: JIT data cache
memoryPoolName [ 3]: miscellaneous non-heap storage
isValid : true
[ 1]
GarbageCollectorMXBean? : true
--------
name : J9 GC
memoryPoolNames.length : 1
memoryPoolName [ 0]: Java heap
isValid : true大雑把に言えば、ヒープメモリを管理するメモリマネージャはGarbageCollectorMXBean。逆にGarbageCollectorMXBeanでないものはヒープメモリ以外で管理するもの、例えばClassオブジェクトとかバイトコードをコンパイルしたネイティブコードとかを保持するメモリ領域を管理するメモリマネージャ、ということか。