Search in sources :

Example 1 with MemoryAllocator

use of org.apache.geode.internal.offheap.MemoryAllocator in project geode by apache.

the class AbstractRegionEntry method prepareValueForCache.

@Override
@Retained(ABSTRACT_REGION_ENTRY_PREPARE_VALUE_FOR_CACHE)
public Object prepareValueForCache(RegionEntryContext r, @Retained(ABSTRACT_REGION_ENTRY_PREPARE_VALUE_FOR_CACHE) Object val, EntryEventImpl event, boolean isEntryUpdate) {
    if (r != null && r.getOffHeap() && okToStoreOffHeap(val, this)) {
        if (val instanceof StoredObject) {
            // Check to see if val has the same compression settings as this region.
            // The recursive calls in this section are safe because
            // we only do it after copy the off-heap value to the heap.
            // This is needed to fix bug 52057.
            StoredObject soVal = (StoredObject) val;
            assert !soVal.isCompressed();
            if (r.getCompressor() != null) {
                // val is uncompressed and we need a compressed value.
                // So copy the off-heap value to the heap in a form that can be compressed.
                byte[] valAsBytes = soVal.getValueAsHeapByteArray();
                Object heapValue;
                if (soVal.isSerialized()) {
                    heapValue = CachedDeserializableFactory.create(valAsBytes);
                } else {
                    heapValue = valAsBytes;
                }
                return prepareValueForCache(r, heapValue, event, isEntryUpdate);
            }
            if (soVal.hasRefCount()) {
                // if the reused guy has a refcount then need to inc it
                if (!soVal.retain()) {
                    throw new IllegalStateException("Could not use an off heap value because it was freed");
                }
            }
        // else it is has no refCount so just return it as prepared.
        } else {
            byte[] data;
            boolean isSerialized = !(val instanceof byte[]);
            if (isSerialized) {
                if (event != null && event.getCachedSerializedNewValue() != null) {
                    data = event.getCachedSerializedNewValue();
                } else if (val instanceof CachedDeserializable) {
                    data = ((CachedDeserializable) val).getSerializedValue();
                } else if (val instanceof PdxInstance) {
                    try {
                        data = ((ConvertableToBytes) val).toBytes();
                    } catch (IOException e) {
                        throw new PdxSerializationException("Could not convert " + val + " to bytes", e);
                    }
                } else {
                    data = EntryEventImpl.serialize(val);
                }
            } else {
                data = (byte[]) val;
            }
            byte[] compressedData = compressBytes(r, data);
            // TODO: array comparison is broken
            boolean isCompressed = compressedData != data;
            ReferenceCountHelper.setReferenceCountOwner(this);
            // fix for bug 47875
            MemoryAllocator ma = MemoryAllocatorImpl.getAllocator();
            val = ma.allocateAndInitialize(compressedData, isSerialized, isCompressed, data);
            ReferenceCountHelper.setReferenceCountOwner(null);
        }
        return val;
    }
    @Unretained Object nv = val;
    if (nv instanceof StoredObject) {
        // This off heap value is being put into a on heap region.
        byte[] data = ((StoredObject) nv).getSerializedValue();
        nv = CachedDeserializableFactory.create(data);
    }
    if (nv instanceof PdxInstanceImpl) {
        // So get the serialized bytes and use a CachedDeserializable.
        try {
            byte[] data = ((ConvertableToBytes) nv).toBytes();
            byte[] compressedData = compressBytes(r, data);
            // TODO: array comparison is broken
            if (data == compressedData) {
                nv = CachedDeserializableFactory.create(data);
            } else {
                nv = compressedData;
            }
        } catch (IOException e) {
            throw new PdxSerializationException("Could not convert " + nv + " to bytes", e);
        }
    } else {
        nv = compress(r, nv, event);
    }
    return nv;
}
Also used : MemoryAllocator(org.apache.geode.internal.offheap.MemoryAllocator) IOException(java.io.IOException) ConvertableToBytes(org.apache.geode.pdx.internal.ConvertableToBytes) PdxSerializationException(org.apache.geode.pdx.PdxSerializationException) StoredObject(org.apache.geode.internal.offheap.StoredObject) PdxInstance(org.apache.geode.pdx.PdxInstance) PdxInstanceImpl(org.apache.geode.pdx.internal.PdxInstanceImpl) StoredObject(org.apache.geode.internal.offheap.StoredObject) Unretained(org.apache.geode.internal.offheap.annotations.Unretained) Retained(org.apache.geode.internal.offheap.annotations.Retained)

Example 2 with MemoryAllocator

use of org.apache.geode.internal.offheap.MemoryAllocator in project geode by apache.

