src/hotspot/share/gc/cms/freeChunk.hpp
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57811 947252a54b98
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49392
diff changeset
     2
 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
     4
 *
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
     8
 *
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    13
 * accompanied this code).
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    14
 *
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
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.
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    22
 *
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    23
 */
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49392
diff changeset
    25
#ifndef SHARE_GC_CMS_FREECHUNK_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49392
diff changeset
    26
#define SHARE_GC_CMS_FREECHUNK_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
    28
#include "memory/memRegion.hpp"
57811
947252a54b98 8229838: Rename markOop files to markWord
stefank
parents: 57777
diff changeset
    29
#include "oops/markWord.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
    30
#include "runtime/mutex.hpp"
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 14123
diff changeset
    31
#include "runtime/orderAccess.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
    32
#include "utilities/debug.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
    33
#include "utilities/globalDefinitions.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
    34
#include "utilities/ostream.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
    35
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    36
//
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    37
// Free block maintenance for Concurrent Mark Sweep Generation
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    38
//
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    39
// The main data structure for free blocks are
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    40
// . an indexed array of small free blocks, and
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    41
// . a dictionary of large free blocks
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    42
//
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    43
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    44
// No virtuals in FreeChunk (don't want any vtables).
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    45
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    46
// A FreeChunk is merely a chunk that can be in a doubly linked list
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    47
// and has a size field. NOTE: FreeChunks are distinguished from allocated
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    48
// objects in two ways (by the sweeper), depending on whether the VM is 32 or
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    49
// 64 bits.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    50
// In 32 bits or 64 bits without CompressedOops, the second word (prev) has the
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    51
// LSB set to indicate a free chunk; allocated objects' klass() pointers
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    52
// don't have their LSB set. The corresponding bit in the CMSBitMap is
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    53
// set when the chunk is allocated. There are also blocks that "look free"
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    54
// but are not part of the free list and should not be coalesced into larger
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    55
// free blocks. These free blocks have their two LSB's set.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    56
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 47216
diff changeset
    57
class FreeChunk {
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    58
  friend class VMStructs;
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 53244
diff changeset
    59
  // For 64 bit compressed oops, the markWord encodes both the size and the
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    60
  // indication that this is a FreeChunk and not an object.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    61
  volatile size_t   _size;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    62
  FreeChunk* _prev;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    63
  FreeChunk* _next;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    64
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 53244
diff changeset
    65
  markWord mark()     const volatile { return markWord((uintptr_t)_size); }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 53244
diff changeset
    66
  void set_mark(markWord m)          { _size = (size_t)m.value(); }
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    67
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    68
 public:
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    69
  NOT_PRODUCT(static const size_t header_size();)
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    70
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    71
  // Returns "true" if the address indicates that the block represents
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    72
  // a free chunk.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    73
  static bool indicatesFreeChunk(const HeapWord* addr) {
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    74
    // Force volatile read from addr because value might change between
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    75
    // calls.  We really want the read of _mark and _prev from this pointer
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    76
    // to be volatile but making the fields volatile causes all sorts of
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    77
    // compilation errors.
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
    78
    return ((volatile FreeChunk*)addr)->is_free();
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    79
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    80
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
    81
  bool is_free() const volatile {
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 53244
diff changeset
    82
    LP64_ONLY(if (UseCompressedOops) return mark().is_cms_free_chunk(); else)
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    83
    return (((intptr_t)_prev) & 0x1) == 0x1;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    84
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    85
  bool cantCoalesce() const {
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
    86
    assert(is_free(), "can't get coalesce bit on not free");
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    87
    return (((intptr_t)_prev) & 0x2) == 0x2;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    88
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    89
  void dontCoalesce() {
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    90
    // the block should be free
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
    91
    assert(is_free(), "Should look like a free block");
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    92
    _prev = (FreeChunk*)(((intptr_t)_prev) | 0x2);
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    93
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    94
  FreeChunk* prev() const {
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    95
    return (FreeChunk*)(((intptr_t)_prev) & ~(0x3));
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    96
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    97
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
    98
  debug_only(void* prev_addr() const { return (void*)&_prev; })
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 613
diff changeset
    99
  debug_only(void* next_addr() const { return (void*)&_next; })
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 613
diff changeset
   100
  debug_only(void* size_addr() const { return (void*)&_size; })
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   101
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   102
  size_t size() const volatile {
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 53244
diff changeset
   103
    LP64_ONLY(if (UseCompressedOops) return mark().get_size(); else )
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   104
    return _size;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   105
  }
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
   106
  void set_size(size_t sz) {
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 53244
diff changeset
   107
    LP64_ONLY(if (UseCompressedOops) set_mark(markWord::set_size_and_free(sz)); else )
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   108
    _size = sz;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   109
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   110
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   111
  FreeChunk* next()   const { return _next; }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   112
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
   113
  void link_after(FreeChunk* ptr) {
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
   114
    link_next(ptr);
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
   115
    if (ptr != NULL) ptr->link_prev(this);
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   116
  }
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
   117
  void link_next(FreeChunk* ptr) { _next = ptr; }
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
   118
  void link_prev(FreeChunk* ptr) {
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5702
diff changeset
   119
    LP64_ONLY(if (UseCompressedOops) _prev = ptr; else)
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5702
diff changeset
   120
    _prev = (FreeChunk*)((intptr_t)ptr | 0x1);
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   121
  }
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
   122
  void clear_next()              { _next = NULL; }
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   123
  void markNotFree() {
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5702
diff changeset
   124
    // Set _prev (klass) to null before (if) clearing the mark word below
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5702
diff changeset
   125
    _prev = NULL;
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5702
diff changeset
   126
#ifdef _LP64
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5702
diff changeset
   127
    if (UseCompressedOops) {
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5702
diff changeset
   128
      OrderAccess::storestore();
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 53244
diff changeset
   129
      set_mark(markWord::prototype());
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5702
diff changeset
   130
    }
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5702
diff changeset
   131
#endif
12509
6228e2085074 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 9984
diff changeset
   132
    assert(!is_free(), "Error");
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   133
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   134
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   135
  // Return the address past the end of this chunk
14123
944e56f74fba 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 13963
diff changeset
   136
  uintptr_t* end() const { return ((uintptr_t*) this) + size(); }
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   137
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   138
  // debugging
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   139
  void verify()             const PRODUCT_RETURN;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   140
  void verifyList()         const PRODUCT_RETURN;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   141
  void mangleAllocated(size_t size) PRODUCT_RETURN;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   142
  void mangleFreed(size_t size)     PRODUCT_RETURN;
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   143
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 977
diff changeset
   144
  void print_on(outputStream* st);
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   145
};
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   146
5694
1e0532a6abff 6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents: 4574
diff changeset
   147
extern size_t MinChunkSize;
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents:
diff changeset
   148
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
   149
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49392
diff changeset
   150
#endif // SHARE_GC_CMS_FREECHUNK_HPP