src/share/vm/code/codeBlob.cpp

Mon, 28 Feb 2011 06:07:12 -0800

author
twisti
date
Mon, 28 Feb 2011 06:07:12 -0800
changeset 2603
1b4e6a5d98e0
parent 2508
b92c45f2bc75
child 2708
1d1603768966
permissions
-rw-r--r--

7012914: JSR 292 MethodHandlesTest C1: frame::verify_return_pc(return_address) failed: must be a return pc
Reviewed-by: never, bdelsart

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
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "code/codeBlob.hpp"
stefank@2314 27 #include "code/codeCache.hpp"
stefank@2314 28 #include "code/relocInfo.hpp"
stefank@2314 29 #include "compiler/disassembler.hpp"
stefank@2314 30 #include "interpreter/bytecode.hpp"
stefank@2314 31 #include "memory/allocation.inline.hpp"
stefank@2314 32 #include "memory/heap.hpp"
stefank@2314 33 #include "oops/oop.inline.hpp"
stefank@2314 34 #include "prims/forte.hpp"
stefank@2314 35 #include "runtime/handles.inline.hpp"
stefank@2314 36 #include "runtime/interfaceSupport.hpp"
stefank@2314 37 #include "runtime/mutexLocker.hpp"
stefank@2314 38 #include "runtime/safepoint.hpp"
stefank@2314 39 #include "runtime/sharedRuntime.hpp"
stefank@2314 40 #include "runtime/vframe.hpp"
stefank@2314 41 #include "services/memoryService.hpp"
stefank@2314 42 #ifdef TARGET_ARCH_x86
stefank@2314 43 # include "nativeInst_x86.hpp"
stefank@2314 44 #endif
stefank@2314 45 #ifdef TARGET_ARCH_sparc
stefank@2314 46 # include "nativeInst_sparc.hpp"
stefank@2314 47 #endif
stefank@2314 48 #ifdef TARGET_ARCH_zero
stefank@2314 49 # include "nativeInst_zero.hpp"
stefank@2314 50 #endif
bobv@2508 51 #ifdef TARGET_ARCH_arm
bobv@2508 52 # include "nativeInst_arm.hpp"
bobv@2508 53 #endif
bobv@2508 54 #ifdef TARGET_ARCH_ppc
bobv@2508 55 # include "nativeInst_ppc.hpp"
bobv@2508 56 #endif
stefank@2314 57 #ifdef COMPILER1
stefank@2314 58 #include "c1/c1_Runtime1.hpp"
stefank@2314 59 #endif
duke@435 60
duke@435 61 unsigned int align_code_offset(int offset) {
duke@435 62 // align the size to CodeEntryAlignment
duke@435 63 return
duke@435 64 ((offset + (int)CodeHeap::header_size() + (CodeEntryAlignment-1)) & ~(CodeEntryAlignment-1))
duke@435 65 - (int)CodeHeap::header_size();
duke@435 66 }
duke@435 67
duke@435 68
duke@435 69 // This must be consistent with the CodeBlob constructor's layout actions.
duke@435 70 unsigned int CodeBlob::allocation_size(CodeBuffer* cb, int header_size) {
duke@435 71 unsigned int size = header_size;
duke@435 72 size += round_to(cb->total_relocation_size(), oopSize);
duke@435 73 // align the size to CodeEntryAlignment
duke@435 74 size = align_code_offset(size);
twisti@2103 75 size += round_to(cb->total_content_size(), oopSize);
duke@435 76 size += round_to(cb->total_oop_size(), oopSize);
duke@435 77 return size;
duke@435 78 }
duke@435 79
duke@435 80
duke@435 81 // Creates a simple CodeBlob. Sets up the size of the different regions.
duke@435 82 CodeBlob::CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size) {
twisti@2103 83 assert(size == round_to(size, oopSize), "unaligned size");
twisti@2103 84 assert(locs_size == round_to(locs_size, oopSize), "unaligned size");
duke@435 85 assert(header_size == round_to(header_size, oopSize), "unaligned size");
duke@435 86 assert(!UseRelocIndex, "no space allocated for reloc index yet");
duke@435 87
duke@435 88 // Note: If UseRelocIndex is enabled, there needs to be (at least) one
duke@435 89 // extra word for the relocation information, containing the reloc
duke@435 90 // index table length. Unfortunately, the reloc index table imple-
duke@435 91 // mentation is not easily understandable and thus it is not clear
duke@435 92 // what exactly the format is supposed to be. For now, we just turn
duke@435 93 // off the use of this table (gri 7/6/2000).
duke@435 94
duke@435 95 _name = name;
duke@435 96 _size = size;
duke@435 97 _frame_complete_offset = frame_complete;
duke@435 98 _header_size = header_size;
duke@435 99 _relocation_size = locs_size;
twisti@2103 100 _content_offset = align_code_offset(header_size + _relocation_size);
twisti@2103 101 _code_offset = _content_offset;
duke@435 102 _data_offset = size;
duke@435 103 _frame_size = 0;
duke@435 104 set_oop_maps(NULL);
duke@435 105 }
duke@435 106
duke@435 107
duke@435 108 // Creates a CodeBlob from a CodeBuffer. Sets up the size of the different regions,
duke@435 109 // and copy code and relocation info.
duke@435 110 CodeBlob::CodeBlob(
duke@435 111 const char* name,
duke@435 112 CodeBuffer* cb,
duke@435 113 int header_size,
duke@435 114 int size,
duke@435 115 int frame_complete,
duke@435 116 int frame_size,
duke@435 117 OopMapSet* oop_maps
duke@435 118 ) {
twisti@2103 119 assert(size == round_to(size, oopSize), "unaligned size");
duke@435 120 assert(header_size == round_to(header_size, oopSize), "unaligned size");
duke@435 121
duke@435 122 _name = name;
duke@435 123 _size = size;
duke@435 124 _frame_complete_offset = frame_complete;
duke@435 125 _header_size = header_size;
duke@435 126 _relocation_size = round_to(cb->total_relocation_size(), oopSize);
twisti@2103 127 _content_offset = align_code_offset(header_size + _relocation_size);
twisti@2117 128 _code_offset = _content_offset + cb->total_offset_of(cb->insts());
twisti@2103 129 _data_offset = _content_offset + round_to(cb->total_content_size(), oopSize);
duke@435 130 assert(_data_offset <= size, "codeBlob is too small");
duke@435 131
duke@435 132 cb->copy_code_and_locs_to(this);
duke@435 133 set_oop_maps(oop_maps);
duke@435 134 _frame_size = frame_size;
duke@435 135 #ifdef COMPILER1
duke@435 136 // probably wrong for tiered
duke@435 137 assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs");
duke@435 138 #endif // COMPILER1
duke@435 139 }
duke@435 140
duke@435 141
duke@435 142 void CodeBlob::set_oop_maps(OopMapSet* p) {
duke@435 143 // Danger Will Robinson! This method allocates a big
duke@435 144 // chunk of memory, its your job to free it.
duke@435 145 if (p != NULL) {
duke@435 146 // We need to allocate a chunk big enough to hold the OopMapSet and all of its OopMaps
duke@435 147 _oop_maps = (OopMapSet* )NEW_C_HEAP_ARRAY(unsigned char, p->heap_size());
duke@435 148 p->copy_to((address)_oop_maps);
duke@435 149 } else {
duke@435 150 _oop_maps = NULL;
duke@435 151 }
duke@435 152 }
duke@435 153
duke@435 154
duke@435 155 void CodeBlob::flush() {
duke@435 156 if (_oop_maps) {
duke@435 157 FREE_C_HEAP_ARRAY(unsigned char, _oop_maps);
duke@435 158 _oop_maps = NULL;
duke@435 159 }
duke@435 160 _comments.free();
duke@435 161 }
duke@435 162
duke@435 163
duke@435 164 OopMap* CodeBlob::oop_map_for_return_address(address return_address) {
twisti@2103 165 assert(oop_maps() != NULL, "nope");
twisti@2103 166 return oop_maps()->find_map_at_offset((intptr_t) return_address - (intptr_t) code_begin());
duke@435 167 }
duke@435 168
duke@435 169
duke@435 170 //----------------------------------------------------------------------------------------------------
duke@435 171 // Implementation of BufferBlob
duke@435 172
duke@435 173
duke@435 174 BufferBlob::BufferBlob(const char* name, int size)
duke@435 175 : CodeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0)
duke@435 176 {}
duke@435 177
duke@435 178 BufferBlob* BufferBlob::create(const char* name, int buffer_size) {
duke@435 179 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 180
duke@435 181 BufferBlob* blob = NULL;
duke@435 182 unsigned int size = sizeof(BufferBlob);
duke@435 183 // align the size to CodeEntryAlignment
duke@435 184 size = align_code_offset(size);
duke@435 185 size += round_to(buffer_size, oopSize);
duke@435 186 assert(name != NULL, "must provide a name");
duke@435 187 {
duke@435 188 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 189 blob = new (size) BufferBlob(name, size);
duke@435 190 }
duke@435 191 // Track memory usage statistic after releasing CodeCache_lock
duke@435 192 MemoryService::track_code_cache_memory_usage();
duke@435 193
duke@435 194 return blob;
duke@435 195 }
duke@435 196
duke@435 197
duke@435 198 BufferBlob::BufferBlob(const char* name, int size, CodeBuffer* cb)
duke@435 199 : CodeBlob(name, cb, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, 0, NULL)
duke@435 200 {}
duke@435 201
duke@435 202 BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) {
duke@435 203 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 204
duke@435 205 BufferBlob* blob = NULL;
duke@435 206 unsigned int size = allocation_size(cb, sizeof(BufferBlob));
duke@435 207 assert(name != NULL, "must provide a name");
duke@435 208 {
duke@435 209 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 210 blob = new (size) BufferBlob(name, size, cb);
duke@435 211 }
duke@435 212 // Track memory usage statistic after releasing CodeCache_lock
duke@435 213 MemoryService::track_code_cache_memory_usage();
duke@435 214
duke@435 215 return blob;
duke@435 216 }
duke@435 217
duke@435 218
duke@435 219 void* BufferBlob::operator new(size_t s, unsigned size) {
duke@435 220 void* p = CodeCache::allocate(size);
duke@435 221 return p;
duke@435 222 }
duke@435 223
duke@435 224
duke@435 225 void BufferBlob::free( BufferBlob *blob ) {
duke@435 226 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 227 {
duke@435 228 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 229 CodeCache::free((CodeBlob*)blob);
duke@435 230 }
duke@435 231 // Track memory usage statistic after releasing CodeCache_lock
duke@435 232 MemoryService::track_code_cache_memory_usage();
duke@435 233 }
duke@435 234
twisti@1734 235
twisti@1734 236 //----------------------------------------------------------------------------------------------------
twisti@1734 237 // Implementation of AdapterBlob
twisti@1734 238
never@2018 239 AdapterBlob::AdapterBlob(int size, CodeBuffer* cb) :
never@2018 240 BufferBlob("I2C/C2I adapters", size, cb) {
never@2018 241 CodeCache::commit(this);
never@2018 242 }
never@2018 243
twisti@1734 244 AdapterBlob* AdapterBlob::create(CodeBuffer* cb) {
twisti@1734 245 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
twisti@1734 246
twisti@1734 247 AdapterBlob* blob = NULL;
twisti@1734 248 unsigned int size = allocation_size(cb, sizeof(AdapterBlob));
twisti@1734 249 {
twisti@1734 250 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
twisti@1734 251 blob = new (size) AdapterBlob(size, cb);
twisti@1734 252 }
twisti@1734 253 // Track memory usage statistic after releasing CodeCache_lock
twisti@1734 254 MemoryService::track_code_cache_memory_usage();
twisti@1734 255
twisti@1734 256 return blob;
duke@435 257 }
duke@435 258
twisti@1734 259
twisti@1734 260 //----------------------------------------------------------------------------------------------------
twisti@1734 261 // Implementation of MethodHandlesAdapterBlob
twisti@1734 262
twisti@1734 263 MethodHandlesAdapterBlob* MethodHandlesAdapterBlob::create(int buffer_size) {
twisti@1734 264 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
twisti@1734 265
twisti@1734 266 MethodHandlesAdapterBlob* blob = NULL;
twisti@1734 267 unsigned int size = sizeof(MethodHandlesAdapterBlob);
twisti@1734 268 // align the size to CodeEntryAlignment
twisti@1734 269 size = align_code_offset(size);
twisti@1734 270 size += round_to(buffer_size, oopSize);
twisti@1734 271 {
twisti@1734 272 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
twisti@1734 273 blob = new (size) MethodHandlesAdapterBlob(size);
twisti@1734 274 }
twisti@1734 275 // Track memory usage statistic after releasing CodeCache_lock
twisti@1734 276 MemoryService::track_code_cache_memory_usage();
twisti@1734 277
twisti@1734 278 return blob;
twisti@1734 279 }
twisti@1734 280
twisti@1734 281
duke@435 282 //----------------------------------------------------------------------------------------------------
duke@435 283 // Implementation of RuntimeStub
duke@435 284
duke@435 285 RuntimeStub::RuntimeStub(
duke@435 286 const char* name,
duke@435 287 CodeBuffer* cb,
duke@435 288 int size,
duke@435 289 int frame_complete,
duke@435 290 int frame_size,
duke@435 291 OopMapSet* oop_maps,
duke@435 292 bool caller_must_gc_arguments
duke@435 293 )
duke@435 294 : CodeBlob(name, cb, sizeof(RuntimeStub), size, frame_complete, frame_size, oop_maps)
duke@435 295 {
duke@435 296 _caller_must_gc_arguments = caller_must_gc_arguments;
duke@435 297 }
duke@435 298
duke@435 299
duke@435 300 RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
duke@435 301 CodeBuffer* cb,
duke@435 302 int frame_complete,
duke@435 303 int frame_size,
duke@435 304 OopMapSet* oop_maps,
duke@435 305 bool caller_must_gc_arguments)
duke@435 306 {
duke@435 307 RuntimeStub* stub = NULL;
duke@435 308 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 309 {
duke@435 310 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 311 unsigned int size = allocation_size(cb, sizeof(RuntimeStub));
duke@435 312 stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
duke@435 313 }
duke@435 314
duke@435 315 // Do not hold the CodeCache lock during name formatting.
duke@435 316 if (stub != NULL) {
duke@435 317 char stub_id[256];
duke@435 318 jio_snprintf(stub_id, sizeof(stub_id), "RuntimeStub - %s", stub_name);
duke@435 319 if (PrintStubCode) {
duke@435 320 tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, stub);
twisti@2103 321 Disassembler::decode(stub->code_begin(), stub->code_end());
duke@435 322 }
twisti@2103 323 Forte::register_stub(stub_id, stub->code_begin(), stub->code_end());
duke@435 324
duke@435 325 if (JvmtiExport::should_post_dynamic_code_generated()) {
twisti@2103 326 JvmtiExport::post_dynamic_code_generated(stub_name, stub->code_begin(), stub->code_end());
duke@435 327 }
duke@435 328 }
duke@435 329
duke@435 330 // Track memory usage statistic after releasing CodeCache_lock
duke@435 331 MemoryService::track_code_cache_memory_usage();
duke@435 332
duke@435 333 return stub;
duke@435 334 }
duke@435 335
duke@435 336
duke@435 337 void* RuntimeStub::operator new(size_t s, unsigned size) {
duke@435 338 void* p = CodeCache::allocate(size);
duke@435 339 if (!p) fatal("Initial size of CodeCache is too small");
duke@435 340 return p;
duke@435 341 }
duke@435 342
duke@435 343
duke@435 344 //----------------------------------------------------------------------------------------------------
duke@435 345 // Implementation of DeoptimizationBlob
duke@435 346
duke@435 347 DeoptimizationBlob::DeoptimizationBlob(
duke@435 348 CodeBuffer* cb,
duke@435 349 int size,
duke@435 350 OopMapSet* oop_maps,
duke@435 351 int unpack_offset,
duke@435 352 int unpack_with_exception_offset,
duke@435 353 int unpack_with_reexecution_offset,
duke@435 354 int frame_size
duke@435 355 )
duke@435 356 : SingletonBlob("DeoptimizationBlob", cb, sizeof(DeoptimizationBlob), size, frame_size, oop_maps)
duke@435 357 {
duke@435 358 _unpack_offset = unpack_offset;
duke@435 359 _unpack_with_exception = unpack_with_exception_offset;
duke@435 360 _unpack_with_reexecution = unpack_with_reexecution_offset;
duke@435 361 #ifdef COMPILER1
duke@435 362 _unpack_with_exception_in_tls = -1;
duke@435 363 #endif
duke@435 364 }
duke@435 365
duke@435 366
duke@435 367 DeoptimizationBlob* DeoptimizationBlob::create(
duke@435 368 CodeBuffer* cb,
duke@435 369 OopMapSet* oop_maps,
duke@435 370 int unpack_offset,
duke@435 371 int unpack_with_exception_offset,
duke@435 372 int unpack_with_reexecution_offset,
duke@435 373 int frame_size)
duke@435 374 {
duke@435 375 DeoptimizationBlob* blob = NULL;
duke@435 376 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 377 {
duke@435 378 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 379 unsigned int size = allocation_size(cb, sizeof(DeoptimizationBlob));
duke@435 380 blob = new (size) DeoptimizationBlob(cb,
duke@435 381 size,
duke@435 382 oop_maps,
duke@435 383 unpack_offset,
duke@435 384 unpack_with_exception_offset,
duke@435 385 unpack_with_reexecution_offset,
duke@435 386 frame_size);
duke@435 387 }
duke@435 388
duke@435 389 // Do not hold the CodeCache lock during name formatting.
duke@435 390 if (blob != NULL) {
duke@435 391 char blob_id[256];
twisti@2103 392 jio_snprintf(blob_id, sizeof(blob_id), "DeoptimizationBlob@" PTR_FORMAT, blob->code_begin());
duke@435 393 if (PrintStubCode) {
duke@435 394 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob);
twisti@2103 395 Disassembler::decode(blob->code_begin(), blob->code_end());
duke@435 396 }
twisti@2103 397 Forte::register_stub(blob_id, blob->code_begin(), blob->code_end());
duke@435 398
duke@435 399 if (JvmtiExport::should_post_dynamic_code_generated()) {
twisti@2103 400 JvmtiExport::post_dynamic_code_generated("DeoptimizationBlob", blob->code_begin(), blob->code_end());
duke@435 401 }
duke@435 402 }
duke@435 403
duke@435 404 // Track memory usage statistic after releasing CodeCache_lock
duke@435 405 MemoryService::track_code_cache_memory_usage();
duke@435 406
duke@435 407 return blob;
duke@435 408 }
duke@435 409
duke@435 410
duke@435 411 void* DeoptimizationBlob::operator new(size_t s, unsigned size) {
duke@435 412 void* p = CodeCache::allocate(size);
duke@435 413 if (!p) fatal("Initial size of CodeCache is too small");
duke@435 414 return p;
duke@435 415 }
duke@435 416
duke@435 417 //----------------------------------------------------------------------------------------------------
duke@435 418 // Implementation of UncommonTrapBlob
duke@435 419
duke@435 420 #ifdef COMPILER2
duke@435 421 UncommonTrapBlob::UncommonTrapBlob(
duke@435 422 CodeBuffer* cb,
duke@435 423 int size,
duke@435 424 OopMapSet* oop_maps,
duke@435 425 int frame_size
duke@435 426 )
duke@435 427 : SingletonBlob("UncommonTrapBlob", cb, sizeof(UncommonTrapBlob), size, frame_size, oop_maps)
duke@435 428 {}
duke@435 429
duke@435 430
duke@435 431 UncommonTrapBlob* UncommonTrapBlob::create(
duke@435 432 CodeBuffer* cb,
duke@435 433 OopMapSet* oop_maps,
duke@435 434 int frame_size)
duke@435 435 {
duke@435 436 UncommonTrapBlob* blob = NULL;
duke@435 437 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 438 {
duke@435 439 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 440 unsigned int size = allocation_size(cb, sizeof(UncommonTrapBlob));
duke@435 441 blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size);
duke@435 442 }
duke@435 443
duke@435 444 // Do not hold the CodeCache lock during name formatting.
duke@435 445 if (blob != NULL) {
duke@435 446 char blob_id[256];
twisti@2103 447 jio_snprintf(blob_id, sizeof(blob_id), "UncommonTrapBlob@" PTR_FORMAT, blob->code_begin());
duke@435 448 if (PrintStubCode) {
duke@435 449 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob);
twisti@2103 450 Disassembler::decode(blob->code_begin(), blob->code_end());
duke@435 451 }
twisti@2103 452 Forte::register_stub(blob_id, blob->code_begin(), blob->code_end());
duke@435 453
duke@435 454 if (JvmtiExport::should_post_dynamic_code_generated()) {
twisti@2103 455 JvmtiExport::post_dynamic_code_generated("UncommonTrapBlob", blob->code_begin(), blob->code_end());
duke@435 456 }
duke@435 457 }
duke@435 458
duke@435 459 // Track memory usage statistic after releasing CodeCache_lock
duke@435 460 MemoryService::track_code_cache_memory_usage();
duke@435 461
duke@435 462 return blob;
duke@435 463 }
duke@435 464
duke@435 465
duke@435 466 void* UncommonTrapBlob::operator new(size_t s, unsigned size) {
duke@435 467 void* p = CodeCache::allocate(size);
duke@435 468 if (!p) fatal("Initial size of CodeCache is too small");
duke@435 469 return p;
duke@435 470 }
duke@435 471 #endif // COMPILER2
duke@435 472
duke@435 473
duke@435 474 //----------------------------------------------------------------------------------------------------
duke@435 475 // Implementation of ExceptionBlob
duke@435 476
duke@435 477 #ifdef COMPILER2
duke@435 478 ExceptionBlob::ExceptionBlob(
duke@435 479 CodeBuffer* cb,
duke@435 480 int size,
duke@435 481 OopMapSet* oop_maps,
duke@435 482 int frame_size
duke@435 483 )
duke@435 484 : SingletonBlob("ExceptionBlob", cb, sizeof(ExceptionBlob), size, frame_size, oop_maps)
duke@435 485 {}
duke@435 486
duke@435 487
duke@435 488 ExceptionBlob* ExceptionBlob::create(
duke@435 489 CodeBuffer* cb,
duke@435 490 OopMapSet* oop_maps,
duke@435 491 int frame_size)
duke@435 492 {
duke@435 493 ExceptionBlob* blob = NULL;
duke@435 494 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 495 {
duke@435 496 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 497 unsigned int size = allocation_size(cb, sizeof(ExceptionBlob));
duke@435 498 blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size);
duke@435 499 }
duke@435 500
duke@435 501 // We do not need to hold the CodeCache lock during name formatting
duke@435 502 if (blob != NULL) {
duke@435 503 char blob_id[256];
twisti@2103 504 jio_snprintf(blob_id, sizeof(blob_id), "ExceptionBlob@" PTR_FORMAT, blob->code_begin());
duke@435 505 if (PrintStubCode) {
duke@435 506 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob);
twisti@2103 507 Disassembler::decode(blob->code_begin(), blob->code_end());
duke@435 508 }
twisti@2103 509 Forte::register_stub(blob_id, blob->code_begin(), blob->code_end());
duke@435 510
duke@435 511 if (JvmtiExport::should_post_dynamic_code_generated()) {
twisti@2103 512 JvmtiExport::post_dynamic_code_generated("ExceptionBlob", blob->code_begin(), blob->code_end());
duke@435 513 }
duke@435 514 }
duke@435 515
duke@435 516 // Track memory usage statistic after releasing CodeCache_lock
duke@435 517 MemoryService::track_code_cache_memory_usage();
duke@435 518
duke@435 519 return blob;
duke@435 520 }
duke@435 521
duke@435 522
duke@435 523 void* ExceptionBlob::operator new(size_t s, unsigned size) {
duke@435 524 void* p = CodeCache::allocate(size);
duke@435 525 if (!p) fatal("Initial size of CodeCache is too small");
duke@435 526 return p;
duke@435 527 }
duke@435 528 #endif // COMPILER2
duke@435 529
duke@435 530
duke@435 531 //----------------------------------------------------------------------------------------------------
duke@435 532 // Implementation of SafepointBlob
duke@435 533
duke@435 534 SafepointBlob::SafepointBlob(
duke@435 535 CodeBuffer* cb,
duke@435 536 int size,
duke@435 537 OopMapSet* oop_maps,
duke@435 538 int frame_size
duke@435 539 )
duke@435 540 : SingletonBlob("SafepointBlob", cb, sizeof(SafepointBlob), size, frame_size, oop_maps)
duke@435 541 {}
duke@435 542
duke@435 543
duke@435 544 SafepointBlob* SafepointBlob::create(
duke@435 545 CodeBuffer* cb,
duke@435 546 OopMapSet* oop_maps,
duke@435 547 int frame_size)
duke@435 548 {
duke@435 549 SafepointBlob* blob = NULL;
duke@435 550 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 551 {
duke@435 552 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 553 unsigned int size = allocation_size(cb, sizeof(SafepointBlob));
duke@435 554 blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size);
duke@435 555 }
duke@435 556
duke@435 557 // We do not need to hold the CodeCache lock during name formatting.
duke@435 558 if (blob != NULL) {
duke@435 559 char blob_id[256];
twisti@2103 560 jio_snprintf(blob_id, sizeof(blob_id), "SafepointBlob@" PTR_FORMAT, blob->code_begin());
duke@435 561 if (PrintStubCode) {
duke@435 562 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob);
twisti@2103 563 Disassembler::decode(blob->code_begin(), blob->code_end());
duke@435 564 }
twisti@2103 565 Forte::register_stub(blob_id, blob->code_begin(), blob->code_end());
duke@435 566
duke@435 567 if (JvmtiExport::should_post_dynamic_code_generated()) {
twisti@2103 568 JvmtiExport::post_dynamic_code_generated("SafepointBlob", blob->code_begin(), blob->code_end());
duke@435 569 }
duke@435 570 }
duke@435 571
duke@435 572 // Track memory usage statistic after releasing CodeCache_lock
duke@435 573 MemoryService::track_code_cache_memory_usage();
duke@435 574
duke@435 575 return blob;
duke@435 576 }
duke@435 577
duke@435 578
duke@435 579 void* SafepointBlob::operator new(size_t s, unsigned size) {
duke@435 580 void* p = CodeCache::allocate(size);
duke@435 581 if (!p) fatal("Initial size of CodeCache is too small");
duke@435 582 return p;
duke@435 583 }
duke@435 584
duke@435 585
duke@435 586 //----------------------------------------------------------------------------------------------------
duke@435 587 // Verification and printing
duke@435 588
duke@435 589 void CodeBlob::verify() {
duke@435 590 ShouldNotReachHere();
duke@435 591 }
duke@435 592
bobv@2036 593 void CodeBlob::print_on(outputStream* st) const {
bobv@2036 594 st->print_cr("[CodeBlob (" INTPTR_FORMAT ")]", this);
bobv@2036 595 st->print_cr("Framesize: %d", _frame_size);
duke@435 596 }
duke@435 597
duke@435 598 void CodeBlob::print_value_on(outputStream* st) const {
duke@435 599 st->print_cr("[CodeBlob]");
duke@435 600 }
duke@435 601
duke@435 602 void BufferBlob::verify() {
duke@435 603 // unimplemented
duke@435 604 }
duke@435 605
bobv@2036 606 void BufferBlob::print_on(outputStream* st) const {
bobv@2036 607 CodeBlob::print_on(st);
bobv@2036 608 print_value_on(st);
duke@435 609 }
duke@435 610
duke@435 611 void BufferBlob::print_value_on(outputStream* st) const {
duke@435 612 st->print_cr("BufferBlob (" INTPTR_FORMAT ") used for %s", this, name());
duke@435 613 }
duke@435 614
duke@435 615 void RuntimeStub::verify() {
duke@435 616 // unimplemented
duke@435 617 }
duke@435 618
bobv@2036 619 void RuntimeStub::print_on(outputStream* st) const {
bobv@2036 620 CodeBlob::print_on(st);
bobv@2036 621 st->print("Runtime Stub (" INTPTR_FORMAT "): ", this);
bobv@2036 622 st->print_cr(name());
bobv@2036 623 Disassembler::decode((CodeBlob*)this, st);
duke@435 624 }
duke@435 625
duke@435 626 void RuntimeStub::print_value_on(outputStream* st) const {
duke@435 627 st->print("RuntimeStub (" INTPTR_FORMAT "): ", this); st->print(name());
duke@435 628 }
duke@435 629
duke@435 630 void SingletonBlob::verify() {
duke@435 631 // unimplemented
duke@435 632 }
duke@435 633
bobv@2036 634 void SingletonBlob::print_on(outputStream* st) const {
bobv@2036 635 CodeBlob::print_on(st);
bobv@2036 636 st->print_cr(name());
bobv@2036 637 Disassembler::decode((CodeBlob*)this, st);
duke@435 638 }
duke@435 639
duke@435 640 void SingletonBlob::print_value_on(outputStream* st) const {
duke@435 641 st->print_cr(name());
duke@435 642 }
duke@435 643
duke@435 644 void DeoptimizationBlob::print_value_on(outputStream* st) const {
duke@435 645 st->print_cr("Deoptimization (frame not available)");
duke@435 646 }

mercurial