hotspot/src/share/vm/memory/freeList.hpp
author stefank
Fri, 14 Feb 2014 09:29:56 +0100
changeset 22883 5378704451dc
parent 22234 da823d78ad65
child 27251 7d667f91ec8d
permissions -rw-r--r--
8034764: Use process_strong_roots to adjust the StringTable Reviewed-by: tschatzl, brutisso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 17632
diff changeset
     2
 * Copyright (c) 2001, 2013, 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: 4574
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4574
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: 4574
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
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
    25
#ifndef SHARE_VM_MEMORY_FREELIST_HPP
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
    26
#define SHARE_VM_MEMORY_FREELIST_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "gc_implementation/shared/allocationStats.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
class CompactibleFreeListSpace;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
    32
// A class for maintaining a free list of Chunk's.  The FreeList
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// maintains a the structure of the list (head, tail, etc.) plus
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// statistics for allocations from the list.  The links between items
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// are not part of FreeList.  The statistics are
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
    36
// used to make decisions about coalescing Chunk's when they
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// are swept during collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// See the corresponding .cpp file for a description of the specifics
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// for that implementation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
class Mutex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    44
template <class Chunk_t>
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
class FreeList VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  friend class CompactibleFreeListSpace;
578
862a85ed20db 6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents: 185
diff changeset
    47
  friend class VMStructs;
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    48
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    49
 private:
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    50
  Chunk_t*      _head;          // Head of list of free chunks
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    51
  Chunk_t*      _tail;          // Tail of list of free chunks
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    52
  size_t        _size;          // Size in Heap words of each chunk
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  ssize_t       _count;         // Number of entries in list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    55
 protected:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  Mutex*        _protecting_lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // Asserts false if the protecting lock (if any) is not held.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  void assert_proper_lock_protection_work() const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  void assert_proper_lock_protection() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    if (_protecting_lock != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      assert_proper_lock_protection_work();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    70
  void increment_count()    {
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    71
    _count++;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    72
  }
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 670
diff changeset
    73
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  void decrement_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    _count--;
185
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
    76
    assert(_count >= 0, "Count should not be negative");
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
    77
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // Construct a list without any entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  FreeList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    84
  // Do initialization
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    85
  void initialize();
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    86
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    87
  // Reset the head, tail, and count of a free list.
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    88
  void reset();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Declare the current free list to be protected by the given lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
#ifdef ASSERT
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    92
  Mutex* protecting_lock() const { return _protecting_lock; }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    93
  void set_protecting_lock(Mutex* v) {
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    94
    _protecting_lock = v;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Accessors.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
    99
  Chunk_t* head() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    return _head;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   103
  void set_head(Chunk_t* v) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    _head = v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    assert(!_head || _head->size() == _size, "bad chunk size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // Set the head of the list and set the prev field of non-null
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // values to NULL.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   110
  void link_head(Chunk_t* v);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   112
  Chunk_t* tail() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    return _tail;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   116
  void set_tail(Chunk_t* v) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    _tail = v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    assert(!_tail || _tail->size() == _size, "bad chunk size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // Set the tail of the list and set the next field of non-null
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // values to NULL.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   123
  void link_tail(Chunk_t* v) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    set_tail(v);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    if (v != NULL) {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 12507
diff changeset
   127
      v->clear_next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // No locking checks in read-accessors: lock-free reads (only) are benign.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // Readers are expected to have the lock if they are doing work that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // requires atomicity guarantees in sections of code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  size_t size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    return _size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  void set_size(size_t v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    assert_proper_lock_protection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    _size = v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   141
  ssize_t count() const { return _count; }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   142
  void set_count(ssize_t v) { _count = v;}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   144
  size_t get_better_size() { return size(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   146
  size_t returned_bytes() const { ShouldNotReachHere(); return 0; }
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   147
  void set_returned_bytes(size_t v) {}
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   148
  void increment_returned_bytes_by(size_t v) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Unlink head of list and return it.  Returns NULL if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // the list is empty.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   152
  Chunk_t* get_chunk_at_head();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // Remove the first "n" or "count", whichever is smaller, chunks from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  // list, setting "fl", which is required to be empty, to point to them.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   156
  void getFirstNChunksFromList(size_t n, FreeList<Chunk_t>* fl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Unlink this chunk from it's free list
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   159
  void remove_chunk(Chunk_t* fc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // Add this chunk to this free list.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   162
  void return_chunk_at_head(Chunk_t* fc);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   163
  void return_chunk_at_tail(Chunk_t* fc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // Similar to returnChunk* but also records some diagnostic
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // information.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   167
  void return_chunk_at_head(Chunk_t* fc, bool record_return);
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   168
  void return_chunk_at_tail(Chunk_t* fc, bool record_return);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // Prepend "fl" (whose size is required to be the same as that of "this")
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // to the front of "this" list.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   172
  void prepend(FreeList<Chunk_t>* fl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // Verify that the chunk is in the list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // found.  Return NULL if "fc" is not found.
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   176
  bool verify_chunk_in_free_list(Chunk_t* fc) const;
185
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   177
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   178
  // Printing support
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   179
  static void print_labels_on(outputStream* st, const char* c);
cda2a1eb4be5 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 1
diff changeset
   180
  void print_on(outputStream* st, const char* c = NULL) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   182
12507
6182ca66bc7b 7131629: Generalize the CMS free list code
jmasa
parents: 7397
diff changeset
   183
#endif // SHARE_VM_MEMORY_FREELIST_HPP