Mercurial > hg > graal-compiler
annotate src/share/vm/c1/c1_Compilation.hpp @ 1751:2528b5bd749c
6980262: Memory leak when exception is thrown in static initializer
Summary: Use resource memory instead of c-heap for the exception message
Reviewed-by: phh, jmasa
author | kamg |
---|---|
date | Fri, 27 Aug 2010 15:05:28 -0400 |
parents | 4a665be40fd3 |
children | d5d065957597 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1397
diff
changeset
|
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1397
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1397
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1397
diff
changeset
|
21 * questions. |
0 | 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 // compilation specifics | |
1584 | 58 Arena* _arena; |
59 int _next_id; | |
60 int _next_block_id; | |
0 | 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; | |
1691
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1681
diff
changeset
|
72 bool _has_method_handle_invokes; // True if this method has MethodHandle invokes. |
0 | 73 const char* _bailout_msg; |
74 ExceptionInfoList* _exception_info_list; | |
75 ExceptionHandlerTable _exception_handler_table; | |
76 ImplicitExceptionTable _implicit_exception_table; | |
77 LinearScan* _allocator; | |
78 CodeOffsets _offsets; | |
79 CodeBuffer _code; | |
80 | |
81 // compilation helpers | |
82 void initialize(); | |
83 void build_hir(); | |
84 void emit_lir(); | |
85 | |
86 void emit_code_epilog(LIR_Assembler* assembler); | |
87 int emit_code_body(); | |
88 | |
89 int compile_java_method(); | |
90 void install_code(int frame_size); | |
91 void compile_method(); | |
92 | |
93 void generate_exception_handler_table(); | |
94 | |
95 ExceptionInfoList* exception_info_list() const { return _exception_info_list; } | |
96 ExceptionHandlerTable* exception_handler_table() { return &_exception_handler_table; } | |
97 | |
98 LinearScan* allocator() { return _allocator; } | |
99 void set_allocator(LinearScan* allocator) { _allocator = allocator; } | |
100 | |
101 Instruction* _current_instruction; // the instruction currently being processed | |
102 #ifndef PRODUCT | |
103 Instruction* _last_instruction_printed; // the last instruction printed during traversal | |
104 #endif // PRODUCT | |
105 | |
106 public: | |
107 // creation | |
1584 | 108 Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method, |
109 int osr_bci, BufferBlob* buffer_blob); | |
0 | 110 ~Compilation(); |
111 | |
1584 | 112 |
113 static Compilation* current() { | |
114 return (Compilation*) ciEnv::current()->compiler_data(); | |
115 } | |
0 | 116 |
117 // accessors | |
118 ciEnv* env() const { return _env; } | |
119 AbstractCompiler* compiler() const { return _compiler; } | |
120 bool has_exception_handlers() const { return _has_exception_handlers; } | |
121 bool has_fpu_code() const { return _has_fpu_code; } | |
122 bool has_unsafe_access() const { return _has_unsafe_access; } | |
123 ciMethod* method() const { return _method; } | |
124 int osr_bci() const { return _osr_bci; } | |
125 bool is_osr_compile() const { return osr_bci() >= 0; } | |
126 IR* hir() const { return _hir; } | |
127 int max_spills() const { return _max_spills; } | |
128 FrameMap* frame_map() const { return _frame_map; } | |
129 CodeBuffer* code() { return &_code; } | |
130 C1_MacroAssembler* masm() const { return _masm; } | |
131 CodeOffsets* offsets() { return &_offsets; } | |
1584 | 132 Arena* arena() { return _arena; } |
133 | |
134 // Instruction ids | |
135 int get_next_id() { return _next_id++; } | |
136 int number_of_instructions() const { return _next_id; } | |
137 | |
138 // BlockBegin ids | |
139 int get_next_block_id() { return _next_block_id++; } | |
140 int number_of_blocks() const { return _next_block_id; } | |
0 | 141 |
142 // setters | |
143 void set_has_exception_handlers(bool f) { _has_exception_handlers = f; } | |
144 void set_has_fpu_code(bool f) { _has_fpu_code = f; } | |
145 void set_has_unsafe_access(bool f) { _has_unsafe_access = f; } | |
146 // Add a set of exception handlers covering the given PC offset | |
147 void add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers); | |
148 // Statistics gathering | |
149 void notice_inlined_method(ciMethod* method); | |
150 | |
1691
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1681
diff
changeset
|
151 // JSR 292 |
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1681
diff
changeset
|
152 bool has_method_handle_invokes() const { return _has_method_handle_invokes; } |
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1681
diff
changeset
|
153 void set_has_method_handle_invokes(bool z) { _has_method_handle_invokes = z; } |
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1681
diff
changeset
|
154 |
0 | 155 DebugInformationRecorder* debug_info_recorder() const; // = _env->debug_info(); |
156 Dependencies* dependency_recorder() const; // = _env->dependencies() | |
157 ImplicitExceptionTable* implicit_exception_table() { return &_implicit_exception_table; } | |
158 | |
159 Instruction* current_instruction() const { return _current_instruction; } | |
160 Instruction* set_current_instruction(Instruction* instr) { | |
161 Instruction* previous = _current_instruction; | |
162 _current_instruction = instr; | |
163 return previous; | |
164 } | |
165 | |
166 #ifndef PRODUCT | |
167 void maybe_print_current_instruction(); | |
168 #endif // PRODUCT | |
169 | |
170 // error handling | |
171 void bailout(const char* msg); | |
172 bool bailed_out() const { return _bailout_msg != NULL; } | |
173 const char* bailout_msg() const { return _bailout_msg; } | |
174 | |
1584 | 175 static int desired_max_code_buffer_size() { |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
176 #ifndef PPC |
1584 | 177 return (int) NMethodSizeLimit; // default 256K or 512K |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
178 #else |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
179 // conditional branches on PPC are restricted to 16 bit signed |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
180 return MAX2((unsigned int)NMethodSizeLimit,32*K); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
181 #endif |
1584 | 182 } |
183 static int desired_max_constant_size() { | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
184 #ifndef PPC |
1584 | 185 return (int) NMethodSizeLimit / 10; // about 25K |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
186 #else |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
187 return (MAX2((unsigned int)NMethodSizeLimit, 32*K)) / 10; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
188 #endif |
1584 | 189 } |
190 | |
191 static void setup_code_buffer(CodeBuffer* cb, int call_stub_estimate); | |
192 | |
0 | 193 // timers |
194 static void print_timers(); | |
195 | |
196 #ifndef PRODUCT | |
197 // debugging support. | |
198 // produces a file named c1compileonly in the current directory with | |
199 // directives to compile only the current method and it's inlines. | |
200 // The file can be passed to the command line option -XX:Flags=<filename> | |
201 void compile_only_this_method(); | |
202 void compile_only_this_scope(outputStream* st, IRScope* scope); | |
203 void exclude_this_method(); | |
204 #endif // PRODUCT | |
205 }; | |
206 | |
207 | |
208 // Macro definitions for unified bailout-support | |
209 // The methods bailout() and bailed_out() are present in all classes | |
210 // that might bailout, but forward all calls to Compilation | |
211 #define BAILOUT(msg) { bailout(msg); return; } | |
212 #define BAILOUT_(msg, res) { bailout(msg); return res; } | |
213 | |
214 #define CHECK_BAILOUT() { if (bailed_out()) return; } | |
215 #define CHECK_BAILOUT_(res) { if (bailed_out()) return res; } | |
216 | |
217 | |
218 class InstructionMark: public StackObj { | |
219 private: | |
220 Compilation* _compilation; | |
221 Instruction* _previous; | |
222 | |
223 public: | |
224 InstructionMark(Compilation* compilation, Instruction* instr) { | |
225 _compilation = compilation; | |
226 _previous = _compilation->set_current_instruction(instr); | |
227 } | |
228 ~InstructionMark() { | |
229 _compilation->set_current_instruction(_previous); | |
230 } | |
231 }; | |
232 | |
233 | |
234 //---------------------------------------------------------------------- | |
235 // Base class for objects allocated by the compiler in the compilation arena | |
236 class CompilationResourceObj ALLOCATION_SUPER_CLASS_SPEC { | |
237 public: | |
1584 | 238 void* operator new(size_t size) { return Compilation::current()->arena()->Amalloc(size); } |
239 void* operator new(size_t size, Arena* arena) { | |
240 return arena->Amalloc(size); | |
241 } | |
0 | 242 void operator delete(void* p) {} // nothing to do |
243 }; | |
244 | |
245 | |
246 //---------------------------------------------------------------------- | |
247 // Class for aggregating exception handler information. | |
248 | |
249 // Effectively extends XHandlers class with PC offset of | |
250 // potentially exception-throwing instruction. | |
251 // This class is used at the end of the compilation to build the | |
252 // ExceptionHandlerTable. | |
253 class ExceptionInfo: public CompilationResourceObj { | |
254 private: | |
255 int _pco; // PC of potentially exception-throwing instruction | |
256 XHandlers* _exception_handlers; // flat list of exception handlers covering this PC | |
257 | |
258 public: | |
259 ExceptionInfo(int pco, XHandlers* exception_handlers) | |
260 : _pco(pco) | |
261 , _exception_handlers(exception_handlers) | |
262 { } | |
263 | |
264 int pco() { return _pco; } | |
265 XHandlers* exception_handlers() { return _exception_handlers; } | |
266 }; |