Skip to content

Commit 45e0892

Browse files
authored
Update (2023.03.31)
30412: LA port of 8303684: Lift upcall sharing mechanism to AbstractLinker (mainline) 30411: LA port of 8304283: Modernize the switch statements in jdk.internal.foreign 30410: LA port of 8303154: Investigate and improve instruction cache flushing during compilation
1 parent 22c4d45 commit 45e0892

File tree

5 files changed

+36
-38
lines changed

5 files changed

+36
-38
lines changed

src/hotspot/cpu/loongarch/sharedRuntime_loongarch_64.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,6 @@ AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm
740740
__ block_comment("gen_c2i_adapter");
741741
gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
742742

743-
__ flush();
744743
return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, c2i_no_clinit_check_entry);
745744
}
746745

src/java.base/share/classes/jdk/internal/foreign/abi/loongarch64/LoongArch64Architecture.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ public boolean isStackType(int cls) {
4848

4949
@Override
5050
public int typeSize(int cls) {
51-
switch (cls) {
52-
case StorageType.INTEGER: return INTEGER_REG_SIZE;
53-
case StorageType.FLOAT: return FLOAT_REG_SIZE;
51+
return switch (cls) {
52+
case StorageType.INTEGER -> INTEGER_REG_SIZE;
53+
case StorageType.FLOAT -> FLOAT_REG_SIZE;
5454
// STACK is deliberately omitted
55-
}
56-
57-
throw new IllegalArgumentException("Invalid Storage Class: " + cls);
55+
default -> throw new IllegalArgumentException("Invalid Storage Class: " + cls);
56+
};
5857
}
5958

6059
public interface StorageType {

src/java.base/share/classes/jdk/internal/foreign/abi/loongarch64/linux/LinuxLoongArch64CallArranger.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.lang.foreign.MemoryLayout;
3232
import java.lang.foreign.MemorySegment;
3333
import jdk.internal.foreign.abi.ABIDescriptor;
34+
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
3435
import jdk.internal.foreign.abi.Binding;
3536
import jdk.internal.foreign.abi.CallingSequence;
3637
import jdk.internal.foreign.abi.CallingSequenceBuilder;
@@ -121,15 +122,11 @@ public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDe
121122
return handle;
122123
}
123124

124-
public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, SegmentScope scope) {
125-
125+
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc) {
126126
Bindings bindings = getBindings(mt, cDesc, true);
127-
128-
if (bindings.isInMemoryReturn) {
129-
target = SharedUtils.adaptUpcallForIMR(target, true /* drop return, since we don't have bindings for it */);
130-
}
131-
132-
return UpcallLinker.make(CLinux, target, bindings.callingSequence, scope);
127+
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
128+
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
129+
bindings.callingSequence);
133130
}
134131

135132
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {

src/java.base/share/classes/jdk/internal/foreign/abi/loongarch64/linux/LinuxLoongArch64Linker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ protected MethodHandle arrangeDowncall(MethodType inferredMethodType, FunctionDe
5757
}
5858

5959
@Override
60-
protected MemorySegment arrangeUpcall(MethodHandle target, MethodType targetType, FunctionDescriptor function, SegmentScope scope) {
61-
return LinuxLoongArch64CallArranger.arrangeUpcall(target, targetType, function, scope);
60+
protected UpcallStubFactory arrangeUpcall(MethodType targetType, FunctionDescriptor function) {
61+
return LinuxLoongArch64CallArranger.arrangeUpcall(targetType, function);
6262
}
6363

6464
public static VaList newVaList(Consumer<VaList.Builder> actions, SegmentScope scope) {

src/java.base/share/classes/jdk/internal/foreign/abi/loongarch64/linux/TypeClass.java

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,33 @@ private static record FieldCounter(long integerCnt, long floatCnt, long pointerC
8282
static final FieldCounter SINGLE_POINTER = new FieldCounter(0, 0, 1);
8383

8484
static FieldCounter flatten(MemoryLayout layout) {
85-
if (layout instanceof ValueLayout valueLayout) {
86-
return switch (classifyValueType(valueLayout)) {
87-
case INTEGER -> FieldCounter.SINGLE_INTEGER;
88-
case FLOAT -> FieldCounter.SINGLE_FLOAT;
89-
case POINTER -> FieldCounter.SINGLE_POINTER;
90-
default -> throw new IllegalStateException("Should not reach here.");
91-
};
92-
} else if (layout instanceof GroupLayout groupLayout) {
93-
FieldCounter currCounter = FieldCounter.EMPTY;
94-
for (MemoryLayout memberLayout : groupLayout.memberLayouts()) {
95-
if (memberLayout instanceof PaddingLayout) {
96-
continue;
85+
switch (layout) {
86+
case ValueLayout valueLayout -> {
87+
return switch (classifyValueType(valueLayout)) {
88+
case INTEGER -> FieldCounter.SINGLE_INTEGER;
89+
case FLOAT -> FieldCounter.SINGLE_FLOAT;
90+
case POINTER -> FieldCounter.SINGLE_POINTER;
91+
default -> throw new IllegalStateException("Should not reach here.");
92+
};
93+
}
94+
case GroupLayout groupLayout -> {
95+
FieldCounter currCounter = FieldCounter.EMPTY;
96+
for (MemoryLayout memberLayout : groupLayout.memberLayouts()) {
97+
if (memberLayout instanceof PaddingLayout) {
98+
continue;
99+
}
100+
currCounter = currCounter.add(flatten(memberLayout));
97101
}
98-
currCounter = currCounter.add(flatten(memberLayout));
102+
return currCounter;
99103
}
100-
return currCounter;
101-
} else if (layout instanceof SequenceLayout sequenceLayout) {
102-
long elementCount = sequenceLayout.elementCount();
103-
if (elementCount == 0) {
104-
return FieldCounter.EMPTY;
104+
case SequenceLayout sequenceLayout -> {
105+
long elementCount = sequenceLayout.elementCount();
106+
if (elementCount == 0) {
107+
return FieldCounter.EMPTY;
108+
}
109+
return flatten(sequenceLayout.elementLayout()).mul(elementCount);
105110
}
106-
return flatten(sequenceLayout.elementLayout()).mul(elementCount);
107-
} else {
108-
throw new IllegalStateException("Cannot get here: " + layout);
111+
default -> throw new IllegalStateException("Cannot get here: " + layout);
109112
}
110113
}
111114

0 commit comments

Comments
 (0)