Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8304283: Modernize the switch statements in jdk.internal.foreign #13047

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -28,6 +28,16 @@
import jdk.internal.foreign.MemorySessionImpl;
import jdk.internal.foreign.NativeMemorySegmentImpl;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.Binding.Allocate;
import jdk.internal.foreign.abi.Binding.BoxAddress;
import jdk.internal.foreign.abi.Binding.BufferLoad;
import jdk.internal.foreign.abi.Binding.BufferStore;
import jdk.internal.foreign.abi.Binding.Cast;
import jdk.internal.foreign.abi.Binding.Copy;
import jdk.internal.foreign.abi.Binding.Dup;
import jdk.internal.foreign.abi.Binding.UnboxAddress;
import jdk.internal.foreign.abi.Binding.VMLoad;
import jdk.internal.foreign.abi.Binding.VMStore;
import jdk.internal.misc.VM;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter;
@@ -437,9 +447,9 @@ private void specialize() {

private boolean needsSession() {
return callingSequence.argumentBindings()
.filter(Binding.BoxAddress.class::isInstance)
.map(Binding.BoxAddress.class::cast)
.anyMatch(Binding.BoxAddress::needsScope);
.filter(BoxAddress.class::isInstance)
.map(BoxAddress.class::cast)
.anyMatch(BoxAddress::needsScope);
}

private boolean shouldAcquire(int paramIndex) {
@@ -468,16 +478,16 @@ private void emitCleanup() {
private void doBindings(List<Binding> bindings) {
for (Binding binding : bindings) {
switch (binding) {
case Binding.VMStore vmStore -> emitVMStore(vmStore);
case Binding.VMLoad vmLoad -> emitVMLoad(vmLoad);
case Binding.BufferStore bufferStore -> emitBufferStore(bufferStore);
case Binding.BufferLoad bufferLoad -> emitBufferLoad(bufferLoad);
case Binding.Copy copy -> emitCopyBuffer(copy);
case Binding.Allocate allocate -> emitAllocBuffer(allocate);
case Binding.BoxAddress boxAddress -> emitBoxAddress(boxAddress);
case Binding.UnboxAddress unused -> emitUnboxAddress();
case Binding.Dup unused -> emitDupBinding();
case Binding.Cast cast -> emitCast(cast);
case VMStore vmStore -> emitVMStore(vmStore);
case VMLoad vmLoad -> emitVMLoad(vmLoad);
case BufferStore bufferStore -> emitBufferStore(bufferStore);
case BufferLoad bufferLoad -> emitBufferLoad(bufferLoad);
case Copy copy -> emitCopyBuffer(copy);
case Allocate allocate -> emitAllocBuffer(allocate);
case BoxAddress boxAddress -> emitBoxAddress(boxAddress);
case UnboxAddress unused -> emitUnboxAddress();
case Dup unused -> emitDupBinding();
case Cast cast -> emitCast(cast);
}
}
}
@@ -579,7 +589,7 @@ private void emitCloseContext() {
emitInvokeVirtual(Binding.Context.class, "close", CLOSE_DESC);
}

private void emitBoxAddress(Binding.BoxAddress boxAddress) {
private void emitBoxAddress(BoxAddress boxAddress) {
popType(long.class);
emitConst(boxAddress.size());
if (needsSession()) {
@@ -591,7 +601,7 @@ private void emitBoxAddress(Binding.BoxAddress boxAddress) {
pushType(MemorySegment.class);
}

private void emitAllocBuffer(Binding.Allocate binding) {
private void emitAllocBuffer(Allocate binding) {
if (callingSequence.forDowncall()) {
assert returnAllocatorIdx != -1;
emitLoad(Object.class, returnAllocatorIdx);
@@ -602,7 +612,7 @@ private void emitAllocBuffer(Binding.Allocate binding) {
pushType(MemorySegment.class);
}

private void emitBufferStore(Binding.BufferStore bufferStore) {
private void emitBufferStore(BufferStore bufferStore) {
Class<?> storeType = bufferStore.type();
long offset = bufferStore.offset();
int byteWidth = bufferStore.byteWidth();
@@ -684,7 +694,7 @@ private void emitBufferStore(Binding.BufferStore bufferStore) {
}

// VM_STORE and VM_LOAD are emulated, which is different for down/upcalls
private void emitVMStore(Binding.VMStore vmStore) {
private void emitVMStore(VMStore vmStore) {
Class<?> storeType = vmStore.type();
popType(storeType);

@@ -711,7 +721,7 @@ private void emitVMStore(Binding.VMStore vmStore) {
}
}

private void emitVMLoad(Binding.VMLoad vmLoad) {
private void emitVMLoad(VMLoad vmLoad) {
Class<?> loadType = vmLoad.type();

if (callingSequence.forDowncall()) {
@@ -740,7 +750,7 @@ private void emitDupBinding() {
pushType(dupType);
}

private void emitCast(Binding.Cast cast) {
private void emitCast(Cast cast) {
Class<?> fromType = cast.fromType();
Class<?> toType = cast.toType();

@@ -773,7 +783,7 @@ private void emitUnboxAddress() {
pushType(long.class);
}

private void emitBufferLoad(Binding.BufferLoad bufferLoad) {
private void emitBufferLoad(BufferLoad bufferLoad) {
Class<?> loadType = bufferLoad.type();
long offset = bufferLoad.offset();
int byteWidth = bufferLoad.byteWidth();
@@ -855,7 +865,7 @@ private void emitBufferLoad(Binding.BufferLoad bufferLoad) {
pushType(loadType);
}

private void emitCopyBuffer(Binding.Copy copy) {
private void emitCopyBuffer(Copy copy) {
long size = copy.size();
long alignment = copy.alignment();

Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ public boolean isStackType(int cls) {
public int typeSize(int cls) {
return switch (cls) {
case StorageType.INTEGER -> INTEGER_REG_SIZE;
case StorageType.FLOAT -> FLOAT_REG_SIZE;
case StorageType.FLOAT -> FLOAT_REG_SIZE;
// STACK is deliberately omitted
default -> throw new IllegalArgumentException("Invalid Storage Class: " + cls);
};
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ static FieldCounter flatten(MemoryLayout layout) {
case ValueLayout valueLayout -> {
return switch (classifyValueType(valueLayout)) {
case INTEGER -> FieldCounter.SINGLE_INTEGER;
case FLOAT -> FieldCounter.SINGLE_FLOAT;
case FLOAT -> FieldCounter.SINGLE_FLOAT;
case POINTER -> FieldCounter.SINGLE_POINTER;
default -> throw new IllegalStateException("Should not reach here.");
};
Original file line number Diff line number Diff line change
@@ -57,8 +57,8 @@ public boolean isStackType(int cls) {
public int typeSize(int cls) {
return switch (cls) {
case StorageType.INTEGER -> INTEGER_REG_SIZE;
case StorageType.VECTOR -> VECTOR_REG_SIZE;
case StorageType.X87 -> X87_REG_SIZE;
case StorageType.VECTOR -> VECTOR_REG_SIZE;
case StorageType.X87 -> X87_REG_SIZE;
// STACK is deliberately omitted
default -> throw new IllegalArgumentException("Invalid Storage Class: " +cls);
};