use of sun.misc.Unsafe in project Universal-Pointer-Searcher by BullyWiiPlaza.
the class UnsafeTesting method runTest.
private void runTest(boolean useUnsafeMethod) throws Exception {
Unsafe unsafe = getUnsafeInstance();
long destinationByteBufferAddress = ((DirectBuffer) destinationByteBuffer).address();
long sourceByteBufferAddress = ((DirectBuffer) sourceByteBuffer).address();
int executionsCount = 0;
if (useUnsafeMethod) {
for (int sourceBufferIndex = 0; sourceBufferIndex < destinationByteBuffer.remaining() - 3; sourceBufferIndex += 4) {
long sourceOffset = sourceByteBufferAddress + sourceBufferIndex;
int value = unsafe.getInt(sourceOffset);
long targetOffset = destinationByteBufferAddress + sourceBufferIndex;
unsafe.putInt(targetOffset, value);
executionsCount++;
}
} else {
while (sourceByteBuffer.remaining() > 3) {
int value = destinationByteBuffer.getInt();
sourceByteBuffer.putInt(value);
executionsCount++;
}
}
/*sourceByteBuffer.position(0);
destinationByteBuffer.position(0);
boolean equal = sourceByteBuffer.equals(destinationByteBuffer);
if (!equal)
{
throw new IllegalStateException("Buffers not equal!");
}*/
System.out.println("Executions: " + executionsCount);
}
use of sun.misc.Unsafe in project graal by oracle.
the class AMD64GraphBuilderPlugins method registerUnsafePlugins.
private static void registerUnsafePlugins(InvocationPlugins plugins, BytecodeProvider replacementsBytecodeProvider) {
Registration r;
if (Java8OrEarlier) {
r = new Registration(plugins, Unsafe.class);
} else {
r = new Registration(plugins, "jdk.internal.misc.Unsafe", replacementsBytecodeProvider);
}
for (JavaKind kind : new JavaKind[] { JavaKind.Int, JavaKind.Long, JavaKind.Object }) {
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
r.register4("getAndSet" + kind.name(), Receiver.class, Object.class, long.class, javaClass, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode value) {
// Emits a null-check for the otherwise unused receiver
unsafe.get();
b.addPush(kind, new AtomicReadAndWriteNode(object, offset, value, kind, LocationIdentity.any()));
b.getGraph().markUnsafeAccess();
return true;
}
});
if (kind != JavaKind.Object) {
r.register4("getAndAdd" + kind.name(), Receiver.class, Object.class, long.class, javaClass, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode delta) {
// Emits a null-check for the otherwise unused receiver
unsafe.get();
AddressNode address = b.add(new OffsetAddressNode(object, offset));
b.addPush(kind, new AtomicReadAndAddNode(address, delta, LocationIdentity.any()));
b.getGraph().markUnsafeAccess();
return true;
}
});
}
}
for (JavaKind kind : new JavaKind[] { JavaKind.Char, JavaKind.Short, JavaKind.Int, JavaKind.Long }) {
Class<?> javaClass = kind.toJavaClass();
r.registerOptional3("get" + kind.name() + "Unaligned", Receiver.class, Object.class, long.class, new UnsafeGetPlugin(kind, false));
r.registerOptional4("put" + kind.name() + "Unaligned", Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, false));
}
}
use of sun.misc.Unsafe in project openj9 by eclipse.
the class FrameIteratorTestGenerator method testFrameIteratorSkipAnnontationForNonBootstrapClass.
@Test
public void testFrameIteratorSkipAnnontationForNonBootstrapClass() throws Throwable {
final byte[] classBytes = FrameIteratorTestGenerator.dump();
/* Use reflect to get Unsafe so we can avoid the 'must be bootstrap' check */
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
Unsafe unsafe = (Unsafe) theUnsafe.get(null);
/* Force the class to be loaded in the Extension Loader so we can use sun.reflect.Reflection.getCallerClass() */
ClassLoader extLoader = Cmvc194781.class.getClassLoader().getParent();
Class<?> test = unsafe.defineClass("FrameIteratorTest", classBytes, 0, classBytes.length, extLoader, Cmvc194781.class.getProtectionDomain());
PrivilegedAction<Class<?>> instance = (PrivilegedAction<Class<?>>) test.newInstance();
Class<?> caller = (Class<?>) instance.run();
AssertJUnit.assertEquals(Cmvc194781.class, caller);
}
use of sun.misc.Unsafe in project hpcourse by cscenter.
the class MyAtomicInteger method getUnsafe.
// @SuppressWarnings("restriction")
private static Unsafe getUnsafe() {
try {
Field singleoneInstanceField = Unsafe.class.getDeclaredField("theUnsafe");
singleoneInstanceField.setAccessible(true);
return (Unsafe) singleoneInstanceField.get(null);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new IllegalStateException(e);
}
}
use of sun.misc.Unsafe in project incubator-crail by apache.
the class RdmaStorageLocalEndpoint method getUnsafe.
private Unsafe getUnsafe() throws Exception {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
Unsafe unsafe = (Unsafe) theUnsafe.get(null);
return unsafe;
}
Aggregations