Skip to content

Commit

Permalink
Update (2024.10.16)
Browse files Browse the repository at this point in the history
11541: Prevent load reorder of VarHandle::getOpaque
  • Loading branch information
loongson-jvm authored Oct 17, 2024
1 parent d74db6e commit 68354ae
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/hotspot/cpu/loongarch/loongarch_64.ad
Original file line number Diff line number Diff line change
Expand Up @@ -6438,6 +6438,17 @@ instruct membar_storestore() %{
ins_pipe(empty);
%}

instruct same_addr_load_fence() %{
match(SameAddrLoadFence);
ins_cost(400);

format %{ "MEMBAR @ same_addr_load_fence" %}
ins_encode %{
__ dbar(0x700);
%}
ins_pipe(pipe_slow);
%}

//----------Move Instructions--------------------------------------------------
instruct castX2P(mRegP dst, mRegL src) %{
match(Set dst (CastX2P src));
Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/adlc/formssel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
*
*/

/*
* This file has been modified by Loongson Technology in 2023, These
* modifications are Copyright (c) 2023, Loongson Technology, and are made
* available on the same license terms set forth above.
*/

// FORMS.CPP - Definitions for ADL Parser Forms Classes
#include "adlc.hpp"

Expand Down Expand Up @@ -4109,6 +4115,7 @@ bool MatchRule::is_ideal_membar() const {
!strcmp(_opType,"MemBarVolatile") ||
!strcmp(_opType,"MemBarCPUOrder") ||
!strcmp(_opType,"MemBarStoreStore") ||
!strcmp(_opType,"SameAddrLoadFence" ) ||
!strcmp(_opType,"OnSpinWait");
}

Expand Down
15 changes: 15 additions & 0 deletions src/hotspot/share/gc/shared/c2/barrierSetC2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
*
*/

/*
* This file has been modified by Loongson Technology in 2023, These
* modifications are Copyright (c) 2023, Loongson Technology, and are made
* available on the same license terms set forth above.
*/

#include "precompiled.hpp"
#include "gc/shared/c2/barrierSetC2.hpp"
#include "opto/arraycopynode.hpp"
Expand Down Expand Up @@ -197,6 +203,8 @@ class C2AccessFence: public StackObj {

bool is_volatile = (decorators & MO_SEQ_CST) != 0;
bool is_acquire = (decorators & MO_ACQUIRE) != 0;
bool is_relaxed = (decorators & MO_RELAXED) != 0;
bool is_unsafe = (decorators & C2_UNSAFE_ACCESS) != 0;

// If reference is volatile, prevent following volatiles ops from
// floating up before the volatile access.
Expand Down Expand Up @@ -227,6 +235,13 @@ class C2AccessFence: public StackObj {
assert(_leading_membar == NULL || support_IRIW_for_not_multiple_copy_atomic_cpu, "no leading membar expected");
Node* mb = kit->insert_mem_bar(Op_MemBarAcquire, n);
mb->as_MemBar()->set_trailing_load();
} else if (is_relaxed && is_unsafe) {
#ifdef LOONGARCH64
assert(kit != NULL, "unsupported at optimization time");
Node* n = _access.raw_access();
Node* mb = kit->insert_mem_bar(Op_SameAddrLoadFence, n);
mb->as_MemBar()->set_trailing_load();
#endif
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/opto/classes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
*
*/

/*
* This file has been modified by Loongson Technology in 2023, These
* modifications are Copyright (c) 2023, Loongson Technology, and are made
* available on the same license terms set forth above.
*/

#include "utilities/macros.hpp"

// The giant table of Node classes.
Expand Down Expand Up @@ -217,6 +223,7 @@ macro(StoreFence)
macro(MemBarReleaseLock)
macro(MemBarVolatile)
macro(MemBarStoreStore)
macro(SameAddrLoadFence)
macro(MergeMem)
macro(MinD)
macro(MinF)
Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/opto/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
*
*/

/*
* This file has been modified by Loongson Technology in 2023, These
* modifications are Copyright (c) 2023, Loongson Technology, and are made
* available on the same license terms set forth above.
*/

#include "precompiled.hpp"
#include "asm/macroAssembler.hpp"
#include "asm/macroAssembler.inline.hpp"
Expand Down Expand Up @@ -3448,6 +3454,7 @@ void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
n->set_req(MemBarNode::Precedent, top());
}
break;
case Op_SameAddrLoadFence:
case Op_MemBarAcquire: {
if (n->as_MemBar()->trailing_load() && n->req() > MemBarNode::Precedent) {
// At parse time, the trailing MemBarAcquire for a volatile load
Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/opto/memnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
*
*/

/*
* This file has been modified by Loongson Technology in 2023, These
* modifications are Copyright (c) 2023, Loongson Technology, and are made
* available on the same license terms set forth above.
*/

#include "precompiled.hpp"
#include "classfile/systemDictionary.hpp"
#include "compiler/compileLog.hpp"
Expand Down Expand Up @@ -3190,6 +3196,7 @@ MemBarNode* MemBarNode::make(Compile* C, int opcode, int atp, Node* pn) {
case Op_MemBarReleaseLock: return new MemBarReleaseLockNode(C, atp, pn);
case Op_MemBarVolatile: return new MemBarVolatileNode(C, atp, pn);
case Op_MemBarCPUOrder: return new MemBarCPUOrderNode(C, atp, pn);
case Op_SameAddrLoadFence: return new SameAddrLoadFenceNode(C, atp, pn);
case Op_OnSpinWait: return new OnSpinWaitNode(C, atp, pn);
case Op_Initialize: return new InitializeNode(C, atp, pn);
case Op_MemBarStoreStore: return new MemBarStoreStoreNode(C, atp, pn);
Expand Down
14 changes: 14 additions & 0 deletions src/hotspot/share/opto/memnode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
*
*/

/*
* This file has been modified by Loongson Technology in 2023, These
* modifications are Copyright (c) 2023, Loongson Technology, and are made
* available on the same license terms set forth above.
*/

#ifndef SHARE_VM_OPTO_MEMNODE_HPP
#define SHARE_VM_OPTO_MEMNODE_HPP

Expand Down Expand Up @@ -1293,6 +1299,14 @@ class MemBarCPUOrderNode: public MemBarNode {
virtual uint ideal_reg() const { return 0; } // not matched in the AD file
};

// Used to prevent LoadLoad reorder for same address.
class SameAddrLoadFenceNode: public MemBarNode {
public:
SameAddrLoadFenceNode(Compile* C, int alias_idx, Node* precedent)
: MemBarNode(C, alias_idx, precedent) {}
virtual int Opcode() const;
};

class OnSpinWaitNode: public MemBarNode {
public:
OnSpinWaitNode(Compile* C, int alias_idx, Node* precedent)
Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/runtime/vmStructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
*
*/

/*
* This file has been modified by Loongson Technology in 2023, These
* modifications are Copyright (c) 2023, Loongson Technology, and are made
* available on the same license terms set forth above.
*/

#include "precompiled.hpp"
#include "ci/ciField.hpp"
#include "ci/ciInstance.hpp"
Expand Down Expand Up @@ -1642,6 +1648,7 @@ typedef PaddedEnd<ObjectMonitor> PaddedObjectMonitor;
declare_c2_type(StoreFenceNode, MemBarNode) \
declare_c2_type(MemBarVolatileNode, MemBarNode) \
declare_c2_type(MemBarCPUOrderNode, MemBarNode) \
declare_c2_type(SameAddrLoadFenceNode, MemBarNode) \
declare_c2_type(OnSpinWaitNode, MemBarNode) \
declare_c2_type(InitializeNode, MemBarNode) \
declare_c2_type(ThreadLocalNode, Node) \
Expand Down

0 comments on commit 68354ae

Please sign in to comment.