src/hotspot/share/gc/shared/softRefPolicy.hpp
author stefank
Thu, 22 Feb 2018 18:36:32 +0100
changeset 49048 4e8c86b75428
parent 49047 8f004146e407
child 53244 9807daeb47c4
permissions -rw-r--r--
8198525: Move _size_policy out of GenCollectorPolicy into GenCollectedHeap Reviewed-by: pliden, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49047
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
     1
/*
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
     2
 * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
     4
 *
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
     8
 *
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    13
 * accompanied this code).
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    14
 *
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    18
 *
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    21
 * questions.
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    22
 *
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    23
 */
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    24
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_SHARED_SOFTREFPOLICY_HPP
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    26
#define SHARE_VM_GC_SHARED_SOFTREFPOLICY_HPP
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    27
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    28
#include "memory/allocation.hpp"
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    29
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    30
class SoftRefPolicy {
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    31
 private:
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    32
  // Set to true when policy wants soft refs cleared.
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    33
  // Reset to false by gc after it clears all soft refs.
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    34
  bool _should_clear_all_soft_refs;
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    35
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    36
  // Set to true by the GC if the just-completed gc cleared all
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    37
  // softrefs.  This is set to true whenever a gc clears all softrefs, and
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    38
  // set to false each time gc returns to the mutator.  For example, in the
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    39
  // ParallelScavengeHeap case the latter would be done toward the end of
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    40
  // mem_allocate() where it returns op.result()
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    41
  bool _all_soft_refs_clear;
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    42
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    43
 public:
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    44
  SoftRefPolicy();
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    45
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    46
  bool should_clear_all_soft_refs() { return _should_clear_all_soft_refs; }
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    47
  void set_should_clear_all_soft_refs(bool v) { _should_clear_all_soft_refs = v; }
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    48
  // Returns the current value of _should_clear_all_soft_refs.
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    49
  // _should_clear_all_soft_refs is set to false as a side effect.
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    50
  bool use_should_clear_all_soft_refs(bool v);
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    51
  bool all_soft_refs_clear() { return _all_soft_refs_clear; }
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    52
  void set_all_soft_refs_clear(bool v) { _all_soft_refs_clear = v; }
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    53
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    54
  // Called by the GC after Soft Refs have been cleared to indicate
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    55
  // that the request in _should_clear_all_soft_refs has been fulfilled.
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    56
  virtual void cleared_all_soft_refs();
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    57
};
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    58
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    59
class ClearedAllSoftRefs : public StackObj {
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    60
  bool           _clear_all_soft_refs;
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    61
  SoftRefPolicy* _soft_ref_policy;
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    62
 public:
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    63
  ClearedAllSoftRefs(bool clear_all_soft_refs, SoftRefPolicy* soft_ref_policy) :
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    64
    _clear_all_soft_refs(clear_all_soft_refs),
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    65
    _soft_ref_policy(soft_ref_policy) {}
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    66
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    67
  ~ClearedAllSoftRefs() {
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    68
    if (_clear_all_soft_refs) {
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    69
      _soft_ref_policy->cleared_all_soft_refs();
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    70
    }
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    71
  }
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    72
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    73
  bool should_clear() { return _clear_all_soft_refs; }
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    74
};
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    75
8f004146e407 8198515: Extract SoftReferencePolicy code out of CollectorPolicy
stefank
parents:
diff changeset
    76
#endif // SHARE_VM_GC_SHARED_SOFTREFPOLICY_HPP