hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp
author jrose
Tue, 15 Sep 2009 21:53:47 -0700
changeset 3908 24b55ad4c228
parent 670 ddf3e9583f2f
child 3912 3aaaaad1ccb0
permissions -rw-r--r--
6863023: need non-perm oops in code cache for JSR 292 Summary: Make a special root-list for those few nmethods which might contain non-perm oops. Reviewed-by: twisti, kvn, never, jmasa, ysr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
670
ddf3e9583f2f 6719955: Update copyright year
xdono
parents: 360
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
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
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_markSweep.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
GrowableArray<oop>*     MarkSweep::_marking_stack       = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
GrowableArray<Klass*>*  MarkSweep::_revisit_klass_stack = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
GrowableArray<oop>*     MarkSweep::_preserved_oop_stack = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
GrowableArray<markOop>* MarkSweep::_preserved_mark_stack= NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
size_t                  MarkSweep::_preserved_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
size_t                  MarkSweep::_preserved_count_max = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
PreservedMark*          MarkSweep::_preserved_marks = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
ReferenceProcessor*     MarkSweep::_ref_processor   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
#ifdef VALIDATE_MARK_SWEEP
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    39
GrowableArray<void*>*   MarkSweep::_root_refs_stack = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
GrowableArray<oop> *    MarkSweep::_live_oops = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
GrowableArray<oop> *    MarkSweep::_live_oops_moved_to = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
GrowableArray<size_t>*  MarkSweep::_live_oops_size = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
size_t                  MarkSweep::_live_oops_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
size_t                  MarkSweep::_live_oops_index_at_perm = 0;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    45
GrowableArray<void*>*   MarkSweep::_other_refs_stack = NULL;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    46
GrowableArray<void*>*   MarkSweep::_adjusted_pointers = NULL;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    47
bool                         MarkSweep::_pointer_tracking = false;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    48
bool                         MarkSweep::_root_tracking = true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops_moved_to = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
GrowableArray<size_t>   * MarkSweep::_cur_gc_live_oops_size = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops_moved_to = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
GrowableArray<size_t>   * MarkSweep::_last_gc_live_oops_size = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
void MarkSweep::revisit_weak_klass_link(Klass* k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _revisit_klass_stack->push(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
void MarkSweep::follow_weak_klass_links() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // All klasses on the revisit stack are marked at this point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // Update and follow all subklass, sibling and implementor links.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  for (int i = 0; i < _revisit_klass_stack->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    _revisit_klass_stack->at(i)->follow_weak_klass_links(&is_alive,&keep_alive);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  follow_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    71
MarkSweep::FollowRootClosure  MarkSweep::follow_root_closure;
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 670
diff changeset
    72
CodeBlobToOopClosure MarkSweep::follow_code_root_closure(&MarkSweep::follow_root_closure, /*do_marking=*/ true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    74
void MarkSweep::FollowRootClosure::do_oop(oop* p)       { follow_root(p); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    75
void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    79
void MarkSweep::MarkAndPushClosure::do_oop(oop* p)       { mark_and_push(p); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    80
void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
void MarkSweep::follow_stack() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  while (!_marking_stack->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    oop obj = _marking_stack->pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    assert (obj->is_gc_marked(), "p must be marked");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    obj->follow_contents();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    92
void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
// We preserve the mark which should be replaced at the end and the location that it
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
// will go.  Note that the object that this markOop belongs to isn't currently at that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
// address but it will be after phase4
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
void MarkSweep::preserve_mark(oop obj, markOop mark) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // we try to store preserved marks in the to space of the new generation since this
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // is storage which should be available.  Most of the time this should be sufficient
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // space for the marks we need to preserve but if it isn't we fall back in using
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // GrowableArrays to keep track of the overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  if (_preserved_count < _preserved_count_max) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    _preserved_marks[_preserved_count++].init(obj, mark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    if (_preserved_mark_stack == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      _preserved_mark_stack = new (ResourceObj::C_HEAP) GrowableArray<markOop>(40, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      _preserved_oop_stack = new (ResourceObj::C_HEAP) GrowableArray<oop>(40, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    _preserved_mark_stack->push(mark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    _preserved_oop_stack->push(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
MarkSweep::AdjustPointerClosure MarkSweep::adjust_root_pointer_closure(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   117
void MarkSweep::AdjustPointerClosure::do_oop(oop* p)       { adjust_pointer(p, _is_root); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   118
void MarkSweep::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p, _is_root); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   119
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
void MarkSweep::adjust_marks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  assert(_preserved_oop_stack == NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
         _preserved_oop_stack->length() == _preserved_mark_stack->length(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
         "inconsistent preserved oop stacks");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // adjust the oops we saved earlier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  for (size_t i = 0; i < _preserved_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    _preserved_marks[i].adjust_pointer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // deal with the overflow stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  if (_preserved_oop_stack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    for (int i = 0; i < _preserved_oop_stack->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      oop* p = _preserved_oop_stack->adr_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      adjust_pointer(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
void MarkSweep::restore_marks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  assert(_preserved_oop_stack == NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
         _preserved_oop_stack->length() == _preserved_mark_stack->length(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
         "inconsistent preserved oop stacks");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (PrintGC && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    gclog_or_tty->print_cr("Restoring %d marks", _preserved_count +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
                  (_preserved_oop_stack ? _preserved_oop_stack->length() : 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // restore the marks we saved earlier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  for (size_t i = 0; i < _preserved_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    _preserved_marks[i].restore();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // deal with the overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  if (_preserved_oop_stack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    for (int i = 0; i < _preserved_oop_stack->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      oop obj       = _preserved_oop_stack->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      markOop mark  = _preserved_mark_stack->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      obj->set_mark(mark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
#ifdef VALIDATE_MARK_SWEEP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   165
void MarkSweep::track_adjusted_pointer(void* p, bool isroot) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  if (!ValidateMarkSweep)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  if (!isroot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    if (_pointer_tracking) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      guarantee(_adjusted_pointers->contains(p), "should have seen this pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      _adjusted_pointers->remove(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    ptrdiff_t index = _root_refs_stack->find(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    if (index != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      int l = _root_refs_stack->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      if (l > 0 && l - 1 != index) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   179
        void* last = _root_refs_stack->pop();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        assert(last != p, "should be different");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
        _root_refs_stack->at_put(index, last);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        _root_refs_stack->remove(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   189
void MarkSweep::check_adjust_pointer(void* p) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  _adjusted_pointers->push(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
class AdjusterTracker: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
 public:
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   195
  AdjusterTracker() {}
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   196
  void do_oop(oop* o)       { MarkSweep::check_adjust_pointer(o); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   197
  void do_oop(narrowOop* o) { MarkSweep::check_adjust_pointer(o); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
void MarkSweep::track_interior_pointers(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    _adjusted_pointers->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    _pointer_tracking = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    AdjusterTracker checker;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    obj->oop_iterate(&checker);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
void MarkSweep::check_interior_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    _pointer_tracking = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    guarantee(_adjusted_pointers->length() == 0, "should have processed the same pointers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
void MarkSweep::reset_live_oop_tracking(bool at_perm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    guarantee((size_t)_live_oops->length() == _live_oops_index, "should be at end of live oops");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    _live_oops_index = at_perm ? _live_oops_index_at_perm : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
void MarkSweep::register_live_oop(oop p, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    _live_oops->push(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    _live_oops_size->push(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    _live_oops_index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
void MarkSweep::validate_live_oop(oop p, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    oop obj = _live_oops->at((int)_live_oops_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    guarantee(obj == p, "should be the same object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    guarantee(_live_oops_size->at((int)_live_oops_index) == size, "should be the same size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    _live_oops_index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
void MarkSweep::live_oop_moved_to(HeapWord* q, size_t size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
                                  HeapWord* compaction_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  assert(oop(q)->forwardee() == NULL || oop(q)->forwardee() == oop(compaction_top),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
         "should be moved to forwarded location");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    MarkSweep::validate_live_oop(oop(q), size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    _live_oops_moved_to->push(oop(compaction_top));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  if (RecordMarkSweepCompaction) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    _cur_gc_live_oops->push(q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    _cur_gc_live_oops_moved_to->push(compaction_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    _cur_gc_live_oops_size->push(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
void MarkSweep::compaction_complete() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  if (RecordMarkSweepCompaction) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    GrowableArray<HeapWord*>* _tmp_live_oops          = _cur_gc_live_oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    GrowableArray<HeapWord*>* _tmp_live_oops_moved_to = _cur_gc_live_oops_moved_to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    GrowableArray<size_t>   * _tmp_live_oops_size     = _cur_gc_live_oops_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    _cur_gc_live_oops           = _last_gc_live_oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    _cur_gc_live_oops_moved_to  = _last_gc_live_oops_moved_to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    _cur_gc_live_oops_size      = _last_gc_live_oops_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    _last_gc_live_oops          = _tmp_live_oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    _last_gc_live_oops_moved_to = _tmp_live_oops_moved_to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    _last_gc_live_oops_size     = _tmp_live_oops_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
void MarkSweep::print_new_location_of_heap_address(HeapWord* q) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  if (!RecordMarkSweepCompaction) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    tty->print_cr("Requires RecordMarkSweepCompaction to be enabled");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  if (_last_gc_live_oops == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    tty->print_cr("No compaction information gathered yet");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  for (int i = 0; i < _last_gc_live_oops->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    HeapWord* old_oop = _last_gc_live_oops->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    size_t    sz      = _last_gc_live_oops_size->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    if (old_oop <= q && q < (old_oop + sz)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      HeapWord* new_oop = _last_gc_live_oops_moved_to->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
      size_t offset = (q - old_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      tty->print_cr("Address " PTR_FORMAT, q);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   289
      tty->print_cr(" Was in oop " PTR_FORMAT ", size " SIZE_FORMAT ", at offset " SIZE_FORMAT, old_oop, sz, offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
      tty->print_cr(" Now in oop " PTR_FORMAT ", actual address " PTR_FORMAT, new_oop, new_oop + offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  tty->print_cr("Address " PTR_FORMAT " not found in live oop information from last GC", q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
#endif //VALIDATE_MARK_SWEEP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   299
MarkSweep::IsAliveClosure   MarkSweep::is_alive;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   301
void MarkSweep::IsAliveClosure::do_object(oop p)   { ShouldNotReachHere(); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   302
bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   306
void MarkSweep::KeepAliveClosure::do_oop(oop* p)       { MarkSweep::KeepAliveClosure::do_oop_work(p); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   307
void MarkSweep::KeepAliveClosure::do_oop(narrowOop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   308
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
void marksweep_init() { /* empty */ }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
void MarkSweep::trace(const char* msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  if (TraceMarkSweep)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    gclog_or_tty->print("%s", msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
#endif