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());
}
}
}
use of sun.misc.Unsafe in project undertow by undertow-io.
the class ServletPrintWriterDelegate method getUnsafe0.
private static Unsafe getUnsafe0() {
try {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
return (Unsafe) theUnsafe.get(null);
} catch (Throwable t) {
throw new RuntimeException("JDK did not allow accessing unsafe", t);
}
}
use of sun.misc.Unsafe in project undertow by undertow-io.
the class FastConcurrentDirectDeque method getUnsafe0.
private static Unsafe getUnsafe0() {
try {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
return (Unsafe) theUnsafe.get(null);
} catch (Throwable t) {
throw new RuntimeException("JDK did not allow accessing unsafe", t);
}
}
use of sun.misc.Unsafe in project jdk8u_jdk by JetBrains.
the class MarlinTileGenerator method getAlphaRLE.
/**
* Gets the alpha coverage values for the current tile.
* Either this method, or the nextTile() method should be called
* once per tile, but not both.
*/
private void getAlphaRLE(final byte[] tile, final int offset, final int rowstride) {
if (DO_MONITORS) {
rdrCtx.stats.mon_ptg_getAlpha.start();
}
// Decode run-length encoded alpha mask data
// The data for row j begins at cache.rowOffsetsRLE[j]
// and is encoded as a set of 2-byte pairs (val, runLen)
// terminated by a (0, 0) pair.
// local vars for performance:
final MarlinCache _cache = this.cache;
final long[] rowAAChunkIndex = _cache.rowAAChunkIndex;
final int[] rowAAx0 = _cache.rowAAx0;
final int[] rowAAx1 = _cache.rowAAx1;
final int[] rowAAEnc = _cache.rowAAEnc;
final long[] rowAALen = _cache.rowAALen;
final long[] rowAAPos = _cache.rowAAPos;
final int x0 = this.x;
final int x1 = FloatMath.min(x0 + TILE_SIZE, _cache.bboxX1);
// note: process tile line [0 - 32[
final int y0 = 0;
final int y1 = FloatMath.min(this.y + TILE_SIZE, _cache.bboxY1) - this.y;
if (DO_LOG_BOUNDS) {
MarlinUtils.logInfo("getAlpha = [" + x0 + " ... " + x1 + "[ [" + y0 + " ... " + y1 + "[");
}
final Unsafe _unsafe = OffHeapArray.UNSAFE;
final long SIZE_BYTE = 1L;
final long SIZE_INT = 4L;
final long addr_rowAA = _cache.rowAAChunk.address;
long addr, addr_row, last_addr, addr_end;
final int skipRowPixels = (rowstride - (x1 - x0));
int cx, cy, cx1;
int rx0, rx1, runLen, end;
int packed;
byte val;
int idx = offset;
for (cy = y0; cy < y1; cy++) {
// empty line (default)
cx = x0;
if (rowAAEnc[cy] == 0) {
// Raw encoding:
// exclusive
final int aax1 = rowAAx1[cy];
// corresponding to this tile [x0; x1[
if (aax1 > x0) {
// inclusive
final int aax0 = rowAAx0[cy];
if (aax0 < x1) {
// note: cx is the cursor pointer in the tile array
// (left to right)
cx = aax0;
// ensure cx >= x0
if (cx <= x0) {
cx = x0;
} else {
// fill line start until first AA pixel rowAA exclusive:
for (end = x0; end < cx; end++) {
tile[idx++] = 0;
}
}
// now: cx >= x0 but cx < aax0 (x1 < aax0)
// Copy AA data (sum alpha data):
addr = addr_rowAA + rowAAChunkIndex[cy] + (cx - aax0);
for (end = (aax1 <= x1) ? aax1 : x1; cx < end; cx++) {
// [0..255]
tile[idx++] = _unsafe.getByte(addr);
addr += SIZE_BYTE;
}
}
}
} else {
// corresponding to this tile [x0; x1[
if (rowAAx1[cy] > x0) {
// last pixel exclusive
// inclusive
cx = rowAAx0[cy];
if (cx > x1) {
cx = x1;
}
// fill line start until first AA pixel rowAA exclusive:
for (int i = x0; i < cx; i++) {
tile[idx++] = 0;
}
// get row address:
addr_row = addr_rowAA + rowAAChunkIndex[cy];
// get row end address:
// coded length
addr_end = addr_row + rowAALen[cy];
// reuse previous iteration position:
addr = addr_row + rowAAPos[cy];
last_addr = 0L;
while ((cx < x1) && (addr < addr_end)) {
// keep current position:
last_addr = addr;
// packed value:
packed = _unsafe.getInt(addr);
// last exclusive pixel x-coordinate:
cx1 = (packed >> 8);
// as bytes:
addr += SIZE_INT;
rx0 = cx;
if (rx0 < x0) {
rx0 = x0;
}
rx1 = cx = cx1;
if (rx1 > x1) {
rx1 = x1;
// fix last x
cx = x1;
}
// adjust runLen:
runLen = rx1 - rx0;
// ensure rx1 > rx0:
if (runLen > 0) {
// [0..255]
val = (byte) (packed & 0xFF);
do {
tile[idx++] = val;
} while (--runLen > 0);
}
}
// Update last position in RLE entries:
if (last_addr != 0L) {
// Fix x0:
// inclusive
rowAAx0[cy] = cx;
// Fix position:
rowAAPos[cy] = (last_addr - addr_row);
}
}
}
// fill line end
while (cx < x1) {
tile[idx++] = 0;
cx++;
}
if (DO_TRACE) {
for (int i = idx - (x1 - x0); i < idx; i++) {
System.out.print(hex(tile[i], 2));
}
System.out.println();
}
idx += skipRowPixels;
}
nextTile();
if (DO_MONITORS) {
rdrCtx.stats.mon_ptg_getAlpha.stop();
}
}
use of sun.misc.Unsafe in project jdk8u_jdk by JetBrains.
the class MarlinTileGenerator method getAlphaNoRLE.
/**
* Gets the alpha coverage values for the current tile.
* Either this method, or the nextTile() method should be called
* once per tile, but not both.
*/
private void getAlphaNoRLE(final byte[] tile, final int offset, final int rowstride) {
if (DO_MONITORS) {
rdrCtx.stats.mon_ptg_getAlpha.start();
}
// local vars for performance:
final MarlinCache _cache = this.cache;
final long[] rowAAChunkIndex = _cache.rowAAChunkIndex;
final int[] rowAAx0 = _cache.rowAAx0;
final int[] rowAAx1 = _cache.rowAAx1;
final int x0 = this.x;
final int x1 = FloatMath.min(x0 + TILE_SIZE, _cache.bboxX1);
// note: process tile line [0 - 32[
final int y0 = 0;
final int y1 = FloatMath.min(this.y + TILE_SIZE, _cache.bboxY1) - this.y;
if (DO_LOG_BOUNDS) {
MarlinUtils.logInfo("getAlpha = [" + x0 + " ... " + x1 + "[ [" + y0 + " ... " + y1 + "[");
}
final Unsafe _unsafe = OffHeapArray.UNSAFE;
final long SIZE = 1L;
final long addr_rowAA = _cache.rowAAChunk.address;
long addr;
final int skipRowPixels = (rowstride - (x1 - x0));
int aax0, aax1, end;
int idx = offset;
for (int cy = y0, cx; cy < y1; cy++) {
// empty line (default)
cx = x0;
// exclusive
aax1 = rowAAx1[cy];
// corresponding to this tile [x0; x1[
if (aax1 > x0) {
// inclusive
aax0 = rowAAx0[cy];
if (aax0 < x1) {
// note: cx is the cursor pointer in the tile array
// (left to right)
cx = aax0;
// ensure cx >= x0
if (cx <= x0) {
cx = x0;
} else {
// fill line start until first AA pixel rowAA exclusive:
for (end = x0; end < cx; end++) {
tile[idx++] = 0;
}
}
// now: cx >= x0 but cx < aax0 (x1 < aax0)
// Copy AA data (sum alpha data):
addr = addr_rowAA + rowAAChunkIndex[cy] + (cx - aax0);
for (end = (aax1 <= x1) ? aax1 : x1; cx < end; cx++) {
// cx inside tile[x0; x1[ :
// [0..255]
tile[idx++] = _unsafe.getByte(addr);
addr += SIZE;
}
}
}
// fill line end
while (cx < x1) {
tile[idx++] = 0;
cx++;
}
if (DO_TRACE) {
for (int i = idx - (x1 - x0); i < idx; i++) {
System.out.print(hex(tile[i], 2));
}
System.out.println();
}
idx += skipRowPixels;
}
nextTile();
if (DO_MONITORS) {
rdrCtx.stats.mon_ptg_getAlpha.stop();
}
}
Aggregations