Path: blob/master/src/hotspot/share/opto/graphKit.hpp
64441 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);345// Cast array allocation's length as narrow as possible.346// If replace_length_in_map is true, replace length with CastIINode in map.347// This method is invoked after creating/moving ArrayAllocationNode or in load_array_length348Node* array_ideal_length(AllocateArrayNode* alloc,349const TypeOopPtr* oop_type,350bool replace_length_in_map);351352353// Helper function to do a NULL pointer check or ZERO check based on type.354// Throw an exception if a given value is null.355// Return the value cast to not-null.356// Be clever about equivalent dominating null checks.357Node* null_check_common(Node* value, BasicType type,358bool assert_null = false,359Node* *null_control = NULL,360bool speculative = false);361Node* null_check(Node* value, BasicType type = T_OBJECT) {362return null_check_common(value, type, false, NULL, !_gvn.type(value)->speculative_maybe_null());363}364Node* null_check_receiver() {365assert(argument(0)->bottom_type()->isa_ptr(), "must be");366return null_check(argument(0));367}368Node* zero_check_int(Node* value) {369assert(value->bottom_type()->basic_type() == T_INT,370"wrong type: %s", type2name(value->bottom_type()->basic_type()));371return null_check_common(value, T_INT);372}373Node* zero_check_long(Node* value) {374assert(value->bottom_type()->basic_type() == T_LONG,375"wrong type: %s", type2name(value->bottom_type()->basic_type()));376return null_check_common(value, T_LONG);377}378// Throw an uncommon trap if a given value is __not__ null.379// Return the value cast to null, and be clever about dominating checks.380Node* null_assert(Node* value, BasicType type = T_OBJECT) {381return null_check_common(value, type, true, NULL, _gvn.type(value)->speculative_always_null());382}383384// Check if value is null and abort if it is385Node* must_be_not_null(Node* value, bool do_replace_in_map);386387// Null check oop. Return null-path control into (*null_control).388// Return a cast-not-null node which depends on the not-null control.389// If never_see_null, use an uncommon trap (*null_control sees a top).390// The cast is not valid along the null path; keep a copy of the original.391// If safe_for_replace, then we can replace the value with the cast392// in the parsing map (the cast is guaranteed to dominate the map)393Node* null_check_oop(Node* value, Node* *null_control,394bool never_see_null = false,395bool safe_for_replace = false,396bool speculative = false);397398// Check the null_seen bit.399bool seems_never_null(Node* obj, ciProfileData* data, bool& speculating);400401void guard_klass_being_initialized(Node* klass);402void guard_init_thread(Node* klass);403404void clinit_barrier(ciInstanceKlass* ik, ciMethod* context);405406// Check for unique class for receiver at call407ciKlass* profile_has_unique_klass() {408ciCallProfile profile = method()->call_profile_at_bci(bci());409if (profile.count() >= 0 && // no cast failures here410profile.has_receiver(0) &&411profile.morphism() == 1) {412return profile.receiver(0);413}414return NULL;415}416417// record type from profiling with the type system418Node* record_profile_for_speculation(Node* n, ciKlass* exact_kls, ProfilePtrKind ptr_kind);419void record_profiled_arguments_for_speculation(ciMethod* dest_method, Bytecodes::Code bc);420void record_profiled_parameters_for_speculation();421void record_profiled_return_for_speculation();422Node* record_profiled_receiver_for_speculation(Node* n);423424// Use the type profile to narrow an object type.425Node* maybe_cast_profiled_receiver(Node* not_null_obj,426ciKlass* require_klass,427ciKlass* spec,428bool safe_for_replace);429430// Cast obj to type and emit guard unless we had too many traps here already431Node* maybe_cast_profiled_obj(Node* obj,432ciKlass* type,433bool not_null = false);434435// Cast obj to not-null on this path436Node* cast_not_null(Node* obj, bool do_replace_in_map = true);437// Replace all occurrences of one node by another.438void replace_in_map(Node* old, Node* neww);439440void push(Node* n) { map_not_null(); _map->set_stack(_map->_jvms, _sp++ , n); }441Node* pop() { map_not_null(); return _map->stack( _map->_jvms, --_sp ); }442Node* peek(int off = 0) { map_not_null(); return _map->stack( _map->_jvms, _sp - off - 1 ); }443444void push_pair(Node* ldval) {445push(ldval);446push(top()); // the halfword is merely a placeholder447}448void push_pair_local(int i) {449// longs are stored in locals in "push" order450push( local(i+0) ); // the real value451assert(local(i+1) == top(), "");452push(top()); // halfword placeholder453}454Node* pop_pair() {455// the second half is pushed last & popped first; it contains exactly nothing456Node* halfword = pop();457assert(halfword == top(), "");458// the long bits are pushed first & popped last:459return pop();460}461void set_pair_local(int i, Node* lval) {462// longs are stored in locals as a value/half pair (like doubles)463set_local(i+0, lval);464set_local(i+1, top());465}466467// Push the node, which may be zero, one, or two words.468void push_node(BasicType n_type, Node* n) {469int n_size = type2size[n_type];470if (n_size == 1) push( n ); // T_INT, ...471else if (n_size == 2) push_pair( n ); // T_DOUBLE, T_LONG472else { assert(n_size == 0, "must be T_VOID"); }473}474475Node* pop_node(BasicType n_type) {476int n_size = type2size[n_type];477if (n_size == 1) return pop();478else if (n_size == 2) return pop_pair();479else return NULL;480}481482Node* control() const { return map_not_null()->control(); }483Node* i_o() const { return map_not_null()->i_o(); }484Node* returnadr() const { return map_not_null()->returnadr(); }485Node* frameptr() const { return map_not_null()->frameptr(); }486Node* local(uint idx) const { map_not_null(); return _map->local( _map->_jvms, idx); }487Node* stack(uint idx) const { map_not_null(); return _map->stack( _map->_jvms, idx); }488Node* argument(uint idx) const { map_not_null(); return _map->argument( _map->_jvms, idx); }489Node* monitor_box(uint idx) const { map_not_null(); return _map->monitor_box(_map->_jvms, idx); }490Node* monitor_obj(uint idx) const { map_not_null(); return _map->monitor_obj(_map->_jvms, idx); }491492void set_control (Node* c) { map_not_null()->set_control(c); }493void set_i_o (Node* c) { map_not_null()->set_i_o(c); }494void set_local(uint idx, Node* c) { map_not_null(); _map->set_local( _map->_jvms, idx, c); }495void set_stack(uint idx, Node* c) { map_not_null(); _map->set_stack( _map->_jvms, idx, c); }496void set_argument(uint idx, Node* c){ map_not_null(); _map->set_argument(_map->_jvms, idx, c); }497void ensure_stack(uint stk_size) { map_not_null(); _map->ensure_stack(_map->_jvms, stk_size); }498499// Access unaliased memory500Node* memory(uint alias_idx);501Node* memory(const TypePtr *tp) { return memory(C->get_alias_index(tp)); }502Node* memory(Node* adr) { return memory(_gvn.type(adr)->is_ptr()); }503504// Access immutable memory505Node* immutable_memory() { return C->immutable_memory(); }506507// Set unaliased memory508void set_memory(Node* c, uint alias_idx) { merged_memory()->set_memory_at(alias_idx, c); }509void set_memory(Node* c, const TypePtr *tp) { set_memory(c,C->get_alias_index(tp)); }510void set_memory(Node* c, Node* adr) { set_memory(c,_gvn.type(adr)->is_ptr()); }511512// Get the entire memory state (probably a MergeMemNode), and reset it513// (The resetting prevents somebody from using the dangling Node pointer.)514Node* reset_memory();515516// Get the entire memory state, asserted to be a MergeMemNode.517MergeMemNode* merged_memory() {518Node* mem = map_not_null()->memory();519assert(mem->is_MergeMem(), "parse memory is always pre-split");520return mem->as_MergeMem();521}522523// Set the entire memory state; produce a new MergeMemNode.524void set_all_memory(Node* newmem);525526// Create a memory projection from the call, then set_all_memory.527void set_all_memory_call(Node* call, bool separate_io_proj = false);528529// Create a LoadNode, reading from the parser's memory state.530// (Note: require_atomic_access is useful only with T_LONG.)531//532// We choose the unordered semantics by default because we have533// adapted the `do_put_xxx' and `do_get_xxx' procedures for the case534// of volatile fields.535Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt,536MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,537bool require_atomic_access = false, bool unaligned = false,538bool mismatched = false, bool unsafe = false, uint8_t barrier_data = 0) {539// This version computes alias_index from bottom_type540return make_load(ctl, adr, t, bt, adr->bottom_type()->is_ptr(),541mo, control_dependency, require_atomic_access,542unaligned, mismatched, unsafe, barrier_data);543}544Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, const TypePtr* adr_type,545MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,546bool require_atomic_access = false, bool unaligned = false,547bool mismatched = false, bool unsafe = false, uint8_t barrier_data = 0) {548// This version computes alias_index from an address type549assert(adr_type != NULL, "use other make_load factory");550return make_load(ctl, adr, t, bt, C->get_alias_index(adr_type),551mo, control_dependency, require_atomic_access,552unaligned, mismatched, unsafe, barrier_data);553}554// This is the base version which is given an alias index.555Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, int adr_idx,556MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,557bool require_atomic_access = false, bool unaligned = false,558bool mismatched = false, bool unsafe = false, uint8_t barrier_data = 0);559560// Create & transform a StoreNode and store the effect into the561// parser's memory state.562//563// We must ensure that stores of object references will be visible564// only after the object's initialization. So the clients of this565// procedure must indicate that the store requires `release'566// semantics, if the stored value is an object reference that might567// point to a new object and may become externally visible.568Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,569const TypePtr* adr_type,570MemNode::MemOrd mo,571bool require_atomic_access = false,572bool unaligned = false,573bool mismatched = false,574bool unsafe = false) {575// This version computes alias_index from an address type576assert(adr_type != NULL, "use other store_to_memory factory");577return store_to_memory(ctl, adr, val, bt,578C->get_alias_index(adr_type),579mo, require_atomic_access,580unaligned, mismatched, unsafe);581}582// This is the base version which is given alias index583// Return the new StoreXNode584Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,585int adr_idx,586MemNode::MemOrd,587bool require_atomic_access = false,588bool unaligned = false,589bool mismatched = false,590bool unsafe = false);591592// Perform decorated accesses593594Node* access_store_at(Node* obj, // containing obj595Node* adr, // actual adress to store val at596const TypePtr* adr_type,597Node* val,598const Type* val_type,599BasicType bt,600DecoratorSet decorators);601602Node* access_load_at(Node* obj, // containing obj603Node* adr, // actual adress to load val at604const TypePtr* adr_type,605const Type* val_type,606BasicType bt,607DecoratorSet decorators);608609Node* access_load(Node* adr, // actual adress to load val at610const Type* val_type,611BasicType bt,612DecoratorSet decorators);613614Node* access_atomic_cmpxchg_val_at(Node* obj,615Node* adr,616const TypePtr* adr_type,617int alias_idx,618Node* expected_val,619Node* new_val,620const Type* value_type,621BasicType bt,622DecoratorSet decorators);623624Node* access_atomic_cmpxchg_bool_at(Node* obj,625Node* adr,626const TypePtr* adr_type,627int alias_idx,628Node* expected_val,629Node* new_val,630const Type* value_type,631BasicType bt,632DecoratorSet decorators);633634Node* access_atomic_xchg_at(Node* obj,635Node* adr,636const TypePtr* adr_type,637int alias_idx,638Node* new_val,639const Type* value_type,640BasicType bt,641DecoratorSet decorators);642643Node* access_atomic_add_at(Node* obj,644Node* adr,645const TypePtr* adr_type,646int alias_idx,647Node* new_val,648const Type* value_type,649BasicType bt,650DecoratorSet decorators);651652void access_clone(Node* src, Node* dst, Node* size, bool is_array);653654// Return addressing for an array element.655Node* array_element_address(Node* ary, Node* idx, BasicType elembt,656// Optional constraint on the array size:657const TypeInt* sizetype = NULL,658// Optional control dependency (for example, on range check)659Node* ctrl = NULL);660661// Return a load of array element at idx.662Node* load_array_element(Node* ary, Node* idx, const TypeAryPtr* arytype, bool set_ctrl);663664//---------------- Dtrace support --------------------665void make_dtrace_method_entry_exit(ciMethod* method, bool is_entry);666void make_dtrace_method_entry(ciMethod* method) {667make_dtrace_method_entry_exit(method, true);668}669void make_dtrace_method_exit(ciMethod* method) {670make_dtrace_method_entry_exit(method, false);671}672673//--------------- stub generation -------------------674public:675void gen_stub(address C_function,676const char *name,677int is_fancy_jump,678bool pass_tls,679bool return_pc);680681//---------- help for generating calls --------------682683// Do a null check on the receiver as it would happen before the call to684// callee (with all arguments still on the stack).685Node* null_check_receiver_before_call(ciMethod* callee) {686assert(!callee->is_static(), "must be a virtual method");687// Callsite signature can be different from actual method being called (i.e _linkTo* sites).688// Use callsite signature always.689ciMethod* declared_method = method()->get_method_at_bci(bci());690const int nargs = declared_method->arg_size();691inc_sp(nargs);692Node* n = null_check_receiver();693dec_sp(nargs);694return n;695}696697// Fill in argument edges for the call from argument(0), argument(1), ...698// (The next step is to call set_edges_for_java_call.)699void set_arguments_for_java_call(CallJavaNode* call);700701// Fill in non-argument edges for the call.702// Transform the call, and update the basics: control, i_o, memory.703// (The next step is usually to call set_results_for_java_call.)704void set_edges_for_java_call(CallJavaNode* call,705bool must_throw = false, bool separate_io_proj = false);706707// Finish up a java call that was started by set_edges_for_java_call.708// Call add_exception on any throw arising from the call.709// Return the call result (transformed).710Node* set_results_for_java_call(CallJavaNode* call, bool separate_io_proj = false, bool deoptimize = false);711712// Similar to set_edges_for_java_call, but simplified for runtime calls.713void set_predefined_output_for_runtime_call(Node* call) {714set_predefined_output_for_runtime_call(call, NULL, NULL);715}716void set_predefined_output_for_runtime_call(Node* call,717Node* keep_mem,718const TypePtr* hook_mem);719Node* set_predefined_input_for_runtime_call(SafePointNode* call, Node* narrow_mem = NULL);720721// Replace the call with the current state of the kit. Requires722// that the call was generated with separate io_projs so that723// exceptional control flow can be handled properly.724void replace_call(CallNode* call, Node* result, bool do_replaced_nodes = false);725726// helper functions for statistics727void increment_counter(address counter_addr); // increment a debug counter728void increment_counter(Node* counter_addr); // increment a debug counter729730// Bail out to the interpreter right now731// The optional klass is the one causing the trap.732// The optional reason is debug information written to the compile log.733// Optional must_throw is the same as with add_safepoint_edges.734void uncommon_trap(int trap_request,735ciKlass* klass = NULL, const char* reason_string = NULL,736bool must_throw = false, bool keep_exact_action = false);737738// Shorthand, to avoid saying "Deoptimization::" so many times.739void uncommon_trap(Deoptimization::DeoptReason reason,740Deoptimization::DeoptAction action,741ciKlass* klass = NULL, const char* reason_string = NULL,742bool must_throw = false, bool keep_exact_action = false) {743uncommon_trap(Deoptimization::make_trap_request(reason, action),744klass, reason_string, must_throw, keep_exact_action);745}746747// Bail out to the interpreter and keep exact action (avoid switching to Action_none).748void uncommon_trap_exact(Deoptimization::DeoptReason reason,749Deoptimization::DeoptAction action,750ciKlass* klass = NULL, const char* reason_string = NULL,751bool must_throw = false) {752uncommon_trap(Deoptimization::make_trap_request(reason, action),753klass, reason_string, must_throw, /*keep_exact_action=*/true);754}755756// SP when bytecode needs to be reexecuted.757virtual int reexecute_sp() { return sp(); }758759// Report if there were too many traps at the current method and bci.760// Report if a trap was recorded, and/or PerMethodTrapLimit was exceeded.761// If there is no MDO at all, report no trap unless told to assume it.762bool too_many_traps(Deoptimization::DeoptReason reason) {763return C->too_many_traps(method(), bci(), reason);764}765766// Report if there were too many recompiles at the current method and bci.767bool too_many_recompiles(Deoptimization::DeoptReason reason) {768return C->too_many_recompiles(method(), bci(), reason);769}770771bool too_many_traps_or_recompiles(Deoptimization::DeoptReason reason) {772return C->too_many_traps_or_recompiles(method(), bci(), reason);773}774775// Returns the object (if any) which was created the moment before.776Node* just_allocated_object(Node* current_control);777778// Sync Ideal and Graph kits.779void sync_kit(IdealKit& ideal);780void final_sync(IdealKit& ideal);781782public:783// Helper function to round double arguments before a call784void round_double_arguments(ciMethod* dest_method);785786// rounding for strict float precision conformance787Node* precision_rounding(Node* n);788789// rounding for strict double precision conformance790Node* dprecision_rounding(Node* n);791792// rounding for non-strict double stores793Node* dstore_rounding(Node* n);794795// Helper functions for fast/slow path codes796Node* opt_iff(Node* region, Node* iff);797Node* make_runtime_call(int flags,798const TypeFunc* call_type, address call_addr,799const char* call_name,800const TypePtr* adr_type, // NULL if no memory effects801Node* parm0 = NULL, Node* parm1 = NULL,802Node* parm2 = NULL, Node* parm3 = NULL,803Node* parm4 = NULL, Node* parm5 = NULL,804Node* parm6 = NULL, Node* parm7 = NULL);805806Node* sign_extend_byte(Node* in);807Node* sign_extend_short(Node* in);808809Node* make_native_call(address call_addr, const TypeFunc* call_type, uint nargs, ciNativeEntryPoint* nep);810811enum { // flag values for make_runtime_call812RC_NO_FP = 1, // CallLeafNoFPNode813RC_NO_IO = 2, // do not hook IO edges814RC_NO_LEAF = 4, // CallStaticJavaNode815RC_MUST_THROW = 8, // flag passed to add_safepoint_edges816RC_NARROW_MEM = 16, // input memory is same as output817RC_UNCOMMON = 32, // freq. expected to be like uncommon trap818RC_VECTOR = 64, // CallLeafVectorNode819RC_LEAF = 0 // null value: no flags set820};821822// merge in all memory slices from new_mem, along the given path823void merge_memory(Node* new_mem, Node* region, int new_path);824void make_slow_call_ex(Node* call, ciInstanceKlass* ex_klass, bool separate_io_proj, bool deoptimize = false);825826// Helper functions to build synchronizations827int next_monitor();828Node* insert_mem_bar(int opcode, Node* precedent = NULL);829Node* insert_mem_bar_volatile(int opcode, int alias_idx, Node* precedent = NULL);830// Optional 'precedent' is appended as an extra edge, to force ordering.831FastLockNode* shared_lock(Node* obj);832void shared_unlock(Node* box, Node* obj);833834// helper functions for the fast path/slow path idioms835Node* 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);836837// Generate an instance-of idiom. Used by both the instance-of bytecode838// and the reflective instance-of call.839Node* gen_instanceof(Node *subobj, Node* superkls, bool safe_for_replace = false);840841// Generate a check-cast idiom. Used by both the check-cast bytecode842// and the array-store bytecode843Node* gen_checkcast( Node *subobj, Node* superkls,844Node* *failure_control = NULL );845846Node* gen_subtype_check(Node* obj, Node* superklass);847848// Exact type check used for predicted calls and casts.849// Rewrites (*casted_receiver) to be casted to the stronger type.850// (Caller is responsible for doing replace_in_map.)851Node* type_check_receiver(Node* receiver, ciKlass* klass, float prob,852Node* *casted_receiver);853854// Inexact type check used for predicted calls.855Node* subtype_check_receiver(Node* receiver, ciKlass* klass,856Node** casted_receiver);857858// implementation of object creation859Node* set_output_for_allocation(AllocateNode* alloc,860const TypeOopPtr* oop_type,861bool deoptimize_on_exception=false);862Node* get_layout_helper(Node* klass_node, jint& constant_value);863Node* new_instance(Node* klass_node,864Node* slow_test = NULL,865Node* *return_size_val = NULL,866bool deoptimize_on_exception = false);867Node* new_array(Node* klass_node, Node* count_val, int nargs,868Node* *return_size_val = NULL,869bool deoptimize_on_exception = false);870871// java.lang.String helpers872Node* load_String_length(Node* str, bool set_ctrl);873Node* load_String_value(Node* str, bool set_ctrl);874Node* load_String_coder(Node* str, bool set_ctrl);875void store_String_value(Node* str, Node* value);876void store_String_coder(Node* str, Node* value);877Node* capture_memory(const TypePtr* src_type, const TypePtr* dst_type);878Node* compress_string(Node* src, const TypeAryPtr* src_type, Node* dst, Node* count);879void inflate_string(Node* src, Node* dst, const TypeAryPtr* dst_type, Node* count);880void inflate_string_slow(Node* src, Node* dst, Node* start, Node* count);881882// Handy for making control flow883IfNode* create_and_map_if(Node* ctrl, Node* tst, float prob, float cnt) {884IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's885_gvn.set_type(iff, iff->Value(&_gvn)); // Value may be known at parse-time886// Place 'if' on worklist if it will be in graph887if (!tst->is_Con()) record_for_igvn(iff); // Range-check and Null-check removal is later888return iff;889}890891IfNode* create_and_xform_if(Node* ctrl, Node* tst, float prob, float cnt) {892IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's893_gvn.transform(iff); // Value may be known at parse-time894// Place 'if' on worklist if it will be in graph895if (!tst->is_Con()) record_for_igvn(iff); // Range-check and Null-check removal is later896return iff;897}898899void add_empty_predicates(int nargs = 0);900void add_empty_predicate_impl(Deoptimization::DeoptReason reason, int nargs);901902Node* make_constant_from_field(ciField* field, Node* obj);903904// Vector API support (implemented in vectorIntrinsics.cpp)905Node* box_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool deoptimize_on_exception = false);906Node* unbox_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool shuffle_to_vector = false);907Node* vector_shift_count(Node* cnt, int shift_op, BasicType bt, int num_elem);908};909910// Helper class to support building of control flow branches. Upon911// creation the map and sp at bci are cloned and restored upon de-912// struction. Typical use:913//914// { PreserveJVMState pjvms(this);915// // code of new branch916// }917// // here the JVM state at bci is established918919class PreserveJVMState: public StackObj {920protected:921GraphKit* _kit;922#ifdef ASSERT923int _block; // PO of current block, if a Parse924int _bci;925#endif926SafePointNode* _map;927uint _sp;928929public:930PreserveJVMState(GraphKit* kit, bool clone_map = true);931~PreserveJVMState();932};933934// Helper class to build cutouts of the form if (p) ; else {x...}.935// The code {x...} must not fall through.936// The kit's main flow of control is set to the "then" continuation of if(p).937class BuildCutout: public PreserveJVMState {938public:939BuildCutout(GraphKit* kit, Node* p, float prob, float cnt = COUNT_UNKNOWN);940~BuildCutout();941};942943// Helper class to preserve the original _reexecute bit and _sp and restore944// them back945class PreserveReexecuteState: public StackObj {946protected:947GraphKit* _kit;948uint _sp;949JVMState::ReexecuteState _reexecute;950951public:952PreserveReexecuteState(GraphKit* kit);953~PreserveReexecuteState();954};955956#endif // SHARE_OPTO_GRAPHKIT_HPP957958959