private void singleThreadDeltaSearch(ProgressMonitor monitor, ObjectToPack[] list, int cnt) throws IOException { long totalWeight = 0; for (int i = 0; i < cnt; i++) { ObjectToPack o = list[i]; totalWeight += DeltaTask.getAdjustedWeight(o); } long bytesPerUnit = 1; while (DeltaTask.MAX_METER <= (totalWeight / bytesPerUnit)) bytesPerUnit <<= 10; int cost = (int) (totalWeight / bytesPerUnit); if (totalWeight % bytesPerUnit != 0) cost++; beginPhase(PackingPhase.COMPRESSING, monitor, cost); new DeltaWindow(config, new DeltaCache(config), reader, monitor, bytesPerUnit, list, 0, cnt).search(); endPhase(monitor); }
return NEXT_SRC; int msz = deltaSizeLimit(src); if (msz <= 8) // Nearly impossible to fit useful delta. return NEXT_SRC; srcIndex = index(src); } catch (LargeObjectException tooBig) { resBuf = buffer(res); } catch (LargeObjectException tooBig) { : new TemporaryBuffer.Heap(msz); if (srcIndex.encode(delta, resBuf, msz)) selectDeltaBase(src, delta); } catch (IOException deltaTooBig) {
if (src.empty()) break; if (delta(src) /* == NEXT_SRC */) continue; bestBase = null; keepInWindow(); return; resObj.setDeltaDepth(depth); resObj.clearReuseAsIs(); cacheDelta(srcObj, resObj);
clear(res); final long need = estimateSize(next); DeltaWindowEntry n = res.next; for (; maxMemory < loaded + need && n != res; n = n.next) clear(n); clearWindowOnTypeSwitch(); keepInWindow(); } else { bytesProcessed -= d * bytesPerUnit; searchInWindow();
private DeltaIndex index(DeltaWindowEntry ent) throws MissingObjectException, IncorrectObjectTypeException, IOException, LargeObjectException { DeltaIndex idx = ent.index; if (idx == null) { checkLoadable(ent, estimateIndexSize(ent)); try { idx = new DeltaIndex(buffer(ent)); } catch (OutOfMemoryError noMemory) { LargeObjectException.OutOfMemory e; e = new LargeObjectException.OutOfMemory(noMemory); e.setObjectId(ent.object); throw e; } if (maxMemory != 0) loaded += idx.getIndexSize() - idx.getSourceSize(); ent.index = idx; } return idx; }
private void cacheDelta(ObjectToPack srcObj, ObjectToPack resObj) { if (deltaCache.canCache(deltaLen, srcObj, resObj)) { try { byte[] zbuf = new byte[deflateBound(deltaLen)]; ZipStream zs = new ZipStream(deflater(), zbuf); if (deltaBuf instanceof byte[]) zs.write((byte[]) deltaBuf, 0, deltaLen); else ((TemporaryBuffer.Heap) deltaBuf).writeTo(zs, null); deltaBuf = null; int len = zs.finish(); resObj.setCachedDelta(deltaCache.cache(zbuf, len, deltaLen)); resObj.setCachedSize(deltaLen); } catch (IOException err) { deltaCache.credit(deltaLen); } catch (OutOfMemoryError err) { deltaCache.credit(deltaLen); } } }
private void checkLoadable(DeltaWindowEntry ent, long need) { if (maxMemory == 0) return; DeltaWindowEntry n = res.next; for (; maxMemory < loaded + need; n = n.next) { clear(n); if (n == ent) throw new LargeObjectException.ExceedsLimit( maxMemory, loaded + need); } }
private byte[] buffer(DeltaWindowEntry ent) throws MissingObjectException, IncorrectObjectTypeException, IOException, LargeObjectException { byte[] buf = ent.buffer; if (buf == null) { checkLoadable(ent, ent.size()); buf = PackWriter.buffer(config, reader, ent.object); if (maxMemory != 0) loaded += buf.length; ent.buffer = buf; } return buf; }
DeltaWindow initWindow(Slice s) { DeltaWindow w = new DeltaWindow(block.config, block.dc, or, block.pm, block.bytesPerUnit, block.list, s.beginIndex, s.endIndex); synchronized (this) { dw = w; } return w; }
clear(res); final long need = estimateSize(next); DeltaWindowEntry n = res.next; for (; maxMemory < loaded + need && n != res; n = n.next) clear(n); clearWindowOnTypeSwitch(); keepInWindow(); } else { bytesProcessed -= d * bytesPerUnit; searchInWindow();
private DeltaIndex index(DeltaWindowEntry ent) throws MissingObjectException, IncorrectObjectTypeException, IOException, LargeObjectException { DeltaIndex idx = ent.index; if (idx == null) { checkLoadable(ent, estimateIndexSize(ent)); try { idx = new DeltaIndex(buffer(ent)); } catch (OutOfMemoryError noMemory) { LargeObjectException.OutOfMemory e; e = new LargeObjectException.OutOfMemory(noMemory); e.setObjectId(ent.object); throw e; } if (maxMemory != 0) loaded += idx.getIndexSize() - idx.getSourceSize(); ent.index = idx; } return idx; }
private void cacheDelta(ObjectToPack srcObj, ObjectToPack resObj) { if (deltaCache.canCache(deltaLen, srcObj, resObj)) { try { byte[] zbuf = new byte[deflateBound(deltaLen)]; ZipStream zs = new ZipStream(deflater(), zbuf); if (deltaBuf instanceof byte[]) zs.write((byte[]) deltaBuf, 0, deltaLen); else ((TemporaryBuffer.Heap) deltaBuf).writeTo(zs, null); deltaBuf = null; int len = zs.finish(); resObj.setCachedDelta(deltaCache.cache(zbuf, len, deltaLen)); resObj.setCachedSize(deltaLen); } catch (IOException err) { deltaCache.credit(deltaLen); } catch (OutOfMemoryError err) { deltaCache.credit(deltaLen); } } }
private void clearWindowOnTypeSwitch() { DeltaWindowEntry p = res.prev; if (!p.empty() && res.type() != p.type()) { for (; p != res; p = p.prev) { clear(p); } } }
private byte[] buffer(DeltaWindowEntry ent) throws MissingObjectException, IncorrectObjectTypeException, IOException, LargeObjectException { byte[] buf = ent.buffer; if (buf == null) { checkLoadable(ent, ent.size()); buf = PackWriter.buffer(config, reader, ent.object); if (maxMemory != 0) loaded += buf.length; ent.buffer = buf; } return buf; }
DeltaWindow initWindow(Slice s) { DeltaWindow w = new DeltaWindow(block.config, block.dc, or, block.pm, block.bytesPerUnit, block.list, s.beginIndex, s.endIndex); synchronized (this) { dw = w; } return w; }
return NEXT_SRC; int msz = deltaSizeLimit(src); if (msz <= 8) // Nearly impossible to fit useful delta. return NEXT_SRC; srcIndex = index(src); } catch (LargeObjectException tooBig) { resBuf = buffer(res); } catch (LargeObjectException tooBig) { : new TemporaryBuffer.Heap(msz); if (srcIndex.encode(delta, resBuf, msz)) selectDeltaBase(src, delta); } catch (IOException deltaTooBig) {
clear(res); final long need = estimateSize(next); DeltaWindowEntry n = res.next; for (; maxMemory < loaded + need && n != res; n = n.next) clear(n); keepInWindow(); } else { bytesProcessed -= d * bytesPerUnit; searchInWindow();
private DeltaIndex index(DeltaWindowEntry ent) throws MissingObjectException, IncorrectObjectTypeException, IOException, LargeObjectException { DeltaIndex idx = ent.index; if (idx == null) { checkLoadable(ent, estimateIndexSize(ent)); try { idx = new DeltaIndex(buffer(ent)); } catch (OutOfMemoryError noMemory) { LargeObjectException.OutOfMemory e; e = new LargeObjectException.OutOfMemory(noMemory); e.setObjectId(ent.object); throw e; } if (maxMemory != 0) loaded += idx.getIndexSize() - idx.getSourceSize(); ent.index = idx; } return idx; }
if (src.empty()) break; if (delta(src) /* == NEXT_SRC */) continue; bestBase = null; keepInWindow(); return; resObj.setDeltaDepth(depth); resObj.clearReuseAsIs(); cacheDelta(srcObj, resObj);
private void singleThreadDeltaSearch(ProgressMonitor monitor, ObjectToPack[] list, int cnt) throws IOException { long totalWeight = 0; for (int i = 0; i < cnt; i++) { ObjectToPack o = list[i]; totalWeight += DeltaTask.getAdjustedWeight(o); } long bytesPerUnit = 1; while (DeltaTask.MAX_METER <= (totalWeight / bytesPerUnit)) bytesPerUnit <<= 10; int cost = (int) (totalWeight / bytesPerUnit); if (totalWeight % bytesPerUnit != 0) cost++; beginPhase(PackingPhase.COMPRESSING, monitor, cost); new DeltaWindow(config, new DeltaCache(config), reader, monitor, bytesPerUnit, list, 0, cnt).search(); endPhase(monitor); }