Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.neo4j.collection.trackable;
import static org.neo4j.memory.HeapEstimator.shallowSizeOfInstance;
import static org.neo4j.memory.HeapEstimator.shallowSizeOfObjectArray;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.concurrent.atomic.LongAdder;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.neo4j.memory.MemoryTracker;
/**
* This class contains a fork of org.eclipse.collections.impl.map.mutable.ConcurrentHashMap extending
* it with memory tracking capabilities.
*
* Modifications are marked in the code as following:
*
*
* NOTE: this class only tracks the memory of the internal structures, it will not track the individual entries.
* The user of this class can use {@link #sizeOfWrapperObject()} to improve the estimation. Furthermore, this class uses a
* LongAdder to keep track of the size. LongAdder uses a padded array that may grow under contention up to the number of cores. This
* class doesn't properly keep track of the internal memory usage of LongAdder.
*/
public abstract class AbstractHeapTrackingConcurrentHash {
static final Object RESIZE_SENTINEL = new Object();
static final int DEFAULT_INITIAL_CAPACITY = 16;
/**
* The maximum capacity, used if a higher value is implicitly specified
* by either of the constructors with arguments.
* MUST be a power of two <= 1<<30.
*/
static final int MAXIMUM_CAPACITY = 1 << 30;
@SuppressWarnings("unchecked")
private static final AtomicReferenceFieldUpdater>
TABLE_UPDATER = AtomicReferenceFieldUpdater.newUpdater(
AbstractHeapTrackingConcurrentHash.class,
(Class>) (Class>) AtomicReferenceArray.class,
"table");
static final Object RESIZED = new Object();
static final Object RESIZING = new Object();
static final Object RESERVED = new Object();
static final long SHALLOW_SIZE_ATOMIC_REFERENCE_ARRAY = shallowSizeOfInstance(AtomicReferenceArray.class);
// NOTE: Using the shallow size will underestimate the actual memory usage since internally LongAdder uses a padded
// Cell[] that can grow up to the number of available cores..
private static final long SHALLOW_SIZE_LONG_ADDER = shallowSizeOfInstance(LongAdder.class);
/**
* The table, resized as necessary. Length MUST Always be a power of two.
*/
volatile AtomicReferenceArray