src/share/vm/code/codeBlob.hpp

Fri, 08 Nov 2013 01:13:11 -0800

author
vlivanov
date
Fri, 08 Nov 2013 01:13:11 -0800
changeset 6096
e2509677809c
parent 5919
469216acdb28
child 6876
710a3c8b516e
child 9185
82f9d3b7e317
permissions
-rw-r--r--

8023037: Race between ciEnv::register_method and nmethod::make_not_entrant_or_zombie
Reviewed-by: kvn, iveresov

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

mercurial