Path: blob/master/src/hotspot/share/opto/graphKit.hpp
40930 views
/*1* Copyright (c) 2001, 2021, 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_GRAPHKIT_HPP25#define SHARE_OPTO_GRAPHKIT_HPP2627#include "ci/ciEnv.hpp"28#include "ci/ciMethodData.hpp"29#include "gc/shared/c2/barrierSetC2.hpp"30#include "opto/addnode.hpp"31#include "opto/callnode.hpp"32#include "opto/cfgnode.hpp"33#include "opto/compile.hpp"34#include "opto/divnode.hpp"35#include "opto/mulnode.hpp"36#include "opto/phaseX.hpp"37#include "opto/subnode.hpp"38#include "opto/type.hpp"39#include "runtime/deoptimization.hpp"4041class BarrierSetC2;42class FastLockNode;43class FastUnlockNode;44class IdealKit;45class LibraryCallKit;46class Parse;47class RootNode;4849//-----------------------------------------------------------------------------50//----------------------------GraphKit-----------------------------------------51// Toolkit for building the common sorts of subgraphs.52// Does not know about bytecode parsing or type-flow results.53// It is able to create graphs implementing the semantics of most54// or all bytecodes, so that it can expand intrinsics and calls.55// It may depend on JVMState structure, but it must not depend56// on specific bytecode streams.57class GraphKit : public Phase {58friend class PreserveJVMState;5960protected:61ciEnv* _env; // Compilation environment62PhaseGVN &_gvn; // Some optimizations while parsing63SafePointNode* _map; // Parser map from JVM to Nodes64SafePointNode* _exceptions;// Parser map(s) for exception state(s)65int _bci; // JVM Bytecode Pointer66ciMethod* _method; // JVM Current Method67BarrierSetC2* _barrier_set;6869private:70int _sp; // JVM Expression Stack Pointer; don't modify directly!7172private:73SafePointNode* map_not_null() const {74assert(_map != NULL, "must call stopped() to test for reset compiler map");75return _map;76}7778public:79GraphKit(); // empty constructor80GraphKit(JVMState* jvms); // the JVM state on which to operate8182#ifdef ASSERT83~GraphKit() {84assert(!has_exceptions(), "user must call transfer_exceptions_into_jvms");85}86#endif8788virtual Parse* is_Parse() const { return NULL; }89virtual LibraryCallKit* is_LibraryCallKit() const { return NULL; }9091ciEnv* env() const { return _env; }92PhaseGVN& gvn() const { return _gvn; }93void* barrier_set_state() const { return C->barrier_set_state(); }9495void record_for_igvn(Node* n) const { C->record_for_igvn(n); } // delegate to Compile9697// Handy well-known nodes:98Node* null() const { return zerocon(T_OBJECT); }99Node* top() const { return C->top(); }100RootNode* root() const { return C->root(); }101102// Create or find a constant node103Node* intcon(jint con) const { return _gvn.intcon(con); }104Node* longcon(jlong con) const { return _gvn.longcon(con); }105Node* integercon(jlong con, BasicType bt) const {106if (bt == T_INT) {107return intcon(checked_cast<jint>(con));108}109assert(bt == T_LONG, "basic type not an int or long");110return longcon(con);111}112Node* makecon(const Type *t) const { return _gvn.makecon(t); }113Node* zerocon(BasicType bt) const { return _gvn.zerocon(bt); }114// (See also macro MakeConX in type.hpp, which uses intcon or longcon.)115116jint find_int_con(Node* n, jint value_if_unknown) {117return _gvn.find_int_con(n, value_if_unknown);118}119jlong find_long_con(Node* n, jlong value_if_unknown) {120return _gvn.find_long_con(n, value_if_unknown);121}122// (See also macro find_intptr_t_con in type.hpp, which uses one of these.)123124// JVM State accessors:125// Parser mapping from JVM indices into Nodes.126// Low slots are accessed by the StartNode::enum.127// Then come the locals at StartNode::Parms to StartNode::Parms+max_locals();128// Then come JVM stack slots.129// Finally come the monitors, if any.130// See layout accessors in class JVMState.131132SafePointNode* map() const { return _map; }133bool has_exceptions() const { return _exceptions != NULL; }134JVMState* jvms() const { return map_not_null()->_jvms; }135int sp() const { return _sp; }136int bci() const { return _bci; }137Bytecodes::Code java_bc() const;138ciMethod* method() const { return _method; }139140void set_jvms(JVMState* jvms) { set_map(jvms->map());141assert(jvms == this->jvms(), "sanity");142_sp = jvms->sp();143_bci = jvms->bci();144_method = jvms->has_method() ? jvms->method() : NULL; }145void set_map(SafePointNode* m) { _map = m; debug_only(verify_map()); }146void set_sp(int sp) { assert(sp >= 0, "sp must be non-negative: %d", sp); _sp = sp; }147void clean_stack(int from_sp); // clear garbage beyond from_sp to top148149void inc_sp(int i) { set_sp(sp() + i); }150void dec_sp(int i) { set_sp(sp() - i); }151void set_bci(int bci) { _bci = bci; }152153// Make sure jvms has current bci & sp.154JVMState* sync_jvms() const;155JVMState* sync_jvms_for_reexecute();156157#ifdef ASSERT158// Make sure JVMS has an updated copy of bci and sp.159// Also sanity-check method, depth, and monitor depth.160bool jvms_in_sync() const;161162// Make sure the map looks OK.163void verify_map() const;164165// Make sure a proposed exception state looks OK.166static void verify_exception_state(SafePointNode* ex_map);167#endif168169// Clone the existing map state. (Implements PreserveJVMState.)170SafePointNode* clone_map();171172// Set the map to a clone of the given one.173void set_map_clone(SafePointNode* m);174175// Tell if the compilation is failing.176bool failing() const { return C->failing(); }177178// Set _map to NULL, signalling a stop to further bytecode execution.179// Preserve the map intact for future use, and return it back to the caller.180SafePointNode* stop() { SafePointNode* m = map(); set_map(NULL); return m; }181182// Stop, but first smash the map's inputs to NULL, to mark it dead.183void stop_and_kill_map();184185// Tell if _map is NULL, or control is top.186bool stopped();187188// Tell if this method or any caller method has exception handlers.189bool has_ex_handler();190191// Save an exception without blowing stack contents or other JVM state.192// (The extra pointer is stuck with add_req on the map, beyond the JVMS.)193static void set_saved_ex_oop(SafePointNode* ex_map, Node* ex_oop);194195// Recover a saved exception from its map.196static Node* saved_ex_oop(SafePointNode* ex_map);197198// Recover a saved exception from its map, and remove it from the map.199static Node* clear_saved_ex_oop(SafePointNode* ex_map);200201#ifdef ASSERT202// Recover a saved exception from its map, and remove it from the map.203static bool has_saved_ex_oop(SafePointNode* ex_map);204#endif205206// Push an exception in the canonical position for handlers (stack(0)).207void push_ex_oop(Node* ex_oop) {208ensure_stack(1); // ensure room to push the exception209set_stack(0, ex_oop);210set_sp(1);211clean_stack(1);212}213214// Detach and return an exception state.215SafePointNode* pop_exception_state() {216SafePointNode* ex_map = _exceptions;217if (ex_map != NULL) {218_exceptions = ex_map->next_exception();219ex_map->set_next_exception(NULL);220debug_only(verify_exception_state(ex_map));221}222return ex_map;223}224225// Add an exception, using the given JVM state, without commoning.226void push_exception_state(SafePointNode* ex_map) {227debug_only(verify_exception_state(ex_map));228ex_map->set_next_exception(_exceptions);229_exceptions = ex_map;230}231232// Turn the current JVM state into an exception state, appending the ex_oop.233SafePointNode* make_exception_state(Node* ex_oop);234235// Add an exception, using the given JVM state.236// Combine all exceptions with a common exception type into a single state.237// (This is done via combine_exception_states.)238void add_exception_state(SafePointNode* ex_map);239240// Combine all exceptions of any sort whatever into a single master state.241SafePointNode* combine_and_pop_all_exception_states() {242if (_exceptions == NULL) return NULL;243SafePointNode* phi_map = pop_exception_state();244SafePointNode* ex_map;245while ((ex_map = pop_exception_state()) != NULL) {246combine_exception_states(ex_map, phi_map);247}248return phi_map;249}250251// Combine the two exception states, building phis as necessary.252// The second argument is updated to include contributions from the first.253void combine_exception_states(SafePointNode* ex_map, SafePointNode* phi_map);254255// Reset the map to the given state. If there are any half-finished phis256// in it (created by combine_exception_states), transform them now.257// Returns the exception oop. (Caller must call push_ex_oop if required.)258Node* use_exception_state(SafePointNode* ex_map);259260// Collect exceptions from a given JVM state into my exception list.261void add_exception_states_from(JVMState* jvms);262263// Collect all raised exceptions into the current JVM state.264// Clear the current exception list and map, returns the combined states.265JVMState* transfer_exceptions_into_jvms();266267// Helper to throw a built-in exception.268// Range checks take the offending index.269// Cast and array store checks take the offending class.270// Others do not take the optional argument.271// The JVMS must allow the bytecode to be re-executed272// via an uncommon trap.273void builtin_throw(Deoptimization::DeoptReason reason, Node* arg = NULL);274275// Helper to check the JavaThread::_should_post_on_exceptions flag276// and branch to an uncommon_trap if it is true (with the specified reason and must_throw)277void uncommon_trap_if_should_post_on_exceptions(Deoptimization::DeoptReason reason,278bool must_throw) ;279280// Helper Functions for adding debug information281void kill_dead_locals();282#ifdef ASSERT283bool dead_locals_are_killed();284#endif285// The call may deoptimize. Supply required JVM state as debug info.286// If must_throw is true, the call is guaranteed not to return normally.287void add_safepoint_edges(SafePointNode* call,288bool must_throw = false);289290// How many stack inputs does the current BC consume?291// And, how does the stack change after the bytecode?292// Returns false if unknown.293bool compute_stack_effects(int& inputs, int& depth);294295// Add a fixed offset to a pointer296Node* basic_plus_adr(Node* base, Node* ptr, intptr_t offset) {297return basic_plus_adr(base, ptr, MakeConX(offset));298}299Node* basic_plus_adr(Node* base, intptr_t offset) {300return basic_plus_adr(base, base, MakeConX(offset));301}302// Add a variable offset to a pointer303Node* basic_plus_adr(Node* base, Node* offset) {304return basic_plus_adr(base, base, offset);305}306Node* basic_plus_adr(Node* base, Node* ptr, Node* offset);307308309// Some convenient shortcuts for common nodes310Node* IfTrue(IfNode* iff) { return _gvn.transform(new IfTrueNode(iff)); }311Node* IfFalse(IfNode* iff) { return _gvn.transform(new IfFalseNode(iff)); }312313Node* AddI(Node* l, Node* r) { return _gvn.transform(new AddINode(l, r)); }314Node* SubI(Node* l, Node* r) { return _gvn.transform(new SubINode(l, r)); }315Node* MulI(Node* l, Node* r) { return _gvn.transform(new MulINode(l, r)); }316Node* DivI(Node* ctl, Node* l, Node* r) { return _gvn.transform(new DivINode(ctl, l, r)); }317318Node* AndI(Node* l, Node* r) { return _gvn.transform(new AndINode(l, r)); }319Node* OrI(Node* l, Node* r) { return _gvn.transform(new OrINode(l, r)); }320Node* XorI(Node* l, Node* r) { return _gvn.transform(new XorINode(l, r)); }321322Node* MaxI(Node* l, Node* r) { return _gvn.transform(new MaxINode(l, r)); }323Node* MinI(Node* l, Node* r) { return _gvn.transform(new MinINode(l, r)); }324325Node* LShiftI(Node* l, Node* r) { return _gvn.transform(new LShiftINode(l, r)); }326Node* RShiftI(Node* l, Node* r) { return _gvn.transform(new RShiftINode(l, r)); }327Node* URShiftI(Node* l, Node* r) { return _gvn.transform(new URShiftINode(l, r)); }328329Node* CmpI(Node* l, Node* r) { return _gvn.transform(new CmpINode(l, r)); }330Node* CmpL(Node* l, Node* r) { return _gvn.transform(new CmpLNode(l, r)); }331Node* CmpP(Node* l, Node* r) { return _gvn.transform(new CmpPNode(l, r)); }332Node* Bool(Node* cmp, BoolTest::mask relop) { return _gvn.transform(new BoolNode(cmp, relop)); }333334Node* AddP(Node* b, Node* a, Node* o) { return _gvn.transform(new AddPNode(b, a, o)); }335336// Convert between int and long, and size_t.337// (See macros ConvI2X, etc., in type.hpp for ConvI2X, etc.)338Node* ConvI2L(Node* offset);339Node* ConvI2UL(Node* offset);340Node* ConvL2I(Node* offset);341// Find out the klass of an object.342Node* load_object_klass(Node* object);343// Find out the length of an array.344Node* load_array_length(Node* array);345346347// Helper function to do a NULL pointer check or ZERO check based on type.348// Throw an exception if a given value is null.349// Return the value cast to not-null.350// Be clever about equivalent dominating null checks.351Node* null_check_common(Node* value, BasicType type,352bool assert_null = false,353Node* *null_control = NULL,354bool speculative = false);355Node* null_check(Node* value, BasicType type = T_OBJECT) {356return null_check_common(value, type, false, NULL, !_gvn.type(value)->speculative_maybe_null());357}358Node* null_check_receiver() {359assert(argument(0)->bottom_type()->isa_ptr(), "must be");360return null_check(argument(0));361}362Node* zero_check_int(Node* value) {363assert(value->bottom_type()->basic_type() == T_INT,364"wrong type: %s", type2name(value->bottom_type()->basic_type()));365return null_check_common(value, T_INT);366}367Node* zero_check_long(Node* value) {368assert(value->bottom_type()->basic_type() == T_LONG,369"wrong type: %s", type2name(value->bottom_type()->basic_type()));370return null_check_common(value, T_LONG);371}372// Throw an uncommon trap if a given value is __not__ null.373// Return the value cast to null, and be clever about dominating checks.374Node* null_assert(Node* value, BasicType type = T_OBJECT) {375return null_check_common(value, type, true, NULL, _gvn.type(value)->speculative_always_null());376}377378// Check if value is null and abort if it is379Node* must_be_not_null(Node* value, bool do_replace_in_map);380381// Null check oop. Return null-path control into (*null_control).382// Return a cast-not-null node which depends on the not-null control.383// If never_see_null, use an uncommon trap (*null_control sees a top).384// The cast is not valid along the null path; keep a copy of the original.385// If safe_for_replace, then we can replace the value with the cast386// in the parsing map (the cast is guaranteed to dominate the map)387Node* null_check_oop(Node* value, Node* *null_control,388bool never_see_null = false,389bool safe_for_replace = false,390bool speculative = false);391392// Check the null_seen bit.393bool seems_never_null(Node* obj, ciProfileData* data, bool& speculating);394395void guard_klass_being_initialized(Node* klass);396void guard_init_thread(Node* klass);397398void clinit_barrier(ciInstanceKlass* ik, ciMethod* context);399400// Check for unique class for receiver at call401ciKlass* profile_has_unique_klass() {402ciCallProfile profile = method()->call_profile_at_bci(bci());403if (profile.count() >= 0 && // no cast failures here404profile.has_receiver(0) &&405profile.morphism() == 1) {406return profile.receiver(0);407}408return NULL;409}410411// record type from profiling with the type system412Node* record_profile_for_speculation(Node* n, ciKlass* exact_kls, ProfilePtrKind ptr_kind);413void record_profiled_arguments_for_speculation(ciMethod* dest_method, Bytecodes::Code bc);414void record_profiled_parameters_for_speculation();415void record_profiled_return_for_speculation();416Node* record_profiled_receiver_for_speculation(Node* n);417418// Use the type profile to narrow an object type.419Node* maybe_cast_profiled_receiver(Node* not_null_obj,420ciKlass* require_klass,421ciKlass* spec,422bool safe_for_replace);423424// Cast obj to type and emit guard unless we had too many traps here already425Node* maybe_cast_profiled_obj(Node* obj,426ciKlass* type,427bool not_null = false);428429// Cast obj to not-null on this path430Node* cast_not_null(Node* obj, bool do_replace_in_map = true);431// Replace all occurrences of one node by another.432void replace_in_map(Node* old, Node* neww);433434void push(Node* n) { map_not_null(); _map->set_stack(_map->_jvms, _sp++ , n); }435Node* pop() { map_not_null(); return _map->stack( _map->_jvms, --_sp ); }436Node* peek(int off = 0) { map_not_null(); return _map->stack( _map->_jvms, _sp - off - 1 ); }437438void push_pair(Node* ldval) {439push(ldval);440push(top()); // the halfword is merely a placeholder441}442void push_pair_local(int i) {443// longs are stored in locals in "push" order444push( local(i+0) ); // the real value445assert(local(i+1) == top(), "");446push(top()); // halfword placeholder447}448Node* pop_pair() {449// the second half is pushed last & popped first; it contains exactly nothing450Node* halfword = pop();451assert(halfword == top(), "");452// the long bits are pushed first & popped last:453return pop();454}455void set_pair_local(int i, Node* lval) {456// longs are stored in locals as a value/half pair (like doubles)457set_local(i+0, lval);458set_local(i+1, top());459}460461// Push the node, which may be zero, one, or two words.462void push_node(BasicType n_type, Node* n) {463int n_size = type2size[n_type];464if (n_size == 1) push( n ); // T_INT, ...465else if (n_size == 2) push_pair( n ); // T_DOUBLE, T_LONG466else { assert(n_size == 0, "must be T_VOID"); }467}468469Node* pop_node(BasicType n_type) {470int n_size = type2size[n_type];471if (n_size == 1) return pop();472else if (n_size == 2) return pop_pair();473else return NULL;474}475476Node* control() const { return map_not_null()->control(); }477Node* i_o() const { return map_not_null()->i_o(); }478Node* returnadr() const { return map_not_null()->returnadr(); }479Node* frameptr() const { return map_not_null()->frameptr(); }480Node* local(uint idx) const { map_not_null(); return _map->local( _map->_jvms, idx); }481Node* stack(uint idx) const { map_not_null(); return _map->stack( _map->_jvms, idx); }482Node* argument(uint idx) const { map_not_null(); return _map->argument( _map->_jvms, idx); }483Node* monitor_box(uint idx) const { map_not_null(); return _map->monitor_box(_map->_jvms, idx); }484Node* monitor_obj(uint idx) const { map_not_null(); return _map->monitor_obj(_map->_jvms, idx); }485486void set_control (Node* c) { map_not_null()->set_control(c); }487void set_i_o (Node* c) { map_not_null()->set_i_o(c); }488void set_local(uint idx, Node* c) { map_not_null(); _map->set_local( _map->_jvms, idx, c); }489void set_stack(uint idx, Node* c) { map_not_null(); _map->set_stack( _map->_jvms, idx, c); }490void set_argument(uint idx, Node* c){ map_not_null(); _map->set_argument(_map->_jvms, idx, c); }491void ensure_stack(uint stk_size) { map_not_null(); _map->ensure_stack(_map->_jvms, stk_size); }492493// Access unaliased memory494Node* memory(uint alias_idx);495Node* memory(const TypePtr *tp) { return memory(C->get_alias_index(tp)); }496Node* memory(Node* adr) { return memory(_gvn.type(adr)->is_ptr()); }497498// Access immutable memory499Node* immutable_memory() { return C->immutable_memory(); }500501// Set unaliased memory502void set_memory(Node* c, uint alias_idx) { merged_memory()->set_memory_at(alias_idx, c); }503void set_memory(Node* c, const TypePtr *tp) { set_memory(c,C->get_alias_index(tp)); }504void set_memory(Node* c, Node* adr) { set_memory(c,_gvn.type(adr)->is_ptr()); }505506// Get the entire memory state (probably a MergeMemNode), and reset it507// (The resetting prevents somebody from using the dangling Node pointer.)508Node* reset_memory();509510// Get the entire memory state, asserted to be a MergeMemNode.511MergeMemNode* merged_memory() {512Node* mem = map_not_null()->memory();513assert(mem->is_MergeMem(), "parse memory is always pre-split");514return mem->as_MergeMem();515}516517// Set the entire memory state; produce a new MergeMemNode.518void set_all_memory(Node* newmem);519520// Create a memory projection from the call, then set_all_memory.521void set_all_memory_call(Node* call, bool separate_io_proj = false);522523// Create a LoadNode, reading from the parser's memory state.524// (Note: require_atomic_access is useful only with T_LONG.)525//526// We choose the unordered semantics by default because we have527// adapted the `do_put_xxx' and `do_get_xxx' procedures for the case528// of volatile fields.529Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt,530MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,531bool require_atomic_access = false, bool unaligned = false,532bool mismatched = false, bool unsafe = false, uint8_t barrier_data = 0) {533// This version computes alias_index from bottom_type534return make_load(ctl, adr, t, bt, adr->bottom_type()->is_ptr(),535mo, control_dependency, require_atomic_access,536unaligned, mismatched, unsafe, barrier_data);537}538Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, const TypePtr* adr_type,539MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,540bool require_atomic_access = false, bool unaligned = false,541bool mismatched = false, bool unsafe = false, uint8_t barrier_data = 0) {542// This version computes alias_index from an address type543assert(adr_type != NULL, "use other make_load factory");544return make_load(ctl, adr, t, bt, C->get_alias_index(adr_type),545mo, control_dependency, require_atomic_access,546unaligned, mismatched, unsafe, barrier_data);547}548// This is the base version which is given an alias index.549Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, int adr_idx,550MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,551bool require_atomic_access = false, bool unaligned = false,552bool mismatched = false, bool unsafe = false, uint8_t barrier_data = 0);553554// Create & transform a StoreNode and store the effect into the555// parser's memory state.556//557// We must ensure that stores of object references will be visible558// only after the object's initialization. So the clients of this559// procedure must indicate that the store requires `release'560// semantics, if the stored value is an object reference that might561// point to a new object and may become externally visible.562Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,563const TypePtr* adr_type,564MemNode::MemOrd mo,565bool require_atomic_access = false,566bool unaligned = false,567bool mismatched = false,568bool unsafe = false) {569// This version computes alias_index from an address type570assert(adr_type != NULL, "use other store_to_memory factory");571return store_to_memory(ctl, adr, val, bt,572C->get_alias_index(adr_type),573mo, require_atomic_access,574unaligned, mismatched, unsafe);575}576// This is the base version which is given alias index577// Return the new StoreXNode578Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,579int adr_idx,580MemNode::MemOrd,581bool require_atomic_access = false,582bool unaligned = false,583bool mismatched = false,584bool unsafe = false);585586// Perform decorated accesses587588Node* access_store_at(Node* obj, // containing obj589Node* adr, // actual adress to store val at590const TypePtr* adr_type,591Node* val,592const Type* val_type,593BasicType bt,594DecoratorSet decorators);595596Node* access_load_at(Node* obj, // containing obj597Node* adr, // actual adress to load val at598const TypePtr* adr_type,599const Type* val_type,600BasicType bt,601DecoratorSet decorators);602603Node* access_load(Node* adr, // actual adress to load val at604const Type* val_type,605BasicType bt,606DecoratorSet decorators);607608Node* access_atomic_cmpxchg_val_at(Node* obj,609Node* adr,610const TypePtr* adr_type,611int alias_idx,612Node* expected_val,613Node* new_val,614const Type* value_type,615BasicType bt,616DecoratorSet decorators);617618Node* access_atomic_cmpxchg_bool_at(Node* obj,619Node* adr,620const TypePtr* adr_type,621int alias_idx,622Node* expected_val,623Node* new_val,624const Type* value_type,625BasicType bt,626DecoratorSet decorators);627628Node* access_atomic_xchg_at(Node* obj,629Node* adr,630const TypePtr* adr_type,631int alias_idx,632Node* new_val,633const Type* value_type,634BasicType bt,635DecoratorSet decorators);636637Node* access_atomic_add_at(Node* obj,638Node* adr,639const TypePtr* adr_type,640int alias_idx,641Node* new_val,642const Type* value_type,643BasicType bt,644DecoratorSet decorators);645646void access_clone(Node* src, Node* dst, Node* size, bool is_array);647648// Return addressing for an array element.649Node* array_element_address(Node* ary, Node* idx, BasicType elembt,650// Optional constraint on the array size:651const TypeInt* sizetype = NULL,652// Optional control dependency (for example, on range check)653Node* ctrl = NULL);654655// Return a load of array element at idx.656Node* load_array_element(Node* ctl, Node* ary, Node* idx, const TypeAryPtr* arytype);657658//---------------- Dtrace support --------------------659void make_dtrace_method_entry_exit(ciMethod* method, bool is_entry);660void make_dtrace_method_entry(ciMethod* method) {661make_dtrace_method_entry_exit(method, true);662}663void make_dtrace_method_exit(ciMethod* method) {664make_dtrace_method_entry_exit(method, false);665}666667//--------------- stub generation -------------------668public:669void gen_stub(address C_function,670const char *name,671int is_fancy_jump,672bool pass_tls,673bool return_pc);674675//---------- help for generating calls --------------676677// Do a null check on the receiver as it would happen before the call to678// callee (with all arguments still on the stack).679Node* null_check_receiver_before_call(ciMethod* callee) {680assert(!callee->is_static(), "must be a virtual method");681// Callsite signature can be different from actual method being called (i.e _linkTo* sites).682// Use callsite signature always.683ciMethod* declared_method = method()->get_method_at_bci(bci());684const int nargs = declared_method->arg_size();685inc_sp(nargs);686Node* n = null_check_receiver();687dec_sp(nargs);688return n;689}690691// Fill in argument edges for the call from argument(0), argument(1), ...692// (The next step is to call set_edges_for_java_call.)693void set_arguments_for_java_call(CallJavaNode* call);694695// Fill in non-argument edges for the call.696// Transform the call, and update the basics: control, i_o, memory.697// (The next step is usually to call set_results_for_java_call.)698void set_edges_for_java_call(CallJavaNode* call,699bool must_throw = false, bool separate_io_proj = false);700701// Finish up a java call that was started by set_edges_for_java_call.702// Call add_exception on any throw arising from the call.703// Return the call result (transformed).704Node* set_results_for_java_call(CallJavaNode* call, bool separate_io_proj = false, bool deoptimize = false);705706// Similar to set_edges_for_java_call, but simplified for runtime calls.707void set_predefined_output_for_runtime_call(Node* call) {708set_predefined_output_for_runtime_call(call, NULL, NULL);709}710void set_predefined_output_for_runtime_call(Node* call,711Node* keep_mem,712const TypePtr* hook_mem);713Node* set_predefined_input_for_runtime_call(SafePointNode* call, Node* narrow_mem = NULL);714715// Replace the call with the current state of the kit. Requires716// that the call was generated with separate io_projs so that717// exceptional control flow can be handled properly.718void replace_call(CallNode* call, Node* result, bool do_replaced_nodes = false);719720// helper functions for statistics721void increment_counter(address counter_addr); // increment a debug counter722void increment_counter(Node* counter_addr); // increment a debug counter723724// Bail out to the interpreter right now725// The optional klass is the one causing the trap.726// The optional reason is debug information written to the compile log.727// Optional must_throw is the same as with add_safepoint_edges.728void uncommon_trap(int trap_request,729ciKlass* klass = NULL, const char* reason_string = NULL,730bool must_throw = false, bool keep_exact_action = false);731732// Shorthand, to avoid saying "Deoptimization::" so many times.733void uncommon_trap(Deoptimization::DeoptReason reason,734Deoptimization::DeoptAction action,735ciKlass* klass = NULL, const char* reason_string = NULL,736bool must_throw = false, bool keep_exact_action = false) {737uncommon_trap(Deoptimization::make_trap_request(reason, action),738klass, reason_string, must_throw, keep_exact_action);739}740741// Bail out to the interpreter and keep exact action (avoid switching to Action_none).742void uncommon_trap_exact(Deoptimization::DeoptReason reason,743Deoptimization::DeoptAction action,744ciKlass* klass = NULL, const char* reason_string = NULL,745bool must_throw = false) {746uncommon_trap(Deoptimization::make_trap_request(reason, action),747klass, reason_string, must_throw, /*keep_exact_action=*/true);748}749750// SP when bytecode needs to be reexecuted.751virtual int reexecute_sp() { return sp(); }752753// Report if there were too many traps at the current method and bci.754// Report if a trap was recorded, and/or PerMethodTrapLimit was exceeded.755// If there is no MDO at all, report no trap unless told to assume it.756bool too_many_traps(Deoptimization::DeoptReason reason) {757return C->too_many_traps(method(), bci(), reason);758}759760// Report if there were too many recompiles at the current method and bci.761bool too_many_recompiles(Deoptimization::DeoptReason reason) {762return C->too_many_recompiles(method(), bci(), reason);763}764765bool too_many_traps_or_recompiles(Deoptimization::DeoptReason reason) {766return C->too_many_traps_or_recompiles(method(), bci(), reason);767}768769// Returns the object (if any) which was created the moment before.770Node* just_allocated_object(Node* current_control);771772// Sync Ideal and Graph kits.773void sync_kit(IdealKit& ideal);774void final_sync(IdealKit& ideal);775776public:777// Helper function to round double arguments before a call778void round_double_arguments(ciMethod* dest_method);779780// rounding for strict float precision conformance781Node* precision_rounding(Node* n);782783// rounding for strict double precision conformance784Node* dprecision_rounding(Node* n);785786// rounding for non-strict double stores787Node* dstore_rounding(Node* n);788789// Helper functions for fast/slow path codes790Node* opt_iff(Node* region, Node* iff);791Node* make_runtime_call(int flags,792const TypeFunc* call_type, address call_addr,793const char* call_name,794const TypePtr* adr_type, // NULL if no memory effects795Node* parm0 = NULL, Node* parm1 = NULL,796Node* parm2 = NULL, Node* parm3 = NULL,797Node* parm4 = NULL, Node* parm5 = NULL,798Node* parm6 = NULL, Node* parm7 = NULL);799800Node* sign_extend_byte(Node* in);801Node* sign_extend_short(Node* in);802803Node* make_native_call(address call_addr, const TypeFunc* call_type, uint nargs, ciNativeEntryPoint* nep);804805enum { // flag values for make_runtime_call806RC_NO_FP = 1, // CallLeafNoFPNode807RC_NO_IO = 2, // do not hook IO edges808RC_NO_LEAF = 4, // CallStaticJavaNode809RC_MUST_THROW = 8, // flag passed to add_safepoint_edges810RC_NARROW_MEM = 16, // input memory is same as output811RC_UNCOMMON = 32, // freq. expected to be like uncommon trap812RC_VECTOR = 64, // CallLeafVectorNode813RC_LEAF = 0 // null value: no flags set814};815816// merge in all memory slices from new_mem, along the given path817void merge_memory(Node* new_mem, Node* region, int new_path);818void make_slow_call_ex(Node* call, ciInstanceKlass* ex_klass, bool separate_io_proj, bool deoptimize = false);819820// Helper functions to build synchronizations821int next_monitor();822Node* insert_mem_bar(int opcode, Node* precedent = NULL);823Node* insert_mem_bar_volatile(int opcode, int alias_idx, Node* precedent = NULL);824// Optional 'precedent' is appended as an extra edge, to force ordering.825FastLockNode* shared_lock(Node* obj);826void shared_unlock(Node* box, Node* obj);827828// helper functions for the fast path/slow path idioms829Node* fast_and_slow(Node* in, const Type *result_type, Node* null_result, IfNode* fast_test, Node* fast_result, address slow_call, const TypeFunc *slow_call_type, Node* slow_arg, Klass* ex_klass, Node* slow_result);830831// Generate an instance-of idiom. Used by both the instance-of bytecode832// and the reflective instance-of call.833Node* gen_instanceof(Node *subobj, Node* superkls, bool safe_for_replace = false);834835// Generate a check-cast idiom. Used by both the check-cast bytecode836// and the array-store bytecode837Node* gen_checkcast( Node *subobj, Node* superkls,838Node* *failure_control = NULL );839840Node* gen_subtype_check(Node* obj, Node* superklass);841842// Exact type check used for predicted calls and casts.843// Rewrites (*casted_receiver) to be casted to the stronger type.844// (Caller is responsible for doing replace_in_map.)845Node* type_check_receiver(Node* receiver, ciKlass* klass, float prob,846Node* *casted_receiver);847848// Inexact type check used for predicted calls.849Node* subtype_check_receiver(Node* receiver, ciKlass* klass,850Node** casted_receiver);851852// implementation of object creation853Node* set_output_for_allocation(AllocateNode* alloc,854const TypeOopPtr* oop_type,855bool deoptimize_on_exception=false);856Node* get_layout_helper(Node* klass_node, jint& constant_value);857Node* new_instance(Node* klass_node,858Node* slow_test = NULL,859Node* *return_size_val = NULL,860bool deoptimize_on_exception = false);861Node* new_array(Node* klass_node, Node* count_val, int nargs,862Node* *return_size_val = NULL,863bool deoptimize_on_exception = false);864865// java.lang.String helpers866Node* load_String_length(Node* str, bool set_ctrl);867Node* load_String_value(Node* str, bool set_ctrl);868Node* load_String_coder(Node* str, bool set_ctrl);869void store_String_value(Node* str, Node* value);870void store_String_coder(Node* str, Node* value);871Node* capture_memory(const TypePtr* src_type, const TypePtr* dst_type);872Node* compress_string(Node* src, const TypeAryPtr* src_type, Node* dst, Node* count);873void inflate_string(Node* src, Node* dst, const TypeAryPtr* dst_type, Node* count);874void inflate_string_slow(Node* src, Node* dst, Node* start, Node* count);875876// Handy for making control flow877IfNode* create_and_map_if(Node* ctrl, Node* tst, float prob, float cnt) {878IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's879_gvn.set_type(iff, iff->Value(&_gvn)); // Value may be known at parse-time880// Place 'if' on worklist if it will be in graph881if (!tst->is_Con()) record_for_igvn(iff); // Range-check and Null-check removal is later882return iff;883}884885IfNode* create_and_xform_if(Node* ctrl, Node* tst, float prob, float cnt) {886IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's887_gvn.transform(iff); // Value may be known at parse-time888// Place 'if' on worklist if it will be in graph889if (!tst->is_Con()) record_for_igvn(iff); // Range-check and Null-check removal is later890return iff;891}892893void add_empty_predicates(int nargs = 0);894void add_empty_predicate_impl(Deoptimization::DeoptReason reason, int nargs);895896Node* make_constant_from_field(ciField* field, Node* obj);897898// Vector API support (implemented in vectorIntrinsics.cpp)899Node* box_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool deoptimize_on_exception = false);900Node* unbox_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool shuffle_to_vector = false);901Node* vector_shift_count(Node* cnt, int shift_op, BasicType bt, int num_elem);902};903904// Helper class to support building of control flow branches. Upon905// creation the map and sp at bci are cloned and restored upon de-906// struction. Typical use:907//908// { PreserveJVMState pjvms(this);909// // code of new branch910// }911// // here the JVM state at bci is established912913class PreserveJVMState: public StackObj {914protected:915GraphKit* _kit;916#ifdef ASSERT917int _block; // PO of current block, if a Parse918int _bci;919#endif920SafePointNode* _map;921uint _sp;922923public:924PreserveJVMState(GraphKit* kit, bool clone_map = true);925~PreserveJVMState();926};927928// Helper class to build cutouts of the form if (p) ; else {x...}.929// The code {x...} must not fall through.930// The kit's main flow of control is set to the "then" continuation of if(p).931class BuildCutout: public PreserveJVMState {932public:933BuildCutout(GraphKit* kit, Node* p, float prob, float cnt = COUNT_UNKNOWN);934~BuildCutout();935};936937// Helper class to preserve the original _reexecute bit and _sp and restore938// them back939class PreserveReexecuteState: public StackObj {940protected:941GraphKit* _kit;942uint _sp;943JVMState::ReexecuteState _reexecute;944945public:946PreserveReexecuteState(GraphKit* kit);947~PreserveReexecuteState();948};949950#endif // SHARE_OPTO_GRAPHKIT_HPP951952953