hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp
author zgu
Thu, 28 Jun 2012 17:03:16 -0400
changeset 13195 be27e1b6a4b9
parent 8921 14bfe81f2a9d
child 13728 882756847a04
permissions -rw-r--r--
6995781: Native Memory Tracking (Phase 1) 7151532: DCmd for hotspot native memory tracking Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd Reviewed-by: acorn, coleenp, fparain
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
8921
14bfe81f2a9d 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 8076
diff changeset
     2
 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5080
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5080
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5080
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    26
#include "compiler/compileBroker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    27
#include "gc_implementation/shared/markSweep.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    28
#include "gc_interface/collectedHeap.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    29
#include "oops/methodDataOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    30
#include "oops/objArrayKlass.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    31
#include "oops/oop.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    33
Stack<oop, mtGC>              MarkSweep::_marking_stack;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    34
Stack<DataLayout*, mtGC>      MarkSweep::_revisit_mdo_stack;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    35
Stack<Klass*, mtGC>           MarkSweep::_revisit_klass_stack;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    36
Stack<ObjArrayTask, mtGC>     MarkSweep::_objarray_stack;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    38
Stack<oop, mtGC>              MarkSweep::_preserved_oop_stack;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    39
Stack<markOop, mtGC>          MarkSweep::_preserved_mark_stack;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
size_t                  MarkSweep::_preserved_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
size_t                  MarkSweep::_preserved_count_max = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
PreservedMark*          MarkSweep::_preserved_marks = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
ReferenceProcessor*     MarkSweep::_ref_processor   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
#ifdef VALIDATE_MARK_SWEEP
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    46
GrowableArray<void*>*   MarkSweep::_root_refs_stack = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
GrowableArray<oop> *    MarkSweep::_live_oops = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
GrowableArray<oop> *    MarkSweep::_live_oops_moved_to = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
GrowableArray<size_t>*  MarkSweep::_live_oops_size = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
size_t                  MarkSweep::_live_oops_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
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
    52
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
    53
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
    54
bool                         MarkSweep::_pointer_tracking = false;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    55
bool                         MarkSweep::_root_tracking = true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops_moved_to = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
GrowableArray<size_t>   * MarkSweep::_cur_gc_live_oops_size = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops_moved_to = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
GrowableArray<size_t>   * MarkSweep::_last_gc_live_oops_size = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
void MarkSweep::revisit_weak_klass_link(Klass* k) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    66
  _revisit_klass_stack.push(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
void MarkSweep::follow_weak_klass_links() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // All klasses on the revisit stack are marked at this point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // Update and follow all subklass, sibling and implementor links.
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
    72
  if (PrintRevisitStats) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    73
    gclog_or_tty->print_cr("#classes in system dictionary = %d",
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    74
                           SystemDictionary::number_of_classes());
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    75
    gclog_or_tty->print_cr("Revisit klass stack size = " SIZE_FORMAT,
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    76
                           _revisit_klass_stack.size());
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
    77
  }
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    78
  while (!_revisit_klass_stack.is_empty()) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    79
    Klass* const k = _revisit_klass_stack.pop();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    80
    k->follow_weak_klass_links(&is_alive, &keep_alive);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  follow_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
    85
void MarkSweep::revisit_mdo(DataLayout* p) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    86
  _revisit_mdo_stack.push(p);
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
    87
}
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
    88
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
    89
void MarkSweep::follow_mdo_weak_refs() {
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
    90
  // All strongly reachable oops have been marked at this point;
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
    91
  // we can visit and clear any weak references from MDO's which
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
    92
  // we memoized during the strong marking phase.
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    93
  assert(_marking_stack.is_empty(), "Marking stack should be empty");
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
    94
  if (PrintRevisitStats) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    95
    gclog_or_tty->print_cr("#classes in system dictionary = %d",
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    96
                           SystemDictionary::number_of_classes());
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    97
    gclog_or_tty->print_cr("Revisit MDO stack size = " SIZE_FORMAT,
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
    98
                           _revisit_mdo_stack.size());
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
    99
  }
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   100
  while (!_revisit_mdo_stack.is_empty()) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   101
    _revisit_mdo_stack.pop()->follow_weak_refs(&is_alive);
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
   102
  }
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
   103
  follow_stack();
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
   104
}
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 670
diff changeset
   105
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   106
MarkSweep::FollowRootClosure  MarkSweep::follow_root_closure;
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 670
diff changeset
   107
