Path: blob/master/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.hpp
40976 views
/*1* Copyright (c) 2015, 2021, Red Hat, Inc. 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_SHENANDOAH_C2_SHENANDOAHSUPPORT_HPP25#define SHARE_GC_SHENANDOAH_C2_SHENANDOAHSUPPORT_HPP2627#include "gc/shenandoah/shenandoahBarrierSet.hpp"28#include "memory/allocation.hpp"29#include "opto/addnode.hpp"30#include "opto/graphKit.hpp"31#include "opto/machnode.hpp"32#include "opto/memnode.hpp"33#include "opto/multnode.hpp"34#include "opto/node.hpp"3536class PhaseGVN;37class MemoryGraphFixer;3839class ShenandoahBarrierC2Support : public AllStatic {40private:41#ifdef ASSERT42enum verify_type {43ShenandoahLoad,44ShenandoahStore,45ShenandoahValue,46ShenandoahOopStore,47ShenandoahNone48};4950static bool verify_helper(Node* in, Node_Stack& phis, VectorSet& visited, verify_type t, bool trace, Unique_Node_List& barriers_used);51static void report_verify_failure(const char* msg, Node* n1 = NULL, Node* n2 = NULL);52static void verify_raw_mem(RootNode* root);53#endif54static Node* dom_mem(Node* mem, Node* ctrl, int alias, Node*& mem_ctrl, PhaseIdealLoop* phase);55static Node* no_branches(Node* c, Node* dom, bool allow_one_proj, PhaseIdealLoop* phase);56static bool is_gc_state_test(Node* iff, int mask);57static bool has_safepoint_between(Node* start, Node* stop, PhaseIdealLoop *phase);58static Node* find_bottom_mem(Node* ctrl, PhaseIdealLoop* phase);59static void follow_barrier_uses(Node* n, Node* ctrl, Unique_Node_List& uses, PhaseIdealLoop* phase);60static void test_null(Node*& ctrl, Node* val, Node*& null_ctrl, PhaseIdealLoop* phase);61static void test_gc_state(Node*& ctrl, Node* raw_mem, Node*& heap_stable_ctrl,62PhaseIdealLoop* phase, int flags);63static void call_lrb_stub(Node*& ctrl, Node*& val, Node* load_addr, Node*& result_mem, Node* raw_mem,64DecoratorSet decorators, PhaseIdealLoop* phase);65static void test_in_cset(Node*& ctrl, Node*& not_cset_ctrl, Node* val, Node* raw_mem, PhaseIdealLoop* phase);66static void move_gc_state_test_out_of_loop(IfNode* iff, PhaseIdealLoop* phase);67static void merge_back_to_back_tests(Node* n, PhaseIdealLoop* phase);68static bool identical_backtoback_ifs(Node *n, PhaseIdealLoop* phase);69static void fix_ctrl(Node* barrier, Node* region, const MemoryGraphFixer& fixer, Unique_Node_List& uses, Unique_Node_List& uses_to_ignore, uint last, PhaseIdealLoop* phase);70static IfNode* find_unswitching_candidate(const IdealLoopTree *loop, PhaseIdealLoop* phase);7172static Node* get_load_addr(PhaseIdealLoop* phase, VectorSet& visited, Node* lrb);73public:74static bool is_dominator(Node* d_c, Node* n_c, Node* d, Node* n, PhaseIdealLoop* phase);75static bool is_dominator_same_ctrl(Node* c, Node* d, Node* n, PhaseIdealLoop* phase);7677static bool is_gc_state_load(Node* n);78static bool is_heap_stable_test(Node* iff);7980static bool expand(Compile* C, PhaseIterGVN& igvn);81static void pin_and_expand(PhaseIdealLoop* phase);82static void optimize_after_expansion(VectorSet& visited, Node_Stack& nstack, Node_List& old_new, PhaseIdealLoop* phase);8384#ifdef ASSERT85static void verify(RootNode* root);86#endif87};8889class ShenandoahIUBarrierNode : public Node {90public:91ShenandoahIUBarrierNode(Node* val);9293const Type *bottom_type() const;94const Type* Value(PhaseGVN* phase) const;95Node* Identity(PhaseGVN* phase);9697int Opcode() const;9899private:100enum { Needed, NotNeeded, MaybeNeeded };101102static int needed(Node* n);103static Node* next(Node* n);104};105106class MemoryGraphFixer : public ResourceObj {107private:108Node_List _memory_nodes;109int _alias;110PhaseIdealLoop* _phase;111bool _include_lsm;112113void collect_memory_nodes();114Node* get_ctrl(Node* n) const;115Node* ctrl_or_self(Node* n) const;116bool mem_is_valid(Node* m, Node* c) const;117MergeMemNode* allocate_merge_mem(Node* mem, Node* rep_proj, Node* rep_ctrl) const;118MergeMemNode* clone_merge_mem(Node* u, Node* mem, Node* rep_proj, Node* rep_ctrl, DUIterator& i) const;119void fix_memory_uses(Node* mem, Node* replacement, Node* rep_proj, Node* rep_ctrl) const;120bool should_process_phi(Node* phi) const;121bool has_mem_phi(Node* region) const;122123public:124MemoryGraphFixer(int alias, bool include_lsm, PhaseIdealLoop* phase) :125_alias(alias), _phase(phase), _include_lsm(include_lsm) {126assert(_alias != Compile::AliasIdxBot, "unsupported");127collect_memory_nodes();128}129130Node* find_mem(Node* ctrl, Node* n) const;131void fix_mem(Node* ctrl, Node* region, Node* mem, Node* mem_for_ctrl, Node* mem_phi, Unique_Node_List& uses);132int alias() const { return _alias; }133};134135class ShenandoahCompareAndSwapPNode : public CompareAndSwapPNode {136public:137ShenandoahCompareAndSwapPNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord)138: CompareAndSwapPNode(c, mem, adr, val, ex, mem_ord) { }139140virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {141if (in(ExpectedIn) != NULL && phase->type(in(ExpectedIn)) == TypePtr::NULL_PTR) {142return new CompareAndSwapPNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), order());143}144return NULL;145}146147virtual int Opcode() const;148};149150class ShenandoahCompareAndSwapNNode : public CompareAndSwapNNode {151public:152ShenandoahCompareAndSwapNNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord)153: CompareAndSwapNNode(c, mem, adr, val, ex, mem_ord) { }154155virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {156if (in(ExpectedIn) != NULL && phase->type(in(ExpectedIn)) == TypeNarrowOop::NULL_PTR) {157return new CompareAndSwapNNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), order());158}159return NULL;160}161162virtual int Opcode() const;163};164165class ShenandoahWeakCompareAndSwapPNode : public WeakCompareAndSwapPNode {166public:167ShenandoahWeakCompareAndSwapPNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord)168: WeakCompareAndSwapPNode(c, mem, adr, val, ex, mem_ord) { }169170virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {171if (in(ExpectedIn) != NULL && phase->type(in(ExpectedIn)) == TypePtr::NULL_PTR) {172return new WeakCompareAndSwapPNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), order());173}174return NULL;175}176177virtual int Opcode() const;178};179180class ShenandoahWeakCompareAndSwapNNode : public WeakCompareAndSwapNNode {181public:182ShenandoahWeakCompareAndSwapNNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord)183: WeakCompareAndSwapNNode(c, mem, adr, val, ex, mem_ord) { }184185virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {186if (in(ExpectedIn) != NULL && phase->type(in(ExpectedIn)) == TypeNarrowOop::NULL_PTR) {187return new WeakCompareAndSwapNNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), order());188}189return NULL;190}191192virtual int Opcode() const;193};194195class ShenandoahCompareAndExchangePNode : public CompareAndExchangePNode {196public:197ShenandoahCompareAndExchangePNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, const Type* t, MemNode::MemOrd mem_ord)198: CompareAndExchangePNode(c, mem, adr, val, ex, at, t, mem_ord) { }199200virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {201if (in(ExpectedIn) != NULL && phase->type(in(ExpectedIn)) == TypePtr::NULL_PTR) {202return new CompareAndExchangePNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), adr_type(), bottom_type(), order());203}204return NULL;205}206207virtual int Opcode() const;208};209210class ShenandoahCompareAndExchangeNNode : public CompareAndExchangeNNode {211public:212ShenandoahCompareAndExchangeNNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, const Type* t, MemNode::MemOrd mem_ord)213: CompareAndExchangeNNode(c, mem, adr, val, ex, at, t, mem_ord) { }214215virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {216if (in(ExpectedIn) != NULL && phase->type(in(ExpectedIn)) == TypeNarrowOop::NULL_PTR) {217return new CompareAndExchangeNNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), adr_type(), bottom_type(), order());218}219return NULL;220}221222virtual int Opcode() const;223};224225class ShenandoahLoadReferenceBarrierNode : public Node {226public:227enum {228Control,229ValueIn230};231232private:233DecoratorSet _decorators;234235public:236ShenandoahLoadReferenceBarrierNode(Node* ctrl, Node* val, DecoratorSet decorators);237238DecoratorSet decorators() const;239virtual int Opcode() const;240virtual const Type* bottom_type() const;241virtual const Type* Value(PhaseGVN* phase) const;242virtual const class TypePtr *adr_type() const { return TypeOopPtr::BOTTOM; }243virtual uint match_edge(uint idx) const {244return idx >= ValueIn;245}246virtual uint ideal_reg() const { return Op_RegP; }247248virtual Node* Identity(PhaseGVN* phase);249250virtual uint size_of() const;251virtual uint hash() const;252virtual bool cmp( const Node &n ) const;253254private:255bool needs_barrier(PhaseGVN* phase, Node* n);256bool needs_barrier_impl(PhaseGVN* phase, Node* n, Unique_Node_List &visited);257};258259260#endif // SHARE_GC_SHENANDOAH_C2_SHENANDOAHSUPPORT_HPP261262263