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;
}
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;
}
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;
}
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);
}
Aggregations