CodeBlobToOopClosure MarkSweep::follow_code_root_closure(&MarkSweep::follow_root_closure, /*do_marking=*/ true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   109
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
   110
void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   114
void MarkSweep::MarkAndPushClosure::do_oop(oop* p)       { assert(*p == NULL || (*p)->is_oop(), ""); mark_and_push(p); }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   115
void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
void MarkSweep::follow_stack() {
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3919
diff changeset
   118
  do {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   119
    while (!_marking_stack.is_empty()) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   120
      oop obj = _marking_stack.pop();
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3919
diff changeset
   121
      assert (obj->is_gc_marked(), "p must be marked");
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3919
diff changeset
   122
      obj->follow_contents();
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3919
diff changeset
   123
    }
5080
eff0cc882603 6935839: excessive marking stack growth during full gcs
jcoomes
parents: 5076
diff changeset
   124
    // Process ObjArrays one at a time to avoid marking stack bloat.
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   125
    if (!_objarray_stack.is_empty()) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   126
      ObjArrayTask task = _objarray_stack.pop();
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3919
diff changeset
   127
      objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint();
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3919
diff changeset
   128
      k->oop_follow_contents(task.obj(), task.index());
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3919
diff changeset
   129
    }
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   130
  } while (!_marking_stack.is_empty() || !_objarray_stack.is_empty());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   135
