Tabnine Logo
UpfrontAllocatingPageSource
Code IndexAdd Tabnine to your IDE (free)

How to use
UpfrontAllocatingPageSource
in
org.terracotta.offheapstore.paging

Best Java code snippets using org.terracotta.offheapstore.paging.UpfrontAllocatingPageSource (Showing top 16 results out of 315)

origin: ehcache/ehcache3

public ResourcePageSource(ServerSideConfiguration.Pool pool) {
 this.pool = pool;
 this.delegatePageSource = new UpfrontAllocatingPageSource(new OffHeapBufferSource(), pool.getSize(), GIGABYTES.toBytes(1), MEGABYTES.toBytes(128));
}
origin: ehcache/ehcache3

@Override
public void free(Page page) {
 delegatePageSource.free(page);
}
origin: ehcache/ehcache3

@Override
public Page allocate(int size, boolean thief, boolean victim, OffHeapStorageArea owner) {
 return delegatePageSource.allocate(size, thief, victim, owner);
}
origin: org.terracotta/offheap-store

private Page allocateAsThief(final int size, boolean victim, OffHeapStorageArea owner) {
 Page free = allocateFromFree(size, victim, owner);
    victimAllocator = victimAllocators.get(i);
    sliceAllocator = sliceAllocators.get(i);
    targets = findVictimPages(i, address, size);
   for (Page p : targets) {
    victimAllocator.free(p.address(), p.size());
    free(p);
   return allocateFromFree(size, victim, owner);
  } else {
   for (Page p : targets) {
    if (results.contains(p)) {
     victimAllocator.free(p.address(), p.size());
     free(p);
    } else {
     failedReleases.add(p);
  return allocateAsThief(size, victim, owner);
 } finally {
  synchronized (this) {
origin: org.terracotta/offheap-store

/**
 * Allocates a byte buffer of at least the given size.
 * <p>
 * This {@code BufferSource} is limited to allocating regions that are a power
 * of two in size.  Supplied sizes are therefore rounded up to the next
 * largest power of two.
 *
 * @return a buffer of at least the given size
 */
@Override
public Page allocate(int size, boolean thief, boolean victim, OffHeapStorageArea owner) {
 if (thief) {
  return allocateAsThief(size, victim, owner);
 } else {
  return allocateFromFree(size, victim, owner);
 }
}
origin: org.terracotta/offheap-store

for (ByteBuffer buffer : allocateBackingBuffers(source, toAllocate, maxChunk, minChunk, fixed)) {
 sliceAllocators.add(new PowerOfTwoAllocator(buffer.capacity()));
 victimAllocators.add(new PowerOfTwoAllocator(buffer.capacity()));
origin: Terracotta-OSS/offheap-store

private Page allocateAsThief(final int size, boolean victim, OffHeapStorageArea owner) {
 Page free = allocateFromFree(size, victim, owner);
    victimAllocator = victimAllocators.get(i);
    sliceAllocator = sliceAllocators.get(i);
    targets = findVictimPages(i, address, size);
   for (Page p : targets) {
    victimAllocator.free(p.address(), p.size());
    free(p);
   return allocateFromFree(size, victim, owner);
  } else {
   for (Page p : targets) {
    if (results.contains(p)) {
     victimAllocator.free(p.address(), p.size());
     free(p);
    } else {
     failedReleases.add(p);
  return allocateAsThief(size, victim, owner);
 } finally {
  synchronized (this) {
origin: Terracotta-OSS/offheap-store

/**
 * Allocates a byte buffer of at least the given size.
 * <p>
 * This {@code BufferSource} is limited to allocating regions that are a power
 * of two in size.  Supplied sizes are therefore rounded up to the next
 * largest power of two.
 *
 * @return a buffer of at least the given size
 */
@Override
public Page allocate(int size, boolean thief, boolean victim, OffHeapStorageArea owner) {
 if (thief) {
  return allocateAsThief(size, victim, owner);
 } else {
  return allocateFromFree(size, victim, owner);
 }
}
origin: Terracotta-OSS/offheap-store

for (ByteBuffer buffer : allocateBackingBuffers(source, toAllocate, maxChunk, minChunk, fixed)) {
 sliceAllocators.add(new PowerOfTwoAllocator(buffer.capacity()));
 victimAllocators.add(new PowerOfTwoAllocator(buffer.capacity()));
origin: ehcache/ehcache3

@Test
public void testCrossSegmentShrinking() {
 long seed = System.nanoTime();
 Random random = new Random(seed);
 try {
  OffHeapServerStore store = new OffHeapServerStore(new UpfrontAllocatingPageSource(new OffHeapBufferSource(), MEGABYTES.toBytes(1L), MEGABYTES.toBytes(1)), DEFAULT_MAPPER, false);
  ByteBuffer smallValue = ByteBuffer.allocate(1024);
  for (int i = 0; i < 10000; i++) {
   try {
    store.getAndAppend(random.nextInt(500), smallValue.duplicate());
   } catch (OversizeMappingException e) {
    //ignore
   }
  }
  ByteBuffer largeValue = ByteBuffer.allocate(100 * 1024);
  for (int i = 0; i < 10000; i++) {
   try {
    store.getAndAppend(random.nextInt(500), largeValue.duplicate());
   } catch (OversizeMappingException e) {
    //ignore
   }
  }
 } catch (Throwable t) {
  throw (AssertionError) new AssertionError("Failed with seed " + seed).initCause(t);
 }
}
origin: ehcache/ehcache3

private EhcacheConcurrentOffHeapClockCache<K, OffHeapValueHolder<V>> createBackingMap(long size, Serializer<K> keySerializer, Serializer<V> valueSerializer, SwitchableEvictionAdvisor<K, OffHeapValueHolder<V>> evictionAdvisor) {
 HeuristicConfiguration config = new HeuristicConfiguration(size);
 PageSource source = new UpfrontAllocatingPageSource(getBufferSource(), config.getMaximumSize(), config.getMaximumChunkSize(), config.getMinimumChunkSize());
 Portability<K> keyPortability = new SerializerPortability<>(keySerializer);
 Portability<OffHeapValueHolder<V>> elementPortability = new OffHeapValueHolderPortability<>(valueSerializer);
 Factory<OffHeapBufferStorageEngine<K, OffHeapValueHolder<V>>> storageEngineFactory = OffHeapBufferStorageEngine.createFactory(PointerSize.INT, source, config
   .getSegmentDataPageSize(), keyPortability, elementPortability, false, true);
 Factory<? extends PinnableSegment<K, OffHeapValueHolder<V>>> segmentFactory = new EhcacheSegmentFactory<>(
  source,
  storageEngineFactory,
  config.getInitialSegmentTableSize(),
  evictionAdvisor,
  mapEvictionListener);
 return new EhcacheConcurrentOffHeapClockCache<>(evictionAdvisor, segmentFactory, config.getConcurrency());
}
origin: ehcache/ehcache3

SerializationProvider serializationProvider = new DefaultSerializationProvider(null);
serializationProvider.start(providerContaining());
PageSource pageSource = new UpfrontAllocatingPageSource(getBufferSource(), configuration.getMaximumSize(), configuration.getMaximumChunkSize(), configuration.getMinimumChunkSize());
Serializer<String> keySerializer = serializationProvider.createKeySerializer(String.class, EhcacheConcurrentOffHeapClockCacheTest.class.getClassLoader());
Serializer<String> valueSerializer = serializationProvider.createValueSerializer(String.class, EhcacheConcurrentOffHeapClockCacheTest.class.getClassLoader());
origin: ehcache/ehcache3

SerializationProvider serializationProvider = new DefaultSerializationProvider(null);
serializationProvider.start(providerContaining());
PageSource pageSource = new UpfrontAllocatingPageSource(getBufferSource(), configuration.getMaximumSize(), configuration.getMaximumChunkSize(), configuration.getMinimumChunkSize());
Serializer<String> keySerializer = serializationProvider.createKeySerializer(String.class, EhcacheSegmentTest.class.getClassLoader());
Serializer<String> valueSerializer = serializationProvider.createValueSerializer(String.class, EhcacheSegmentTest.class.getClassLoader());
origin: ehcache/ehcache3

@Test
public void testContinualAppendCausingEvictionIsStable() {
 UpfrontAllocatingPageSource pageSource = new UpfrontAllocatingPageSource(new OffHeapBufferSource(), KILOBYTES.toBytes(1024L), KILOBYTES.toBytes(1024));
 if (steal) {
  OffHeapChainMap<String> mapA = new OffHeapChainMap<>(pageSource, StringPortability.INSTANCE, minPageSize, maxPageSize, true);
origin: ehcache/ehcache3

@Test
public void testServerSideUsageStats() {
 long maxBytes = MEGABYTES.toBytes(1);
 OffHeapServerStore store = new OffHeapServerStore(new UpfrontAllocatingPageSource(new OffHeapBufferSource(), maxBytes, MEGABYTES.toBytes(1)), new KeySegmentMapper(16), false);
 int oneKb = 1024;
 long smallLoopCount = 5;
 ByteBuffer smallValue = ByteBuffer.allocate(oneKb);
 for (long i = 0; i < smallLoopCount; i++) {
  store.getAndAppend(i, smallValue.duplicate());
 }
 Assert.assertThat(store.getAllocatedMemory(),lessThanOrEqualTo(maxBytes));
 Assert.assertThat(store.getAllocatedMemory(),greaterThanOrEqualTo(smallLoopCount * oneKb));
 Assert.assertThat(store.getAllocatedMemory(),greaterThanOrEqualTo(store.getOccupiedMemory()));
 //asserts above already guarantee that occupiedMemory <= maxBytes and that occupiedMemory <= allocatedMemory
 Assert.assertThat(store.getOccupiedMemory(),greaterThanOrEqualTo(smallLoopCount * oneKb));
 Assert.assertThat(store.getSize(), is(smallLoopCount));
 int multiplier = 100;
 long largeLoopCount = 5 + smallLoopCount;
 ByteBuffer largeValue = ByteBuffer.allocate(multiplier * oneKb);
 for (long i = smallLoopCount; i < largeLoopCount; i++) {
  store.getAndAppend(i, largeValue.duplicate());
 }
 Assert.assertThat(store.getAllocatedMemory(),lessThanOrEqualTo(maxBytes));
 Assert.assertThat(store.getAllocatedMemory(),greaterThanOrEqualTo( (smallLoopCount * oneKb) + ( (largeLoopCount - smallLoopCount) * oneKb * multiplier) ));
 Assert.assertThat(store.getAllocatedMemory(),greaterThanOrEqualTo(store.getOccupiedMemory()));
 //asserts above already guarantee that occupiedMemory <= maxBytes and that occupiedMemory <= allocatedMemory
 Assert.assertThat(store.getOccupiedMemory(),greaterThanOrEqualTo(smallLoopCount * oneKb));
 Assert.assertThat(store.getSize(), is(smallLoopCount + (largeLoopCount - smallLoopCount)));
}
origin: org.ehcache/ehcache

private EhcacheConcurrentOffHeapClockCache<K, OffHeapValueHolder<V>> createBackingMap(long size, Serializer<K> keySerializer, Serializer<V> valueSerializer, SwitchableEvictionAdvisor<K, OffHeapValueHolder<V>> evictionAdvisor) {
 HeuristicConfiguration config = new HeuristicConfiguration(size);
 PageSource source = new UpfrontAllocatingPageSource(getBufferSource(), config.getMaximumSize(), config.getMaximumChunkSize(), config.getMinimumChunkSize());
 Portability<K> keyPortability = new SerializerPortability<>(keySerializer);
 Portability<OffHeapValueHolder<V>> elementPortability = new OffHeapValueHolderPortability<>(valueSerializer);
 Factory<OffHeapBufferStorageEngine<K, OffHeapValueHolder<V>>> storageEngineFactory = OffHeapBufferStorageEngine.createFactory(PointerSize.INT, source, config
   .getSegmentDataPageSize(), keyPortability, elementPortability, false, true);
 Factory<? extends PinnableSegment<K, OffHeapValueHolder<V>>> segmentFactory = new EhcacheSegmentFactory<>(
  source,
  storageEngineFactory,
  config.getInitialSegmentTableSize(),
  evictionAdvisor,
  mapEvictionListener);
 return new EhcacheConcurrentOffHeapClockCache<>(evictionAdvisor, segmentFactory, config.getConcurrency());
}
org.terracotta.offheapstore.pagingUpfrontAllocatingPageSource

Javadoc

An upfront allocating direct byte buffer source.

This buffer source implementation allocates all of its required storage up-front in fixed size chunks. Runtime allocations are then satisfied using slices from these initial chunks.

Most used methods

  • <init>
    Create an up-front allocating buffer source of toAllocate total bytes, in maximally sized chunks, wi
  • free
    Frees the supplied buffer. If the given buffer was not allocated by this source or has already been
  • allocate
    Allocates a byte buffer of at least the given size. This BufferSource is limited to allocating regio
  • allocateAsThief
  • allocateBackingBuffers
    Allocate multiple buffers to fulfill the requested memory toAllocate. We first divide toAllocate in
  • allocateFromFree
  • bufferAllocation
  • createAllocatorLog
  • findVictimPages
  • fireThresholds
  • getAllocatedSize
  • getAllocatedSizeUnSync
  • getAllocatedSize,
  • getAllocatedSizeUnSync,
  • isUnavailable,
  • markAllAvailable,
  • markUnavailable,
  • uninterruptibleGet

Popular in Java

  • Parsing JSON documents to java classes using gson
  • onRequestPermissionsResult (Fragment)
  • getSupportFragmentManager (FragmentActivity)
  • getApplicationContext (Context)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now