本文整理了Java中sun.misc.Unsafe.putAddress()
方法的一些代码示例,展示了Unsafe.putAddress()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe.putAddress()
方法的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
方法名:putAddress
[英]Stores a native pointer into a given memory address. If the address is zero, or does not point into a block obtained from #allocateMemory, the results are undefined.
The number of bytes actually written at the target address maybe determined by consulting #addressSize.
[中]将本机指针存储到给定的内存地址中。如果地址为零,或未指向从#allocateMemory获得的块,则结果未定义。
在目标地址实际写入的字节数可能由#addressSize决定。
代码示例来源:origin: stackoverflow.com
import sun.misc.Unsafe;
public class Crash {
private static final Unsafe unsafe = Unsafe.getUnsafe();
public static void crash() {
unsafe.putAddress(0, 0);
}
public static void main(String[] args) {
crash();
}
}
代码示例来源:origin: Devexperts/lin-check
@Override
public final OnAddressFollowBy putAddress(long address){
UNSAFE.putAddress(currentAddress,address);
currentAddress += SIZE_ADDRESS;
return this;
}
代码示例来源:origin: com.tomitribe.tribestream/tribestream-metrics-bytecode
public static void putAddress(final long address, final long x) {
UNSAFE.putAddress(address, x);
}
代码示例来源:origin: MyCATApache/Mycat-JCache
public static void putAddress(long addr,long value){
unsafe.putAddress(addr, value);
}
代码示例来源:origin: serkan-ozal/mysafe
@Override
public void putAddress(Unsafe unsafe, long address, long x) {
unsafe.putAddress(address, x);
}
代码示例来源:origin: Devexperts/lin-check
public static final void putAddress(long address,long addrValue) {
UNSAFE.putAddress(address,addrValue);
}
代码示例来源:origin: org.lwjgl.lwjgl/lwjgl_util
public static void aput(long value, long addr) {
INSTANCE.putAddress(addr, value);
}
代码示例来源:origin: org.lwjgl.lwjgl/lwjgl_util
public static void aput(MappedObject mapped, long value, int fieldOffset) {
INSTANCE.putAddress(mapped.viewAddress + fieldOffset, value);
}
代码示例来源:origin: Devexperts/lin-check
private static final void tlp_FreePages_addToHead(long addrFreePagesHead,
long newFreePage,
long addrNumFreePages) {
long numFreePages = UNSAFE.getLong(addrNumFreePages);
long oldHead = UNSAFE.getAddress(addrFreePagesHead);
if (numFreePages != 0) {//oldHead!=availablePageTail
UNSAFE.putAddress(oldHead + ZMPAGE_PREVFREEPAGE_OFFSET, newFreePage);
}else {//oldHead is tail
UNSAFE.putAddress(oldHead, newFreePage);
}
UNSAFE.putAddress(newFreePage + ZMPAGE_NEXTFREEPAGE_OFFSET, oldHead);
UNSAFE.putAddress(newFreePage + ZMPAGE_PREVFREEPAGE_OFFSET,
addrFreePagesHead);
UNSAFE.putAddress(addrFreePagesHead, newFreePage);
UNSAFE.putLong(addrNumFreePages, numFreePages + 1);
}
代码示例来源:origin: Devexperts/lin-check
private static final void tlp_AvailablePages_addToHead(
long addrAvailablePageHead,
long newAvailablePage) {
long addrNumAvailablePage = addrAvailablePageHead+2*SIZE_LONG_TYPE;
long numAvailablePage = UNSAFE.getLong(addrNumAvailablePage);
long oldHead = UNSAFE.getAddress(addrAvailablePageHead);
if (numAvailablePage != 0) {//oldHead!=availablePageTail
UNSAFE.putAddress(oldHead + ZMPAGE_PREVPAGE_OFFSET,
newAvailablePage);
}else {//oldHead is tail
UNSAFE.putAddress(oldHead, newAvailablePage);
}
UNSAFE.putAddress(newAvailablePage + ZMPAGE_NEXTPAGE_OFFSET, oldHead);
UNSAFE.putAddress(newAvailablePage + ZMPAGE_PREVPAGE_OFFSET,
addrAvailablePageHead);
UNSAFE.putAddress(addrAvailablePageHead, newAvailablePage);
UNSAFE.putLong(addrNumAvailablePage, numAvailablePage + 1);
}
代码示例来源:origin: Devexperts/lin-check
private static final void pg_AvailableChunks_push(long addressPage,
long addressChunk) {
//availableChunks = addressPage
long head = UNSAFE.getAddress(addressPage);
UNSAFE.putAddress(addressPage, addressChunk);
UNSAFE.putAddress(addressChunk, head);
long numAvailableChunks = addressPage+ZMPAGE_NUMAVAILABLECHUNKS_OFFSET;
UNSAFE.putInt(numAvailableChunks, UNSAFE.getInt(numAvailableChunks) + 1);
}
代码示例来源:origin: Devexperts/lin-check
private static final void tlp_RemoteFreedChunksHead_add(
long addrRemoteFreedChunksTail,
long addrRemoteFreedChunk) {
UNSAFE.putAddress(addrRemoteFreedChunk,NULL_ADDRESS);
// UNSAFE.fullFence();
long oldTail = UNSAFE.getAndSetLong(null,
addrRemoteFreedChunksTail, addrRemoteFreedChunk);
UNSAFE.putAddress(oldTail, addrRemoteFreedChunk);
UNSAFE.fullFence();
}
代码示例来源:origin: Devexperts/lin-check
private static final void tlp_FreePages_remove(long addrFreePagesHead,
long addrFreePagesTail,
long addrNumFreePages,
long removedFreePage) {
long addrPrevFreePage = removedFreePage+ZMPAGE_PREVFREEPAGE_OFFSET;
long addrNextFreePage = removedFreePage+ZMPAGE_NEXTFREEPAGE_OFFSET;
long prev = UNSAFE.getAddress(addrPrevFreePage);
long next = UNSAFE.getAddress(addrNextFreePage);
if (prev!=addrFreePagesHead) {
UNSAFE.putAddress(prev+ZMPAGE_NEXTFREEPAGE_OFFSET,next);
} else {//prev is head
UNSAFE.putAddress(prev,next);
}
if (next!=addrFreePagesTail) {
UNSAFE.putAddress(next+ZMPAGE_PREVFREEPAGE_OFFSET,prev);
} else {//next is tail
UNSAFE.putAddress(next,prev);
}
UNSAFE.putLong(addrNumFreePages, UNSAFE.getLong(addrNumFreePages)-1);
}
代码示例来源:origin: Devexperts/lin-check
private static final long pg_AvailableChunks_pop(long addressPage) {
//long availableChunks = addressPage+ZMPAGE_AVAILABLECHUNKS_OFFSET;
long head = UNSAFE.getAddress(addressPage);
if (head != NULL_ADDRESS) {
UNSAFE.putAddress(addressPage, UNSAFE.getAddress(head));
long numAvailableChunks = addressPage+ZMPAGE_NUMAVAILABLECHUNKS_OFFSET;
UNSAFE.putInt(numAvailableChunks, UNSAFE.getInt(numAvailableChunks) - 1);
}//meet a full zmalloc page when head ==0L
return head;
}
代码示例来源:origin: noctarius/unsafe-java-world
public static void main(String[] args) throws Exception {
// Reading the address of the String class
long strClassAddress = normalize(UnsafeSupport.UNSAFE.getInt("", 8L));
// Reading the address of the Integer class
long intClassAddress = normalize(UnsafeSupport.UNSAFE.getInt(new Integer(0), 8L));
// Write String class address as superclass to Integer class
UnsafeSupport.UNSAFE.putAddress(intClassAddress + 32, strClassAddress);
// Creating a new Integer object
Integer intValue = new Integer(666);
// Casting the Integer to it's now String superclass
String value = (String) (Object) intValue;
// Proof it works :)
System.out.println("String (Integer) value is: " + value);
Class<?> clazz = Integer.class;
while (clazz != null) {
System.out.println("Class: " + clazz);
clazz = clazz.getSuperclass();
}
}
代码示例来源:origin: stackoverflow.com
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class Direct {
public static void main(String... args) {
Unsafe unsafe = null;
try {
Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
unsafe = (sun.misc.Unsafe) field.get(null);
} catch (Exception e) {
throw new AssertionError(e);
}
long value = 12345;
byte size = 1;
long allocateMemory = unsafe.allocateMemory(size);
unsafe.putAddress(allocateMemory, value);
long readValue = unsafe.getAddress(allocateMemory);
System.out.println("read value : " + readValue);
}
}
代码示例来源:origin: org.graalvm.compiler/compiler
@Override
@Operation(opcode = Opcode.WRITE_POINTER)
public void writeWord(WordBase offset, WordBase val) {
UNSAFE.putAddress(add((Word) offset).unbox(), ((Word) val).unbox());
}
代码示例来源:origin: org.graalvm.compiler/compiler
@Override
@Operation(opcode = Opcode.WRITE_POINTER)
public void writeWord(WordBase offset, WordBase val, LocationIdentity locationIdentity) {
UNSAFE.putAddress(add((Word) offset).unbox(), ((Word) val).unbox());
}
代码示例来源:origin: apache/mnemonic
@Override
public void setName(String name, boolean destroy) throws OutOfHybridMemory,
RetrieveDurableEntityError {
if (destroy && null != getName()) {
m_name_1B779B.destroy();
m_name_1B779B = null;
m_unsafe_B1757C.putAddress(m_holder_3CE8C3.get() + 0, 0L);
}
if (null == name) {
m_unsafe_B1757C.putLong(m_holder_3CE8C3.get() + 0, 0L);
} else {
m_name_1B779B = m_allocator_11A68B.createBuffer(name.length() * 2, m_autoreclaim_071A8E);
if (null == m_name_1B779B) {
throw new OutOfHybridMemory("Create Durable String Error!");
}
m_name_1B779B.get().asCharBuffer().put(name);
m_unsafe_B1757C.putLong(m_holder_3CE8C3.get() + 0, m_allocator_11A68B.getBufferHandler(m_name_1B779B));
}
}
代码示例来源:origin: apache/mnemonic
@Override
public void setName(String name, boolean destroy) throws OutOfHybridMemory,
RetrieveDurableEntityError {
if (destroy && null != getName()) {
m_name_9807CF.destroy();
m_name_9807CF = null;
m_unsafe_760FBE.putAddress(m_holder_68BA57.get() + 0, 0L);
}
if (null == name) {
m_unsafe_760FBE.putLong(m_holder_68BA57.get() + 0, 0L);
} else {
m_name_9807CF = m_allocator_77CA34.createBuffer(name.length() * 2, m_autoreclaim_7E4A25);
if (null == m_name_9807CF) {
throw new OutOfHybridMemory("Create Durable String Error!");
}
m_name_9807CF.get().asCharBuffer().put(name);
m_unsafe_760FBE.putLong(m_holder_68BA57.get() + 0, m_allocator_77CA34.getBufferHandler(m_name_9807CF));
}
}
内容来源于网络,如有侵权,请联系作者删除!