src/share/vm/code/codeBlob.hpp

Wed, 02 Jun 2010 22:45:42 -0700

author
jrose
date
Wed, 02 Jun 2010 22:45:42 -0700
changeset 1934
e9ff18c4ace7
parent 1907
c18cbe5936b8
parent 1918
1a5913bf5e19
child 2018
7139e81efd2d
permissions
-rw-r--r--

Merge

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

mercurial