Path: blob/master/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp
40974 views
/*1* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_SHARED_C2_BARRIERSETC2_HPP25#define SHARE_GC_SHARED_C2_BARRIERSETC2_HPP2627#include "memory/allocation.hpp"28#include "oops/accessDecorators.hpp"29#include "opto/loopnode.hpp"30#include "opto/matcher.hpp"31#include "opto/memnode.hpp"32#include "utilities/globalDefinitions.hpp"3334// This means the access is mismatched. This means the value of an access35// is not equivalent to the value pointed to by the address.36const DecoratorSet C2_MISMATCHED = DECORATOR_LAST << 1;37// The access may not be aligned to its natural size.38const DecoratorSet C2_UNALIGNED = DECORATOR_LAST << 2;39// The atomic cmpxchg is weak, meaning that spurious false negatives are allowed,40// but never false positives.41const DecoratorSet C2_WEAK_CMPXCHG = DECORATOR_LAST << 3;42// This denotes that a load has control dependency.43const DecoratorSet C2_CONTROL_DEPENDENT_LOAD = DECORATOR_LAST << 4;44// This denotes that a load that must be pinned, but may float above safepoints.45const DecoratorSet C2_UNKNOWN_CONTROL_LOAD = DECORATOR_LAST << 5;46// This denotes that the access is produced from the sun.misc.Unsafe intrinsics.47const DecoratorSet C2_UNSAFE_ACCESS = DECORATOR_LAST << 6;48// This denotes that the access mutates state.49const DecoratorSet C2_WRITE_ACCESS = DECORATOR_LAST << 7;50// This denotes that the access reads state.51const DecoratorSet C2_READ_ACCESS = DECORATOR_LAST << 8;52// A nearby allocation?53const DecoratorSet C2_TIGHTLY_COUPLED_ALLOC = DECORATOR_LAST << 9;54// Loads and stores from an arraycopy being optimized55const DecoratorSet C2_ARRAY_COPY = DECORATOR_LAST << 10;56// Loads from immutable memory57const DecoratorSet C2_IMMUTABLE_MEMORY = DECORATOR_LAST << 11;5859class Compile;60class ConnectionGraph;61class GraphKit;62class IdealKit;63class Node;64class PhaseGVN;65class PhaseIdealLoop;66class PhaseMacroExpand;67class Type;68class TypePtr;69class Unique_Node_List;7071// This class wraps a node and a type.72class C2AccessValue: public StackObj {73protected:74Node* _node;75const Type* _type;7677public:78C2AccessValue(Node* node, const Type* type) :79_node(node),80_type(type) {}8182Node* node() const { return _node; }83const Type* type() const { return _type; }8485void set_node(Node* node) { _node = node; }86};8788// This class wraps a node and a pointer type.89class C2AccessValuePtr: public C2AccessValue {9091public:92C2AccessValuePtr(Node* node, const TypePtr* type) :93C2AccessValue(node, reinterpret_cast<const Type*>(type)) {}9495const TypePtr* type() const { return reinterpret_cast<const TypePtr*>(_type); }96};9798// This class wraps a bunch of context parameters thare are passed around in the99// BarrierSetC2 backend hierarchy, for loads and stores, to reduce boiler plate.100class C2Access: public StackObj {101protected:102DecoratorSet _decorators;103BasicType _type;104Node* _base;105C2AccessValuePtr& _addr;106Node* _raw_access;107uint8_t _barrier_data;108109void fixup_decorators();110111public:112C2Access(DecoratorSet decorators,113BasicType type, Node* base, C2AccessValuePtr& addr) :114_decorators(decorators),115_type(type),116_base(base),117_addr(addr),118_raw_access(NULL),119_barrier_data(0)120{}121122DecoratorSet decorators() const { return _decorators; }123Node* base() const { return _base; }124C2AccessValuePtr& addr() const { return _addr; }125BasicType type() const { return _type; }126bool is_oop() const { return is_reference_type(_type); }127bool is_raw() const { return (_decorators & AS_RAW) != 0; }128Node* raw_access() const { return _raw_access; }129130uint8_t barrier_data() const { return _barrier_data; }131void set_barrier_data(uint8_t data) { _barrier_data = data; }132133void set_raw_access(Node* raw_access) { _raw_access = raw_access; }134virtual void set_memory() {} // no-op for normal accesses, but not for atomic accesses.135136MemNode::MemOrd mem_node_mo() const;137bool needs_cpu_membar() const;138139virtual PhaseGVN& gvn() const = 0;140virtual bool is_parse_access() const { return false; }141virtual bool is_opt_access() const { return false; }142};143144// C2Access for parse time calls to the BarrierSetC2 backend.145class C2ParseAccess: public C2Access {146protected:147GraphKit* _kit;148149void* barrier_set_state() const;150151public:152C2ParseAccess(GraphKit* kit, DecoratorSet decorators,153BasicType type, Node* base, C2AccessValuePtr& addr) :154C2Access(decorators, type, base, addr),155_kit(kit) {156fixup_decorators();157}158159GraphKit* kit() const { return _kit; }160161virtual PhaseGVN& gvn() const;162virtual bool is_parse_access() const { return true; }163};164165// This class wraps a bunch of context parameters thare are passed around in the166// BarrierSetC2 backend hierarchy, for atomic accesses, to reduce boiler plate.167class C2AtomicParseAccess: public C2ParseAccess {168Node* _memory;169uint _alias_idx;170bool _needs_pinning;171172public:173C2AtomicParseAccess(GraphKit* kit, DecoratorSet decorators, BasicType type,174Node* base, C2AccessValuePtr& addr, uint alias_idx) :175C2ParseAccess(kit, decorators, type, base, addr),176_memory(NULL),177_alias_idx(alias_idx),178_needs_pinning(true) {}179180// Set the memory node based on the current memory slice.181virtual void set_memory();182183Node* memory() const { return _memory; }184uint alias_idx() const { return _alias_idx; }185bool needs_pinning() const { return _needs_pinning; }186};187188// C2Access for optimization time calls to the BarrierSetC2 backend.189class C2OptAccess: public C2Access {190PhaseGVN& _gvn;191MergeMemNode* _mem;192Node* _ctl;193194public:195C2OptAccess(PhaseGVN& gvn, Node* ctl, MergeMemNode* mem, DecoratorSet decorators,196BasicType type, Node* base, C2AccessValuePtr& addr) :197C2Access(decorators, type, base, addr),198_gvn(gvn), _mem(mem), _ctl(ctl) {199fixup_decorators();200}201202MergeMemNode* mem() const { return _mem; }203Node* ctl() const { return _ctl; }204205virtual PhaseGVN& gvn() const { return _gvn; }206virtual bool is_opt_access() const { return true; }207};208209210// This is the top-level class for the backend of the Access API in C2.211// The top-level class is responsible for performing raw accesses. The212// various GC barrier sets inherit from the BarrierSetC2 class to sprinkle213// barriers into the accesses.214class BarrierSetC2: public CHeapObj<mtGC> {215protected:216virtual void resolve_address(C2Access& access) const;217virtual Node* store_at_resolved(C2Access& access, C2AccessValue& val) const;218virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const;219220virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,221Node* new_val, const Type* val_type) const;222virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,223Node* new_val, const Type* value_type) const;224virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const;225virtual Node* atomic_add_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const;226void pin_atomic_op(C2AtomicParseAccess& access) const;227228public:229// This is the entry-point for the backend to perform accesses through the Access API.230virtual Node* store_at(C2Access& access, C2AccessValue& val) const;231virtual Node* load_at(C2Access& access, const Type* val_type) const;232233virtual Node* atomic_cmpxchg_val_at(C2AtomicParseAccess& access, Node* expected_val,234Node* new_val, const Type* val_type) const;235virtual Node* atomic_cmpxchg_bool_at(C2AtomicParseAccess& access, Node* expected_val,236Node* new_val, const Type* val_type) const;237virtual Node* atomic_xchg_at(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const;238virtual Node* atomic_add_at(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const;239240virtual void clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const;241242virtual Node* obj_allocate(PhaseMacroExpand* macro, Node* mem, Node* toobig_false, Node* size_in_bytes,243Node*& i_o, Node*& needgc_ctrl,244Node*& fast_oop_ctrl, Node*& fast_oop_rawmem,245intx prefetch_lines) const;246247virtual Node* ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const { return NULL; }248249// These are general helper methods used by C2250enum ArrayCopyPhase {251Parsing,252Optimization,253Expansion254};255256virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const { return false; }257virtual void clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const;258259// Support for GC barriers emitted during parsing260virtual bool has_load_barrier_nodes() const { return false; }261virtual bool is_gc_barrier_node(Node* node) const { return false; }262virtual Node* step_over_gc_barrier(Node* c) const { return c; }263264// Support for macro expanded GC barriers265virtual void register_potential_barrier_node(Node* node) const { }266virtual void unregister_potential_barrier_node(Node* node) const { }267virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const { }268virtual void enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const {}269virtual void eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const {}270271// Allow barrier sets to have shared state that is preserved across a compilation unit.272// This could for example comprise macro nodes to be expanded during macro expansion.273virtual void* create_barrier_state(Arena* comp_arena) const { return NULL; }274// If the BarrierSetC2 state has barrier nodes in its compilation275// unit state to be expanded later, then now is the time to do so.276virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const { return false; }277virtual bool optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const { return false; }278virtual bool strip_mined_loops_expanded(LoopOptsMode mode) const { return false; }279virtual bool is_gc_specific_loop_opts_pass(LoopOptsMode mode) const { return false; }280281enum CompilePhase {282BeforeOptimize,283BeforeMacroExpand,284BeforeCodeGen285};286287#ifdef ASSERT288virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const {}289#endif290291virtual bool final_graph_reshaping(Compile* compile, Node* n, uint opcode) const { return false; }292293virtual bool escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const { return false; }294virtual bool escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const { return false; }295virtual bool escape_has_out_with_unsafe_object(Node* n) const { return false; }296297virtual bool matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const { return false; };298virtual bool matcher_is_store_load_barrier(Node* x, uint xop) const { return false; }299300virtual void late_barrier_analysis() const { }301virtual int estimate_stub_size() const { return 0; }302virtual void emit_stubs(CodeBuffer& cb) const { }303304static int arraycopy_payload_base_offset(bool is_array);305};306307#endif // SHARE_GC_SHARED_C2_BARRIERSETC2_HPP308309310