1
|
1 |
/*
|
|
2 |
* Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
class BlockBegin;
|
|
26 |
class CompilationResourceObj;
|
|
27 |
class XHandlers;
|
|
28 |
class ExceptionInfo;
|
|
29 |
class DebugInformationRecorder;
|
|
30 |
class FrameMap;
|
|
31 |
class IR;
|
|
32 |
class IRScope;
|
|
33 |
class Instruction;
|
|
34 |
class LinearScan;
|
|
35 |
class OopMap;
|
|
36 |
class LIR_Emitter;
|
|
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 _needs_debug_information;
|
|
74 |
bool _has_exception_handlers;
|
|
75 |
bool _has_fpu_code;
|
|
76 |
bool _has_unsafe_access;
|
|
77 |
const char* _bailout_msg;
|
|
78 |
ExceptionInfoList* _exception_info_list;
|
|
79 |
ExceptionHandlerTable _exception_handler_table;
|
|
80 |
ImplicitExceptionTable _implicit_exception_table;
|
|
81 |
LinearScan* _allocator;
|
|
82 |
CodeOffsets _offsets;
|
|
83 |
CodeBuffer _code;
|
|
84 |
|
|
85 |
// compilation helpers
|
|
86 |
void initialize();
|
|
87 |
void build_hir();
|
|
88 |
void emit_lir();
|
|
89 |
|
|
90 |
void emit_code_epilog(LIR_Assembler* assembler);
|
|
91 |
int emit_code_body();
|
|
92 |
|
|
93 |
int compile_java_method();
|
|
94 |
void install_code(int frame_size);
|
|
95 |
void compile_method();
|
|
96 |
|
|
97 |
void generate_exception_handler_table();
|
|
98 |
|
|
99 |
ExceptionInfoList* exception_info_list() const { return _exception_info_list; }
|
|
100 |
ExceptionHandlerTable* exception_handler_table() { return &_exception_handler_table; }
|
|
101 |
|
|
102 |
LinearScan* allocator() { return _allocator; }
|
|
103 |
void set_allocator(LinearScan* allocator) { _allocator = allocator; }
|
|
104 |
|
|
105 |
Instruction* _current_instruction; // the instruction currently being processed
|
|
106 |
#ifndef PRODUCT
|
|
107 |
Instruction* _last_instruction_printed; // the last instruction printed during traversal
|
|
108 |
#endif // PRODUCT
|
|
109 |
|
|
110 |
public:
|
|
111 |
// creation
|
|
112 |
Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method, int osr_bci);
|
|
113 |
~Compilation();
|
|
114 |
|
|
115 |
static Compilation* current_compilation() { return _compilation; }
|
|
116 |
|
|
117 |
// accessors
|
|
118 |
ciEnv* env() const { return _env; }
|
|
119 |
AbstractCompiler* compiler() const { return _compiler; }
|
|
120 |
bool needs_debug_information() const { return _needs_debug_information; }
|
|
121 |
bool has_exception_handlers() const { return _has_exception_handlers; }
|
|
122 |
bool has_fpu_code() const { return _has_fpu_code; }
|
|
123 |
bool has_unsafe_access() const { return _has_unsafe_access; }
|
|
124 |
ciMethod* method() const { return _method; }
|
|
125 |
int osr_bci() const { return _osr_bci; }
|
|
126 |
bool is_osr_compile() const { return osr_bci() >= 0; }
|
|
127 |
IR* hir() const { return _hir; }
|
|
128 |
int max_spills() const { return _max_spills; }
|
|
129 |
FrameMap* frame_map() const { return _frame_map; }
|
|
130 |
CodeBuffer* code() { return &_code; }
|
|
131 |
C1_MacroAssembler* masm() const { return _masm; }
|
|
132 |
CodeOffsets* offsets() { return &_offsets; }
|
|
133 |
|
|
134 |
// setters
|
|
135 |
void set_needs_debug_information(bool f) { _needs_debug_information = f; }
|
|
136 |
void set_has_exception_handlers(bool f) { _has_exception_handlers = f; }
|
|
137 |
void set_has_fpu_code(bool f) { _has_fpu_code = f; }
|
|
138 |
void set_has_unsafe_access(bool f) { _has_unsafe_access = f; }
|
|
139 |
// Add a set of exception handlers covering the given PC offset
|
|
140 |
void add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers);
|
|
141 |
// Statistics gathering
|
|
142 |
void notice_inlined_method(ciMethod* method);
|
|
143 |
|
|
144 |
DebugInformationRecorder* debug_info_recorder() const; // = _env->debug_info();
|
|
145 |
Dependencies* dependency_recorder() const; // = _env->dependencies()
|
|
146 |
ImplicitExceptionTable* implicit_exception_table() { return &_implicit_exception_table; }
|
|
147 |
|
|
148 |
Instruction* current_instruction() const { return _current_instruction; }
|
|
149 |
Instruction* set_current_instruction(Instruction* instr) {
|
|
150 |
Instruction* previous = _current_instruction;
|
|
151 |
_current_instruction = instr;
|
|
152 |
return previous;
|
|
153 |
}
|
|
154 |
|
|
155 |
#ifndef PRODUCT
|
|
156 |
void maybe_print_current_instruction();
|
|
157 |
#endif // PRODUCT
|
|
158 |
|
|
159 |
// error handling
|
|
160 |
void bailout(const char* msg);
|
|
161 |
bool bailed_out() const { return _bailout_msg != NULL; }
|
|
162 |
const char* bailout_msg() const { return _bailout_msg; }
|
|
163 |
|
|
164 |
// timers
|
|
165 |
static void print_timers();
|
|
166 |
|
|
167 |
#ifndef PRODUCT
|
|
168 |
// debugging support.
|
|
169 |
// produces a file named c1compileonly in the current directory with
|
|
170 |
// directives to compile only the current method and it's inlines.
|
|
171 |
// The file can be passed to the command line option -XX:Flags=<filename>
|
|
172 |
void compile_only_this_method();
|
|
173 |
void compile_only_this_scope(outputStream* st, IRScope* scope);
|
|
174 |
void exclude_this_method();
|
|
175 |
#endif // PRODUCT
|
|
176 |
};
|
|
177 |
|
|
178 |
|
|
179 |
// Macro definitions for unified bailout-support
|
|
180 |
// The methods bailout() and bailed_out() are present in all classes
|
|
181 |
// that might bailout, but forward all calls to Compilation
|
|
182 |
#define BAILOUT(msg) { bailout(msg); return; }
|
|
183 |
#define BAILOUT_(msg, res) { bailout(msg); return res; }
|
|
184 |
|
|
185 |
#define CHECK_BAILOUT() { if (bailed_out()) return; }
|
|
186 |
#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
|
|
187 |
|
|
188 |
|
|
189 |
class InstructionMark: public StackObj {
|
|
190 |
private:
|
|
191 |
Compilation* _compilation;
|
|
192 |
Instruction* _previous;
|
|
193 |
|
|
194 |
public:
|
|
195 |
InstructionMark(Compilation* compilation, Instruction* instr) {
|
|
196 |
_compilation = compilation;
|
|
197 |
_previous = _compilation->set_current_instruction(instr);
|
|
198 |
}
|
|
199 |
~InstructionMark() {
|
|
200 |
_compilation->set_current_instruction(_previous);
|
|
201 |
}
|
|
202 |
};
|
|
203 |
|
|
204 |
|
|
205 |
//----------------------------------------------------------------------
|
|
206 |
// Base class for objects allocated by the compiler in the compilation arena
|
|
207 |
class CompilationResourceObj ALLOCATION_SUPER_CLASS_SPEC {
|
|
208 |
public:
|
|
209 |
void* operator new(size_t size) { return Compilation::arena()->Amalloc(size); }
|
|
210 |
void operator delete(void* p) {} // nothing to do
|
|
211 |
};
|
|
212 |
|
|
213 |
|
|
214 |
//----------------------------------------------------------------------
|
|
215 |
// Class for aggregating exception handler information.
|
|
216 |
|
|
217 |
// Effectively extends XHandlers class with PC offset of
|
|
218 |
// potentially exception-throwing instruction.
|
|
219 |
// This class is used at the end of the compilation to build the
|
|
220 |
// ExceptionHandlerTable.
|
|
221 |
class ExceptionInfo: public CompilationResourceObj {
|
|
222 |
private:
|
|
223 |
int _pco; // PC of potentially exception-throwing instruction
|
|
224 |
XHandlers* _exception_handlers; // flat list of exception handlers covering this PC
|
|
225 |
|
|
226 |
public:
|
|
227 |
ExceptionInfo(int pco, XHandlers* exception_handlers)
|
|
228 |
: _pco(pco)
|
|
229 |
, _exception_handlers(exception_handlers)
|
|
230 |
{ }
|
|
231 |
|
|
232 |
int pco() { return _pco; }
|
|
233 |
XHandlers* exception_handlers() { return _exception_handlers; }
|
|
234 |
};
|