MMTk代码学习(整体结构)
必要的整体模块
对于一个完整的内存管理工具,主要涉及:
内存映射(Address)内存组织结构(Resource,Page)基于内存结构的策略:分配、回收(Alloc, Collect)org.jikesrvm.mm.mminterface.MemoryManager
/** * Allocate a scalar object. * * @param size Size in bytes of the object, including any headers * that need space. * @param tib Type of the object (pointer to TIB). * @param allocator Specify which allocation scheme/area JMTk should * allocate the memory from. * @param align the alignment requested; must be a power of 2. * @param offset the offset at which the alignment is desired. * @param site allocation site. * @return the initialized Object */ @Inline public static Object allocateScalar(int size, TIB tib, int allocator, int align, int offset, int site) { Selected.Mutator mutator = Selected.Mutator.get(); allocator = mutator.checkAllocator(org.jikesrvm.runtime.Memory.alignUp(size, MIN_ALIGNMENT), align, allocator); Address region = allocateSpace(mutator, size, align, offset, allocator, site); Object result = ObjectModel.initializeScalar(region, tib, size); mutator.postAlloc(ObjectReference.fromObject(result), ObjectReference.fromObject(tib), size, allocator); return result; }
allocSlow
主动调用org.jikesrvm.mm.mminterface.MemoryManager
/** * External call to force a garbage collection. */ @Interruptible public static void gc() { Selected.Plan.handleUserCollectionRequest(); }