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