Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/opto/graphKit.hpp
32285 views
/*1* Copyright (c) 2001, 2013, 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_VM_OPTO_GRAPHKIT_HPP25#define SHARE_VM_OPTO_GRAPHKIT_HPP2627#include "ci/ciEnv.hpp"28#include "ci/ciMethodData.hpp"29#include "opto/addnode.hpp"30#include "opto/callnode.hpp"31#include "opto/cfgnode.hpp"32#include "opto/compile.hpp"33#include "opto/divnode.hpp"34#include "opto/mulnode.hpp"35#include "opto/phaseX.hpp"36#include "opto/subnode.hpp"37#include "opto/type.hpp"38#include "runtime/deoptimization.hpp"3940class FastLockNode;41class FastUnlockNode;42class IdealKit;43class LibraryCallKit;44class Parse;45class RootNode;4647//-----------------------------------------------------------------------------48//----------------------------GraphKit-----------------------------------------49// Toolkit for building the common sorts of subgraphs.50// Does not know about bytecode parsing or type-flow results.51// It is able to create graphs implementing the semantics of most52// or all bytecodes, so that it can expand intrinsics and calls.53// It may depend on JVMState structure, but it must not depend54// on specific bytecode streams.55class GraphKit : public Phase {56friend class PreserveJVMState;5758protected:59ciEnv* _env; // Compilation environment60PhaseGVN &_gvn; // Some optimizations while parsing61SafePointNode* _map; // Parser map from JVM to Nodes62SafePointNode* _exceptions;// Parser map(s) for exception state(s)63int _bci; // JVM Bytecode Pointer64ciMethod* _method; // JVM Current Method6566private:67int _sp; // JVM Expression Stack Pointer; don't modify directly!6869private:70SafePointNode* map_not_null() const {71assert(_map != NULL, "must call stopped() to test for reset compiler map");72return _map;73}7475public:76GraphKit(); // empty constructor77GraphKit(JVMState* jvms); // the JVM state on which to operate7879#ifdef ASSERT80~GraphKit() {81assert(!has_exceptions(), "user must call transfer_exceptions_into_jvms");82}83#endif8485virtual Parse* is_Parse() const { return NULL; }86virtual LibraryCallKit* is_LibraryCallKit() const { return NULL; }8788ciEnv* env() const { return _env; }89PhaseGVN& gvn() const { return _gvn; }9091void record_for_igvn(Node* n) const { C->record_for_igvn(n); } // delegate to Compile9293// Handy well-known nodes:94Node* null() const { return zerocon(T_OBJECT); }95Node* top() const { return C->top(); }96RootNode* root() const { return C->root(); }9798// Create or find a constant node99Node* intcon(jint con) const { return _gvn.intcon(con); }100Node* longcon(jlong con) const { return _gvn.longcon(con); }101Node* makecon(const Type *t) const { return _gvn.makecon(t); }102Node* zerocon(BasicType bt) const { return _gvn.zerocon(bt); }103// (See also macro MakeConX in type.hpp, which uses intcon or longcon.)104105// Helper for byte_map_base106Node* byte_map_base_node() {107// Get base of card map108CardTableModRefBS* ct = (CardTableModRefBS*)(Universe::heap()->barrier_set());109assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust users of this code");110if (ct->byte_map_base != NULL) {111return makecon(TypeRawPtr::make((address)ct->byte_map_base));112} else {113return null();114}115}116117jint find_int_con(Node* n, jint value_if_unknown) {118return _gvn.find_int_con(n, value_if_unknown);119}120jlong find_long_con(Node* n, jlong value_if_unknown) {121return _gvn.find_long_con(n, value_if_unknown);122}123// (See also macro find_intptr_t_con in type.hpp, which uses one of these.)124125// JVM State accessors:126// Parser mapping from JVM indices into Nodes.127// Low slots are accessed by the StartNode::enum.128// Then come the locals at StartNode::Parms to StartNode::Parms+max_locals();129// Then come JVM stack slots.130// Finally come the monitors, if any.131// See layout accessors in class JVMState.132133SafePointNode* map() const { return _map; }134bool has_exceptions() const { return _exceptions != NULL; }135JVMState* jvms() const { return map_not_null()->_jvms; }136int sp() const { return _sp; }137int bci() const { return _bci; }138Bytecodes::Code java_bc() const;139ciMethod* method() const { return _method; }140141void set_jvms(JVMState* jvms) { set_map(jvms->map());142assert(jvms == this->jvms(), "sanity");143_sp = jvms->sp();144_bci = jvms->bci();145_method = jvms->has_method() ? jvms->method() : NULL; }146void set_map(SafePointNode* m) { _map = m; debug_only(verify_map()); }147void set_sp(int sp) { assert(sp >= 0, err_msg_res("sp must be non-negative: %d", sp)); _sp = sp; }148void clean_stack(int from_sp); // clear garbage beyond from_sp to top149150void inc_sp(int i) { set_sp(sp() + i); }151void dec_sp(int i) { set_sp(sp() - i); }152void set_bci(int bci) { _bci = bci; }153154// Make sure jvms has current bci & sp.155JVMState* sync_jvms() const;156JVMState* sync_jvms_for_reexecute();157158#ifdef ASSERT159// Make sure JVMS has an updated copy of bci and sp.160// Also sanity-check method, depth, and monitor depth.161bool jvms_in_sync() const;162163// Make sure the map looks OK.164void verify_map() const;165166// Make sure a proposed exception state looks OK.167static void verify_exception_state(SafePointNode* ex_map);168#endif169170// Clone the existing map state. (Implements PreserveJVMState.)171SafePointNode* clone_map();172173// Set the map to a clone of the given one.174void set_map_clone(SafePointNode* m);175176// Tell if the compilation is failing.177bool failing() const { return C->failing(); }178179// Set _map to NULL, signalling a stop to further bytecode execution.180// Preserve the map intact for future use, and return it back to the caller.181SafePointNode* stop() { SafePointNode* m = map(); set_map(NULL); return m; }182183// Stop, but first smash the map's inputs to NULL, to mark it dead.184void stop_and_kill_map();185186// Tell if _map is NULL, or control is top.187bool stopped();188189// Tell if this method or any caller method has exception handlers.190bool has_ex_handler();191192// Save an exception without blowing stack contents or other JVM state.193// (The extra pointer is stuck with add_req on the map, beyond the JVMS.)194static void set_saved_ex_oop(SafePointNode* ex_map, Node* ex_oop);195196// Recover a saved exception from its map.197static Node* saved_ex_oop(SafePointNode* ex_map);198199// Recover a saved exception from its map, and remove it from the map.200static Node* clear_saved_ex_oop(SafePointNode* ex_map);201202#ifdef ASSERT203// Recover a saved exception from its map, and remove it from the map.204static bool has_saved_ex_oop(SafePointNode* ex_map);205#endif206207// Push an exception in the canonical position for handlers (stack(0)).208void push_ex_oop(Node* ex_oop) {209ensure_stack(1); // ensure room to push the exception210set_stack(0, ex_oop);211set_sp(1);212clean_stack(1);213}214215// Detach and return an exception state.216SafePointNode* pop_exception_state() {217SafePointNode* ex_map = _exceptions;218if (ex_map != NULL) {219_exceptions = ex_map->next_exception();220ex_map->set_next_exception(NULL);221debug_only(verify_exception_state(ex_map));222}223return ex_map;224}225226// Add an exception, using the given JVM state, without commoning.227void push_exception_state(SafePointNode* ex_map) {228debug_only(verify_exception_state(ex_map));229ex_map->set_next_exception(_exceptions);230_exceptions = ex_map;231}232233// Turn the current JVM state into an exception state, appending the ex_oop.234SafePointNode* make_exception_state(Node* ex_oop);235236// Add an exception, using the given JVM state.237// Combine all exceptions with a common exception type into a single state.238// (This is done via combine_exception_states.)239void add_exception_state(SafePointNode* ex_map);240241// Combine all exceptions of any sort whatever into a single master state.242SafePointNode* combine_and_pop_all_exception_states() {243if (_exceptions == NULL) return NULL;244SafePointNode* phi_map = pop_exception_state();245SafePointNode* ex_map;246while ((ex_map = pop_exception_state()) != NULL) {247combine_exception_states(ex_map, phi_map);248}249return phi_map;250}251252// Combine the two exception states, building phis as necessary.253// The second argument is updated to include contributions from the first.254void combine_exception_states(SafePointNode* ex_map, SafePointNode* phi_map);255256// Reset the map to the given state. If there are any half-finished phis257// in it (created by combine_exception_states), transform them now.258// Returns the exception oop. (Caller must call push_ex_oop if required.)259Node* use_exception_state(SafePointNode* ex_map);260261// Collect exceptions from a given JVM state into my exception list.262void add_exception_states_from(JVMState* jvms);263264// Collect all raised exceptions into the current JVM state.265// Clear the current exception list and map, returns the combined states.266JVMState* transfer_exceptions_into_jvms();267268// Helper to throw a built-in exception.269// Range checks take the offending index.270// Cast and array store checks take the offending class.271// Others do not take the optional argument.272// The JVMS must allow the bytecode to be re-executed273// via an uncommon trap.274void builtin_throw(Deoptimization::DeoptReason reason, Node* arg = NULL);275276// Helper to check the JavaThread::_should_post_on_exceptions flag277// and branch to an uncommon_trap if it is true (with the specified reason and must_throw)278void uncommon_trap_if_should_post_on_exceptions(Deoptimization::DeoptReason reason,279bool must_throw) ;280281// Helper Functions for adding debug information282void kill_dead_locals();283#ifdef ASSERT284bool dead_locals_are_killed();285#endif286// The call may deoptimize. Supply required JVM state as debug info.287// If must_throw is true, the call is guaranteed not to return normally.288void add_safepoint_edges(SafePointNode* call,289bool must_throw = false);290291// How many stack inputs does the current BC consume?292// And, how does the stack change after the bytecode?293// Returns false if unknown.294bool compute_stack_effects(int& inputs, int& depth);295296// Add a fixed offset to a pointer297Node* basic_plus_adr(Node* base, Node* ptr, intptr_t offset) {298return basic_plus_adr(base, ptr, MakeConX(offset));299}300Node* basic_plus_adr(Node* base, intptr_t offset) {301return basic_plus_adr(base, base, MakeConX(offset));302}303// Add a variable offset to a pointer304Node* basic_plus_adr(Node* base, Node* offset) {305return basic_plus_adr(base, base, offset);306}307Node* basic_plus_adr(Node* base, Node* ptr, Node* offset);308309310// Some convenient shortcuts for common nodes311Node* IfTrue(IfNode* iff) { return _gvn.transform(new (C) IfTrueNode(iff)); }312Node* IfFalse(IfNode* iff) { return _gvn.transform(new (C) IfFalseNode(iff)); }313314Node* AddI(Node* l, Node* r) { return _gvn.transform(new (C) AddINode(l, r)); }315Node* SubI(Node* l, Node* r) { return _gvn.transform(new (C) SubINode(l, r)); }316Node* MulI(Node* l, Node* r) { return _gvn.transform(new (C) MulINode(l, r)); }317Node* DivI(Node* ctl, Node* l, Node* r) { return _gvn.transform(new (C) DivINode(ctl, l, r)); }318319Node* AndI(Node* l, Node* r) { return _gvn.transform(new (C) AndINode(l, r)); }320Node* OrI(Node* l, Node* r) { return _gvn.transform(new (C) OrINode(l, r)); }321Node* XorI(Node* l, Node* r) { return _gvn.transform(new (C) XorINode(l, r)); }322323Node* MaxI(Node* l, Node* r) { return _gvn.transform(new (C) MaxINode(l, r)); }324Node* MinI(Node* l, Node* r) { return _gvn.transform(new (C) MinINode(l, r)); }325326Node* LShiftI(Node* l, Node* r) { return _gvn.transform(new (C) LShiftINode(l, r)); }327Node* RShiftI(Node* l, Node* r) { return _gvn.transform(new (C) RShiftINode(l, r)); }328Node* URShiftI(Node* l, Node* r) { return _gvn.transform(new (C) URShiftINode(l, r)); }329330Node* CmpI(Node* l, Node* r) { return _gvn.transform(new (C) CmpINode(l, r)); }331Node* CmpL(Node* l, Node* r) { return _gvn.transform(new (C) CmpLNode(l, r)); }332Node* CmpP(Node* l, Node* r) { return _gvn.transform(new (C) CmpPNode(l, r)); }333Node* Bool(Node* cmp, BoolTest::mask relop) { return _gvn.transform(new (C) BoolNode(cmp, relop)); }334335Node* AddP(Node* b, Node* a, Node* o) { return _gvn.transform(new (C) AddPNode(b, a, o)); }336337// Convert between int and long, and size_t.338// (See macros ConvI2X, etc., in type.hpp for ConvI2X, etc.)339Node* ConvI2L(Node* offset);340Node* ConvI2UL(Node* offset);341Node* ConvL2I(Node* offset);342// Find out the klass of an object.343Node* load_object_klass(Node* object);344// Find out the length of an array.345Node* load_array_length(Node* array);346347348// Helper function to do a NULL pointer check or ZERO check based on type.349// Throw an exception if a given value is null.350// Return the value cast to not-null.351// Be clever about equivalent dominating null checks.352Node* null_check_common(Node* value, BasicType type,353bool assert_null = false, Node* *null_control = NULL);354Node* null_check(Node* value, BasicType type = T_OBJECT) {355return null_check_common(value, type);356}357Node* null_check_receiver() {358assert(argument(0)->bottom_type()->isa_ptr(), "must be");359return null_check(argument(0));360}361Node* zero_check_int(Node* value) {362assert(value->bottom_type()->basic_type() == T_INT,363err_msg_res("wrong type: %s", type2name(value->bottom_type()->basic_type())));364return null_check_common(value, T_INT);365}366Node* zero_check_long(Node* value) {367assert(value->bottom_type()->basic_type() == T_LONG,368err_msg_res("wrong type: %s", type2name(value->bottom_type()->basic_type())));369return null_check_common(value, T_LONG);370}371// Throw an uncommon trap if a given value is __not__ null.372// Return the value cast to null, and be clever about dominating checks.373Node* null_assert(Node* value, BasicType type = T_OBJECT) {374return null_check_common(value, type, true);375}376377// Null check oop. Return null-path control into (*null_control).378// Return a cast-not-null node which depends on the not-null control.379// If never_see_null, use an uncommon trap (*null_control sees a top).380// The cast is not valid along the null path; keep a copy of the original.381// If safe_for_replace, then we can replace the value with the cast382// in the parsing map (the cast is guaranteed to dominate the map)383Node* null_check_oop(Node* value, Node* *null_control,384bool never_see_null = false, bool safe_for_replace = false);385386// Check the null_seen bit.387bool seems_never_null(Node* obj, ciProfileData* data);388389// Check for unique class for receiver at call390ciKlass* profile_has_unique_klass() {391ciCallProfile profile = method()->call_profile_at_bci(bci());392if (profile.count() >= 0 && // no cast failures here393profile.has_receiver(0) &&394profile.morphism() == 1) {395return profile.receiver(0);396}397return NULL;398}399400// record type from profiling with the type system401Node* record_profile_for_speculation(Node* n, ciKlass* exact_kls);402Node* record_profiled_receiver_for_speculation(Node* n);403void record_profiled_arguments_for_speculation(ciMethod* dest_method, Bytecodes::Code bc);404void record_profiled_parameters_for_speculation();405406// Use the type profile to narrow an object type.407Node* maybe_cast_profiled_receiver(Node* not_null_obj,408ciKlass* require_klass,409ciKlass* spec,410bool safe_for_replace);411412// Cast obj to type and emit guard unless we had too many traps here already413Node* maybe_cast_profiled_obj(Node* obj,414ciKlass* type,415bool not_null = false);416417// Cast obj to not-null on this path418Node* cast_not_null(Node* obj, bool do_replace_in_map = true);419// Replace all occurrences of one node by another.420void replace_in_map(Node* old, Node* neww);421422void push(Node* n) { map_not_null(); _map->set_stack(_map->_jvms, _sp++ , n); }423Node* pop() { map_not_null(); return _map->stack( _map->_jvms, --_sp ); }424Node* peek(int off = 0) { map_not_null(); return _map->stack( _map->_jvms, _sp - off - 1 ); }425426void push_pair(Node* ldval) {427push(ldval);428push(top()); // the halfword is merely a placeholder429}430void push_pair_local(int i) {431// longs are stored in locals in "push" order432push( local(i+0) ); // the real value433assert(local(i+1) == top(), "");434push(top()); // halfword placeholder435}436Node* pop_pair() {437// the second half is pushed last & popped first; it contains exactly nothing438Node* halfword = pop();439assert(halfword == top(), "");440// the long bits are pushed first & popped last:441return pop();442}443void set_pair_local(int i, Node* lval) {444// longs are stored in locals as a value/half pair (like doubles)445set_local(i+0, lval);446set_local(i+1, top());447}448449// Push the node, which may be zero, one, or two words.450void push_node(BasicType n_type, Node* n) {451int n_size = type2size[n_type];452if (n_size == 1) push( n ); // T_INT, ...453else if (n_size == 2) push_pair( n ); // T_DOUBLE, T_LONG454else { assert(n_size == 0, "must be T_VOID"); }455}456457Node* pop_node(BasicType n_type) {458int n_size = type2size[n_type];459if (n_size == 1) return pop();460else if (n_size == 2) return pop_pair();461else return NULL;462}463464Node* control() const { return map_not_null()->control(); }465Node* i_o() const { return map_not_null()->i_o(); }466Node* returnadr() const { return map_not_null()->returnadr(); }467Node* frameptr() const { return map_not_null()->frameptr(); }468Node* local(uint idx) const { map_not_null(); return _map->local( _map->_jvms, idx); }469Node* stack(uint idx) const { map_not_null(); return _map->stack( _map->_jvms, idx); }470Node* argument(uint idx) const { map_not_null(); return _map->argument( _map->_jvms, idx); }471Node* monitor_box(uint idx) const { map_not_null(); return _map->monitor_box(_map->_jvms, idx); }472Node* monitor_obj(uint idx) const { map_not_null(); return _map->monitor_obj(_map->_jvms, idx); }473474void set_control (Node* c) { map_not_null()->set_control(c); }475void set_i_o (Node* c) { map_not_null()->set_i_o(c); }476void set_local(uint idx, Node* c) { map_not_null(); _map->set_local( _map->_jvms, idx, c); }477void set_stack(uint idx, Node* c) { map_not_null(); _map->set_stack( _map->_jvms, idx, c); }478void set_argument(uint idx, Node* c){ map_not_null(); _map->set_argument(_map->_jvms, idx, c); }479void ensure_stack(uint stk_size) { map_not_null(); _map->ensure_stack(_map->_jvms, stk_size); }480481// Access unaliased memory482Node* memory(uint alias_idx);483Node* memory(const TypePtr *tp) { return memory(C->get_alias_index(tp)); }484Node* memory(Node* adr) { return memory(_gvn.type(adr)->is_ptr()); }485486// Access immutable memory487Node* immutable_memory() { return C->immutable_memory(); }488489// Set unaliased memory490void set_memory(Node* c, uint alias_idx) { merged_memory()->set_memory_at(alias_idx, c); }491void set_memory(Node* c, const TypePtr *tp) { set_memory(c,C->get_alias_index(tp)); }492void set_memory(Node* c, Node* adr) { set_memory(c,_gvn.type(adr)->is_ptr()); }493494// Get the entire memory state (probably a MergeMemNode), and reset it495// (The resetting prevents somebody from using the dangling Node pointer.)496Node* reset_memory();497498// Get the entire memory state, asserted to be a MergeMemNode.499MergeMemNode* merged_memory() {500Node* mem = map_not_null()->memory();501assert(mem->is_MergeMem(), "parse memory is always pre-split");502return mem->as_MergeMem();503}504505// Set the entire memory state; produce a new MergeMemNode.506void set_all_memory(Node* newmem);507508// Create a memory projection from the call, then set_all_memory.509void set_all_memory_call(Node* call, bool separate_io_proj = false);510511// Create a LoadNode, reading from the parser's memory state.512// (Note: require_atomic_access is useful only with T_LONG.)513//514// We choose the unordered semantics by default because we have515// adapted the `do_put_xxx' and `do_get_xxx' procedures for the case516// of volatile fields.517Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt,518MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,519bool require_atomic_access = false, bool unaligned = false,520bool mismatched = false) {521// This version computes alias_index from bottom_type522return make_load(ctl, adr, t, bt, adr->bottom_type()->is_ptr(),523mo, control_dependency, require_atomic_access,524unaligned, mismatched);525}526Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, const TypePtr* adr_type,527MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,528bool require_atomic_access = false, bool unaligned = false,529bool mismatched = false) {530// This version computes alias_index from an address type531assert(adr_type != NULL, "use other make_load factory");532return make_load(ctl, adr, t, bt, C->get_alias_index(adr_type),533mo, control_dependency, require_atomic_access,534unaligned, mismatched);535}536// This is the base version which is given an alias index.537Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, int adr_idx,538MemNode::MemOrd mo, LoadNode::ControlDependency control_dependency = LoadNode::DependsOnlyOnTest,539bool require_atomic_access = false, bool unaligned = false,540bool mismatched = false);541542// Create & transform a StoreNode and store the effect into the543// parser's memory state.544//545// We must ensure that stores of object references will be visible546// only after the object's initialization. So the clients of this547// procedure must indicate that the store requires `release'548// semantics, if the stored value is an object reference that might549// point to a new object and may become externally visible.550Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,551const TypePtr* adr_type,552MemNode::MemOrd mo,553bool require_atomic_access = false,554bool unaligned = false,555bool mismatched = false) {556// This version computes alias_index from an address type557assert(adr_type != NULL, "use other store_to_memory factory");558return store_to_memory(ctl, adr, val, bt,559C->get_alias_index(adr_type),560mo, require_atomic_access,561unaligned, mismatched);562}563// This is the base version which is given alias index564// Return the new StoreXNode565Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,566int adr_idx,567MemNode::MemOrd,568bool require_atomic_access = false,569bool unaligned = false,570bool mismatched = false);571572573// All in one pre-barrier, store, post_barrier574// Insert a write-barrier'd store. This is to let generational GC575// work; we have to flag all oop-stores before the next GC point.576//577// It comes in 3 flavors of store to an object, array, or unknown.578// We use precise card marks for arrays to avoid scanning the entire579// array. We use imprecise for object. We use precise for unknown580// since we don't know if we have an array or and object or even581// where the object starts.582//583// If val==NULL, it is taken to be a completely unknown value. QQQ584585Node* store_oop(Node* ctl,586Node* obj, // containing obj587Node* adr, // actual adress to store val at588const TypePtr* adr_type,589Node* val,590const TypeOopPtr* val_type,591BasicType bt,592bool use_precise,593MemNode::MemOrd mo,594bool mismatched = false);595596Node* store_oop_to_object(Node* ctl,597Node* obj, // containing obj598Node* adr, // actual adress to store val at599const TypePtr* adr_type,600Node* val,601const TypeOopPtr* val_type,602BasicType bt,603MemNode::MemOrd mo) {604return store_oop(ctl, obj, adr, adr_type, val, val_type, bt, false, mo);605}606607Node* store_oop_to_array(Node* ctl,608Node* obj, // containing obj609Node* adr, // actual adress to store val at610const TypePtr* adr_type,611Node* val,612const TypeOopPtr* val_type,613BasicType bt,614MemNode::MemOrd mo) {615return store_oop(ctl, obj, adr, adr_type, val, val_type, bt, true, mo);616}617618// Could be an array or object we don't know at compile time (unsafe ref.)619Node* store_oop_to_unknown(Node* ctl,620Node* obj, // containing obj621Node* adr, // actual adress to store val at622const TypePtr* adr_type,623Node* val,624BasicType bt,625MemNode::MemOrd mo,626bool mismatched = false);627628// For the few case where the barriers need special help629void pre_barrier(bool do_load, Node* ctl,630Node* obj, Node* adr, uint adr_idx, Node* val, const TypeOopPtr* val_type,631Node* pre_val,632BasicType bt);633634void post_barrier(Node* ctl, Node* store, Node* obj, Node* adr, uint adr_idx,635Node* val, BasicType bt, bool use_precise);636637// Return addressing for an array element.638Node* array_element_address(Node* ary, Node* idx, BasicType elembt,639// Optional constraint on the array size:640const TypeInt* sizetype = NULL,641// Optional control dependency (for example, on range check)642Node* ctrl = NULL);643644// Return a load of array element at idx.645Node* load_array_element(Node* ctl, Node* ary, Node* idx, const TypeAryPtr* arytype);646647//---------------- Dtrace support --------------------648void make_dtrace_method_entry_exit(ciMethod* method, bool is_entry);649void make_dtrace_method_entry(ciMethod* method) {650make_dtrace_method_entry_exit(method, true);651}652void make_dtrace_method_exit(ciMethod* method) {653make_dtrace_method_entry_exit(method, false);654}655656//--------------- stub generation -------------------657public:658void gen_stub(address C_function,659const char *name,660int is_fancy_jump,661bool pass_tls,662bool return_pc);663664//---------- help for generating calls --------------665666// Do a null check on the receiver as it would happen before the call to667// callee (with all arguments still on the stack).668Node* null_check_receiver_before_call(ciMethod* callee) {669assert(!callee->is_static(), "must be a virtual method");670// Callsite signature can be different from actual method being called (i.e _linkTo* sites).671// Use callsite signature always.672ciMethod* declared_method = method()->get_method_at_bci(bci());673const int nargs = declared_method->arg_size();674inc_sp(nargs);675Node* n = null_check_receiver();676dec_sp(nargs);677return n;678}679680// Fill in argument edges for the call from argument(0), argument(1), ...681// (The next step is to call set_edges_for_java_call.)682void set_arguments_for_java_call(CallJavaNode* call);683684// Fill in non-argument edges for the call.685// Transform the call, and update the basics: control, i_o, memory.686// (The next step is usually to call set_results_for_java_call.)687void set_edges_for_java_call(CallJavaNode* call,688bool must_throw = false, bool separate_io_proj = false);689690// Finish up a java call that was started by set_edges_for_java_call.691// Call add_exception on any throw arising from the call.692// Return the call result (transformed).693Node* set_results_for_java_call(CallJavaNode* call, bool separate_io_proj = false);694695// Similar to set_edges_for_java_call, but simplified for runtime calls.696void set_predefined_output_for_runtime_call(Node* call) {697set_predefined_output_for_runtime_call(call, NULL, NULL);698}699void set_predefined_output_for_runtime_call(Node* call,700Node* keep_mem,701const TypePtr* hook_mem);702Node* set_predefined_input_for_runtime_call(SafePointNode* call, Node* narrow_mem = NULL);703704// Replace the call with the current state of the kit. Requires705// that the call was generated with separate io_projs so that706// exceptional control flow can be handled properly.707void replace_call(CallNode* call, Node* result, bool do_replaced_nodes = false);708709// helper functions for statistics710void increment_counter(address counter_addr); // increment a debug counter711void increment_counter(Node* counter_addr); // increment a debug counter712713// Bail out to the interpreter right now714// The optional klass is the one causing the trap.715// The optional reason is debug information written to the compile log.716// Optional must_throw is the same as with add_safepoint_edges.717void uncommon_trap(int trap_request,718ciKlass* klass = NULL, const char* reason_string = NULL,719bool must_throw = false, bool keep_exact_action = false);720721// Shorthand, to avoid saying "Deoptimization::" so many times.722void uncommon_trap(Deoptimization::DeoptReason reason,723Deoptimization::DeoptAction action,724ciKlass* klass = NULL, const char* reason_string = NULL,725bool must_throw = false, bool keep_exact_action = false) {726uncommon_trap(Deoptimization::make_trap_request(reason, action),727klass, reason_string, must_throw, keep_exact_action);728}729730// Bail out to the interpreter and keep exact action (avoid switching to Action_none).731void uncommon_trap_exact(Deoptimization::DeoptReason reason,732Deoptimization::DeoptAction action,733ciKlass* klass = NULL, const char* reason_string = NULL,734bool must_throw = false) {735uncommon_trap(Deoptimization::make_trap_request(reason, action),736klass, reason_string, must_throw, /*keep_exact_action=*/true);737}738739// SP when bytecode needs to be reexecuted.740virtual int reexecute_sp() { return sp(); }741742// Report if there were too many traps at the current method and bci.743// Report if a trap was recorded, and/or PerMethodTrapLimit was exceeded.744// If there is no MDO at all, report no trap unless told to assume it.745bool too_many_traps(Deoptimization::DeoptReason reason) {746return C->too_many_traps(method(), bci(), reason);747}748749// Report if there were too many recompiles at the current method and bci.750bool too_many_recompiles(Deoptimization::DeoptReason reason) {751return C->too_many_recompiles(method(), bci(), reason);752}753754// Returns the object (if any) which was created the moment before.755Node* just_allocated_object(Node* current_control);756757static bool use_ReduceInitialCardMarks() {758return (ReduceInitialCardMarks759&& Universe::heap()->can_elide_tlab_store_barriers());760}761762// Sync Ideal and Graph kits.763void sync_kit(IdealKit& ideal);764void final_sync(IdealKit& ideal);765766// vanilla/CMS post barrier767void write_barrier_post(Node *store, Node* obj,768Node* adr, uint adr_idx, Node* val, bool use_precise);769770// Allow reordering of pre-barrier with oop store and/or post-barrier.771// Used for load_store operations which loads old value.772bool can_move_pre_barrier() const;773774// G1 pre/post barriers775void g1_write_barrier_pre(bool do_load,776Node* obj,777Node* adr,778uint alias_idx,779Node* val,780const TypeOopPtr* val_type,781Node* pre_val,782BasicType bt);783784void g1_write_barrier_post(Node* store,785Node* obj,786Node* adr,787uint alias_idx,788Node* val,789BasicType bt,790bool use_precise);791// Helper function for g1792private:793void g1_mark_card(IdealKit& ideal, Node* card_adr, Node* store, uint oop_alias_idx,794Node* index, Node* index_adr,795Node* buffer, const TypeFunc* tf);796797public:798// Helper function to round double arguments before a call799void round_double_arguments(ciMethod* dest_method);800void round_double_result(ciMethod* dest_method);801802// rounding for strict float precision conformance803Node* precision_rounding(Node* n);804805// rounding for strict double precision conformance806Node* dprecision_rounding(Node* n);807808// rounding for non-strict double stores809Node* dstore_rounding(Node* n);810811// Helper functions for fast/slow path codes812Node* opt_iff(Node* region, Node* iff);813Node* make_runtime_call(int flags,814const TypeFunc* call_type, address call_addr,815const char* call_name,816const TypePtr* adr_type, // NULL if no memory effects817Node* parm0 = NULL, Node* parm1 = NULL,818Node* parm2 = NULL, Node* parm3 = NULL,819Node* parm4 = NULL, Node* parm5 = NULL,820Node* parm6 = NULL, Node* parm7 = NULL);821enum { // flag values for make_runtime_call822RC_NO_FP = 1, // CallLeafNoFPNode823RC_NO_IO = 2, // do not hook IO edges824RC_NO_LEAF = 4, // CallStaticJavaNode825RC_MUST_THROW = 8, // flag passed to add_safepoint_edges826RC_NARROW_MEM = 16, // input memory is same as output827RC_UNCOMMON = 32, // freq. expected to be like uncommon trap828RC_LEAF = 0 // null value: no flags set829};830831// merge in all memory slices from new_mem, along the given path832void merge_memory(Node* new_mem, Node* region, int new_path);833void make_slow_call_ex(Node* call, ciInstanceKlass* ex_klass, bool separate_io_proj, bool deoptimize = false);834835// Helper functions to build synchronizations836int next_monitor();837Node* insert_mem_bar(int opcode, Node* precedent = NULL);838Node* insert_mem_bar_volatile(int opcode, int alias_idx, Node* precedent = NULL);839// Optional 'precedent' is appended as an extra edge, to force ordering.840FastLockNode* shared_lock(Node* obj);841void shared_unlock(Node* box, Node* obj);842843// helper functions for the fast path/slow path idioms844Node* 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);845846// Generate an instance-of idiom. Used by both the instance-of bytecode847// and the reflective instance-of call.848Node* gen_instanceof(Node *subobj, Node* superkls, bool safe_for_replace = false);849850// Generate a check-cast idiom. Used by both the check-cast bytecode851// and the array-store bytecode852Node* gen_checkcast( Node *subobj, Node* superkls,853Node* *failure_control = NULL );854855// Generate a subtyping check. Takes as input the subtype and supertype.856// Returns 2 values: sets the default control() to the true path and857// returns the false path. Only reads from constant memory taken from the858// default memory; does not write anything. It also doesn't take in an859// Object; if you wish to check an Object you need to load the Object's860// class prior to coming here.861Node* gen_subtype_check(Node* subklass, Node* superklass);862863// Static parse-time type checking logic for gen_subtype_check:864enum { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };865int static_subtype_check(ciKlass* superk, ciKlass* subk);866867// Exact type check used for predicted calls and casts.868// Rewrites (*casted_receiver) to be casted to the stronger type.869// (Caller is responsible for doing replace_in_map.)870Node* type_check_receiver(Node* receiver, ciKlass* klass, float prob,871Node* *casted_receiver);872873// implementation of object creation874Node* set_output_for_allocation(AllocateNode* alloc,875const TypeOopPtr* oop_type,876bool deoptimize_on_exception=false);877Node* get_layout_helper(Node* klass_node, jint& constant_value);878Node* new_instance(Node* klass_node,879Node* slow_test = NULL,880Node* *return_size_val = NULL,881bool deoptimize_on_exception = false);882Node* new_array(Node* klass_node, Node* count_val, int nargs,883Node* *return_size_val = NULL,884bool deoptimize_on_exception = false);885886// java.lang.String helpers887Node* load_String_offset(Node* ctrl, Node* str);888Node* load_String_length(Node* ctrl, Node* str);889Node* load_String_value(Node* ctrl, Node* str);890void store_String_offset(Node* ctrl, Node* str, Node* value);891void store_String_length(Node* ctrl, Node* str, Node* value);892void store_String_value(Node* ctrl, Node* str, Node* value);893894// Handy for making control flow895IfNode* create_and_map_if(Node* ctrl, Node* tst, float prob, float cnt) {896IfNode* iff = new (C) IfNode(ctrl, tst, prob, cnt);// New IfNode's897_gvn.set_type(iff, iff->Value(&_gvn)); // Value may be known at parse-time898// Place 'if' on worklist if it will be in graph899if (!tst->is_Con()) record_for_igvn(iff); // Range-check and Null-check removal is later900return iff;901}902903IfNode* create_and_xform_if(Node* ctrl, Node* tst, float prob, float cnt) {904IfNode* iff = new (C) IfNode(ctrl, tst, prob, cnt);// New IfNode's905_gvn.transform(iff); // Value may be known at parse-time906// Place 'if' on worklist if it will be in graph907if (!tst->is_Con()) record_for_igvn(iff); // Range-check and Null-check removal is later908return iff;909}910911// Insert a loop predicate into the graph912void add_predicate(int nargs = 0);913void add_predicate_impl(Deoptimization::DeoptReason reason, int nargs);914915// Produce new array node of stable type916Node* cast_array_to_stable(Node* ary, const TypeAryPtr* ary_type);917};918919// Helper class to support building of control flow branches. Upon920// creation the map and sp at bci are cloned and restored upon de-921// struction. Typical use:922//923// { PreserveJVMState pjvms(this);924// // code of new branch925// }926// // here the JVM state at bci is established927928class PreserveJVMState: public StackObj {929protected:930GraphKit* _kit;931#ifdef ASSERT932int _block; // PO of current block, if a Parse933int _bci;934#endif935SafePointNode* _map;936uint _sp;937938public:939PreserveJVMState(GraphKit* kit, bool clone_map = true);940~PreserveJVMState();941};942943// Helper class to build cutouts of the form if (p) ; else {x...}.944// The code {x...} must not fall through.945// The kit's main flow of control is set to the "then" continuation of if(p).946class BuildCutout: public PreserveJVMState {947public:948BuildCutout(GraphKit* kit, Node* p, float prob, float cnt = COUNT_UNKNOWN);949~BuildCutout();950};951952// Helper class to preserve the original _reexecute bit and _sp and restore953// them back954class PreserveReexecuteState: public StackObj {955protected:956GraphKit* _kit;957uint _sp;958JVMState::ReexecuteState _reexecute;959960public:961PreserveReexecuteState(GraphKit* kit);962~PreserveReexecuteState();963};964965#endif // SHARE_VM_OPTO_GRAPHKIT_HPP966967968