hotspot/src/share/vm/memory/genOopClosures.inline.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 360 21d113ecbf6a
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2001-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
inline OopsInGenClosure::OopsInGenClosure(Generation* gen) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
  OopClosure(gen->ref_processor()), _orig_gen(gen), _rs(NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
  set_generation(gen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
inline void OopsInGenClosure::set_generation(Generation* gen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  _gen = gen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  _gen_boundary = _gen->reserved().start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // Barrier set for the heap, must be set after heap is initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  if (_rs == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    GenRemSet* rs = SharedHeap::heap()->rem_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    assert(rs->rs_kind() == GenRemSet::CardTable, "Wrong rem set kind");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    _rs = (CardTableRS*)rs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
inline void OopsInGenClosure::do_barrier(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  assert(generation()->is_in_reserved(p), "expected ref in generation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  oop obj = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  assert(obj != NULL, "expected non-null object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // If p points to a younger generation, mark the card.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  if ((HeapWord*)obj < _gen_boundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    _rs->inline_write_ref_field_gc(p, obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// NOTE! Any changes made here should also be made
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// in FastScanClosure::do_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
inline void ScanClosure::do_oop(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  oop obj = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // Should we copy the obj?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  if (obj != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    if ((HeapWord*)obj < _boundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      if (obj->is_forwarded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
        *p = obj->forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
        *p = _g->copy_to_survivor_space(obj, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    if (_gc_barrier) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      // Now call parent closure
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      do_barrier(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
inline void ScanClosure::do_oop_nv(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  ScanClosure::do_oop(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
// NOTE! Any changes made here should also be made
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// in ScanClosure::do_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
inline void FastScanClosure::do_oop(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  oop obj = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Should we copy the obj?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  if (obj != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    if ((HeapWord*)obj < _boundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      if (obj->is_forwarded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
        *p = obj->forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
        *p = _g->copy_to_survivor_space(obj, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      if (_gc_barrier) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
        // Now call parent closure
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        do_barrier(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
inline void FastScanClosure::do_oop_nv(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  FastScanClosure::do_oop(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
// Note similarity to ScanClosure; the difference is that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
// the barrier set is taken care of outside this closure.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
inline void ScanWeakRefClosure::do_oop(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  oop obj = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  assert (obj != NULL, "null weak reference?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // weak references are sometimes scanned twice; must check
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // that to-space doesn't already contain this object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  if ((HeapWord*)obj < _boundary && !_g->to()->is_in_reserved(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    if (obj->is_forwarded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      *p = obj->forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      *p = _g->copy_to_survivor_space(obj, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
inline void ScanWeakRefClosure::do_oop_nv(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  ScanWeakRefClosure::do_oop(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}