hotspot/src/share/vm/oops/oop.pcgc.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 2005-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 oopDesc::update_contents(ParCompactionManager* cm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
  // The klass field must be updated before anything else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
  // can be done.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
  DEBUG_ONLY(klassOopDesc* original_klass = klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  // Can the option to update and/or copy be moved up in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  // call chain to avoid calling into here?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  if (PSParallelCompact::should_update_klass(klass())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
    update_header();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    assert(klass()->is_klass(), "Not updated correctly");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    assert(klass()->is_klass(), "Not updated");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  Klass* new_klass = blueprint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  if (!new_klass->oop_is_typeArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    // It might contain oops beyond the header, so take the virtual call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    new_klass->oop_update_pointers(cm, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // Else skip it.  The typeArrayKlass in the header never needs scavenging.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
inline void oopDesc::update_contents(ParCompactionManager* cm,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
                                     HeapWord* begin_limit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
                                     HeapWord* end_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // The klass field must be updated before anything else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // can be done.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  debug_only(klassOopDesc* original_klass = klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  update_contents(cm, klass(), begin_limit, end_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
inline void oopDesc::update_contents(ParCompactionManager* cm,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
                                     klassOop old_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
                                     HeapWord* begin_limit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
                                     HeapWord* end_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  klassOop updated_klass =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    PSParallelCompact::summary_data().calc_new_klass(old_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Needs to be boundary aware for the 64 bit case
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // update_header();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // The klass has moved.  Is the location of the klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // within the limits?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  if ((((HeapWord*)&_klass) >= begin_limit) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
      (((HeapWord*)&_klass) < end_limit)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    set_klass(updated_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  Klass* klass = updated_klass->klass_part();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  if (!klass->oop_is_typeArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    // It might contain oops beyond the header, so take the virtual call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    klass->oop_update_pointers(cm, this, begin_limit, end_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Else skip it.  The typeArrayKlass in the header never needs scavenging.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
inline void oopDesc::follow_contents(ParCompactionManager* cm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  assert (PSParallelCompact::mark_bitmap()->is_marked(this),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    "should be marked");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  blueprint()->oop_follow_contents(cm, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
// Used by parallel old GC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
inline void oopDesc::follow_header(ParCompactionManager* cm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  PSParallelCompact::mark_and_push(cm, (oop*)&_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
inline oop oopDesc::forward_to_atomic(oop p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  assert(ParNewGeneration::is_legal_forward_ptr(p),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
         "illegal forwarding pointer value.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  markOop oldMark = mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  markOop forwardPtrMark = markOopDesc::encode_pointer_as_mark(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  markOop curMark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  assert(forwardPtrMark->decode_pointer() == p, "encoding must be reversable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  assert(sizeof(markOop) == sizeof(intptr_t), "CAS below requires this.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  while (!is_forwarded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    curMark = (markOop)Atomic::cmpxchg_ptr(forwardPtrMark, &_mark, oldMark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    if (curMark == oldMark) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      assert(is_forwarded(), "the CAS should have succeeded.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    oldMark = curMark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  return forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
inline void oopDesc::update_header() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  PSParallelCompact::adjust_pointer((oop*)&_klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
inline void oopDesc::update_header(HeapWord* beg_addr, HeapWord* end_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  PSParallelCompact::adjust_pointer((oop*)&_klass, beg_addr, end_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}