Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/c1/c1_Compilation.hpp
32285 views
/*1* Copyright (c) 1999, 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_C1_C1_COMPILATION_HPP25#define SHARE_VM_C1_C1_COMPILATION_HPP2627#include "ci/ciEnv.hpp"28#include "ci/ciMethodData.hpp"29#include "code/exceptionHandlerTable.hpp"30#include "memory/resourceArea.hpp"31#include "runtime/deoptimization.hpp"3233class CompilationResourceObj;34class XHandlers;35class ExceptionInfo;36class DebugInformationRecorder;37class FrameMap;38class IR;39class IRScope;40class Instruction;41class LinearScan;42class OopMap;43class LIR_Emitter;44class LIR_Assembler;45class CodeEmitInfo;46class ciEnv;47class ciMethod;48class ValueStack;49class LIR_OprDesc;50class C1_MacroAssembler;51class CFGPrinter;52typedef LIR_OprDesc* LIR_Opr;535455define_array(BasicTypeArray, BasicType)56define_stack(BasicTypeList, BasicTypeArray)5758define_array(ExceptionInfoArray, ExceptionInfo*)59define_stack(ExceptionInfoList, ExceptionInfoArray)6061class Compilation: public StackObj {62friend class CompilationResourceObj;63private:64// compilation specifics65Arena* _arena;66int _next_id;67int _next_block_id;68AbstractCompiler* _compiler;69ciEnv* _env;70CompileLog* _log;71ciMethod* _method;72int _osr_bci;73IR* _hir;74int _max_spills;75FrameMap* _frame_map;76C1_MacroAssembler* _masm;77bool _has_exception_handlers;78bool _has_fpu_code;79bool _has_unsafe_access;80bool _would_profile;81bool _has_method_handle_invokes; // True if this method has MethodHandle invokes.82const char* _bailout_msg;83ExceptionInfoList* _exception_info_list;84ExceptionHandlerTable _exception_handler_table;85ImplicitExceptionTable _implicit_exception_table;86LinearScan* _allocator;87CodeOffsets _offsets;88CodeBuffer _code;89bool _has_access_indexed;90int _interpreter_frame_size; // Stack space needed in case of a deoptimization9192// compilation helpers93void initialize();94void build_hir();95void emit_lir();9697void emit_code_epilog(LIR_Assembler* assembler);98int emit_code_body();99100int compile_java_method();101void install_code(int frame_size);102void compile_method();103104void generate_exception_handler_table();105106ExceptionInfoList* exception_info_list() const { return _exception_info_list; }107ExceptionHandlerTable* exception_handler_table() { return &_exception_handler_table; }108109LinearScan* allocator() { return _allocator; }110void set_allocator(LinearScan* allocator) { _allocator = allocator; }111112Instruction* _current_instruction; // the instruction currently being processed113#ifndef PRODUCT114Instruction* _last_instruction_printed; // the last instruction printed during traversal115#endif // PRODUCT116117public:118// creation119Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method,120int osr_bci, BufferBlob* buffer_blob);121~Compilation();122123124static Compilation* current() {125return (Compilation*) ciEnv::current()->compiler_data();126}127128// accessors129ciEnv* env() const { return _env; }130CompileLog* log() const { return _log; }131AbstractCompiler* compiler() const { return _compiler; }132bool has_exception_handlers() const { return _has_exception_handlers; }133bool has_fpu_code() const { return _has_fpu_code; }134bool has_unsafe_access() const { return _has_unsafe_access; }135int max_vector_size() const { return 0; }136ciMethod* method() const { return _method; }137int osr_bci() const { return _osr_bci; }138bool is_osr_compile() const { return osr_bci() >= 0; }139IR* hir() const { return _hir; }140int max_spills() const { return _max_spills; }141FrameMap* frame_map() const { return _frame_map; }142CodeBuffer* code() { return &_code; }143C1_MacroAssembler* masm() const { return _masm; }144CodeOffsets* offsets() { return &_offsets; }145Arena* arena() { return _arena; }146bool has_access_indexed() { return _has_access_indexed; }147148// Instruction ids149int get_next_id() { return _next_id++; }150int number_of_instructions() const { return _next_id; }151152// BlockBegin ids153int get_next_block_id() { return _next_block_id++; }154int number_of_blocks() const { return _next_block_id; }155156// setters157void set_has_exception_handlers(bool f) { _has_exception_handlers = f; }158void set_has_fpu_code(bool f) { _has_fpu_code = f; }159void set_has_unsafe_access(bool f) { _has_unsafe_access = f; }160void set_would_profile(bool f) { _would_profile = f; }161void set_has_access_indexed(bool f) { _has_access_indexed = f; }162// Add a set of exception handlers covering the given PC offset163void add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers);164// Statistics gathering165void notice_inlined_method(ciMethod* method);166167// JSR 292168bool has_method_handle_invokes() const { return _has_method_handle_invokes; }169void set_has_method_handle_invokes(bool z) { _has_method_handle_invokes = z; }170171DebugInformationRecorder* debug_info_recorder() const; // = _env->debug_info();172Dependencies* dependency_recorder() const; // = _env->dependencies()173ImplicitExceptionTable* implicit_exception_table() { return &_implicit_exception_table; }174175Instruction* current_instruction() const { return _current_instruction; }176Instruction* set_current_instruction(Instruction* instr) {177Instruction* previous = _current_instruction;178_current_instruction = instr;179return previous;180}181182#ifndef PRODUCT183void maybe_print_current_instruction();184#endif // PRODUCT185186// error handling187void bailout(const char* msg);188bool bailed_out() const { return _bailout_msg != NULL; }189const char* bailout_msg() const { return _bailout_msg; }190191static int desired_max_code_buffer_size() {192#ifndef PPC193return (int) NMethodSizeLimit; // default 256K or 512K194#else195// conditional branches on PPC are restricted to 16 bit signed196return MIN2((unsigned int)NMethodSizeLimit,32*K);197#endif198}199static int desired_max_constant_size() {200return desired_max_code_buffer_size() / 10;201}202203static bool setup_code_buffer(CodeBuffer* cb, int call_stub_estimate);204205// timers206static void print_timers();207208#ifndef PRODUCT209// debugging support.210// produces a file named c1compileonly in the current directory with211// directives to compile only the current method and it's inlines.212// The file can be passed to the command line option -XX:Flags=<filename>213void compile_only_this_method();214void compile_only_this_scope(outputStream* st, IRScope* scope);215void exclude_this_method();216#endif // PRODUCT217218bool is_profiling() {219return env()->comp_level() == CompLevel_full_profile ||220env()->comp_level() == CompLevel_limited_profile;221}222bool count_invocations() { return is_profiling(); }223bool count_backedges() { return is_profiling(); }224225// Helpers for generation of profile information226bool profile_branches() {227return env()->comp_level() == CompLevel_full_profile &&228C1UpdateMethodData && C1ProfileBranches;229}230bool profile_calls() {231return env()->comp_level() == CompLevel_full_profile &&232C1UpdateMethodData && C1ProfileCalls;233}234bool profile_inlined_calls() {235return profile_calls() && C1ProfileInlinedCalls;236}237bool profile_checkcasts() {238return env()->comp_level() == CompLevel_full_profile &&239C1UpdateMethodData && C1ProfileCheckcasts;240}241bool profile_parameters() {242return env()->comp_level() == CompLevel_full_profile &&243C1UpdateMethodData && MethodData::profile_parameters();244}245bool profile_arguments() {246return env()->comp_level() == CompLevel_full_profile &&247C1UpdateMethodData && MethodData::profile_arguments();248}249bool profile_return() {250return env()->comp_level() == CompLevel_full_profile &&251C1UpdateMethodData && MethodData::profile_return();252}253// will compilation make optimistic assumptions that might lead to254// deoptimization and that the runtime will account for?255bool is_optimistic() const {256return !TieredCompilation &&257(RangeCheckElimination || UseLoopInvariantCodeMotion) &&258method()->method_data()->trap_count(Deoptimization::Reason_none) == 0;259}260261ciKlass* cha_exact_type(ciType* type);262263// Dump inlining replay data to the stream.264void dump_inline_data(outputStream* out) { /* do nothing now */ }265266// How much stack space would the interpreter need in case of a267// deoptimization (worst case)268void update_interpreter_frame_size(int size) {269if (_interpreter_frame_size < size) {270_interpreter_frame_size = size;271}272}273274int interpreter_frame_size() const {275return _interpreter_frame_size;276}277};278279280// Macro definitions for unified bailout-support281// The methods bailout() and bailed_out() are present in all classes282// that might bailout, but forward all calls to Compilation283#define BAILOUT(msg) { bailout(msg); return; }284#define BAILOUT_(msg, res) { bailout(msg); return res; }285286#define CHECK_BAILOUT() { if (bailed_out()) return; }287#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }288289290class InstructionMark: public StackObj {291private:292Compilation* _compilation;293Instruction* _previous;294295public:296InstructionMark(Compilation* compilation, Instruction* instr) {297_compilation = compilation;298_previous = _compilation->set_current_instruction(instr);299}300~InstructionMark() {301_compilation->set_current_instruction(_previous);302}303};304305306//----------------------------------------------------------------------307// Base class for objects allocated by the compiler in the compilation arena308class CompilationResourceObj ALLOCATION_SUPER_CLASS_SPEC {309public:310void* operator new(size_t size) throw() { return Compilation::current()->arena()->Amalloc(size); }311void* operator new(size_t size, Arena* arena) throw() {312return arena->Amalloc(size);313}314void operator delete(void* p) {} // nothing to do315};316317318//----------------------------------------------------------------------319// Class for aggregating exception handler information.320321// Effectively extends XHandlers class with PC offset of322// potentially exception-throwing instruction.323// This class is used at the end of the compilation to build the324// ExceptionHandlerTable.325class ExceptionInfo: public CompilationResourceObj {326private:327int _pco; // PC of potentially exception-throwing instruction328XHandlers* _exception_handlers; // flat list of exception handlers covering this PC329330public:331ExceptionInfo(int pco, XHandlers* exception_handlers)332: _pco(pco)333, _exception_handlers(exception_handlers)334{ }335336int pco() { return _pco; }337XHandlers* exception_handlers() { return _exception_handlers; }338};339340#endif // SHARE_VM_C1_C1_COMPILATION_HPP341342343