You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2016/03/07 22:43:10 UTC
svn commit: r1733990 [1/2] -
/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/
Author: schor
Date: Mon Mar 7 21:43:10 2016
New Revision: 1733990
URL: http://svn.apache.org/viewvc?rev=1733990&view=rev
Log:
[UIMA-4825] [UIMA-4820] preserve required simulated addr info, remove redundant checking
Modified:
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes.java
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CommonSerDesSequential.java
uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImplC.java
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes.java?rev=1733990&r1=1733989&r2=1733990&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes.java Mon Mar 7 21:43:10 2016
@@ -66,12 +66,39 @@ import org.apache.uima.util.Misc;
* in this class.
*
* There is one instance of this class per CAS (shared by all views of that CAS).
+ *
+ * Lifecycle:
+ * created when a CAS (any view) is first created, as part of the shared view data for that CAS.
+ * never re-created.
+ *
+ * Data created when non-delta serializing, in case needed when delta-deserializing later:
+ * xxxAuxAddr2fsa maps aux arrays to FSs
+ *
+ * Data created when non-delta deserializing, in case needed when delta-serializing later:
+ * heaps and nextXXXHeapAddrAfterMark (in this case mark is the end).
+ *
+ * Reset:
+ *
+ * Instance Data:
+ * baseCas - ref to the corresponding CAS (final)
+ * tsi - the CAS's type system impl (can change; each use sets it from CAS API)
+ *
+ * heaps - there is 1 main heap, and 4 aux heaps (Byte, Short, Long, and String
+ * Some uses of this class require these be materialized. (May be input or output)
+ *
+ * for Delta deserialization:
+ * 5 ints - representing the first free address in the above 5 heaps, after the mark
+ *
+ * For delta deserialization: Maps for Aux arrays representing updatable arrays (not String):
+ * From starting addr in the aux array to the corresponding V3 FS object
*/
public class BinaryCasSerDes {
- static final int Version1Flag_V3 = 0x01_00_00;
private static final boolean TRACE_DESER = false;
+ private static final boolean SOFA_IN_NORMAL_ORDER = false;
+ private static final boolean SOFA_AHEAD_OF_NORMAL_ORDER = true;
+
/**
* The offset for the array length cell. An array consists of length+2 number
* of cells, where the first cell contains the type, the second one the length,
@@ -153,9 +180,9 @@ public class BinaryCasSerDes {
* updated when delta deserializing
* reset at end of delta deserializings because multiple mods not supported
*/
- final Int2ObjHashMap<TOP> byteAuxAddr2fsa = new Int2ObjHashMap<>(TOP.class);
- final Int2ObjHashMap<TOP> shortAuxAddr2fsa = new Int2ObjHashMap<>(TOP.class);
- final Int2ObjHashMap<TOP> longAuxAddr2fsa = new Int2ObjHashMap<>(TOP.class);
+ final private Int2ObjHashMap<TOP> byteAuxAddr2fsa = new Int2ObjHashMap<>(TOP.class);
+ final private Int2ObjHashMap<TOP> shortAuxAddr2fsa = new Int2ObjHashMap<>(TOP.class);
+ final private Int2ObjHashMap<TOP> longAuxAddr2fsa = new Int2ObjHashMap<>(TOP.class);
public BinaryCasSerDes(CASImpl baseCAS) {
this.baseCas = baseCAS;
@@ -176,6 +203,17 @@ public class BinaryCasSerDes {
.getByteArray(), ser.getShortArray(), ser.getLongArray());
}
+ /**
+ * This is for deserializing (never delta) from a serialized java object representation or maybe from the JNI bridge
+ *
+ * @param heapMetadata -
+ * @param heapArray -
+ * @param stringTable -
+ * @param fsIndex -
+ * @param byteHeapArray -
+ * @param shortHeapArray -
+ * @param longHeapArray -
+ */
void reinit(int[] heapMetadata, int[] heapArray, String[] stringTable, int[] fsIndex,
byte[] byteHeapArray, short[] shortHeapArray, long[] longHeapArray) {
CommonSerDesSequential csds = new CommonSerDesSequential(baseCas);
@@ -206,6 +244,7 @@ public class BinaryCasSerDes {
/**
* Deserializer for CASCompleteSerializer instances - includes type system and index definitions
+ * Never delta
* @param casCompSer -
*/
public void reinit(CASCompleteSerializer casCompSer) {
@@ -371,6 +410,8 @@ public class BinaryCasSerDes {
* needed if the blob is from C++ -- C++ blob serialization writes data in
* native byte order.
*
+ * Supports delta deserialization. For that, the the csds from the serialization event must be used.
+ *
* @param istream -
* @return - the format of the input stream detected
* @throws CASRuntimeException wraps IOException
@@ -459,21 +500,21 @@ public class BinaryCasSerDes {
*/
private SerialFormat binaryDeserialization(Header h) {
- CommonSerDesSequential csds = new CommonSerDesSequential(baseCas);
-
final boolean delta = h.isDelta;
final Reading r = h.reading;
final DataInputStream dis = r.dis;
+ final CommonSerDesSequential csds;
+
if (delta) {
if (nextHeapAddrAfterMark == 0 ||
heap == null ||
heap.getCellsUsed() <=1) {
Misc.internalError(); // can't deserialize without a previous binary serialization for this CAS
}
- csds.setup();
+ csds = baseCas.getCsds();
} else {
if (heap == null) heap = new Heap(); else heap.reset();
if (byteHeap == null) byteHeap = new ByteHeap(); else byteHeap.reset();
@@ -481,7 +522,7 @@ public class BinaryCasSerDes {
if (longHeap == null) longHeap = new LongHeap(); else longHeap.reset();
if (stringHeap == null) stringHeap = new StringHeap(); else stringHeap.reset();
clearDeltaOffsets();
- csds.clear();
+ csds = baseCas.newCsds();
}
try {
@@ -654,7 +695,7 @@ public class BinaryCasSerDes {
* The modifications are all to existing FSs.
* The modifications consist of an address (offset in an aux array) which is an array element.
* We don't update the aux array, but instead update the actual FS below the line representing the array.
- * To identify the fs, we use the xxAuxAddr2fs sorted list forms and do a binary search to find the item to update,
+ * To identify the fs, we use the xxAuxAddr2fsa sorted list forms and do a binary search to find the item to update,
* with a fast path for the same or next item.
* Same - use case is multiple updates into the same array
*/
@@ -742,9 +783,10 @@ public class BinaryCasSerDes {
if (!delta) {
setHeapExtents();
+ csds.setHeapEnd(nextHeapAddrAfterMark);
}
- // cleanup
+ // cleanup at the end of Binary Deserialization, both Delta and full
// saved and not cleaned up
// because needed by subsequent delta serialization:
// fs2addr, addr2fs,
@@ -759,8 +801,6 @@ public class BinaryCasSerDes {
shortHeap = null;
longHeap = null;
- csds.clearSortedFSs();
-
// cleared because only used for delta deser, for mods, and mods not allowed for multiple deltas
byteAuxAddr2fsa.clear();
shortAuxAddr2fsa.clear();
@@ -786,7 +826,7 @@ public class BinaryCasSerDes {
nextStringHeapAddrAfterMark = stringHeap.getSize() - 1;
nextByteHeapAddrAfterMark = byteHeap.getSize() - 1;
nextShortHeapAddrAfterMark = shortHeap.getSize() - 1;
- nextLongHeapAddrAfterMark = longHeap.getSize() - 1;
+ nextLongHeapAddrAfterMark = longHeap.getSize() - 1;
}
/**
* Called 3 times to process non-compressed binary deserialization of aux array modifications
@@ -1190,14 +1230,16 @@ public class BinaryCasSerDes {
void scanAllFSsForBinarySerialization(MarkerImpl mark, CommonSerDesSequential csds) {
final boolean isMarkSet = mark != null;
- csds.clear();
-
-
- // in delta case, as well as non delta case,
- // add above and below the line (**all**) FSs to fs2addr map
-
- csds.setup();
-
+ if (isMarkSet) {
+ if (csds.getHeapEnd() == 0) {
+ System.out.println("debug");
+ }
+ csds.setup(mark.getNextFSId(), csds.getHeapEnd());
+ } else {
+ csds.clear();
+ csds.setup();
+ }
+
// For delta, these heaps will start at 1, and only hold new items
heap = new Heap();
byteHeap = new ByteHeap();
@@ -1209,7 +1251,7 @@ public class BinaryCasSerDes {
clearDeltaOffsets(); // set nextXXheapAfterMark to 0;
}
- for (TOP fs : csds.sortedFSs) {
+ for (TOP fs : csds.getSortedFSs()) {
if (!isMarkSet || mark.isNew(fs)) {
// skip extraction for FSs below the mark.
// - updated slots will update aux heaps when delta mods are processed
@@ -1307,27 +1349,27 @@ public class BinaryCasSerDes {
int i = pos + 1;
for (FeatureImpl feat : type.getFeatureImpls()) {
switch (feat.getSlotKind()) {
- case Slot_Boolean: heap.heap[i++] = fs.getBooleanValue(feat) ? 1 : 0; break;
- case Slot_Byte: heap.heap[i++] = fs.getByteValue(feat); break;
- case Slot_Short: heap.heap[i++] = fs.getShortValue(feat); break;
- case Slot_Int: heap.heap[i++] = fs.getIntValue(feat); break;
- case Slot_Float: heap.heap[i++] = CASImpl.float2int(fs.getFloatValue(feat)); break;
+ case Slot_Boolean: heap.heap[i++] = fs._getBooleanValueNc(feat) ? 1 : 0; break;
+ case Slot_Byte: heap.heap[i++] = fs._getByteValueNc(feat); break;
+ case Slot_Short: heap.heap[i++] = fs._getShortValueNc(feat); break;
+ case Slot_Int: heap.heap[i++] = fs._getIntValueNc(feat); break;
+ case Slot_Float: heap.heap[i++] = CASImpl.float2int(fs._getFloatValueNc(feat)); break;
case Slot_LongRef: {
- int lAddr = longHeap.addLong(fs.getLongValue(feat));
+ int lAddr = longHeap.addLong(fs._getLongValueNc(feat));
heap.heap[i++] = nextLongHeapAddrAfterMark + lAddr;
break;
}
case Slot_DoubleRef: {
- int lAddr = longHeap.addLong(CASImpl.double2long(fs.getDoubleValue(feat)));
+ int lAddr = longHeap.addLong(CASImpl.double2long(fs._getDoubleValueNc(feat)));
heap.heap[i++] = nextLongHeapAddrAfterMark + lAddr;
break;
}
case Slot_StrRef: {
- int sAddr = stringHeap.addString(fs.getStringValue(feat));
+ int sAddr = stringHeap.addString(fs._getStringValueNc(feat));
heap.heap[i++] = (sAddr == 0) ? 0 : nextStringHeapAddrAfterMark + sAddr; // is 0 if string is null
break;
}
- case Slot_HeapRef: heap.heap[i++] = fs2addr.get(fs.getFeatureValue(feat)); break;
+ case Slot_HeapRef: heap.heap[i++] = fs2addr.get(fs._getFeatureValueNc(feat)); break;
default: Misc.internalError();
} // end of switch
} // end of iter over all features
@@ -1360,16 +1402,12 @@ public class BinaryCasSerDes {
* Delta serialization: this routine adds just the new (above-the-line) FSs, and augments existing addr2fs and auxAddr2fsa
*/
private void createFSsFromHeaps(boolean isDelta, int startPos, CommonSerDesSequential csds) {
- final Int2ObjHashMap<TOP> addr2fs = csds.addr2fs;
final int heapsz = heap.getCellsUsed();
+ final Int2ObjHashMap<TOP> addr2fs = csds.addr2fs;
tsi = baseCas.getTypeSystemImpl();
TOP fs;
TypeImpl type;
CASImpl initialView = baseCas.getInitialView(); // creates if needed
- if (!isDelta) {
- addr2fs.clear();
- // key 0 is automatically mapped to null, can't add it to map
- }
List<Runnable> fixups4forwardFsRefs = new ArrayList<>();
@@ -1384,7 +1422,7 @@ public class BinaryCasSerDes {
final int hhi = heapIndex + arrayContentOffset;
fs = baseCas.createArray(type, len);
- addr2fs.put(heapIndex, fs);
+ csds.addFS(fs, heapIndex);
switch(type.getComponentSlotKind()) {
case Slot_BooleanRef: {
@@ -1462,7 +1500,7 @@ public class BinaryCasSerDes {
CASImpl view = null;
boolean isSofa = false;
if (type.isAnnotationBaseType()) {
- Sofa sofa = getSofaFromAnnotBase(heapIndex, stringHeap, addr2fs); // creates sofa if needed and exists (forward ref case)
+ Sofa sofa = getSofaFromAnnotBase(heapIndex, stringHeap, addr2fs, csds); // creates sofa if needed and exists (forward ref case)
view = (sofa == null) ? baseCas.getInitialView() : baseCas.getView(sofa);
if (type == tsi.docType) {
fs = view.getDocumentAnnotation(); // creates the document annotation if it doesn't exist
@@ -1471,12 +1509,12 @@ public class BinaryCasSerDes {
fs = view.createFS(type);
}
} else if (type == tsi.sofaType) {
- fs = makeSofaFromHeap(heapIndex, stringHeap, addr2fs); // creates Sofa if not already created due to annotationbase code above
+ fs = makeSofaFromHeap(heapIndex, stringHeap, csds, SOFA_IN_NORMAL_ORDER); // creates Sofa if not already created due to annotationbase code above
isSofa = true;
} else {
fs = initialView.createFS(type);
}
- addr2fs.put(heapIndex, fs);
+ csds.addFS(fs, heapIndex);
for (final FeatureImpl feat : type.getFeatureImpls()) {
SlotKind slotKind = feat.getSlotKind();
@@ -1487,39 +1525,17 @@ public class BinaryCasSerDes {
case Slot_Int:
case Slot_Float:
if (!isSofa || feat != tsi.sofaNum) {
- fs.setIntLikeValueNcNj(slotKind, feat, heapFeat(heapIndex, feat));
+ fs._setIntLikeValueNcNj(slotKind, feat, heapFeat(heapIndex, feat));
}
break;
- case Slot_LongRef: fs.setLongValueNcNj(feat, longHeap.heap[heapFeat(heapIndex, feat)]); break;
- case Slot_DoubleRef: fs.setDoubleValueNcNj(feat, CASImpl.long2double(longHeap.heap[heapFeat(heapIndex, feat)])); break;
+ case Slot_LongRef: fs._setLongValueNcNj(feat, longHeap.heap[heapFeat(heapIndex, feat)]); break;
+ case Slot_DoubleRef: fs._setDoubleValueNcNj(feat, CASImpl.long2double(longHeap.heap[heapFeat(heapIndex, feat)])); break;
case Slot_StrRef: {
String s = stringHeap.getStringForCode(heapFeat(heapIndex, feat));
- if (null == s) {
- break; // null is the default value, no need to set it
- }
- if (fs instanceof Sofa) {
- if (feat == tsi.sofaId) {
- break; // do nothing, this value was already used
- }
- Sofa sofa = (Sofa)fs;
- if (feat == tsi.sofaMime) {
- sofa.setMimeType(s);
- break;
- }
- if (feat == tsi.sofaUri) {
- sofa.setRemoteSofaURI(s);
- break;
- }
- if (feat == tsi.sofaString) {
- // has to be deferred because it updates docAnnot which might not be deser yet.
- Sofa capturedSofa = sofa;
- String capturedString = s;
- fixups4forwardFsRefs.add(() -> capturedSofa.setLocalSofaData(capturedString));
- break;
- }
+ if (updateStringFeature(fs, feat, s, fixups4forwardFsRefs)) {
+ fs._setStringValueNcNj(feat, s);
}
- fs.setStringValueNcNj(feat, s);
break;
}
@@ -1532,7 +1548,7 @@ public class BinaryCasSerDes {
if (feat == tsi.sofaArray) {
((Sofa)finalFs).setLocalSofaData(item);
} else {
- finalFs.setFeatureValueNcNj(feat, item);
+ finalFs._setFeatureValueNcNj(feat, item);
}}, addr2fs);
break;
}
@@ -1579,17 +1595,18 @@ public class BinaryCasSerDes {
return heap.heap[nextFsAddr + 1 + feat.getOffset()];
}
- private Sofa getSofaFromAnnotBase(int annotBaseAddr, StringHeap stringHeap2, Int2ObjHashMap<TOP> addr2fs) {
+ private Sofa getSofaFromAnnotBase(int annotBaseAddr, StringHeap stringHeap2, Int2ObjHashMap<TOP> addr2fs,
+ CommonSerDesSequential csds) {
int sofaAddr = heapFeat(annotBaseAddr, tsi.annotBaseSofaFeat);
if (0 == sofaAddr) {
return null;
}
// get existing sofa or create sofa
- return makeSofaFromHeap(sofaAddr, stringHeap2, addr2fs);
+ return makeSofaFromHeap(sofaAddr, stringHeap2, csds, SOFA_AHEAD_OF_NORMAL_ORDER);
}
- private Sofa makeSofaFromHeap(int sofaAddr, StringHeap stringHeap2, Int2ObjHashMap<TOP> addr2fs) {
- TOP sofa = addr2fs.get(sofaAddr);
+ private Sofa makeSofaFromHeap(int sofaAddr, StringHeap stringHeap2, CommonSerDesSequential csds, boolean isUnordered) {
+ TOP sofa = csds.addr2fs.get(sofaAddr);
if (sofa != null) {
return (Sofa) sofa;
}
@@ -1597,7 +1614,11 @@ public class BinaryCasSerDes {
int sofaNum = heapFeat(sofaAddr, tsi.sofaNum);
String sofaName = stringHeap2.getStringForCode(heapFeat(sofaAddr, tsi.sofaId));
sofa = baseCas.createSofa(sofaNum, sofaName, null);
- addr2fs.put(sofaAddr, sofa);
+ if (isUnordered) {
+ csds.addFSunordered(sofa, sofaAddr);
+ } else {
+ csds.addFS(sofa, sofaAddr);
+ }
return (Sofa) sofa;
}
@@ -1645,17 +1666,64 @@ public class BinaryCasSerDes {
case Slot_Byte:
case Slot_Short:
case Slot_Int:
- case Slot_Float: fs.setIntLikeValue(slotKind, feat, slotValue); break;
+ case Slot_Float: fs._setIntLikeValue(slotKind, feat, slotValue); break;
case Slot_LongRef: fs.setLongValue(feat, longHeap.getHeapValue(slotValue)); break;
case Slot_DoubleRef: fs.setDoubleValue(feat, CASImpl.long2double(longHeap.getHeapValue(slotValue))); break;
- case Slot_StrRef: fs.setStringValue(feat, stringHeap.getStringForCode(slotValue)); break;
+ case Slot_StrRef: {
+ String s = stringHeap.getStringForCode(slotValue);
+ if (updateStringFeature(fs, feat, s, null)) {
+ fs.setStringValue(feat, stringHeap.getStringForCode(slotValue));
+ }
+ break;
+ }
+
case Slot_HeapRef: fs.setFeatureValue(feat, addr2fs.get(slotValue)); break;
default: Misc.internalError();
}
}
}
+ /**
+ *
+ * @param fs
+ * @param feat
+ * @param s
+ * @param fixups4forwardFsRefs
+ * @return true if caller needs to do an appropriate fs._setStringValue...
+ */
+ private boolean updateStringFeature(TOP fs, FeatureImpl feat, String s, List<Runnable> fixups4forwardFsRefs) {
+ if (null == s) {
+ return false; // null is the default value, no need to set it
+ }
+ if (fs instanceof Sofa) {
+ if (feat == tsi.sofaId) {
+ return false; // do nothing, this value was already used
+ }
+ Sofa sofa = (Sofa)fs;
+ if (feat == tsi.sofaMime) {
+ sofa.setMimeType(s);
+ return false;
+ }
+ if (feat == tsi.sofaUri) {
+ sofa.setRemoteSofaURI(s);
+ return false;
+ }
+ if (feat == tsi.sofaString) {
+ if (fixups4forwardFsRefs != null) {
+ // has to be deferred because it updates docAnnot which might not be deser yet.
+ Sofa capturedSofa = sofa;
+ String capturedString = s;
+ fixups4forwardFsRefs.add(() -> capturedSofa.setLocalSofaData(capturedString));
+ } else {
+ sofa.setLocalSofaData(s);
+ }
+ return false;
+ }
+ }
+ return true; // fs._setStringValueNcNj(feat, s);
+ }
+
CASImpl getCas() {
return baseCas;
}
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java?rev=1733990&r1=1733989&r2=1733990&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java Mon Mar 7 21:43:10 2016
@@ -127,7 +127,9 @@ import org.apache.uima.util.impl.Seriali
*
*/
public class BinaryCasSerDes4 implements SlotKindsConstants {
- // 0 - original, 1 = fixes from V3 in v2, 2 = v3 --------------------------v
+ private static final boolean TRACE_SER = false;
+ private static final boolean TRACE_DES = false;
+
private static final boolean TRACE_DOUBLE = false;
// private static final boolean TRACE_INT = false;
public static final int TYPECODE_COMPR = 8;
@@ -455,7 +457,8 @@ public class BinaryCasSerDes4 implements
CompressStrat compressStrategy) {
this.baseCas = cas.getBaseCAS();
this.bcsd = cas.getBinaryCasSerDes();
- this.csds = new CommonSerDesSequential(this.baseCas);
+ this.isDelta = (mark != null);
+ this.csds = isDelta ? baseCas.getCsds() : baseCas.newCsds();
// this.ccs = new CommonCompressedSerialization(
// new CommonSerDesTypeMap(cas.getTypeSystemImpl(), cas.getTypeSystemImpl()), // no type mapping
// mark);
@@ -464,7 +467,7 @@ public class BinaryCasSerDes4 implements
this.sm = sm;
this.compressLevel = compressLevel;
this.compressStrategy = compressStrategy;
- isDelta = (mark != null);
+
doMeasurement = (sm != null);
// heap = cas.getHeap().heap;
@@ -534,32 +537,39 @@ public class BinaryCasSerDes4 implements
.delta(isDelta)
.write(serializedOut);
+ if (TRACE_SER) System.out.println("Form4Ser start, delta: " + (isDelta ? "true" : "false"));
/*******************************************************************************
* Setup tables that map to v2 "addresses" - needed for backwards compatibility
* fs2addr - feature structure to address
* addr2fs - address to feature structure
* sortedFSs - sorted by addr (sorted by id)
*******************************************************************************/
- csds.setup();
+ if (isDelta) {
+ csds.setup(mark.getNextFSId(), csds.getHeapEnd());
+ } else {
+ csds.clear();
+ csds.setup();
+ }
fs2seq.clear();
seq2fs.clear();
int seq = 1; // origin 1
- for (TOP fs : csds.sortedFSs) {
+ final List<TOP> localSortedFSs = csds.getSortedFSs();
+ for (TOP fs : localSortedFSs) {
fs2seq.put(fs, seq);
seq2fs.put(seq++, fs);
}
final List<TOP> newSortedFSs; // a sublist for delta cas of just the new ones
// may be null if there are no FSs to serialize
- TOP firstFS = isDelta ? baseCas.getFsFromId(mark.getNextFSId()) : (csds.sortedFSs.size() == 0) ? null : csds.sortedFSs.get(0);
+ TOP firstFS = isDelta ? baseCas.getFsFromId(mark.getNextFSId()) : (localSortedFSs.size() == 0) ? null : localSortedFSs.get(0);
if (firstFS != null) {
if (isDelta) {
- int i = Collections.binarySearch(csds.sortedFSs, firstFS);
+ int i = Collections.binarySearch(localSortedFSs, firstFS); // depends on increasing id's for compare order
assert(i >= 0);
- newSortedFSs = csds.sortedFSs.subList(i, csds.sortedFSs.size());
+ newSortedFSs = localSortedFSs.subList(i, localSortedFSs.size());
} else {
- newSortedFSs = csds.sortedFSs;
+ newSortedFSs = localSortedFSs;
}
} else {
newSortedFSs = Collections.emptyList();
@@ -591,7 +601,7 @@ public class BinaryCasSerDes4 implements
/***************************
* Prepare to walk main heap
***************************/
- heapEnd = csds.heapEnd;
+ heapEnd = csds.getHeapEnd();
if (isDelta) {
@@ -614,7 +624,7 @@ public class BinaryCasSerDes4 implements
// }
writeVnumber(control_dos, heapEnd - heapStart); // used for delta heap size to grow the CAS and ending condition on deser loop
-
+ if (TRACE_SER) System.out.println("Form4Ser heapstart: " + heapStart + " heapEnd: " + heapEnd);
Arrays.fill(prevFsByType, null);
// if (heapStart == 0) {
@@ -634,10 +644,12 @@ public class BinaryCasSerDes4 implements
for (TOP fs : newSortedFSs) {
writeFs(fs);
}
-
+
+ if (TRACE_SER) System.out.println("Form4Ser writing index info");
serializeIndexedFeatureStructures();
if (isDelta) {
+ if (TRACE_SER) System.out.println("Form4Ser writing modified FSs");
(new SerializeModifiedFSs()).serializeModifiedFSs();
}
@@ -882,45 +894,45 @@ public class BinaryCasSerDes4 implements
SlotKind kind = feat.getSlotKind();
switch (kind) {
case Slot_Int: {
- final int prev = (prevFs == null) ? 0 : prevFs.getIntValueNc(feat);
- final int v = fs.getIntValue(feat);
+ final int prev = (prevFs == null) ? 0 : prevFs._getIntValueNc(feat);
+ final int v = fs._getIntValueNc(feat);
// if (TRACE_INT) System.out.format("writeInt value: %,d prev: %,d%n", v, prev);
writeDiff(kind.ordinal(), v, prev);
break;
}
case Slot_Short:
- writeDiff(kind.ordinal(), fs.getShortValueNc(feat), (prevFs == null) ? 0 : prevFs.getShortValueNc(feat));
+ writeDiff(kind.ordinal(), fs._getShortValueNc(feat), (prevFs == null) ? 0 : prevFs._getShortValueNc(feat));
break;
case Slot_HeapRef:
- final TOP ref = fs.getFeatureValueNc(feat);
+ final TOP ref = fs._getFeatureValueNc(feat);
writeDiff(kind.ordinal(), fs2seq(ref),
- (prevFs == null) ? 0 : fs2seq(prevFs.getFeatureValueNc(feat)));
+ (prevFs == null) ? 0 : fs2seq(prevFs._getFeatureValueNc(feat)));
break;
case Slot_Float:
- writeFloat(CASImpl.float2int(fs.getFloatValueNc(feat)));
+ writeFloat(CASImpl.float2int(fs._getFloatValueNc(feat)));
break;
case Slot_Boolean:
- byte_dos.write(fs.getBooleanValueNc(feat) ? 1 : 0);
+ byte_dos.write(fs._getBooleanValueNc(feat) ? 1 : 0);
break;
case Slot_Byte:
- byte_dos.write(fs.getByteValueNc(feat));
+ byte_dos.write(fs._getByteValueNc(feat));
break;
case Slot_StrRef:
- writeString(fs.getStringValueNc(feat));
+ writeString(fs._getStringValueNc(feat));
break;
case Slot_LongRef:
- writeLong(fs.getLongValueNc(feat), (prevFs == null) ? 0L : prevFs.getLongValueNc(feat));
+ writeLong(fs._getLongValueNc(feat), (prevFs == null) ? 0L : prevFs._getLongValueNc(feat));
break;
case Slot_DoubleRef:
- writeDouble(CASImpl.double2long(fs.getDoubleValueNc(feat)));
+ writeDouble(CASImpl.double2long(fs._getDoubleValueNc(feat)));
break;
default: Misc.internalError();
@@ -1239,7 +1251,7 @@ public class BinaryCasSerDes4 implements
} else { // end of is-array
for (FeatureImpl feat : type.getFeatureImpls()) {
if (feat.getSlotKind() == SlotKind.Slot_StrRef) {
- os.add(fs.getStringValueNc(feat));
+ os.add(fs._getStringValueNc(feat));
}
} // end of iter over all features
} // end of if-is-not-array
@@ -1264,7 +1276,7 @@ public class BinaryCasSerDes4 implements
for (int offset = fm.nextSetBit(0); offset >= 0; offset = fm.nextSetBit(offset + 1)) {
FeatureImpl feat = type.getFeatureImpls().get(offset);
if (feat.getSlotKind() == SlotKind.Slot_StrRef) {
- os.add(fs.getStringValueNc(feat));
+ os.add(fs._getStringValueNc(feat));
}
} // end of iter over features
} // end of is-not-array
@@ -1349,51 +1361,51 @@ public class BinaryCasSerDes4 implements
switch (kind) {
case Slot_Boolean:
- byte_dos.write(fs.getBooleanValueNc(feat) ? 1 : 0);
+ byte_dos.write(fs._getBooleanValueNc(feat) ? 1 : 0);
break;
case Slot_Byte:
- byte_dos.write(fs.getByteValueNc(feat));
+ byte_dos.write(fs._getByteValueNc(feat));
break;
case Slot_Short: {
- final short v = fs.getShortValueNc(feat);
+ final short v = fs._getShortValueNc(feat);
writeDiff(kindi, v, vPrevModShort);
vPrevModShort = v;
break;
}
case Slot_Int: {
- final int v = fs.getIntValueNc(feat);
+ final int v = fs._getIntValueNc(feat);
writeDiff(kindi, v, vPrevModInt);
vPrevModInt = v;
break;
}
case Slot_Float:
- writeFloat(CASImpl.float2int(fs.getFloatValueNc(feat)));
+ writeFloat(CASImpl.float2int(fs._getFloatValueNc(feat)));
break;
case Slot_LongRef: {
- long v = fs.getLongValueNc(feat);
+ long v = fs._getLongValueNc(feat);
writeLong(v, vPrevModLong);
vPrevModLong = v;
break;
}
case Slot_DoubleRef:
- writeDouble(CASImpl.double2long(fs.getDoubleValueNc(feat)));
+ writeDouble(CASImpl.double2long(fs._getDoubleValueNc(feat)));
break;
case Slot_HeapRef: {
- int v = fs2seq(fs.getFeatureValueNc(feat));
+ int v = fs2seq(fs._getFeatureValueNc(feat));
writeDiff(kindi, v, vPrevModHeapRef);
vPrevModHeapRef = v;
break;
}
case Slot_StrRef:
- writeString(fs.getStringValueNc(feat));
+ writeString(fs._getStringValueNc(feat));
break;
default: Misc.internalError();
@@ -1623,7 +1635,7 @@ public class BinaryCasSerDes4 implements
this.baseCas = cas.getBaseCAS();
this.ivCas = baseCas.getInitialView();
this.bcsd = cas.getBinaryCasSerDes();
- this.csds = new CommonSerDesSequential(this.baseCas);
+ this.csds = isDelta ? cas.getCsds() : cas.newCsds();
this.deserIn = deserIn;
this.isDelta = isDelta;
@@ -1664,6 +1676,7 @@ public class BinaryCasSerDes4 implements
private void deserialize(int version1) throws IOException {
+ if (TRACE_DES) System.out.println("Form4Deser starting");
isBeforeV3 = (version1 & 0xff00) == 0;
// fs2seq.clear();
@@ -1685,17 +1698,24 @@ public class BinaryCasSerDes4 implements
only1CommonString = lenCmnStrs == 1;
/***************************
* Prepare to walk main heap
+ * The csds must be either empty (for receiving non- delta)
+ * or the same as when the CAS was previous sent out (for receiving delta)
+ * Can't recompute it for delta case because a GC may have eliminated some of the items.
***************************/
- csds.setup();
+
+ if (!isDelta) {
+ csds.setup();
+ }
+
int seq = 1;
- for (TOP fs : csds.sortedFSs) {
+ for (TOP fs : csds.getSortedFSs()) {
// fs2seq.put(fs, seq);
seq2fs.put(seq++, fs);
}
int deltaHeapSize = readVnumber(control_dis);
- heapStart = isDelta ? csds.heapEnd : 0;
+ heapStart = isDelta ? csds.getHeapEnd() : 0;
// stringTableOffset = isDelta ? (stringHeapObj.getSize() - 1) : 0;
@@ -1730,6 +1750,7 @@ public class BinaryCasSerDes4 implements
int arraySize = 0;
Arrays.fill(prevFsByType, null);
+ if (TRACE_DES) System.out.println("Form4Deser heapStart: " + heapStart + " heapEnd: " + heapEnd);
for (int iHeap = heapStart; iHeap < heapEnd; iHeap += type.getFsSpaceReq(arraySize)) {
final int typeCode = readVnumber(typeCode_dis);
@@ -1810,14 +1831,19 @@ public class BinaryCasSerDes4 implements
prevFsByType[adjTypeCode] = currentFs;
}
+
+
+ if (TRACE_DES) System.out.println("Form4Deser running deferred fixups after all FSs deserialized");
for (Runnable r : fixupsNeeded) {
r.run();
}
+ if (TRACE_DES) System.out.println("Form4Deser indexing FSs");
readIndexedFeatureStructures();
if (isDelta) {
+ if (TRACE_DES) System.out.println("Form4Deser modifying existing FSs");
(new ReadModifiedFSs()).readModifiedFSs();
}
@@ -1930,32 +1956,32 @@ public class BinaryCasSerDes4 implements
if (feat == ts.sofaNum) {
sofaNum = i;
} else {
- maybeStoreOrDefer((lfs) -> lfs.setIntValueNcNj(feat, i));
+ maybeStoreOrDefer((lfs) -> lfs._setIntValueNcNj(feat, i));
}
break;
}
case Slot_Short: {
final int i = readDiffWithPrevTypeSlot(kind, feat);
- maybeStoreOrDefer(lfs -> lfs.setIntLikeValueNcNj(kind, feat, i));
+ maybeStoreOrDefer(lfs -> lfs._setIntLikeValueNcNj(kind, feat, i));
break;
}
case Slot_Float: {
final int i = readFloat();
- maybeStoreOrDefer(lfs -> lfs.setFloatValueNcNj(feat, CASImpl.int2float(i)));
+ maybeStoreOrDefer(lfs -> lfs._setFloatValueNcNj(feat, CASImpl.int2float(i)));
break;
}
case Slot_Boolean: {
final byte i = byte_dis.readByte();
- maybeStoreOrDefer(lfs -> lfs.setBooleanValueNcNj(feat, i == 1));
+ maybeStoreOrDefer(lfs -> lfs._setBooleanValueNcNj(feat, i == 1));
break;
}
case Slot_Byte: {
final byte i = byte_dis.readByte();
- maybeStoreOrDefer(lfs -> lfs.setByteValueNcNj(feat, i));
+ maybeStoreOrDefer(lfs -> lfs._setByteValueNcNj(feat, i));
break;
}
@@ -1974,7 +2000,7 @@ public class BinaryCasSerDes4 implements
if (feat == ts.sofaArray) {
maybeStoreOrDefer_slotFixups(vh, ref_fs -> ((Sofa)lfs).setLocalSofaData(ref_fs));
} else {
- maybeStoreOrDefer_slotFixups(vh, ref_fs -> lfs.setFeatureValueNcNj(feat, ref_fs));
+ maybeStoreOrDefer_slotFixups(vh, ref_fs -> lfs._setFeatureValueNcNj(feat, ref_fs));
}
});
}
@@ -2003,20 +2029,20 @@ public class BinaryCasSerDes4 implements
}
// other user-defined custom sofa extended string features (if any)
// as well as non-sofa FS features, are set by the following code
- maybeStoreOrDefer(lfs -> lfs.setStringValueNcNj(feat, s));
+ maybeStoreOrDefer(lfs -> lfs._setStringValueNcNj(feat, s));
break;
}
case Slot_LongRef: {
- final long prevLong = (prevFs == null) ? 0L : prevFs.getLongValueNc(feat);
+ final long prevLong = (prevFs == null) ? 0L : prevFs._getLongValueNc(feat);
long v = readLongOrDouble(kind, prevLong);
- maybeStoreOrDefer(lfs -> lfs.setLongValueNcNj(feat, v));
+ maybeStoreOrDefer(lfs -> lfs._setLongValueNcNj(feat, v));
break;
}
case Slot_DoubleRef: {
long v = readDouble();
- maybeStoreOrDefer(lfs -> lfs.setDoubleValueNcNj(feat, CASImpl.long2double(v)));
+ maybeStoreOrDefer(lfs -> lfs._setDoubleValueNcNj(feat, CASImpl.long2double(v)));
break;
}
@@ -2231,7 +2257,7 @@ public class BinaryCasSerDes4 implements
if (kind == SlotKind.Slot_HeapRef) {
return (prevFsRefs == null) ? 0 : prevFsRefs[(feat == null) ? 0 : feat.getOffset()];
}
- return (prevFs == null) ? 0 : prevFs.getIntLikeValue(kind, feat);
+ return (prevFs == null) ? 0 : prevFs._getIntLikeValue(kind, feat);
}
private void savePrevHeapRef(int typecode, int nbrOfSlots, int offset, int v) {
@@ -2526,9 +2552,9 @@ public class BinaryCasSerDes4 implements
vPrevModHeapRef = v;
final TOP ref_fs = seq2fs(v);
- if (ref_fs == null) {
- System.out.println("debug");
- }
+// if (ref_fs == null) {
+// System.out.println("debug addr: " + v);
+// }
assert(ref_fs != null);
if (isArray) {
((FSArray)fs).set(offsetInFs - 2, ref_fs);
@@ -3108,16 +3134,16 @@ public class BinaryCasSerDes4 implements
*/
public static void dumpCas(CASImpl cas) {
- CommonSerDesSequential csds = new CommonSerDesSequential(cas.getBaseCAS());
+ CommonSerDesSequential csds = new CommonSerDesSequential(cas);
csds.setup();
- for (TOP fs : csds.sortedFSs) {
+ for (TOP fs : csds.getSortedFSs()) {
// System.out.format("debug heapAddr: %,d type: %s%n", csds.fs2addr.get(fs), fs._typeImpl.getShortName());
if (csds.fs2addr.get(fs) == 439) {
System.out.format("debug, fs: %s%n", fs);
}
}
- System.out.format("debug heapend: %,d%n", csds.heapEnd);
+ System.out.format("debug heapend: %,d%n", csds.getHeapEnd());
}
}
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java?rev=1733990&r1=1733989&r2=1733990&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java Mon Mar 7 21:43:10 2016
@@ -876,26 +876,26 @@ public class BinaryCasSerDes6 implements
SlotKind kind = feat.getSlotKind();
switch (kind) {
//Slot_Int, Slot_Float, Slot_Boolean, Slot_Byte, Slot_Short
- case Slot_Short: serializeDiffWithPrevTypeSlot(kind, fs, feat, fs.getShortValueNc(feat)); break;
- case Slot_Int: serializeDiffWithPrevTypeSlot(kind, fs, feat, fs.getIntValueNc(feat)); break;
+ case Slot_Short: serializeDiffWithPrevTypeSlot(kind, fs, feat, fs._getShortValueNc(feat)); break;
+ case Slot_Int: serializeDiffWithPrevTypeSlot(kind, fs, feat, fs._getIntValueNc(feat)); break;
case Slot_HeapRef:
// if ()
- serializeDiffWithPrevTypeSlot(kind, fs, feat, getTgtSeqFromSrcFS(fs.getFeatureValueNc(feat)));
+ serializeDiffWithPrevTypeSlot(kind, fs, feat, getTgtSeqFromSrcFS(fs._getFeatureValueNc(feat)));
break;
- case Slot_Float: writeFloat(CASImpl.float2int(fs.getFloatValueNc(feat))); break;
- case Slot_Boolean: byte_dos.write(fs.getBooleanValueNc(feat) ? 1 : 0); break;
- case Slot_Byte: byte_dos.write(fs.getByteValueNc(feat)); break;
- case Slot_StrRef: writeString(fs.getStringValueNc(feat)); break;
+ case Slot_Float: writeFloat(CASImpl.float2int(fs._getFloatValueNc(feat))); break;
+ case Slot_Boolean: byte_dos.write(fs._getBooleanValueNc(feat) ? 1 : 0); break;
+ case Slot_Byte: byte_dos.write(fs._getByteValueNc(feat)); break;
+ case Slot_StrRef: writeString(fs._getStringValueNc(feat)); break;
case Slot_LongRef:
final TypeImpl ti = fs._typeImpl;
final int offset = feat.getOffset();
final long prevLong = getPrevLongValue(ti.getCode(), offset);
- final long vLong = fs.getLongValueNc(feat);
+ final long vLong = fs._getLongValueNc(feat);
writeLong(vLong, prevLong);
updatePrevLongValue(ti, offset, vLong);
break;
- case Slot_DoubleRef: writeDouble(Double.doubleToRawLongBits(fs.getDoubleValueNc(feat))); break;
+ case Slot_DoubleRef: writeDouble(Double.doubleToRawLongBits(fs._getDoubleValueNc(feat))); break;
default:
throw new RuntimeException("internal error");
} // end of switch
@@ -1398,7 +1398,7 @@ public class BinaryCasSerDes6 implements
continue; // skip - feature not in target type
}
if (srcFeat.getRangeImpl().isStringOrStringSubtype()) {
- os.add(fs.getStringValueNc(feats.get(next)));
+ os.add(fs._getStringValueNc(feats.get(next)));
}
next = featuresModified.nextSetBit(next + 1);
}
@@ -1556,24 +1556,24 @@ public class BinaryCasSerDes6 implements
final SlotKind slotKind = fi.getSlotKind();
switch (slotKind) {
- case Slot_Boolean: byte_dos.write(fs.getBooleanValueNc(fi) ? 1 : 0); break;
- case Slot_Byte: byte_dos.write(fs.getByteValueNc(fi)); break;
- case Slot_Short: vPrevModShort = (short) writeDiff(int_i, fs.getShortValueNc(fi), vPrevModShort); break;
- case Slot_Int: vPrevModInt = writeDiff(int_i, fs.getIntValueNc(fi), vPrevModInt); break;
+ case Slot_Boolean: byte_dos.write(fs._getBooleanValueNc(fi) ? 1 : 0); break;
+ case Slot_Byte: byte_dos.write(fs._getByteValueNc(fi)); break;
+ case Slot_Short: vPrevModShort = (short) writeDiff(int_i, fs._getShortValueNc(fi), vPrevModShort); break;
+ case Slot_Int: vPrevModInt = writeDiff(int_i, fs._getIntValueNc(fi), vPrevModInt); break;
case Slot_LongRef: {
- long v = fs.getLongValueNc(fi);
+ long v = fs._getLongValueNc(fi);
writeLong(v, vPrevModLong);
vPrevModLong = v;
break;
}
- case Slot_Float: writeFloat(CASImpl.float2int(fs.getFloatValueNc(fi))); break;
- case Slot_DoubleRef: writeDouble(Double.doubleToRawLongBits(fs.getDoubleValueNc(fi))); break;
+ case Slot_Float: writeFloat(CASImpl.float2int(fs._getFloatValueNc(fi))); break;
+ case Slot_DoubleRef: writeDouble(Double.doubleToRawLongBits(fs._getDoubleValueNc(fi))); break;
case Slot_HeapRef: {
- final int v = getTgtSeqFromSrcFS(fs.getFeatureValueNc(fi));
+ final int v = getTgtSeqFromSrcFS(fs._getFeatureValueNc(fi));
vPrevModHeapRef = writeDiff(heapRef_i, v, vPrevModHeapRef);
}
break;
- case Slot_StrRef: writeString(fs.getStringValueNc(fi)); break;
+ case Slot_StrRef: writeString(fs._getStringValueNc(fi)); break;
case Slot_JavaObjectRef: throw new UnsupportedOperationException();
default: Misc.internalError();
} // end of Switch
@@ -1959,13 +1959,13 @@ public class BinaryCasSerDes6 implements
if (srcFeat == srcTs.sofaNum) {
sofaNum = vi;
} else {
- maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs.setIntLikeValueNcNj(kind, srcFeat, vi));
+ maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs._setIntLikeValueNcNj(kind, srcFeat, vi));
}
break;
case Slot_Short:
int vs = readDiffIntSlot(storeIt, tgtFeatOffset, kind, tgtType);
- maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs.setIntLikeValueNcNj(kind, srcFeat, vs));
+ maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs._setIntLikeValueNcNj(kind, srcFeat, vs));
break;
case Slot_HeapRef:
@@ -1986,7 +1986,7 @@ public class BinaryCasSerDes6 implements
maybeStoreOrDefer_slotFixups(vh, ref_fs -> sofa.setLocalSofaData(ref_fs));
}
} else {
- maybeStoreOrDefer_slotFixups(vh, ref_fs -> lfs.setFeatureValueNcNj(srcFeat, ref_fs));
+ maybeStoreOrDefer_slotFixups(vh, ref_fs -> lfs._setFeatureValueNcNj(srcFeat, ref_fs));
}
});
}
@@ -1994,12 +1994,12 @@ public class BinaryCasSerDes6 implements
case Slot_Float:
final int floatAsInt = readFloat();
- maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs.setFloatValueNcNj(srcFeat, Float.intBitsToFloat(floatAsInt)));
+ maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs._setFloatValueNcNj(srcFeat, Float.intBitsToFloat(floatAsInt)));
break;
case Slot_Boolean: case Slot_Byte:
final byte vByte = byte_dis.readByte();
- maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs.setIntLikeValueNcNj(kind, srcFeat, vByte));
+ maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs._setIntLikeValueNcNj(kind, srcFeat, vByte));
break;
case Slot_StrRef:
@@ -2028,7 +2028,7 @@ public class BinaryCasSerDes6 implements
}
// other user-defined custom sofa extended string features (if any)
// as well as non-sofa FS features, are set by the following code
- maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs.setStringValueNcNj(srcFeat, vString));
+ maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs._setStringValueNcNj(srcFeat, vString));
}
break;
@@ -2036,12 +2036,12 @@ public class BinaryCasSerDes6 implements
long prevLong = getPrevLongValue(tgtType.getCode(), tgtFeatOffset);
long vl = readLongOrDouble(kind, prevLong);
updatePrevLongValue(tgtType, tgtFeatOffset, vl);
- maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs.setLongValueNcNj(srcFeat, vl));
+ maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs._setLongValueNcNj(srcFeat, vl));
break;
case Slot_DoubleRef:
long vd = readDouble();
- maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs.setDoubleValueNcNj(srcFeat, CASImpl.long2double(vd)));
+ maybeStoreOrDefer(storeIt, fs, (lfs) -> lfs._setDoubleValueNcNj(srcFeat, CASImpl.long2double(vd)));
break;
default: Misc.internalError();
@@ -2859,7 +2859,7 @@ public class BinaryCasSerDes6 implements
}
}
if (srcFeat.getRangeImpl().isRefType) {
- enqueueFS(fs.getFeatureValueNc(srcFeat));
+ enqueueFS(fs._getFeatureValueNc(srcFeat));
}
}
}
@@ -2918,7 +2918,7 @@ public class BinaryCasSerDes6 implements
for (FeatureImpl fi : fs._typeImpl.getFeatureImpls()) {
if (fi.getRange() instanceof TypeImpl_string) {
- os.add(fs.getStringValueNc(fi));
+ os.add(fs._getStringValueNc(fi));
}
}
}
@@ -3149,17 +3149,17 @@ public class BinaryCasSerDes6 implements
private boolean compareSlot(FeatureImpl fi1, FeatureImpl fi2) {
SlotKind kind = fi1.getSlotKind();
switch (kind) {
- case Slot_Int: return fs1.getIntValueNc(fi1) == fs2.getIntValueNc(fi2);
- case Slot_Short: return fs1.getShortValueNc(fi1) == fs2.getShortValueNc(fi2);
- case Slot_Boolean: return fs1.getBooleanValueNc(fi1) == fs2.getBooleanValueNc(fi2);
- case Slot_Byte: return fs1.getByteValueNc(fi1) == fs2.getByteValueNc(fi2);
+ case Slot_Int: return fs1._getIntValueNc(fi1) == fs2._getIntValueNc(fi2);
+ case Slot_Short: return fs1._getShortValueNc(fi1) == fs2._getShortValueNc(fi2);
+ case Slot_Boolean: return fs1._getBooleanValueNc(fi1) == fs2._getBooleanValueNc(fi2);
+ case Slot_Byte: return fs1._getByteValueNc(fi1) == fs2._getByteValueNc(fi2);
// don't compare floats directly - the NaN is defined to miscompare
- case Slot_Float: return CASImpl.float2int(fs1.getFloatValueNc(fi1)) == CASImpl.float2int(fs2.getFloatValueNc(fi2));
- case Slot_HeapRef: return compareRefs(fs1.getFeatureValueNc(fi1), fs2.getFeatureValueNc(fi2), fi1);
- case Slot_StrRef: return areStringsEqual(fs1.getStringValueNc(fi1), fs2.getStringValueNc(fi2));
- case Slot_LongRef: return fs1.getLongValueNc(fi1) == fs2.getLongValueNc(fi2);
+ case Slot_Float: return CASImpl.float2int(fs1._getFloatValueNc(fi1)) == CASImpl.float2int(fs2._getFloatValueNc(fi2));
+ case Slot_HeapRef: return compareRefs(fs1._getFeatureValueNc(fi1), fs2._getFeatureValueNc(fi2), fi1);
+ case Slot_StrRef: return areStringsEqual(fs1._getStringValueNc(fi1), fs2._getStringValueNc(fi2));
+ case Slot_LongRef: return fs1._getLongValueNc(fi1) == fs2._getLongValueNc(fi2);
// don't compare doubles directly - the NaN is defined to miscompare
- case Slot_DoubleRef: return Double.doubleToRawLongBits(fs1.getDoubleValueNc(fi1)) == Double.doubleToRawLongBits(fs2.getDoubleValueNc(fi2));
+ case Slot_DoubleRef: return Double.doubleToRawLongBits(fs1._getDoubleValueNc(fi1)) == Double.doubleToRawLongBits(fs2._getDoubleValueNc(fi2));
default: Misc.internalError(); return true;
}
}
@@ -3357,36 +3357,36 @@ public class BinaryCasSerDes6 implements
SlotKind kind = fi.getSlotKind();
switch(kind) { // ...Ref are either long/double/str
case Slot_Boolean:
- c = Boolean.compare(scFs1.getBooleanValueNc(fi), scFs2.getBooleanValueNc(fi));
+ c = Boolean.compare(scFs1._getBooleanValueNc(fi), scFs2._getBooleanValueNc(fi));
if (c != 0) return c; continue;
case Slot_Byte:
- c = Byte.compare(scFs1.getByteValueNc(fi), scFs2.getByteValueNc(fi));
+ c = Byte.compare(scFs1._getByteValueNc(fi), scFs2._getByteValueNc(fi));
if (c != 0) return c; continue;
case Slot_Short:
- c = Short.compare(scFs1.getShortValueNc(fi), scFs2.getShortValueNc(fi));
+ c = Short.compare(scFs1._getShortValueNc(fi), scFs2._getShortValueNc(fi));
if (c != 0) return c; continue;
case Slot_Int:
- c = Integer.compare(scFs1.getIntValueNc(fi), scFs2.getIntValueNc(fi));
+ c = Integer.compare(scFs1._getIntValueNc(fi), scFs2._getIntValueNc(fi));
if (c != 0) return c; continue;
case Slot_Float:
- c = Integer.compare(CASImpl.float2int(scFs1.getFloatValueNc(fi)),
- CASImpl.float2int(scFs2.getFloatValueNc(fi)));
+ c = Integer.compare(CASImpl.float2int(scFs1._getFloatValueNc(fi)),
+ CASImpl.float2int(scFs2._getFloatValueNc(fi)));
if (c != 0) return c; continue;
case Slot_LongRef:
- c = Long.compare(scFs1.getLongValueNc(fi), scFs2.getLongValueNc(fi));
+ c = Long.compare(scFs1._getLongValueNc(fi), scFs2._getLongValueNc(fi));
if (c != 0) return c; continue;
case Slot_DoubleRef:
- c = Long.compare(Double.doubleToRawLongBits(scFs1.getDoubleValueNc(fi)),
- Double.doubleToRawLongBits(scFs2.getDoubleValueNc(fi)));
+ c = Long.compare(Double.doubleToRawLongBits(scFs1._getDoubleValueNc(fi)),
+ Double.doubleToRawLongBits(scFs2._getDoubleValueNc(fi)));
if (c != 0) return c; continue;
case Slot_StrRef:
- c = Misc.compareStrings(scFs1.getStringValueNc(fi), scFs2.getStringValueNc(fi));
+ c = Misc.compareStrings(scFs1._getStringValueNc(fi), scFs2._getStringValueNc(fi));
if (c != 0) return c;
continue;
case Slot_HeapRef:
- TOP refFs1 = scFs1.getFeatureValueNc(fi);
- TOP refFs2 = scFs2.getFeatureValueNc(fi);
+ TOP refFs1 = scFs1._getFeatureValueNc(fi);
+ TOP refFs2 = scFs2._getFeatureValueNc(fi);
if (null == refFs1) {
if (null == refFs2) {
continue;
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java?rev=1733990&r1=1733989&r2=1733990&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java Mon Mar 7 21:43:10 2016
@@ -138,7 +138,7 @@ public class CASSerializer implements Se
*/
public void addCAS(CASImpl cas, boolean addMetaData) {
BinaryCasSerDes bcsd = cas.getBinaryCasSerDes();
- CommonSerDesSequential csds = new CommonSerDesSequential(cas.getBaseCAS());
+ CommonSerDesSequential csds = cas.newCsds();
scanAllFSsForBinarySerialization(bcsd, null, csds); // populates the arrays
this.fsIndex = bcsd.getIndexedFSs(csds.fs2addr); // must follow scanAll...
@@ -251,7 +251,7 @@ public class CASSerializer implements Se
public void addCAS(CASImpl cas, OutputStream ostream) {
final BinaryCasSerDes bcsd = cas.getBinaryCasSerDes();
- final CommonSerDesSequential csds = new CommonSerDesSequential(cas.getBaseCAS());
+ final CommonSerDesSequential csds = cas.newCsds();
scanAllFSsForBinarySerialization(bcsd, null, csds); // populates the arrays
try {
@@ -373,6 +373,8 @@ public class CASSerializer implements Se
}
bcsd.setHeapExtents();
+ // non delta serialization
+ csds.setHeapEnd(bcsd.nextHeapAddrAfterMark);
}
@@ -425,7 +427,10 @@ public class CASSerializer implements Se
// because the output is only the new elements, this populates the arrays with only the new elements
// Note: all heaps reserve slot 0 for null, real data starts at position 1
- final CommonSerDesSequential csds = new CommonSerDesSequential(cas.getBaseCAS());
+ final CommonSerDesSequential csds = cas.getCsds();
+ if (csds.getHeapEnd() == 0) {
+ System.out.println("debug");
+ }
scanAllFSsForBinarySerialization(bcsd, mark, csds); // populates the arrays
try {
@@ -690,28 +695,28 @@ public class CASSerializer implements Se
FeatureImpl feat = type.getFeatureImpls().get(offset);
switch (feat.getSlotKind()) {
- case Slot_Boolean: chgMainHeapValue.add(fs.getBooleanValueNc(feat) ? 1 : 0); break;
+ case Slot_Boolean: chgMainHeapValue.add(fs._getBooleanValueNc(feat) ? 1 : 0); break;
- case Slot_Byte: chgMainHeapValue.add(fs.getByteValueNc(feat)); break;
- case Slot_Short: chgMainHeapValue.add(fs.getShortValueNc(feat)); break;
- case Slot_Int: chgMainHeapValue.add(fs.getIntValueNc(feat)); break;
- case Slot_Float: chgMainHeapValue.add(CASImpl.float2int(fs.getFloatValueNc(feat))); break;
+ case Slot_Byte: chgMainHeapValue.add(fs._getByteValueNc(feat)); break;
+ case Slot_Short: chgMainHeapValue.add(fs._getShortValueNc(feat)); break;
+ case Slot_Int: chgMainHeapValue.add(fs._getIntValueNc(feat)); break;
+ case Slot_Float: chgMainHeapValue.add(CASImpl.float2int(fs._getFloatValueNc(feat))); break;
case Slot_LongRef: {
- int v = bcsd.nextLongHeapAddrAfterMark + bcsd.longHeap.addLong(fs.getLongValueNc(feat));
+ int v = bcsd.nextLongHeapAddrAfterMark + bcsd.longHeap.addLong(fs._getLongValueNc(feat));
chgMainHeapValue.add(v);
break;
}
case Slot_DoubleRef: {
- int v = bcsd.nextLongHeapAddrAfterMark + bcsd.longHeap.addLong(CASImpl.double2long(fs.getDoubleValueNc(feat)));
+ int v = bcsd.nextLongHeapAddrAfterMark + bcsd.longHeap.addLong(CASImpl.double2long(fs._getDoubleValueNc(feat)));
chgMainHeapValue.add(v);
break;
}
case Slot_StrRef: {
- int v = bcsd.nextStringHeapAddrAfterMark + bcsd.stringHeap.addString(fs.getStringValueNc(feat));
+ int v = bcsd.nextStringHeapAddrAfterMark + bcsd.stringHeap.addString(fs._getStringValueNc(feat));
chgMainHeapValue.add(v);
break;
}
- case Slot_HeapRef: chgMainHeapValue.add(fs2addr.get(fs.getFeatureValueNc(feat))); break;
+ case Slot_HeapRef: chgMainHeapValue.add(fs2addr.get(fs._getFeatureValueNc(feat))); break;
default: Misc.internalError();
} // end of switch
Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CommonSerDesSequential.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CommonSerDesSequential.java?rev=1733990&r1=1733989&r2=1733990&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CommonSerDesSequential.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/CommonSerDesSequential.java Mon Mar 7 21:43:10 2016
@@ -21,19 +21,37 @@ package org.apache.uima.cas.impl;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.apache.uima.cas.function.Consumer_T_withIOException;
import org.apache.uima.internal.util.Int2ObjHashMap;
import org.apache.uima.internal.util.Obj2IntIdentityHashMap;
import org.apache.uima.jcas.cas.TOP;
+import org.apache.uima.util.Misc;
/**
* Common de/serialization for plain binary and compressed binary form 4
* which both walk the cas using the sequential, incrementing id approach
+ *
+ * Lifecycle:
+ * There is 0/1 instance per CAS, representing the FSs at some point in time in that CAS.
+ *
+ * Creation:
+ * non-delta serialization
+ * non-delta deserialization
+ *
+ * Reset:
+ * CAS Reset
+ * API call (for optimization - used after all delta deserializations into a particular CAS are complete.
+ *
+ * Logical constraints:
+ * - delta de/serialization must use an existing version of this,
+ * -- set during a previous non-delta de/serialization
*/
public class CommonSerDesSequential {
+ public static final boolean TRACE_SETUP = false;
/**
* a map from a fs to its addr in the modeled heap
*
@@ -45,7 +63,7 @@ public class CommonSerDesSequential {
final Obj2IntIdentityHashMap<TOP> fs2addr = new Obj2IntIdentityHashMap<>(TOP.class, TOP.singleton);
/**
- * a map from a fs addr to the V3 FS
+ * a map from the modelled FS addr to the V3 FS
* created when serializing (non-delta), deserializing (non-delta)
* augmented when deserializing(delta)
* used when deserializing (delta and non-delta)
@@ -57,28 +75,31 @@ public class CommonSerDesSequential {
final Int2ObjHashMap<TOP> addr2fs = new Int2ObjHashMap<>(TOP.class);
/**
- * This is populated from the main CAS's id to fs map, which is accessed once;
+ * The FSs in this list are not necessarily sequential, but is in ascending (simulated heap) order,
+ * needed for V2 compatibility of serialized forms.
+ * This is populated from the main CAS's id-to-fs map, which is accessed once;
* Subsequent accessing of that could return different lists due to an intervening Garbage Collection.
+ *
+ * Before accessing this, any pending items must be merged.
*/
- final List<TOP> sortedFSs = new ArrayList<>(); // holds the FSs sorted by id
- final private CASImpl baseCas;
- int heapEnd; // == the last addr + length of that
-
- public CommonSerDesSequential(CASImpl baseCas) {
- this.baseCas = baseCas;
- }
-
+ final private List<TOP> sortedFSs = new ArrayList<>(); // holds the FSs sorted by id
+
+ final private List<TOP> pending = new ArrayList<>(); // batches up FSs that need to be inserted into sortedFSs
+
/**
- * Cleanup - clear the list of sortedFSs
+ * The associated CAS
*/
- void clearSortedFSs() {
- sortedFSs.clear();
- }
+ final private CASImpl baseCas;
- void addSortedFSs(TOP fs) {
- sortedFSs.add(fs);
+ /**
+ * The first free (available) simulated heap addr, also the last addr + length of that
+ */
+ private int heapEnd; // == the last addr + length of that
+
+ public CommonSerDesSequential(CASImpl cas) {
+ this.baseCas = cas.getBaseCAS();
}
-
+
/**
* Must call in fs sorted order
* @param fs
@@ -89,27 +110,46 @@ public class CommonSerDesSequential {
addr2fs.put(addr, fs);
}
+ /**
+ * For out of order calls
+ * @param fs
+ */
+ void addFSunordered(TOP fs, int addr) {
+ fs2addr.put(fs, addr);
+ pending.add(fs);
+ addr2fs.put(addr, fs);
+ }
+
void clear() {
sortedFSs.clear();
fs2addr.clear();
addr2fs.clear();
+ pending.clear();
}
- void setup() {
+ void setup(int fromId, int fromAddr) {
// local value as "final" to permit use in lambda below
- final int[] nextAddr = {1};
- clear();
+ final int[] nextAddr = {fromAddr};
+ if (TRACE_SETUP) System.out.println("Cmn serDes sequential setup called by: " + Misc.getCaller());
baseCas.walkReachablePlusFSsSorted(fs -> {
- fs2addr.put(fs, nextAddr[0]);
- sortedFSs.add(fs);
- addr2fs.put(nextAddr[0], fs);
+ addFS(fs, nextAddr[0]);
+ if (TRACE_SETUP) {
+ System.out.format("Cmn serDes sequential setup: add FS id: %,4d addr: %,5d type: %s%n", fs.id(), nextAddr[0], fs._typeImpl.getShortName());
+ }
nextAddr[0] += BinaryCasSerDes.getFsSpaceReq(fs, fs._typeImpl);
- });
+ }, fromId);
heapEnd = nextAddr[0];
+ if (heapEnd == 0) {
+ System.out.println("debug");
+ }
}
-
+ /**
+ * called to augment an existing csds with information on FSs added after the mark was set
+ * @param mark -
+ */
+ void setup() { setup(1, 1); }
void walkSeqFSs(Consumer_T_withIOException<TOP> action) throws IOException {
for (TOP fs : sortedFSs) {
@@ -117,4 +157,21 @@ public class CommonSerDesSequential {
}
}
+ List<TOP> getSortedFSs() {
+ if (pending.size() != 0) {
+ merge();
+ }
+ return sortedFSs;
+ }
+
+ int getHeapEnd() { return heapEnd; }
+
+ void setHeapEnd(int heapEnd) { this.heapEnd = heapEnd; }
+
+ private void merge() {
+ Collections.sort(pending);
+ sortedFSs.addAll(pending);
+ pending.clear();
+ Collections.sort(sortedFSs);
+ }
}