Path: blob/master/src/hotspot/share/opto/callGenerator.hpp
40930 views
/*1* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_OPTO_CALLGENERATOR_HPP25#define SHARE_OPTO_CALLGENERATOR_HPP2627#include "compiler/compileBroker.hpp"28#include "opto/callnode.hpp"29#include "opto/compile.hpp"30#include "opto/type.hpp"31#include "runtime/deoptimization.hpp"3233//---------------------------CallGenerator-------------------------------------34// The subclasses of this class handle generation of ideal nodes for35// call sites and method entry points.3637class CallGenerator : public ResourceObj {38private:39ciMethod* _method; // The method being called.4041protected:42CallGenerator(ciMethod* method) : _method(method) {}4344void do_late_inline_helper();4546virtual bool do_late_inline_check(Compile* C, JVMState* jvms) { ShouldNotReachHere(); return false; }47virtual CallGenerator* inline_cg() const { ShouldNotReachHere(); return NULL; }48virtual bool is_pure_call() const { ShouldNotReachHere(); return false; }4950public:51// Accessors52ciMethod* method() const { return _method; }5354// is_inline: At least some code implementing the method is copied here.55virtual bool is_inline() const { return false; }56// is_intrinsic: There's a method-specific way of generating the inline code.57virtual bool is_intrinsic() const { return false; }58// is_parse: Bytecodes implementing the specific method are copied here.59virtual bool is_parse() const { return false; }60// is_virtual: The call uses the receiver type to select or check the method.61virtual bool is_virtual() const { return false; }62// is_deferred: The decision whether to inline or not is deferred.63virtual bool is_deferred() const { return false; }64// is_predicated: Uses an explicit check (predicate).65virtual bool is_predicated() const { return false; }66virtual int predicates_count() const { return 0; }67// is_trap: Does not return to the caller. (E.g., uncommon trap.)68virtual bool is_trap() const { return false; }69// does_virtual_dispatch: Should try inlining as normal method first.70virtual bool does_virtual_dispatch() const { return false; }7172// is_late_inline: supports conversion of call into an inline73virtual bool is_late_inline() const { return false; }74// same but for method handle calls75virtual bool is_mh_late_inline() const { return false; }76virtual bool is_boxing_late_inline() const { return false; }77virtual bool is_string_late_inline() const { return false; }78virtual bool is_virtual_late_inline() const { return false; }7980// Replace the call with an inline version of the code81virtual void do_late_inline() { ShouldNotReachHere(); }8283virtual CallNode* call_node() const { return NULL; }84virtual CallGenerator* with_call_node(CallNode* call) { return this; }8586virtual void set_unique_id(jlong id) { fatal("unique id only for late inlines"); };87virtual jlong unique_id() const { fatal("unique id only for late inlines"); return 0; };8889virtual void set_callee_method(ciMethod* callee) { ShouldNotReachHere(); }9091// Note: It is possible for a CG to be both inline and virtual.92// (The hashCode intrinsic does a vtable check and an inlined fast path.)9394// Allocate CallGenerators only in Compile arena since some of them are referenced from CallNodes.95void* operator new(size_t size) throw() {96Compile* C = Compile::current();97return ResourceObj::operator new(size, C->comp_arena());98}99100// Utilities:101const TypeFunc* tf() const;102103// The given jvms has state and arguments for a call to my method.104// Edges after jvms->argoff() carry all (pre-popped) argument values.105//106// Update the map with state and return values (if any) and return it.107// The return values (0, 1, or 2) must be pushed on the map's stack,108// and the sp of the jvms incremented accordingly.109//110// The jvms is returned on success. Alternatively, a copy of the111// given jvms, suitably updated, may be returned, in which case the112// caller should discard the original jvms.113//114// The non-Parm edges of the returned map will contain updated global state,115// and one or two edges before jvms->sp() will carry any return values.116// Other map edges may contain locals or monitors, and should not117// be changed in meaning.118//119// If the call traps, the returned map must have a control edge of top.120// If the call can throw, the returned map must report has_exceptions().121//122// If the result is NULL, it means that this CallGenerator was unable123// to handle the given call, and another CallGenerator should be consulted.124virtual JVMState* generate(JVMState* jvms) = 0;125126// How to generate a call site that is inlined:127static CallGenerator* for_inline(ciMethod* m, float expected_uses = -1);128// How to generate code for an on-stack replacement handler.129static CallGenerator* for_osr(ciMethod* m, int osr_bci);130131// How to generate vanilla out-of-line call sites:132static CallGenerator* for_direct_call(ciMethod* m, bool separate_io_projs = false); // static, special133static CallGenerator* for_virtual_call(ciMethod* m, int vtable_index); // virtual, interface134135static CallGenerator* for_method_handle_call( JVMState* jvms, ciMethod* caller, ciMethod* callee, bool allow_inline);136static CallGenerator* for_method_handle_inline(JVMState* jvms, ciMethod* caller, ciMethod* callee, bool allow_inline, bool& input_not_const);137138// How to generate a replace a direct call with an inline version139static CallGenerator* for_late_inline(ciMethod* m, CallGenerator* inline_cg);140static CallGenerator* for_mh_late_inline(ciMethod* caller, ciMethod* callee, bool input_not_const);141static CallGenerator* for_string_late_inline(ciMethod* m, CallGenerator* inline_cg);142static CallGenerator* for_boxing_late_inline(ciMethod* m, CallGenerator* inline_cg);143static CallGenerator* for_vector_reboxing_late_inline(ciMethod* m, CallGenerator* inline_cg);144static CallGenerator* for_late_inline_virtual(ciMethod* m, int vtable_index, float expected_uses);145146// How to make a call that optimistically assumes a receiver type:147static CallGenerator* for_predicted_call(ciKlass* predicted_receiver,148CallGenerator* if_missed,149CallGenerator* if_hit,150float hit_prob);151152static CallGenerator* for_guarded_call(ciKlass* predicted_receiver,153CallGenerator* if_missed,154CallGenerator* if_hit);155156// How to make a call that optimistically assumes a MethodHandle target:157static CallGenerator* for_predicted_dynamic_call(ciMethodHandle* predicted_method_handle,158CallGenerator* if_missed,159CallGenerator* if_hit,160float hit_prob);161162// How to make a call that gives up and goes back to the interpreter:163static CallGenerator* for_uncommon_trap(ciMethod* m,164Deoptimization::DeoptReason reason,165Deoptimization::DeoptAction action);166167// Registry for intrinsics:168static CallGenerator* for_intrinsic(ciMethod* m);169static void register_intrinsic(ciMethod* m, CallGenerator* cg);170static CallGenerator* for_predicated_intrinsic(CallGenerator* intrinsic,171CallGenerator* cg);172virtual Node* generate_predicate(JVMState* jvms, int predicate) { return NULL; };173174virtual void print_inlining_late(const char* msg) { ShouldNotReachHere(); }175176static void print_inlining(Compile* C, ciMethod* callee, int inline_level, int bci, const char* msg) {177if (C->print_inlining()) {178C->print_inlining(callee, inline_level, bci, msg);179}180}181182static void print_inlining_failure(Compile* C, ciMethod* callee, int inline_level, int bci, const char* msg) {183print_inlining(C, callee, inline_level, bci, msg);184C->log_inline_failure(msg);185}186187static bool is_inlined_method_handle_intrinsic(JVMState* jvms, ciMethod* m);188static bool is_inlined_method_handle_intrinsic(ciMethod* caller, int bci, ciMethod* m);189static bool is_inlined_method_handle_intrinsic(ciMethod* symbolic_info, ciMethod* m);190};191192193//------------------------InlineCallGenerator----------------------------------194class InlineCallGenerator : public CallGenerator {195protected:196InlineCallGenerator(ciMethod* method) : CallGenerator(method) {}197198public:199virtual bool is_inline() const { return true; }200};201202#endif // SHARE_OPTO_CALLGENERATOR_HPP203204205