diff --git a/pom.xml b/pom.xml
index 4587be893..f4d559250 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,7 +53,7 @@
net.openhft
affinity
- 2.1.4
+ 2.2
diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java
index 995eea719..62486bae2 100644
--- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java
+++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java
@@ -28,7 +28,7 @@ import java.io.Serializable;
public abstract class CopyingMetaBytesInterop extends BasicCopyingMetaBytesInterop {
private static final long serialVersionUID = 1L;
- private static final long MAX_REASONABLE_SERIALIZED_SIZE = MemoryUnit.MEGABYTES.toBytes(512L);
+ private static final long MAX_REASONABLE_SERIALIZED_SIZE = MemoryUnit.MEGABYTES.toBytes(16L);
public static void checkMaxSizeStillReasonable(long maxSize, Exception ex) {
if (maxSize > MAX_REASONABLE_SERIALIZED_SIZE) {
diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueMetaBytesInterop.java
index 87eeb84b5..4a596b457 100644
--- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueMetaBytesInterop.java
+++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueMetaBytesInterop.java
@@ -34,7 +34,7 @@ public abstract class DataValueMetaBytesInterop
}
void init(BytesWriter writer, E e, long size) {
- Bytes buffer = this.buffer.obtain(size, false);
+ Bytes buffer = this.buffer.obtain(size, true);
writer.write(buffer, e);
buffer.flip();
assert buffer.remaining() == size;
diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DirectBytesBuffer.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DirectBytesBuffer.java
index c01ceb59d..8965b5c3c 100644
--- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DirectBytesBuffer.java
+++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DirectBytesBuffer.java
@@ -17,7 +17,6 @@
package net.openhft.chronicle.hash.serialization.internal;
import net.openhft.chronicle.hash.serialization.BytesWriter;
-import net.openhft.lang.io.BoundsCheckingNativeBytes;
import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.DirectBytes;
import net.openhft.lang.io.DirectStore;
@@ -34,7 +33,6 @@ class DirectBytesBuffer
private static final long serialVersionUID = 0L;
private final Serializable identity;
transient DirectBytes buffer;
- transient BoundsCheckingNativeBytes checkingBuffer;
transient ForBytesMarshaller forBytesMarshaller;
transient ForBytesWriter forBytesWriter;
@@ -60,29 +58,16 @@ class DirectBytesBuffer
DirectBytes buf;
if ((buf = buffer) != null) {
if (maxSize <= buf.capacity()) {
- if (!boundsChecking)
- return buf.clear();
- Bytes checkingBuf;
- if ((checkingBuf = checkingBuffer) != null) {
- return checkingBuf.clear();
- } else {
- return (checkingBuffer = new BoundsCheckingNativeBytes(buf)).clear();
- }
+ return buf.clear();
} else {
DirectStore store = (DirectStore) buf.store();
- store.resize(maxSize, true);
- buf = buffer = store.bytes();
- if (!boundsChecking)
- return buf;
- return (checkingBuffer = new BoundsCheckingNativeBytes(buf));
+ store.resize(maxSize, false);
+ return buffer = store.bytes();
}
} else {
- buf = buffer = new DirectStore(JDKObjectSerializer.INSTANCE,
- // don't allocate 0 bytes
- Math.max(1, maxSize), true).bytes();
- if (!boundsChecking)
- return buf;
- return (checkingBuffer = new BoundsCheckingNativeBytes(buf));
+ buffer = new DirectStore(JDKObjectSerializer.INSTANCE, Math.max(1, maxSize), true)
+ .bytes();
+ return buffer;
}
}
@@ -140,7 +125,7 @@ class DirectBytesBuffer
this.writer = writer;
cur = e;
long size = writer.size(e);
- Bytes buffer = this.buffer.obtain(size, false);
+ Bytes buffer = this.buffer.obtain(size, true);
writer.write(buffer, e);
buffer.flip();
this.size = size;
diff --git a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java
index 98846efb3..7f1bec3df 100644
--- a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java
+++ b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java
@@ -34,9 +34,7 @@ import net.openhft.lang.threadlocal.ThreadLocalCopies;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.Serializable;
+import java.io.*;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -50,6 +48,7 @@ import static net.openhft.chronicle.hash.serialization.SizeMarshallers.stopBit;
import static net.openhft.chronicle.map.Objects.hash;
final class SerializationBuilder implements Cloneable, Serializable {
+ private static final long serialVersionUID = 0L;
private static final Bytes EMPTY_BYTES = new ByteBufferBytes(ByteBuffer.allocate(0));
@@ -88,6 +87,8 @@ final class SerializationBuilder implements Cloneable, Serializable {
private long maxSize;
final boolean sizeIsStaticallyKnown;
+
+ boolean serializesGeneratedClasses = false;
@SuppressWarnings("unchecked")
SerializationBuilder(Class eClass, Role role) {
@@ -112,10 +113,12 @@ final class SerializationBuilder implements Cloneable, Serializable {
metaInterop((MetaBytesInterop) DataValueMetaBytesInterop.forIdentity(role));
metaInteropProvider(DataValueMetaBytesInterop.interopProvider(eClass));
sizeMarshaller(constant((long) size));
+ serializesGeneratedClasses = true;
return;
} catch (Exception e) {
try {
eClass = DataValueClasses.directClassFor(eClass);
+ serializesGeneratedClasses = true;
} catch (Exception ex) {
// ignore, fall through
}
@@ -173,6 +176,25 @@ final class SerializationBuilder implements Cloneable, Serializable {
}
}
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ out.writeBoolean(serializesGeneratedClasses);
+ if (serializesGeneratedClasses) {
+ out.writeObject(eClass);
+ out.writeObject(role);
+ }
+ out.defaultWriteObject();
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ boolean generatedClassesSerialized = in.readBoolean();
+ if (generatedClassesSerialized) {
+ Class eClass = (Class) in.readObject();
+ Role role = (Role) in.readObject();
+ new SerializationBuilder(eClass, role);
+ }
+ in.defaultReadObject();
+ }
+
boolean possibleOffHeapReferences() {
if (reader instanceof CharSequenceReader)
return false;
diff --git a/src/test/java/net/openhft/lang/values/LongValue$$Native.java b/src/test/java/net/openhft/lang/values/LongValue$$Native.java
index 8e737b3a7..597ba10ca 100644
--- a/src/test/java/net/openhft/lang/values/LongValue$$Native.java
+++ b/src/test/java/net/openhft/lang/values/LongValue$$Native.java
@@ -50,12 +50,18 @@ public class LongValue$$Native implements LongValue, BytesMarshallable, Byteable
public long addValue(long $) {
return _bytes.addLong(_offset + VALUE, $);
- } public long addAtomicValue(long $) {
+ }
+
+ public long addAtomicValue(long $) {
return _bytes.addAtomicLong(_offset + VALUE, $);
- } public boolean compareAndSwapValue(long _1, long _2) {
+ }
+
+ public boolean compareAndSwapValue(long _1, long _2) {
return _bytes.compareAndSwapLong(_offset + VALUE, _1, _2);
- } @Override
- public void copyFrom(net.openhft.lang.values.LongValue from) {
+ }
+
+ @Override
+ public void copyFrom(net.openhft.lang.values.LongValue from) {
setValue(from.getValue());
}
@@ -63,27 +69,33 @@ public class LongValue$$Native implements LongValue, BytesMarshallable, Byteable
public void writeMarshallable(Bytes out) {
out.writeLong(getValue());
}
+
@Override
public void readMarshallable(Bytes in) {
setValue(in.readLong());
}
+
@Override
public void bytes(Bytes bytes, long offset) {
this._bytes = bytes;
this._offset = offset;
}
+
@Override
public Bytes bytes() {
return _bytes;
}
+
@Override
public long offset() {
return _offset;
}
+
@Override
public int maxSize() {
return 8;
}
+
public int hashCode() {
long lhc = longHashCode();
return (int) ((lhc >>> 32) ^ lhc);
@@ -98,7 +110,7 @@ public class LongValue$$Native implements LongValue, BytesMarshallable, Byteable
if (!(o instanceof LongValue)) return false;
LongValue that = (LongValue) o;
- if(!isEqual(getValue(), that.getValue())) return false;
+ if (!isEqual(getValue(), that.getValue())) return false;
return true;
}