sun.misc.Unsafe.arrayBaseOffset()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(229)

本文整理了Java中sun.misc.Unsafe.arrayBaseOffset()方法的一些代码示例,展示了Unsafe.arrayBaseOffset()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe.arrayBaseOffset()方法的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
方法名:arrayBaseOffset

Unsafe.arrayBaseOffset介绍

[英]Gets the offset from the start of an array object's memory to the memory used to store its initial (zeroeth) element.
[中]获取从数组对象的内存开始到用于存储其初始(零)元素的内存的偏移量。

代码示例

代码示例来源:origin: neo4j/neo4j

public static int arrayBaseOffset( Class klass )
{
  return unsafe.arrayBaseOffset( klass );
}

代码示例来源:origin: apache/ignite

/**
 * Returns the offset of the first element in the storage allocation of a given array class.
 *
 * @param cls Class.
 * @return the offset of the first element in the storage allocation of a given array class.
 */
public static int arrayBaseOffset(Class cls) {
  return UNSAFE.arrayBaseOffset(cls);
}

代码示例来源:origin: apache/hbase

@Override
int arrayHeaderSize() {
 return UnsafeAccess.theUnsafe.arrayBaseOffset(byte[].class);
}

代码示例来源:origin: fengjiachun/Jupiter

/**
 * Reports the offset of the first element in the storage allocation of a
 * given array class.
 */
public static int arrayBaseOffset(Class<?> clazz) {
  return unsafe != null ? unsafe.arrayBaseOffset(clazz) : -1;
}

代码示例来源:origin: com.google.protobuf/protobuf-java

public final int arrayBaseOffset(Class<?> clazz) {
 return unsafe.arrayBaseOffset(clazz);
}

代码示例来源:origin: apache/geode

public int arrayBaseOffset(Class c) {
 return this.unsafe.arrayBaseOffset(c);
}

代码示例来源:origin: fengjiachun/Jupiter

/**
 * Reports the offset of the first element in the storage allocation of a
 * given array class.
 */
public static int arrayBaseOffset(Class<?> clazz) {
  return unsafe != null ? unsafe.arrayBaseOffset(clazz) : -1;
}

代码示例来源:origin: greenrobot/essentials

int testInt = unsafe.getInt(test, (long) unsafe.arrayBaseOffset(byte[].class));
if (testInt == 0xcafebabe) {
  if (BIG_ENDIAN) {

代码示例来源:origin: greenrobot/essentials

int testInt = unsafe.getInt(test, (long) unsafe.arrayBaseOffset(byte[].class));
if (testInt == 0xcafebabe) {
  if (BIG_ENDIAN) {

代码示例来源:origin: stackoverflow.com

long baseOffset = unsafe.arrayBaseOffset(Object[].class);
int addressSize = unsafe.addressSize();
long objectAddress;

代码示例来源:origin: stackoverflow.com

System.out.print(label + ": 0x");
long last = 0;
int offset = unsafe.arrayBaseOffset(objects.getClass());
int scale = unsafe.arrayIndexScale(objects.getClass());
switch (scale) {

代码示例来源:origin: prestodb/presto

int base = VMSupport.U.arrayBaseOffset(Class.forName(data.arrayClass()));
int scale = VMSupport.U.arrayIndexScale(Class.forName(data.arrayClass()));

代码示例来源:origin: stackoverflow.com

import sun.misc.Unsafe;
import java.lang.reflect.Field;

public class Main {

  public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException, InstantiationException {
    /* too lazy to run with VM args, use Reflection */
    Field f = Unsafe.class.getDeclaredField("theUnsafe");
    f.setAccessible(true);
    /* get array address */
    Unsafe unsafe = (Unsafe)f.get(null);
    byte four_bytes[] = {25, 25, 25, 25};
    Object trash[] = new Object[] { four_bytes };
    long base_offset_bytes = unsafe.arrayBaseOffset(Object[].class);
    long four_bytes_address = unsafe.getLong(trash, base_offset_bytes); // <- this is it
    long ints_addr = unsafe.allocateMemory(16); // allocate 4 * 4 bytes, i.e. 4 ints
    unsafe.copyMemory(four_bytes_address + base_offset_bytes, ints_addr, 4); // copy all four bytes
    for(int i = 0; i < 4; i++) {
      System.out.println(unsafe.getInt(ints_addr + i)); //run through entire allocated int[],
                               // get some intestines
    }
    System.out.println("*****************************");
    for(int i = 0; i < 16; i++) {
      System.out.println(unsafe.getByte(ints_addr + i)); //run through entire allocated int[],
                               // get some intestines
    }
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

if (obj.getClass().isArray()) {
  Class<?> klazz = obj.getClass();
  int base = UNSAFE.arrayBaseOffset(klazz);
  int scale = UNSAFE.arrayIndexScale(klazz);
  long size = base + (scale * Array.getLength(obj));

代码示例来源:origin: com.google.protobuf/protobuf-lite

/**
 * Get the base offset for byte arrays, or {@code -1} if {@code sun.misc.Unsafe} is not available.
 */
private static int byteArrayBaseOffset() {
 return HAS_UNSAFE_ARRAY_OPERATIONS ? UNSAFE.arrayBaseOffset(byte[].class) : -1;
}

代码示例来源:origin: yeriomin/play-store-api

/**
 * Get the base offset for byte arrays, or {@code -1} if {@code sun.misc.Unsafe} is not available.
 */
private static int byteArrayBaseOffset() {
 return HAS_UNSAFE_ARRAY_OPERATIONS ? UNSAFE.arrayBaseOffset(byte[].class) : -1;
}

代码示例来源:origin: org.jupiter-rpc/jupiter-common

/**
 * Reports the offset of the first element in the storage allocation of a
 * given array class.
 */
public static int arrayBaseOffset(Class<?> clazz) {
  return unsafe != null ? unsafe.arrayBaseOffset(clazz) : -1;
}

代码示例来源:origin: com.orientechnologies/orient-commons

@Override
public byte[] get(long pointer, final int length) {
 final byte[] result = new byte[length];
 unsafe.copyMemory(null, pointer, result, unsafe.arrayBaseOffset(byte[].class), length);
 return result;
}

代码示例来源:origin: ethjava/web3j-sample

public static Object fromAddress(long address) {
  Object[] array = new Object[]{null};
  long baseOffset = getUnsafe().arrayBaseOffset(Object[].class);
  getUnsafe().putLong(array, baseOffset, address);
  return array[0];
}

代码示例来源:origin: ethjava/web3j-sample

public static long toAddress(Object obj) {
  Object[] array = new Object[]{obj};
  long baseOffset = getUnsafe().arrayBaseOffset(Object[].class);
  return normalize(getUnsafe().getInt(array, baseOffset));
}

相关文章

Unsafe类方法