Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
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_C1_C1_COMPILATION_HPP |
aoqi@0 | 26 | #define SHARE_VM_C1_C1_COMPILATION_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "ci/ciEnv.hpp" |
aoqi@0 | 29 | #include "ci/ciMethodData.hpp" |
aoqi@0 | 30 | #include "code/exceptionHandlerTable.hpp" |
aoqi@0 | 31 | #include "memory/resourceArea.hpp" |
aoqi@0 | 32 | #include "runtime/deoptimization.hpp" |
aoqi@0 | 33 | |
aoqi@0 | 34 | class CompilationResourceObj; |
aoqi@0 | 35 | class XHandlers; |
aoqi@0 | 36 | class ExceptionInfo; |
aoqi@0 | 37 | class DebugInformationRecorder; |
aoqi@0 | 38 | class FrameMap; |
aoqi@0 | 39 | class IR; |
aoqi@0 | 40 | class IRScope; |
aoqi@0 | 41 | class Instruction; |
aoqi@0 | 42 | class LinearScan; |
aoqi@0 | 43 | class OopMap; |
aoqi@0 | 44 | class LIR_Emitter; |
aoqi@0 | 45 | class LIR_Assembler; |
aoqi@0 | 46 | class CodeEmitInfo; |
aoqi@0 | 47 | class ciEnv; |
aoqi@0 | 48 | class ciMethod; |
aoqi@0 | 49 | class ValueStack; |
aoqi@0 | 50 | class LIR_OprDesc; |
aoqi@0 | 51 | class C1_MacroAssembler; |
aoqi@0 | 52 | class CFGPrinter; |
aoqi@0 | 53 | typedef LIR_OprDesc* LIR_Opr; |
aoqi@0 | 54 | |
aoqi@0 | 55 | |
aoqi@0 | 56 | define_array(BasicTypeArray, BasicType) |
aoqi@0 | 57 | define_stack(BasicTypeList, BasicTypeArray) |
aoqi@0 | 58 | |
aoqi@0 | 59 | define_array(ExceptionInfoArray, ExceptionInfo*) |
aoqi@0 | 60 | define_stack(ExceptionInfoList, ExceptionInfoArray) |
aoqi@0 | 61 | |
aoqi@0 | 62 | class Compilation: public StackObj { |
aoqi@0 | 63 | friend class CompilationResourceObj; |
aoqi@0 | 64 | private: |
aoqi@0 | 65 | // compilation specifics |
aoqi@0 | 66 | Arena* _arena; |
aoqi@0 | 67 | int _next_id; |
aoqi@0 | 68 | int _next_block_id; |
aoqi@0 | 69 | AbstractCompiler* _compiler; |
aoqi@0 | 70 | ciEnv* _env; |
aoqi@0 | 71 | CompileLog* _log; |
aoqi@0 | 72 | ciMethod* _method; |
aoqi@0 | 73 | int _osr_bci; |
aoqi@0 | 74 | IR* _hir; |
aoqi@0 | 75 | int _max_spills; |
aoqi@0 | 76 | FrameMap* _frame_map; |
aoqi@0 | 77 | C1_MacroAssembler* _masm; |
aoqi@0 | 78 | bool _has_exception_handlers; |
aoqi@0 | 79 | bool _has_fpu_code; |
aoqi@0 | 80 | bool _has_unsafe_access; |
aoqi@0 | 81 | bool _would_profile; |
aoqi@0 | 82 | bool _has_method_handle_invokes; // True if this method has MethodHandle invokes. |
aoqi@0 | 83 | const char* _bailout_msg; |
aoqi@0 | 84 | ExceptionInfoList* _exception_info_list; |
aoqi@0 | 85 | ExceptionHandlerTable _exception_handler_table; |
aoqi@0 | 86 | ImplicitExceptionTable _implicit_exception_table; |
aoqi@0 | 87 | LinearScan* _allocator; |
aoqi@0 | 88 | CodeOffsets _offsets; |
aoqi@0 | 89 | CodeBuffer _code; |
aoqi@0 | 90 | bool _has_access_indexed; |
aoqi@0 | 91 | int _interpreter_frame_size; // Stack space needed in case of a deoptimization |
aoqi@0 | 92 | |
aoqi@0 | 93 | // compilation helpers |
aoqi@0 | 94 | void initialize(); |
aoqi@0 | 95 | void build_hir(); |
aoqi@0 | 96 | void emit_lir(); |
aoqi@0 | 97 | |
aoqi@0 | 98 | void emit_code_epilog(LIR_Assembler* assembler); |
aoqi@0 | 99 | int emit_code_body(); |
aoqi@0 | 100 | |
aoqi@0 | 101 | int compile_java_method(); |
aoqi@0 | 102 | void install_code(int frame_size); |
aoqi@0 | 103 | void compile_method(); |
aoqi@0 | 104 | |
aoqi@0 | 105 | void generate_exception_handler_table(); |
aoqi@0 | 106 | |
aoqi@0 | 107 | ExceptionInfoList* exception_info_list() const { return _exception_info_list; } |
aoqi@0 | 108 | ExceptionHandlerTable* exception_handler_table() { return &_exception_handler_table; } |
aoqi@0 | 109 | |
aoqi@0 | 110 | LinearScan* allocator() { return _allocator; } |
aoqi@0 | 111 | void set_allocator(LinearScan* allocator) { _allocator = allocator; } |
aoqi@0 | 112 | |
aoqi@0 | 113 | Instruction* _current_instruction; // the instruction currently being processed |
aoqi@0 | 114 | #ifndef PRODUCT |
aoqi@0 | 115 | Instruction* _last_instruction_printed; // the last instruction printed during traversal |
aoqi@0 | 116 | #endif // PRODUCT |
aoqi@0 | 117 | |
aoqi@0 | 118 | public: |
aoqi@0 | 119 | // creation |
aoqi@0 | 120 | Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method, |
aoqi@0 | 121 | int osr_bci, BufferBlob* buffer_blob); |
aoqi@0 | 122 | ~Compilation(); |
aoqi@0 | 123 | |
aoqi@0 | 124 | |
aoqi@0 | 125 | static Compilation* current() { |
aoqi@0 | 126 | return (Compilation*) ciEnv::current()->compiler_data(); |
aoqi@0 | 127 | } |
aoqi@0 | 128 | |
aoqi@0 | 129 | // accessors |
aoqi@0 | 130 | ciEnv* env() const { return _env; } |
aoqi@0 | 131 | CompileLog* log() const { return _log; } |
aoqi@0 | 132 | AbstractCompiler* compiler() const { return _compiler; } |
aoqi@0 | 133 | bool has_exception_handlers() const { return _has_exception_handlers; } |
aoqi@0 | 134 | bool has_fpu_code() const { return _has_fpu_code; } |
aoqi@0 | 135 | bool has_unsafe_access() const { return _has_unsafe_access; } |
aoqi@0 | 136 | int max_vector_size() const { return 0; } |
aoqi@0 | 137 | ciMethod* method() const { return _method; } |
aoqi@0 | 138 | int osr_bci() const { return _osr_bci; } |
aoqi@0 | 139 | bool is_osr_compile() const { return osr_bci() >= 0; } |
aoqi@0 | 140 | IR* hir() const { return _hir; } |
aoqi@0 | 141 | int max_spills() const { return _max_spills; } |
aoqi@0 | 142 | FrameMap* frame_map() const { return _frame_map; } |
aoqi@0 | 143 | CodeBuffer* code() { return &_code; } |
aoqi@0 | 144 | C1_MacroAssembler* masm() const { return _masm; } |
aoqi@0 | 145 | CodeOffsets* offsets() { return &_offsets; } |
aoqi@0 | 146 | Arena* arena() { return _arena; } |
aoqi@0 | 147 | bool has_access_indexed() { return _has_access_indexed; } |
aoqi@0 | 148 | |
aoqi@0 | 149 | // Instruction ids |
aoqi@0 | 150 | int get_next_id() { return _next_id++; } |
aoqi@0 | 151 | int number_of_instructions() const { return _next_id; } |
aoqi@0 | 152 | |
aoqi@0 | 153 | // BlockBegin ids |
aoqi@0 | 154 | int get_next_block_id() { return _next_block_id++; } |
aoqi@0 | 155 | int number_of_blocks() const { return _next_block_id; } |
aoqi@0 | 156 | |
aoqi@0 | 157 | // setters |
aoqi@0 | 158 | void set_has_exception_handlers(bool f) { _has_exception_handlers = f; } |
aoqi@0 | 159 | void set_has_fpu_code(bool f) { _has_fpu_code = f; } |
aoqi@0 | 160 | void set_has_unsafe_access(bool f) { _has_unsafe_access = f; } |
aoqi@0 | 161 | void set_would_profile(bool f) { _would_profile = f; } |
aoqi@0 | 162 | void set_has_access_indexed(bool f) { _has_access_indexed = f; } |
aoqi@0 | 163 | // Add a set of exception handlers covering the given PC offset |
aoqi@0 | 164 | void add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers); |
aoqi@0 | 165 | // Statistics gathering |
aoqi@0 | 166 | void notice_inlined_method(ciMethod* method); |
aoqi@0 | 167 | |
aoqi@0 | 168 | // JSR 292 |
aoqi@0 | 169 | bool has_method_handle_invokes() const { return _has_method_handle_invokes; } |
aoqi@0 | 170 | void set_has_method_handle_invokes(bool z) { _has_method_handle_invokes = z; } |
aoqi@0 | 171 | |
aoqi@0 | 172 | DebugInformationRecorder* debug_info_recorder() const; // = _env->debug_info(); |
aoqi@0 | 173 | Dependencies* dependency_recorder() const; // = _env->dependencies() |
aoqi@0 | 174 | ImplicitExceptionTable* implicit_exception_table() { return &_implicit_exception_table; } |
aoqi@0 | 175 | |
aoqi@0 | 176 | Instruction* current_instruction() const { return _current_instruction; } |
aoqi@0 | 177 | Instruction* set_current_instruction(Instruction* instr) { |
aoqi@0 | 178 | Instruction* previous = _current_instruction; |
aoqi@0 | 179 | _current_instruction = instr; |
aoqi@0 | 180 | return previous; |
aoqi@0 | 181 | } |
aoqi@0 | 182 | |
aoqi@0 | 183 | #ifndef PRODUCT |
aoqi@0 | 184 | void maybe_print_current_instruction(); |
aoqi@0 | 185 | #endif // PRODUCT |
aoqi@0 | 186 | |
aoqi@0 | 187 | // error handling |
aoqi@0 | 188 | void bailout(const char* msg); |
aoqi@0 | 189 | bool bailed_out() const { return _bailout_msg != NULL; } |
aoqi@0 | 190 | const char* bailout_msg() const { return _bailout_msg; } |
aoqi@0 | 191 | |
aoqi@0 | 192 | static int desired_max_code_buffer_size() { |
aoqi@0 | 193 | #ifndef PPC |
aoqi@0 | 194 | return (int) NMethodSizeLimit; // default 256K or 512K |
aoqi@0 | 195 | #else |
aoqi@0 | 196 | // conditional branches on PPC are restricted to 16 bit signed |
aoqi@0 | 197 | return MIN2((unsigned int)NMethodSizeLimit,32*K); |
aoqi@0 | 198 | #endif |
aoqi@0 | 199 | } |
aoqi@0 | 200 | static int desired_max_constant_size() { |
aoqi@0 | 201 | return desired_max_code_buffer_size() / 10; |
aoqi@0 | 202 | } |
aoqi@0 | 203 | |
aoqi@0 | 204 | static bool setup_code_buffer(CodeBuffer* cb, int call_stub_estimate); |
aoqi@0 | 205 | |
aoqi@0 | 206 | // timers |
aoqi@0 | 207 | static void print_timers(); |
aoqi@0 | 208 | |
aoqi@0 | 209 | #ifndef PRODUCT |
aoqi@0 | 210 | // debugging support. |
aoqi@0 | 211 | // produces a file named c1compileonly in the current directory with |
aoqi@0 | 212 | // directives to compile only the current method and it's inlines. |
aoqi@0 | 213 | // The file can be passed to the command line option -XX:Flags=<filename> |
aoqi@0 | 214 | void compile_only_this_method(); |
aoqi@0 | 215 | void compile_only_this_scope(outputStream* st, IRScope* scope); |
aoqi@0 | 216 | void exclude_this_method(); |
aoqi@0 | 217 | #endif // PRODUCT |
aoqi@0 | 218 | |
aoqi@0 | 219 | bool is_profiling() { |
aoqi@0 | 220 | return env()->comp_level() == CompLevel_full_profile || |
aoqi@0 | 221 | env()->comp_level() == CompLevel_limited_profile; |
aoqi@0 | 222 | } |
aoqi@0 | 223 | bool count_invocations() { return is_profiling(); } |
aoqi@0 | 224 | bool count_backedges() { return is_profiling(); } |
aoqi@0 | 225 | |
aoqi@0 | 226 | // Helpers for generation of profile information |
aoqi@0 | 227 | bool profile_branches() { |
aoqi@0 | 228 | return env()->comp_level() == CompLevel_full_profile && |
aoqi@0 | 229 | C1UpdateMethodData && C1ProfileBranches; |
aoqi@0 | 230 | } |
aoqi@0 | 231 | bool profile_calls() { |
aoqi@0 | 232 | return env()->comp_level() == CompLevel_full_profile && |
aoqi@0 | 233 | C1UpdateMethodData && C1ProfileCalls; |
aoqi@0 | 234 | } |
aoqi@0 | 235 | bool profile_inlined_calls() { |
aoqi@0 | 236 | return profile_calls() && C1ProfileInlinedCalls; |
aoqi@0 | 237 | } |
aoqi@0 | 238 | bool profile_checkcasts() { |
aoqi@0 | 239 | return env()->comp_level() == CompLevel_full_profile && |
aoqi@0 | 240 | C1UpdateMethodData && C1ProfileCheckcasts; |
aoqi@0 | 241 | } |
aoqi@0 | 242 | bool profile_parameters() { |
aoqi@0 | 243 | return env()->comp_level() == CompLevel_full_profile && |
aoqi@0 | 244 | C1UpdateMethodData && MethodData::profile_parameters(); |
aoqi@0 | 245 | } |
aoqi@0 | 246 | bool profile_arguments() { |
aoqi@0 | 247 | return env()->comp_level() == CompLevel_full_profile && |
aoqi@0 | 248 | C1UpdateMethodData && MethodData::profile_arguments(); |
aoqi@0 | 249 | } |
aoqi@0 | 250 | bool profile_return() { |
aoqi@0 | 251 | return env()->comp_level() == CompLevel_full_profile && |
aoqi@0 | 252 | C1UpdateMethodData && MethodData::profile_return(); |
aoqi@0 | 253 | } |
aoqi@0 | 254 | // will compilation make optimistic assumptions that might lead to |
aoqi@0 | 255 | // deoptimization and that the runtime will account for? |
aoqi@0 | 256 | bool is_optimistic() const { |
aoqi@0 | 257 | return !TieredCompilation && |
aoqi@0 | 258 | (RangeCheckElimination || UseLoopInvariantCodeMotion) && |
aoqi@0 | 259 | method()->method_data()->trap_count(Deoptimization::Reason_none) == 0; |
aoqi@0 | 260 | } |
aoqi@0 | 261 | |
aoqi@0 | 262 | ciKlass* cha_exact_type(ciType* type); |
aoqi@0 | 263 | |
aoqi@0 | 264 | // Dump inlining replay data to the stream. |
aoqi@0 | 265 | void dump_inline_data(outputStream* out) { /* do nothing now */ } |
aoqi@0 | 266 | |
aoqi@0 | 267 | // How much stack space would the interpreter need in case of a |
aoqi@0 | 268 | // deoptimization (worst case) |
aoqi@0 | 269 | void update_interpreter_frame_size(int size) { |
aoqi@0 | 270 | if (_interpreter_frame_size < size) { |
aoqi@0 | 271 | _interpreter_frame_size = size; |
aoqi@0 | 272 | } |
aoqi@0 | 273 | } |
aoqi@0 | 274 | |
aoqi@0 | 275 | int interpreter_frame_size() const { |
aoqi@0 | 276 | return _interpreter_frame_size; |
aoqi@0 | 277 | } |
aoqi@0 | 278 | }; |
aoqi@0 | 279 | |
aoqi@0 | 280 | |
aoqi@0 | 281 | // Macro definitions for unified bailout-support |
aoqi@0 | 282 | // The methods bailout() and bailed_out() are present in all classes |
aoqi@0 | 283 | // that might bailout, but forward all calls to Compilation |
aoqi@0 | 284 | #define BAILOUT(msg) { bailout(msg); return; } |
aoqi@0 | 285 | #define BAILOUT_(msg, res) { bailout(msg); return res; } |
aoqi@0 | 286 | |
aoqi@0 | 287 | #define CHECK_BAILOUT() { if (bailed_out()) return; } |
aoqi@0 | 288 | #define CHECK_BAILOUT_(res) { if (bailed_out()) return res; } |
aoqi@0 | 289 | |
aoqi@0 | 290 | |
aoqi@0 | 291 | class InstructionMark: public StackObj { |
aoqi@0 | 292 | private: |
aoqi@0 | 293 | Compilation* _compilation; |
aoqi@0 | 294 | Instruction* _previous; |
aoqi@0 | 295 | |
aoqi@0 | 296 | public: |
aoqi@0 | 297 | InstructionMark(Compilation* compilation, Instruction* instr) { |
aoqi@0 | 298 | _compilation = compilation; |
aoqi@0 | 299 | _previous = _compilation->set_current_instruction(instr); |
aoqi@0 | 300 | } |
aoqi@0 | 301 | ~InstructionMark() { |
aoqi@0 | 302 | _compilation->set_current_instruction(_previous); |
aoqi@0 | 303 | } |
aoqi@0 | 304 | }; |
aoqi@0 | 305 | |
aoqi@0 | 306 | |
aoqi@0 | 307 | //---------------------------------------------------------------------- |
aoqi@0 | 308 | // Base class for objects allocated by the compiler in the compilation arena |
aoqi@0 | 309 | class CompilationResourceObj ALLOCATION_SUPER_CLASS_SPEC { |
aoqi@0 | 310 | public: |
aoqi@0 | 311 | void* operator new(size_t size) throw() { return Compilation::current()->arena()->Amalloc(size); } |
aoqi@0 | 312 | void* operator new(size_t size, Arena* arena) throw() { |
aoqi@0 | 313 | return arena->Amalloc(size); |
aoqi@0 | 314 | } |
aoqi@0 | 315 | void operator delete(void* p) {} // nothing to do |
aoqi@0 | 316 | }; |
aoqi@0 | 317 | |
aoqi@0 | 318 | |
aoqi@0 | 319 | //---------------------------------------------------------------------- |
aoqi@0 | 320 | // Class for aggregating exception handler information. |
aoqi@0 | 321 | |
aoqi@0 | 322 | // Effectively extends XHandlers class with PC offset of |
aoqi@0 | 323 | // potentially exception-throwing instruction. |
aoqi@0 | 324 | // This class is used at the end of the compilation to build the |
aoqi@0 | 325 | // ExceptionHandlerTable. |
aoqi@0 | 326 | class ExceptionInfo: public CompilationResourceObj { |
aoqi@0 | 327 | private: |
aoqi@0 | 328 | int _pco; // PC of potentially exception-throwing instruction |
aoqi@0 | 329 | XHandlers* _exception_handlers; // flat list of exception handlers covering this PC |
aoqi@0 | 330 | |
aoqi@0 | 331 | public: |
aoqi@0 | 332 | ExceptionInfo(int pco, XHandlers* exception_handlers) |
aoqi@0 | 333 | : _pco(pco) |
aoqi@0 | 334 | , _exception_handlers(exception_handlers) |
aoqi@0 | 335 | { } |
aoqi@0 | 336 | |
aoqi@0 | 337 | int pco() { return _pco; } |
aoqi@0 | 338 | XHandlers* exception_handlers() { return _exception_handlers; } |
aoqi@0 | 339 | }; |
aoqi@0 | 340 | |
aoqi@0 | 341 | #endif // SHARE_VM_C1_C1_COMPILATION_HPP |