Mercurial > hg > truffle
comparison src/share/vm/code/codeBlob.hpp @ 0:a61af66fc99e jdk7-b24
Initial load
author | duke |
---|---|
date | Sat, 01 Dec 2007 00:00:00 +0000 |
parents | |
children | 148e5441d916 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a61af66fc99e |
---|---|
1 /* | |
2 * Copyright 1998-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 // 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 | |
105 // Boundaries | |
106 address header_begin() const { return (address) this; } | |
107 address header_end() const { return ((address) this) + _header_size; }; | |
108 relocInfo* relocation_begin() const { return (relocInfo*) header_end(); }; | |
109 relocInfo* relocation_end() const { return (relocInfo*)(header_end() + _relocation_size); } | |
110 address instructions_begin() const { return (address) header_begin() + _instructions_offset; } | |
111 address instructions_end() const { return (address) header_begin() + _data_offset; } | |
112 address data_begin() const { return (address) header_begin() + _data_offset; } | |
113 address data_end() const { return (address) header_begin() + _size; } | |
114 oop* oops_begin() const { return (oop*) (header_begin() + _oops_offset); } | |
115 oop* oops_end() const { return oops_begin() + _oops_length; } | |
116 | |
117 // Offsets | |
118 int relocation_offset() const { return _header_size; } | |
119 int instructions_offset() const { return _instructions_offset; } | |
120 int data_offset() const { return _data_offset; } | |
121 int oops_offset() const { return _oops_offset; } | |
122 | |
123 // Sizes | |
124 int size() const { return _size; } | |
125 int header_size() const { return _header_size; } | |
126 int relocation_size() const { return (address) relocation_end() - (address) relocation_begin(); } | |
127 int instructions_size() const { return instructions_end() - instructions_begin(); } | |
128 int data_size() const { return data_end() - data_begin(); } | |
129 int oops_size() const { return (address) oops_end() - (address) oops_begin(); } | |
130 | |
131 // Containment | |
132 bool blob_contains(address addr) const { return header_begin() <= addr && addr < data_end(); } | |
133 bool relocation_contains(relocInfo* addr) const{ return relocation_begin() <= addr && addr < relocation_end(); } | |
134 bool instructions_contains(address addr) const { return instructions_begin() <= addr && addr < instructions_end(); } | |
135 bool data_contains(address addr) const { return data_begin() <= addr && addr < data_end(); } | |
136 bool oops_contains(oop* addr) const { return oops_begin() <= addr && addr < oops_end(); } | |
137 bool contains(address addr) const { return instructions_contains(addr); } | |
138 bool is_frame_complete_at(address addr) const { return instructions_contains(addr) && | |
139 addr >= instructions_begin() + _frame_complete_offset; } | |
140 | |
141 // Relocation support | |
142 void fix_oop_relocations(address begin, address end) { | |
143 fix_oop_relocations(begin, end, false); | |
144 } | |
145 void fix_oop_relocations() { | |
146 fix_oop_relocations(NULL, NULL, false); | |
147 } | |
148 relocInfo::relocType reloc_type_for_address(address pc); | |
149 bool is_at_poll_return(address pc); | |
150 bool is_at_poll_or_poll_return(address pc); | |
151 | |
152 // Support for oops in scopes and relocs: | |
153 // Note: index 0 is reserved for null. | |
154 oop oop_at(int index) const { return index == 0? (oop)NULL: *oop_addr_at(index); } | |
155 oop* oop_addr_at(int index) const{ // for GC | |
156 // relocation indexes are biased by 1 (because 0 is reserved) | |
157 assert(index > 0 && index <= _oops_length, "must be a valid non-zero index"); | |
158 return &oops_begin()[index-1]; | |
159 } | |
160 | |
161 void copy_oops(GrowableArray<jobject>* oops); | |
162 | |
163 // CodeCache support: really only used by the nmethods, but in order to get | |
164 // asserts and certain bookkeeping to work in the CodeCache they are defined | |
165 // virtual here. | |
166 virtual bool is_zombie() const { return false; } | |
167 virtual bool is_locked_by_vm() const { return false; } | |
168 | |
169 virtual bool is_unloaded() const { return false; } | |
170 virtual bool is_not_entrant() const { return false; } | |
171 | |
172 // GC support | |
173 virtual bool is_alive() const = 0; | |
174 virtual void do_unloading(BoolObjectClosure* is_alive, | |
175 OopClosure* keep_alive, | |
176 bool unloading_occurred); | |
177 virtual void oops_do(OopClosure* f) = 0; | |
178 | |
179 // OopMap for frame | |
180 OopMapSet* oop_maps() const { return _oop_maps; } | |
181 void set_oop_maps(OopMapSet* p); | |
182 OopMap* oop_map_for_return_address(address return_address); | |
183 virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { ShouldNotReachHere(); } | |
184 | |
185 // Frame support | |
186 int frame_size() const { return _frame_size; } | |
187 void set_frame_size(int size) { _frame_size = size; } | |
188 | |
189 // Returns true, if the next frame is responsible for GC'ing oops passed as arguments | |
190 virtual bool caller_must_gc_arguments(JavaThread* thread) const { return false; } | |
191 | |
192 // Naming | |
193 const char* name() const { return _name; } | |
194 void set_name(const char* name) { _name = name; } | |
195 | |
196 // Debugging | |
197 virtual void verify(); | |
198 virtual void print() const PRODUCT_RETURN; | |
199 virtual void print_value_on(outputStream* st) const PRODUCT_RETURN; | |
200 | |
201 // Print the comment associated with offset on stream, if there is one | |
202 void print_block_comment(outputStream* stream, intptr_t offset) { | |
203 _comments.print_block_comment(stream, offset); | |
204 } | |
205 | |
206 // Transfer ownership of comments to this CodeBlob | |
207 void set_comments(CodeComments& comments) { | |
208 _comments.assign(comments); | |
209 } | |
210 }; | |
211 | |
212 | |
213 //---------------------------------------------------------------------------------------------------- | |
214 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc. | |
215 | |
216 class BufferBlob: public CodeBlob { | |
217 friend class VMStructs; | |
218 private: | |
219 // Creation support | |
220 BufferBlob(const char* name, int size); | |
221 BufferBlob(const char* name, int size, CodeBuffer* cb); | |
222 | |
223 void* operator new(size_t s, unsigned size); | |
224 | |
225 public: | |
226 // Creation | |
227 static BufferBlob* create(const char* name, int buffer_size); | |
228 static BufferBlob* create(const char* name, CodeBuffer* cb); | |
229 | |
230 static void free(BufferBlob* buf); | |
231 | |
232 // Typing | |
233 bool is_buffer_blob() const { return true; } | |
234 bool is_adapter_blob() const; | |
235 | |
236 // GC/Verification support | |
237 void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ } | |
238 bool is_alive() const { return true; } | |
239 void do_unloading(BoolObjectClosure* is_alive, | |
240 OopClosure* keep_alive, | |
241 bool unloading_occurred) { /* do nothing */ } | |
242 | |
243 void oops_do(OopClosure* f) { /* do nothing*/ } | |
244 | |
245 void verify(); | |
246 void print() const PRODUCT_RETURN; | |
247 void print_value_on(outputStream* st) const PRODUCT_RETURN; | |
248 }; | |
249 | |
250 | |
251 //---------------------------------------------------------------------------------------------------- | |
252 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine | |
253 | |
254 class RuntimeStub: public CodeBlob { | |
255 friend class VMStructs; | |
256 private: | |
257 bool _caller_must_gc_arguments; | |
258 | |
259 // Creation support | |
260 RuntimeStub( | |
261 const char* name, | |
262 CodeBuffer* cb, | |
263 int size, | |
264 int frame_complete, | |
265 int frame_size, | |
266 OopMapSet* oop_maps, | |
267 bool caller_must_gc_arguments | |
268 ); | |
269 | |
270 void* operator new(size_t s, unsigned size); | |
271 | |
272 public: | |
273 // Creation | |
274 static RuntimeStub* new_runtime_stub( | |
275 const char* stub_name, | |
276 CodeBuffer* cb, | |
277 int frame_complete, | |
278 int frame_size, | |
279 OopMapSet* oop_maps, | |
280 bool caller_must_gc_arguments | |
281 ); | |
282 | |
283 // Typing | |
284 bool is_runtime_stub() const { return true; } | |
285 | |
286 // GC support | |
287 bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; } | |
288 | |
289 address entry_point() { return instructions_begin(); } | |
290 | |
291 // GC/Verification support | |
292 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ } | |
293 bool is_alive() const { return true; } | |
294 void do_unloading(BoolObjectClosure* is_alive, | |
295 OopClosure* keep_alive, | |
296 bool unloading_occurred) { /* do nothing */ } | |
297 void oops_do(OopClosure* f) { /* do-nothing*/ } | |
298 | |
299 void verify(); | |
300 void print() const PRODUCT_RETURN; | |
301 void print_value_on(outputStream* st) const PRODUCT_RETURN; | |
302 }; | |
303 | |
304 | |
305 //---------------------------------------------------------------------------------------------------- | |
306 // Super-class for all blobs that exist in only one instance. Implements default behaviour. | |
307 | |
308 class SingletonBlob: public CodeBlob { | |
309 friend class VMStructs; | |
310 public: | |
311 SingletonBlob( | |
312 const char* name, | |
313 CodeBuffer* cb, | |
314 int header_size, | |
315 int size, | |
316 int frame_size, | |
317 OopMapSet* oop_maps | |
318 ) | |
319 : CodeBlob(name, cb, header_size, size, CodeOffsets::frame_never_safe, frame_size, oop_maps) | |
320 {}; | |
321 | |
322 bool is_alive() const { return true; } | |
323 void do_unloading(BoolObjectClosure* is_alive, | |
324 OopClosure* keep_alive, | |
325 bool unloading_occurred) { /* do-nothing*/ } | |
326 | |
327 void verify(); // does nothing | |
328 void print() const PRODUCT_RETURN; | |
329 void print_value_on(outputStream* st) const PRODUCT_RETURN; | |
330 }; | |
331 | |
332 | |
333 //---------------------------------------------------------------------------------------------------- | |
334 // DeoptimizationBlob | |
335 | |
336 class DeoptimizationBlob: public SingletonBlob { | |
337 friend class VMStructs; | |
338 private: | |
339 int _unpack_offset; | |
340 int _unpack_with_exception; | |
341 int _unpack_with_reexecution; | |
342 | |
343 int _unpack_with_exception_in_tls; | |
344 | |
345 // Creation support | |
346 DeoptimizationBlob( | |
347 CodeBuffer* cb, | |
348 int size, | |
349 OopMapSet* oop_maps, | |
350 int unpack_offset, | |
351 int unpack_with_exception_offset, | |
352 int unpack_with_reexecution_offset, | |
353 int frame_size | |
354 ); | |
355 | |
356 void* operator new(size_t s, unsigned size); | |
357 | |
358 public: | |
359 // Creation | |
360 static DeoptimizationBlob* create( | |
361 CodeBuffer* cb, | |
362 OopMapSet* oop_maps, | |
363 int unpack_offset, | |
364 int unpack_with_exception_offset, | |
365 int unpack_with_reexecution_offset, | |
366 int frame_size | |
367 ); | |
368 | |
369 // Typing | |
370 bool is_deoptimization_stub() const { return true; } | |
371 const DeoptimizationBlob *as_deoptimization_stub() const { return this; } | |
372 bool exception_address_is_unpack_entry(address pc) const { | |
373 address unpack_pc = unpack(); | |
374 return (pc == unpack_pc || (pc + frame::pc_return_offset) == unpack_pc); | |
375 } | |
376 | |
377 | |
378 | |
379 | |
380 // GC for args | |
381 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* Nothing to do */ } | |
382 | |
383 // Iteration | |
384 void oops_do(OopClosure* f) {} | |
385 | |
386 // Printing | |
387 void print_value_on(outputStream* st) const PRODUCT_RETURN; | |
388 | |
389 address unpack() const { return instructions_begin() + _unpack_offset; } | |
390 address unpack_with_exception() const { return instructions_begin() + _unpack_with_exception; } | |
391 address unpack_with_reexecution() const { return instructions_begin() + _unpack_with_reexecution; } | |
392 | |
393 // Alternate entry point for C1 where the exception and issuing pc | |
394 // are in JavaThread::_exception_oop and JavaThread::_exception_pc | |
395 // instead of being in registers. This is needed because C1 doesn't | |
396 // model exception paths in a way that keeps these registers free so | |
397 // there may be live values in those registers during deopt. | |
398 void set_unpack_with_exception_in_tls_offset(int offset) { | |
399 _unpack_with_exception_in_tls = offset; | |
400 assert(contains(instructions_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob"); | |
401 } | |
402 address unpack_with_exception_in_tls() const { return instructions_begin() + _unpack_with_exception_in_tls; } | |
403 }; | |
404 | |
405 | |
406 //---------------------------------------------------------------------------------------------------- | |
407 // UncommonTrapBlob (currently only used by Compiler 2) | |
408 | |
409 #ifdef COMPILER2 | |
410 | |
411 class UncommonTrapBlob: public SingletonBlob { | |
412 friend class VMStructs; | |
413 private: | |
414 // Creation support | |
415 UncommonTrapBlob( | |
416 CodeBuffer* cb, | |
417 int size, | |
418 OopMapSet* oop_maps, | |
419 int frame_size | |
420 ); | |
421 | |
422 void* operator new(size_t s, unsigned size); | |
423 | |
424 public: | |
425 // Creation | |
426 static UncommonTrapBlob* create( | |
427 CodeBuffer* cb, | |
428 OopMapSet* oop_maps, | |
429 int frame_size | |
430 ); | |
431 | |
432 // GC for args | |
433 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ } | |
434 | |
435 // Typing | |
436 bool is_uncommon_trap_stub() const { return true; } | |
437 | |
438 // Iteration | |
439 void oops_do(OopClosure* f) {} | |
440 }; | |
441 | |
442 | |
443 //---------------------------------------------------------------------------------------------------- | |
444 // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2) | |
445 | |
446 class ExceptionBlob: public SingletonBlob { | |
447 friend class VMStructs; | |
448 private: | |
449 // Creation support | |
450 ExceptionBlob( | |
451 CodeBuffer* cb, | |
452 int size, | |
453 OopMapSet* oop_maps, | |
454 int frame_size | |
455 ); | |
456 | |
457 void* operator new(size_t s, unsigned size); | |
458 | |
459 public: | |
460 // Creation | |
461 static ExceptionBlob* create( | |
462 CodeBuffer* cb, | |
463 OopMapSet* oop_maps, | |
464 int frame_size | |
465 ); | |
466 | |
467 // GC for args | |
468 void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ } | |
469 | |
470 // Typing | |
471 bool is_exception_stub() const { return true; } | |
472 | |
473 // Iteration | |
474 void oops_do(OopClosure* f) {} | |
475 }; | |
476 #endif // COMPILER2 | |
477 | |
478 | |
479 //---------------------------------------------------------------------------------------------------- | |
480 // SafepointBlob: handles illegal_instruction exceptions during a safepoint | |
481 | |
482 class SafepointBlob: public SingletonBlob { | |
483 friend class VMStructs; | |
484 private: | |
485 // Creation support | |
486 SafepointBlob( | |
487 CodeBuffer* cb, | |
488 int size, | |
489 OopMapSet* oop_maps, | |
490 int frame_size | |
491 ); | |
492 | |
493 void* operator new(size_t s, unsigned size); | |
494 | |
495 public: | |
496 // Creation | |
497 static SafepointBlob* create( | |
498 CodeBuffer* cb, | |
499 OopMapSet* oop_maps, | |
500 int frame_size | |
501 ); | |
502 | |
503 // GC for args | |
504 void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ } | |
505 | |
506 // Typing | |
507 bool is_safepoint_stub() const { return true; } | |
508 | |
509 // Iteration | |
510 void oops_do(OopClosure* f) {} | |
511 }; |