diff --git a/src/hotspot/cpu/loongarch/c1_LIRAssembler_loongarch_64.cpp b/src/hotspot/cpu/loongarch/c1_LIRAssembler_loongarch_64.cpp index 29805acc3b678..6cf79726fd66d 100644 --- a/src/hotspot/cpu/loongarch/c1_LIRAssembler_loongarch_64.cpp +++ b/src/hotspot/cpu/loongarch/c1_LIRAssembler_loongarch_64.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2021, 2024, Loongson Technology. All rights reserved. + * Copyright (c) 2021, 2025, Loongson Technology. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1162,6 +1162,7 @@ void LIR_Assembler::emit_opConvert(LIR_OpConvert* op) { void LIR_Assembler::emit_alloc_obj(LIR_OpAllocObj* op) { if (op->init_check()) { __ ld_bu(SCR1, Address(op->klass()->as_register(), InstanceKlass::init_state_offset())); + __ membar(MacroAssembler::Membar_mask_bits(MacroAssembler::LoadLoad | MacroAssembler::LoadStore)); __ li(SCR2, InstanceKlass::fully_initialized); add_debug_info_for_null_check_here(op->stub()->info()); __ bne_far(SCR1, SCR2, *op->stub()->entry()); diff --git a/src/hotspot/cpu/loongarch/c2_CodeStubs_loongarch.cpp b/src/hotspot/cpu/loongarch/c2_CodeStubs_loongarch.cpp index 37b74d4ac1618..bce8b1044864d 100644 --- a/src/hotspot/cpu/loongarch/c2_CodeStubs_loongarch.cpp +++ b/src/hotspot/cpu/loongarch/c2_CodeStubs_loongarch.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2021, 2023, Loongson Technology. All rights reserved. + * Copyright (c) 2021, 2025, Loongson Technology. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -62,30 +62,4 @@ void C2EntryBarrierStub::emit(C2_MacroAssembler& masm) { __ emit_int32(0); // nmethod guard value } -int C2HandleAnonOMOwnerStub::max_size() const { - // Max size of stub has been determined by testing with 0, in which case - // C2CodeStubList::emit() will throw an assertion and report the actual size that - // is needed. - return 24; -} - -void C2HandleAnonOMOwnerStub::emit(C2_MacroAssembler& masm) { - __ bind(entry()); - Register mon = monitor(); - Register t = tmp(); - assert(t != noreg, "need tmp register"); - // Fix owner to be the current thread. - __ st_d(TREG, Address(mon, ObjectMonitor::owner_offset())); - - // Pop owner object from lock-stack. - __ ld_wu(t, Address(TREG, JavaThread::lock_stack_top_offset())); - __ addi_w(t, t, -oopSize); -#ifdef ASSERT - __ stx_d(R0, TREG, t); -#endif - __ st_w(t, Address(TREG, JavaThread::lock_stack_top_offset())); - - __ b(continuation()); -} - #undef __ diff --git a/src/hotspot/cpu/loongarch/macroAssembler_loongarch.cpp b/src/hotspot/cpu/loongarch/macroAssembler_loongarch.cpp index 51d3b94bec9cf..0197d492c7271 100644 --- a/src/hotspot/cpu/loongarch/macroAssembler_loongarch.cpp +++ b/src/hotspot/cpu/loongarch/macroAssembler_loongarch.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2017, 2024, Loongson Technology. All rights reserved. + * Copyright (c) 2017, 2025, Loongson Technology. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2866,6 +2866,7 @@ void MacroAssembler::clinit_barrier(Register klass, Register scratch, Label* L_f // Fast path check: class is fully initialized ld_b(scratch, Address(klass, InstanceKlass::init_state_offset())); + membar(Membar_mask_bits(LoadLoad | LoadStore)); addi_d(scratch, scratch, -InstanceKlass::fully_initialized); beqz(scratch, *L_fast_path); diff --git a/src/hotspot/cpu/loongarch/stubGenerator_loongarch_64.cpp b/src/hotspot/cpu/loongarch/stubGenerator_loongarch_64.cpp index d3cc9cba25ffb..10936035eaa82 100644 --- a/src/hotspot/cpu/loongarch/stubGenerator_loongarch_64.cpp +++ b/src/hotspot/cpu/loongarch/stubGenerator_loongarch_64.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2015, 2024, Loongson Technology. All rights reserved. + * Copyright (c) 2015, 2025, Loongson Technology. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -5074,6 +5074,29 @@ static const int64_t right_3_bits = right_n_bits(3); return start; } + // load Method* target of MethodHandle + // j_rarg0 = jobject receiver + // xmethod = Method* result + address generate_upcall_stub_load_target() { + + StubCodeMark mark(this, "StubRoutines", "upcall_stub_load_target"); + address start = __ pc(); + + __ resolve_global_jobject(j_rarg0, SCR2, SCR1); + // Load target method from receiver + __ load_heap_oop(Rmethod, Address(j_rarg0, java_lang_invoke_MethodHandle::form_offset()), SCR2, SCR1); + __ load_heap_oop(Rmethod, Address(Rmethod, java_lang_invoke_LambdaForm::vmentry_offset()), SCR2, SCR1); + __ load_heap_oop(Rmethod, Address(Rmethod, java_lang_invoke_MemberName::method_offset()), SCR2, SCR1); + __ access_load_at(T_ADDRESS, IN_HEAP, Rmethod, + Address(Rmethod, java_lang_invoke_ResolvedMethodName::vmtarget_offset()), + noreg, noreg); + __ st_d(Rmethod, Address(TREG, JavaThread::callee_target_offset())); // just in case callee is deoptimized + + __ jr(RA); + + return start; + } + #undef __ #define __ masm-> @@ -5692,6 +5715,7 @@ static const int64_t right_3_bits = right_n_bits(3); #endif // COMPILER2 StubRoutines::_upcall_stub_exception_handler = generate_upcall_stub_exception_handler(); + StubRoutines::_upcall_stub_load_target = generate_upcall_stub_load_target(); } void generate_compiler_stubs() { diff --git a/src/hotspot/cpu/loongarch/upcallLinker_loongarch_64.cpp b/src/hotspot/cpu/loongarch/upcallLinker_loongarch_64.cpp index e05ab577f0c8c..8014e3778b4bf 100644 --- a/src/hotspot/cpu/loongarch/upcallLinker_loongarch_64.cpp +++ b/src/hotspot/cpu/loongarch/upcallLinker_loongarch_64.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2020, Red Hat, Inc. All rights reserved. - * Copyright (c) 2021, 2024, Loongson Technology. All rights reserved. + * Copyright (c) 2021, 2025, Loongson Technology. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,6 +24,7 @@ #include "precompiled.hpp" #include "asm/macroAssembler.hpp" +#include "classfile/javaClasses.hpp" #include "logging/logStream.hpp" #include "memory/resourceArea.hpp" #include "prims/upcallLinker.hpp" @@ -116,7 +117,7 @@ static void restore_callee_saved_registers(MacroAssembler* _masm, const ABIDescr static const int upcall_stub_code_base_size = 2048; static const int upcall_stub_size_per_arg = 16; -address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry, +address UpcallLinker::make_upcall_stub(jobject receiver, Symbol* signature, BasicType* out_sig_bt, int total_out_args, BasicType ret_type, jobject jabi, jobject jconv, @@ -222,7 +223,6 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry, __ block_comment("{ on_entry"); __ lea(c_rarg0, Address(SP, frame_data_offset)); - __ li(c_rarg1, (intptr_t)receiver); __ call(CAST_FROM_FN_PTR(address, UpcallLinker::on_entry), relocInfo::runtime_call_type); __ move(TREG, V0); __ reinit_heapbase(); @@ -237,12 +237,10 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry, arg_shuffle.generate(_masm, as_VMStorage(shuffle_reg), abi._shadow_space_bytes, 0); __ block_comment("} argument shuffle"); - __ block_comment("{ receiver "); - __ get_vm_result(j_rarg0, TREG); - __ block_comment("} receiver "); - - __ mov_metadata(Rmethod, entry); - __ st_d(Rmethod, TREG, in_bytes(JavaThread::callee_target_offset())); // just in case callee is deoptimized + __ block_comment("{ load target "); + __ li(j_rarg0, (intptr_t)receiver); + __ call(StubRoutines::upcall_stub_load_target(), relocInfo::runtime_call_type); // puts target Method* in rmethod + __ block_comment("} load target "); __ push_cont_fastpath(TREG); @@ -316,7 +314,7 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry, #ifndef PRODUCT stringStream ss; - ss.print("upcall_stub_%s", entry->signature()->as_C_string()); + ss.print("upcall_stub_%s", signature->as_C_string()); const char* name = _masm->code_string(ss.as_string()); #else // PRODUCT const char* name = "upcall_stub"; diff --git a/src/hotspot/os_cpu/linux_loongarch/vmStructs_linux_loongarch.hpp b/src/hotspot/os_cpu/linux_loongarch/vmStructs_linux_loongarch.hpp index a39cb79bb1eef..3c656ff875465 100644 --- a/src/hotspot/os_cpu/linux_loongarch/vmStructs_linux_loongarch.hpp +++ b/src/hotspot/os_cpu/linux_loongarch/vmStructs_linux_loongarch.hpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2015, 2022, Loongson Technology. All rights reserved. + * Copyright (c) 2015, 2025, Loongson Technology. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,23 +30,9 @@ // constants required by the Serviceability Agent. This file is // referenced by vmStructs.cpp. -#define VM_STRUCTS_OS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field) \ - \ - /******************************/ \ - /* Threads (NOTE: incomplete) */ \ - /******************************/ \ - nonstatic_field(OSThread, _thread_id, pid_t) \ - nonstatic_field(OSThread, _pthread_id, pthread_t) +#define VM_STRUCTS_OS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field) - -#define VM_TYPES_OS_CPU(declare_type, declare_toplevel_type, declare_oop_type, declare_integer_type, declare_unsigned_integer_type, declare_c1_toplevel_type, declare_c2_type, declare_c2_toplevel_type) \ - \ - /**********************/ \ - /* Posix Thread IDs */ \ - /**********************/ \ - \ - declare_integer_type(pid_t) \ - declare_unsigned_integer_type(pthread_t) +#define VM_TYPES_OS_CPU(declare_type, declare_toplevel_type, declare_oop_type, declare_integer_type, declare_unsigned_integer_type, declare_c1_toplevel_type, declare_c2_type, declare_c2_toplevel_type) #define VM_INT_CONSTANTS_OS_CPU(declare_constant, declare_preprocessor_constant, declare_c1_constant, declare_c2_constant, declare_c2_preprocessor_constant) diff --git a/test/jdk/java/foreign/TestUpcallStress.java b/test/jdk/java/foreign/TestUpcallStress.java index 4060774685641..09b563d45485e 100644 --- a/test/jdk/java/foreign/TestUpcallStress.java +++ b/test/jdk/java/foreign/TestUpcallStress.java @@ -21,10 +21,16 @@ * questions. */ +/* + * This file has been modified by Loongson Technology in 2025. These + * modifications are Copyright (c) 2025, Loongson Technology, and are made + * available on the same license terms set forth above. + */ + /* * @test * @requires jdk.foreign.linker != "FALLBACK" - * @requires (os.arch == "aarch64" | os.arch=="riscv64") & os.name == "Linux" + * @requires (os.arch == "aarch64" | os.arch=="riscv64" | os.arch=="loongarch64") & os.name == "Linux" * @requires os.maxMemory > 4G * @modules java.base/jdk.internal.foreign * @build NativeTestHelper CallGeneratorHelper TestUpcallBase