当前位置: 首页>>代码示例>>Java>>正文


Java Unsafe.ARRAY_BYTE_INDEX_SCALE属性代码示例

本文整理汇总了Java中sun.misc.Unsafe.ARRAY_BYTE_INDEX_SCALE属性的典型用法代码示例。如果您正苦于以下问题:Java Unsafe.ARRAY_BYTE_INDEX_SCALE属性的具体用法?Java Unsafe.ARRAY_BYTE_INDEX_SCALE怎么用?Java Unsafe.ARRAY_BYTE_INDEX_SCALE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在sun.misc.Unsafe的用法示例。


在下文中一共展示了Unsafe.ARRAY_BYTE_INDEX_SCALE属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: entryIndexForOffset

public static int entryIndexForOffset(long constantOffset, JavaKind expectedEntryKind, ResolvedJavaType componentType, int length) {
    int baseOffset;
    int indexScale;
    switch (componentType.getJavaKind()) {
        case Boolean:
            baseOffset = Unsafe.ARRAY_BOOLEAN_BASE_OFFSET;
            indexScale = Unsafe.ARRAY_BOOLEAN_INDEX_SCALE;
            break;
        case Byte:
            baseOffset = Unsafe.ARRAY_BYTE_BASE_OFFSET;
            indexScale = Unsafe.ARRAY_BYTE_INDEX_SCALE;
            break;
        case Short:
            baseOffset = Unsafe.ARRAY_SHORT_BASE_OFFSET;
            indexScale = Unsafe.ARRAY_SHORT_INDEX_SCALE;
            break;
        case Char:
            baseOffset = Unsafe.ARRAY_CHAR_BASE_OFFSET;
            indexScale = Unsafe.ARRAY_CHAR_INDEX_SCALE;
            break;
        case Int:
            baseOffset = Unsafe.ARRAY_INT_BASE_OFFSET;
            indexScale = Unsafe.ARRAY_INT_INDEX_SCALE;
            break;
        case Long:
            baseOffset = Unsafe.ARRAY_LONG_BASE_OFFSET;
            indexScale = Unsafe.ARRAY_LONG_INDEX_SCALE;
            break;
        case Float:
            baseOffset = Unsafe.ARRAY_FLOAT_BASE_OFFSET;
            indexScale = Unsafe.ARRAY_FLOAT_INDEX_SCALE;
            break;
        case Double:
            baseOffset = Unsafe.ARRAY_DOUBLE_BASE_OFFSET;
            indexScale = Unsafe.ARRAY_DOUBLE_INDEX_SCALE;
            break;
        case Object:
            baseOffset = Unsafe.ARRAY_OBJECT_BASE_OFFSET;
            indexScale = Unsafe.ARRAY_OBJECT_INDEX_SCALE;
            break;
        default:
            return -1;
    }
    long offset;
    if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN && componentType.isPrimitive()) {
        // On big endian, we do just get expect the type be right aligned in this memory slot
        offset = constantOffset - (componentType.getJavaKind().getByteCount() - Math.min(componentType.getJavaKind().getByteCount(), 4 + expectedEntryKind.getByteCount()));
    } else {
        offset = constantOffset;
    }
    long index = offset - baseOffset;
    if (index % indexScale != 0) {
        return -1;
    }
    long elementIndex = index / indexScale;
    if (elementIndex < 0 || elementIndex >= length) {
        return -1;
    }
    return (int) elementIndex;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:60,代码来源:VirtualArrayNode.java


注:本文中的sun.misc.Unsafe.ARRAY_BYTE_INDEX_SCALE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。