hotspot/src/share/vm/gc_implementation/parNew/parOopClosures.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 (c) 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 void ParScanWeakRefClosure::do_oop(oop* p)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
  oop obj = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
  assert (obj != NULL, "null weak reference?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  // weak references are sometimes scanned twice; must check
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  // that to-space doesn't already contain this object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  if ((HeapWord*)obj < _boundary && !_g->to()->is_in_reserved(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
    // we need to ensure that it is copied (see comment in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
    // ParScanClosure::do_oop_work).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
    klassOop objK = obj->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    markOop m = obj->mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    if (m->is_marked()) { // Contains forwarding pointer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
      *p = ParNewGeneration::real_forwardee(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
      size_t obj_sz = obj->size_given_klass(objK->klass_part());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
      *p = ((ParNewGeneration*)_g)->copy_to_survivor_space(_par_scan_state,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
                                                           obj, obj_sz, m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
inline void ParScanWeakRefClosure::do_oop_nv(oop* p)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  ParScanWeakRefClosure::do_oop(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
inline void ParScanClosure::par_do_barrier(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  assert(generation()->is_in_reserved(p), "expected ref in generation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  oop obj = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  assert(obj != NULL, "expected non-null object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // If p points to a younger generation, mark the card.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  if ((HeapWord*)obj < gen_boundary()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    rs()->write_ref_field_gc_par(p, obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
inline void ParScanClosure::do_oop_work(oop* p,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
                                        bool gc_barrier,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
                                        bool root_scan) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  oop obj = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  assert((!Universe::heap()->is_in_reserved(p) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
          generation()->is_in_reserved(p))
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
         && (generation()->level() == 0 || gc_barrier),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
         "The gen must be right, and we must be doing the barrier "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
         "in older generations.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  if (obj != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    if ((HeapWord*)obj < _boundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      assert(!_g->to()->is_in_reserved(obj), "Scanning field twice?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      // OK, we need to ensure that it is copied.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      // We read the klass and mark in this order, so that we can reliably
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      // get the size of the object: if the mark we read is not a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      // forwarding pointer, then the klass is valid: the klass is only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      // overwritten with an overflow next pointer after the object is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      // forwarded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      klassOop objK = obj->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      markOop m = obj->mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
      if (m->is_marked()) { // Contains forwarding pointer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
        *p = ParNewGeneration::real_forwardee(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
        size_t obj_sz = obj->size_given_klass(objK->klass_part());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
        *p = _g->copy_to_survivor_space(_par_scan_state, obj, obj_sz, m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
        if (root_scan) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
          // This may have pushed an object.  If we have a root
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
          // category with a lot of roots, can't let the queue get too
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
          // full:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
          (void)_par_scan_state->trim_queues(10 * ParallelGCThreads);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      if (gc_barrier) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        // Now call parent closure
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
        par_do_barrier(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}