Skip to content

Commit 52ccacb

Browse files
committedMar 29, 2022
8283863: Drop support for Constable in MemoryLayout and FunctionDescriptor
Reviewed-by: jvernee
1 parent 32b76e9 commit 52ccacb

File tree

9 files changed

+5
-374
lines changed

9 files changed

+5
-374
lines changed
 

‎src/java.base/share/classes/java/lang/foreign/AbstractLayout.java

-71
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,11 @@
2525
*/
2626
package java.lang.foreign;
2727

28-
import java.lang.constant.ClassDesc;
29-
import java.lang.constant.ConstantDesc;
30-
import java.lang.constant.DirectMethodHandleDesc;
31-
import java.lang.constant.DynamicConstantDesc;
32-
import java.lang.constant.MethodHandleDesc;
33-
import java.lang.constant.MethodTypeDesc;
34-
import java.nio.ByteOrder;
3528
import java.util.Objects;
3629
import java.util.Optional;
3730
import jdk.internal.foreign.Utils;
3831
import jdk.internal.vm.annotation.Stable;
3932

40-
import static java.lang.constant.ConstantDescs.BSM_GET_STATIC_FINAL;
41-
import static java.lang.constant.ConstantDescs.BSM_INVOKE;
42-
import static java.lang.constant.ConstantDescs.CD_Class;
43-
import static java.lang.constant.ConstantDescs.CD_String;
44-
import static java.lang.constant.ConstantDescs.CD_long;
45-
4633
abstract non-sealed class AbstractLayout implements MemoryLayout {
4734

4835
private final long size;
@@ -122,19 +109,6 @@ String decorateLayoutString(String s) {
122109
return s;
123110
}
124111

125-
<T> DynamicConstantDesc<T> decorateLayoutConstant(DynamicConstantDesc<T> desc) {
126-
if (!hasNaturalAlignment()) {
127-
desc = DynamicConstantDesc.ofNamed(BSM_INVOKE, "withBitAlignment", desc.constantType(), MH_WITH_BIT_ALIGNMENT,
128-
desc, bitAlignment());
129-
}
130-
if (name().isPresent()) {
131-
desc = DynamicConstantDesc.ofNamed(BSM_INVOKE, "withName", desc.constantType(), MH_WITH_NAME,
132-
desc, name().get().describeConstable().orElseThrow());
133-
}
134-
135-
return desc;
136-
}
137-
138112
boolean hasNaturalAlignment() {
139113
return size == alignment;
140114
}
@@ -186,49 +160,4 @@ public boolean equals(Object that) {
186160
* {@return the string representation of this layout}
187161
*/
188162
public abstract String toString();
189-
190-
/*** Helper constants for implementing Layout::describeConstable ***/
191-
192-
static final ClassDesc CD_MEMORY_LAYOUT = MemoryLayout.class.describeConstable().get();
193-
194-
static final ClassDesc CD_VALUE_LAYOUT = ValueLayout.class.describeConstable().get();
195-
196-
static final ClassDesc CD_SEQUENCE_LAYOUT = SequenceLayout.class.describeConstable().get();
197-
198-
static final ClassDesc CD_GROUP_LAYOUT = GroupLayout.class.describeConstable().get();
199-
200-
static final ClassDesc CD_BYTEORDER = ByteOrder.class.describeConstable().get();
201-
202-
static final ClassDesc CD_FUNCTION_DESC = FunctionDescriptor.class.describeConstable().get();
203-
204-
static final ConstantDesc BIG_ENDIAN = DynamicConstantDesc.ofNamed(BSM_GET_STATIC_FINAL, "BIG_ENDIAN", CD_BYTEORDER, CD_BYTEORDER);
205-
206-
static final ConstantDesc LITTLE_ENDIAN = DynamicConstantDesc.ofNamed(BSM_GET_STATIC_FINAL, "LITTLE_ENDIAN", CD_BYTEORDER, CD_BYTEORDER);
207-
208-
static final MethodHandleDesc MH_PADDING = MethodHandleDesc.ofMethod(DirectMethodHandleDesc.Kind.INTERFACE_STATIC, CD_MEMORY_LAYOUT, "paddingLayout",
209-
MethodTypeDesc.of(CD_MEMORY_LAYOUT, CD_long));
210-
211-
static final MethodHandleDesc MH_SIZED_SEQUENCE = MethodHandleDesc.ofMethod(DirectMethodHandleDesc.Kind.INTERFACE_STATIC, CD_MEMORY_LAYOUT, "sequenceLayout",
212-
MethodTypeDesc.of(CD_SEQUENCE_LAYOUT, CD_long, CD_MEMORY_LAYOUT));
213-
214-
static final MethodHandleDesc MH_STRUCT = MethodHandleDesc.ofMethod(DirectMethodHandleDesc.Kind.INTERFACE_STATIC, CD_MEMORY_LAYOUT, "structLayout",
215-
MethodTypeDesc.of(CD_GROUP_LAYOUT, CD_MEMORY_LAYOUT.arrayType()));
216-
217-
static final MethodHandleDesc MH_UNION = MethodHandleDesc.ofMethod(DirectMethodHandleDesc.Kind.INTERFACE_STATIC, CD_MEMORY_LAYOUT, "unionLayout",
218-
MethodTypeDesc.of(CD_GROUP_LAYOUT, CD_MEMORY_LAYOUT.arrayType()));
219-
220-
static final MethodHandleDesc MH_VALUE = MethodHandleDesc.ofMethod(DirectMethodHandleDesc.Kind.INTERFACE_STATIC, CD_MEMORY_LAYOUT, "valueLayout",
221-
MethodTypeDesc.of(CD_VALUE_LAYOUT, CD_Class, CD_BYTEORDER));
222-
223-
static final MethodHandleDesc MH_VOID_FUNCTION = MethodHandleDesc.ofMethod(DirectMethodHandleDesc.Kind.STATIC, CD_FUNCTION_DESC, "ofVoid",
224-
MethodTypeDesc.of(CD_FUNCTION_DESC, CD_MEMORY_LAYOUT.arrayType()));
225-
226-
static final MethodHandleDesc MH_FUNCTION = MethodHandleDesc.ofMethod(DirectMethodHandleDesc.Kind.STATIC, CD_FUNCTION_DESC, "of",
227-
MethodTypeDesc.of(CD_FUNCTION_DESC, CD_MEMORY_LAYOUT, CD_MEMORY_LAYOUT.arrayType()));
228-
229-
static final MethodHandleDesc MH_WITH_BIT_ALIGNMENT = MethodHandleDesc.ofMethod(DirectMethodHandleDesc.Kind.INTERFACE_VIRTUAL, CD_MEMORY_LAYOUT, "withBitAlignment",
230-
MethodTypeDesc.of(CD_MEMORY_LAYOUT, CD_long));
231-
232-
static final MethodHandleDesc MH_WITH_NAME = MethodHandleDesc.ofMethod(DirectMethodHandleDesc.Kind.INTERFACE_VIRTUAL, CD_MEMORY_LAYOUT, "withName",
233-
MethodTypeDesc.of(CD_MEMORY_LAYOUT, CD_String));
234163
}

‎src/java.base/share/classes/java/lang/foreign/FunctionDescriptor.java

+1-27
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
*/
2525
package java.lang.foreign;
2626

27-
import java.lang.constant.Constable;
28-
import java.lang.constant.ConstantDesc;
29-
import java.lang.constant.ConstantDescs;
30-
import java.lang.constant.DynamicConstantDesc;
3127
import java.lang.invoke.MethodHandle;
3228
import java.util.ArrayList;
3329
import java.util.Arrays;
@@ -52,7 +48,7 @@
5248
* @since 19
5349
*/
5450
@PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
55-
public sealed class FunctionDescriptor implements Constable permits FunctionDescriptor.VariadicFunction {
51+
public sealed class FunctionDescriptor permits FunctionDescriptor.VariadicFunction {
5652

5753
private final MemoryLayout resLayout;
5854
private final List<MemoryLayout> argLayouts;
@@ -213,23 +209,6 @@ public int hashCode() {
213209
return Objects.hash(argLayouts, resLayout, firstVariadicArgumentIndex());
214210
}
215211

216-
/**
217-
* {@return the nominal descriptor for this function descriptor, if one can be constructed}
218-
*/
219-
@Override
220-
public Optional<DynamicConstantDesc<FunctionDescriptor>> describeConstable() {
221-
List<ConstantDesc> constants = new ArrayList<>();
222-
constants.add(resLayout == null ? AbstractLayout.MH_VOID_FUNCTION : AbstractLayout.MH_FUNCTION);
223-
if (resLayout != null) {
224-
constants.add(resLayout.describeConstable().get());
225-
}
226-
for (MemoryLayout argLayout : argLayouts) {
227-
constants.add(argLayout.describeConstable().get());
228-
}
229-
return Optional.of(DynamicConstantDesc.ofNamed(
230-
ConstantDescs.BSM_INVOKE, "function", AbstractLayout.CD_FUNCTION_DESC, constants.toArray(new ConstantDesc[0])));
231-
}
232-
233212
static final class VariadicFunction extends FunctionDescriptor {
234213

235214
private final int firstVariadicIndex;
@@ -264,10 +243,5 @@ public FunctionDescriptor changeReturnLayout(MemoryLayout newReturn) {
264243
public FunctionDescriptor dropReturnLayout() {
265244
throw new UnsupportedOperationException();
266245
}
267-
268-
@Override
269-
public Optional<DynamicConstantDesc<FunctionDescriptor>> describeConstable() {
270-
return Optional.empty();
271-
}
272246
}
273247
}

‎src/java.base/share/classes/java/lang/foreign/GroupLayout.java

+3-21
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
*/
2626
package java.lang.foreign;
2727

28-
import java.lang.constant.ConstantDesc;
29-
import java.lang.constant.ConstantDescs;
30-
import java.lang.constant.DynamicConstantDesc;
31-
import java.lang.constant.MethodHandleDesc;
3228
import java.util.Collections;
3329
import java.util.List;
3430
import java.util.Objects;
@@ -58,19 +54,17 @@ enum Kind {
5854
/**
5955
* A 'struct' kind.
6056
*/
61-
STRUCT("", MH_STRUCT, Long::sum),
57+
STRUCT("", Long::sum),
6258
/**
6359
* A 'union' kind.
6460
*/
65-
UNION("|", MH_UNION, Math::max);
61+
UNION("|", Math::max);
6662

6763
final String delimTag;
68-
final MethodHandleDesc mhDesc;
6964
final LongBinaryOperator sizeOp;
7065

71-
Kind(String delimTag, MethodHandleDesc mhDesc, LongBinaryOperator sizeOp) {
66+
Kind(String delimTag, LongBinaryOperator sizeOp) {
7267
this.delimTag = delimTag;
73-
this.mhDesc = mhDesc;
7468
this.sizeOp = sizeOp;
7569
}
7670

@@ -173,18 +167,6 @@ boolean hasNaturalAlignment() {
173167
return alignment == kind.alignof(elements);
174168
}
175169

176-
@Override
177-
public Optional<DynamicConstantDesc<GroupLayout>> describeConstable() {
178-
ConstantDesc[] constants = new ConstantDesc[1 + elements.size()];
179-
constants[0] = kind.mhDesc;
180-
for (int i = 0 ; i < elements.size() ; i++) {
181-
constants[i + 1] = elements.get(i).describeConstable().get();
182-
}
183-
return Optional.of(decorateLayoutConstant(DynamicConstantDesc.ofNamed(
184-
ConstantDescs.BSM_INVOKE, kind.name().toLowerCase(),
185-
CD_GROUP_LAYOUT, constants)));
186-
}
187-
188170
//hack: the declarations below are to make javadoc happy; we could have used generics in AbstractLayout
189171
//but that causes issues with javadoc, see JDK-8224052
190172

‎src/java.base/share/classes/java/lang/foreign/MemoryLayout.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
*/
2626
package java.lang.foreign;
2727

28-
import java.lang.constant.Constable;
29-
import java.lang.constant.DynamicConstantDesc;
3028
import java.lang.invoke.MethodHandle;
3129
import java.lang.invoke.MethodHandles;
3230
import java.lang.invoke.VarHandle;
@@ -36,7 +34,6 @@
3634
import java.util.Optional;
3735
import java.util.Set;
3836
import java.util.function.Function;
39-
import java.util.function.UnaryOperator;
4037
import java.util.stream.Collectors;
4138
import java.util.stream.Stream;
4239
import jdk.internal.foreign.LayoutPath;
@@ -167,13 +164,7 @@
167164
* @since 19
168165
*/
169166
@PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
170-
public sealed interface MemoryLayout extends Constable permits AbstractLayout, SequenceLayout, GroupLayout, PaddingLayout, ValueLayout {
171-
172-
/**
173-
* {@return the nominal descriptor for this layout, if one can be constructed}
174-
*/
175-
@Override
176-
Optional<? extends DynamicConstantDesc<? extends MemoryLayout>> describeConstable();
167+
public sealed interface MemoryLayout permits AbstractLayout, SequenceLayout, GroupLayout, PaddingLayout, ValueLayout {
177168

178169
/**
179170
* {@return the layout size, in bits}

‎src/java.base/share/classes/java/lang/foreign/PaddingLayout.java

-8
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
*/
2626
package java.lang.foreign;
2727

28-
import java.lang.constant.ConstantDescs;
29-
import java.lang.constant.DynamicConstantDesc;
3028
import java.util.Objects;
3129
import java.util.Optional;
3230

@@ -81,12 +79,6 @@ public boolean hasNaturalAlignment() {
8179
return true;
8280
}
8381

84-
@Override
85-
public Optional<DynamicConstantDesc<MemoryLayout>> describeConstable() {
86-
return Optional.of(decorateLayoutConstant(DynamicConstantDesc.ofNamed(ConstantDescs.BSM_INVOKE, "padding",
87-
CD_MEMORY_LAYOUT, MH_PADDING, bitSize())));
88-
}
89-
9082
//hack: the declarations below are to make javadoc happy; we could have used generics in AbstractLayout
9183
//but that causes issues with javadoc, see JDK-8224052
9284

‎src/java.base/share/classes/java/lang/foreign/SequenceLayout.java

-9
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
*/
2626
package java.lang.foreign;
2727

28-
import java.lang.constant.ConstantDescs;
29-
import java.lang.constant.DynamicConstantDesc;
3028
import java.util.Objects;
3129
import java.util.Optional;
3230

@@ -237,13 +235,6 @@ boolean hasNaturalAlignment() {
237235
return alignment == elementLayout.bitAlignment();
238236
}
239237

240-
@Override
241-
public Optional<DynamicConstantDesc<SequenceLayout>> describeConstable() {
242-
return Optional.of(decorateLayoutConstant(
243-
DynamicConstantDesc.ofNamed(ConstantDescs.BSM_INVOKE, "value",
244-
CD_SEQUENCE_LAYOUT, MH_SIZED_SEQUENCE, elemCount, elementLayout.describeConstable().get())));
245-
}
246-
247238
//hack: the declarations below are to make javadoc happy; we could have used generics in AbstractLayout
248239
//but that causes issues with javadoc, see JDK-8224052
249240

‎src/java.base/share/classes/java/lang/foreign/ValueLayout.java

-8
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
*/
2626
package java.lang.foreign;
2727

28-
import java.lang.constant.ConstantDescs;
29-
import java.lang.constant.DynamicConstantDesc;
3028
import java.lang.invoke.VarHandle;
3129
import java.nio.ByteOrder;
3230
import java.util.Objects;
@@ -135,12 +133,6 @@ ValueLayout dup(long alignment, Optional<String> name) {
135133
return new ValueLayout(carrier, order, bitSize(), alignment, name());
136134
}
137135

138-
@Override
139-
public Optional<DynamicConstantDesc<ValueLayout>> describeConstable() {
140-
return Optional.of(decorateLayoutConstant(DynamicConstantDesc.ofNamed(ConstantDescs.BSM_INVOKE, "value",
141-
CD_VALUE_LAYOUT, MH_VALUE, carrier().describeConstable().get(), order == ByteOrder.BIG_ENDIAN ? BIG_ENDIAN : LITTLE_ENDIAN)));
142-
}
143-
144136
//hack: the declarations below are to make javadoc happy; we could have used generics in AbstractLayout
145137
//but that causes issues with javadoc, see JDK-8224052
146138

‎test/jdk/java/foreign/TestCondy.java

-94
This file was deleted.

‎test/jdk/java/foreign/TestLayoutConstants.java

-126
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.