Skip to content
Permalink
Browse files
Some small naming changes to the byte order variables to improve clarity
rippled throughout.

It looks worse than it really is as there was no logic changes.
  • Loading branch information
leerho committed Jul 11, 2019
1 parent b564abd commit 9f6059713cafb5f6b68e7624abe5c7775ea4ed66
Showing 37 changed files with 238 additions and 188 deletions.
@@ -0,0 +1,23 @@
#!/bin/bash

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

PARAM=$1
cd ../
RESULT=$(mvn help:evaluate -Dexpression=$PARAM -q -DforceStdout)
echo $RESULT
@@ -54,7 +54,7 @@ final class BBNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | REGION | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new BBWritableBufferImpl(
unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
type, byteBuf, originMemory)
@@ -66,7 +66,7 @@ unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
@Override
BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | DUPLICATE | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new BBWritableBufferImpl(
unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(),
type, byteBuf, originMemory)
@@ -53,7 +53,7 @@ final class BBNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | REGION | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new BBWritableMemoryImpl(
unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
type, getByteBuffer())
@@ -65,7 +65,7 @@ unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
@Override
BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new BBWritableBufferImpl(
unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(),
type, byteBuf, this)
@@ -54,7 +54,7 @@ final class BBWritableBufferImpl extends WritableBufferImpl {
BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | REGION | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new BBWritableBufferImpl(
unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
type, byteBuf, originMemory)
@@ -66,7 +66,7 @@ unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
@Override
BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | DUPLICATE | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new BBWritableBufferImpl(
unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(),
type, byteBuf, originMemory)
@@ -53,7 +53,7 @@ final class BBWritableMemoryImpl extends WritableMemoryImpl {
BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | REGION | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new BBWritableMemoryImpl(
unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
type, getByteBuffer())
@@ -65,7 +65,7 @@ unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
@Override
BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new BBWritableBufferImpl(
unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(),
type, byteBuf, this)
@@ -36,6 +36,11 @@
*/
abstract class BaseState {

//Byte Order related
static final ByteOrder nativeCpuByteOrder = ByteOrder.nativeOrder();
static final ByteOrder nonNativeCpuByteOrder = (nativeCpuByteOrder == ByteOrder.LITTLE_ENDIAN)
? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;

//Monitoring
static final AtomicLong currentDirectMemoryAllocations_ = new AtomicLong();
static final AtomicLong currentDirectMemoryAllocated_ = new AtomicLong();
@@ -92,6 +97,49 @@ abstract class BaseState {
: unsafe.arrayBaseOffset(unsafeObj.getClass()));
}

//Byte Order Related

/**
* Returns the CPU Byte Order
* @return the CPU Byte Order
*/
public static final ByteOrder getCpuByteOrder() {
return nativeCpuByteOrder;
}

/**
* Gets the current Type ByteOrder.
* This may be different from the ByteOrder of the backing resource and of the CPU Byte Order.
* @return the current Type ByteOrder.
*/
public final ByteOrder getTypeByteOrder() {
return isNonNativeType() ? BaseState.nonNativeCpuByteOrder : BaseState.nativeCpuByteOrder;
}

/**
* Returns true if the given byteOrder is the same as the native CPU byte order.
* @param byteOrder the given byte order
* @return true if the given byteOrder is the same as the native CPU byte order.
*/
static boolean isNativeCpuByteOrder(final ByteOrder byteOrder) {
if (byteOrder == null) {
throw new IllegalArgumentException("ByteOrder parameter cannot be null.");
}
return (BaseState.nativeCpuByteOrder == byteOrder);
}

/**
* Returns true if the ByteOrder of the CPU is the same as the ByteOrder of the
* current Buffer or Memory and the same ByteOrder as the given byteOrder.
* @param byteOrder the given ByteOrder
* @return true if the ByteOrder of the CPU is the same as the ByteOrder of the
* current Buffer or Memory and the same ByteOrder as the given byteOrder.
*/
public final boolean isByteOrderCompatible(final ByteOrder byteOrder) {
final ByteOrder typeBO = getTypeByteOrder();
return ((typeBO == getCpuByteOrder()) && (typeBO == byteOrder));
}

/**
* Returns true if the given object is an instance of this class and has equal data contents.
* @param that the given object
@@ -132,15 +180,6 @@ public ByteBuffer getByteBuffer() {
return null;
}

/**
* Gets the current ByteOrder.
* This may be different from the ByteOrder of the backing resource.
* @return the current ByteOrder.
*/
public final ByteOrder getByteOrder() {
return isNonNativeType() ? Util.nonNativeOrder : Util.nativeOrder;
}

/**
* Gets the capacity of this object in bytes
* @return the capacity of this object in bytes
@@ -279,15 +318,6 @@ public final boolean isDirect() {
return getUnsafeObject() == null;
}

/**
* Returns true if the current byte order is native order.
* @return true if the current byte order is native order.
*/
public final boolean isNativeOrder() {
assertValid();
return Util.isNativeOrder(getByteOrder());
}

/**
* Returns true if this object or the backing resource is read-only.
* @return true if this object or the backing resource is read-only.
@@ -508,7 +538,8 @@ static final String toHex(final BaseState state, final String preamble, final lo
sb.append("MemReq, hashCode : ").append(memReqStr).append(LS);
sb.append("Valid : ").append(state.isValid()).append(LS);
sb.append("Read Only : ").append(state.isReadOnly()).append(LS);
sb.append("Byte Order : ").append(state.getByteOrder().toString()).append(LS);
sb.append("Type Byte Order : ").append(state.getTypeByteOrder().toString()).append(LS);
sb.append("CPU Byte Order : ").append(nativeCpuByteOrder.toString()).append(LS);
sb.append("JDK Major Version : ").append(UnsafeUtil.JDK).append(LS);
//Data detail
sb.append("Data, littleEndian : 0 1 2 3 4 5 6 7");
@@ -71,7 +71,7 @@ abstract class BaseWritableBufferImpl extends WritableBuffer {
//REGIONS
@Override
public Buffer region() {
return writableRegionImpl(getPosition(), getEnd() - getPosition(), true, getByteOrder());
return writableRegionImpl(getPosition(), getEnd() - getPosition(), true, getTypeByteOrder());
}

@Override
@@ -84,7 +84,7 @@ public Buffer region(final long offsetBytes, final long capacityBytes,

@Override
public WritableBuffer writableRegion() {
return writableRegionImpl(getPosition(), getEnd() - getPosition(), false, getByteOrder());
return writableRegionImpl(getPosition(), getEnd() - getPosition(), false, getTypeByteOrder());
}

@Override
@@ -114,7 +114,7 @@ abstract BaseWritableBufferImpl toWritableRegion(
//DUPLICATES
@Override
public Buffer duplicate() {
return writableDuplicateImpl(true, getByteOrder());
return writableDuplicateImpl(true, getTypeByteOrder());
}

@Override
@@ -124,7 +124,7 @@ public Buffer duplicate(final ByteOrder byteOrder) {

@Override
public WritableBuffer writableDuplicate() {
return writableDuplicateImpl(false, getByteOrder());
return writableDuplicateImpl(false, getTypeByteOrder());
}

@Override
@@ -72,7 +72,7 @@ static BaseWritableMemoryImpl wrapHeapArray(final Object arr, final long offsetB
final long lengthBytes, final boolean localReadOnly, final ByteOrder byteOrder) {
if (lengthBytes == 0) { return BaseWritableMemoryImpl.ZERO_SIZE_MEMORY; }
final int typeId = localReadOnly ? READONLY : 0;
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new HeapWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId)
: new HeapNonNativeWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId);
}
@@ -84,7 +84,7 @@ static BaseWritableMemoryImpl wrapByteBuffer(
throw new ReadOnlyException("ByteBuffer is Read Only");
}
final int typeId = (abb.resourceReadOnly || localReadOnly) ? READONLY : 0;
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new BBWritableMemoryImpl(abb.unsafeObj, abb.nativeBaseOffset,
abb.regionOffset, abb.capacityBytes, typeId, byteBuf)
: new BBNonNativeWritableMemoryImpl(abb.unsafeObj, abb.nativeBaseOffset,
@@ -102,7 +102,7 @@ static WritableMapHandle wrapMap(final File file, final long fileOffsetBytes,
throw new ReadOnlyException("File is Read Only");
}
final int typeId = (dirWMap.resourceReadOnly || localReadOnly) ? READONLY : 0;
final BaseWritableMemoryImpl wmem = Util.isNativeOrder(byteOrder)
final BaseWritableMemoryImpl wmem = isNativeCpuByteOrder(byteOrder)
? new MapWritableMemoryImpl(dirWMap.nativeBaseOffset, 0L, capacityBytes,
typeId, dirWMap.getValid())
: new MapNonNativeWritableMemoryImpl(dirWMap.nativeBaseOffset, 0L, capacityBytes,
@@ -119,7 +119,7 @@ static WritableDirectHandle wrapDirect(final long capacityBytes,
}
final AllocateDirect direct = new AllocateDirect(capacityBytes);
final int typeId = 0; //direct is never read-only on construction
final BaseWritableMemoryImpl wmem = Util.isNativeOrder(byteOrder)
final BaseWritableMemoryImpl wmem = isNativeCpuByteOrder(byteOrder)
? new DirectWritableMemoryImpl(direct.getNativeBaseOffset(), 0L, capacityBytes,
typeId, direct.getValid(), memReqSvr)
: new DirectNonNativeWritableMemoryImpl(direct.getNativeBaseOffset(), 0L, capacityBytes,
@@ -148,14 +148,14 @@ public ByteBuffer unsafeByteBufferView(final long offsetBytes, final int capacit
+ unsafeObj.getClass().getSimpleName()
+ " array, it could not be viewed as a ByteBuffer.");
}
result.order(getByteOrder());
result.order(getTypeByteOrder());
return result;
}

//REGIONS
@Override
public Memory region(final long offsetBytes, final long capacityBytes) {
return writableRegionImpl(offsetBytes, capacityBytes, true, getByteOrder());
return writableRegionImpl(offsetBytes, capacityBytes, true, getTypeByteOrder());
}

@Override
@@ -165,7 +165,7 @@ public Memory region(final long offsetBytes, final long capacityBytes, final Byt

@Override
public WritableMemory writableRegion(final long offsetBytes, final long capacityBytes) {
return writableRegionImpl(offsetBytes, capacityBytes, false, getByteOrder());
return writableRegionImpl(offsetBytes, capacityBytes, false, getTypeByteOrder());
}

@Override
@@ -191,7 +191,7 @@ abstract BaseWritableMemoryImpl toWritableRegion(
//AS BUFFER
@Override
public Buffer asBuffer() {
return asWritableBufferImpl(true, getByteOrder());
return asWritableBufferImpl(true, getTypeByteOrder());
}

@Override
@@ -201,7 +201,7 @@ public Buffer asBuffer(final ByteOrder byteOrder) {

@Override
public WritableBuffer asWritableBuffer() {
return asWritableBufferImpl(false, getByteOrder());
return asWritableBufferImpl(false, getTypeByteOrder());
}

@Override
@@ -54,7 +54,7 @@ final class DirectNonNativeWritableBufferImpl extends NonNativeWritableBufferImp
BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | REGION | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new DirectWritableBufferImpl(
nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
type, valid, memReqSvr, originMemory)
@@ -66,7 +66,7 @@ nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
@Override
BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | DUPLICATE | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new DirectWritableBufferImpl(
nativeBaseOffset, getRegionOffset(), getCapacity(),
type, valid, memReqSvr, originMemory)
@@ -52,7 +52,7 @@ final class DirectNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImp
BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | REGION | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new DirectWritableMemoryImpl(
nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
type, valid, memReqSvr)
@@ -64,7 +64,7 @@ nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
@Override
BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new DirectWritableBufferImpl(
nativeBaseOffset, getRegionOffset(), getCapacity(),
type, valid, memReqSvr, this)
@@ -54,7 +54,7 @@ final class DirectWritableBufferImpl extends WritableBufferImpl {
BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | REGION | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new DirectWritableBufferImpl(
nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
type, valid, memReqSvr, originMemory)
@@ -66,7 +66,7 @@ nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
@Override
BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | DUPLICATE | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new DirectWritableBufferImpl(
nativeBaseOffset, getRegionOffset(), getCapacity(),
type, valid, memReqSvr, originMemory)
@@ -52,7 +52,7 @@ final class DirectWritableMemoryImpl extends WritableMemoryImpl {
BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | REGION | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new DirectWritableMemoryImpl(
nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
type, valid, memReqSvr)
@@ -64,7 +64,7 @@ nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes,
@Override
BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
final int type = typeId | (readOnly ? READONLY : 0);
return Util.isNativeOrder(byteOrder)
return isNativeCpuByteOrder(byteOrder)
? new DirectWritableBufferImpl(
nativeBaseOffset, getRegionOffset(), getCapacity(),
type, valid, memReqSvr, this)

0 comments on commit 9f60597

Please sign in to comment.