113 // Layout path projections
114
115 public long offset() {
116 return offset;
117 }
118
119 public VarHandle dereferenceHandle(Class<?> carrier) {
120 if (!(layout instanceof ValueLayout)) {
121 throw badLayoutPath("layout path does not select a value layout");
122 }
123
124 if (!carrier.isPrimitive() || carrier == void.class || carrier == boolean.class // illegal carrier?
125 || Wrapper.forPrimitiveType(carrier).bitWidth() != layout.bitSize()) { // carrier has the right size?
126 throw new IllegalArgumentException("Invalid carrier: " + carrier + ", for layout " + layout);
127 }
128
129 checkAlignment(this);
130
131 return JLI.memoryAddressViewVarHandle(
132 carrier,
133 layout.byteAlignment(),
134 ((ValueLayout) layout).order(),
135 Utils.bitsToBytesOrThrow(offset, IllegalStateException::new),
136 LongStream.of(scales).map(s -> Utils.bitsToBytesOrThrow(s, IllegalStateException::new)).toArray());
137 }
138
139 // Layout path construction
140
141 public static LayoutPath rootPath(MemoryLayout layout) {
142 return new LayoutPath(layout, 0L, EMPTY_SCALES, null);
143 }
144
145 private static LayoutPath nestedPath(MemoryLayout layout, long offset, long[] scales, LayoutPath encl) {
146 return new LayoutPath(layout, offset, scales, encl);
147 }
148
149 // Helper methods
150
151 private void check(Class<?> layoutClass, String msg) {
152 if (!layoutClass.isAssignableFrom(layout.getClass())) {
153 throw badLayoutPath(msg);
|
113 // Layout path projections
114
115 public long offset() {
116 return offset;
117 }
118
119 public VarHandle dereferenceHandle(Class<?> carrier) {
120 if (!(layout instanceof ValueLayout)) {
121 throw badLayoutPath("layout path does not select a value layout");
122 }
123
124 if (!carrier.isPrimitive() || carrier == void.class || carrier == boolean.class // illegal carrier?
125 || Wrapper.forPrimitiveType(carrier).bitWidth() != layout.bitSize()) { // carrier has the right size?
126 throw new IllegalArgumentException("Invalid carrier: " + carrier + ", for layout " + layout);
127 }
128
129 checkAlignment(this);
130
131 return JLI.memoryAddressViewVarHandle(
132 carrier,
133 layout.byteAlignment() - 1, //mask
134 ((ValueLayout) layout).order(),
135 Utils.bitsToBytesOrThrow(offset, IllegalStateException::new),
136 LongStream.of(scales).map(s -> Utils.bitsToBytesOrThrow(s, IllegalStateException::new)).toArray());
137 }
138
139 // Layout path construction
140
141 public static LayoutPath rootPath(MemoryLayout layout) {
142 return new LayoutPath(layout, 0L, EMPTY_SCALES, null);
143 }
144
145 private static LayoutPath nestedPath(MemoryLayout layout, long offset, long[] scales, LayoutPath encl) {
146 return new LayoutPath(layout, offset, scales, encl);
147 }
148
149 // Helper methods
150
151 private void check(Class<?> layoutClass, String msg) {
152 if (!layoutClass.isAssignableFrom(layout.getClass())) {
153 throw badLayoutPath(msg);
|