MMTk代码学习(整体结构)

必要的整体模块

对于一个完整的内存管理工具,主要涉及:

  • 内存映射(Address)
  • 内存组织结构(Resource,Page)
  • 基于内存结构的策略:分配、回收(Alloc, Collect)
  • 内存跟踪(Trace, Log)

对应到MMTk的具体模块

系统结构

  • Plan

     
  • CollectorContext, MutatorContext 上下文环境
    • 所有collector都继承于CollectorContext(包含有run()方法接口用于线程化) TLS(Thread Local storage)

       
    • 所有mutator都继承于MutatorContext

       
  • Phase, ConcurrentPhase, ComplexPhase:将GC分成多个过程,整个GC由若干Phase组成

内存映射

  • Address

内存组织结构

  • PageResource
  • FreeListPageResource
  • MonotonePageResource

主要流程

初始化

  1. enableAllocation: allow allocation (but not collection).
  2. processOptions: the VM has parsed/prepared options for MMTk to react to.
  3. enableCollection: the VM can support the spawning of MMTk collector contexts.
  4. fullyBooted: control is jst about to be given to application code.

分配对象

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;
  }
  1. checkAllocator: 选择一个合适的allocator
  2. allocateSpace: mutator.alloc(allocSlow:可能调用GC)
  3. 初始化对象数据
  4. mutator.postAlloc

垃圾收集

Alloc时触发

allocSlow

主动调用

org.jikesrvm.mm.mminterface.MemoryManager

  /**
   * External call to force a garbage collection.
   */
  @Interruptible
  public static void gc() {
    Selected.Plan.handleUserCollectionRequest();
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值