Example #1
0
  public void copyCollect(GcIntList roots, GcHeap sourceHeap, GcHeap targetHeap) {
    if (sourceHeap.heapIndex == 0 || sourceHeap.isEmpty()) {
      throw new IllegalStateException("invalid source heap #" + sourceHeap.heapIndex);
    }
    if (targetHeap.heapIndex == 0 || !targetHeap.isEmpty()) {
      throw new IllegalStateException("invalid target heap #" + targetHeap.heapIndex);
    }

    this.sourceHeap = sourceHeap;
    this.targetHeap = targetHeap;

    this.flag = flag_provider.incrementAndGet();

    for (int i = 0; i < roots.size(); i++) {
      int newRoot = this.traceAndMarkAndRewritePointers(roots.get(i));
      if (newRoot > 0) {
        roots.set(i, newRoot);
      }
    }

    sourceHeap.free();
  }
Example #2
0
  public void mergeCopyCollect(
      GcIntList roots,
      GcHeap sourceHeap1,
      GcHeap sourceHeap2,
      final GcHeap targetHeap1,
      final GcHeap targetHeap2) {
    copyCollect(roots, sourceHeap1, targetHeap1);
    copyCollect(roots, sourceHeap2, targetHeap2);

    if (targetHeap1.used() + targetHeap2.used() > sourceHeap1.space) {
      throw new IllegalStateException();
    }

    final GcHeap small1 = targetHeap1;
    final GcHeap small2 = targetHeap2;
    new Gc(memory) {
      @Override
      boolean shouldMoveObject(int object) {
        return (object / memory.heapSize == small1.heapIndex)
            || //
            (object / memory.heapSize == small2.heapIndex);
      }
    }.copyCollect(roots, small1 /* dummy */, sourceHeap1);
  }