< prev index next > src/java.base/share/classes/jdk/internal/foreign/layout/ValueLayouts.java
Print this page
import jdk.internal.misc.Unsafe;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.Stable;
- import sun.invoke.util.Wrapper;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
- import java.lang.foreign.AddressLayout;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
- import java.util.ArrayList;
- import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* A value layout. A value layout is used to model the memory layout associated with values of basic data types, such as <em>integral</em> types
import jdk.internal.misc.Unsafe;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.Stable;
+ import java.lang.foreign.AddressLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;
import java.util.Objects;
import java.util.Optional;
/**
* A value layout. A value layout is used to model the memory layout associated with values of basic data types, such as <em>integral</em> types
super.equals(other) &&
carrier.equals(otherValue.carrier) &&
order.equals(otherValue.order);
}
- public final VarHandle arrayElementVarHandle(int... shape) {
- Objects.requireNonNull(shape);
- if (!Utils.isElementAligned((ValueLayout) this)) {
- throw new UnsupportedOperationException("Layout alignment greater than its size");
- }
- MemoryLayout layout = self();
- List<MemoryLayout.PathElement> path = new ArrayList<>();
- for (int i = shape.length; i > 0; i--) {
- int size = shape[i - 1];
- if (size < 0) throw new IllegalArgumentException("Invalid shape size: " + size);
- layout = MemoryLayout.sequenceLayout(size, layout);
- path.add(MemoryLayout.PathElement.sequenceElement());
- }
- layout = MemoryLayout.sequenceLayout(layout);
- path.add(MemoryLayout.PathElement.sequenceElement());
- return layout.varHandle(path.toArray(new MemoryLayout.PathElement[0]));
- }
-
/**
* {@return the carrier associated with this value layout}
*/
public final Class<?> carrier() {
return carrier;
|| carrier == double.class
|| carrier == MemorySegment.class;
}
@ForceInline
! public final VarHandle accessHandle() {
if (handle == null) {
// this store to stable field is safe, because return value of 'makeMemoryAccessVarHandle' has stable identity
handle = Utils.makeSegmentViewVarHandle(self());
}
return handle;
|| carrier == double.class
|| carrier == MemorySegment.class;
}
@ForceInline
! public final VarHandle varHandle() {
if (handle == null) {
// this store to stable field is safe, because return value of 'makeMemoryAccessVarHandle' has stable identity
handle = Utils.makeSegmentViewVarHandle(self());
}
return handle;
* <li>{@link ValueLayout.OfChar}, for {@code char.class}</li>
* <li>{@link ValueLayout.OfInt}, for {@code int.class}</li>
* <li>{@link ValueLayout.OfFloat}, for {@code float.class}</li>
* <li>{@link ValueLayout.OfLong}, for {@code long.class}</li>
* <li>{@link ValueLayout.OfDouble}, for {@code double.class}</li>
! * <li>{@link ValueLayout.OfAddress}, for {@code MemorySegment.class}</li>
* </ul>
* @param carrier the value layout carrier.
* @param order the value layout's byte order.
* @return a value layout with the given Java carrier and byte-order.
* @throws IllegalArgumentException if the carrier type is not supported.
* <li>{@link ValueLayout.OfChar}, for {@code char.class}</li>
* <li>{@link ValueLayout.OfInt}, for {@code int.class}</li>
* <li>{@link ValueLayout.OfFloat}, for {@code float.class}</li>
* <li>{@link ValueLayout.OfLong}, for {@code long.class}</li>
* <li>{@link ValueLayout.OfDouble}, for {@code double.class}</li>
! * <li>{@link AddressLayout}, for {@code MemorySegment.class}</li>
* </ul>
* @param carrier the value layout carrier.
* @param order the value layout's byte order.
* @return a value layout with the given Java carrier and byte-order.
* @throws IllegalArgumentException if the carrier type is not supported.
< prev index next >