hotspot/src/share/vm/gc/shared/preservedMarks.inline.hpp
author tonyp
Thu, 07 Apr 2016 10:55:54 +0200
changeset 37422 8a7443b5edf8
parent 36202 219f8808c3bd
child 39228 32ce84798166
permissions -rw-r--r--
8152312: ParNew: Restore preserved marks in parallel Reviewed-by: tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36202
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
     1
/*
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
     4
 *
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
     8
 *
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    13
 * accompanied this code).
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    14
 *
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    18
 *
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    21
 * questions.
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    22
 *
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    23
 */
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    24
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_SHARED_PRESERVEDMARKS_INLINE_HPP
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    26
#define SHARE_VM_GC_SHARED_PRESERVEDMARKS_INLINE_HPP
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    27
37422
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    28
#include "gc/shared/preservedMarks.hpp"
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    29
#include "oops/oop.inline.hpp"
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    30
#include "utilities/stack.inline.hpp"
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    31
36202
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    32
inline bool PreservedMarks::should_preserve_mark(oop obj, markOop m) const {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    33
  return m->must_be_preserved_for_promotion_failure(obj);
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    34
}
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    35
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    36
inline void PreservedMarks::push(oop obj, markOop m) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    37
  assert(should_preserve_mark(obj, m), "pre-condition");
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    38
  OopAndMarkOop elem(obj, m);
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    39
  _stack.push(elem);
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    40
}
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    41
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    42
inline void PreservedMarks::push_if_necessary(oop obj, markOop m) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    43
  if (should_preserve_mark(obj, m)) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    44
    push(obj, m);
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    45
  }
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    46
}
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    47
37422
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    48
inline void PreservedMarks::init_forwarded_mark(oop obj) {
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    49
  obj->init_mark();
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    50
}
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    51
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    52
template <class E>
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    53
inline void PreservedMarksSet::restore(E* executor) {
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    54
  volatile size_t total_size = 0;
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    55
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    56
#ifdef ASSERT
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    57
  // This is to make sure the total_size we'll calculate below is correct.
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    58
  size_t total_size_before = 0;
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    59
  for (uint i = 0; i < _num; i += 1) {
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    60
    total_size_before += get(i)->size();
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    61
  }
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    62
#endif // def ASSERT
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    63
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    64
  if (executor == NULL) {
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    65
    for (uint i = 0; i < _num; i += 1) {
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    66
      total_size += get(i)->size();
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    67
      get(i)->restore();
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    68
    }
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    69
  } else {
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    70
    // Right now, if the executor is not NULL we do the work in
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    71
    // parallel. In the future we might want to do the restoration
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    72
    // serially, if there's only a small number of marks per stack.
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    73
    restore_internal(executor, &total_size);
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    74
  }
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    75
  assert_empty();
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    76
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    77
  assert(total_size == total_size_before,
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    78
         "total_size = " SIZE_FORMAT " before = " SIZE_FORMAT,
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    79
         total_size, total_size_before);
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    80
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    81
  log_trace(gc)("Restored " SIZE_FORMAT " marks", total_size);
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    82
}
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    83
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    84
inline PreservedMarks::PreservedMarks()
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    85
    : _stack(OopAndMarkOopStack::default_segment_size(),
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    86
             // This stack should be used very infrequently so there's
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    87
             // no point in caching stack segments (there will be a
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    88
             // waste of space most of the time). So we set the max
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    89
             // cache size to 0.
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    90
             0 /* max_cache_size */) { }
8a7443b5edf8 8152312: ParNew: Restore preserved marks in parallel
tonyp
parents: 36202
diff changeset
    91
36202
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    92
#endif // SHARE_VM_GC_SHARED_PRESERVEDMARKS_INLINE_HPP