Skip to content

Commit ffb601f

Browse files
authored
Update (2023.12.08, 3rd)
32922: LA port of 8318609: Upcall stubs should be smaller 32921: LA port of 8318598: FFM stylistic cleanups
1 parent f3b1a7d commit ffb601f

File tree

5 files changed

+51
-50
lines changed

5 files changed

+51
-50
lines changed

src/hotspot/cpu/loongarch/stubGenerator_loongarch_64.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "oops/objArrayKlass.hpp"
3737
#include "oops/oop.inline.hpp"
3838
#include "prims/methodHandles.hpp"
39+
#include "prims/upcallLinker.hpp"
3940
#include "runtime/continuation.hpp"
4041
#include "runtime/continuationEntry.inline.hpp"
4142
#include "runtime/frame.inline.hpp"
@@ -4898,6 +4899,20 @@ class StubGenerator: public StubCodeGenerator {
48984899

48994900
#endif // INCLUDE_JFR
49004901

4902+
// exception handler for upcall stubs
4903+
address generate_upcall_stub_exception_handler() {
4904+
StubCodeMark mark(this, "StubRoutines", "upcall stub exception handler");
4905+
address start = __ pc();
4906+
4907+
// Native caller has no idea how to handle exceptions,
4908+
// so we just crash here. Up to callee to catch exceptions.
4909+
__ verify_oop(A0); // return a exception oop in a0
4910+
__ call(CAST_FROM_FN_PTR(address, UpcallLinker::handle_uncaught_exception), relocInfo::runtime_call_type);
4911+
__ should_not_reach_here();
4912+
4913+
return start;
4914+
}
4915+
49014916
#undef __
49024917
#define __ masm->
49034918

@@ -5635,6 +5650,8 @@ class StubGenerator: public StubCodeGenerator {
56355650
if (bs_nm != nullptr) {
56365651
StubRoutines::la::_method_entry_barrier = generate_method_entry_barrier();
56375652
}
5653+
5654+
StubRoutines::_upcall_stub_exception_handler = generate_upcall_stub_exception_handler();
56385655
}
56395656

56405657
void generate_compiler_stubs() {

src/hotspot/cpu/loongarch/upcallLinker_loongarch_64.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
217217

218218
__ block_comment("{ on_entry");
219219
__ lea(c_rarg0, Address(SP, frame_data_offset));
220+
__ li(c_rarg1, (intptr_t)receiver);
220221
__ call(CAST_FROM_FN_PTR(address, UpcallLinker::on_entry), relocInfo::runtime_call_type);
221222
__ move(TREG, V0);
222223
__ reinit_heapbase();
@@ -232,9 +233,7 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
232233
__ block_comment("} argument shuffle");
233234

234235
__ block_comment("{ receiver ");
235-
__ li(shuffle_reg, (intptr_t)receiver);
236-
__ resolve_jobject(shuffle_reg, SCR2, SCR1);
237-
__ move(j_rarg0, shuffle_reg);
236+
__ get_vm_result(j_rarg0, TREG);
238237
__ block_comment("} receiver ");
239238

240239
__ mov_metadata(Rmethod, entry);
@@ -304,18 +303,6 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
304303

305304
//////////////////////////////////////////////////////////////////////////////
306305

307-
__ block_comment("{ exception handler");
308-
309-
intptr_t exception_handler_offset = __ pc() - start;
310-
311-
// Native caller has no idea how to handle exceptions,
312-
// so we just crash here. Up to callee to catch exceptions.
313-
__ verify_oop(V0);
314-
__ call(CAST_FROM_FN_PTR(address, UpcallLinker::handle_uncaught_exception), relocInfo::runtime_call_type);
315-
__ should_not_reach_here();
316-
317-
__ block_comment("} exception handler");
318-
319306
_masm->flush();
320307

321308
#ifndef PRODUCT
@@ -331,7 +318,6 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
331318
UpcallStub* blob
332319
= UpcallStub::create(name,
333320
&buffer,
334-
exception_handler_offset,
335321
receiver,
336322
in_ByteSize(frame_data_offset));
337323

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import jdk.internal.foreign.abi.Architecture;
3131
import jdk.internal.foreign.abi.StubLocations;
3232
import jdk.internal.foreign.abi.VMStorage;
33-
import jdk.internal.foreign.abi.loongarch64.linux.TypeClass;
3433

3534
public final class LoongArch64Architecture implements Architecture {
3635
public static final Architecture INSTANCE = new LoongArch64Architecture();

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@
3838
import jdk.internal.foreign.abi.CallingSequenceBuilder;
3939
import jdk.internal.foreign.abi.DowncallLinker;
4040
import jdk.internal.foreign.abi.LinkerOptions;
41-
import jdk.internal.foreign.abi.UpcallLinker;
4241
import jdk.internal.foreign.abi.SharedUtils;
4342
import jdk.internal.foreign.abi.VMStorage;
4443
import jdk.internal.foreign.Utils;
4544

46-
import java.lang.foreign.ValueLayout;
4745
import java.lang.invoke.MethodHandle;
4846
import java.lang.invoke.MethodType;
4947
import java.util.List;
@@ -149,7 +147,7 @@ public StorageCalculator(boolean forArguments) {
149147
this.forArguments = forArguments;
150148
}
151149

152-
// Aggregates or scalars passed on the stack are aligned to the greater of
150+
// Aggregates or scalars passed on the stack are aligned to the greatest of
153151
// the type alignment and XLEN bits, but never more than the stack alignment.
154152
void alignStack(long alignment) {
155153
alignment = Utils.alignUp(Math.clamp(alignment, STACK_SLOT_SIZE, 16), STACK_SLOT_SIZE);
@@ -252,8 +250,8 @@ protected BindingCalculator(boolean forArguments) {
252250
Map.entry(STRUCT_REGISTER_XF, STRUCT_REGISTER_X));
253251
}
254252

255-
static class UnboxBindingCalculator extends BindingCalculator {
256-
boolean forArguments;
253+
static final class UnboxBindingCalculator extends BindingCalculator {
254+
final boolean forArguments;
257255

258256
UnboxBindingCalculator(boolean forArguments) {
259257
super(forArguments);

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

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public enum TypeClass {
7575
* Struct will be flattened while classifying. That is, struct{struct{int, double}} will be treated
7676
* same as struct{int, double} and struct{int[2]} will be treated same as struct{int, int}.
7777
* */
78-
private static record FieldCounter(long integerCnt, long floatCnt, long pointerCnt) {
78+
private record FieldCounter(long integerCnt, long floatCnt, long pointerCnt) {
7979
static final FieldCounter EMPTY = new FieldCounter(0, 0, 0);
8080
static final FieldCounter SINGLE_INTEGER = new FieldCounter(1, 0, 0);
8181
static final FieldCounter SINGLE_FLOAT = new FieldCounter(0, 1, 0);
@@ -125,39 +125,40 @@ FieldCounter add(FieldCounter other) {
125125
}
126126
}
127127

128-
public static record FlattenedFieldDesc(TypeClass typeClass, long offset, ValueLayout layout) {
129-
130-
}
128+
public record FlattenedFieldDesc(TypeClass typeClass, long offset, ValueLayout layout) { }
131129

132130
private static List<FlattenedFieldDesc> getFlattenedFieldsInner(long offset, MemoryLayout layout) {
133-
if (layout instanceof ValueLayout valueLayout) {
134-
TypeClass typeClass = classifyValueType(valueLayout);
135-
return List.of(switch (typeClass) {
136-
case INTEGER, FLOAT -> new FlattenedFieldDesc(typeClass, offset, valueLayout);
137-
default -> throw new IllegalStateException("Should not reach here.");
138-
});
139-
} else if (layout instanceof GroupLayout groupLayout) {
140-
List<FlattenedFieldDesc> fields = new ArrayList<>();
141-
for (MemoryLayout memberLayout : groupLayout.memberLayouts()) {
142-
if (memberLayout instanceof PaddingLayout) {
131+
return switch (layout) {
132+
case ValueLayout valueLayout -> {
133+
TypeClass typeClass = classifyValueType(valueLayout);
134+
yield List.of(switch (typeClass) {
135+
case INTEGER, FLOAT -> new FlattenedFieldDesc(typeClass, offset, valueLayout);
136+
default -> throw new IllegalStateException("Should not reach here.");
137+
});
138+
}
139+
case GroupLayout groupLayout -> {
140+
List<FlattenedFieldDesc> fields = new ArrayList<>();
141+
for (MemoryLayout memberLayout : groupLayout.memberLayouts()) {
142+
if (memberLayout instanceof PaddingLayout) {
143+
offset += memberLayout.byteSize();
144+
continue;
145+
}
146+
fields.addAll(getFlattenedFieldsInner(offset, memberLayout));
143147
offset += memberLayout.byteSize();
144-
continue;
145148
}
146-
fields.addAll(getFlattenedFieldsInner(offset, memberLayout));
147-
offset += memberLayout.byteSize();
149+
yield fields;
148150
}
149-
return fields;
150-
} else if (layout instanceof SequenceLayout sequenceLayout) {
151-
List<FlattenedFieldDesc> fields = new ArrayList<>();
152-
MemoryLayout elementLayout = sequenceLayout.elementLayout();
153-
for (long i = 0; i < sequenceLayout.elementCount(); i++) {
154-
fields.addAll(getFlattenedFieldsInner(offset, elementLayout));
155-
offset += elementLayout.byteSize();
151+
case SequenceLayout sequenceLayout -> {
152+
List<FlattenedFieldDesc> fields = new ArrayList<>();
153+
MemoryLayout elementLayout = sequenceLayout.elementLayout();
154+
for (long i = 0; i < sequenceLayout.elementCount(); i++) {
155+
fields.addAll(getFlattenedFieldsInner(offset, elementLayout));
156+
offset += elementLayout.byteSize();
157+
}
158+
yield fields;
156159
}
157-
return fields;
158-
} else {
159-
throw new IllegalStateException("Cannot get here: " + layout);
160-
}
160+
case null, default -> throw new IllegalStateException("Cannot get here: " + layout);
161+
};
161162
}
162163

163164
public static List<FlattenedFieldDesc> getFlattenedFields(GroupLayout layout) {

0 commit comments

Comments
 (0)