void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   137
// We preserve the mark which should be replaced at the end and the location
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   138
// that it will go.  Note that the object that this markOop belongs to isn't
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   139
// currently at that address but it will be after phase4
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
void MarkSweep::preserve_mark(oop obj, markOop mark) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   141
  // We try to store preserved marks in the to space of the new generation since
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   142
  // this is storage which should be available.  Most of the time this should be
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   143
  // sufficient space for the marks we need to preserve but if it isn't we fall
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   144
  // back to using Stacks to keep track of the overflow.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  if (_preserved_count < _preserved_count_max) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    _preserved_marks[_preserved_count++].init(obj, mark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  } else {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   148
    _preserved_mark_stack.push(mark);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   149
    _preserved_oop_stack.push(obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
MarkSweep::AdjustPointerClosure MarkSweep::adjust_root_pointer_closure(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   156
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
   157
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
   158
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
void MarkSweep::adjust_marks() {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   160
  assert( _preserved_oop_stack.size() == _preserved_mark_stack.size(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
         "inconsistent preserved oop stacks");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // adjust the oops we saved earlier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  for (size_t i = 0; i < _preserved_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    _preserved_marks[i].adjust_pointer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // deal with the overflow stack
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   169
  StackIterator<oop, mtGC> iter(_preserved_oop_stack);
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   170
  while (!iter.is_empty()) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   171
    oop* p = iter.next_addr();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   172
    adjust_pointer(p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
void MarkSweep::restore_marks() {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   177
  assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
         "inconsistent preserved oop stacks");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  if (PrintGC && Verbose) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   180
    gclog_or_tty->print_cr("Restoring %d marks",
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   181
                           _preserved_count + _preserved_oop_stack.size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // restore the marks we saved earlier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  for (size_t i = 0; i < _preserved_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    _preserved_marks[i].restore();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // deal with the overflow
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   190
  while (!_preserved_oop_stack.is_empty()) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   191
    oop obj       = _preserved_oop_stack.pop();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   192
    markOop mark  = _preserved_mark_stack.pop();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   193
    obj->set_mark(mark);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
#ifdef VALIDATE_MARK_SWEEP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   199
void MarkSweep::track_adjusted_pointer(void* p, bool isroot) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  if (!ValidateMarkSweep)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  if (!isroot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    if (_pointer_tracking) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      guarantee(_adjusted_pointers->contains(p), "should have seen this pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      _adjusted_pointers->remove(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    ptrdiff_t index = _root_refs_stack->find(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    if (index != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
      int l = _root_refs_stack->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      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
   213
        void* last = _root_refs_stack->pop();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        assert(last != p, "should be different");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        _root_refs_stack->at_put(index, last);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
        _root_refs_stack->remove(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   223
void MarkSweep::check_adjust_pointer(void* p) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  _adjusted_pointers->push(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
class AdjusterTracker: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
 public:
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   229
  AdjusterTracker() {}
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   230
  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
   231
  void do_oop(narrowOop* o) { MarkSweep::check_adjust_pointer(o); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
void MarkSweep::track_interior_pointers(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    _adjusted_pointers->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    _pointer_tracking = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    AdjusterTracker checker;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    obj->oop_iterate(&checker);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
void MarkSweep::check_interior_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    _pointer_tracking = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    guarantee(_adjusted_pointers->length() == 0, "should have processed the same pointers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
void MarkSweep::reset_live_oop_tracking(bool at_perm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    guarantee((size_t)_live_oops->length() == _live_oops_index, "should be at end of live oops");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    _live_oops_index = at_perm ? _live_oops_index_at_perm : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
void MarkSweep::register_live_oop(oop p, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    _live_oops->push(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    _live_oops_size->push(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    _live_oops_index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
void MarkSweep::validate_live_oop(oop p, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    oop obj = _live_oops->at((int)_live_oops_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    guarantee(obj == p, "should be the same object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    guarantee(_live_oops_size->at((int)_live_oops_index) == size, "should be the same size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    _live_oops_index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
void MarkSweep::live_oop_moved_to(HeapWord* q, size_t size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
                                  HeapWord* compaction_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  assert(oop(q)->forwardee() == NULL || oop(q)->forwardee() == oop(compaction_top),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
         "should be moved to forwarded location");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  if (ValidateMarkSweep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    MarkSweep::validate_live_oop(oop(q), size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    _live_oops_moved_to->push(oop(compaction_top));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  if (RecordMarkSweepCompaction) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    _cur_gc_live_oops->push(q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    _cur_gc_live_oops_moved_to->push(compaction_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    _cur_gc_live_oops_size->push(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
void MarkSweep::compaction_complete() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  if (RecordMarkSweepCompaction) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    GrowableArray<HeapWord*>* _tmp_live_oops          = _cur_gc_live_oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    GrowableArray<HeapWord*>* _tmp_live_oops_moved_to = _cur_gc_live_oops_moved_to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    GrowableArray<size_t>   * _tmp_live_oops_size     = _cur_gc_live_oops_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    _cur_gc_live_oops           = _last_gc_live_oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    _cur_gc_live_oops_moved_to  = _last_gc_live_oops_moved_to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    _cur_gc_live_oops_size      = _last_gc_live_oops_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    _last_gc_live_oops          = _tmp_live_oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    _last_gc_live_oops_moved_to = _tmp_live_oops_moved_to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    _last_gc_live_oops_size     = _tmp_live_oops_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
void MarkSweep::print_new_location_of_heap_address(HeapWord* q) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  if (!RecordMarkSweepCompaction) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    tty->print_cr("Requires RecordMarkSweepCompaction to be enabled");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  if (_last_gc_live_oops == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    tty->print_cr("No compaction information gathered yet");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  for (int i = 0; i < _last_gc_live_oops->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    HeapWord* old_oop = _last_gc_live_oops->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    size_t    sz      = _last_gc_live_oops_size->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    if (old_oop <= q && q < (old_oop + sz)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      HeapWord* new_oop = _last_gc_live_oops_moved_to->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      size_t offset = (q - old_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      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
   323
      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
   324
      tty->print_cr(" Now in oop " PTR_FORMAT ", actual address " PTR_FORMAT, new_oop, new_oop + offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  tty->print_cr("Address " PTR_FORMAT " not found in live oop information from last GC", q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
#endif //VALIDATE_MARK_SWEEP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   333
MarkSweep::IsAliveClosure   MarkSweep::is_alive;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   335
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
   336
bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   340
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
   341
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
   342
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
void marksweep_init() { /* empty */ }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
void MarkSweep::trace(const char* msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  if (TraceMarkSweep)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    gclog_or_tty->print("%s", msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
#endif