the class MemberMBeanBridge method getOffHeapStats.

/**
   * Returns the OffHeapMemoryStats for this VM.
   */
private OffHeapMemoryStats getOffHeapStats() {
    OffHeapMemoryStats stats = null;
    MemoryAllocator offHeap = this.cache.getOffHeapStore();
    if (null != offHeap) {
        stats = offHeap.getStats();
    }
    return stats;
}
Also used : MemoryAllocator(org.apache.geode.internal.offheap.MemoryAllocator) OffHeapMemoryStats(org.apache.geode.internal.offheap.OffHeapMemoryStats)

Example 3 with MemoryAllocator

use of org.apache.geode.internal.offheap.MemoryAllocator in project geode by apache.

the class MemberMBeanBridge method init.

public MemberMBeanBridge init() {
    CachePerfStats cachePerfStats = this.cache.getCachePerfStats();
    addCacheStats(cachePerfStats);
    addFunctionStats(system.getFunctionServiceStats());
    if (system.getDistributionManager().getStats() instanceof DistributionStats) {
        DistributionStats distributionStats = (DistributionStats) system.getDistributionManager().getStats();
        addDistributionStats(distributionStats);
    }
    if (PureJavaMode.osStatsAreAvailable()) {
        Statistics[] systemStats = null;
        if (HostStatHelper.isSolaris()) {
            systemStats = system.findStatisticsByType(SolarisSystemStats.getType());
        } else if (HostStatHelper.isLinux()) {
            systemStats = system.findStatisticsByType(LinuxSystemStats.getType());
        } else if (HostStatHelper.isOSX()) {
            // @TODO once OSX stats are implemented
            systemStats = null;
        } else if (HostStatHelper.isWindows()) {
            systemStats = system.findStatisticsByType(WindowsSystemStats.getType());
        }
        if (systemStats != null) {
            systemStat = systemStats[0];
        }
    }
    MemoryAllocator allocator = this.cache.getOffHeapStore();
    if ((null != allocator)) {
        OffHeapMemoryStats offHeapStats = allocator.getStats();
        if (null != offHeapStats) {
            addOffHeapStats(offHeapStats);
        }
    }
    addSystemStats();
    addVMStats();
    initializeStats();
    return this;
}
Also used : MemoryAllocator(org.apache.geode.internal.offheap.MemoryAllocator) OffHeapMemoryStats(org.apache.geode.internal.offheap.OffHeapMemoryStats) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) Statistics(org.apache.geode.Statistics) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) DistributionStats(org.apache.geode.distributed.internal.DistributionStats)

Example 4 with MemoryAllocator

use of org.apache.geode.internal.offheap.MemoryAllocator in project geode by apache.

the class OffHeapEvictor method calculateEvictionBurst.

private void calculateEvictionBurst() {
    float evictionBurstPercentage = Float.parseFloat(System.getProperty(DistributionConfig.GEMFIRE_PREFIX + "HeapLRUCapacityController.evictionBurstPercentage", "0.4"));
    MemoryAllocator allocator = this.cache.getOffHeapStore();
    /*
     * Bail if there is no off-heap memory to evict.
     */
    if (null == allocator) {
        throw new IllegalStateException(LocalizedStrings.MEMSCALE_EVICTION_INIT_FAIL.toLocalizedString());
    }
    bytesToEvictWithEachBurst = (long) (allocator.getTotalMemory() * 0.01 * evictionBurstPercentage);
}
Also used : MemoryAllocator(org.apache.geode.internal.offheap.MemoryAllocator)

Aggregations

MemoryAllocator (org.apache.geode.internal.offheap.MemoryAllocator)4 OffHeapMemoryStats (org.apache.geode.internal.offheap.OffHeapMemoryStats)2 IOException (java.io.IOException)1 Statistics (org.apache.geode.Statistics)1 DistributionStats (org.apache.geode.distributed.internal.DistributionStats)1 CachePerfStats (org.apache.geode.internal.cache.CachePerfStats)1 LRUStatistics (org.apache.geode.internal.cache.lru.LRUStatistics)1 StoredObject (org.apache.geode.internal.offheap.StoredObject)1 Retained (org.apache.geode.internal.offheap.annotations.Retained)1 Unretained (org.apache.geode.internal.offheap.annotations.Unretained)1 PdxInstance (org.apache.geode.pdx.PdxInstance)1 PdxSerializationException (org.apache.geode.pdx.PdxSerializationException)1 ConvertableToBytes (org.apache.geode.pdx.internal.ConvertableToBytes)1 PdxInstanceImpl (org.apache.geode.pdx.internal.PdxInstanceImpl)1