Path: blob/master/src/hotspot/share/opto/arraycopynode.hpp
40930 views
/*1* Copyright (c) 2016, 2019, 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_OPTO_ARRAYCOPYNODE_HPP25#define SHARE_OPTO_ARRAYCOPYNODE_HPP2627#include "gc/shared/c2/barrierSetC2.hpp"28#include "opto/callnode.hpp"2930class GraphKit;3132class ArrayCopyNode : public CallNode {33private:3435// What kind of arraycopy variant is this?36enum {37None, // not set yet38ArrayCopy, // System.arraycopy()39CloneInst, // A clone of instances40CloneArray, // A clone of arrays that don't require a barrier41// - depends on GC - some need to treat oop arrays separately42CloneOopArray, // An oop array clone that requires GC barriers43CopyOf, // Arrays.copyOf()44CopyOfRange // Arrays.copyOfRange()45} _kind;4647#ifndef PRODUCT48static const char* _kind_names[CopyOfRange+1];49#endif50// Is the alloc obtained with51// AllocateArrayNode::Ideal_array_allocation() tightly coupled52// (arraycopy follows immediately the allocation)?53// We cache the result of LibraryCallKit::tightly_coupled_allocation54// here because it's much easier to find whether there's a tightly55// couple allocation at parse time than at macro expansion time. At56// macro expansion time, for every use of the allocation node we57// would need to figure out whether it happens after the arraycopy (and58// can be ignored) or between the allocation and the arraycopy. At59// parse time, it's straightforward because whatever happens after60// the arraycopy is not parsed yet so doesn't exist when61// LibraryCallKit::tightly_coupled_allocation() is called.62bool _alloc_tightly_coupled;63bool _has_negative_length_guard;6465bool _arguments_validated;6667static const TypeFunc* arraycopy_type() {68const Type** fields = TypeTuple::fields(ParmLimit - TypeFunc::Parms);69fields[Src] = TypeInstPtr::BOTTOM;70fields[SrcPos] = TypeInt::INT;71fields[Dest] = TypeInstPtr::BOTTOM;72fields[DestPos] = TypeInt::INT;73fields[Length] = TypeInt::INT;74fields[SrcLen] = TypeInt::INT;75fields[DestLen] = TypeInt::INT;76fields[SrcKlass] = TypeKlassPtr::BOTTOM;77fields[DestKlass] = TypeKlassPtr::BOTTOM;78const TypeTuple *domain = TypeTuple::make(ParmLimit, fields);7980// create result type (range)81fields = TypeTuple::fields(0);8283const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);8485return TypeFunc::make(domain, range);86}8788ArrayCopyNode(Compile* C, bool alloc_tightly_coupled, bool has_negative_length_guard);8990intptr_t get_length_if_constant(PhaseGVN *phase) const;91int get_count(PhaseGVN *phase) const;92static const TypePtr* get_address_type(PhaseGVN* phase, const TypePtr* atp, Node* n);9394Node* try_clone_instance(PhaseGVN *phase, bool can_reshape, int count);95bool prepare_array_copy(PhaseGVN *phase, bool can_reshape,96Node*& adr_src, Node*& base_src, Node*& adr_dest, Node*& base_dest,97BasicType& copy_type, const Type*& value_type, bool& disjoint_bases);98void array_copy_test_overlap(PhaseGVN *phase, bool can_reshape,99bool disjoint_bases, int count,100Node*& forward_ctl, Node*& backward_ctl);101Node* array_copy_forward(PhaseGVN *phase, bool can_reshape, Node*& ctl,102Node* mem,103const TypePtr* atp_src, const TypePtr* atp_dest,104Node* adr_src, Node* base_src, Node* adr_dest, Node* base_dest,105BasicType copy_type, const Type* value_type, int count);106Node* array_copy_backward(PhaseGVN *phase, bool can_reshape, Node*& ctl,107Node* mem,108const TypePtr* atp_src, const TypePtr* atp_dest,109Node* adr_src, Node* base_src, Node* adr_dest, Node* base_dest,110BasicType copy_type, const Type* value_type, int count);111bool finish_transform(PhaseGVN *phase, bool can_reshape,112Node* ctl, Node *mem);113static bool may_modify_helper(const TypeOopPtr *t_oop, Node* n, PhaseTransform *phase, CallNode*& call);114public:115static Node* load(BarrierSetC2* bs, PhaseGVN *phase, Node*& ctl, MergeMemNode* mem, Node* addr, const TypePtr* adr_type, const Type *type, BasicType bt);116private:117void store(BarrierSetC2* bs, PhaseGVN *phase, Node*& ctl, MergeMemNode* mem, Node* addr, const TypePtr* adr_type, Node* val, const Type *type, BasicType bt);118119public:120121enum {122Src = TypeFunc::Parms,123SrcPos,124Dest,125DestPos,126Length,127SrcLen,128DestLen,129SrcKlass,130DestKlass,131ParmLimit132};133134// Results from escape analysis for non escaping inputs135const TypeOopPtr* _src_type;136const TypeOopPtr* _dest_type;137138static ArrayCopyNode* make(GraphKit* kit, bool may_throw,139Node* src, Node* src_offset,140Node* dest, Node* dest_offset,141Node* length,142bool alloc_tightly_coupled,143bool has_negative_length_guard,144Node* src_klass = NULL, Node* dest_klass = NULL,145Node* src_length = NULL, Node* dest_length = NULL);146147void connect_outputs(GraphKit* kit, bool deoptimize_on_exception = false);148149bool is_arraycopy() const { assert(_kind != None, "should bet set"); return _kind == ArrayCopy; }150bool is_arraycopy_validated() const { assert(_kind != None, "should bet set"); return _kind == ArrayCopy && _arguments_validated; }151bool is_clone_inst() const { assert(_kind != None, "should bet set"); return _kind == CloneInst; }152// is_clone_array - true for all arrays when using GCs that has no barriers153bool is_clone_array() const { assert(_kind != None, "should bet set"); return _kind == CloneArray; }154// is_clone_oop_array is used when oop arrays need GC barriers155bool is_clone_oop_array() const { assert(_kind != None, "should bet set"); return _kind == CloneOopArray; }156// is_clonebasic - is true for any type of clone that doesn't need a writebarrier.157bool is_clonebasic() const { assert(_kind != None, "should bet set"); return _kind == CloneInst || _kind == CloneArray; }158bool is_copyof() const { assert(_kind != None, "should bet set"); return _kind == CopyOf; }159bool is_copyof_validated() const { assert(_kind != None, "should bet set"); return _kind == CopyOf && _arguments_validated; }160bool is_copyofrange() const { assert(_kind != None, "should bet set"); return _kind == CopyOfRange; }161bool is_copyofrange_validated() const { assert(_kind != None, "should bet set"); return _kind == CopyOfRange && _arguments_validated; }162163void set_arraycopy(bool validated) { assert(_kind == None, "shouldn't bet set yet"); _kind = ArrayCopy; _arguments_validated = validated; }164void set_clone_inst() { assert(_kind == None, "shouldn't bet set yet"); _kind = CloneInst; }165void set_clone_array() { assert(_kind == None, "shouldn't bet set yet"); _kind = CloneArray; }166void set_clone_oop_array() { assert(_kind == None, "shouldn't bet set yet"); _kind = CloneOopArray; }167void set_copyof(bool validated) { assert(_kind == None, "shouldn't bet set yet"); _kind = CopyOf; _arguments_validated = validated; }168void set_copyofrange(bool validated) { assert(_kind == None, "shouldn't bet set yet"); _kind = CopyOfRange; _arguments_validated = validated; }169170virtual int Opcode() const;171virtual uint size_of() const; // Size is bigger172virtual bool guaranteed_safepoint() { return false; }173virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);174175virtual bool may_modify(const TypeOopPtr *t_oop, PhaseTransform *phase);176177bool is_alloc_tightly_coupled() const { return _alloc_tightly_coupled; }178179bool has_negative_length_guard() const { return _has_negative_length_guard; }180181static bool may_modify(const TypeOopPtr *t_oop, MemBarNode* mb, PhaseTransform *phase, ArrayCopyNode*& ac);182183static int get_partial_inline_vector_lane_count(BasicType type, int const_len);184185bool modifies(intptr_t offset_lo, intptr_t offset_hi, PhaseTransform* phase, bool must_modify) const;186187#ifndef PRODUCT188virtual void dump_spec(outputStream *st) const;189virtual void dump_compact_spec(outputStream* st) const;190#endif191};192#endif // SHARE_OPTO_ARRAYCOPYNODE_HPP193194195