You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2015/11/20 02:07:54 UTC
[19/20] incubator-geode git commit: move SyncChunkStack from
SimpleMemoryAllocatorImpl
move SyncChunkStack from SimpleMemoryAllocatorImpl
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/18f5e9d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/18f5e9d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/18f5e9d5
Branch: refs/heads/feature/GEODE-580
Commit: 18f5e9d53725609a2b94a4335a2403681120ae2f
Parents: 27b2aeb
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 16:58:04 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 16:58:04 2015 -0800
----------------------------------------------------------------------
.../offheap/SimpleMemoryAllocatorImpl.java | 101 +-------------
.../internal/offheap/SyncChunkStack.java | 130 +++++++++++++++++++
2 files changed, 131 insertions(+), 100 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/18f5e9d5/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
index 6303f5b..0cb7068 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
@@ -1223,105 +1223,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
- public static class SyncChunkStack {
- // Ok to read without sync but must be synced on write
- private volatile long topAddr;
-
- public SyncChunkStack(long addr) {
- if (addr != 0L) validateAddress(addr);
- this.topAddr = addr;
- }
- public SyncChunkStack() {
- this.topAddr = 0L;
- }
- public boolean isEmpty() {
- return this.topAddr == 0L;
- }
- public void offer(long e) {
- assert e != 0;
- validateAddress(e);
- synchronized (this) {
- Chunk.setNext(e, this.topAddr);
- this.topAddr = e;
- }
- }
- public long poll() {
- long result;
- synchronized (this) {
- result = this.topAddr;
- if (result != 0L) {
- this.topAddr = Chunk.getNext(result);
- }
- }
- return result;
- }
- /**
- * Removes all the Chunks from this stack
- * and returns the address of the first chunk.
- * The caller owns all the Chunks after this call.
- */
- public long clear() {
- long result;
- synchronized (this) {
- result = this.topAddr;
- if (result != 0L) {
- this.topAddr = 0L;
- }
- }
- return result;
- }
- public void logSizes(LogWriter lw, String msg) {
- long headAddr = this.topAddr;
- long addr;
- boolean concurrentModDetected;
- do {
- concurrentModDetected = false;
- addr = headAddr;
- while (addr != 0L) {
- int curSize = Chunk.getSize(addr);
- addr = Chunk.getNext(addr);
- long curHead = this.topAddr;
- if (curHead != headAddr) {
- headAddr = curHead;
- concurrentModDetected = true;
- // Someone added or removed from the stack.
- // So we break out of the inner loop and start
- // again at the new head.
- break;
- }
- // TODO construct a single log msg
- // that gets reset on the concurrent mad.
- lw.info(msg + curSize);
- }
- } while (concurrentModDetected);
- }
- public long computeTotalSize() {
- long result;
- long headAddr = this.topAddr;
- long addr;
- boolean concurrentModDetected;
- do {
- concurrentModDetected = false;
- result = 0;
- addr = headAddr;
- while (addr != 0L) {
- result += Chunk.getSize(addr);
- addr = Chunk.getNext(addr);
- long curHead = this.topAddr;
- if (curHead != headAddr) {
- headAddr = curHead;
- concurrentModDetected = true;
- // Someone added or removed from the stack.
- // So we break out of the inner loop and start
- // again at the new head.
- break;
- }
- }
- } while (concurrentModDetected);
- return result;
- }
- }
-
static void validateAddress(long addr) {
validateAddressAndSize(addr, -1);
}
@@ -1522,7 +1423,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
AtomicReferenceArray<SyncChunkStack> chunkStacks = this.freeList.tinyFreeLists;
for (int i = 0; i < chunkStacks.length(); i++) {
if (chunkStacks.get(i) == null) continue;
- long addr = chunkStacks.get(i).topAddr;
+ long addr = chunkStacks.get(i).getTopAddress();
final int size = Chunk.getSize(addr);
final long address = addr;
final int freeListId = i;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/18f5e9d5/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SyncChunkStack.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SyncChunkStack.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SyncChunkStack.java
new file mode 100644
index 0000000..a615af0
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SyncChunkStack.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.offheap;
+
+import com.gemstone.gemfire.LogWriter;
+
+/**
+ * A "stack" of "chunk" instances. The chunks are not kept
+ * in java object form but instead each "chunk" is just an
+ * off-heap address.
+ * This class is used for each "tiny" free-list of the off-heap memory allocator.
+ */
+public class SyncChunkStack {
+ // Ok to read without sync but must be synced on write
+ private volatile long topAddr;
+
+ public SyncChunkStack(long addr) {
+ if (addr != 0L) SimpleMemoryAllocatorImpl.validateAddress(addr);
+ this.topAddr = addr;
+ }
+ public SyncChunkStack() {
+ this.topAddr = 0L;
+ }
+ public boolean isEmpty() {
+ return this.topAddr == 0L;
+ }
+ public void offer(long e) {
+ assert e != 0;
+ SimpleMemoryAllocatorImpl.validateAddress(e);
+ synchronized (this) {
+ Chunk.setNext(e, this.topAddr);
+ this.topAddr = e;
+ }
+ }
+ public long poll() {
+ long result;
+ synchronized (this) {
+ result = this.topAddr;
+ if (result != 0L) {
+ this.topAddr = Chunk.getNext(result);
+ }
+ }
+ return result;
+ }
+ /**
+ * Returns the address of the "top" item in this stack.
+ */
+ public long getTopAddress() {
+ return this.topAddr;
+ }
+ /**
+ * Removes all the Chunks from this stack
+ * and returns the address of the first chunk.
+ * The caller owns all the Chunks after this call.
+ */
+ public long clear() {
+ long result;
+ synchronized (this) {
+ result = this.topAddr;
+ if (result != 0L) {
+ this.topAddr = 0L;
+ }
+ }
+ return result;
+ }
+ public void logSizes(LogWriter lw, String msg) {
+ long headAddr = this.topAddr;
+ long addr;
+ boolean concurrentModDetected;
+ do {
+ concurrentModDetected = false;
+ addr = headAddr;
+ while (addr != 0L) {
+ int curSize = Chunk.getSize(addr);
+ addr = Chunk.getNext(addr);
+ long curHead = this.topAddr;
+ if (curHead != headAddr) {
+ headAddr = curHead;
+ concurrentModDetected = true;
+ // Someone added or removed from the stack.
+ // So we break out of the inner loop and start
+ // again at the new head.
+ break;
+ }
+ // TODO construct a single log msg
+ // that gets reset on the concurrent mad.
+ lw.info(msg + curSize);
+ }
+ } while (concurrentModDetected);
+ }
+ public long computeTotalSize() {
+ long result;
+ long headAddr = this.topAddr;
+ long addr;
+ boolean concurrentModDetected;
+ do {
+ concurrentModDetected = false;
+ result = 0;
+ addr = headAddr;
+ while (addr != 0L) {
+ result += Chunk.getSize(addr);
+ addr = Chunk.getNext(addr);
+ long curHead = this.topAddr;
+ if (curHead != headAddr) {
+ headAddr = curHead;
+ concurrentModDetected = true;
+ // Someone added or removed from the stack.
+ // So we break out of the inner loop and start
+ // again at the new head.
+ break;
+ }
+ }
+ } while (concurrentModDetected);
+ return result;
+ }
+}
\ No newline at end of file