Fri, 08 Jan 2010 13:47:01 -0800
6912062: disassembler plugin needs to produce symbolic information in product mode
Summary: More informative disassembly in product mode. Also, a more consistent CompileCommand syntax.
Reviewed-by: never
1 /*
2 * Copyright 1998-2009 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 */
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;
42 class CodeBlob VALUE_OBJ_CLASS_SPEC {
44 friend class VMStructs;
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;
63 friend class OopRecorder;
65 void fix_oop_relocations(address begin, address end, bool initialize_immediates);
66 inline void initialize_immediate_oop(oop* dest, jobject handle);
68 public:
69 // Returns the space needed for CodeBlob
70 static unsigned int allocation_size(CodeBuffer* cb, int header_size);
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);
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 );
89 // Deletion
90 void flush();
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; }
102 virtual bool is_compiled_by_c2() const { return false; }
103 virtual bool is_compiled_by_c1() const { return false; }
105 // Casting
106 nmethod* as_nmethod_or_null() { return is_nmethod() ? (nmethod*) this : NULL; }
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; }
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; }
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(); }
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; }
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);
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 }
164 void copy_oops(GrowableArray<jobject>* oops);
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; }
172 virtual bool is_unloaded() const { return false; }
173 virtual bool is_not_entrant() const { return false; }
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;
181 // (All CodeBlob subtypes other than NMethod currently have
182 // an empty oops_do() method.
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(); }
190 // Frame support
191 int frame_size() const { return _frame_size; }
192 void set_frame_size(int size) { _frame_size = size; }
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; }
197 // Naming
198 const char* name() const { return _name; }
199 void set_name(const char* name) { _name = name; }
201 // Debugging
202 virtual void verify();
203 virtual void print() const PRODUCT_RETURN;
204 virtual void print_value_on(outputStream* st) const PRODUCT_RETURN;
206 // Print the comment associated with offset on stream, if there is one
207 virtual void print_block_comment(outputStream* stream, address block_begin) {
208 intptr_t offset = (intptr_t)(block_begin - instructions_begin());
209 _comments.print_block_comment(stream, offset);
210 }
212 // Transfer ownership of comments to this CodeBlob
213 void set_comments(CodeComments& comments) {
214 _comments.assign(comments);
215 }
216 };
219 //----------------------------------------------------------------------------------------------------
220 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
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);
229 void* operator new(size_t s, unsigned size);
231 public:
232 // Creation
233 static BufferBlob* create(const char* name, int buffer_size);
234 static BufferBlob* create(const char* name, CodeBuffer* cb);
236 static void free(BufferBlob* buf);
238 // Typing
239 bool is_buffer_blob() const { return true; }
240 bool is_adapter_blob() const;
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 */ }
249 void oops_do(OopClosure* f) { /* do nothing*/ }
251 void verify();
252 void print() const PRODUCT_RETURN;
253 void print_value_on(outputStream* st) const PRODUCT_RETURN;
254 };
257 //----------------------------------------------------------------------------------------------------
258 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
260 class RuntimeStub: public CodeBlob {
261 friend class VMStructs;
262 private:
263 bool _caller_must_gc_arguments;
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 );
276 void* operator new(size_t s, unsigned size);
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 );
289 // Typing
290 bool is_runtime_stub() const { return true; }
292 // GC support
293 bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; }
295 address entry_point() { return instructions_begin(); }
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*/ }
305 void verify();
306 void print() const PRODUCT_RETURN;
307 void print_value_on(outputStream* st) const PRODUCT_RETURN;
308 };
311 //----------------------------------------------------------------------------------------------------
312 // Super-class for all blobs that exist in only one instance. Implements default behaviour.
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 {};
328 bool is_alive() const { return true; }
329 void do_unloading(BoolObjectClosure* is_alive,
330 OopClosure* keep_alive,
331 bool unloading_occurred) { /* do-nothing*/ }
333 void verify(); // does nothing
334 void print() const PRODUCT_RETURN;
335 void print_value_on(outputStream* st) const PRODUCT_RETURN;
336 };
339 //----------------------------------------------------------------------------------------------------
340 // DeoptimizationBlob
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;
349 int _unpack_with_exception_in_tls;
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 );
362 void* operator new(size_t s, unsigned size);
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 );
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 }
386 // GC for args
387 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* Nothing to do */ }
389 // Iteration
390 void oops_do(OopClosure* f) {}
392 // Printing
393 void print_value_on(outputStream* st) const PRODUCT_RETURN;
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; }
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 };
412 //----------------------------------------------------------------------------------------------------
413 // UncommonTrapBlob (currently only used by Compiler 2)
415 #ifdef COMPILER2
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 );
428 void* operator new(size_t s, unsigned size);
430 public:
431 // Creation
432 static UncommonTrapBlob* create(
433 CodeBuffer* cb,
434 OopMapSet* oop_maps,
435 int frame_size
436 );
438 // GC for args
439 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ }
441 // Typing
442 bool is_uncommon_trap_stub() const { return true; }
444 // Iteration
445 void oops_do(OopClosure* f) {}
446 };
449 //----------------------------------------------------------------------------------------------------
450 // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2)
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 );
463 void* operator new(size_t s, unsigned size);
465 public:
466 // Creation
467 static ExceptionBlob* create(
468 CodeBuffer* cb,
469 OopMapSet* oop_maps,
470 int frame_size
471 );
473 // GC for args
474 void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ }
476 // Typing
477 bool is_exception_stub() const { return true; }
479 // Iteration
480 void oops_do(OopClosure* f) {}
481 };
482 #endif // COMPILER2
485 //----------------------------------------------------------------------------------------------------
486 // SafepointBlob: handles illegal_instruction exceptions during a safepoint
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 );
499 void* operator new(size_t s, unsigned size);
501 public:
502 // Creation
503 static SafepointBlob* create(
504 CodeBuffer* cb,
505 OopMapSet* oop_maps,
506 int frame_size
507 );
509 // GC for args
510 void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ }
512 // Typing
513 bool is_safepoint_stub() const { return true; }
515 // Iteration
516 void oops_do(OopClosure* f) {}
517 };