hotspot/src/share/vm/gc/shared/preservedMarks.cpp
author tonyp
Wed, 09 Mar 2016 09:45:47 +0100
changeset 37045 41e3f98fa3dc
parent 36202 219f8808c3bd
child 37422 8a7443b5edf8
permissions -rw-r--r--
8146991: Introduce per-worker preserved mark stacks in ParallelGC Reviewed-by: tschatzl, ysr
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
#include "precompiled.hpp"
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    26
#include "gc/shared/preservedMarks.inline.hpp"
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    27
#include "memory/allocation.inline.hpp"
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    28
#include "oops/oop.inline.hpp"
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    29
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    30
void PreservedMarks::restore() {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    31
  // First, iterate over the stack and restore all marks.
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    32
  StackIterator<OopAndMarkOop, mtGC> iter(_stack);
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    33
  while (!iter.is_empty()) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    34
    OopAndMarkOop elem = iter.next();
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    35
    elem.set_mark();
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    36
  }
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    37
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    38
  // Second, reclaim all the stack memory
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    39
  _stack.clear(true /* clear_cache */);
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
void RemoveForwardedPointerClosure::do_object(oop obj) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    43
  if (obj->is_forwarded()) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    44
    obj->init_mark();
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
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    48
void PreservedMarksSet::init(uint num) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    49
  assert(_stacks == NULL && _num == 0, "do not re-initialize");
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    50
  assert(num > 0, "pre-condition");
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    51
  if (_in_c_heap) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    52
    _stacks = NEW_C_HEAP_ARRAY(Padded<PreservedMarks>, num, mtGC);
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    53
  } else {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    54
    _stacks = NEW_RESOURCE_ARRAY(Padded<PreservedMarks>, num);
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    55
  }
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    56
  for (uint i = 0; i < num; i += 1) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    57
    ::new (_stacks + i) PreservedMarks();
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    58
  }
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    59
  _num = num;
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    60
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    61
  assert_empty();
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    62
}
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    63
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    64
void PreservedMarksSet::restore() {
37045
41e3f98fa3dc 8146991: Introduce per-worker preserved mark stacks in ParallelGC
tonyp
parents: 36202
diff changeset
    65
  size_t total_size = 0;
36202
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    66
  for (uint i = 0; i < _num; i += 1) {
37045
41e3f98fa3dc 8146991: Introduce per-worker preserved mark stacks in ParallelGC
tonyp
parents: 36202
diff changeset
    67
    total_size += get(i)->size();
36202
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    68
    get(i)->restore();
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    69
  }
37045
41e3f98fa3dc 8146991: Introduce per-worker preserved mark stacks in ParallelGC
tonyp
parents: 36202
diff changeset
    70
  assert_empty();
41e3f98fa3dc 8146991: Introduce per-worker preserved mark stacks in ParallelGC
tonyp
parents: 36202
diff changeset
    71
41e3f98fa3dc 8146991: Introduce per-worker preserved mark stacks in ParallelGC
tonyp
parents: 36202
diff changeset
    72
  log_trace(gc)("Restored " SIZE_FORMAT " marks", total_size);
36202
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    73
}
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    74
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    75
void PreservedMarksSet::reclaim() {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    76
  assert_empty();
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    77
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    78
  for (uint i = 0; i < _num; i += 1) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    79
    _stacks[i].~Padded<PreservedMarks>();
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    80
  }
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    81
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    82
  if (_in_c_heap) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    83
    FREE_C_HEAP_ARRAY(Padded<PreservedMarks>, _stacks);
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    84
  } else {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    85
    // the array was resource-allocated, so nothing to do
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    86
  }
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    87
  _stacks = NULL;
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    88
  _num = 0;
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    89
}
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    90
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    91
#ifndef PRODUCT
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    92
void PreservedMarksSet::assert_empty() {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    93
  assert(_stacks != NULL && _num > 0, "should have been initialized");
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    94
  for (uint i = 0; i < _num; i += 1) {
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    95
    assert(get(i)->is_empty(), "stack should be empty");
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    96
  }
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    97
}
219f8808c3bd 8146989: Introduce per-worker preserved mark stacks in ParNew
tonyp
parents:
diff changeset
    98
#endif // ndef PRODUCT