src/share/vm/ci/ciMethod.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6723
0bf37f737702
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_CI_CIMETHOD_HPP
aoqi@0 26 #define SHARE_VM_CI_CIMETHOD_HPP
aoqi@0 27
aoqi@0 28 #include "ci/ciFlags.hpp"
aoqi@0 29 #include "ci/ciInstanceKlass.hpp"
aoqi@0 30 #include "ci/ciObject.hpp"
aoqi@0 31 #include "ci/ciSignature.hpp"
aoqi@0 32 #include "compiler/methodLiveness.hpp"
aoqi@0 33 #include "prims/methodHandles.hpp"
aoqi@0 34 #include "utilities/bitMap.hpp"
aoqi@0 35
aoqi@0 36 class ciMethodBlocks;
aoqi@0 37 class MethodLiveness;
aoqi@0 38 class BitMap;
aoqi@0 39 class Arena;
aoqi@0 40 class BCEscapeAnalyzer;
aoqi@0 41
aoqi@0 42
aoqi@0 43 // ciMethod
aoqi@0 44 //
aoqi@0 45 // This class represents a Method* in the HotSpot virtual
aoqi@0 46 // machine.
aoqi@0 47 class ciMethod : public ciMetadata {
aoqi@0 48 friend class CompileBroker;
aoqi@0 49 CI_PACKAGE_ACCESS
aoqi@0 50 friend class ciEnv;
aoqi@0 51 friend class ciExceptionHandlerStream;
aoqi@0 52 friend class ciBytecodeStream;
aoqi@0 53 friend class ciMethodHandle;
aoqi@0 54 friend class ciReplay;
aoqi@0 55
aoqi@0 56 private:
aoqi@0 57 // General method information.
aoqi@0 58 ciFlags _flags;
aoqi@0 59 ciSymbol* _name;
aoqi@0 60 ciInstanceKlass* _holder;
aoqi@0 61 ciSignature* _signature;
aoqi@0 62 ciMethodData* _method_data;
aoqi@0 63 ciMethodBlocks* _method_blocks;
aoqi@0 64
aoqi@0 65 // Code attributes.
aoqi@0 66 int _code_size;
aoqi@0 67 int _max_stack;
aoqi@0 68 int _max_locals;
aoqi@0 69 vmIntrinsics::ID _intrinsic_id;
aoqi@0 70 int _handler_count;
aoqi@0 71 int _interpreter_invocation_count;
aoqi@0 72 int _interpreter_throwout_count;
aoqi@0 73 int _instructions_size;
aoqi@0 74 int _size_of_parameters;
aoqi@0 75
aoqi@0 76 bool _uses_monitors;
aoqi@0 77 bool _balanced_monitors;
aoqi@0 78 bool _is_c1_compilable;
aoqi@0 79 bool _is_c2_compilable;
aoqi@0 80 bool _can_be_statically_bound;
aoqi@0 81
aoqi@0 82 // Lazy fields, filled in on demand
aoqi@0 83 address _code;
aoqi@0 84 ciExceptionHandler** _exception_handlers;
aoqi@0 85
aoqi@0 86 // Optional liveness analyzer.
aoqi@0 87 MethodLiveness* _liveness;
aoqi@0 88 #if defined(COMPILER2) || defined(SHARK)
aoqi@0 89 ciTypeFlow* _flow;
aoqi@0 90 BCEscapeAnalyzer* _bcea;
aoqi@0 91 #endif
aoqi@0 92
aoqi@0 93 ciMethod(methodHandle h_m);
aoqi@0 94 ciMethod(ciInstanceKlass* holder, ciSymbol* name, ciSymbol* signature, ciInstanceKlass* accessor);
aoqi@0 95
aoqi@0 96 Method* get_Method() const {
aoqi@0 97 Method* m = (Method*)_metadata;
aoqi@0 98 assert(m != NULL, "illegal use of unloaded method");
aoqi@0 99 return m;
aoqi@0 100 }
aoqi@0 101
aoqi@0 102 oop loader() const { return _holder->loader(); }
aoqi@0 103
aoqi@0 104 const char* type_string() { return "ciMethod"; }
aoqi@0 105
aoqi@0 106 void print_impl(outputStream* st);
aoqi@0 107
aoqi@0 108 void load_code();
aoqi@0 109
aoqi@0 110 void check_is_loaded() const { assert(is_loaded(), "not loaded"); }
aoqi@0 111
aoqi@0 112 bool ensure_method_data(methodHandle h_m);
aoqi@0 113
aoqi@0 114 void code_at_put(int bci, Bytecodes::Code code) {
aoqi@0 115 Bytecodes::check(code);
aoqi@0 116 assert(0 <= bci && bci < code_size(), "valid bci");
aoqi@0 117 address bcp = _code + bci;
aoqi@0 118 *bcp = code;
aoqi@0 119 }
aoqi@0 120
aoqi@0 121 // Check bytecode and profile data collected are compatible
aoqi@0 122 void assert_virtual_call_type_ok(int bci);
aoqi@0 123 void assert_call_type_ok(int bci);
aoqi@0 124
aoqi@0 125 public:
aoqi@0 126 // Basic method information.
aoqi@0 127 ciFlags flags() const { check_is_loaded(); return _flags; }
aoqi@0 128 ciSymbol* name() const { return _name; }
aoqi@0 129 ciInstanceKlass* holder() const { return _holder; }
aoqi@0 130 ciMethodData* method_data();
aoqi@0 131 ciMethodData* method_data_or_null();
aoqi@0 132
aoqi@0 133 // Signature information.
aoqi@0 134 ciSignature* signature() const { return _signature; }
aoqi@0 135 ciType* return_type() const { return _signature->return_type(); }
aoqi@0 136 int arg_size_no_receiver() const { return _signature->size(); }
aoqi@0 137 // Can only be used on loaded ciMethods
aoqi@0 138 int arg_size() const {
aoqi@0 139 check_is_loaded();
aoqi@0 140 return _signature->size() + (_flags.is_static() ? 0 : 1);
aoqi@0 141 }
aoqi@0 142 // Report the number of elements on stack when invoking this method.
aoqi@0 143 // This is different than the regular arg_size because invokedynamic
aoqi@0 144 // has an implicit receiver.
aoqi@0 145 int invoke_arg_size(Bytecodes::Code code) const {
aoqi@0 146 if (is_loaded()) {
aoqi@0 147 return arg_size();
aoqi@0 148 } else {
aoqi@0 149 int arg_size = _signature->size();
aoqi@0 150 // Add a receiver argument, maybe:
aoqi@0 151 if (code != Bytecodes::_invokestatic &&
aoqi@0 152 code != Bytecodes::_invokedynamic) {
aoqi@0 153 arg_size++;
aoqi@0 154 }
aoqi@0 155 return arg_size;
aoqi@0 156 }
aoqi@0 157 }
aoqi@0 158
aoqi@0 159
aoqi@0 160 // Method code and related information.
aoqi@0 161 address code() { if (_code == NULL) load_code(); return _code; }
aoqi@0 162 int code_size() const { check_is_loaded(); return _code_size; }
aoqi@0 163 int max_stack() const { check_is_loaded(); return _max_stack; }
aoqi@0 164 int max_locals() const { check_is_loaded(); return _max_locals; }
aoqi@0 165 vmIntrinsics::ID intrinsic_id() const { check_is_loaded(); return _intrinsic_id; }
aoqi@0 166 bool has_exception_handlers() const { check_is_loaded(); return _handler_count > 0; }
aoqi@0 167 int exception_table_length() const { check_is_loaded(); return _handler_count; }
aoqi@0 168 int interpreter_invocation_count() const { check_is_loaded(); return _interpreter_invocation_count; }
aoqi@0 169 int interpreter_throwout_count() const { check_is_loaded(); return _interpreter_throwout_count; }
aoqi@0 170 int size_of_parameters() const { check_is_loaded(); return _size_of_parameters; }
aoqi@0 171
aoqi@0 172 // Code size for inlining decisions.
aoqi@0 173 int code_size_for_inlining();
aoqi@0 174
aoqi@0 175 bool caller_sensitive() { return get_Method()->caller_sensitive(); }
aoqi@0 176 bool force_inline() { return get_Method()->force_inline(); }
aoqi@0 177 bool dont_inline() { return get_Method()->dont_inline(); }
aoqi@0 178
aoqi@0 179 int comp_level();
aoqi@0 180 int highest_osr_comp_level();
aoqi@0 181
aoqi@0 182 Bytecodes::Code java_code_at_bci(int bci) {
aoqi@0 183 address bcp = code() + bci;
aoqi@0 184 return Bytecodes::java_code_at(NULL, bcp);
aoqi@0 185 }
aoqi@0 186 Bytecodes::Code raw_code_at_bci(int bci) {
aoqi@0 187 address bcp = code() + bci;
aoqi@0 188 return Bytecodes::code_at(NULL, bcp);
aoqi@0 189 }
aoqi@0 190 BCEscapeAnalyzer *get_bcea();
aoqi@0 191 ciMethodBlocks *get_method_blocks();
aoqi@0 192
aoqi@0 193 bool has_linenumber_table() const; // length unknown until decompression
aoqi@0 194 u_char* compressed_linenumber_table() const; // not preserved by gc
aoqi@0 195
aoqi@0 196 int line_number_from_bci(int bci) const;
aoqi@0 197
aoqi@0 198 // Runtime information.
aoqi@0 199 int vtable_index();
aoqi@0 200 #ifdef SHARK
aoqi@0 201 int itable_index();
aoqi@0 202 #endif // SHARK
aoqi@0 203 address native_entry();
aoqi@0 204 address interpreter_entry();
aoqi@0 205
aoqi@0 206 // Analysis and profiling.
aoqi@0 207 //
aoqi@0 208 // Usage note: liveness_at_bci and init_vars should be wrapped in ResourceMarks.
aoqi@0 209 bool has_monitor_bytecodes() const { return _uses_monitors; }
aoqi@0 210 bool has_balanced_monitors();
aoqi@0 211
aoqi@0 212 // Returns a bitmap indicating which locals are required to be
aoqi@0 213 // maintained as live for deopt. raw_liveness_at_bci is always the
aoqi@0 214 // direct output of the liveness computation while liveness_at_bci
aoqi@0 215 // may mark all locals as live to improve support for debugging Java
aoqi@0 216 // code by maintaining the state of as many locals as possible.
aoqi@0 217 MethodLivenessResult raw_liveness_at_bci(int bci);
aoqi@0 218 MethodLivenessResult liveness_at_bci(int bci);
aoqi@0 219
aoqi@0 220 // Get the interpreters viewpoint on oop liveness. MethodLiveness is
aoqi@0 221 // conservative in the sense that it may consider locals to be live which
aoqi@0 222 // cannot be live, like in the case where a local could contain an oop or
aoqi@0 223 // a primitive along different paths. In that case the local must be
aoqi@0 224 // dead when those paths merge. Since the interpreter's viewpoint is
aoqi@0 225 // used when gc'ing an interpreter frame we need to use its viewpoint
aoqi@0 226 // during OSR when loading the locals.
aoqi@0 227
aoqi@0 228 BitMap live_local_oops_at_bci(int bci);
aoqi@0 229
aoqi@0 230 #ifdef COMPILER1
aoqi@0 231 const BitMap bci_block_start();
aoqi@0 232 #endif
aoqi@0 233
aoqi@0 234 ciTypeFlow* get_flow_analysis();
aoqi@0 235 ciTypeFlow* get_osr_flow_analysis(int osr_bci); // alternate entry point
aoqi@0 236 ciCallProfile call_profile_at_bci(int bci);
aoqi@0 237 int interpreter_call_site_count(int bci);
aoqi@0 238
aoqi@0 239 // Does type profiling provide a useful type at this point?
aoqi@0 240 ciKlass* argument_profiled_type(int bci, int i);
aoqi@0 241 ciKlass* parameter_profiled_type(int i);
aoqi@0 242 ciKlass* return_profiled_type(int bci);
aoqi@0 243
aoqi@0 244 ciField* get_field_at_bci( int bci, bool &will_link);
aoqi@0 245 ciMethod* get_method_at_bci(int bci, bool &will_link, ciSignature* *declared_signature);
aoqi@0 246 // Given a certain calling environment, find the monomorphic target
aoqi@0 247 // for the call. Return NULL if the call is not monomorphic in
aoqi@0 248 // its calling environment.
aoqi@0 249 ciMethod* find_monomorphic_target(ciInstanceKlass* caller,
aoqi@0 250 ciInstanceKlass* callee_holder,
aoqi@0 251 ciInstanceKlass* actual_receiver);
aoqi@0 252
aoqi@0 253 // Given a known receiver klass, find the target for the call.
aoqi@0 254 // Return NULL if the call has no target or is abstract.
aoqi@0 255 ciMethod* resolve_invoke(ciKlass* caller, ciKlass* exact_receiver);
aoqi@0 256
aoqi@0 257 // Find the proper vtable index to invoke this method.
aoqi@0 258 int resolve_vtable_index(ciKlass* caller, ciKlass* receiver);
aoqi@0 259
aoqi@0 260 // Compilation directives
aoqi@0 261 bool should_exclude();
aoqi@0 262 bool should_inline();
aoqi@0 263 bool should_not_inline();
aoqi@0 264 bool should_print_assembly();
aoqi@0 265 bool break_at_execute();
aoqi@0 266 bool has_option(const char *option);
aoqi@0 267 bool can_be_compiled();
aoqi@0 268 bool can_be_osr_compiled(int entry_bci);
aoqi@0 269 void set_not_compilable(const char* reason = NULL);
aoqi@0 270 bool has_compiled_code();
aoqi@0 271 void log_nmethod_identity(xmlStream* log);
aoqi@0 272 bool is_not_reached(int bci);
aoqi@0 273 bool was_executed_more_than(int times);
aoqi@0 274 bool has_unloaded_classes_in_signature();
aoqi@0 275 bool is_klass_loaded(int refinfo_index, bool must_be_resolved) const;
aoqi@0 276 bool check_call(int refinfo_index, bool is_static) const;
aoqi@0 277 bool ensure_method_data(); // make sure it exists in the VM also
aoqi@0 278 MethodCounters* ensure_method_counters();
aoqi@0 279 int instructions_size();
aoqi@0 280 int scale_count(int count, float prof_factor = 1.); // make MDO count commensurate with IIC
aoqi@0 281
aoqi@0 282 // Stack walking support
aoqi@0 283 bool is_ignored_by_security_stack_walk() const;
aoqi@0 284
aoqi@0 285 // JSR 292 support
aoqi@0 286 bool is_method_handle_intrinsic() const;
aoqi@0 287 bool is_compiled_lambda_form() const;
aoqi@0 288 bool has_member_arg() const;
aoqi@0 289
aoqi@0 290 // What kind of ciObject is this?
aoqi@0 291 bool is_method() const { return true; }
aoqi@0 292
aoqi@0 293 // Java access flags
aoqi@0 294 bool is_public () const { return flags().is_public(); }
aoqi@0 295 bool is_private () const { return flags().is_private(); }
aoqi@0 296 bool is_protected () const { return flags().is_protected(); }
aoqi@0 297 bool is_static () const { return flags().is_static(); }
aoqi@0 298 bool is_final () const { return flags().is_final(); }
aoqi@0 299 bool is_synchronized() const { return flags().is_synchronized(); }
aoqi@0 300 bool is_native () const { return flags().is_native(); }
aoqi@0 301 bool is_interface () const { return flags().is_interface(); }
aoqi@0 302 bool is_abstract () const { return flags().is_abstract(); }
aoqi@0 303 bool is_strict () const { return flags().is_strict(); }
aoqi@0 304
aoqi@0 305 // Other flags
aoqi@0 306 bool is_empty_method() const;
aoqi@0 307 bool is_vanilla_constructor() const;
aoqi@0 308 bool is_final_method() const { return is_final() || holder()->is_final(); }
aoqi@0 309 bool has_loops () const;
aoqi@0 310 bool has_jsrs () const;
aoqi@0 311 bool is_accessor () const;
aoqi@0 312 bool is_initializer () const;
aoqi@0 313 bool can_be_statically_bound() const { return _can_be_statically_bound; }
aoqi@0 314 bool is_boxing_method() const;
aoqi@0 315 bool is_unboxing_method() const;
aoqi@0 316
aoqi@0 317 // Replay data methods
aoqi@0 318 void dump_name_as_ascii(outputStream* st);
aoqi@0 319 void dump_replay_data(outputStream* st);
aoqi@0 320
aoqi@0 321 // Print the bytecodes of this method.
aoqi@0 322 void print_codes_on(outputStream* st);
aoqi@0 323 void print_codes() {
aoqi@0 324 print_codes_on(tty);
aoqi@0 325 }
aoqi@0 326 void print_codes_on(int from, int to, outputStream* st);
aoqi@0 327
aoqi@0 328 // Print the name of this method in various incarnations.
aoqi@0 329 void print_name(outputStream* st = tty);
aoqi@0 330 void print_short_name(outputStream* st = tty);
aoqi@0 331 };
aoqi@0 332
aoqi@0 333 #endif // SHARE_VM_CI_CIMETHOD_HPP

mercurial