use of sun.misc.Unsafe in project jdk8u_jdk by JetBrains.
the class MarlinCache method copyAARowRLE_WithBlockFlags.
void copyAARowRLE_WithBlockFlags(final int[] blkFlags, final int[] alphaRow, final int y, final int px0, final int px1) {
if (DO_MONITORS) {
rdrCtx.stats.mon_rdr_copyAARow.start();
}
// Copy rowAA data into the piscesCache if one is present
final int _bboxX0 = bboxX0;
// process tile line [0 - 32]
final int row = y - bboxY0;
// first pixel inclusive
final int from = px0 - _bboxX0;
// skip useless pixels above boundary
final int px_bbox1 = FloatMath.min(px1, bboxX1);
// last pixel exclusive
final int to = px_bbox1 - _bboxX0;
if (DO_LOG_BOUNDS) {
MarlinUtils.logInfo("row = [" + px0 + " ... " + px_bbox1 + " (" + px1 + ") [ for y=" + y);
}
// get current position:
final long initialPos = startRLERow(row, px0, px_bbox1);
// determine need array size:
// pessimistic: max needed size = deltaX x 4 (1 int)
final long needSize = initialPos + ((to - from) << 2);
// update row data:
OffHeapArray _rowAAChunk = rowAAChunk;
// ensure rowAAChunk capacity:
if (_rowAAChunk.length < needSize) {
expandRowAAChunk(needSize);
}
final Unsafe _unsafe = OffHeapArray.UNSAFE;
final long SIZE_INT = 4L;
final long addr_alpha = ALPHA_MAP_UNSAFE.address;
long addr_off = _rowAAChunk.address + initialPos;
final int[] _touchedTile = touchedTile;
final int _TILE_SIZE_LG = TILE_SIZE_LG;
final int _BLK_SIZE_LG = BLOCK_SIZE_LG;
// traverse flagged blocks:
final int blkW = (from >> _BLK_SIZE_LG);
final int blkE = (to >> _BLK_SIZE_LG) + 1;
// Perform run-length encoding and store results in the piscesCache
int val = 0;
int cx0 = from;
int runLen;
final int _MAX_VALUE = Integer.MAX_VALUE;
int last_t0 = _MAX_VALUE;
int skip = 0;
for (int t = blkW, blk_x0, blk_x1, cx, delta; t <= blkE; t++) {
if (blkFlags[t] != 0) {
blkFlags[t] = 0;
if (last_t0 == _MAX_VALUE) {
last_t0 = t;
}
continue;
}
if (last_t0 != _MAX_VALUE) {
// emit blocks:
blk_x0 = FloatMath.max(last_t0 << _BLK_SIZE_LG, from);
last_t0 = _MAX_VALUE;
// (last block pixel+1) inclusive => +1
blk_x1 = FloatMath.min((t << _BLK_SIZE_LG) + 1, to);
for (cx = blk_x0; cx < blk_x1; cx++) {
if ((delta = alphaRow[cx]) != 0) {
alphaRow[cx] = 0;
// not first rle entry:
if (cx != cx0) {
runLen = cx - cx0;
// check address alignment to 4 bytes:
if (DO_CHECK_UNSAFE) {
if ((addr_off & 3) != 0) {
MarlinUtils.logInfo("Misaligned Unsafe address: " + addr_off);
}
}
// special case to encode entries into a single int:
if (val == 0) {
_unsafe.putInt(addr_off, ((_bboxX0 + cx) << 8));
} else {
_unsafe.putInt(addr_off, ((_bboxX0 + cx) << 8) | // [0..255]
(((int) _unsafe.getByte(addr_alpha + val)) & 0xFF));
if (runLen == 1) {
_touchedTile[cx0 >> _TILE_SIZE_LG] += val;
} else {
touchTile(cx0, val, cx, runLen, _touchedTile);
}
}
addr_off += SIZE_INT;
if (DO_STATS) {
rdrCtx.stats.hist_tile_generator_encoding_runLen.add(runLen);
}
cx0 = cx;
}
// alpha value = running sum of coverage delta:
val += delta;
// ensure values are in [0; MAX_AA_ALPHA] range
if (DO_AA_RANGE_CHECK) {
if (val < 0) {
System.out.println("Invalid coverage = " + val);
val = 0;
}
if (val > MAX_AA_ALPHA) {
System.out.println("Invalid coverage = " + val);
val = MAX_AA_ALPHA;
}
}
}
}
} else if (DO_STATS) {
skip++;
}
}
// Process remaining RLE run:
runLen = to - cx0;
// check address alignment to 4 bytes:
if (DO_CHECK_UNSAFE) {
if ((addr_off & 3) != 0) {
MarlinUtils.logInfo("Misaligned Unsafe address: " + addr_off);
}
}
// special case to encode entries into a single int:
if (val == 0) {
_unsafe.putInt(addr_off, ((_bboxX0 + to) << 8));
} else {
_unsafe.putInt(addr_off, ((_bboxX0 + to) << 8) | // [0..255]
(((int) _unsafe.getByte(addr_alpha + val)) & 0xFF));
if (runLen == 1) {
_touchedTile[cx0 >> _TILE_SIZE_LG] += val;
} else {
touchTile(cx0, val, to, runLen, _touchedTile);
}
}
addr_off += SIZE_INT;
if (DO_STATS) {
rdrCtx.stats.hist_tile_generator_encoding_runLen.add(runLen);
}
long len = (addr_off - _rowAAChunk.address);
// update coded length as bytes:
rowAALen[row] = (len - initialPos);
// update current position:
rowAAChunkPos = len;
if (DO_STATS) {
rdrCtx.stats.stat_cache_rowAA.add(rowAALen[row]);
rdrCtx.stats.hist_tile_generator_encoding_ratio.add((100 * skip) / (blkE - blkW));
}
// update tile used marks:
// inclusive
int tx = from >> _TILE_SIZE_LG;
if (tx < tileMin) {
tileMin = tx;
}
// exclusive (+1 to be sure)
tx = ((to - 1) >> _TILE_SIZE_LG) + 1;
if (tx > tileMax) {
tileMax = tx;
}
// Clear alpha row for reuse:
if (px1 > bboxX1) {
alphaRow[to] = 0;
alphaRow[to + 1] = 0;
}
if (DO_CHECKS) {
IntArrayCache.check(blkFlags, blkW, blkE, 0);
IntArrayCache.check(alphaRow, from, px1 - bboxX0, 0);
}
if (DO_MONITORS) {
rdrCtx.stats.mon_rdr_copyAARow.stop();
}
}
use of sun.misc.Unsafe in project jdk8u_jdk by JetBrains.
the class CopyMemory method main.
public static void main(String[] args) throws Exception {
Unsafe unsafe = getUnsafe();
testSetByteArray(unsafe);
testSetRawMemory(unsafe);
testCopyByteArrayToByteArray(unsafe);
testCopyByteArrayToRawMemory(unsafe);
testCopyRawMemoryToByteArray(unsafe);
testCopyRawMemoryToRawMemory(unsafe);
System.out.println("OK");
}
use of sun.misc.Unsafe in project algorithms by Iurii-Dziuban.
the class CrashIntTest method getUnsafe.
// the way how to get Unsafe without Security exception
private static Unsafe getUnsafe() {
try {
Field singleOneInstanceField = Unsafe.class.getDeclaredField("theUnsafe");
singleOneInstanceField.setAccessible(true);
return (Unsafe) singleOneInstanceField.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of sun.misc.Unsafe in project suite by stupidsing.
the class UnsafeUtil method defineClass.
public <T> Class<? extends T> defineClass(Class<T> interfaceClazz, String className, byte[] bytes, Object[] array) {
Unsafe unsafe = source.source();
@SuppressWarnings("unchecked") Class<? extends T> clazz = (Class<? extends T>) unsafe.defineAnonymousClass(interfaceClazz, bytes, array);
return clazz;
}
use of sun.misc.Unsafe in project ignite by apache.
the class ConcurrentLinkedDeque8 method unsafe.
/**
* @return Instance of Unsafe class.
*/
static Unsafe unsafe() {
try {
return Unsafe.getUnsafe();
} catch (SecurityException ignored) {
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<Unsafe>() {
@Override
public Unsafe run() throws Exception {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
}
});
} catch (PrivilegedActionException e) {
throw new RuntimeException("Could not initialize intrinsics.", e.getCause());
}
}
}
Aggregations