Merge remote-tracking branch 'origin/master'

This commit is contained in:
Rob Austin
2014-11-26 13:39:18 +00:00
6 changed files with 40 additions and 31 deletions
@@ -20,14 +20,14 @@ package net.openhft.chronicle.hash.serialization.internal;
import net.openhft.chronicle.hash.serialization.BytesWriter;
import net.openhft.chronicle.hash.serialization.Hasher;
import net.openhft.lang.threadlocal.Provider;
import net.openhft.lang.threadlocal.StatefulCopyable;
import net.openhft.lang.threadlocal.ThreadLocalCopies;
import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.DirectBytes;
import net.openhft.lang.io.DirectStore;
import net.openhft.lang.io.serialization.BytesMarshaller;
import net.openhft.lang.io.serialization.JDKObjectSerializer;
import net.openhft.lang.io.serialization.JDKZObjectSerializer;
import net.openhft.lang.threadlocal.Provider;
import net.openhft.lang.threadlocal.StatefulCopyable;
import net.openhft.lang.threadlocal.ThreadLocalCopies;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -206,7 +206,7 @@ public abstract class CopyingMetaBytesInterop<E, W> implements MetaBytesInterop<
return buffer = store.bytes();
}
} else {
buffer = new DirectStore(JDKObjectSerializer.INSTANCE, maxSize, false).bytes();
buffer = new DirectStore(JDKZObjectSerializer.INSTANCE, maxSize, false).bytes();
return buffer;
}
}
@@ -605,10 +605,9 @@ abstract class AbstractChronicleMapBuilder<K, V,
return self();
}
ObjectSerializer objectSerializer() {
ObjectSerializer acquireObjectSerializer(ObjectSerializer defaultSerializer) {
return objectSerializer == null ?
objectSerializer = BytesMarshallableSerializer.create(
bytesMarshallerFactory(), JDKObjectSerializer.INSTANCE) :
BytesMarshallableSerializer.create(bytesMarshallerFactory(), defaultSerializer) :
objectSerializer;
}
@@ -861,7 +860,7 @@ abstract class AbstractChronicleMapBuilder<K, V,
VanillaChronicleMap<K, ?, ?, V, ?, ?> map =
new ReplicatedChronicleMap<K, Object, MetaBytesInterop<K, Object>,
V, Object, MetaBytesWriter<V, Object>>(this, identifier);
BytesStore bytesStore = new DirectStore(JDKObjectSerializer.INSTANCE,
BytesStore bytesStore = new DirectStore(JDKZObjectSerializer.INSTANCE,
map.sizeInBytes(), true);
map.createMappedStoreAndSegments(bytesStore);
return map;
@@ -872,7 +871,7 @@ abstract class AbstractChronicleMapBuilder<K, V,
pushingToMapEventListener();
try {
VanillaChronicleMap<K, ?, ?, V, ?, ?> map = newMap(singleHashReplication, channel);
BytesStore bytesStore = new DirectStore(JDKObjectSerializer.INSTANCE,
BytesStore bytesStore = new DirectStore(JDKZObjectSerializer.INSTANCE,
map.sizeInBytes(), true);
map.createMappedStoreAndSegments(bytesStore);
return establishReplication(map, singleHashReplication, channel);
@@ -933,8 +932,8 @@ abstract class AbstractChronicleMapBuilder<K, V,
}
void preMapConstruction(boolean replicated) {
keyBuilder.objectSerializer(objectSerializer());
valueBuilder.objectSerializer(objectSerializer());
keyBuilder.objectSerializer(acquireObjectSerializer(JDKObjectSerializer.INSTANCE));
valueBuilder.objectSerializer(acquireObjectSerializer(JDKZObjectSerializer.INSTANCE));
long maxSize = (long) entrySize(replicated) * figureBufferAllocationFactor();
keyBuilder.maxSize(maxSize);
@@ -28,7 +28,7 @@ import net.openhft.chronicle.hash.serialization.internal.MetaProvider;
import net.openhft.lang.collection.DirectBitSet;
import net.openhft.lang.collection.SingleThreadedDirectBitSet;
import net.openhft.lang.io.*;
import net.openhft.lang.io.serialization.JDKObjectSerializer;
import net.openhft.lang.io.serialization.JDKZObjectSerializer;
import net.openhft.lang.io.serialization.impl.VanillaBytesMarshallerFactory;
import net.openhft.lang.model.constraints.Nullable;
import net.openhft.lang.threadlocal.Provider;
@@ -208,7 +208,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
long createMappedStoreAndSegments(File file) throws IOException {
return createMappedStoreAndSegments(new MappedStore(file, FileChannel.MapMode.READ_WRITE,
sizeInBytes(), JDKObjectSerializer.INSTANCE));
sizeInBytes(), JDKZObjectSerializer.INSTANCE));
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
@@ -20,10 +20,7 @@ package net.openhft.chronicle.map;
import net.openhft.lang.Jvm;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.io.*;
import java.util.Arrays;
/**
@@ -35,15 +32,21 @@ import java.util.Arrays;
public class OSResizesMain {
public static void main(String[] args) throws IOException, InterruptedException {
File file = File.createTempFile("over-sized", "deleteme");
ChronicleMap<String, String> map = ChronicleMapBuilder.of(String.class, String.class)
.entrySize(100 * 1024 * 1024)
.entries(1000 * 1000)
int valueSize = 1000 * 1000;
ChronicleMap<String, ByteArray> map = ChronicleMapBuilder.of(String.class, ByteArray.class)
.entrySize(50 * 1024 * 1024)
.valueSize(valueSize + 16)
.createPersistedTo(file);
for (int i = 0; i < 10000; i++) {
char[] chars = new char[i];
Arrays.fill(chars, '+');
map.put("key-" + i, new String(chars));
byte[] chars = new byte[valueSize];
Arrays.fill(chars, (byte) '+');
ByteArray ba = new ByteArray(chars);
for (int i = 0; i < 1000; i++) {
map.put("key-" + i, ba);
}
long start = System.currentTimeMillis();
System.gc();
long time0 = System.currentTimeMillis() - start;
System.out.printf("GC time: %,d ms%n", time0);
System.out.printf("System memory: %.1f GB, Extents of map: %.1f GB, disk used: %sB, addressRange: %s%n",
Double.parseDouble(run("head", "-1", "/proc/meminfo").split("\\s+")[1]) / 1e6,
file.length() / 1e9,
@@ -51,7 +54,7 @@ public class OSResizesMain {
run("grep", "over-sized", "/proc/" + Jvm.getProcessId() + "/maps").split("\\s")[0]);
// show up in top.
long time = System.currentTimeMillis();
while (time + 20000 > System.currentTimeMillis())
while (time + 30000 > System.currentTimeMillis())
Thread.yield();
map.close();
file.delete();
@@ -73,3 +76,11 @@ public class OSResizesMain {
return sw.toString();
}
}
class ByteArray implements Serializable {
final byte[] bytes;
ByteArray(byte[] bytes) {
this.bytes = bytes;
}
}
@@ -18,7 +18,7 @@
package net.openhft.chronicle.map;
import net.openhft.lang.io.serialization.JDKObjectSerializer;
import net.openhft.lang.io.serialization.JDKZObjectSerializer;
import org.junit.Test;
import java.io.*;
@@ -35,7 +35,7 @@ public class RecursiveRefereneChMapTest {
file.deleteOnExit();
Map<String, StupidCycle> map = ChronicleMapBuilder.of(String.class, StupidCycle.class)
.entries(64)
.objectSerializer(JDKObjectSerializer.INSTANCE).create();
.objectSerializer(JDKZObjectSerializer.INSTANCE).create();
map.put("Test", new StupidCycle());
map.put("Test2", new StupidCycle2());
StupidCycle cycle = (StupidCycle) map.get("Test");
@@ -19,6 +19,7 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.map.jrs166.JSR166TestCase;
import org.junit.Ignore;
import org.junit.Test;
import java.io.IOException;
@@ -33,10 +34,8 @@ import static org.junit.Assert.*;
* Other contributors include Andrew Wright, Jeffrey Hayes,
* Pat Fisher, Mike Judd. Then modified by the Open HFT team.
*/
@Ignore
public class ReplicatedChronicleMapTest extends JSR166TestCase {
ChronicleMap<Integer, CharSequence> newShmIntString() throws IOException {
return ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.create();