src/share/vm/code/codeBlob.hpp

Wed, 25 Aug 2010 05:27:54 -0700

author
twisti
date
Wed, 25 Aug 2010 05:27:54 -0700
changeset 2103
3e8fbc61cee8
parent 2036
126ea7725993
child 2314
f95d63e2154a
permissions
-rw-r--r--

6978355: renaming for 6961697
Summary: This is the renaming part of 6961697 to keep the actual changes small for review.
Reviewed-by: kvn, never

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

mercurial