src/share/vm/code/codeBlob.hpp

Thu, 22 Jul 2010 15:29:22 -0700

author
never
date
Thu, 22 Jul 2010 15:29:22 -0700
changeset 2018
7139e81efd2d
parent 1934
e9ff18c4ace7
child 2036
126ea7725993
permissions
-rw-r--r--

6970566: runThese fails with SIGSEGV
Reviewed-by: kvn

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:
never@2018 222 AdapterBlob(int size, CodeBuffer* cb);
twisti@1734 223
twisti@1734 224 public:
twisti@1734 225 // Creation
twisti@1734 226 static AdapterBlob* create(CodeBuffer* cb);
twisti@1734 227
twisti@1734 228 // Typing
twisti@1734 229 virtual bool is_adapter_blob() const { return true; }
twisti@1734 230 };
twisti@1734 231
twisti@1734 232
twisti@1734 233 //----------------------------------------------------------------------------------------------------
twisti@1734 234 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
twisti@1734 235
twisti@1734 236 class MethodHandlesAdapterBlob: public BufferBlob {
twisti@1734 237 private:
twisti@1734 238 MethodHandlesAdapterBlob(int size) : BufferBlob("MethodHandles adapters", size) {}
twisti@1734 239 MethodHandlesAdapterBlob(int size, CodeBuffer* cb) : BufferBlob("MethodHandles adapters", size, cb) {}
twisti@1734 240
twisti@1734 241 public:
twisti@1734 242 // Creation
twisti@1734 243 static MethodHandlesAdapterBlob* create(int buffer_size);
twisti@1734 244
twisti@1734 245 // Typing
twisti@1734 246 virtual bool is_method_handles_adapter_blob() const { return true; }
twisti@1734 247 };
twisti@1734 248
twisti@1734 249
twisti@1734 250 //----------------------------------------------------------------------------------------------------
duke@435 251 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
duke@435 252
duke@435 253 class RuntimeStub: public CodeBlob {
duke@435 254 friend class VMStructs;
duke@435 255 private:
duke@435 256 bool _caller_must_gc_arguments;
duke@435 257
duke@435 258 // Creation support
duke@435 259 RuntimeStub(
duke@435 260 const char* name,
duke@435 261 CodeBuffer* cb,
duke@435 262 int size,
duke@435 263 int frame_complete,
duke@435 264 int frame_size,
duke@435 265 OopMapSet* oop_maps,
duke@435 266 bool caller_must_gc_arguments
duke@435 267 );
duke@435 268
duke@435 269 void* operator new(size_t s, unsigned size);
duke@435 270
duke@435 271 public:
duke@435 272 // Creation
duke@435 273 static RuntimeStub* new_runtime_stub(
duke@435 274 const char* stub_name,
duke@435 275 CodeBuffer* cb,
duke@435 276 int frame_complete,
duke@435 277 int frame_size,
duke@435 278 OopMapSet* oop_maps,
duke@435 279 bool caller_must_gc_arguments
duke@435 280 );
duke@435 281
duke@435 282 // Typing
duke@435 283 bool is_runtime_stub() const { return true; }
duke@435 284
duke@435 285 // GC support
duke@435 286 bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; }
duke@435 287
duke@435 288 address entry_point() { return instructions_begin(); }
duke@435 289
duke@435 290 // GC/Verification support
duke@435 291 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ }
duke@435 292 bool is_alive() const { return true; }
duke@435 293
duke@435 294 void verify();
duke@435 295 void print() const PRODUCT_RETURN;
duke@435 296 void print_value_on(outputStream* st) const PRODUCT_RETURN;
duke@435 297 };
duke@435 298
duke@435 299
duke@435 300 //----------------------------------------------------------------------------------------------------
duke@435 301 // Super-class for all blobs that exist in only one instance. Implements default behaviour.
duke@435 302
duke@435 303 class SingletonBlob: public CodeBlob {
duke@435 304 friend class VMStructs;
duke@435 305 public:
duke@435 306 SingletonBlob(
duke@435 307 const char* name,
duke@435 308 CodeBuffer* cb,
duke@435 309 int header_size,
duke@435 310 int size,
duke@435 311 int frame_size,
duke@435 312 OopMapSet* oop_maps
duke@435 313 )
duke@435 314 : CodeBlob(name, cb, header_size, size, CodeOffsets::frame_never_safe, frame_size, oop_maps)
duke@435 315 {};
duke@435 316
duke@435 317 bool is_alive() const { return true; }
duke@435 318
duke@435 319 void verify(); // does nothing
duke@435 320 void print() const PRODUCT_RETURN;
duke@435 321 void print_value_on(outputStream* st) const PRODUCT_RETURN;
duke@435 322 };
duke@435 323
duke@435 324
duke@435 325 //----------------------------------------------------------------------------------------------------
duke@435 326 // DeoptimizationBlob
duke@435 327
duke@435 328 class DeoptimizationBlob: public SingletonBlob {
duke@435 329 friend class VMStructs;
duke@435 330 private:
duke@435 331 int _unpack_offset;
duke@435 332 int _unpack_with_exception;
duke@435 333 int _unpack_with_reexecution;
duke@435 334
duke@435 335 int _unpack_with_exception_in_tls;
duke@435 336
duke@435 337 // Creation support
duke@435 338 DeoptimizationBlob(
duke@435 339 CodeBuffer* cb,
duke@435 340 int size,
duke@435 341 OopMapSet* oop_maps,
duke@435 342 int unpack_offset,
duke@435 343 int unpack_with_exception_offset,
duke@435 344 int unpack_with_reexecution_offset,
duke@435 345 int frame_size
duke@435 346 );
duke@435 347
duke@435 348 void* operator new(size_t s, unsigned size);
duke@435 349
duke@435 350 public:
duke@435 351 // Creation
duke@435 352 static DeoptimizationBlob* create(
duke@435 353 CodeBuffer* cb,
duke@435 354 OopMapSet* oop_maps,
duke@435 355 int unpack_offset,
duke@435 356 int unpack_with_exception_offset,
duke@435 357 int unpack_with_reexecution_offset,
duke@435 358 int frame_size
duke@435 359 );
duke@435 360
duke@435 361 // Typing
duke@435 362 bool is_deoptimization_stub() const { return true; }
duke@435 363 const DeoptimizationBlob *as_deoptimization_stub() const { return this; }
duke@435 364 bool exception_address_is_unpack_entry(address pc) const {
duke@435 365 address unpack_pc = unpack();
duke@435 366 return (pc == unpack_pc || (pc + frame::pc_return_offset) == unpack_pc);
duke@435 367 }
duke@435 368
duke@435 369
duke@435 370
duke@435 371
duke@435 372 // GC for args
duke@435 373 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* Nothing to do */ }
duke@435 374
duke@435 375 // Printing
duke@435 376 void print_value_on(outputStream* st) const PRODUCT_RETURN;
duke@435 377
duke@435 378 address unpack() const { return instructions_begin() + _unpack_offset; }
duke@435 379 address unpack_with_exception() const { return instructions_begin() + _unpack_with_exception; }
duke@435 380 address unpack_with_reexecution() const { return instructions_begin() + _unpack_with_reexecution; }
duke@435 381
duke@435 382 // Alternate entry point for C1 where the exception and issuing pc
duke@435 383 // are in JavaThread::_exception_oop and JavaThread::_exception_pc
duke@435 384 // instead of being in registers. This is needed because C1 doesn't
duke@435 385 // model exception paths in a way that keeps these registers free so
duke@435 386 // there may be live values in those registers during deopt.
duke@435 387 void set_unpack_with_exception_in_tls_offset(int offset) {
duke@435 388 _unpack_with_exception_in_tls = offset;
duke@435 389 assert(contains(instructions_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob");
duke@435 390 }
duke@435 391 address unpack_with_exception_in_tls() const { return instructions_begin() + _unpack_with_exception_in_tls; }
duke@435 392 };
duke@435 393
duke@435 394
duke@435 395 //----------------------------------------------------------------------------------------------------
duke@435 396 // UncommonTrapBlob (currently only used by Compiler 2)
duke@435 397
duke@435 398 #ifdef COMPILER2
duke@435 399
duke@435 400 class UncommonTrapBlob: public SingletonBlob {
duke@435 401 friend class VMStructs;
duke@435 402 private:
duke@435 403 // Creation support
duke@435 404 UncommonTrapBlob(
duke@435 405 CodeBuffer* cb,
duke@435 406 int size,
duke@435 407 OopMapSet* oop_maps,
duke@435 408 int frame_size
duke@435 409 );
duke@435 410
duke@435 411 void* operator new(size_t s, unsigned size);
duke@435 412
duke@435 413 public:
duke@435 414 // Creation
duke@435 415 static UncommonTrapBlob* create(
duke@435 416 CodeBuffer* cb,
duke@435 417 OopMapSet* oop_maps,
duke@435 418 int frame_size
duke@435 419 );
duke@435 420
duke@435 421 // GC for args
duke@435 422 void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ }
duke@435 423
duke@435 424 // Typing
duke@435 425 bool is_uncommon_trap_stub() const { return true; }
duke@435 426 };
duke@435 427
duke@435 428
duke@435 429 //----------------------------------------------------------------------------------------------------
duke@435 430 // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2)
duke@435 431
duke@435 432 class ExceptionBlob: public SingletonBlob {
duke@435 433 friend class VMStructs;
duke@435 434 private:
duke@435 435 // Creation support
duke@435 436 ExceptionBlob(
duke@435 437 CodeBuffer* cb,
duke@435 438 int size,
duke@435 439 OopMapSet* oop_maps,
duke@435 440 int frame_size
duke@435 441 );
duke@435 442
duke@435 443 void* operator new(size_t s, unsigned size);
duke@435 444
duke@435 445 public:
duke@435 446 // Creation
duke@435 447 static ExceptionBlob* create(
duke@435 448 CodeBuffer* cb,
duke@435 449 OopMapSet* oop_maps,
duke@435 450 int frame_size
duke@435 451 );
duke@435 452
duke@435 453 // GC for args
duke@435 454 void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ }
duke@435 455
duke@435 456 // Typing
duke@435 457 bool is_exception_stub() const { return true; }
duke@435 458 };
duke@435 459 #endif // COMPILER2
duke@435 460
duke@435 461
duke@435 462 //----------------------------------------------------------------------------------------------------
duke@435 463 // SafepointBlob: handles illegal_instruction exceptions during a safepoint
duke@435 464
duke@435 465 class SafepointBlob: public SingletonBlob {
duke@435 466 friend class VMStructs;
duke@435 467 private:
duke@435 468 // Creation support
duke@435 469 SafepointBlob(
duke@435 470 CodeBuffer* cb,
duke@435 471 int size,
duke@435 472 OopMapSet* oop_maps,
duke@435 473 int frame_size
duke@435 474 );
duke@435 475
duke@435 476 void* operator new(size_t s, unsigned size);
duke@435 477
duke@435 478 public:
duke@435 479 // Creation
duke@435 480 static SafepointBlob* create(
duke@435 481 CodeBuffer* cb,
duke@435 482 OopMapSet* oop_maps,
duke@435 483 int frame_size
duke@435 484 );
duke@435 485
duke@435 486 // GC for args
duke@435 487 void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ }
duke@435 488
duke@435 489 // Typing
duke@435 490 bool is_safepoint_stub() const { return true; }
duke@435 491 };

mercurial