Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeChunk.hpp
38920 views
/*1* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_FREECHUNK_HPP25#define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_FREECHUNK_HPP2627#include "memory/allocation.hpp"28#include "memory/memRegion.hpp"29#include "oops/markOop.hpp"30#include "runtime/mutex.hpp"31#include "utilities/debug.hpp"32#include "utilities/globalDefinitions.hpp"33#include "utilities/ostream.hpp"3435//36// Free block maintenance for Concurrent Mark Sweep Generation37//38// The main data structure for free blocks are39// . an indexed array of small free blocks, and40// . a dictionary of large free blocks41//4243// No virtuals in FreeChunk (don't want any vtables).4445// A FreeChunk is merely a chunk that can be in a doubly linked list46// and has a size field. NOTE: FreeChunks are distinguished from allocated47// objects in two ways (by the sweeper), depending on whether the VM is 32 or48// 64 bits.49// In 32 bits or 64 bits without CompressedOops, the second word (prev) has the50// LSB set to indicate a free chunk; allocated objects' klass() pointers51// don't have their LSB set. The corresponding bit in the CMSBitMap is52// set when the chunk is allocated. There are also blocks that "look free"53// but are not part of the free list and should not be coalesced into larger54// free blocks. These free blocks have their two LSB's set.5556class FreeChunk VALUE_OBJ_CLASS_SPEC {57friend class VMStructs;58// For 64 bit compressed oops, the markOop encodes both the size and the59// indication that this is a FreeChunk and not an object.60volatile size_t _size;61FreeChunk* _prev;62FreeChunk* _next;6364markOop mark() const volatile { return (markOop)_size; }65void set_mark(markOop m) { _size = (size_t)m; }6667public:68NOT_PRODUCT(static const size_t header_size();)6970// Returns "true" if the address indicates that the block represents71// a free chunk.72static bool indicatesFreeChunk(const HeapWord* addr) {73// Force volatile read from addr because value might change between74// calls. We really want the read of _mark and _prev from this pointer75// to be volatile but making the fields volatile causes all sorts of76// compilation errors.77return ((volatile FreeChunk*)addr)->is_free();78}7980bool is_free() const volatile {81LP64_ONLY(if (UseCompressedOops) return mark()->is_cms_free_chunk(); else)82return (((intptr_t)_prev) & 0x1) == 0x1;83}84bool cantCoalesce() const {85assert(is_free(), "can't get coalesce bit on not free");86return (((intptr_t)_prev) & 0x2) == 0x2;87}88void dontCoalesce() {89// the block should be free90assert(is_free(), "Should look like a free block");91_prev = (FreeChunk*)(((intptr_t)_prev) | 0x2);92}93FreeChunk* prev() const {94return (FreeChunk*)(((intptr_t)_prev) & ~(0x3));95}9697debug_only(void* prev_addr() const { return (void*)&_prev; })98debug_only(void* next_addr() const { return (void*)&_next; })99debug_only(void* size_addr() const { return (void*)&_size; })100101size_t size() const volatile {102LP64_ONLY(if (UseCompressedOops) return mark()->get_size(); else )103return _size;104}105void set_size(size_t sz) {106LP64_ONLY(if (UseCompressedOops) set_mark(markOopDesc::set_size_and_free(sz)); else )107_size = sz;108}109110FreeChunk* next() const { return _next; }111112void link_after(FreeChunk* ptr) {113link_next(ptr);114if (ptr != NULL) ptr->link_prev(this);115}116void link_next(FreeChunk* ptr) { _next = ptr; }117void link_prev(FreeChunk* ptr) {118LP64_ONLY(if (UseCompressedOops) _prev = ptr; else)119_prev = (FreeChunk*)((intptr_t)ptr | 0x1);120}121void clear_next() { _next = NULL; }122void markNotFree() {123// Set _prev (klass) to null before (if) clearing the mark word below124_prev = NULL;125#ifdef _LP64126if (UseCompressedOops) {127OrderAccess::storestore();128set_mark(markOopDesc::prototype());129}130#endif131assert(!is_free(), "Error");132}133134// Return the address past the end of this chunk135uintptr_t* end() const { return ((uintptr_t*) this) + size(); }136137// debugging138void verify() const PRODUCT_RETURN;139void verifyList() const PRODUCT_RETURN;140void mangleAllocated(size_t size) PRODUCT_RETURN;141void mangleFreed(size_t size) PRODUCT_RETURN;142143void print_on(outputStream* st);144};145146extern size_t MinChunkSize;147148149#endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_FREECHUNK_HPP150151152