37 class LIR_Assembler;
38 class CodeEmitInfo;
39 class ciEnv;
40 class ciMethod;
41 class ValueStack;
42 class LIR_OprDesc;
43 class C1_MacroAssembler;
44 class CFGPrinter;
45 typedef LIR_OprDesc* LIR_Opr;
46
47
48 define_array(BasicTypeArray, BasicType)
49 define_stack(BasicTypeList, BasicTypeArray)
50
51 define_array(ExceptionInfoArray, ExceptionInfo*)
52 define_stack(ExceptionInfoList, ExceptionInfoArray)
53
54 class Compilation: public StackObj {
55 friend class CompilationResourceObj;
56 private:
57
58 static Arena* _arena;
59 static Arena* arena() { return _arena; }
60
61 static Compilation* _compilation;
62
63 private:
64 // compilation specifics
65 AbstractCompiler* _compiler;
66 ciEnv* _env;
67 ciMethod* _method;
68 int _osr_bci;
69 IR* _hir;
70 int _max_spills;
71 FrameMap* _frame_map;
72 C1_MacroAssembler* _masm;
73 bool _has_exception_handlers;
74 bool _has_fpu_code;
75 bool _has_unsafe_access;
76 const char* _bailout_msg;
77 ExceptionInfoList* _exception_info_list;
78 ExceptionHandlerTable _exception_handler_table;
79 ImplicitExceptionTable _implicit_exception_table;
80 LinearScan* _allocator;
81 CodeOffsets _offsets;
82 CodeBuffer _code;
83
84 // compilation helpers
91
92 int compile_java_method();
93 void install_code(int frame_size);
94 void compile_method();
95
96 void generate_exception_handler_table();
97
98 ExceptionInfoList* exception_info_list() const { return _exception_info_list; }
99 ExceptionHandlerTable* exception_handler_table() { return &_exception_handler_table; }
100
101 LinearScan* allocator() { return _allocator; }
102 void set_allocator(LinearScan* allocator) { _allocator = allocator; }
103
104 Instruction* _current_instruction; // the instruction currently being processed
105 #ifndef PRODUCT
106 Instruction* _last_instruction_printed; // the last instruction printed during traversal
107 #endif // PRODUCT
108
109 public:
110 // creation
111 Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method, int osr_bci);
112 ~Compilation();
113
114 static Compilation* current_compilation() { return _compilation; }
115
116 // accessors
117 ciEnv* env() const { return _env; }
118 AbstractCompiler* compiler() const { return _compiler; }
119 bool has_exception_handlers() const { return _has_exception_handlers; }
120 bool has_fpu_code() const { return _has_fpu_code; }
121 bool has_unsafe_access() const { return _has_unsafe_access; }
122 ciMethod* method() const { return _method; }
123 int osr_bci() const { return _osr_bci; }
124 bool is_osr_compile() const { return osr_bci() >= 0; }
125 IR* hir() const { return _hir; }
126 int max_spills() const { return _max_spills; }
127 FrameMap* frame_map() const { return _frame_map; }
128 CodeBuffer* code() { return &_code; }
129 C1_MacroAssembler* masm() const { return _masm; }
130 CodeOffsets* offsets() { return &_offsets; }
131
132 // setters
133 void set_has_exception_handlers(bool f) { _has_exception_handlers = f; }
134 void set_has_fpu_code(bool f) { _has_fpu_code = f; }
135 void set_has_unsafe_access(bool f) { _has_unsafe_access = f; }
136 // Add a set of exception handlers covering the given PC offset
137 void add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers);
138 // Statistics gathering
139 void notice_inlined_method(ciMethod* method);
140
141 DebugInformationRecorder* debug_info_recorder() const; // = _env->debug_info();
142 Dependencies* dependency_recorder() const; // = _env->dependencies()
143 ImplicitExceptionTable* implicit_exception_table() { return &_implicit_exception_table; }
144
145 Instruction* current_instruction() const { return _current_instruction; }
146 Instruction* set_current_instruction(Instruction* instr) {
147 Instruction* previous = _current_instruction;
148 _current_instruction = instr;
149 return previous;
150 }
151
152 #ifndef PRODUCT
153 void maybe_print_current_instruction();
154 #endif // PRODUCT
155
156 // error handling
157 void bailout(const char* msg);
158 bool bailed_out() const { return _bailout_msg != NULL; }
159 const char* bailout_msg() const { return _bailout_msg; }
160
161 // timers
162 static void print_timers();
163
164 #ifndef PRODUCT
165 // debugging support.
166 // produces a file named c1compileonly in the current directory with
167 // directives to compile only the current method and it's inlines.
168 // The file can be passed to the command line option -XX:Flags=<filename>
169 void compile_only_this_method();
170 void compile_only_this_scope(outputStream* st, IRScope* scope);
171 void exclude_this_method();
172 #endif // PRODUCT
173 };
174
175
176 // Macro definitions for unified bailout-support
177 // The methods bailout() and bailed_out() are present in all classes
178 // that might bailout, but forward all calls to Compilation
179 #define BAILOUT(msg) { bailout(msg); return; }
180 #define BAILOUT_(msg, res) { bailout(msg); return res; }
186 class InstructionMark: public StackObj {
187 private:
188 Compilation* _compilation;
189 Instruction* _previous;
190
191 public:
192 InstructionMark(Compilation* compilation, Instruction* instr) {
193 _compilation = compilation;
194 _previous = _compilation->set_current_instruction(instr);
195 }
196 ~InstructionMark() {
197 _compilation->set_current_instruction(_previous);
198 }
199 };
200
201
202 //----------------------------------------------------------------------
203 // Base class for objects allocated by the compiler in the compilation arena
204 class CompilationResourceObj ALLOCATION_SUPER_CLASS_SPEC {
205 public:
206 void* operator new(size_t size) { return Compilation::arena()->Amalloc(size); }
207 void operator delete(void* p) {} // nothing to do
208 };
209
210
211 //----------------------------------------------------------------------
212 // Class for aggregating exception handler information.
213
214 // Effectively extends XHandlers class with PC offset of
215 // potentially exception-throwing instruction.
216 // This class is used at the end of the compilation to build the
217 // ExceptionHandlerTable.
218 class ExceptionInfo: public CompilationResourceObj {
219 private:
220 int _pco; // PC of potentially exception-throwing instruction
221 XHandlers* _exception_handlers; // flat list of exception handlers covering this PC
222
223 public:
224 ExceptionInfo(int pco, XHandlers* exception_handlers)
225 : _pco(pco)
226 , _exception_handlers(exception_handlers)
|
37 class LIR_Assembler;
38 class CodeEmitInfo;
39 class ciEnv;
40 class ciMethod;
41 class ValueStack;
42 class LIR_OprDesc;
43 class C1_MacroAssembler;
44 class CFGPrinter;
45 typedef LIR_OprDesc* LIR_Opr;
46
47
48 define_array(BasicTypeArray, BasicType)
49 define_stack(BasicTypeList, BasicTypeArray)
50
51 define_array(ExceptionInfoArray, ExceptionInfo*)
52 define_stack(ExceptionInfoList, ExceptionInfoArray)
53
54 class Compilation: public StackObj {
55 friend class CompilationResourceObj;
56 private:
57 // compilation specifics
58 Arena* _arena;
59 int _next_id;
60 int _next_block_id;
61 AbstractCompiler* _compiler;
62 ciEnv* _env;
63 ciMethod* _method;
64 int _osr_bci;
65 IR* _hir;
66 int _max_spills;
67 FrameMap* _frame_map;
68 C1_MacroAssembler* _masm;
69 bool _has_exception_handlers;
70 bool _has_fpu_code;
71 bool _has_unsafe_access;
72 const char* _bailout_msg;
73 ExceptionInfoList* _exception_info_list;
74 ExceptionHandlerTable _exception_handler_table;
75 ImplicitExceptionTable _implicit_exception_table;
76 LinearScan* _allocator;
77 CodeOffsets _offsets;
78 CodeBuffer _code;
79
80 // compilation helpers
87
88 int compile_java_method();
89 void install_code(int frame_size);
90 void compile_method();
91
92 void generate_exception_handler_table();
93
94 ExceptionInfoList* exception_info_list() const { return _exception_info_list; }
95 ExceptionHandlerTable* exception_handler_table() { return &_exception_handler_table; }
96
97 LinearScan* allocator() { return _allocator; }
98 void set_allocator(LinearScan* allocator) { _allocator = allocator; }
99
100 Instruction* _current_instruction; // the instruction currently being processed
101 #ifndef PRODUCT
102 Instruction* _last_instruction_printed; // the last instruction printed during traversal
103 #endif // PRODUCT
104
105 public:
106 // creation
107 Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method,
108 int osr_bci, BufferBlob* buffer_blob);
109 ~Compilation();
110
111
112 static Compilation* current() {
113 return (Compilation*) ciEnv::current()->compiler_data();
114 }
115
116 // accessors
117 ciEnv* env() const { return _env; }
118 AbstractCompiler* compiler() const { return _compiler; }
119 bool has_exception_handlers() const { return _has_exception_handlers; }
120 bool has_fpu_code() const { return _has_fpu_code; }
121 bool has_unsafe_access() const { return _has_unsafe_access; }
122 ciMethod* method() const { return _method; }
123 int osr_bci() const { return _osr_bci; }
124 bool is_osr_compile() const { return osr_bci() >= 0; }
125 IR* hir() const { return _hir; }
126 int max_spills() const { return _max_spills; }
127 FrameMap* frame_map() const { return _frame_map; }
128 CodeBuffer* code() { return &_code; }
129 C1_MacroAssembler* masm() const { return _masm; }
130 CodeOffsets* offsets() { return &_offsets; }
131 Arena* arena() { return _arena; }
132
133 // Instruction ids
134 int get_next_id() { return _next_id++; }
135 int number_of_instructions() const { return _next_id; }
136
137 // BlockBegin ids
138 int get_next_block_id() { return _next_block_id++; }
139 int number_of_blocks() const { return _next_block_id; }
140
141 // setters
142 void set_has_exception_handlers(bool f) { _has_exception_handlers = f; }
143 void set_has_fpu_code(bool f) { _has_fpu_code = f; }
144 void set_has_unsafe_access(bool f) { _has_unsafe_access = f; }
145 // Add a set of exception handlers covering the given PC offset
146 void add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers);
147 // Statistics gathering
148 void notice_inlined_method(ciMethod* method);
149
150 DebugInformationRecorder* debug_info_recorder() const; // = _env->debug_info();
151 Dependencies* dependency_recorder() const; // = _env->dependencies()
152 ImplicitExceptionTable* implicit_exception_table() { return &_implicit_exception_table; }
153
154 Instruction* current_instruction() const { return _current_instruction; }
155 Instruction* set_current_instruction(Instruction* instr) {
156 Instruction* previous = _current_instruction;
157 _current_instruction = instr;
158 return previous;
159 }
160
161 #ifndef PRODUCT
162 void maybe_print_current_instruction();
163 #endif // PRODUCT
164
165 // error handling
166 void bailout(const char* msg);
167 bool bailed_out() const { return _bailout_msg != NULL; }
168 const char* bailout_msg() const { return _bailout_msg; }
169
170 static int desired_max_code_buffer_size() {
171 return (int) NMethodSizeLimit; // default 256K or 512K
172 }
173 static int desired_max_constant_size() {
174 return (int) NMethodSizeLimit / 10; // about 25K
175 }
176
177 static void setup_code_buffer(CodeBuffer* cb, int call_stub_estimate);
178
179 // timers
180 static void print_timers();
181
182 #ifndef PRODUCT
183 // debugging support.
184 // produces a file named c1compileonly in the current directory with
185 // directives to compile only the current method and it's inlines.
186 // The file can be passed to the command line option -XX:Flags=<filename>
187 void compile_only_this_method();
188 void compile_only_this_scope(outputStream* st, IRScope* scope);
189 void exclude_this_method();
190 #endif // PRODUCT
191 };
192
193
194 // Macro definitions for unified bailout-support
195 // The methods bailout() and bailed_out() are present in all classes
196 // that might bailout, but forward all calls to Compilation
197 #define BAILOUT(msg) { bailout(msg); return; }
198 #define BAILOUT_(msg, res) { bailout(msg); return res; }
204 class InstructionMark: public StackObj {
205 private:
206 Compilation* _compilation;
207 Instruction* _previous;
208
209 public:
210 InstructionMark(Compilation* compilation, Instruction* instr) {
211 _compilation = compilation;
212 _previous = _compilation->set_current_instruction(instr);
213 }
214 ~InstructionMark() {
215 _compilation->set_current_instruction(_previous);
216 }
217 };
218
219
220 //----------------------------------------------------------------------
221 // Base class for objects allocated by the compiler in the compilation arena
222 class CompilationResourceObj ALLOCATION_SUPER_CLASS_SPEC {
223 public:
224 void* operator new(size_t size) { return Compilation::current()->arena()->Amalloc(size); }
225 void* operator new(size_t size, Arena* arena) {
226 return arena->Amalloc(size);
227 }
228 void operator delete(void* p) {} // nothing to do
229 };
230
231
232 //----------------------------------------------------------------------
233 // Class for aggregating exception handler information.
234
235 // Effectively extends XHandlers class with PC offset of
236 // potentially exception-throwing instruction.
237 // This class is used at the end of the compilation to build the
238 // ExceptionHandlerTable.
239 class ExceptionInfo: public CompilationResourceObj {
240 private:
241 int _pco; // PC of potentially exception-throwing instruction
242 XHandlers* _exception_handlers; // flat list of exception handlers covering this PC
243
244 public:
245 ExceptionInfo(int pco, XHandlers* exception_handlers)
246 : _pco(pco)
247 , _exception_handlers(exception_handlers)
|