Skip to content

Commit

Permalink
Update (2025.01.09, 3rd)
Browse files Browse the repository at this point in the history
35414: LA port of 8338379: Accesses to class init state should be properly synchronized
35413: LA port of 8341413: Stop including osThread_os.hpp in the middle of the OSThread class
35412: LA port of 8341451: Remove C2HandleAnonOMOwnerStub
35411: LA port of 8337753: Target class of upcall stub may be unloaded
  • Loading branch information
loongson-jvm authored Jan 9, 2025
1 parent 2f03188 commit 207daa8
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 58 deletions.
3 changes: 2 additions & 1 deletion src/hotspot/cpu/loongarch/c1_LIRAssembler_loongarch_64.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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());
Expand Down
28 changes: 1 addition & 27 deletions src/hotspot/cpu/loongarch/c2_CodeStubs_loongarch.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 __
3 changes: 2 additions & 1 deletion src/hotspot/cpu/loongarch/macroAssembler_loongarch.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);

Expand Down
26 changes: 25 additions & 1 deletion src/hotspot/cpu/loongarch/stubGenerator_loongarch_64.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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->

Expand Down Expand Up @@ -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() {
Expand Down
18 changes: 8 additions & 10 deletions src/hotspot/cpu/loongarch/upcallLinker_loongarch_64.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand Down Expand Up @@ -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";
Expand Down
20 changes: 3 additions & 17 deletions src/hotspot/os_cpu/linux_loongarch/vmStructs_linux_loongarch.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion test/jdk/java/foreign/TestUpcallStress.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 207daa8

Please sign in to comment.