psScavenge.inline.hpp 4.1 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29 30 31 32
#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP
#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP

#include "gc_implementation/parallelScavenge/cardTableExtension.hpp"
#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
#include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
#include "gc_implementation/parallelScavenge/psScavenge.hpp"

D
duke 已提交
33 34 35 36 37
inline void PSScavenge::save_to_space_top_before_gc() {
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
  _to_space_top_before_gc = heap->young_gen()->to_space()->top();
}

38 39 40 41 42
template <class T> inline bool PSScavenge::should_scavenge(T* p) {
  T heap_oop = oopDesc::load_heap_oop(p);
  if (oopDesc::is_null(heap_oop)) return false;
  oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  return PSScavenge::is_obj_in_young((HeapWord*)obj);
D
duke 已提交
43 44
}

45 46
template <class T>
inline bool PSScavenge::should_scavenge(T* p, MutableSpace* to_space) {
D
duke 已提交
47
  if (should_scavenge(p)) {
48
    oop obj = oopDesc::load_decode_heap_oop_not_null(p);
D
duke 已提交
49
    // Skip objects copied to to_space since the scavenge started.
50
    HeapWord* const addr = (HeapWord*)obj;
D
duke 已提交
51 52 53 54 55
    return addr < to_space_top_before_gc() || addr >= to_space->end();
  }
  return false;
}

56 57
template <class T>
inline bool PSScavenge::should_scavenge(T* p, bool check_to_space) {
D
duke 已提交
58
  if (check_to_space) {
59
    ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
D
duke 已提交
60 61 62 63 64 65 66 67
    return should_scavenge(p, heap->young_gen()->to_space());
  }
  return should_scavenge(p);
}

// Attempt to "claim" oop at p via CAS, push the new obj if successful
// This version tests the oop* to make sure it is within the heap before
// attempting marking.
68
template <class T>
D
duke 已提交
69
inline void PSScavenge::copy_and_push_safe_barrier(PSPromotionManager* pm,
70 71
                                                   T*                  p) {
  assert(should_scavenge(p, true), "revisiting object?");
D
duke 已提交
72

73 74 75
  oop o = oopDesc::load_decode_heap_oop_not_null(p);
  oop new_obj = o->is_forwarded()
        ? o->forwardee()
76
        : pm->copy_to_survivor_space(o);
77
  oopDesc::encode_store_heap_oop_not_null(p, new_obj);
D
duke 已提交
78 79 80

  // We cannot mark without test, as some code passes us pointers
  // that are outside the heap.
81
  if ((!PSScavenge::is_obj_in_young((HeapWord*)p)) &&
D
duke 已提交
82
      Universe::heap()->is_in_reserved(p)) {
83 84
    if (PSScavenge::is_obj_in_young((HeapWord*)new_obj)) {
      card_table()->inline_write_ref_field_gc(p, new_obj);
D
duke 已提交
85 86 87
    }
  }
}
88

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
class PSScavengeRootsClosure: public OopClosure {
 private:
  PSPromotionManager* _promotion_manager;

 protected:
  template <class T> void do_oop_work(T *p) {
    if (PSScavenge::should_scavenge(p)) {
      // We never card mark roots, maybe call a func without test?
      PSScavenge::copy_and_push_safe_barrier(_promotion_manager, p);
    }
  }
 public:
  PSScavengeRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
  void do_oop(oop* p)       { PSScavengeRootsClosure::do_oop_work(p); }
  void do_oop(narrowOop* p) { PSScavengeRootsClosure::do_oop_work(p); }
};

106
#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSSCAVENGE_INLINE_HPP