hotspot/src/share/vm/gc_implementation/shared/markSweep.cpp
author stefank
Thu, 02 Apr 2015 10:04:27 +0200
changeset 30150 d9c940aa42ef
parent 29800 fa5f7a2bf717
child 30151 c7cdaa576875
permissions -rw-r--r--
8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution Reviewed-by: brutisso, coleenp, kbarrett, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
29701
f638fc81a3d0 8075803: Fix GC includes and forward declarations
stefank
parents: 25492
diff changeset
     2
 * Copyright (c) 1997, 2015, 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"
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17626
diff changeset
    27
#include "gc_implementation/shared/gcTimer.hpp"
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17626
diff changeset
    28
#include "gc_implementation/shared/gcTrace.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    29
#include "gc_implementation/shared/markSweep.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    30
#include "gc_interface/collectedHeap.inline.hpp"
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    31
#include "oops/instanceKlass.inline.hpp"
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    32
#include "oops/instanceMirrorKlass.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    33
#include "oops/methodData.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    34
#include "oops/objArrayKlass.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    35
#include "oops/oop.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
17392
2f967c0e4246 6843347: Boundary values in some public GC options cause crashes
tschatzl
parents: 17105
diff changeset
    37
uint                    MarkSweep::_total_invocations = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    38
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    39
Stack<oop, mtGC>              MarkSweep::_marking_stack;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    40
Stack<ObjArrayTask, mtGC>     MarkSweep::_objarray_stack;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    42
Stack<oop, mtGC>              MarkSweep::_preserved_oop_stack;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    43
Stack<markOop, mtGC>          MarkSweep::_preserved_mark_stack;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
size_t                  MarkSweep::_preserved_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
size_t                  MarkSweep::_preserved_count_max = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
PreservedMark*          MarkSweep::_preserved_marks = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
ReferenceProcessor*     MarkSweep::_ref_processor   = NULL;
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17626
diff changeset
    48
STWGCTimer*             MarkSweep::_gc_timer        = NULL;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17626
diff changeset
    49
SerialOldTracer*        MarkSweep::_gc_tracer       = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    51
MarkSweep::FollowRootClosure  MarkSweep::follow_root_closure;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    53
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
    54
void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure;
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
    57
CLDToOopClosure               MarkSweep::follow_cld_closure(&mark_and_push_closure);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
    58
