1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/c1/c1_Compilation.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,341 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_C1_C1_COMPILATION_HPP 1.29 +#define SHARE_VM_C1_C1_COMPILATION_HPP 1.30 + 1.31 +#include "ci/ciEnv.hpp" 1.32 +#include "ci/ciMethodData.hpp" 1.33 +#include "code/exceptionHandlerTable.hpp" 1.34 +#include "memory/resourceArea.hpp" 1.35 +#include "runtime/deoptimization.hpp" 1.36 + 1.37 +class CompilationResourceObj; 1.38 +class XHandlers; 1.39 +class ExceptionInfo; 1.40 +class DebugInformationRecorder; 1.41 +class FrameMap; 1.42 +class IR; 1.43 +class IRScope; 1.44 +class Instruction; 1.45 +class LinearScan; 1.46 +class OopMap; 1.47 +class LIR_Emitter; 1.48 +class LIR_Assembler; 1.49 +class CodeEmitInfo; 1.50 +class ciEnv; 1.51 +class ciMethod; 1.52 +class ValueStack; 1.53 +class LIR_OprDesc; 1.54 +class C1_MacroAssembler; 1.55 +class CFGPrinter; 1.56 +typedef LIR_OprDesc* LIR_Opr; 1.57 + 1.58 + 1.59 +define_array(BasicTypeArray, BasicType) 1.60 +define_stack(BasicTypeList, BasicTypeArray) 1.61 + 1.62 +define_array(ExceptionInfoArray, ExceptionInfo*) 1.63 +define_stack(ExceptionInfoList, ExceptionInfoArray) 1.64 + 1.65 +class Compilation: public StackObj { 1.66 + friend class CompilationResourceObj; 1.67 + private: 1.68 + // compilation specifics 1.69 + Arena* _arena; 1.70 + int _next_id; 1.71 + int _next_block_id; 1.72 + AbstractCompiler* _compiler; 1.73 + ciEnv* _env; 1.74 + CompileLog* _log; 1.75 + ciMethod* _method; 1.76 + int _osr_bci; 1.77 + IR* _hir; 1.78 + int _max_spills; 1.79 + FrameMap* _frame_map; 1.80 + C1_MacroAssembler* _masm; 1.81 + bool _has_exception_handlers; 1.82 + bool _has_fpu_code; 1.83 + bool _has_unsafe_access; 1.84 + bool _would_profile; 1.85 + bool _has_method_handle_invokes; // True if this method has MethodHandle invokes. 1.86 + const char* _bailout_msg; 1.87 + ExceptionInfoList* _exception_info_list; 1.88 + ExceptionHandlerTable _exception_handler_table; 1.89 + ImplicitExceptionTable _implicit_exception_table; 1.90 + LinearScan* _allocator; 1.91 + CodeOffsets _offsets; 1.92 + CodeBuffer _code; 1.93 + bool _has_access_indexed; 1.94 + int _interpreter_frame_size; // Stack space needed in case of a deoptimization 1.95 + 1.96 + // compilation helpers 1.97 + void initialize(); 1.98 + void build_hir(); 1.99 + void emit_lir(); 1.100 + 1.101 + void emit_code_epilog(LIR_Assembler* assembler); 1.102 + int emit_code_body(); 1.103 + 1.104 + int compile_java_method(); 1.105 + void install_code(int frame_size); 1.106 + void compile_method(); 1.107 + 1.108 + void generate_exception_handler_table(); 1.109 + 1.110 + ExceptionInfoList* exception_info_list() const { return _exception_info_list; } 1.111 + ExceptionHandlerTable* exception_handler_table() { return &_exception_handler_table; } 1.112 + 1.113 + LinearScan* allocator() { return _allocator; } 1.114 + void set_allocator(LinearScan* allocator) { _allocator = allocator; } 1.115 + 1.116 + Instruction* _current_instruction; // the instruction currently being processed 1.117 +#ifndef PRODUCT 1.118 + Instruction* _last_instruction_printed; // the last instruction printed during traversal 1.119 +#endif // PRODUCT 1.120 + 1.121 + public: 1.122 + // creation 1.123 + Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method, 1.124 + int osr_bci, BufferBlob* buffer_blob); 1.125 + ~Compilation(); 1.126 + 1.127 + 1.128 + static Compilation* current() { 1.129 + return (Compilation*) ciEnv::current()->compiler_data(); 1.130 + } 1.131 + 1.132 + // accessors 1.133 + ciEnv* env() const { return _env; } 1.134 + CompileLog* log() const { return _log; } 1.135 + AbstractCompiler* compiler() const { return _compiler; } 1.136 + bool has_exception_handlers() const { return _has_exception_handlers; } 1.137 + bool has_fpu_code() const { return _has_fpu_code; } 1.138 + bool has_unsafe_access() const { return _has_unsafe_access; } 1.139 + int max_vector_size() const { return 0; } 1.140 + ciMethod* method() const { return _method; } 1.141 + int osr_bci() const { return _osr_bci; } 1.142 + bool is_osr_compile() const { return osr_bci() >= 0; } 1.143 + IR* hir() const { return _hir; } 1.144 + int max_spills() const { return _max_spills; } 1.145 + FrameMap* frame_map() const { return _frame_map; } 1.146 + CodeBuffer* code() { return &_code; } 1.147 + C1_MacroAssembler* masm() const { return _masm; } 1.148 + CodeOffsets* offsets() { return &_offsets; } 1.149 + Arena* arena() { return _arena; } 1.150 + bool has_access_indexed() { return _has_access_indexed; } 1.151 + 1.152 + // Instruction ids 1.153 + int get_next_id() { return _next_id++; } 1.154 + int number_of_instructions() const { return _next_id; } 1.155 + 1.156 + // BlockBegin ids 1.157 + int get_next_block_id() { return _next_block_id++; } 1.158 + int number_of_blocks() const { return _next_block_id; } 1.159 + 1.160 + // setters 1.161 + void set_has_exception_handlers(bool f) { _has_exception_handlers = f; } 1.162 + void set_has_fpu_code(bool f) { _has_fpu_code = f; } 1.163 + void set_has_unsafe_access(bool f) { _has_unsafe_access = f; } 1.164 + void set_would_profile(bool f) { _would_profile = f; } 1.165 + void set_has_access_indexed(bool f) { _has_access_indexed = f; } 1.166 + // Add a set of exception handlers covering the given PC offset 1.167 + void add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers); 1.168 + // Statistics gathering 1.169 + void notice_inlined_method(ciMethod* method); 1.170 + 1.171 + // JSR 292 1.172 + bool has_method_handle_invokes() const { return _has_method_handle_invokes; } 1.173 + void set_has_method_handle_invokes(bool z) { _has_method_handle_invokes = z; } 1.174 + 1.175 + DebugInformationRecorder* debug_info_recorder() const; // = _env->debug_info(); 1.176 + Dependencies* dependency_recorder() const; // = _env->dependencies() 1.177 + ImplicitExceptionTable* implicit_exception_table() { return &_implicit_exception_table; } 1.178 + 1.179 + Instruction* current_instruction() const { return _current_instruction; } 1.180 + Instruction* set_current_instruction(Instruction* instr) { 1.181 + Instruction* previous = _current_instruction; 1.182 + _current_instruction = instr; 1.183 + return previous; 1.184 + } 1.185 + 1.186 +#ifndef PRODUCT 1.187 + void maybe_print_current_instruction(); 1.188 +#endif // PRODUCT 1.189 + 1.190 + // error handling 1.191 + void bailout(const char* msg); 1.192 + bool bailed_out() const { return _bailout_msg != NULL; } 1.193 + const char* bailout_msg() const { return _bailout_msg; } 1.194 + 1.195 + static int desired_max_code_buffer_size() { 1.196 +#ifndef PPC 1.197 + return (int) NMethodSizeLimit; // default 256K or 512K 1.198 +#else 1.199 + // conditional branches on PPC are restricted to 16 bit signed 1.200 + return MIN2((unsigned int)NMethodSizeLimit,32*K); 1.201 +#endif 1.202 + } 1.203 + static int desired_max_constant_size() { 1.204 + return desired_max_code_buffer_size() / 10; 1.205 + } 1.206 + 1.207 + static bool setup_code_buffer(CodeBuffer* cb, int call_stub_estimate); 1.208 + 1.209 + // timers 1.210 + static void print_timers(); 1.211 + 1.212 +#ifndef PRODUCT 1.213 + // debugging support. 1.214 + // produces a file named c1compileonly in the current directory with 1.215 + // directives to compile only the current method and it's inlines. 1.216 + // The file can be passed to the command line option -XX:Flags=<filename> 1.217 + void compile_only_this_method(); 1.218 + void compile_only_this_scope(outputStream* st, IRScope* scope); 1.219 + void exclude_this_method(); 1.220 +#endif // PRODUCT 1.221 + 1.222 + bool is_profiling() { 1.223 + return env()->comp_level() == CompLevel_full_profile || 1.224 + env()->comp_level() == CompLevel_limited_profile; 1.225 + } 1.226 + bool count_invocations() { return is_profiling(); } 1.227 + bool count_backedges() { return is_profiling(); } 1.228 + 1.229 + // Helpers for generation of profile information 1.230 + bool profile_branches() { 1.231 + return env()->comp_level() == CompLevel_full_profile && 1.232 + C1UpdateMethodData && C1ProfileBranches; 1.233 + } 1.234 + bool profile_calls() { 1.235 + return env()->comp_level() == CompLevel_full_profile && 1.236 + C1UpdateMethodData && C1ProfileCalls; 1.237 + } 1.238 + bool profile_inlined_calls() { 1.239 + return profile_calls() && C1ProfileInlinedCalls; 1.240 + } 1.241 + bool profile_checkcasts() { 1.242 + return env()->comp_level() == CompLevel_full_profile && 1.243 + C1UpdateMethodData && C1ProfileCheckcasts; 1.244 + } 1.245 + bool profile_parameters() { 1.246 + return env()->comp_level() == CompLevel_full_profile && 1.247 + C1UpdateMethodData && MethodData::profile_parameters(); 1.248 + } 1.249 + bool profile_arguments() { 1.250 + return env()->comp_level() == CompLevel_full_profile && 1.251 + C1UpdateMethodData && MethodData::profile_arguments(); 1.252 + } 1.253 + bool profile_return() { 1.254 + return env()->comp_level() == CompLevel_full_profile && 1.255 + C1UpdateMethodData && MethodData::profile_return(); 1.256 + } 1.257 + // will compilation make optimistic assumptions that might lead to 1.258 + // deoptimization and that the runtime will account for? 1.259 + bool is_optimistic() const { 1.260 + return !TieredCompilation && 1.261 + (RangeCheckElimination || UseLoopInvariantCodeMotion) && 1.262 + method()->method_data()->trap_count(Deoptimization::Reason_none) == 0; 1.263 + } 1.264 + 1.265 + ciKlass* cha_exact_type(ciType* type); 1.266 + 1.267 + // Dump inlining replay data to the stream. 1.268 + void dump_inline_data(outputStream* out) { /* do nothing now */ } 1.269 + 1.270 + // How much stack space would the interpreter need in case of a 1.271 + // deoptimization (worst case) 1.272 + void update_interpreter_frame_size(int size) { 1.273 + if (_interpreter_frame_size < size) { 1.274 + _interpreter_frame_size = size; 1.275 + } 1.276 + } 1.277 + 1.278 + int interpreter_frame_size() const { 1.279 + return _interpreter_frame_size; 1.280 + } 1.281 +}; 1.282 + 1.283 + 1.284 +// Macro definitions for unified bailout-support 1.285 +// The methods bailout() and bailed_out() are present in all classes 1.286 +// that might bailout, but forward all calls to Compilation 1.287 +#define BAILOUT(msg) { bailout(msg); return; } 1.288 +#define BAILOUT_(msg, res) { bailout(msg); return res; } 1.289 + 1.290 +#define CHECK_BAILOUT() { if (bailed_out()) return; } 1.291 +#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; } 1.292 + 1.293 + 1.294 +class InstructionMark: public StackObj { 1.295 + private: 1.296 + Compilation* _compilation; 1.297 + Instruction* _previous; 1.298 + 1.299 + public: 1.300 + InstructionMark(Compilation* compilation, Instruction* instr) { 1.301 + _compilation = compilation; 1.302 + _previous = _compilation->set_current_instruction(instr); 1.303 + } 1.304 + ~InstructionMark() { 1.305 + _compilation->set_current_instruction(_previous); 1.306 + } 1.307 +}; 1.308 + 1.309 + 1.310 +//---------------------------------------------------------------------- 1.311 +// Base class for objects allocated by the compiler in the compilation arena 1.312 +class CompilationResourceObj ALLOCATION_SUPER_CLASS_SPEC { 1.313 + public: 1.314 + void* operator new(size_t size) throw() { return Compilation::current()->arena()->Amalloc(size); } 1.315 + void* operator new(size_t size, Arena* arena) throw() { 1.316 + return arena->Amalloc(size); 1.317 + } 1.318 + void operator delete(void* p) {} // nothing to do 1.319 +}; 1.320 + 1.321 + 1.322 +//---------------------------------------------------------------------- 1.323 +// Class for aggregating exception handler information. 1.324 + 1.325 +// Effectively extends XHandlers class with PC offset of 1.326 +// potentially exception-throwing instruction. 1.327 +// This class is used at the end of the compilation to build the 1.328 +// ExceptionHandlerTable. 1.329 +class ExceptionInfo: public CompilationResourceObj { 1.330 + private: 1.331 + int _pco; // PC of potentially exception-throwing instruction 1.332 + XHandlers* _exception_handlers; // flat list of exception handlers covering this PC 1.333 + 1.334 + public: 1.335 + ExceptionInfo(int pco, XHandlers* exception_handlers) 1.336 + : _pco(pco) 1.337 + , _exception_handlers(exception_handlers) 1.338 + { } 1.339 + 1.340 + int pco() { return _pco; } 1.341 + XHandlers* exception_handlers() { return _exception_handlers; } 1.342 +}; 1.343 + 1.344 +#endif // SHARE_VM_C1_C1_COMPILATION_HPP