Mercurial > hg > truffle
annotate src/share/vm/code/codeBlob.hpp @ 1278:da9559b49b84
6915557: assert(_gvn.type(l)->higher_equal(type),"must constrain OSR typestate") with debug build
Reviewed-by: kvn
author | never |
---|---|
date | Thu, 25 Feb 2010 11:38:50 -0800 |
parents | 4e6abf09f540 |
children | 9eba43136cb5 |
rev | line source |
---|---|
0 | 1 /* |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
989
diff
changeset
|
2 * Copyright 1998-2009 Sun Microsystems, Inc. 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 * | |
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 // CodeBlob - superclass for all entries in the CodeCache. | |
26 // | |
27 // Suptypes are: | |
28 // nmethod : Compiled Java methods (include method that calls to native code) | |
29 // RuntimeStub : Call to VM runtime methods | |
30 // DeoptimizationBlob : Used for deoptimizatation | |
31 // ExceptionBlob : Used for stack unrolling | |
32 // SafepointBlob : Used to handle illegal instruction exceptions | |
33 // | |
34 // | |
35 // Layout: | |
36 // - header | |
37 // - relocation | |
38 // - instruction space | |
39 // - data space | |
40 class DeoptimizationBlob; | |
41 | |
42 class CodeBlob VALUE_OBJ_CLASS_SPEC { | |
43 | |
44 friend class VMStructs; | |
45 | |
46 private: | |
47 const char* _name; | |
48 int _size; // total size of CodeBlob in bytes | |
49 int _header_size; // size of header (depends on subclass) | |
50 int _relocation_size; // size of relocation | |
51 int _instructions_offset; // offset to where instructions region begins | |
52 int _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have | |
53 // not finished setting up their frame. Beware of pc's in | |
54 // that range. There is a similar range(s) on returns | |
55 // which we don't detect. | |
56 int _data_offset; // offset to where data region begins | |
57 int _oops_offset; // offset to where embedded oop table begins (inside data) | |
58 int _oops_length; // number of embedded oops | |
59 int _frame_size; // size of stack frame | |
60 OopMapSet* _oop_maps; // OopMap for this CodeBlob | |
61 CodeComments _comments; | |
62 | |
63 friend class OopRecorder; | |
64 | |
65 void fix_oop_relocations(address begin, address end, bool initialize_immediates); | |
66 inline void initialize_immediate_oop(oop* dest, jobject handle); | |
67 | |
68 public: | |
69 // Returns the space needed for CodeBlob | |
70 static unsigned int allocation_size(CodeBuffer* cb, int header_size); | |
71 | |
72 // Creation | |
73 // a) simple CodeBlob | |
74 // frame_complete is the offset from the beginning of the instructions | |
75 // to where the frame setup (from stackwalk viewpoint) is complete. | |
76 CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size); | |
77 | |
78 // b) full CodeBlob | |
79 CodeBlob( | |
80 const char* name, | |
81 CodeBuffer* cb, | |
82 int header_size, | |
83 int size, | |
84 int frame_complete, | |
85 int frame_size, | |
86 OopMapSet* oop_maps | |
87 ); | |
88 | |
89 // Deletion | |
90 void flush(); | |
91 | |
92 // Typing | |
93 virtual bool is_buffer_blob() const { return false; } | |
94 virtual bool is_nmethod() const { return false; } | |
95 virtual bool is_runtime_stub() const { return false; } | |
96 virtual bool is_deoptimization_stub() const { return false; } | |
97 virtual bool is_uncommon_trap_stub() const { return false; } | |
98 virtual bool is_exception_stub() const { return false; } | |
99 virtual bool is_safepoint_stub() const { return false; } | |
100 virtual bool is_adapter_blob() const { return false; } | |
101 | |
102 virtual bool is_compiled_by_c2() const { return false; } | |
103 virtual bool is_compiled_by_c1() const { return false; } | |
104 | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
989
diff
changeset
|
105 // Casting |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
989
diff
changeset
|
106 nmethod* as_nmethod_or_null() { return is_nmethod() ? (nmethod*) this : NULL; } |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
989
diff
changeset
|
107 |
0 | 108 // Boundaries |
109 address header_begin() const { return (address) this; } | |
110 address header_end() const { return ((address) this) + _header_size; }; | |
111 relocInfo* relocation_begin() const { return (relocInfo*) header_end(); }; | |
112 relocInfo* relocation_end() const { return (relocInfo*)(header_end() + _relocation_size); } | |
113 address instructions_begin() const { return (address) header_begin() + _instructions_offset; } | |
114 address instructions_end() const { return (address) header_begin() + _data_offset; } | |
115 address data_begin() const { return (address) header_begin() + _data_offset; } | |
116 address data_end() const { return (address) header_begin() + _size; } | |
117 oop* oops_begin() const { return (oop*) (header_begin() + _oops_offset); } | |
118 oop* oops_end() const { return oops_begin() + _oops_length; } | |
119 | |
120 // Offsets | |
121 int relocation_offset() const { return _header_size; } | |
122 int instructions_offset() const { return _instructions_offset; } | |
123 int data_offset() const { return _data_offset; } | |
124 int oops_offset() const { return _oops_offset; } | |
125 | |
126 // Sizes | |
127 int size() const { return _size; } | |
128 int header_size() const { return _header_size; } | |
129 int relocation_size() const { return (address) relocation_end() - (address) relocation_begin(); } | |
130 int instructions_size() const { return instructions_end() - instructions_begin(); } | |
131 int data_size() const { return data_end() - data_begin(); } | |
132 int oops_size() const { return (address) oops_end() - (address) oops_begin(); } | |
133 | |
134 // Containment | |
135 bool blob_contains(address addr) const { return header_begin() <= addr && addr < data_end(); } | |
136 bool relocation_contains(relocInfo* addr) const{ return relocation_begin() <= addr && addr < relocation_end(); } | |
137 bool instructions_contains(address addr) const { return instructions_begin() <= addr && addr < instructions_end(); } | |
138 bool data_contains(address addr) const { return data_begin() <= addr && addr < data_end(); } | |
139 bool oops_contains(oop* addr) const { return oops_begin() <= addr && addr < oops_end(); } | |
140 bool contains(address addr) const { return instructions_contains(addr); } | |
141 bool is_frame_complete_at(address addr) const { return instructions_contains(addr) && | |
142 addr >= instructions_begin() + _frame_complete_offset; } | |
143 | |
144 // Relocation support | |
145 void fix_oop_relocations(address begin, address end) { | |
146 fix_oop_relocations(begin, end, false); | |
147 } | |
148 void fix_oop_relocations() { | |
149 fix_oop_relocations(NULL, NULL, false); | |
150 } | |
151 relocInfo::relocType reloc_type_for_address(address pc); | |
152 bool is_at_poll_return(address pc); | |
153 bool is_at_poll_or_poll_return(address pc); | |
154 | |
155 // Support for oops in scopes and relocs: | |
156 // Note: index 0 is reserved for null. | |
157 oop oop_at(int index) const { return index == 0? (oop)NULL: *oop_addr_at(index); } | |
158 oop* oop_addr_at(int index) const{ // for GC | |
159 // relocation indexes are biased by 1 (because 0 is reserved) | |
160 assert(index > 0 && index <= _oops_length, "must be a valid non-zero index"); | |
161 return &oops_begin()[index-1]; | |
162 } | |
163 | |
164 void copy_oops(GrowableArray<jobject>* oops); | |
165 | |
166 // CodeCache support: really only used by the nmethods, but in order to get | |
167 // asserts and certain bookkeeping to work in the CodeCache they are defined | |
168 // virtual here. | |
169 virtual bool is_zombie() const { return false; } | |
170 virtual bool is_locked_by_vm() const { return false; } | |
171 | |
172 virtual bool is_unloaded() const { return false; } | |
173 virtual bool is_not_entrant() const { return false; } | |
174 | |
175 // GC support | |
176 virtual bool is_alive() const = 0; | |
177 virtual void do_unloading(BoolObjectClosure* is_alive, | |
178 OopClosure* keep_alive, | |
179 bool unloading_occurred); | |
180 virtual void oops_do(OopClosure* f) = 0; | |
989 | 181 // (All CodeBlob subtypes other than NMethod currently have |
182 // an empty oops_do() method. | |
0 | 183 |
184 // OopMap for frame | |
185 OopMapSet* oop_maps() const { return _oop_maps; } | |
186 void set_oop_maps(OopMapSet* p); | |
187 OopMap* oop_map_for_return_address(address return_address); | |
188 virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { ShouldNotReachHere(); } | |
189 | |
190 // Frame support | |
191 int frame_size() const { return _frame_size; } | |
192 void set_frame_size(int size) { _frame_size = size; } | |
193 | |
194 // Returns true, if the next frame is responsible for GC'ing oops passed as arguments | |
195 virtual bool caller_must_gc_arguments(JavaThread* thread) const { return false; } | |
196 | |
197 // Naming | |
198 const char* name() const { return _name; } | |
199 void set_name(const char* name) { _name = name; } | |
200 | |
201 // Debugging | |
202 virtual void verify(); | |
203 virtual void print() const PRODUCT_RETURN; | |
204 virtual void print_value_on(outputStream* st) const PRODUCT_RETURN; | |
205 | |
206 // Print the comment associated with offset on stream, if there is one | |
1155
4e6abf09f540
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1135
diff
changeset
|
207 virtual void print_block_comment(outputStream* stream, address block_begin) { |
4e6abf09f540
6912062: disassembler plugin needs to produce symbolic information in product mode
jrose
parents:
1135
diff
changeset
|
208 intptr_t offset = (intptr_t)(block_begin - instructions_begin()); |
0 | 209 _comments.print_block_comment(stream, offset); |
210 } | |
211 | |
212 // Transfer ownership of comments to this CodeBlob | |
213 void set_comments(CodeComments& comments) { | |
214 _comments.assign(comments); | |
215 } | |
216 }; | |
217 | |
218 | |
219 //---------------------------------------------------------------------------------------------------- | |
220 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc. | |
221 | |
222 class BufferBlob: public CodeBlob { | |
223 friend class VMStructs; | |
224 private: | |
225 // Creation support | |
226 BufferBlob(const char* name, int size); | |
227 BufferBlob(const char* name, int size, CodeBuffer* cb); | |
228 | |
229 void* operator new(size_t s, unsigned size); | |
230 | |
231 public: | |
232 // Creation | |
233 static BufferBlob* create(const char* name, int buffer_size); | |
234 static BufferBlob* create(const char* name, CodeBuffer* cb); | |
235 | |
236 static void free(BufferBlob* buf); | |
237 | |
238 // Typing | |
239 bool is_buffer_blob() const { return true; } | |
240 bool is_adapter_blob() const; | |
241 | |
242 // GC/Verification support | |
243 void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ } | |
244 bool is_alive() const { return true; } | |
245 void do_unloading(BoolObjectClosure* is_alive, | |
246 OopClosure* keep_alive, | |
247 bool unloading_occurred) { /* do nothing */ } | |
248 | |
249 void oops_do(OopClosure* f) { /* do nothing*/ } | |
250 | |
251 void verify(); | |
252 void print() const PRODUCT_RETURN; | |
253 void print_value_on(outputStream* st) const PRODUCT_RETURN; | |
254 }; | |
255 | |
256 | |
257 //---------------------------------------------------------------------------------------------------- | |
258 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine | |
259 | |
260 class RuntimeStub: public CodeBlob { | |
261 friend class VMStructs; | |
262 private: | |
263 bool _caller_must_gc_arguments; | |
264 | |
265 // Creation support | |
266 RuntimeStub( | |
267 const char* name, | |
268 CodeBuffer* cb, | |
269 int size, | |
270 int frame_complete, | |
271 int frame_size, | |
272 OopMapSet* oop_maps, | |
273 bool caller_must_gc_arguments | |
274 ); | |
275 | |
276 void* operator new(size_t s, unsigned size); | |
277 | |
278 public: | |
279 // Creation | |
280 static RuntimeStub* new_runtime_stub( | |
281 const char* stub_name, | |
282 CodeBuffer* cb, | |
283 int frame_complete, | |
284 int frame_size, | |
285 OopMapSet* oop_maps, | |
286 bool caller_must_gc_arguments | |
287 ); | |
288 | |
289 // Typing | |
290 bool is_runtime_stub() const { return true; } | |
291 | |
292 // GC support | |
293 bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; } | |
294 | |
295 address entry_point() { return instructions_begin(); } | |
296 | |
297 // GC/Verification support | |
298 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ } | |
299 bool is_alive() const { return true; } | |
300 void do_unloading(BoolObjectClosure* is_alive, | |
301 OopClosure* keep_alive, | |
302 bool unloading_occurred) { /* do nothing */ } | |
303 void oops_do(OopClosure* f) { /* do-nothing*/ } | |
304 | |
305 void verify(); | |
306 void print() const PRODUCT_RETURN; | |
307 void print_value_on(outputStream* st) const PRODUCT_RETURN; | |
308 }; | |
309 | |
310 | |
311 //---------------------------------------------------------------------------------------------------- | |
312 // Super-class for all blobs that exist in only one instance. Implements default behaviour. | |
313 | |
314 class SingletonBlob: public CodeBlob { | |
315 friend class VMStructs; | |
316 public: | |
317 SingletonBlob( | |
318 const char* name, | |
319 CodeBuffer* cb, | |
320 int header_size, | |
321 int size, | |
322 int frame_size, | |
323 OopMapSet* oop_maps | |
324 ) | |
325 : CodeBlob(name, cb, header_size, size, CodeOffsets::frame_never_safe, frame_size, oop_maps) | |
326 {}; | |
327 | |
328 bool is_alive() const { return true; } | |
329 void do_unloading(BoolObjectClosure* is_alive, | |
330 OopClosure* keep_alive, | |
331 bool unloading_occurred) { /* do-nothing*/ } | |
332 | |
333 void verify(); // does nothing | |
334 void print() const PRODUCT_RETURN; | |
335 void print_value_on(outputStream* st) const PRODUCT_RETURN; | |
336 }; | |
337 | |
338 | |
339 //---------------------------------------------------------------------------------------------------- | |
340 // DeoptimizationBlob | |
341 | |
342 class DeoptimizationBlob: public SingletonBlob { | |
343 friend class VMStructs; | |
344 private: | |
345 int _unpack_offset; | |
346 int _unpack_with_exception; | |
347 int _unpack_with_reexecution; | |
348 | |
349 int _unpack_with_exception_in_tls; | |
350 | |
351 // Creation support | |
352 DeoptimizationBlob( | |
353 CodeBuffer* cb, | |
354 int size, | |
355 OopMapSet* oop_maps, | |
356 int unpack_offset, | |
357 int unpack_with_exception_offset, | |
358 int unpack_with_reexecution_offset, | |
359 int frame_size | |
360 ); | |
361 | |
362 void* operator new(size_t s, unsigned size); | |
363 | |
364 public: | |
365 // Creation | |
366 static DeoptimizationBlob* create( | |
367 CodeBuffer* cb, | |
368 OopMapSet* oop_maps, | |
369 int unpack_offset, | |
370 int unpack_with_exception_offset, | |
371 int unpack_with_reexecution_offset, | |
372 int frame_size | |
373 ); | |
374 | |
375 // Typing | |
376 bool is_deoptimization_stub() const { return true; } | |
377 const DeoptimizationBlob *as_deoptimization_stub() const { return this; } | |
378 bool exception_address_is_unpack_entry(address pc) const { | |
379 address unpack_pc = unpack(); | |
380 return (pc == unpack_pc || (pc + frame::pc_return_offset) == unpack_pc); | |
381 } | |
382 | |
383 | |
384 | |
385 | |
386 // GC for args | |
387 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* Nothing to do */ } | |
388 | |
389 // Iteration | |
390 void oops_do(OopClosure* f) {} | |
391 | |
392 // Printing | |
393 void print_value_on(outputStream* st) const PRODUCT_RETURN; | |
394 | |
395 address unpack() const { return instructions_begin() + _unpack_offset; } | |
396 address unpack_with_exception() const { return instructions_begin() + _unpack_with_exception; } | |
397 address unpack_with_reexecution() const { return instructions_begin() + _unpack_with_reexecution; } | |
398 | |
399 // Alternate entry point for C1 where the exception and issuing pc | |
400 // are in JavaThread::_exception_oop and JavaThread::_exception_pc | |
401 // instead of being in registers. This is needed because C1 doesn't | |
402 // model exception paths in a way that keeps these registers free so | |
403 // there may be live values in those registers during deopt. | |
404 void set_unpack_with_exception_in_tls_offset(int offset) { | |
405 _unpack_with_exception_in_tls = offset; | |
406 assert(contains(instructions_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob"); | |
407 } | |
408 address unpack_with_exception_in_tls() const { return instructions_begin() + _unpack_with_exception_in_tls; } | |
409 }; | |
410 | |
411 | |
412 //---------------------------------------------------------------------------------------------------- | |
413 // UncommonTrapBlob (currently only used by Compiler 2) | |
414 | |
415 #ifdef COMPILER2 | |
416 | |
417 class UncommonTrapBlob: public SingletonBlob { | |
418 friend class VMStructs; | |
419 private: | |
420 // Creation support | |
421 UncommonTrapBlob( | |
422 CodeBuffer* cb, | |
423 int size, | |
424 OopMapSet* oop_maps, | |
425 int frame_size | |
426 ); | |
427 | |
428 void* operator new(size_t s, unsigned size); | |
429 | |
430 public: | |
431 // Creation | |
432 static UncommonTrapBlob* create( | |
433 CodeBuffer* cb, | |
434 OopMapSet* oop_maps, | |
435 int frame_size | |
436 ); | |
437 | |
438 // GC for args | |
439 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ } | |
440 | |
441 // Typing | |
442 bool is_uncommon_trap_stub() const { return true; } | |
443 | |
444 // Iteration | |
445 void oops_do(OopClosure* f) {} | |
446 }; | |
447 | |
448 | |
449 //---------------------------------------------------------------------------------------------------- | |
450 // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2) | |
451 | |
452 class ExceptionBlob: public SingletonBlob { | |
453 friend class VMStructs; | |
454 private: | |
455 // Creation support | |
456 ExceptionBlob( | |
457 CodeBuffer* cb, | |
458 int size, | |
459 OopMapSet* oop_maps, | |
460 int frame_size | |
461 ); | |
462 | |
463 void* operator new(size_t s, unsigned size); | |
464 | |
465 public: | |
466 // Creation | |
467 static ExceptionBlob* create( | |
468 CodeBuffer* cb, | |
469 OopMapSet* oop_maps, | |
470 int frame_size | |
471 ); | |
472 | |
473 // GC for args | |
474 void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ } | |
475 | |
476 // Typing | |
477 bool is_exception_stub() const { return true; } | |
478 | |
479 // Iteration | |
480 void oops_do(OopClosure* f) {} | |
481 }; | |
482 #endif // COMPILER2 | |
483 | |
484 | |
485 //---------------------------------------------------------------------------------------------------- | |
486 // SafepointBlob: handles illegal_instruction exceptions during a safepoint | |
487 | |
488 class SafepointBlob: public SingletonBlob { | |
489 friend class VMStructs; | |
490 private: | |
491 // Creation support | |
492 SafepointBlob( | |
493 CodeBuffer* cb, | |
494 int size, | |
495 OopMapSet* oop_maps, | |
496 int frame_size | |
497 ); | |
498 | |
499 void* operator new(size_t s, unsigned size); | |
500 | |
501 public: | |
502 // Creation | |
503 static SafepointBlob* create( | |
504 CodeBuffer* cb, | |
505 OopMapSet* oop_maps, | |
506 int frame_size | |
507 ); | |
508 | |
509 // GC for args | |
510 void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ } | |
511 | |
512 // Typing | |
513 bool is_safepoint_stub() const { return true; } | |
514 | |
515 // Iteration | |
516 void oops_do(OopClosure* f) {} | |
517 }; |