CLDToOopClosure               MarkSweep::adjust_cld_closure(&adjust_pointer_closure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    60
template <typename T>
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    61
void MarkSweep::MarkAndPushClosure::do_oop_nv(T* p)       { mark_and_push(p); }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    62
void MarkSweep::MarkAndPushClosure::do_oop(oop* p)        { do_oop_nv(p); }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    63
void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p)  { do_oop_nv(p); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    65
void MarkSweep::follow_class_loader(ClassLoaderData* cld) {
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
    66
  MarkSweep::follow_cld_closure.do_cld(cld);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    67
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    68
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    69
void InstanceKlass::oop_ms_follow_contents(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    70
  assert(obj != NULL, "can't follow the content of NULL object");
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    71
  MarkSweep::follow_klass(obj->klass());
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    72
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    73
  oop_oop_iterate_oop_maps<true>(obj, &MarkSweep::mark_and_push_closure);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    74
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    75
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    76
void InstanceMirrorKlass::oop_ms_follow_contents(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    77
  InstanceKlass::oop_ms_follow_contents(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    78
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    79
  // Follow the klass field in the mirror
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    80
  Klass* klass = java_lang_Class::as_Klass(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    81
  if (klass != NULL) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    82
    // An anonymous class doesn't have its own class loader, so the call
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    83
    // to follow_klass will mark and push its java mirror instead of the
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    84
    // class loader. When handling the java mirror for an anonymous class
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    85
    // we need to make sure its class loader data is claimed, this is done
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    86
    // by calling follow_class_loader explicitly. For non-anonymous classes
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    87
    // the call to follow_class_loader is made when the class loader itself
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    88
    // is handled.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    89
    if (klass->oop_is_instance() && InstanceKlass::cast(klass)->is_anonymous()) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    90
      MarkSweep::follow_class_loader(klass->class_loader_data());
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    91
    } else {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    92
      MarkSweep::follow_klass(klass);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    93
    }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    94
  } else {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    95
    // If klass is NULL then this a mirror for a primitive type.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    96
    // We don't have to follow them, since they are handled as strong
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    97
    // roots in Universe::oops_do.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    98
    assert(java_lang_Class::is_primitive(obj), "Sanity check");
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
    99
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   100
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   101
  oop_oop_iterate_statics<true>(obj, &MarkSweep::mark_and_push_closure);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   102
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   103
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   104
void InstanceClassLoaderKlass::oop_ms_follow_contents(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   105
  InstanceKlass::oop_ms_follow_contents(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   106
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   107
  ClassLoaderData * const loader_data = java_lang_ClassLoader::loader_data(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   108
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   109
  // We must NULL check here, since the class loader
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   110
  // can be found before the loader data has been set up.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   111
  if(loader_data != NULL) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   112
    MarkSweep::follow_class_loader(loader_data);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   113
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   114
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   115
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   116
template <class T>
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   117
static void oop_ms_follow_contents_specialized(InstanceRefKlass* klass, oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   118
  T* referent_addr = (T*)java_lang_ref_Reference::referent_addr(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   119
  T heap_oop = oopDesc::load_heap_oop(referent_addr);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   120
  debug_only(
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   121
    if(TraceReferenceGC && PrintGCDetails) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   122
      gclog_or_tty->print_cr("InstanceRefKlass::oop_ms_follow_contents_specialized " PTR_FORMAT, p2i(obj));
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   123
    }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   124
  )
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   125
  if (!oopDesc::is_null(heap_oop)) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   126
    oop referent = oopDesc::decode_heap_oop_not_null(heap_oop);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   127
    if (!referent->is_gc_marked() &&
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   128
        MarkSweep::ref_processor()->discover_reference(obj, klass->reference_type())) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   129
      // reference was discovered, referent will be traversed later
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   130
      klass->InstanceKlass::oop_ms_follow_contents(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   131
      debug_only(
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   132
        if(TraceReferenceGC && PrintGCDetails) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   133
          gclog_or_tty->print_cr("       Non NULL enqueued " PTR_FORMAT, p2i(obj));
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   134
        }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   135
      )
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   136
      return;
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   137
    } else {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   138
      // treat referent as normal oop
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   139
      debug_only(
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   140
        if(TraceReferenceGC && PrintGCDetails) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   141
          gclog_or_tty->print_cr("       Non NULL normal " PTR_FORMAT, p2i(obj));
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   142
        }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   143
      )
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   144
      MarkSweep::mark_and_push(referent_addr);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   145
    }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   146
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   147
  T* next_addr = (T*)java_lang_ref_Reference::next_addr(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   148
  if (ReferenceProcessor::pending_list_uses_discovered_field()) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   149
    // Treat discovered as normal oop, if ref is not "active",
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   150
    // i.e. if next is non-NULL.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   151
    T  next_oop = oopDesc::load_heap_oop(next_addr);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   152
    if (!oopDesc::is_null(next_oop)) { // i.e. ref is not "active"
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   153
      T* discovered_addr = (T*)java_lang_ref_Reference::discovered_addr(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   154
      debug_only(
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   155
        if(TraceReferenceGC && PrintGCDetails) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   156
          gclog_or_tty->print_cr("   Process discovered as normal "
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   157
                                 PTR_FORMAT, p2i(discovered_addr));
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   158
        }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   159
      )
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   160
      MarkSweep::mark_and_push(discovered_addr);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   161
    }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   162
  } else {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   163
#ifdef ASSERT
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   164
    // In the case of older JDKs which do not use the discovered
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   165
    // field for the pending list, an inactive ref (next != NULL)
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   166
    // must always have a NULL discovered field.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   167
    oop next = oopDesc::load_decode_heap_oop(next_addr);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   168
    oop discovered = java_lang_ref_Reference::discovered(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   169
    assert(oopDesc::is_null(next) || oopDesc::is_null(discovered),
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   170
        err_msg("Found an inactive reference " PTR_FORMAT " with a non-NULL discovered field",
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   171
            p2i(obj)));
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   172
#endif
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   173
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   174
  // treat next as normal oop.  next is a link in the reference queue.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   175
  debug_only(
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   176
    if(TraceReferenceGC && PrintGCDetails) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   177
      gclog_or_tty->print_cr("   Process next as normal " PTR_FORMAT, p2i(next_addr));
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   178
    }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   179
  )
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   180
  MarkSweep::mark_and_push(next_addr);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   181
  klass->InstanceKlass::oop_ms_follow_contents(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   182
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   183
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   184
void InstanceRefKlass::oop_ms_follow_contents(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   185
  if (UseCompressedOops) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   186
    oop_ms_follow_contents_specialized<narrowOop>(this, obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   187
  } else {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   188
    oop_ms_follow_contents_specialized<oop>(this, obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   189
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   190
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   191
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   192
template <class T>
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   193
static void oop_ms_follow_contents_specialized(oop obj, int index) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   194
  objArrayOop a = objArrayOop(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   195
  const size_t len = size_t(a->length());
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   196
  const size_t beg_index = size_t(index);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   197
  assert(beg_index < len || len == 0, "index too large");
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   198
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   199
  const size_t stride = MIN2(len - beg_index, ObjArrayMarkingStride);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   200
  const size_t end_index = beg_index + stride;
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   201
  T* const base = (T*)a->base();
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   202
  T* const beg = base + beg_index;
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   203
  T* const end = base + end_index;
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   204
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   205
  // Push the non-NULL elements of the next stride on the marking stack.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   206
  for (T* e = beg; e < end; e++) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   207
    MarkSweep::mark_and_push<T>(e);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   208
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   209
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   210
  if (end_index < len) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   211
    MarkSweep::push_objarray(a, end_index); // Push the continuation.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   212
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   213
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   214
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   215
void ObjArrayKlass::oop_ms_follow_contents(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   216
  assert (obj->is_array(), "obj must be array");
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   217
  MarkSweep::follow_klass(this);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   218
  if (UseCompressedOops) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   219
    oop_ms_follow_contents_specialized<narrowOop>(obj, 0);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   220
  } else {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   221
    oop_ms_follow_contents_specialized<oop>(obj, 0);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   222
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   223
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   224
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   225
void TypeArrayKlass::oop_ms_follow_contents(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   226
  assert(obj->is_typeArray(),"must be a type array");
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   227
  // Performance tweak: We skip iterating over the klass pointer since we
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   228
  // know that Universe::TypeArrayKlass never moves.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   229
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   230
29792
8c6fa07f0869 8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents: 29701
diff changeset
   231
void MarkSweep::follow_array(objArrayOop array, int index) {
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   232
  if (UseCompressedOops) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   233
    oop_ms_follow_contents_specialized<narrowOop>(array, index);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   234
  } else {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   235
    oop_ms_follow_contents_specialized<oop>(array, index);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   236
  }
29792
8c6fa07f0869 8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents: 29701
diff changeset
   237
}
8c6fa07f0869 8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents: 29701
diff changeset
   238
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
void MarkSweep::follow_stack() {
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3919
diff changeset
   240
  do {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   241
    while (!_marking_stack.is_empty()) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   242
      oop obj = _marking_stack.pop();
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3919
diff changeset
   243
      assert (obj->is_gc_marked(), "p must be marked");
29792
8c6fa07f0869 8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents: 29701
diff changeset
   244
      follow_object(obj);
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3919
diff changeset
   245
    }
5080
eff0cc882603 6935839: excessive marking stack growth during full gcs
jcoomes
parents: 5076
diff changeset
   246
    // 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
   247
    if (!_objarray_stack.is_empty()) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   248
      ObjArrayTask task = _objarray_stack.pop();
29792
8c6fa07f0869 8075957: Reduce calls to the GC specific object visitors in oopDesc
stefank
parents: 29701
diff changeset
   249
      follow_array(objArrayOop(task.obj()), task.index());
5076
8b74a4b60b31 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 3919
diff changeset
   250
    }
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   251
  } while (!_marking_stack.is_empty() || !_objarray_stack.is_empty());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   256
void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
29701
f638fc81a3d0 8075803: Fix GC includes and forward declarations
stefank
parents: 25492
diff changeset
   258
void PreservedMark::adjust_pointer() {
f638fc81a3d0 8075803: Fix GC includes and forward declarations
stefank
parents: 25492
diff changeset
   259
  MarkSweep::adjust_pointer(&_obj);
f638fc81a3d0 8075803: Fix GC includes and forward declarations
stefank
parents: 25492
diff changeset
   260
}
f638fc81a3d0 8075803: Fix GC includes and forward declarations
stefank
parents: 25492
diff changeset
   261
f638fc81a3d0 8075803: Fix GC includes and forward declarations
stefank
parents: 25492
diff changeset
   262
void PreservedMark::restore() {
f638fc81a3d0 8075803: Fix GC includes and forward declarations
stefank
parents: 25492
diff changeset
   263
  _obj->set_mark(_mark);
f638fc81a3d0 8075803: Fix GC includes and forward declarations
stefank
parents: 25492
diff changeset
   264
}
f638fc81a3d0 8075803: Fix GC includes and forward declarations
stefank
parents: 25492
diff changeset
   265
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   266
// 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
   267
// 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
   268
// currently at that address but it will be after phase4
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
void MarkSweep::preserve_mark(oop obj, markOop mark) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   270
  // 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
   271
  // 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
   272
  // 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
   273
  // back to using Stacks to keep track of the overflow.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  if (_preserved_count < _preserved_count_max) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    _preserved_marks[_preserved_count++].init(obj, mark);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  } else {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   277
    _preserved_mark_stack.push(mark);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   278
    _preserved_oop_stack.push(obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
17105
25b392a7740d 8012687: Remove unused is_root checks and closures
stefank
parents: 15088
diff changeset
   282
MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   284
template <typename T>
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   285
void MarkSweep::AdjustPointerClosure::do_oop_nv(T* p)      { adjust_pointer(p); }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   286
void MarkSweep::AdjustPointerClosure::do_oop(oop* p)       { do_oop_nv(p); }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   287
void MarkSweep::AdjustPointerClosure::do_oop(narrowOop* p) { do_oop_nv(p); }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   288
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
void MarkSweep::adjust_marks() {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   290
  assert( _preserved_oop_stack.size() == _preserved_mark_stack.size(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
         "inconsistent preserved oop stacks");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  // adjust the oops we saved earlier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  for (size_t i = 0; i < _preserved_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    _preserved_marks[i].adjust_pointer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  // deal with the overflow stack
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   299
  StackIterator<oop, mtGC> iter(_preserved_oop_stack);
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   300
  while (!iter.is_empty()) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   301
    oop* p = iter.next_addr();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   302
    adjust_pointer(p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
void MarkSweep::restore_marks() {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   307
  assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
         "inconsistent preserved oop stacks");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  if (PrintGC && Verbose) {
24092
e274d864545a 8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents: 22882
diff changeset
   310
    gclog_or_tty->print_cr("Restoring " SIZE_FORMAT " marks",
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   311
                           _preserved_count + _preserved_oop_stack.size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  // restore the marks we saved earlier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  for (size_t i = 0; i < _preserved_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    _preserved_marks[i].restore();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  // deal with the overflow
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   320
  while (!_preserved_oop_stack.is_empty()) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   321
    oop obj       = _preserved_oop_stack.pop();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   322
    markOop mark  = _preserved_mark_stack.pop();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents: 5547
diff changeset
   323
    obj->set_mark(mark);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   327
MarkSweep::IsAliveClosure   MarkSweep::is_alive;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   329
bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
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
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
   334
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
   335
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17626
diff changeset
   336
void marksweep_init() {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17626
diff changeset
   337
  MarkSweep::_gc_timer = new (ResourceObj::C_HEAP, mtGC) STWGCTimer();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17626
diff changeset
   338
  MarkSweep::_gc_tracer = new (ResourceObj::C_HEAP, mtGC) SerialOldTracer();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17626
diff changeset
   339
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
void MarkSweep::trace(const char* msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  if (TraceMarkSweep)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    gclog_or_tty->print("%s", msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
#endif
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   349
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   350
int InstanceKlass::oop_ms_adjust_pointers(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   351
  int size = size_helper();
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   352
  oop_oop_iterate_oop_maps<true>(obj, &MarkSweep::adjust_pointer_closure);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   353
  return size;
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   354
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   355
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   356
int InstanceMirrorKlass::oop_ms_adjust_pointers(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   357
  int size = oop_size(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   358
  InstanceKlass::oop_ms_adjust_pointers(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   359
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   360
  oop_oop_iterate_statics<true>(obj, &MarkSweep::adjust_pointer_closure);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   361
  return size;
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   362
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   363
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   364
int InstanceClassLoaderKlass::oop_ms_adjust_pointers(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   365
  return InstanceKlass::oop_ms_adjust_pointers(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   366
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   367
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   368
#ifdef ASSERT
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   369
template <class T> static void trace_reference_gc(const char *s, oop obj,
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   370
                                                  T* referent_addr,
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   371
                                                  T* next_addr,
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   372
                                                  T* discovered_addr) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   373
  if(TraceReferenceGC && PrintGCDetails) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   374
    gclog_or_tty->print_cr("%s obj " PTR_FORMAT, s, p2i(obj));
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   375
    gclog_or_tty->print_cr("     referent_addr/* " PTR_FORMAT " / "
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   376
                           PTR_FORMAT, p2i(referent_addr),
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   377
                           p2i(referent_addr ?
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   378
                               (address)oopDesc::load_decode_heap_oop(referent_addr) : NULL));
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   379
    gclog_or_tty->print_cr("     next_addr/* " PTR_FORMAT " / "
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   380
                           PTR_FORMAT, p2i(next_addr),
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   381
                           p2i(next_addr ? (address)oopDesc::load_decode_heap_oop(next_addr) : NULL));
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   382
    gclog_or_tty->print_cr("     discovered_addr/* " PTR_FORMAT " / "
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   383
                           PTR_FORMAT, p2i(discovered_addr),
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   384
                           p2i(discovered_addr ?
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   385
                               (address)oopDesc::load_decode_heap_oop(discovered_addr) : NULL));
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   386
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   387
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   388
#endif
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   389
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   390
template <class T> void static adjust_object_specialized(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   391
  T* referent_addr = (T*)java_lang_ref_Reference::referent_addr(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   392
  MarkSweep::adjust_pointer(referent_addr);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   393
  T* next_addr = (T*)java_lang_ref_Reference::next_addr(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   394
  MarkSweep::adjust_pointer(next_addr);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   395
  T* discovered_addr = (T*)java_lang_ref_Reference::discovered_addr(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   396
  MarkSweep::adjust_pointer(discovered_addr);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   397
  debug_only(trace_reference_gc("InstanceRefKlass::oop_ms_adjust_pointers", obj,
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   398
                                referent_addr, next_addr, discovered_addr);)
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   399
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   400
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   401
int InstanceRefKlass::oop_ms_adjust_pointers(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   402
  int size = size_helper();
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   403
  InstanceKlass::oop_ms_adjust_pointers(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   404
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   405
  if (UseCompressedOops) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   406
    adjust_object_specialized<narrowOop>(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   407
  } else {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   408
    adjust_object_specialized<oop>(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   409
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   410
  return size;
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   411
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   412
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   413
int ObjArrayKlass::oop_ms_adjust_pointers(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   414
  assert(obj->is_objArray(), "obj must be obj array");
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   415
  objArrayOop a = objArrayOop(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   416
  // Get size before changing pointers.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   417
  // Don't call size() or oop_size() since that is a virtual call.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   418
  int size = a->object_size();
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   419
  oop_oop_iterate_elements<true>(a, &MarkSweep::adjust_pointer_closure);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   420
  return size;
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   421
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   422
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   423
int TypeArrayKlass::oop_ms_adjust_pointers(oop obj) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   424
  assert(obj->is_typeArray(), "must be a type array");
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   425
  typeArrayOop t = typeArrayOop(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   426
  // Performance tweak: We skip iterating over the klass pointer since we
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   427
  // know that Universe::TypeArrayKlass never moves.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   428
  return t->object_size();
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents: 29800
diff changeset
   429
}