java – G1 gc上的“Ext Root Scanning”的文档/代码/详细解释?

前端之家收集整理的这篇文章主要介绍了java – G1 gc上的“Ext Root Scanning”的文档/代码/详细解释?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1]任何人都可以指向文档或详细解释“Ext Root Scanning”在G1 GC中是如何工作的,特别是对于JNI句柄吗? (如果可能请特定于Java 7)

2]奖励:我们期望G1 gc的openJDK代码与Hotspot有什么不同?如果我们可以期望它是相同的,那么请指出用于G1 GC ext root扫描的openJDK代码的相关部分吗?

谢谢

最佳答案
概观

Oracle Doc开始:

When performing garbage collections,G1 operates in a manner similar to the CMS collector. G1 performs a concurrent global marking phase to determine the liveness of objects throughout the heap.

而外部根区扫描是标记过程的一个阶段.

来自Java Performance Companion:

During this phase the external (off-heap) roots such as the JVM’s system dictionary,VM data structures,JNI thread handles,hardware registers,global variables,and thread stack roots are scanned to find out if any point into the current pause’s collection set (CSet).

细节和代码

是的,我们可以预期openjdk和hotspot的g1代码here所述相同.所以我们可以通过阅读源代码来解释详细过程.

G1CollectedHeap

void
G1CollectedHeap::
g1_process_strong_roots(bool collecting_perm_gen,SharedHeap::ScanningOption so,OopClosure* scan_non_heap_roots,OopsInHeapRegionClosure* scan_rs,OopsInGenClosure* scan_perm,int worker_i) {
  //...
  process_strong_roots(false,// no scoping; this is parallel code
                       collecting_perm_gen,so,&buf_scan_non_heap_roots,&eager_scan_code_roots,&buf_scan_perm);
  //...
}

然后在process_strong_roots中:

  // Global (strong) JNI handles
  if (!_process_strong_tasks->is_task_claimed(SH_PS_JNIHandles_oops_do))
    JNIHandles::oops_do(roots);

关于JNI的核心过程:它迭代JNI处理块并找出这个句柄块的oops(oop:Java的引用抽象)是否指向堆区域,这意味着这个JNI oop是否可以作为gc的根.

for (JNIHandleBlock* current = current_chain; current != NULL;
     current = current->_next) {
  assert(current == current_chain || current->pop_frame_link() == NULL,"only blocks first in chain should have pop frame link set");
  for (int index = 0; index < current->_top; index++) {
    oop* root = &(current->_handles)[index];
    oop value = *root;
    // traverse heap pointers only,not deleted handles or free list
    // pointers
    if (value != NULL && Universe::heap()->is_in_reserved(value)) {
      f->do_oop(root);
    }
  }
  // the next handle block is valid only if current block is full
  if (current->_top < block_size_in_oops) {
    break;
  }
}

然后,在数组中记住这个根,当数组已满时由OopClosure处理,在这种情况下,迭代root的引用以标记活动对象.

更多:

> Code with comments

原文链接:https://www.f2er.com/java/437398.html

猜你在找的Java相关文章