src/share/vm/gc_implementation/concurrentMarkSweep/freeChunk.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/freeChunk.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,150 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_FREECHUNK_HPP
    1.29 +#define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_FREECHUNK_HPP
    1.30 +
    1.31 +#include "memory/allocation.hpp"
    1.32 +#include "memory/memRegion.hpp"
    1.33 +#include "oops/markOop.hpp"
    1.34 +#include "runtime/mutex.hpp"
    1.35 +#include "utilities/debug.hpp"
    1.36 +#include "utilities/globalDefinitions.hpp"
    1.37 +#include "utilities/ostream.hpp"
    1.38 +
    1.39 +//
    1.40 +// Free block maintenance for Concurrent Mark Sweep Generation
    1.41 +//
    1.42 +// The main data structure for free blocks are
    1.43 +// . an indexed array of small free blocks, and
    1.44 +// . a dictionary of large free blocks
    1.45 +//
    1.46 +
    1.47 +// No virtuals in FreeChunk (don't want any vtables).
    1.48 +
    1.49 +// A FreeChunk is merely a chunk that can be in a doubly linked list
    1.50 +// and has a size field. NOTE: FreeChunks are distinguished from allocated
    1.51 +// objects in two ways (by the sweeper), depending on whether the VM is 32 or
    1.52 +// 64 bits.
    1.53 +// In 32 bits or 64 bits without CompressedOops, the second word (prev) has the
    1.54 +// LSB set to indicate a free chunk; allocated objects' klass() pointers
    1.55 +// don't have their LSB set. The corresponding bit in the CMSBitMap is
    1.56 +// set when the chunk is allocated. There are also blocks that "look free"
    1.57 +// but are not part of the free list and should not be coalesced into larger
    1.58 +// free blocks. These free blocks have their two LSB's set.
    1.59 +
    1.60 +class FreeChunk VALUE_OBJ_CLASS_SPEC {
    1.61 +  friend class VMStructs;
    1.62 +  // For 64 bit compressed oops, the markOop encodes both the size and the
    1.63 +  // indication that this is a FreeChunk and not an object.
    1.64 +  volatile size_t   _size;
    1.65 +  FreeChunk* _prev;
    1.66 +  FreeChunk* _next;
    1.67 +
    1.68 +  markOop mark()     const volatile { return (markOop)_size; }
    1.69 +  void set_mark(markOop m)          { _size = (size_t)m; }
    1.70 +
    1.71 + public:
    1.72 +  NOT_PRODUCT(static const size_t header_size();)
    1.73 +
    1.74 +  // Returns "true" if the address indicates that the block represents
    1.75 +  // a free chunk.
    1.76 +  static bool indicatesFreeChunk(const HeapWord* addr) {
    1.77 +    // Force volatile read from addr because value might change between
    1.78 +    // calls.  We really want the read of _mark and _prev from this pointer
    1.79 +    // to be volatile but making the fields volatile causes all sorts of
    1.80 +    // compilation errors.
    1.81 +    return ((volatile FreeChunk*)addr)->is_free();
    1.82 +  }
    1.83 +
    1.84 +  bool is_free() const volatile {
    1.85 +    LP64_ONLY(if (UseCompressedOops) return mark()->is_cms_free_chunk(); else)
    1.86 +    return (((intptr_t)_prev) & 0x1) == 0x1;
    1.87 +  }
    1.88 +  bool cantCoalesce() const {
    1.89 +    assert(is_free(), "can't get coalesce bit on not free");
    1.90 +    return (((intptr_t)_prev) & 0x2) == 0x2;
    1.91 +  }
    1.92 +  void dontCoalesce() {
    1.93 +    // the block should be free
    1.94 +    assert(is_free(), "Should look like a free block");
    1.95 +    _prev = (FreeChunk*)(((intptr_t)_prev) | 0x2);
    1.96 +  }
    1.97 +  FreeChunk* prev() const {
    1.98 +    return (FreeChunk*)(((intptr_t)_prev) & ~(0x3));
    1.99 +  }
   1.100 +
   1.101 +  debug_only(void* prev_addr() const { return (void*)&_prev; })
   1.102 +  debug_only(void* next_addr() const { return (void*)&_next; })
   1.103 +  debug_only(void* size_addr() const { return (void*)&_size; })
   1.104 +
   1.105 +  size_t size() const volatile {
   1.106 +    LP64_ONLY(if (UseCompressedOops) return mark()->get_size(); else )
   1.107 +    return _size;
   1.108 +  }
   1.109 +  void set_size(size_t sz) {
   1.110 +    LP64_ONLY(if (UseCompressedOops) set_mark(markOopDesc::set_size_and_free(sz)); else )
   1.111 +    _size = sz;
   1.112 +  }
   1.113 +
   1.114 +  FreeChunk* next()   const { return _next; }
   1.115 +
   1.116 +  void link_after(FreeChunk* ptr) {
   1.117 +    link_next(ptr);
   1.118 +    if (ptr != NULL) ptr->link_prev(this);
   1.119 +  }
   1.120 +  void link_next(FreeChunk* ptr) { _next = ptr; }
   1.121 +  void link_prev(FreeChunk* ptr) {
   1.122 +    LP64_ONLY(if (UseCompressedOops) _prev = ptr; else)
   1.123 +    _prev = (FreeChunk*)((intptr_t)ptr | 0x1);
   1.124 +  }
   1.125 +  void clear_next()              { _next = NULL; }
   1.126 +  void markNotFree() {
   1.127 +    // Set _prev (klass) to null before (if) clearing the mark word below
   1.128 +    _prev = NULL;
   1.129 +#ifdef _LP64
   1.130 +    if (UseCompressedOops) {
   1.131 +      OrderAccess::storestore();
   1.132 +      set_mark(markOopDesc::prototype());
   1.133 +    }
   1.134 +#endif
   1.135 +    assert(!is_free(), "Error");
   1.136 +  }
   1.137 +
   1.138 +  // Return the address past the end of this chunk
   1.139 +  uintptr_t* end() const { return ((uintptr_t*) this) + size(); }
   1.140 +
   1.141 +  // debugging
   1.142 +  void verify()             const PRODUCT_RETURN;
   1.143 +  void verifyList()         const PRODUCT_RETURN;
   1.144 +  void mangleAllocated(size_t size) PRODUCT_RETURN;
   1.145 +  void mangleFreed(size_t size)     PRODUCT_RETURN;
   1.146 +
   1.147 +  void print_on(outputStream* st);
   1.148 +};
   1.149 +
   1.150 +extern size_t MinChunkSize;
   1.151 +
   1.152 +
   1.153 +#endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_FREECHUNK_HPP

mercurial